Updated Rector to commit eb525ca9fe04a8bc074cf49b5cf25991014fff5f

eb525ca9fe [DeadCode] Skip Array Callable dynamic method using __CLASS__ with constructor (no default args) on RemoveUnusedPrivateMethodRector (#5774)
This commit is contained in:
Tomas Votruba 2024-03-28 08:14:50 +00:00
parent c23b2384d3
commit 30adaf3fc0
2 changed files with 21 additions and 9 deletions

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api * @api
* @var string * @var string
*/ */
public const PACKAGE_VERSION = '3e6a4923d463e2a2d104ac283dae04343ee2a2d0'; public const PACKAGE_VERSION = 'eb525ca9fe04a8bc074cf49b5cf25991014fff5f';
/** /**
* @api * @api
* @var string * @var string
*/ */
public const RELEASE_DATE = '2024-03-27 22:26:48'; public const RELEASE_DATE = '2024-03-28 15:12:20';
/** /**
* @var int * @var int
*/ */

View File

@ -7,6 +7,7 @@ use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Scalar\MagicConst\Class_;
use PhpParser\Node\Scalar\String_; use PhpParser\Node\Scalar\String_;
use PHPStan\Analyser\Scope; use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\ClassReflection;
@ -135,13 +136,14 @@ final class ArrayCallableMethodMatcher
return \in_array($fromFuncCallName, $functionNames, \true); return \in_array($fromFuncCallName, $functionNames, \true);
} }
/** /**
* @param \PhpParser\Node\Expr\ClassConstFetch|\PhpParser\Node\Scalar\MagicConst\Class_ $classContext
* @return \PHPStan\Type\MixedType|\PHPStan\Type\ObjectType * @return \PHPStan\Type\MixedType|\PHPStan\Type\ObjectType
*/ */
private function resolveClassConstFetchType(ClassConstFetch $classConstFetch, Scope $scope, ?string $classMethodName) private function resolveClassContextType($classContext, Scope $scope, ?string $classMethodName)
{ {
$classConstantReference = $this->valueResolver->getValue($classConstFetch); $classConstantReference = $this->valueResolver->getValue($classContext);
if ($classConstantReference === ObjectReference::STATIC) { if ($this->isRequiredClassReflectionResolution($classConstantReference)) {
$classReflection = $this->reflectionResolver->resolveClassReflection($classConstFetch); $classReflection = $this->reflectionResolver->resolveClassReflection($classContext);
if (!$classReflection instanceof ClassReflection || !$classReflection->isClass()) { if (!$classReflection instanceof ClassReflection || !$classReflection->isClass()) {
return new MixedType(); return new MixedType();
} }
@ -173,9 +175,9 @@ final class ArrayCallableMethodMatcher
} }
private function resolveCallerType(Expr $expr, Scope $scope, ?string $classMethodName) : Type private function resolveCallerType(Expr $expr, Scope $scope, ?string $classMethodName) : Type
{ {
if ($expr instanceof ClassConstFetch) { if ($expr instanceof ClassConstFetch || $expr instanceof Class_) {
// static ::class reference? // class context means self|static ::class or __CLASS__
$callerType = $this->resolveClassConstFetchType($expr, $scope, $classMethodName); $callerType = $this->resolveClassContextType($expr, $scope, $classMethodName);
} else { } else {
$callerType = $this->nodeTypeResolver->getType($expr); $callerType = $this->nodeTypeResolver->getType($expr);
} }
@ -184,4 +186,14 @@ final class ArrayCallableMethodMatcher
} }
return $callerType; return $callerType;
} }
private function isRequiredClassReflectionResolution(string $classConstantReference) : bool
{
if ($classConstantReference === ObjectReference::STATIC) {
return \true;
}
if ($classConstantReference === '__CLASS__') {
return \true;
}
return \false;
}
} }