diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index b183c208..0014ba83 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -2,11 +2,11 @@ name: PHP tests on: [push, pull_request] jobs: php-linter: - name: PHP Syntax check 7.2 => 8.1 + name: PHP Syntax check runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2.0.0 + uses: actions/checkout@v6 - name: PHP syntax checker 7.2 uses: prestashop/github-action-php-lint/7.2@master @@ -22,63 +22,92 @@ 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 + + # 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 - with: - php-version: "7.2" - - - name: Checkout - uses: actions/checkout@v2.0.0 - - - name: Cache dependencies - uses: actions/cache@v2 + - name: Run PHP-CS-Fixer + uses: PrestaShop/.github/.github/actions/php-ci/php-cs@master with: - path: vendor - key: php-${{ hashFiles('composer.lock') }} - - - name: Install dependencies - run: composer install + php-version: '8.1' - - name: Run PHP-CS-Fixer - run: ./vendor/bin/php-cs-fixer fix --dry-run --diff --using-cache=no - phpstan: - name: PHPStan + # 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-versions: ["8.0", "latest"] + presta_version: ['8.1.7', '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: Setup PHP - uses: shivammathur/setup-php@v2 + - name: Checkout repository + uses: actions/checkout@v6 with: - php-version: "7.2" + path: ${{ github.event.repository.name }} - - name: Checkout - uses: actions/checkout@v2.0.0 + - 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/phpstan/prepend-constants.php" + echo "memory_limit=512M" + } > ${{ github.event.repository.name }}/.phpstan-php-ini/php.ini - # Add vendor folder in cache to make next builds faster - - name: Cache vendor folder - uses: actions/cache@v1 + - name: Run PHPStan + uses: PrestaShop/.github/.github/actions/php-ci/phpstan@master with: - path: vendor - key: php-${{ hashFiles('composer.lock') }} + php-version: ${{ matrix.php_version }} + presta-version: ${{ matrix.presta_version }} + module-name: ${{ github.event.repository.name }} + phpstan-level: '5' + phpstan-config: tests/phpstan/phpstan-${{ matrix.presta_version }}.neon + phpstan-version: '^0.12' + composer-version: '2.2.18' - # Add composer local folder in cache to make next builds faster - - name: Cache composer folder - uses: actions/cache@v1 + # Run PHPStan against the module (PHP 8.1 – 8.5) + phpstan: + name: PHPStan (PHP 8.1 - 8.5) + runs-on: ubuntu-latest + strategy: + matrix: + presta_version: ['9.1.x', 'develop'] + php_version: ['8.1', '8.5'] + fail-fast: false + env: + PHPRC: ${{ github.workspace }}/${{ github.event.repository.name }}/.phpstan-php-ini + steps: + - name: Checkout repository + uses: actions/checkout@v6 with: - path: ~/.composer/cache - key: php-composer-cache + path: ${{ github.event.repository.name }} - - name: Check composer - run: composer validate + - name: Prepare PHP env for PrestaShop 9.1.x and later (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/phpstan/prepend-constants.php" + echo "memory_limit=512M" + } > ${{ github.event.repository.name }}/.phpstan-php-ini/php.ini - - 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 }} + - 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/phpstan/phpstan-${{ matrix.presta_version }}.neon diff --git a/controllers/front/FrontAjaxGdpr.php b/controllers/front/FrontAjaxGdpr.php index be623951..5544012e 100644 --- a/controllers/front/FrontAjaxGdpr.php +++ b/controllers/front/FrontAjaxGdpr.php @@ -36,7 +36,7 @@ public function display() if (Tools::getValue('action') !== 'AddLog') { $this->ajaxRender(); - return false; + return; } $customerId = (int) Tools::getValue('id_customer'); @@ -63,7 +63,5 @@ public function display() } $this->ajaxRender(); - - return true; } } diff --git a/tests/phpstan.sh b/tests/phpstan.sh deleted file mode 100755 index 6aec4f8e..00000000 --- a/tests/phpstan.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -PS_VERSION=$1 - -set -e - -# Docker images prestashop/prestashop may be used, even if the shop remains uninstalled -echo "Pull PrestaShop files (Tag ${PS_VERSION})" - -docker rm -f temp-ps || true -docker volume rm -f ps-volume || true - -docker run -tid --rm -v ps-volume:/var/www/html --name temp-ps prestashop/prestashop:$PS_VERSION - -# Clear previous instance of the module in the PrestaShop volume -echo "Clear previous module" - -docker exec -t temp-ps rm -rf /var/www/html/modules/psgdpr - -# Run a container for PHPStan, having access to the module content and PrestaShop sources. -# This tool is outside the composer.json because of the compatibility with PHP 5.6 -echo "Run PHPStan using phpstan-${PS_VERSION}.neon file" - -docker run --rm --volumes-from temp-ps \ - -v $PWD:/var/www/html/modules/psgdpr \ - -e _PS_ROOT_DIR_=/var/www/html \ - --workdir=/var/www/html/modules/psgdpr ghcr.io/phpstan/phpstan \ - analyse \ - --configuration=/var/www/html/modules/psgdpr/tests/phpstan/phpstan-$PS_VERSION.neon diff --git a/tests/phpstan/phpstan-8.1.7.neon b/tests/phpstan/phpstan-8.1.7.neon new file mode 100644 index 00000000..cde86899 --- /dev/null +++ b/tests/phpstan/phpstan-8.1.7.neon @@ -0,0 +1,6 @@ +includes: + - %currentWorkingDirectory%/tests/phpstan/phpstan.neon + +parameters: + ignoreErrors: + - '#Method psgdprFrontAjaxGdprModuleFrontController::display\(\) should return bool but (empty return statement found|return statement is missing)\.#' diff --git a/tests/phpstan/phpstan-8.2.x.neon b/tests/phpstan/phpstan-8.2.x.neon new file mode 100644 index 00000000..cde86899 --- /dev/null +++ b/tests/phpstan/phpstan-8.2.x.neon @@ -0,0 +1,6 @@ +includes: + - %currentWorkingDirectory%/tests/phpstan/phpstan.neon + +parameters: + ignoreErrors: + - '#Method psgdprFrontAjaxGdprModuleFrontController::display\(\) should return bool but (empty return statement found|return statement is missing)\.#' diff --git a/tests/phpstan/phpstan-9.1.x.neon b/tests/phpstan/phpstan-9.1.x.neon new file mode 100644 index 00000000..be1fde76 --- /dev/null +++ b/tests/phpstan/phpstan-9.1.x.neon @@ -0,0 +1,13 @@ +includes: + - %currentWorkingDirectory%/tests/phpstan/phpstan.neon + +parameters: + ignoreErrors: + - '#Strict comparison using === between null and mixed will always evaluate to false\.#' + - '#Call to method addJS\(\) on an unknown class PrestaShop\\PrestaShop\\Core\\Context\\LegacyControllerContext\.#' + - '#Call to method addCSS\(\) on an unknown class PrestaShop\\PrestaShop\\Core\\Context\\LegacyControllerContext\.#' + - '#Call to method getLanguages\(\) on an unknown class PrestaShop\\PrestaShop\\Core\\Context\\LegacyControllerContext\.#' + - '#Access to property \$php_self on an unknown class PrestaShop\\PrestaShop\\Core\\Context\\LegacyControllerContext\.#' + - '#Parameter \$request of method PrestaShop\\Module\\Psgdpr\\Controller\\Admin\\[a-zA-Z]+::[a-zA-Z]+\(\) has invalid type Symfony\\Component\\HttpFoundation\\Request\.#' + - '#Call to method getContent\(\) on an unknown class Symfony\\Component\\HttpFoundation\\Request\.#' + - '#Call to an undefined static method CartRule::getAllCustomerCartRules\(\)\.#' diff --git a/tests/phpstan/phpstan-develop.neon b/tests/phpstan/phpstan-develop.neon new file mode 100644 index 00000000..be1fde76 --- /dev/null +++ b/tests/phpstan/phpstan-develop.neon @@ -0,0 +1,13 @@ +includes: + - %currentWorkingDirectory%/tests/phpstan/phpstan.neon + +parameters: + ignoreErrors: + - '#Strict comparison using === between null and mixed will always evaluate to false\.#' + - '#Call to method addJS\(\) on an unknown class PrestaShop\\PrestaShop\\Core\\Context\\LegacyControllerContext\.#' + - '#Call to method addCSS\(\) on an unknown class PrestaShop\\PrestaShop\\Core\\Context\\LegacyControllerContext\.#' + - '#Call to method getLanguages\(\) on an unknown class PrestaShop\\PrestaShop\\Core\\Context\\LegacyControllerContext\.#' + - '#Access to property \$php_self on an unknown class PrestaShop\\PrestaShop\\Core\\Context\\LegacyControllerContext\.#' + - '#Parameter \$request of method PrestaShop\\Module\\Psgdpr\\Controller\\Admin\\[a-zA-Z]+::[a-zA-Z]+\(\) has invalid type Symfony\\Component\\HttpFoundation\\Request\.#' + - '#Call to method getContent\(\) on an unknown class Symfony\\Component\\HttpFoundation\\Request\.#' + - '#Call to an undefined static method CartRule::getAllCustomerCartRules\(\)\.#' diff --git a/tests/phpstan/phpstan.neon b/tests/phpstan/phpstan.neon index 4e63e794..6648e0fe 100644 --- a/tests/phpstan/phpstan.neon +++ b/tests/phpstan/phpstan.neon @@ -1,5 +1,3 @@ -includes: - - %currentWorkingDirectory%/vendor/prestashop/php-dev-tools/phpstan/ps-module-extension.neon parameters: paths: # From PHPStan 0.12, paths to check are relative to the neon file diff --git a/tests/phpstan/prepend-constants.php b/tests/phpstan/prepend-constants.php new file mode 100644 index 00000000..733689a6 --- /dev/null +++ b/tests/phpstan/prepend-constants.php @@ -0,0 +1,11 @@ +