Updated PHPStan to 2.2.6 and fixed the new unnecessary null-coalesce errors - #1159
Merged
Conversation
PHPStan 2.2.6 adds the nullCoalesce.unnecessary check, which flags "?? null" on an expression that is always set. Five call sites tripped it: - Mage_Admin_Model_Session::login() initializes $user to null before the try block instead of relying on "?? null" after it, keeping the guard against a throw before the assignment explicit rather than inferred. - The datetime column renderer, the payment restriction condition and Mage_Sales_Helper_Guest drop a no-op "?? null": explode() always yields index 0 and $_rule defaults to null. The guard on $cookieData[1] stays. - Maho_Ai_Helper_Data::submitTask() defaults a missing message role to '' rather than null. The parameter is a plain array at runtime, so the fallback has to stay or a malformed payload would silently skip the prompt-injection check. Also picks up maho-phpstan-plugin v4.3.0, which implements the method ExtendedMethodReflection gained in PHPStan 2.2.6; without it every analysis run fatals.
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.
Updating PHPStan to 2.2.6 broke
composer lint:phpstanin two ways.The fatal
PHPStan 2.2.6 added
getPureUnlessCallableIsImpureParameters()toExtendedMethodReflection.maho-phpstan-plugin'sPublicMethodReflectiondid not implement it, so every run died as soon as that class was autoloaded — which happens viaBindThisScopeResolverExtension, i.e. any phtml template or install script calling a protected method on$this:Fixed upstream in MahoCommerce/maho-phpstan-plugin#28 and released as v4.3.0, which this lockfile picks up.
The new check
2.2.6 also adds
nullCoalesce.unnecessary, which flags?? nullon an expression that is always set. Five call sites tripped it:Mage_Admin_Model_Session::login()— initialize$user = nullbefore thetryand return it directly. PHPStan considers the variable always set after the block, but only because it treatsgetModel()as a non-throw point;Mage::throwException()from an invalid model would leave$userundefined at runtime. Initializing up front makes the guard explicit instead of inferred, so the behaviour does not depend on that inference being right.Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Datetime,Mage_Payment_Model_Restriction_Rule_Condition_Product::getRule(),Mage_Sales_Helper_Guest::_loadOrderByCookie()— drop a genuine no-op?? null:explode()always yields index 0, and an untyped$_ruleproperty already defaults to null. The?? nullon$cookieData[1]stays, since that index really can be missing.Maho_Ai_Helper_Data::submitTask()— default a missing message role to''rather thannull. PHPStan trusts thearray{role: string, ...}docblock, but the parameter is a plainarrayat runtime, so the fallback has to stay: dropping it would let a payload withoutrolesilently skip the prompt-injection check, which is exactly the bypass that guard exists to close.Verification
composer lintis clean: PHPStan 5261/5261 with no errors, php-cs-fixer 0 of 4769 fixable, Rector OK.Note
Developed with the help of AI.
As part of our commitment to GenAI transparency, we flag pull requests produced with AI assistance alongside human work. As with every change in Maho, a maintainer reviews and validates it before merge, we never merge purely AI-generated changes. See the GenAI transparency section for details.