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

Fix #1891 - don’t enter class_alias if the class doesn’t exist

This commit is contained in:
Matthew Brown 2019-07-04 15:46:11 -04:00
parent af52ad245a
commit 802016757c
4 changed files with 16 additions and 1 deletions

View File

@ -848,7 +848,7 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
}
}
if ($function_id === 'class_alias') {
if ($function_id === 'class_alias' && !$this->skip_if_descendants) {
$first_arg = $node->args[0]->value ?? null;
$second_arg = $node->args[1]->value ?? null;

View File

@ -416,6 +416,19 @@ class ClassTest extends TestCase
}
}'
],
'classAliasOnNonexistantClass' => [
'<?php
if (!class_exists(\PHPUnit\Framework\TestCase::class)) {
/** @psalm-suppress UndefinedClass */
class_alias(\PHPUnit_Framework_TestCase::class, \PHPUnit\Framework\TestCase::class);
}
class T extends \PHPUnit\Framework\TestCase {
}',
[],
['PropertyNotSetInConstructor']
],
];
}

View File

@ -34,3 +34,4 @@ foreach ($arr as list($orig, $alias)) {
// Psalm cannot reason about this in the loading step
class_alias($orig, $alias);
}

View File

@ -22,3 +22,4 @@ if (!function_exists('new_random_bytes')) {
return 5;
}
}