File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
src/Psalm/Internal/Analyzer/Statements/Expression/Call Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 3838use Psalm \Issue \NamedArgumentNotAllowed ;
3939use Psalm \Issue \NoValue ;
4040use Psalm \Issue \NullArgument ;
41+ use Psalm \Issue \ParentNotFound ;
4142use Psalm \Issue \PossiblyFalseArgument ;
4243use Psalm \Issue \PossiblyInvalidArgument ;
4344use Psalm \Issue \PossiblyNullArgument ;
@@ -1297,6 +1298,16 @@ private static function verifyExplicitParam(
12971298
12981299 if ($ callable_fq_class_name === 'parent ' ) {
12991300 $ container_class = $ statements_analyzer ->getParentFQCLN ();
1301+ if ($ container_class === null ) {
1302+ IssueBuffer::accepts (
1303+ new ParentNotFound (
1304+ 'Cannot call method on parent '
1305+ . ' as this class does not extend another ' ,
1306+ $ arg_location ,
1307+ ),
1308+ $ statements_analyzer ->getSuppressedIssues (),
1309+ );
1310+ }
13001311 }
13011312
13021313 if (!$ container_class ) {
Original file line number Diff line number Diff line change @@ -2533,6 +2533,40 @@ function f(callable $c): void {
25332533 'ignored_issues ' => [],
25342534 'php_version ' => '8.0 ' ,
25352535 ],
2536+ 'parentCallableArrayWithoutParent ' => [
2537+ 'code ' => '<?php
2538+ class A {
2539+ public function __construct() {
2540+ $this->run(["parent", "hello"]);
2541+ }
2542+
2543+ /**
2544+ * @param callable $callable
2545+ * @return void
2546+ */
2547+ public function run($callable) {
2548+ call_user_func($callable);
2549+ }
2550+ } ' ,
2551+ 'error_message ' => 'ParentNotFound ' ,
2552+ ],
2553+ 'parentCallableWithoutParent ' => [
2554+ 'code ' => '<?php
2555+ class A {
2556+ public function __construct() {
2557+ $this->run("parent::hello");
2558+ }
2559+
2560+ /**
2561+ * @param callable $callable
2562+ * @return void
2563+ */
2564+ public function run($callable) {
2565+ call_user_func($callable);
2566+ }
2567+ } ' ,
2568+ 'error_message ' => 'ParentNotFound ' ,
2569+ ],
25362570 ];
25372571 }
25382572}
You can’t perform that action at this time.
0 commit comments