Skip to content

Commit

Permalink
Merge pull request #10659 from weirdan/7395-suppress-UndefinedClass-i…
Browse files Browse the repository at this point in the history
…n-whatever_exists
  • Loading branch information
weirdan committed Feb 5, 2024
2 parents f40e23f + b822c33 commit 4621705
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Expand Up @@ -191,7 +191,7 @@ public static function analyze(

$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
) {
Expand Down
27 changes: 25 additions & 2 deletions tests/FunctionCallTest.php
Expand Up @@ -777,8 +777,31 @@ function exploder(string $d, string $s) : array {
}',
],
'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
Expand Down

0 comments on commit 4621705

Please sign in to comment.