This commit is contained in:
Daniil Gentili 2023-11-28 10:18:13 +01:00
parent b36ca5eed0
commit 678f519620
2 changed files with 6 additions and 58 deletions

View File

@ -11,7 +11,7 @@
],
"require": {
"php": "^8.1",
"vimeo/psalm": "^5.0"
"vimeo/psalm": ">=5.16"
},
"conflict": {
"azjezz/psl": "<2.0"

View File

@ -28,80 +28,28 @@ final class FunctionReturnTypeProvider implements FunctionReturnTypeProviderInte
if (null === $argument_type) {
// [unknown] -> list<string>
$value = new Type\Union([new Type\Atomic\TString()], ['possibly_undefined' => true]);
return new Type\Union([new Type\Atomic\TKeyedArray(
[
0 => $value
],
null,
[
Type::getListKey(),
$value
],
true
)]);
return Type::getList($value);
}
$string_argument_type = $argument_type->getAtomicTypes()['string'] ?? null;
if (null === $string_argument_type) {
// [unknown] -> list<string>
$value = new Type\Union([new Type\Atomic\TString()], ['possibly_undefined' => true]);
return new Type\Union([new Type\Atomic\TKeyedArray(
[
0 => $value
],
null,
[
Type::getListKey(),
$value
],
true
)]);
return Type::getList($value);
}
if ($string_argument_type instanceof Type\Atomic\TNonEmptyString) {
// non-empty-lowercase-string => non-empty-list<non-empty-lowercase-string>
if ($string_argument_type instanceof Type\Atomic\TNonEmptyLowercaseString) {
$value = new Type\Union([new Type\Atomic\TNonEmptyLowercaseString()]);
return new Type\Union([new Type\Atomic\TKeyedArray(
[
0 => $value
],
null,
[
Type::getListKey(),
$value
],
true
)]);
return Type::getNonEmptyList(Type::getNonEmptyLowercaseString());
}
// non-empty-string => non-empty-list<non-empty-string>
$value = new Type\Union([new Type\Atomic\TNonEmptyString()]);
return new Type\Union([new Type\Atomic\TKeyedArray(
[
0 => $value
],
null,
[
Type::getListKey(),
$value
],
true
)]);
return Type::getNonEmptyList(Type::getNonEmptyString());
}
// string -> list<string>
$value = new Type\Union([new Type\Atomic\TString()], ['possibly_undefined' => true]);
return new Type\Union([new Type\Atomic\TKeyedArray(
[
0 => $value
],
null,
[
Type::getListKey(),
$value
],
true
)]);
return Type::getList($value);
}
}