Skip to content

Commit

Permalink
Merge pull request #10661 from vimeo/10018-flag-stdclass-constructor-…
Browse files Browse the repository at this point in the history
…with-arguments
  • Loading branch information
weirdan committed Feb 6, 2024
2 parents 4621705 + 62b5259 commit 508da9a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,17 @@ public static function analyze(
new Union([$result_atomic_type]),
);

if (strtolower($fq_class_name) === 'stdclass' && $stmt->getArgs() !== []) {
IssueBuffer::maybeAdd(
new TooManyArguments(
'stdClass::__construct() has no parameters',
new CodeLocation($statements_analyzer->getSource(), $stmt),
'stdClass::__construct',
),
$statements_analyzer->getSuppressedIssues(),
);
}

if (strtolower($fq_class_name) !== 'stdclass' &&
$codebase->classlikes->classExists($fq_class_name)
) {
Expand Down
9 changes: 8 additions & 1 deletion tests/MethodCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ public function x(): void {}
}
class Child1 extends Old {}
class Child2 extends Old {}
/**
* @template IsClient of bool
*/
Expand Down Expand Up @@ -1798,6 +1798,13 @@ public function foo(callable $_a = "strlen"): void {}
',
'error_message' => 'InvalidParamDefault',
],
'stdClassConstructorHasNoParameters' => [
'code' => <<<'PHP'
<?php
$a = new stdClass(5);
PHP,
'error_message' => 'TooManyArguments',
],
];
}
}

0 comments on commit 508da9a

Please sign in to comment.