mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Fix #1514 - catch static interface call
This commit is contained in:
parent
5e287fa83e
commit
bd6fea0d57
@ -184,7 +184,8 @@ abstract class ClassLikeAnalyzer extends SourceAnalyzer implements StatementsSou
|
||||
CodeLocation $code_location,
|
||||
array $suppressed_issues,
|
||||
$inferred = true,
|
||||
bool $allow_trait = false
|
||||
bool $allow_trait = false,
|
||||
bool $allow_interface = true
|
||||
) {
|
||||
$codebase = $statements_source->getCodebase();
|
||||
if (empty($fq_class_name)) {
|
||||
@ -248,6 +249,17 @@ abstract class ClassLikeAnalyzer extends SourceAnalyzer implements StatementsSou
|
||||
}
|
||||
|
||||
return null;
|
||||
} elseif ($interface_exists && !$allow_interface) {
|
||||
if (IssueBuffer::accepts(
|
||||
new UndefinedClass(
|
||||
'Class ' . $fq_class_name . ' does not exist',
|
||||
$code_location,
|
||||
$fq_class_name
|
||||
),
|
||||
$suppressed_issues
|
||||
)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$aliased_name_lc = $codebase->classlikes->getUnAliasedName(
|
||||
|
@ -138,6 +138,8 @@ class StaticCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
|
||||
$fq_class_name,
|
||||
new CodeLocation($source, $stmt->class),
|
||||
$statements_analyzer->getSuppressedIssues(),
|
||||
false,
|
||||
false,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
@ -537,6 +537,16 @@ class InterfaceTest extends TestCase
|
||||
}
|
||||
}',
|
||||
],
|
||||
'allowStaticCallOnInterfaceMethod' => [
|
||||
'<?php
|
||||
interface IFoo {
|
||||
public static function doFoo();
|
||||
}
|
||||
|
||||
function bar(IFoo $i) : void {
|
||||
$i::doFoo();
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -754,6 +764,15 @@ class InterfaceTest extends TestCase
|
||||
}',
|
||||
'error_message' => 'MethodSignatureMismatch',
|
||||
],
|
||||
'staticInterfaceCall' => [
|
||||
'<?php
|
||||
interface Foo {
|
||||
public static function doFoo();
|
||||
}
|
||||
|
||||
Foo::doFoo();',
|
||||
'error_message' => 'UndefinedClass',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user