mirror of
https://github.com/danog/psalm-plugin.git
synced 2024-11-30 04:39:05 +01:00
chore: fix counting empty array
Signed-off-by: azjezz <azjezz@protonmail.com>
This commit is contained in:
parent
0fe10f0af9
commit
19d14701e5
@ -54,24 +54,28 @@ final class FunctionReturnTypeProvider implements FunctionReturnTypeProviderInte
|
|||||||
return Type::getInt(false, $count);
|
return Type::getInt(false, $count);
|
||||||
}
|
}
|
||||||
|
|
||||||
// array{foo: bar} -> literal-int(1)
|
// array{foo: bar} -> int<1, max>
|
||||||
|
// array{foo, bar, baz} -> int<3, max>
|
||||||
if ($array_argument_type instanceof Type\Atomic\TKeyedArray) {
|
if ($array_argument_type instanceof Type\Atomic\TKeyedArray) {
|
||||||
// Psalm allows extra properties in keyed arrays, so we can't return a literal integer
|
// Psalm allows extra properties in keyed arrays, so we can't return a literal integer
|
||||||
// for this.
|
if (($size = count($array_argument_type->properties)) >= 1) {
|
||||||
//
|
return new Type\Union([new Type\Atomic\TIntRange($size, null)]);
|
||||||
// return Type::getInt(false, count($array_argument_type->properties));
|
|
||||||
|
|
||||||
if (count($array_argument_type->properties) >= 1) {
|
|
||||||
return new Type\Union([new Type\Atomic\TIntRange(1, null)]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Type::getInt();
|
return Type::getInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($array_argument_type instanceof Type\Atomic\TArray) {
|
if ($array_argument_type instanceof Type\Atomic\TArray) {
|
||||||
if ($array_argument_type->type_params[0]->isNever() && $array_argument_type->type_params[1]->isNever()) {
|
if (method_exists($array_argument_type, 'isEmptyArray') && $array_argument_type->isEmptyArray()) {
|
||||||
return Type::getInt(false, 0);
|
return Type::getInt(false, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (method_exists($array_argument_type->type_params[0], 'isEmpty')) {
|
||||||
|
if ($array_argument_type->type_params[0]->isEmpty() && $array_argument_type->type_params[1]->isEmpty()) {
|
||||||
|
return Type::getInt(false, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Type::getInt();
|
return Type::getInt();
|
||||||
|
Loading…
Reference in New Issue
Block a user