Skip to content

Fix false positives in ShouldCallParentMethodsRule - #355

Merged
staabm merged 2 commits into
phpstan:2.1.xfrom
staabm:should
Nov 13, 2026
Merged

staabm merged 2 commits into
phpstan:2.1.xfrom
staabm:should

Conversation

@staabm

@staabm staabm commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

get rid of some false-positives before we start auto-fixing

@staabm
staabm marked this pull request as ready for review November 13, 2026 10:17
@staabm
staabm requested review from VincentLanglet and a balanced review from Copilot November 13, 2026 10:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The recursive search incorrectly treats first-class callable creation as an executed parent call, suppressing the missing-call diagnostic even when parent setup never runs.

1 open issue
What changed in this PR

This PR reduces false positives in ShouldCallParentMethodsRule by recognizing parent lifecycle calls nested inside control-flow statements.

Changes:

  • Replaces the top-level scan with recursive traversal, excluding nested functions and classes.
  • Adds fixtures for conditionals, try/catch/finally blocks, closures, and anonymous classes.
  • Updates expected diagnostics for methods whose parent calls occur only in nested scopes.
File Description
tests/​Rules/​PHPUnit/​ShouldCallParentMethodsRuleTest.php Adds expected missing-parent-call diagnostics.
tests/​Rules/​PHPUnit/​data/​missing-parent-method-calls.php Adds control-flow and nested-scope regression cases.
src/​Rules/​PHPUnit/​ShouldCallParentMethodsRule.php Recursively detects parent calls while skipping nested scopes.

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block approval of the parent lifecycle-call detection changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@staabm
staabm merged commit f5e4a5b into phpstan:2.1.x Nov 13, 2026
113 checks passed
@staabm
staabm deleted the should branch November 13, 2026 10:29
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.

3 participants