1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fix #1427 - allow extended methods to be used as callables

This commit is contained in:
Brown 2019-03-05 18:02:42 -05:00
parent bd372e93af
commit cece1def30
2 changed files with 43 additions and 0 deletions

View File

@ -1027,6 +1027,12 @@ class TypeAnalyzer
}
try {
$method_id = $codebase->methods->getDeclaringMethodId($method_id);
if (!$method_id) {
return false;
}
$codebase->methods->getStorage($method_id);
} catch (\Exception $e) {
return false;

View File

@ -757,6 +757,30 @@ class CallableTest extends TestCase
}
}'
],
'publicCallableFromInside' => [
'<?php
class Base {
public function publicMethod() : void {}
}
class Example extends Base {
public function test() : Closure {
return Closure::fromCallable([$this, "publicMethod"]);
}
}',
],
'protectedCallableFromInside' => [
'<?php
class Base {
protected function protectedMethod() : void {}
}
class Example extends Base {
public function test() : Closure {
return Closure::fromCallable([$this, "protectedMethod"]);
}
}',
],
];
}
@ -1234,6 +1258,19 @@ class CallableTest extends TestCase
array_map(["two", "three"], ["one", "two"]);',
'error_message' => 'InvalidArgument'
],
'privateCallable' => [
'<?php
class Base {
private function privateMethod() : void {}
}
class Example extends Base {
public function test() : Closure {
return Closure::fromCallable([$this, "privateMethod"]);
}
}',
'InvalidArgument',
],
];
}
}