diff --git a/.github/workflows/add-issue-to-project.yml b/.github/workflows/add-issue-to-project.yml new file mode 100644 index 00000000..cfa4ba3f --- /dev/null +++ b/.github/workflows/add-issue-to-project.yml @@ -0,0 +1,13 @@ +name: Add Issue to Project + +on: + issues: + types: [ opened ] + +jobs: + add-to-project: + uses: PrestaShop/.github/.github/workflows/reusable-add-to-project.yml@master + with: + project-number: 47 + secrets: + TOKEN: ${{ secrets.JARVIS_TOKEN }} diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index f820d74c..db8e3ce0 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -1,16 +1,12 @@ name: PHP tests on: [push, pull_request] jobs: - # Check there is no syntax errors in the project php-linter: - name: PHP Syntax check 7.1 => 8.1 + name: PHP Syntax check runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3.1.0 - - - name: PHP syntax checker 7.1 - uses: prestashop/github-action-php-lint/7.1@master + uses: actions/checkout@v6 - name: PHP syntax checker 7.2 uses: prestashop/github-action-php-lint/7.2@master @@ -27,63 +23,101 @@ jobs: - name: PHP syntax checker 8.1 uses: prestashop/github-action-php-lint/8.1@master + - name: PHP syntax checker 8.2 + uses: prestashop/github-action-php-lint/8.2@master + + - name: PHP syntax checker 8.3 + uses: prestashop/github-action-php-lint/8.3@master + + - name: PHP syntax checker 8.4 + uses: prestashop/github-action-php-lint/8.4@master + + - name: PHP syntax checker 8.5 + uses: prestashop/github-action-php-lint/8.5@master + # Check the PHP code follow the coding standards php-cs-fixer: name: PHP-CS-Fixer runs-on: ubuntu-latest steps: - - name: Setup PHP - uses: shivammathur/setup-php@v2 + - name: Run PHP-CS-Fixer + uses: PrestaShop/.github/.github/actions/php-ci/php-cs@master with: php-version: '7.4' - - name: Checkout - uses: actions/checkout@v3.1.0 - - - name: Cache dependencies - uses: actions/cache@v3 + # Run PHPStan against the module (PHP 7.4 – 8.1) + phpstan-74: + name: PHPStan (PHP 7.4 - 8.1) + runs-on: ubuntu-latest + strategy: + matrix: + presta_version: ['8.2.x'] + php_version: ['7.4', '8.1'] + fail-fast: false + env: + PHPRC: ${{ github.workspace }}/${{ github.event.repository.name }}/.phpstan-php-ini + steps: + - name: Checkout repository + uses: actions/checkout@v6 with: - path: vendor - key: php-${{ hashFiles('composer.lock') }} - - - name: Install dependencies - run: composer install - - - name: Run PHP-CS-Fixer - run: ./vendor/bin/php-cs-fixer fix --dry-run --diff --using-cache=no --diff-format udiff - - # Run PHPStan against the module and a PrestaShop release + path: ${{ github.event.repository.name }} + + - name: Prepare PHP env for PrestaShop 8 (define constants before any bootstrap) + run: | + mkdir -p ${{ github.event.repository.name }}/.phpstan-php-ini + { + echo "auto_prepend_file=$GITHUB_WORKSPACE/${{ github.event.repository.name }}/tests/php/phpstan/prepend-constants.php" + echo "memory_limit=512M" + } > ${{ github.event.repository.name }}/.phpstan-php-ini/php.ini + + - name: Run PHPStan + uses: PrestaShop/.github/.github/actions/php-ci/phpstan@master + with: + php-version: ${{ matrix.php_version }} + presta-version: ${{ matrix.presta_version }} + module-name: ${{ github.event.repository.name }} + phpstan-level: '5' + phpstan-config: tests/php/phpstan/phpstan-${{ matrix.presta_version }}.neon + phpstan-version: '^0.12' + composer-version: '2.2.18' + + # Run PHPStan against the module (PHP 8.1 – 8.5) phpstan: - name: PHPStan + name: PHPStan (PHP 8.1 - 8.5) runs-on: ubuntu-latest strategy: matrix: - presta-versions: ['1.7.7', '1.7.8', '8.0', 'latest'] + include: + # PrestaShop 9.0.x supports PHP 8.1 up to 8.4 (8.5 is not supported) + - { presta_version: '9.0.3', php_version: '8.1' } + - { presta_version: '9.0.3', php_version: '8.4' } + # PrestaShop 9.1.x and develop support PHP 8.1 up to 8.5 + - { presta_version: '9.1.x', php_version: '8.1' } + - { presta_version: '9.1.x', php_version: '8.5' } + - { presta_version: 'develop', php_version: '8.1' } + - { presta_version: 'develop', php_version: '8.5' } + fail-fast: false + env: + PHPRC: ${{ github.workspace }}/${{ github.event.repository.name }}/.phpstan-php-ini steps: - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: '7.4' - - - name: Checkout - uses: actions/checkout@v3.1.0 - - # Add vendor folder in cache to make next builds faster - - name: Cache vendor folder - uses: actions/cache@v3 + - name: Checkout repository + uses: actions/checkout@v6 with: - path: vendor - key: php-${{ hashFiles('composer.lock') }} - - # Add composer local folder in cache to make next builds faster - - name: Cache composer folder - uses: actions/cache@v3 + path: ${{ github.event.repository.name }} + + - name: Prepare PHP env for PrestaShop ${{ matrix.presta_version }} (define constants before any bootstrap) + run: | + mkdir -p ${{ github.event.repository.name }}/.phpstan-php-ini + { + echo "auto_prepend_file=$GITHUB_WORKSPACE/${{ github.event.repository.name }}/tests/php/phpstan/prepend-constants.php" + echo "memory_limit=512M" + } > ${{ github.event.repository.name }}/.phpstan-php-ini/php.ini + + - name: Run PHPStan + uses: PrestaShop/.github/.github/actions/php-ci/phpstan@master with: - path: ~/.composer/cache - key: php-composer-cache - - - run: composer install - - # Docker images prestashop/prestashop may be used, even if the shop remains uninstalled - - name: Execute PHPStan on PrestaShop (Tag ${{ matrix.presta-versions }}) - run: ./tests/phpstan.sh ${{ matrix.presta-versions }} + php-version: ${{ matrix.php_version }} + presta-version: ${{ matrix.presta_version }} + module-name: ${{ github.event.repository.name }} + phpstan-level: '5' + phpstan-config: tests/php/phpstan/phpstan-${{ matrix.presta_version }}.neon \ No newline at end of file diff --git a/README.md b/README.md index f59978f3..1bf93443 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ To use it, you will need to create a Google Analytics account and insert your Go ## Compatibility -PrestaShop: `1.7.7.0` or later +PrestaShop: `8.2.0` or later ### Notes diff --git a/classes/Hook/HookDisplayBeforeBodyClosingTag.php b/classes/Hook/HookDisplayBeforeBodyClosingTag.php index 33457ff5..24e3a8c3 100644 --- a/classes/Hook/HookDisplayBeforeBodyClosingTag.php +++ b/classes/Hook/HookDisplayBeforeBodyClosingTag.php @@ -140,7 +140,7 @@ private function renderSearch() /** * This method renders tracking code for product listings, like category pages. */ - private function renderCartpage() + private function renderCartPage() { // Check if we are on cart page if ($this->context->controller->php_self != 'cart') { diff --git a/config.xml b/config.xml index 8976d9a9..cb9bf001 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ ps_googleanalytics - + diff --git a/ps_googleanalytics.php b/ps_googleanalytics.php index f2a48ebc..fa3cfee7 100644 --- a/ps_googleanalytics.php +++ b/ps_googleanalytics.php @@ -47,8 +47,8 @@ public function __construct() { $this->name = 'ps_googleanalytics'; $this->tab = 'analytics_stats'; - $this->version = '5.0.3'; - $this->ps_versions_compliancy = ['min' => '1.7.7', 'max' => _PS_VERSION_]; + $this->version = '6.0.0'; + $this->ps_versions_compliancy = ['min' => '8.2.0', 'max' => _PS_VERSION_]; $this->author = 'PrestaShop'; $this->module_key = 'fd2aaefea84ac1bb512e6f1878d990b8'; $this->bootstrap = true; diff --git a/tests/phpstan/index.php b/tests/php/index.php similarity index 69% rename from tests/phpstan/index.php rename to tests/php/index.php index c71b8a1e..6028c7f3 100644 --- a/tests/phpstan/index.php +++ b/tests/php/index.php @@ -1,19 +1,25 @@ - * @copyright Since 2007 PrestaShop SA and Contributors + * @copyright 2007-2020 PrestaShop SA and Contributors * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) * International Registered Trademark & Property of PrestaShop SA */ diff --git a/tests/php/phpstan/index.php b/tests/php/phpstan/index.php new file mode 100644 index 00000000..6028c7f3 --- /dev/null +++ b/tests/php/phpstan/index.php @@ -0,0 +1,34 @@ + + * @copyright 2007-2020 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + * International Registered Trademark & Property of PrestaShop SA + */ +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../'); +exit; diff --git a/tests/php/phpstan/phpstan-8.2.x.neon b/tests/php/phpstan/phpstan-8.2.x.neon new file mode 100644 index 00000000..914a4e6c --- /dev/null +++ b/tests/php/phpstan/phpstan-8.2.x.neon @@ -0,0 +1,15 @@ +includes: + - %currentWorkingDirectory%/tests/php/phpstan/phpstan.neon + +parameters: + ignoreErrors: + # Framework / structural limitations that cannot be fixed in module code: + # - uninstallModule() calls parent::uninstall() through a closure rebound to the + # target module via Closure::bindTo(), a pattern PHPStan cannot statically resolve. + # - Cookie uses magic __get/__set, so its dynamic properties are undefined to PHPStan. + # - HookInterface mandates the constructor signature (Ps_Googleanalytics $module, Context), + # so $module must be stored even in hooks that never read it back. + - '#PrestaShop\\Module\\Ps_Googleanalytics\\Handler\\ModuleHandler::uninstallModule\(\) calls parent::uninstall\(\) but PrestaShop\\Module\\Ps_Googleanalytics\\Handler\\ModuleHandler does not extend any class.#' + - '#Access to an undefined property Cookie\:\:\$ga_admin_order.#' + - '#Access to an undefined property Cookie\:\:\$ga_admin_refund.#' + - '#Property PrestaShop\\Module\\Ps_Googleanalytics\\Hooks\\HookActionValidateOrder::\$module is never read, only written\.#' diff --git a/tests/php/phpstan/phpstan-9.0.3.neon b/tests/php/phpstan/phpstan-9.0.3.neon new file mode 100644 index 00000000..914a4e6c --- /dev/null +++ b/tests/php/phpstan/phpstan-9.0.3.neon @@ -0,0 +1,15 @@ +includes: + - %currentWorkingDirectory%/tests/php/phpstan/phpstan.neon + +parameters: + ignoreErrors: + # Framework / structural limitations that cannot be fixed in module code: + # - uninstallModule() calls parent::uninstall() through a closure rebound to the + # target module via Closure::bindTo(), a pattern PHPStan cannot statically resolve. + # - Cookie uses magic __get/__set, so its dynamic properties are undefined to PHPStan. + # - HookInterface mandates the constructor signature (Ps_Googleanalytics $module, Context), + # so $module must be stored even in hooks that never read it back. + - '#PrestaShop\\Module\\Ps_Googleanalytics\\Handler\\ModuleHandler::uninstallModule\(\) calls parent::uninstall\(\) but PrestaShop\\Module\\Ps_Googleanalytics\\Handler\\ModuleHandler does not extend any class.#' + - '#Access to an undefined property Cookie\:\:\$ga_admin_order.#' + - '#Access to an undefined property Cookie\:\:\$ga_admin_refund.#' + - '#Property PrestaShop\\Module\\Ps_Googleanalytics\\Hooks\\HookActionValidateOrder::\$module is never read, only written\.#' diff --git a/tests/php/phpstan/phpstan-9.1.x.neon b/tests/php/phpstan/phpstan-9.1.x.neon new file mode 100644 index 00000000..914a4e6c --- /dev/null +++ b/tests/php/phpstan/phpstan-9.1.x.neon @@ -0,0 +1,15 @@ +includes: + - %currentWorkingDirectory%/tests/php/phpstan/phpstan.neon + +parameters: + ignoreErrors: + # Framework / structural limitations that cannot be fixed in module code: + # - uninstallModule() calls parent::uninstall() through a closure rebound to the + # target module via Closure::bindTo(), a pattern PHPStan cannot statically resolve. + # - Cookie uses magic __get/__set, so its dynamic properties are undefined to PHPStan. + # - HookInterface mandates the constructor signature (Ps_Googleanalytics $module, Context), + # so $module must be stored even in hooks that never read it back. + - '#PrestaShop\\Module\\Ps_Googleanalytics\\Handler\\ModuleHandler::uninstallModule\(\) calls parent::uninstall\(\) but PrestaShop\\Module\\Ps_Googleanalytics\\Handler\\ModuleHandler does not extend any class.#' + - '#Access to an undefined property Cookie\:\:\$ga_admin_order.#' + - '#Access to an undefined property Cookie\:\:\$ga_admin_refund.#' + - '#Property PrestaShop\\Module\\Ps_Googleanalytics\\Hooks\\HookActionValidateOrder::\$module is never read, only written\.#' diff --git a/tests/php/phpstan/phpstan-develop.neon b/tests/php/phpstan/phpstan-develop.neon new file mode 100644 index 00000000..914a4e6c --- /dev/null +++ b/tests/php/phpstan/phpstan-develop.neon @@ -0,0 +1,15 @@ +includes: + - %currentWorkingDirectory%/tests/php/phpstan/phpstan.neon + +parameters: + ignoreErrors: + # Framework / structural limitations that cannot be fixed in module code: + # - uninstallModule() calls parent::uninstall() through a closure rebound to the + # target module via Closure::bindTo(), a pattern PHPStan cannot statically resolve. + # - Cookie uses magic __get/__set, so its dynamic properties are undefined to PHPStan. + # - HookInterface mandates the constructor signature (Ps_Googleanalytics $module, Context), + # so $module must be stored even in hooks that never read it back. + - '#PrestaShop\\Module\\Ps_Googleanalytics\\Handler\\ModuleHandler::uninstallModule\(\) calls parent::uninstall\(\) but PrestaShop\\Module\\Ps_Googleanalytics\\Handler\\ModuleHandler does not extend any class.#' + - '#Access to an undefined property Cookie\:\:\$ga_admin_order.#' + - '#Access to an undefined property Cookie\:\:\$ga_admin_refund.#' + - '#Property PrestaShop\\Module\\Ps_Googleanalytics\\Hooks\\HookActionValidateOrder::\$module is never read, only written\.#' diff --git a/tests/php/phpstan/phpstan.neon b/tests/php/phpstan/phpstan.neon new file mode 100644 index 00000000..be11823c --- /dev/null +++ b/tests/php/phpstan/phpstan.neon @@ -0,0 +1,2 @@ + # Base PHPStan configuration for the moduleExpand commentComment on line R2ResolvedCode has comments. Press enter to view. + # This file is included by version-specific configs \ No newline at end of file diff --git a/tests/php/phpstan/prepend-constants.php b/tests/php/phpstan/prepend-constants.php new file mode 100644 index 00000000..733689a6 --- /dev/null +++ b/tests/php/phpstan/prepend-constants.php @@ -0,0 +1,11 @@ +