1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 09:37:59 +01:00

Flag stdClass::__construct() calls that have arguments

Fixes vimeo/psalm#10018
This commit is contained in:
Bruce Weirdan 2024-02-06 01:24:18 +01:00
parent f40e23faef
commit 62b525993d
No known key found for this signature in database
GPG Key ID: CFC3AAB181751B0D
2 changed files with 19 additions and 1 deletions

View File

@ -244,6 +244,17 @@ final class NewAnalyzer extends CallAnalyzer
new Union([$result_atomic_type]), 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' && if (strtolower($fq_class_name) !== 'stdclass' &&
$codebase->classlikes->classExists($fq_class_name) $codebase->classlikes->classExists($fq_class_name)
) { ) {

View File

@ -1798,6 +1798,13 @@ class MethodCallTest extends TestCase
', ',
'error_message' => 'InvalidParamDefault', 'error_message' => 'InvalidParamDefault',
], ],
'stdClassConstructorHasNoParameters' => [
'code' => <<<'PHP'
<?php
$a = new stdClass(5);
PHP,
'error_message' => 'TooManyArguments',
],
]; ];
} }
} }