Skip to content

Extract the shared parameter-out type comparison into ParameterOutTypeCheck - #6238

Merged
staabm merged 1 commit into
phpstan:2.2.xfrom
SanderMuller:parameter-out-type-check
Aug 18, 2026
Merged

Extract the shared parameter-out type comparison into ParameterOutTypeCheck#6238
staabm merged 1 commit into
phpstan:2.2.xfrom
SanderMuller:parameter-out-type-check

Conversation

@SanderMuller

Copy link
Copy Markdown
Contributor

Split out of #6227 as requested in #6227 (comment). Pure refactoring, no functional change.

ParameterOutAssignedTypeRule and ParameterOutExecutionEndTypeRule both compare what a by-ref parameter is left holding against the type its callers are promised, and both build the same message out of it. The execution-end rule is the assigned-value rule with @param-out known to be present, so its message is what the other one produces when $isParamOutType is true - identical string, identical paramOut.type identifier, and no tip either way.

The comparison, the level-dependent findTypeToCheck() filtering, the function description and the message now live in ParameterOutTypeCheck. Each rule keeps only what is its own: finding the parameter that the assignment writes to, and walking the parameters at an execution end.

Evidence that nothing changed:

  • Both rule tests keep their expectations untouched - the only diff in tests/ is new ParameterOutTypeCheck(...) wrapping the RuleLevelHelper.
  • Full suite: 21325 tests, 96906 assertions, green.
  • Self-analysis (build/phpstan.neon) reports no errors, phpcs is clean on the five touched files.

Once this is in I will rebase #6227 on top of it, so that PR is left with just the variadic element-type comparison.

…eCheck

ParameterOutAssignedTypeRule and ParameterOutExecutionEndTypeRule both compare
what a by-ref parameter is left holding against the type its callers are
promised, and both build the same message from it - the execution-end rule is
the assigned-value rule with @param-out known to be present. The comparison,
the level-dependent filtering, the function description and the message now
live in one place.

No behaviour change: the messages, identifiers and the tip are unchanged, and
both rule tests keep their expectations - only how the rule is constructed
differs.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

@staabm staabm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you

@staabm
staabm merged commit 9e4cf9d into phpstan:2.2.x Aug 18, 2026
755 of 758 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants