[CodeQuality] Skip NarrowUnusedSetUpDefinedPropertyRector for property used in nested closure#693
Merged
Conversation
…y used in nested closure The rule turned a setUp() property into a local variable while rewriting every $this->property reference inside setUp(), including references inside nested closures (e.g. resolver callbacks stored for later execution). A closure does not capture the local variable (no 'use' binding is added), so at call time the variable was undefined and the closure silently returned null. Skip narrowing when the property is referenced inside a Closure or ArrowFunction within setUp().
…property used in nested closure
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.
Bug
NarrowUnusedSetUpDefinedPropertyRectorturns a property only used insetUp()into a local variable. While doing so it rewrites every
$this->propertyreference inside
setUp()to a bare$propertyvariable — including referencesinside nested closures stored for later execution (resolver callbacks, deferred
factories, etc.).
A closure does not capture that local variable (the rule adds no
use ($property)binding), so when the closure runs after
setUp()the variable is undefined andthe closure silently returns
null.Found in webonyx/graphql-php
(
DeferredFieldsTest), whoserector.phpskips this rule. A resolver closure:The rewrite made the deferred resolvers return
null, breaking the tests(verified: 3 failures with
zend.assertions=1, gone after the fix, full suiteotherwise unchanged).
Fix
Skip narrowing a property when it is referenced inside a
ClosureorArrowFunctionwithinsetUp(). Addedskip_property_used_in_closure.php.inc.