diff --git a/rules/magic-disclosure/src/Rector/MethodCall/DefluentMethodCallRector.php b/rules/magic-disclosure/src/Rector/MethodCall/DefluentMethodCallRector.php index c75e45c32d9..ff888ffc0c3 100644 --- a/rules/magic-disclosure/src/Rector/MethodCall/DefluentMethodCallRector.php +++ b/rules/magic-disclosure/src/Rector/MethodCall/DefluentMethodCallRector.php @@ -94,7 +94,12 @@ PHP return null; } + if ($this->isGetterMethodCall($methodCall)) { + return null; + } + $chainMethodCalls = $this->chainMethodCallNodeAnalyzer->collectAllMethodCallsInChain($methodCall); + $assignAndRootExpr = $this->chainMethodCallRootExtractor->extractFromMethodCalls($chainMethodCalls); if ($assignAndRootExpr === null) { return null; @@ -222,4 +227,16 @@ PHP return $nodesToAdd; } + + private function isGetterMethodCall(MethodCall $methodCall): bool + { + if ($methodCall->var instanceof MethodCall) { + return false; + } + $methodCallStaticType = $this->getStaticType($methodCall); + $methodCallVarStaticType = $this->getStaticType($methodCall->var); + + // getter short call type + return ! $methodCallStaticType->equals($methodCallVarStaticType); + } } diff --git a/rules/magic-disclosure/tests/Rector/MethodCall/DefluentMethodCallRector/Fixture/skip_getter_on_new.php.inc b/rules/magic-disclosure/tests/Rector/MethodCall/DefluentMethodCallRector/Fixture/skip_getter_on_new.php.inc new file mode 100644 index 00000000000..32f7bd164e7 --- /dev/null +++ b/rules/magic-disclosure/tests/Rector/MethodCall/DefluentMethodCallRector/Fixture/skip_getter_on_new.php.inc @@ -0,0 +1,13 @@ +otherFunction(); + } +}