1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

dirname returns non-empty-string when a non-empty-string is passed and level is 1

This commit is contained in:
kkmuffme 2023-05-30 16:09:50 +02:00
parent 2bbfca6d9f
commit f9f1cc244b

View File

@ -9,6 +9,7 @@ use Psalm\Plugin\EventHandler\Event\FunctionReturnTypeProviderEvent;
use Psalm\Plugin\EventHandler\FunctionReturnTypeProviderInterface;
use Psalm\Type;
use Psalm\Type\Atomic\TLiteralInt;
use Psalm\Type\Atomic\TNonEmptyString;
use Psalm\Type\Union;
use function array_values;
@ -61,6 +62,16 @@ class DirnameReturnTypeProvider implements FunctionReturnTypeProviderInterface
$statements_source->getCodebase()->config,
);
if ($evaled_path === null && $dir_level === 1) {
$type = $node_type_provider->getType($call_args[0]->value);
if ($type !== null && $type->isSingle()) {
$atomic_type = array_values($type->getAtomicTypes())[0];
if ($atomic_type instanceof TNonEmptyString) {
return Type::getNonEmptyString();
}
}
}
if ($evaled_path === null) {
return Type::getString();
}