1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

class_esists check with false arg shouldn’t count

Fixes #1682
This commit is contained in:
Matthew Brown 2019-05-26 13:16:44 -04:00
parent 97f4cdb7f5
commit 8b9de8bba6
2 changed files with 26 additions and 1 deletions

View File

@ -2296,7 +2296,18 @@ class AssertionFinder
if ($stmt->name instanceof PhpParser\Node\Name
&& strtolower($stmt->name->parts[0]) === 'class_exists'
) {
return true;
if (!isset($stmt->args[2])) {
return true;
}
$second_arg = $stmt->args[2]->value;
if ($second_arg instanceof PhpParser\Node\Expr\ConstFetch
&& $second_arg->name instanceof PhpParser\Node\Name
&& strtolower($second_arg->name->parts[0]) === 'true'
) {
return true;
}
}
return false;

View File

@ -391,6 +391,20 @@ class ClassTest extends TestCase
if (class_exists($s) || interface_exists($s)) {}
}'
],
'classExistsWithFalseArg' => [
'<?php
/**
* @param class-string $class
* @return ?class-string
*/
function autoload(string $class) : string {
if (class_exists($class, false)) {
return $class;
}
return $class;
}'
],
];
}