Skip to content

Stop counting resets in test code or in closures as clearing a static - #37

Merged
austinderrick merged 2 commits into
mainfrom
fix-test-and-closure-resets
Nov 13, 2026
Merged

austinderrick merged 2 commits into
mainfrom
fix-test-and-closure-resets

Conversation

@austinderrick

Copy link
Copy Markdown
Collaborator

A reset that never runs in a production worker no longer counts as clearing a static:

  • a plugin's resetWorkerState() or a terminating()/RequestReceived listener in test code;
  • a write or call inside a closure that reset code defines, since the closure runs later, if ever.

Before this, such code hid a real leak: request code could fill a production static that only a test plugin cleared, and the rule reported nothing.

Testing

  • New fixtures (phpstan/fixtures/tests/TestResetPlugin.php and a closure in FixturePlugin::resetWorkerState()) cover each case. All four fail against main's rule code and pass with this change.
  • tests/PHPStanRulesTest.php reports exactly the 25 expected lines; PHPStan level 8 (without Larastan) and PHPCS are clean.
  • On a large Winter application, the change adds no findings.

A plugin's resetWorkerState() or request-boundary listener in test code never runs in a production worker, and a closure that reset code defines runs later, if ever. Writes and calls in either no longer mark a production static as cleared.

@github-actions github-actions Bot 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.

Tip

Verdict: APPROVED: no blocking concerns from this pass.

The changes close both false-negative paths: test-only listeners no longer contribute request-boundary edges, and calls inside closures no longer make their enclosing reset method appear to clear state. Excluding test and closure writes from reset recognition complements those call-graph changes.

The four new fixture cases cover direct writes and indirect calls, and the exact-error test now includes the test-directory fixtures. No blocking defects found in the diff.

Automated review of 4d9f554c1e5e52a82f5e8a86d17b1650de86971d by openai/gpt-6.1-sol via OpenRouter. Request a review to run it again.

@austinderrick
austinderrick merged commit 429eb6e into main Nov 13, 2026
9 checks passed
@austinderrick
austinderrick deleted the fix-test-and-closure-resets branch November 13, 2026 22:44
@austinderrick austinderrick mentioned this pull request Nov 13, 2026
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.

1 participant