1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Prevent invalid static invocation

Fixes #1134
This commit is contained in:
Brown 2018-12-17 17:48:13 -05:00
parent 2b7cd6b303
commit 7b03e0159c
2 changed files with 15 additions and 3 deletions

View File

@ -413,8 +413,9 @@ class StaticCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
return false;
}
if ($stmt->class instanceof PhpParser\Node\Name
&& ($stmt->class->parts[0] !== 'parent' || $statements_analyzer->isStatic())
if ((!$stmt->class instanceof PhpParser\Node\Name
|| $stmt->class->parts[0] !== 'parent'
|| $statements_analyzer->isStatic())
&& (
!$context->self
|| $statements_analyzer->isStatic()
@ -423,7 +424,9 @@ class StaticCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
) {
if (MethodAnalyzer::checkStatic(
$method_id,
strtolower($stmt->class->parts[0]) === 'self' || $context->self === $fq_class_name,
($stmt->class instanceof PhpParser\Node\Name
&& strtolower($stmt->class->parts[0]) === 'self')
|| $context->self === $fq_class_name,
!$statements_analyzer->isStatic(),
$codebase,
new CodeLocation($source, $stmt),

View File

@ -435,6 +435,15 @@ class MethodCallTest extends TestCase
}',
'error_message' => 'UndefinedMethod - src/somefile.php:7 - Method (B&A)::zugzug does not exist'
],
'noInstanceCallAsStatic' => [
'<?php
class C {
public function foo() : void {}
}
(new C)::foo();',
'error_message' => 'InvalidStaticInvocation',
],
];
}
}