diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 80364fd..6895995 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -4,21 +4,12 @@ on: [push, pull_request] jobs: # Check there is no syntax errors in the project php-linter: - name: PHP Syntax check 5.6 => 8.2 + name: PHP Syntax check 7.4 => 8.2 runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2.0.0 - - name: PHP syntax checker 5.6 - uses: prestashop/github-action-php-lint/5.6@master - - - name: PHP syntax checker 7.2 - uses: prestashop/github-action-php-lint/7.2@master - - - name: PHP syntax checker 7.3 - uses: prestashop/github-action-php-lint/7.3@master - - name: PHP syntax checker 7.4 uses: prestashop/github-action-php-lint/7.4@master @@ -56,38 +47,106 @@ jobs: - 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 - phpstan: - name: PHPStan + # Run PHPStan against the module (PHP 7.4 – PS 8.2) + phpstan-74-81: + name: PHPStan (PHP 7.4 - 8.1) runs-on: ubuntu-latest strategy: matrix: - presta-versions: ['1.7.7', '1.7.8', '8.0', 'latest'] + 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: Setup PHP - uses: shivammathur/setup-php@v2 + - name: Checkout repository + uses: actions/checkout@v6 with: - php-version: '7.4' - - - name: Checkout - uses: actions/checkout@v2.0.0 - - # Add vendor folder in cache to make next builds faster - - name: Cache vendor folder - uses: actions/cache@v4 + 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: - 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@v4 + 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.4) + phpstan-81-84: + name: PHPStan (PHP 8.1 - 8.4) + runs-on: ubuntu-latest + strategy: + matrix: + presta_version: ['9.0.3'] + php_version: ['8.1', '8.4'] + 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 - - - run: composer install + path: ${{ github.event.repository.name }} + + - 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/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 - # 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 }} + # 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: ${{ github.event.repository.name }} + + - 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/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 diff --git a/dashactivity.php b/dashactivity.php index c9746a1..d72ce25 100755 --- a/dashactivity.php +++ b/dashactivity.php @@ -149,7 +149,19 @@ public function hookDashboardData($params) extract($row); if ($maintenance_ips = Configuration::get('PS_MAINTENANCE_IP')) { - $maintenance_ips = implode(',', array_filter(array_map('ip2long', array_map('trim', explode(',', $maintenance_ips))), '\strlen')); + $maintenance_ips = implode( + ',', + array_filter( + array_map( + 'ip2long', + array_map( + 'trim', + explode(',', $maintenance_ips) + ) + ), + static fn ($item) => (string) $item !== '' + ) + ); } if (Configuration::get('PS_STATSDATA_CUSTOMER_PAGESVIEWS')) { $sql = 'SELECT c.id_guest, c.ip_address, c.date_add, c.http_referer, pt.name as page diff --git a/tests/phpstan/index.php b/tests/php/index.php similarity index 100% rename from tests/phpstan/index.php rename to tests/php/index.php diff --git a/tests/php/phpstan/index.php b/tests/php/phpstan/index.php new file mode 100644 index 0000000..45df26c --- /dev/null +++ b/tests/php/phpstan/index.php @@ -0,0 +1,34 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + */ +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 0000000..a5ad764 --- /dev/null +++ b/tests/php/phpstan/phpstan-8.2.x.neon @@ -0,0 +1,5 @@ +includes: + - %currentWorkingDirectory%/tests/php/phpstan/phpstan.neon + +parameters: + ignoreErrors: 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 0000000..481ff9f --- /dev/null +++ b/tests/php/phpstan/phpstan-9.0.3.neon @@ -0,0 +1,2 @@ +includes: + - %currentWorkingDirectory%/tests/php/phpstan/phpstan.neon \ No newline at end of file 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 0000000..481ff9f --- /dev/null +++ b/tests/php/phpstan/phpstan-9.1.x.neon @@ -0,0 +1,2 @@ +includes: + - %currentWorkingDirectory%/tests/php/phpstan/phpstan.neon \ No newline at end of file diff --git a/tests/php/phpstan/phpstan-develop.neon b/tests/php/phpstan/phpstan-develop.neon new file mode 100644 index 0000000..f75ac74 --- /dev/null +++ b/tests/php/phpstan/phpstan-develop.neon @@ -0,0 +1,3 @@ +includes: + - %currentWorkingDirectory%/tests/php/phpstan/phpstan.neon + diff --git a/tests/php/phpstan/phpstan.neon b/tests/php/phpstan/phpstan.neon new file mode 100644 index 0000000..018ab98 --- /dev/null +++ b/tests/php/phpstan/phpstan.neon @@ -0,0 +1,2 @@ + # Base PHPStan configuration for the module + # 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 0000000..733689a --- /dev/null +++ b/tests/php/phpstan/prepend-constants.php @@ -0,0 +1,11 @@ +