From f604deff8f0535bbc20609f6aad0ce26f50d9c14 Mon Sep 17 00:00:00 2001 From: mattgoud Date: Wed, 9 Sep 2026 18:07:51 +0200 Subject: [PATCH] Pin phpVersion on the 9.x PHPStan jobs and drop the AdminController cast The four 9.x configurations did not pin phpVersion, so PHPStan analysed the PrestaShop 9.x core with the PHP version taken from the composer platform declaration, 7.1.0. At that syntax level it cannot parse LegacyControllerContext and reports it as an unknown class, which is the error getAdminController() was silencing with a @var AdminController that is untrue on 9.x. Pinning phpVersion: 80100 removes the cause, so the helper and its three call sites go back to the direct Context::$controller call. getLanguages() exists on AdminController and on LegacyControllerContext alike, so the call is correct at runtime on both 8.2 and 9.x. phpstan-8.2.x.neon is left untouched: LegacyControllerContext does not exist there and that job runs on PHP 7.2. --- ps_emailsubscription.php | 21 +++------------------ tests/php/phpstan/phpstan-9.0.3.neon | 6 ++++++ tests/php/phpstan/phpstan-9.1.5.neon | 6 ++++++ tests/php/phpstan/phpstan-9.2.x.neon | 6 ++++++ tests/php/phpstan/phpstan-develop.neon | 6 ++++++ 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/ps_emailsubscription.php b/ps_emailsubscription.php index 375734e..2b92863 100644 --- a/ps_emailsubscription.php +++ b/ps_emailsubscription.php @@ -952,21 +952,6 @@ public function hookActionFrontControllerSetMedia() $controller->registerJavascript('modules-psemailsubscription', 'modules/' . $this->name . '/views/js/ps_emailsubscription.js'); } - /** - * Returns the admin controller with a concrete type. Context::$controller is typed - * as the PHPStan-opaque LegacyControllerContext on PrestaShop 9.x, which prevents - * static resolution of legacy controller methods such as getLanguages(). - * - * @return AdminController - */ - private function getAdminController() - { - /** @var AdminController $controller */ - $controller = $this->context->controller; - - return $controller; - } - /** * Deletes duplicates email in newsletter table. * @@ -1153,7 +1138,7 @@ public function renderForm() $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars = [ 'fields_value' => $this->getConfigFieldsValues(), - 'languages' => $this->getAdminController()->getLanguages(), + 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id, ]; @@ -1254,7 +1239,7 @@ public function renderExportForm() $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars = [ 'fields_value' => $this->getConfigFieldsValues(), - 'languages' => $this->getAdminController()->getLanguages(), + 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id, ]; @@ -1293,7 +1278,7 @@ public function renderSearchForm() $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars = [ 'fields_value' => ['searched_email' => $this->_searched_email], - 'languages' => $this->getAdminController()->getLanguages(), + 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id, ]; diff --git a/tests/php/phpstan/phpstan-9.0.3.neon b/tests/php/phpstan/phpstan-9.0.3.neon index efa856c..a976397 100644 --- a/tests/php/phpstan/phpstan-9.0.3.neon +++ b/tests/php/phpstan/phpstan-9.0.3.neon @@ -1,2 +1,8 @@ includes: - %currentWorkingDirectory%/tests/php/phpstan/phpstan.neon + +parameters: + # PrestaShop 9 requires PHP 8.1 as a minimum. It has to be set explicitly because PHPStan + # otherwise infers the analysed PHP version from the composer platform declaration, and the + # resulting older syntax rules make it fail to parse the core classes the module relies on. + phpVersion: 80100 diff --git a/tests/php/phpstan/phpstan-9.1.5.neon b/tests/php/phpstan/phpstan-9.1.5.neon index efa856c..a976397 100644 --- a/tests/php/phpstan/phpstan-9.1.5.neon +++ b/tests/php/phpstan/phpstan-9.1.5.neon @@ -1,2 +1,8 @@ includes: - %currentWorkingDirectory%/tests/php/phpstan/phpstan.neon + +parameters: + # PrestaShop 9 requires PHP 8.1 as a minimum. It has to be set explicitly because PHPStan + # otherwise infers the analysed PHP version from the composer platform declaration, and the + # resulting older syntax rules make it fail to parse the core classes the module relies on. + phpVersion: 80100 diff --git a/tests/php/phpstan/phpstan-9.2.x.neon b/tests/php/phpstan/phpstan-9.2.x.neon index efa856c..a976397 100644 --- a/tests/php/phpstan/phpstan-9.2.x.neon +++ b/tests/php/phpstan/phpstan-9.2.x.neon @@ -1,2 +1,8 @@ includes: - %currentWorkingDirectory%/tests/php/phpstan/phpstan.neon + +parameters: + # PrestaShop 9 requires PHP 8.1 as a minimum. It has to be set explicitly because PHPStan + # otherwise infers the analysed PHP version from the composer platform declaration, and the + # resulting older syntax rules make it fail to parse the core classes the module relies on. + phpVersion: 80100 diff --git a/tests/php/phpstan/phpstan-develop.neon b/tests/php/phpstan/phpstan-develop.neon index efa856c..a976397 100644 --- a/tests/php/phpstan/phpstan-develop.neon +++ b/tests/php/phpstan/phpstan-develop.neon @@ -1,2 +1,8 @@ includes: - %currentWorkingDirectory%/tests/php/phpstan/phpstan.neon + +parameters: + # PrestaShop 9 requires PHP 8.1 as a minimum. It has to be set explicitly because PHPStan + # otherwise infers the analysed PHP version from the composer platform declaration, and the + # resulting older syntax rules make it fail to parse the core classes the module relies on. + phpVersion: 80100