From 4167237eaf89541aa24b7a84dc76b8b67cd887eb Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 2 Mar 2026 00:20:40 -0600 Subject: [PATCH] fix for test --- src/Checks/CallableCheck.php | 6 ++--- tests/units/Checks/TestCallableCheck.php | 30 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/Checks/CallableCheck.php b/src/Checks/CallableCheck.php index 4e49adef..492370dd 100644 --- a/src/Checks/CallableCheck.php +++ b/src/Checks/CallableCheck.php @@ -64,9 +64,9 @@ protected function checkArrayCallable($fileName, ?Scope $scope, ?ClassLike $insi if ($object instanceof Node\Scalar\String_) { // TODO: namespace resolution when resolving a callable string. Users should prefer [Foo::class,"Baz"] syntax. $this->checkClassType($object->value, $fileName, $callableArray); - } elseif ($object instanceof Node\Expr\StaticPropertyFetch) { - if ($object->class instanceof Node\Name && is_string($object->name) && $object->name == "class") { - $this->checkClassType($object->name, $fileName, $callableArray); + } elseif ($object instanceof Node\Expr\ClassConstFetch) { + if ($object->class instanceof Node\Name && strval($object->name) == "class") { + $this->checkClassType($object->class, $fileName, $callableArray); } } else { $classType = $object->getAttribute(TypeComparer::INFERRED_TYPE_ATTR); diff --git a/tests/units/Checks/TestCallableCheck.php b/tests/units/Checks/TestCallableCheck.php index 252230f5..05776492 100644 --- a/tests/units/Checks/TestCallableCheck.php +++ b/tests/units/Checks/TestCallableCheck.php @@ -187,4 +187,34 @@ public function testArrayCallableWithInferredType() { $check->run(__FILE__, $array, null, null); } + /** + * @return void + * @rapid-unit Checks:CallableCheck:Emits error when array callable with ClassConstFetch references undefined method + */ + public function testArrayCallableWithClassConstFetch() { + $output = $this->getMockBuilder(OutputInterface::class) + ->onlyMethods(['emitError']) + ->getMockForAbstractClass(); + + $output->expects($this->once()) + ->method('emitError') + ->with( + $this->anything(), + $this->anything(), + $this->anything(), + $this->anything(), + $this->stringContains("methodThatDoesNotExist") + ); + + $symbolTable = new InMemorySymbolTable(__DIR__); + $check = new CallableCheck($symbolTable, $output); + + $array = new Node\Expr\Array_([ + new Node\Expr\ArrayItem(new Node\Expr\ClassConstFetch(new Node\Name('Exception'), new Node\Identifier('class'))), + new Node\Expr\ArrayItem(new Node\Scalar\String_("methodThatDoesNotExist")) + ]); + + $check->run(__FILE__, $array, null, null); + + } }