1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix #2363 - catch possible class not found errors when getting method

This commit is contained in:
Matthew Brown 2019-11-21 08:56:47 -05:00
parent c50a17d415
commit 3d9c94e29a
3 changed files with 38 additions and 1 deletions

View File

@ -1752,6 +1752,9 @@ class TypeAnalyzer
if ($lhs->isSingleStringLiteral()) {
$class_name = $lhs->getSingleStringLiteral()->value;
if ($class_name[0] === '\\') {
$class_name = substr($class_name, 1);
}
} elseif ($lhs->isSingle()) {
foreach ($lhs->getTypes() as $lhs_atomic_type) {
if ($lhs_atomic_type instanceof TNamedObject) {

View File

@ -913,7 +913,11 @@ class Methods
{
list($fq_class_name, $method_name) = explode('::', $method_id);
$class_storage = $this->classlike_storage_provider->get($fq_class_name);
try {
$class_storage = $this->classlike_storage_provider->get($fq_class_name);
} catch (\InvalidArgumentException $e) {
throw new \UnexpectedValueException($e->getMessage());
}
$method_name_lc = strtolower($method_name);

View File

@ -973,6 +973,18 @@ class CallableTest extends TestCase
}
}',
],
'noFatalErrorOnClassWithSlash' => [
'<?php
class Func {
public function __construct(string $name, callable $callable) {}
}
class Foo {
public static function bar(): string { return "asd"; }
}
new Func("f", ["\Foo", "bar"]);',
],
];
}
@ -1507,6 +1519,24 @@ class CallableTest extends TestCase
}',
'error_message' => 'MixedReturnStatement'
],
'noFatalErrorOnMissingClassWithSlash' => [
'<?php
class Func {
public function __construct(string $name, callable $callable) {}
}
new Func("f", ["\Foo", "bar"]);',
'error_message' => 'InvalidArgument'
],
'noFatalErrorOnMissingClassWithoutSlash' => [
'<?php
class Func {
public function __construct(string $name, callable $callable) {}
}
new Func("f", ["Foo", "bar"]);',
'error_message' => 'InvalidArgument'
],
];
}
}