mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Fix #1891 - don’t enter class_alias if the class doesn’t exist
This commit is contained in:
parent
af52ad245a
commit
802016757c
@ -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;
|
||||
|
||||
|
@ -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']
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
1
tests/fixtures/stubs/class_alias.php
vendored
1
tests/fixtures/stubs/class_alias.php
vendored
@ -34,3 +34,4 @@ foreach ($arr as list($orig, $alias)) {
|
||||
// Psalm cannot reason about this in the loading step
|
||||
class_alias($orig, $alias);
|
||||
}
|
||||
|
||||
|
1
tests/fixtures/stubs/polyfill.php
vendored
1
tests/fixtures/stubs/polyfill.php
vendored
@ -22,3 +22,4 @@ if (!function_exists('new_random_bytes')) {
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user