Skip to content
Permalink
Browse files

Fix treatment of class_exists

  • Loading branch information...
muglug committed Jun 27, 2019
1 parent f29826b commit c4eb127f1180db83e16205a3301c13ae24fcee6b
@@ -642,7 +642,10 @@ function (Assertion $assertion) use ($generic_params) : Assertion {
&& $first_arg->value->name->name === 'class'
) {
$resolved_name = (string) $first_arg->value->class->getAttribute('resolvedName');
$context->phantom_classes[strtolower($resolved_name)] = true;
if (!$codebase->classlikes->classExists($resolved_name)) {
$context->phantom_classes[strtolower($resolved_name)] = true;
}
}
}
} elseif ($function->parts === ['file_exists'] && $first_arg) {
@@ -5,9 +5,6 @@
use Psalm\Context;
use Psalm\Internal\Analyzer\FileAnalyzer;
use Psalm\Tests\Internal\Provider;
use function strpos;
use function preg_quote;
use const DIRECTORY_SEPARATOR;
class UnusedCodeTest extends TestCase
{
@@ -46,7 +43,7 @@ public function setUp() : void
public function testValidCode($code, array $error_levels = [])
{
$test_name = $this->getTestName();
if (strpos($test_name, 'SKIPPED-') !== false) {
if (\strpos($test_name, 'SKIPPED-') !== false) {
$this->markTestSkipped('Skipped due to a bug.');
}
@@ -80,12 +77,12 @@ public function testValidCode($code, array $error_levels = [])
*/
public function testInvalidCode($code, $error_message, $error_levels = [])
{
if (strpos($this->getTestName(), 'SKIPPED-') !== false) {
if (\strpos($this->getTestName(), 'SKIPPED-') !== false) {
$this->markTestSkipped();
}
$this->expectException(\Psalm\Exception\CodeException::class);
$this->expectExceptionMessageRegExp('/\b' . preg_quote($error_message, '/') . '\b/');
$this->expectExceptionMessageRegExp('/\b' . \preg_quote($error_message, '/') . '\b/');
$file_path = self::$src_dir_path . 'somefile.php';
@@ -427,6 +424,16 @@ public function addType(?string $type, array $ids = array())
(new C)->addType(null);'
],
'usedMethodAfterClassExists' => [
'<?php
class A {
public static function bar() : void {}
}
if (class_exists(A::class)) {
A::bar();
}'
],
];
}
@@ -459,7 +466,7 @@ public function foo(int $i) {}
}
(new A)->foo(4);',
'error_message' => 'PossiblyUnusedParam - src' . DIRECTORY_SEPARATOR
'error_message' => 'PossiblyUnusedParam - src' . \DIRECTORY_SEPARATOR
. 'somefile.php:4:49 - Param #1 is never referenced in this method',
],
'unusedParam' => [

0 comments on commit c4eb127

Please sign in to comment.
You can’t perform that action at this time.