Skip to content

Commit 5214cbe

Browse files
authored
Merge pull request #37 from artemmolotov/fix-checking-method-in-isStaticCallToNonStaticMethod
Check "static" callable for method existing in CallableResolver
2 parents 96fb9c2 + eadd74c commit 5214cbe

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/CallableResolver.php

+5
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ private function isStaticCallToNonStaticMethod($callable): bool
109109
{
110110
if (is_array($callable) && is_string($callable[0])) {
111111
[$class, $method] = $callable;
112+
113+
if (! method_exists($class, $method)) {
114+
return false;
115+
}
116+
112117
$reflection = new ReflectionMethod($class, $method);
113118

114119
return ! $reflection->isStatic();

tests/InvokerTest.php

+25
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ public function cannot_invoke_magic_method()
7373
$this->invoker->call([new InvokerTestMagicMethodFixture, 'foo']);
7474
}
7575

76+
/**
77+
* @test
78+
*/
79+
public function cannot_invoke_static_magic_method()
80+
{
81+
$this->expectExceptionMessage('Invoker\Test\InvokerTestStaticMagicMethodFixture::foo() is not a callable. A __call() or __callStatic() method exists but magic methods are not supported.');
82+
$this->expectException(NotCallableException::class);
83+
$this->invoker->call([InvokerTestStaticMagicMethodFixture::class, 'foo']);
84+
}
85+
7686
/**
7787
* @test
7888
*/
@@ -503,3 +513,18 @@ public function __call(string $name, array $args): string
503513
throw new Exception('Unknown method');
504514
}
505515
}
516+
517+
class InvokerTestStaticMagicMethodFixture
518+
{
519+
/** @var bool */
520+
public static $wasCalled = false;
521+
public static function __callStatic(string $name, array $args): string
522+
{
523+
if ($name === 'foo') {
524+
static::$wasCalled = true;
525+
return 'bar';
526+
}
527+
throw new Exception('Unknown method');
528+
}
529+
}
530+

0 commit comments

Comments
 (0)