[MagicDisclosure] Skip getters (#3856)

This commit is contained in:
Tomas Votruba 2020-08-01 02:01:52 +02:00 committed by GitHub
parent 20e28ea763
commit 8b42e67744
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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();
}
}