diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 91d00a7..575e616 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -1,75 +1,84 @@ name: PHP tests on: [push, pull_request] jobs: - # Check there is no syntax errors in the project - php-linter: - name: PHP Syntax check 5.6|7.2|7.3 - 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 - - # 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.4' - - - name: Checkout - uses: actions/checkout@v2.0.0 - - - name: Cache dependencies - uses: actions/cache@v2 - 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 - phpstan: - name: PHPStan - runs-on: ubuntu-latest - strategy: - matrix: - presta-versions: ['1.7.6.9', 'latest'] - steps: - - 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@v1 - 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@v1 - 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/php/phpstan.sh ${{ matrix.presta-versions }} + # Check there is no syntax errors in the project + php-linter: + name: PHP Syntax check 5.6 => 8.1 + 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 + + - name: PHP syntax checker 8.0 + uses: prestashop/github-action-php-lint/8.0@master + + - name: PHP syntax checker 8.1 + uses: prestashop/github-action-php-lint/8.1@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.4' + + - name: Checkout + uses: actions/checkout@v2.0.0 + + - name: Cache dependencies + uses: actions/cache@v2 + 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 + phpstan: + name: PHPStan + runs-on: ubuntu-latest + strategy: + matrix: + presta-versions: ['1.7.6', '1.7.7', '1.7.8', 'latest'] + steps: + - 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@v1 + 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@v1 + 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/php/phpstan.sh ${{ matrix.presta-versions }} diff --git a/MailAlert.php b/MailAlert.php index 40e416d..24b2b66 100644 --- a/MailAlert.php +++ b/MailAlert.php @@ -78,7 +78,7 @@ public static function customerHasNotification($id_customer, $id_product, $id_pr AND `id_product_attribute` = ' . (int) $id_product_attribute . ' AND `id_shop` = ' . (int) $id_shop; - return count(Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql)); + return count(Db::getInstance((bool) _PS_USE_SQL_SLAVE_)->executeS($sql)); } public static function deleteAlert($id_customer, $customer_email, $id_product, $id_product_attribute, $id_shop = null) @@ -280,7 +280,7 @@ public static function getProducts($customer, $id_lang) AND (ma.`id_customer` = ' . (int) $customer->id . ' OR ma.`customer_email` = \'' . pSQL($customer->email) . '\') AND pl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestriction(false, 'ma'); - return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); + return Db::getInstance((bool) _PS_USE_SQL_SLAVE_)->executeS($sql); } /* @@ -299,7 +299,7 @@ public static function getProductAttributeCombination($id_product_attribute, $id ' . Shop::addSqlAssociation('product_attribute', 'pa') . ' WHERE pac.`id_product_attribute` = ' . (int) $id_product_attribute; - return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); + return Db::getInstance((bool) _PS_USE_SQL_SLAVE_)->executeS($sql); } /* @@ -312,6 +312,6 @@ public static function getCustomers($id_product, $id_product_attribute) FROM `' . _DB_PREFIX_ . self::$definition['table'] . '` WHERE `id_product` = ' . (int) $id_product . ' AND `id_product_attribute` = ' . (int) $id_product_attribute; - return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); + return Db::getInstance((bool) _PS_USE_SQL_SLAVE_)->executeS($sql); } } diff --git a/config.xml b/config.xml index 62d85d4..2eaf89b 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ ps_emailalerts - + diff --git a/ps_emailalerts.php b/ps_emailalerts.php index d3880ef..8280a87 100644 --- a/ps_emailalerts.php +++ b/ps_emailalerts.php @@ -61,7 +61,7 @@ public function __construct() { $this->name = 'ps_emailalerts'; $this->tab = 'administration'; - $this->version = '2.3.1'; + $this->version = '2.3.2'; $this->author = 'PrestaShop'; $this->need_instance = 0; @@ -292,12 +292,17 @@ public function getAllMessages($id) * * @param Context $context * - * @return \PrestaShop\PrestaShop\Core\Localization\Locale + * @return \PrestaShop\PrestaShop\Core\Localization\Locale|null * * @throws Exception */ public static function getContextLocale(Context $context) { + $locale = $context->getCurrentLocale(); + if (null !== $locale) { + return $locale; + } + $containerFinder = new \PrestaShop\PrestaShop\Adapter\ContainerFinder($context); $container = $containerFinder->getContainer(); if (null === $context->container) { diff --git a/tests/php/phpstan/phpstan-1.7.6.9.neon b/tests/php/phpstan/phpstan-1.7.6.neon similarity index 59% rename from tests/php/phpstan/phpstan-1.7.6.9.neon rename to tests/php/phpstan/phpstan-1.7.6.neon index 2de6113..f8072a4 100644 --- a/tests/php/phpstan/phpstan-1.7.6.9.neon +++ b/tests/php/phpstan/phpstan-1.7.6.neon @@ -3,5 +3,7 @@ includes: parameters: ignoreErrors: + - '~^Parameter #1 \$share of static method ShopCore::getContextListShopID\(\) expects string, false given\.$~' + - '~^Parameter #1 \$share of static method ShopCore::addSqlRestriction\(\) expects int, false given\.$~' - '~^Parameter #4 \$templateVars of static method MailCore::send\(\) expects string, array given\.$~' - '~^Parameter #1 \$id of class Customer constructor expects null, int given\.$~' diff --git a/tests/php/phpstan/phpstan-1.7.7.neon b/tests/php/phpstan/phpstan-1.7.7.neon new file mode 100644 index 0000000..09d3f95 --- /dev/null +++ b/tests/php/phpstan/phpstan-1.7.7.neon @@ -0,0 +1,7 @@ +includes: + - %currentWorkingDirectory%/tests/php/phpstan/phpstan.neon + +parameters: + ignoreErrors: + - '#Parameter \#1 \$share of static method ShopCore\:\:getContextListShopID\(\) expects string, false given.#' + - '#Parameter \#1 \$share of static method ShopCore\:\:addSqlRestriction\(\) expects int, false given.#' diff --git a/tests/php/phpstan/phpstan-1.7.8.neon b/tests/php/phpstan/phpstan-1.7.8.neon new file mode 100644 index 0000000..09d3f95 --- /dev/null +++ b/tests/php/phpstan/phpstan-1.7.8.neon @@ -0,0 +1,7 @@ +includes: + - %currentWorkingDirectory%/tests/php/phpstan/phpstan.neon + +parameters: + ignoreErrors: + - '#Parameter \#1 \$share of static method ShopCore\:\:getContextListShopID\(\) expects string, false given.#' + - '#Parameter \#1 \$share of static method ShopCore\:\:addSqlRestriction\(\) expects int, false given.#' diff --git a/tests/php/phpstan/phpstan-latest.neon b/tests/php/phpstan/phpstan-latest.neon index efa856c..09d3f95 100644 --- a/tests/php/phpstan/phpstan-latest.neon +++ b/tests/php/phpstan/phpstan-latest.neon @@ -1,2 +1,7 @@ includes: - %currentWorkingDirectory%/tests/php/phpstan/phpstan.neon + +parameters: + ignoreErrors: + - '#Parameter \#1 \$share of static method ShopCore\:\:getContextListShopID\(\) expects string, false given.#' + - '#Parameter \#1 \$share of static method ShopCore\:\:addSqlRestriction\(\) expects int, false given.#' diff --git a/tests/php/phpstan/phpstan.neon b/tests/php/phpstan/phpstan.neon index 2901cb8..77f1e14 100644 --- a/tests/php/phpstan/phpstan.neon +++ b/tests/php/phpstan/phpstan.neon @@ -11,6 +11,4 @@ parameters: reportUnmatchedIgnoredErrors: false level: 5 ignoreErrors: - - '~^Parameter #1 \$master of static method DbCore::getInstance\(\) expects bool, int given\.$~' - - '~^Parameter #1 \$share of static method ShopCore::getContextListShopID\(\) expects string, false given\.$~' - - '~^Parameter #1 \$share of static method ShopCore::addSqlRestriction\(\) expects int, false given\.$~' + - '#Unreachable statement \- code above always terminates\.#'