diff --git a/rules/DeadCode/NodeAnalyzer/CallCollectionAnalyzer.php b/rules/DeadCode/NodeAnalyzer/CallCollectionAnalyzer.php index 62f62aaeb83..dc4758b48f8 100644 --- a/rules/DeadCode/NodeAnalyzer/CallCollectionAnalyzer.php +++ b/rules/DeadCode/NodeAnalyzer/CallCollectionAnalyzer.php @@ -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 { diff --git a/rules/DeadCode/NodeAnalyzer/IsClassMethodUsedAnalyzer.php b/rules/DeadCode/NodeAnalyzer/IsClassMethodUsedAnalyzer.php index 5356cee668e..ec3af1051f3 100644 --- a/rules/DeadCode/NodeAnalyzer/IsClassMethodUsedAnalyzer.php +++ b/rules/DeadCode/NodeAnalyzer/IsClassMethodUsedAnalyzer.php @@ -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) { diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 2e4d0eb27f5..75ff5e466c2 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -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 */