From 8b9de8bba62eb938602a1d83e594b3f50b568432 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Sun, 26 May 2019 13:16:44 -0400 Subject: [PATCH] =?UTF-8?q?class=5Fesists=20check=20with=20false=20arg=20s?= =?UTF-8?q?houldn=E2=80=99t=20count?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #1682 --- .../Statements/Expression/AssertionFinder.php | 13 ++++++++++++- tests/ClassTest.php | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php index 6060888ff..f83203e7a 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php @@ -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; diff --git a/tests/ClassTest.php b/tests/ClassTest.php index b09082910..606aa35bb 100644 --- a/tests/ClassTest.php +++ b/tests/ClassTest.php @@ -391,6 +391,20 @@ class ClassTest extends TestCase if (class_exists($s) || interface_exists($s)) {} }' ], + 'classExistsWithFalseArg' => [ + '