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:
parent
c50a17d415
commit
3d9c94e29a
@ -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) {
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user