Pin phpVersion on the 9.x PHPStan jobs and drop the AdminController cast helper - #143
Open
mattgoud wants to merge 1 commit into
Open
Pin phpVersion on the 9.x PHPStan jobs and drop the AdminController cast helper#143mattgoud wants to merge 1 commit into
mattgoud wants to merge 1 commit into
Conversation
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.
mattgoud
force-pushed
the
fix/phpstan-phpversion-9x
branch
from
September 9, 2026 16:13
72f642f to
f604def
Compare
This was referenced Sep 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
phpVersion: 80100on the four PrestaShop 9.x PHPStan configurations, and remove thegetAdminController()cast helper that existed only to work around the error caused by not pinning it.8.2.xones which are deliberately left untouched. Functionally, open Modules > Module Manager, search "Newsletter subscription", click Configure on both PrestaShop 8.2 and 9.x: the configuration page and its translatable fields must render and save exactly as before.The error the helper was hiding
The four 9.x configurations did not pin
phpVersion, so PHPStan took the syntax level from the composer platform declaration,7.1.0. At that level it cannot parsePrestaShop\PrestaShop\Core\Context\LegacyControllerContext, which uses constructor property promotion,readonlyand union types. Removing the helper without pinning anything produces three of these, at lines 1141, 1242 and 1281:Worth being precise about the message: it is an unknown class, not an undefined method on the
AdminController|FrontController|LegacyControllerContext|nullunion. The union is fine.getLanguages()exists onAdminControllerand onLegacyControllerContextalike, so the call has always been correct at runtime on both 8.2 and 9.x.The
@var AdminControllerannotation made the type resolvable again, which silenced the error without addressing its cause, and left a@return AdminControllerthat is untrue on 9.x, whereContext::$controllerholds aLegacyControllerContext.Measured
Locally against a PrestaShop 9.2.0 core, PHPStan 1.12.12, level 5, using the same
vendor/prestashop/php-dev-tools/phpstan/ps-module-extension.neonmerge the shared CI action performs.phpVersion: 80100plus helper removed9.0.3,9.1.5,9.2.xanddevelopWhy this is worth more than a tidier annotation
The same helper, with a native
: AdminControllerreturn type instead of a phpdoc, threw aTypeErroron the module configuration page ofps_wirepaymenton every PrestaShop 9.x shop, see PrestaShop/ps_wirepayment#103. This module was never affected, since PHP does not enforce a phpdoc. But the annotation is the same untruth, and it is exactly what makes a wrong assumption look verified to static analysis. PinningphpVersionremoves the reason to assert it at all.What is deliberately not in this PR
tests/php/phpstan/phpstan-8.2.x.neonis untouched.LegacyControllerContextdoes not exist on 8.2, where the union isAdminController|FrontController|LegacyControllerBridgeInterface|null, and that job runs on PHP 7.2, so pinning a PHP 8 syntax level there would be wrong.composer.jsonstill declaresrequire.php: >=7.1andconfig.platform.php: 7.1.0, whileps_versions_compliancyhas been at8.2.0since the alignment on [EPIC] Modules - Cleaning Compatibility PrestaShop#41648 and PrestaShop 8.2 requires PHP 7.2.5. Worth aligning on7.2.5, but it touchescomposer.lockand does not affect the issue fixed here, since 7.2.5 is still below the PHP 8.0 needed to parse the core class.tests/php/phpstan/phpstan.neoncarries text accidentally pasted from the GitHub review UI on its first comment line. Harmless, left out to keep this diff focused.