Skip to content

Commit

Permalink
ObjectHelpers: fixed parsing static @methods [Closes #278]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 28, 2022
1 parent 0af4e3d commit 32091bb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Utils/ObjectHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static function strictCall(string $class, string $method, array $addition
} else {
$hint = self::getSuggestion(array_merge(
get_class_methods($class),
self::parseFullDoc(new \ReflectionClass($class), '~^[ \t*]*@method[ \t]+(?:\S+[ \t]+)??(\w+)\(~m'),
self::parseFullDoc(new \ReflectionClass($class), '~^[ \t*]*@method[ \t]+(?:static[ \t]+)?(?:\S+[ \t]+)??(\w+)\(~m'),
$additionalMethods
), $method);
throw new MemberAccessException("Call to undefined method $class::$method()" . ($hint ? ", did you mean $hint()?" : '.'));
Expand Down
15 changes: 15 additions & 0 deletions tests/Utils/SmartObject.undeclaredMethod.annotation.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class ParentClass

/**
* @method classB()
* @method int classC()
* @method static classS1()
* @method static int classS2()
*/
class ChildClass extends ParentClass
{
Expand All @@ -57,6 +60,18 @@ Assert::exception(function () use ($obj) {
$obj->classBX();
}, Nette\MemberAccessException::class, 'Call to undefined method ChildClass::classBX(), did you mean classB()?');

Assert::exception(function () use ($obj) {
$obj->classCX();
}, Nette\MemberAccessException::class, 'Call to undefined method ChildClass::classCX(), did you mean classC()?');

Assert::exception(function () use ($obj) {
$obj->classS1X();
}, Nette\MemberAccessException::class, 'Call to undefined method ChildClass::classS1X(), did you mean classS1()?');

Assert::exception(function () use ($obj) {
$obj->classS2X();
}, Nette\MemberAccessException::class, 'Call to undefined method ChildClass::classS2X(), did you mean classS2()?');

Assert::exception(function () use ($obj) {
$obj->classAX();
}, Nette\MemberAccessException::class, 'Call to undefined method ChildClass::classAX(), did you mean classA()?');
Expand Down

0 comments on commit 32091bb

Please sign in to comment.