mirror of
https://github.com/danog/psalm.git
synced 2024-12-02 09:37:59 +01:00
Merge pull request #10838 from kkmuffme/undefined-parent-not-reported-in-callable
This commit is contained in:
commit
e3d55268f9
@ -38,6 +38,7 @@ use Psalm\Issue\MixedArgumentTypeCoercion;
|
|||||||
use Psalm\Issue\NamedArgumentNotAllowed;
|
use Psalm\Issue\NamedArgumentNotAllowed;
|
||||||
use Psalm\Issue\NoValue;
|
use Psalm\Issue\NoValue;
|
||||||
use Psalm\Issue\NullArgument;
|
use Psalm\Issue\NullArgument;
|
||||||
|
use Psalm\Issue\ParentNotFound;
|
||||||
use Psalm\Issue\PossiblyFalseArgument;
|
use Psalm\Issue\PossiblyFalseArgument;
|
||||||
use Psalm\Issue\PossiblyInvalidArgument;
|
use Psalm\Issue\PossiblyInvalidArgument;
|
||||||
use Psalm\Issue\PossiblyNullArgument;
|
use Psalm\Issue\PossiblyNullArgument;
|
||||||
@ -1297,6 +1298,16 @@ final class ArgumentAnalyzer
|
|||||||
|
|
||||||
if ($callable_fq_class_name === 'parent') {
|
if ($callable_fq_class_name === 'parent') {
|
||||||
$container_class = $statements_analyzer->getParentFQCLN();
|
$container_class = $statements_analyzer->getParentFQCLN();
|
||||||
|
if ($container_class === null) {
|
||||||
|
IssueBuffer::accepts(
|
||||||
|
new ParentNotFound(
|
||||||
|
'Cannot call method on parent'
|
||||||
|
. ' as this class does not extend another',
|
||||||
|
$arg_location,
|
||||||
|
),
|
||||||
|
$statements_analyzer->getSuppressedIssues(),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$container_class) {
|
if (!$container_class) {
|
||||||
|
@ -2533,6 +2533,40 @@ class CallableTest extends TestCase
|
|||||||
'ignored_issues' => [],
|
'ignored_issues' => [],
|
||||||
'php_version' => '8.0',
|
'php_version' => '8.0',
|
||||||
],
|
],
|
||||||
|
'parentCallableArrayWithoutParent' => [
|
||||||
|
'code' => '<?php
|
||||||
|
class A {
|
||||||
|
public function __construct() {
|
||||||
|
$this->run(["parent", "hello"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param callable $callable
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function run($callable) {
|
||||||
|
call_user_func($callable);
|
||||||
|
}
|
||||||
|
}',
|
||||||
|
'error_message' => 'ParentNotFound',
|
||||||
|
],
|
||||||
|
'parentCallableWithoutParent' => [
|
||||||
|
'code' => '<?php
|
||||||
|
class A {
|
||||||
|
public function __construct() {
|
||||||
|
$this->run("parent::hello");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param callable $callable
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function run($callable) {
|
||||||
|
call_user_func($callable);
|
||||||
|
}
|
||||||
|
}',
|
||||||
|
'error_message' => 'ParentNotFound',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user