Skip to content

Commit 1613b9f

Browse files
committed
Fix ClassRegistryInit doesn't work with ClassConstFetch AST
1 parent 37da253 commit 1613b9f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/ClassRegistryInitExtension.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace PHPStanCakePHP2;
66

7+
use PhpParser\Node\Expr\ClassConstFetch;
8+
use PhpParser\Node\Name;
79
use PHPStanCakePHP2\Service\SchemaService;
810
use Inflector;
911
use PhpParser\ConstExprEvaluator;
@@ -44,9 +46,15 @@ public function isStaticMethodSupported(MethodReflection $methodReflection): boo
4446

4547
public function getTypeFromStaticMethodCall(MethodReflection $methodReflection, StaticCall $methodCall, Scope $scope): ?Type
4648
{
47-
$arg1 = $methodCall->getArgs()[0]->value;
49+
$value = $methodCall->getArgs()[0]->value;
4850
$evaluator = new ConstExprEvaluator();
49-
$arg1 = $evaluator->evaluateSilently($arg1);
51+
52+
if ($value instanceof ClassConstFetch && $value->class instanceof Name) {
53+
$value = $value->class->toString();
54+
}
55+
56+
$arg1 = $evaluator->evaluateSilently($value);
57+
5058
if (! is_string($arg1)) {
5159
return $this->getDefaultType();
5260
}

tests/Feature/data/class_registry_init.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@
1212

1313
$modelWithoutClass = ClassRegistry::init('TableWithoutModel');
1414
assertType('Model', $modelWithoutClass);
15+
16+
$class = ClassRegistry::init(BasicModel::class);
17+
assertType('BasicModel', $class);

0 commit comments

Comments
 (0)