mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-14 12:32:00 +02:00
Updated Rector to commit 7e2495e5f572bb566a845a0e1a6329cf141f872d
7e2495e5f5
[Php70] Skip inside Encapsed on ThisCallOnStaticMethodToStaticCallRector (#5481)
This commit is contained in:
parent
bc96a99895
commit
6cacf30624
@ -8,7 +8,9 @@ use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Scalar\Encapsed;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use PHPStan\Reflection\Php\PhpMethodReflection;
|
||||
@ -36,6 +38,10 @@ final class ThisCallOnStaticMethodToStaticCallRector extends AbstractScopeAwareR
|
||||
* @var \Rector\Reflection\ReflectionResolver
|
||||
*/
|
||||
private $reflectionResolver;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $hasChanged = \false;
|
||||
public function __construct(StaticAnalyzer $staticAnalyzer, ReflectionResolver $reflectionResolver)
|
||||
{
|
||||
$this->staticAnalyzer = $staticAnalyzer;
|
||||
@ -95,8 +101,19 @@ CODE_SAMPLE
|
||||
if ($classReflection->isSubclassOf('PHPUnit\\Framework\\TestCase')) {
|
||||
return null;
|
||||
}
|
||||
$hasChanged = \false;
|
||||
$this->traverseNodesWithCallable($node, function (Node $subNode) use($node, $classReflection, &$hasChanged) : ?StaticCall {
|
||||
$this->hasChanged = \false;
|
||||
$this->processThisToStatic($node, $classReflection);
|
||||
if ($this->hasChanged) {
|
||||
return $node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private function processThisToStatic(Class_ $class, ClassReflection $classReflection) : void
|
||||
{
|
||||
$this->traverseNodesWithCallable($class, function (Node $subNode) use($class, $classReflection) {
|
||||
if ($subNode instanceof Encapsed) {
|
||||
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
|
||||
}
|
||||
if (!$subNode instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
@ -113,21 +130,17 @@ CODE_SAMPLE
|
||||
if ($methodName === null) {
|
||||
return null;
|
||||
}
|
||||
$isStaticMethod = $this->staticAnalyzer->isStaticMethod($classReflection, $methodName, $node);
|
||||
$isStaticMethod = $this->staticAnalyzer->isStaticMethod($classReflection, $methodName, $class);
|
||||
if (!$isStaticMethod) {
|
||||
return null;
|
||||
}
|
||||
if ($subNode->isFirstClassCallable()) {
|
||||
return null;
|
||||
}
|
||||
$hasChanged = \true;
|
||||
$this->hasChanged = \true;
|
||||
$objectReference = $this->resolveClassSelf($classReflection, $subNode);
|
||||
return $this->nodeFactory->createStaticCall($objectReference, $methodName, $subNode->args);
|
||||
});
|
||||
if ($hasChanged) {
|
||||
return $node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @return ObjectReference::STATIC|ObjectReference::SELF
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '0.19.2';
|
||||
public const PACKAGE_VERSION = '7e2495e5f572bb566a845a0e1a6329cf141f872d';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2024-01-18 21:39:30';
|
||||
public const RELEASE_DATE = '2024-01-19 21:03:24';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user