[Php70] Skip class has __callStatic() on StaticCallOnNonStaticToInstanceCallRector (#555)

This commit is contained in:
Abdul Malik Ikhsan 2021-07-31 18:41:13 +07:00 committed by GitHub
parent 057c5e6853
commit 1b113a0c93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,13 @@
<?php
namespace Rector\Tests\Php70\Rector\StaticCall\StaticCallOnNonStaticToInstanceCallRector\Fixture;
use Rector\Tests\Php70\Rector\StaticCall\StaticCallOnNonStaticToInstanceCallRector\Source\Service;
class SkipCallStatic
{
public function run()
{
return Service::getAlbum();
}
}

View File

@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Rector\Tests\Php70\Rector\StaticCall\StaticCallOnNonStaticToInstanceCallRector\Source;
use stdClass;
class Service
{
public static function __callStatic($name, $arguments)
{
return Other::$name($arguments);
}
}
class Other
{
public static function getAlbum()
{
return new stdClass;
}
}

View File

@ -10,9 +10,11 @@ use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticCall;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\NodeCollector\ScopeResolver\ParentClassScopeResolver;
use Rector\NodeCollector\StaticAnalyzer;
use ReflectionMethod;
@ -29,6 +31,7 @@ final class StaticCallOnNonStaticToInstanceCallRector extends AbstractRector
public function __construct(
private StaticAnalyzer $staticAnalyzer,
private ReflectionProvider $reflectionProvider,
private ReflectionResolver $reflectionResolver,
private ParentClassScopeResolver $parentClassScopeResolver
) {
}
@ -149,6 +152,11 @@ CODE_SAMPLE
return false;
}
$methodReflection = $this->reflectionResolver->resolveMethodReflection($className, '__callStatic', null);
if ($methodReflection instanceof MethodReflection) {
return false;
}
$classReflection = $this->reflectionProvider->getClass($className);
$reflectionClass = $classReflection->getNativeReflection();