Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 81 additions & 47 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -1,13 +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.2 => 8.2
name: PHP Syntax check 7.2 => 8.5
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3.1.0
uses: actions/checkout@v6

- name: PHP syntax checker 7.2
uses: prestashop/github-action-php-lint/7.2@master
Expand All @@ -27,63 +26,98 @@ jobs:
- 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
Comment thread
cnavarro-prestashop marked this conversation as resolved.
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.2 – 8.1)
phpstan-74:
Comment thread
cnavarro-prestashop marked this conversation as resolved.
name: PHPStan (PHP 7.2 - 8.1)
runs-on: ubuntu-latest
strategy:
matrix:
presta_version: ['8.2.x']
php_version: ['7.2', '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

# 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
- name: Checkout repository
uses: actions/checkout@v6
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
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
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>pagesnotfound</name>
<displayName><![CDATA[Pages not found]]></displayName>
<version><![CDATA[3.0.0]]></version>
<version><![CDATA[4.0.0]]></version>
<description><![CDATA[Displays the pages requested by your visitors that have not been found.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[analytics_stats]]></tab>
Expand Down
15 changes: 8 additions & 7 deletions pagesnotfound.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public function __construct()
{
$this->name = 'pagesnotfound';
$this->tab = 'administration';
$this->version = '3.0.0';
$this->version = '4.0.0';
$this->author = 'PrestaShop';
$this->need_instance = 0;

parent::__construct();

$this->displayName = $this->trans('Pages not found', [], 'Modules.Pagesnotfound.Admin');
$this->description = $this->trans('Enrich your stats, display the pages requested by your visitors that could not be found.', [], 'Modules.Pagesnotfound.Admin');
$this->ps_versions_compliancy = ['min' => '1.7.7', 'max' => _PS_VERSION_];
$this->ps_versions_compliancy = ['min' => '8.2.0', 'max' => _PS_VERSION_];
}

public function install()
Expand Down Expand Up @@ -75,19 +75,20 @@ private function getPages()
WHERE date_add BETWEEN ' . ModuleGraph::getDateBetween()
. Shop::addSqlRestriction() .
'GROUP BY http_referer, request_uri';
/** @var array<int, array{http_referer: string, request_uri: string, nb: int|string}> $result */
$result = Db::getInstance((bool) _PS_USE_SQL_SLAVE_)->executeS($sql);

$pages = [];
foreach ($result as $row) {
$row['http_referer'] = parse_url($row['http_referer'], PHP_URL_HOST) . parse_url($row['http_referer'], PHP_URL_PATH);
if (!isset($row['http_referer']) || empty($row['http_referer'])) {
$row['http_referer'] = '--';
$httpReferer = parse_url($row['http_referer'], PHP_URL_HOST) . parse_url($row['http_referer'], PHP_URL_PATH);
if (empty($httpReferer)) {
$httpReferer = '--';
}
if (!isset($pages[$row['request_uri']])) {
$pages[$row['request_uri']] = ['nb' => 0];
}
$pages[$row['request_uri']][$row['http_referer']] = $row['nb'];
$pages[$row['request_uri']]['nb'] += $row['nb'];
$pages[$row['request_uri']][$httpReferer] = (int) $row['nb'];
$pages[$row['request_uri']]['nb'] += (int) $row['nb'];
}
uasort($pages, 'pnfSort');

Expand Down
9 changes: 9 additions & 0 deletions tests/php/phpstan/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

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;
2 changes: 2 additions & 0 deletions tests/php/phpstan/phpstan-8.2.x.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
includes:
- %currentWorkingDirectory%/tests/php/phpstan/phpstan.neon
2 changes: 2 additions & 0 deletions tests/php/phpstan/phpstan-9.0.3.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
includes:
- %currentWorkingDirectory%/tests/php/phpstan/phpstan.neon
2 changes: 2 additions & 0 deletions tests/php/phpstan/phpstan-9.1.x.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
includes:
- %currentWorkingDirectory%/tests/php/phpstan/phpstan.neon
2 changes: 2 additions & 0 deletions tests/php/phpstan/phpstan-develop.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
includes:
- %currentWorkingDirectory%/tests/php/phpstan/phpstan.neon
2 changes: 2 additions & 0 deletions tests/php/phpstan/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Base PHPStan configuration for the module
# This file is included by version-specific configs
11 changes: 11 additions & 0 deletions tests/php/phpstan/prepend-constants.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
/**
* Defines constants required by PrestaShop config (e.g. defines_uri.inc.php) when running
* PHPStan outside a full request. Loaded via auto_prepend_file in CI for 9.x jobs.
*/
if (!defined('_THEME_NAME_')) {
define('_THEME_NAME_', 'classic');
}
if (!defined('__PS_BASE_URI__')) {
define('__PS_BASE_URI__', '/');
}
28 changes: 0 additions & 28 deletions tests/phpstan.sh

This file was deleted.

34 changes: 0 additions & 34 deletions tests/phpstan/index.php

This file was deleted.

2 changes: 0 additions & 2 deletions tests/phpstan/phpstan-1.7.7.neon

This file was deleted.

2 changes: 0 additions & 2 deletions tests/phpstan/phpstan-1.7.8.neon

This file was deleted.

2 changes: 0 additions & 2 deletions tests/phpstan/phpstan-8.0.neon

This file was deleted.

2 changes: 0 additions & 2 deletions tests/phpstan/phpstan-latest.neon

This file was deleted.

8 changes: 0 additions & 8 deletions tests/phpstan/phpstan.neon

This file was deleted.

Loading