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

Suppress UndefinedClass in whatever_exists()

Fixes vimeo/psalm#7395
This commit is contained in:
Bruce Weirdan 2024-02-05 20:44:09 +01:00
parent f40e23faef
commit b822c3339d
No known key found for this signature in database
GPG Key ID: CFC3AAB181751B0D
2 changed files with 26 additions and 3 deletions

View File

@ -191,7 +191,7 @@ final class ArgumentsAnalyzer
$toggled_class_exists = false;
if ($method_id === 'class_exists'
if (in_array($method_id, ['class_exists', 'interface_exists', 'enum_exists', 'trait_exists'], true)
&& $argument_offset === 0
&& !$context->inside_class_exists
) {

View File

@ -777,8 +777,31 @@ class FunctionCallTest extends TestCase
}',
],
'allowPossiblyUndefinedClassInClassExists' => [
'code' => '<?php
if (class_exists(Foo::class)) {}',
'code' => <<<'PHP'
<?php
if (class_exists(Foo::class)) {}
PHP,
],
'allowPossiblyUndefinedClassInInterfaceExists' => [
'code' => <<<'PHP'
<?php
if (interface_exists(Foo::class)) {}
PHP,
],
'allowPossiblyUndefinedClassInTraitExists' => [
'code' => <<<'PHP'
<?php
if (trait_exists(Foo::class)) {}
PHP,
],
'allowPossiblyUndefinedClassInEnumExists' => [
'code' => <<<'PHP'
<?php
if (enum_exists(Foo::class)) {}
PHP,
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.1',
],
'allowConstructorAfterClassExists' => [
'code' => '<?php