mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-19 14:59:46 +01:00
[MagicDisclosure] Skip getters (#3856)
This commit is contained in:
parent
20e28ea763
commit
8b42e67744
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\MagicDisclosure\Tests\Rector\MethodCall\DefluentMethodCallRector\Fixture;
|
||||
|
||||
use Rector\MagicDisclosure\Tests\Rector\MethodCall\DefluentMethodCallRector\Source\DifferentReturnValues;
|
||||
|
||||
class SkipGetterOnNew
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$differentReturnValues = (new DifferentReturnValues())->otherFunction();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user