Updated Rector to commit 4cd2622ccbe9989cdf76a16aa6d282b5ba73adb0

4cd2622ccb Support NullSafeMethod calls in unused-code analysis (#5838)
This commit is contained in:
Tomas Votruba 2024-04-21 19:23:11 +00:00
parent 6cbc8ec497
commit 3e1d355024
3 changed files with 19 additions and 7 deletions

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\DeadCode\NodeAnalyzer;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\NullsafeMethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
@ -29,7 +30,7 @@ final class CallCollectionAnalyzer
$this->nodeNameResolver = $nodeNameResolver;
}
/**
* @param StaticCall[]|MethodCall[] $calls
* @param StaticCall[]|MethodCall[]|NullsafeMethodCall[] $calls
*/
public function isExists(array $calls, string $classMethodName, string $className) : bool
{
@ -52,14 +53,14 @@ final class CallCollectionAnalyzer
return \false;
}
/**
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $call
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\NullsafeMethodCall $call
*/
private function isSelfStatic($call) : bool
{
return $call instanceof StaticCall && $call->class instanceof Name && \in_array($call->class->toString(), [ObjectReference::SELF, ObjectReference::STATIC], \true);
}
/**
* @param \PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\MethodCall $call
* @param \PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\NullsafeMethodCall $call
*/
private function shouldSkip($call, string $classMethodName) : bool
{

View File

@ -88,11 +88,15 @@ final class IsClassMethodUsedAnalyzer
if ($this->isClassMethodCalledInLocalMethodCall($class, $classMethodName)) {
return \true;
}
// 2. direct static calls
// 2. direct null-safe calls
if ($this->isClassMethodCalledInLocalNullsafeMethodCall($class, $classMethodName)) {
return \true;
}
// 3. direct static calls
if ($this->isClassMethodUsedInLocalStaticCall($class, $classMethodName)) {
return \true;
}
// 3. magic array calls!
// 4. magic array calls!
if ($this->isClassMethodCalledInLocalArrayCall($class, $classMethod, $scope)) {
return \true;
}
@ -113,6 +117,13 @@ final class IsClassMethodUsedAnalyzer
$methodCalls = $this->betterNodeFinder->findInstanceOf($class, MethodCall::class);
return $this->callCollectionAnalyzer->isExists($methodCalls, $classMethodName, $className);
}
private function isClassMethodCalledInLocalNullsafeMethodCall(Class_ $class, string $classMethodName) : bool
{
$className = (string) $this->nodeNameResolver->getName($class);
/** @var Node\Expr\NullsafeMethodCall[] $methodCalls */
$methodCalls = $this->betterNodeFinder->findInstanceOf($class, Node\Expr\NullsafeMethodCall::class);
return $this->callCollectionAnalyzer->isExists($methodCalls, $classMethodName, $className);
}
private function isInArrayMap(Class_ $class, Array_ $array) : bool
{
if (!$array->getAttribute(ArrayMapArgVisitor::ATTRIBUTE_NAME) instanceof Arg) {

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '068799f59b289bef06b9c1f384df4301b19e726e';
public const PACKAGE_VERSION = '4cd2622ccbe9989cdf76a16aa6d282b5ba73adb0';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-04-21 02:27:01';
public const RELEASE_DATE = '2024-04-22 02:20:32';
/**
* @var int
*/