Skip to content

Commit

Permalink
Merge pull request #9 from veewee/psalmv5
Browse files Browse the repository at this point in the history
Psalm5 support
  • Loading branch information
veewee committed Nov 30, 2022
2 parents 2aa6c21 + cab0731 commit bf223f6
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 25 deletions.
9 changes: 5 additions & 4 deletions README.md
Expand Up @@ -51,10 +51,11 @@ and correct type of `array{name: string, age: int, location?: array{city: string

## Compatibility

| PSL | Psalm plugin |
|-----|--------------|
| 2.x | 2.x |
| 1.x | 1.x |
| PSL | Psalm plugin | Psalm |
|-----|------------|-------|
| 2.x | ^2.1 | v5 |
| 2.x | ~2.0.0 | v4 |
| 1.x | 1.x | v4 |

## Sponsors

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -11,7 +11,7 @@
],
"require": {
"php": "^8.1",
"vimeo/psalm": "^4.20 || ^5.0"
"vimeo/psalm": "^5.0"
},
"conflict": {
"azjezz/psl": "<2.0"
Expand Down
8 changes: 4 additions & 4 deletions src/EventHandler/Iter/First/FunctionReturnTypeProvider.php
Expand Up @@ -34,20 +34,20 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
}

if ($array_argument_type instanceof Type\Atomic\TNonEmptyArray) {
return clone $array_argument_type->type_params[1];
return $array_argument_type->type_params[1];
}

if ($array_argument_type instanceof Type\Atomic\TNonEmptyList) {
return clone $array_argument_type->type_param;
return $array_argument_type->type_param;
}

if ($array_argument_type instanceof Type\Atomic\TKeyedArray) {
// TODO(azjezz): add support for this once psalm starts enforcing the shape order ( if ever ).
//
// foreach ($properties as $property) {
// return clone $property;
// return $property;
// }
return clone $array_argument_type->getGenericValueType();
return $array_argument_type->getGenericValueType();
}

return null;
Expand Down
6 changes: 3 additions & 3 deletions src/EventHandler/Iter/FirstKey/FunctionReturnTypeProvider.php
Expand Up @@ -34,7 +34,7 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
}

if ($array_argument_type instanceof Type\Atomic\TNonEmptyArray) {
return clone $array_argument_type->type_params[0];
return $array_argument_type->type_params[0];
}

if ($array_argument_type instanceof Type\Atomic\TNonEmptyList) {
Expand All @@ -45,9 +45,9 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
// TODO(azjezz): add support for this once psalm starts enforcing the shape order ( if ever ).
//
// foreach ($properties as $property) {
// return clone $property;
// return $property;
// }
return clone $array_argument_type->getGenericKeyType();
return $array_argument_type->getGenericKeyType();
}

return null;
Expand Down
8 changes: 4 additions & 4 deletions src/EventHandler/Iter/Last/FunctionReturnTypeProvider.php
Expand Up @@ -34,11 +34,11 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
}

if ($array_argument_type instanceof Type\Atomic\TNonEmptyArray) {
return clone $array_argument_type->type_params[1];
return $array_argument_type->type_params[1];
}

if ($array_argument_type instanceof Type\Atomic\TNonEmptyList) {
return clone $array_argument_type->type_param;
return $array_argument_type->type_param;
}

if ($array_argument_type instanceof Type\Atomic\TKeyedArray) {
Expand All @@ -50,8 +50,8 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
// $last_property = $property;
// }
//
// return clone $last_property;
return clone $array_argument_type->getGenericValueType();
// return $last_property;
return $array_argument_type->getGenericValueType();
}

return null;
Expand Down
6 changes: 3 additions & 3 deletions src/EventHandler/Iter/LastKey/FunctionReturnTypeProvider.php
Expand Up @@ -34,7 +34,7 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
}

if ($array_argument_type instanceof Type\Atomic\TNonEmptyArray) {
return clone $array_argument_type->type_params[0];
return $array_argument_type->type_params[0];
}

if ($array_argument_type instanceof Type\Atomic\TNonEmptyList) {
Expand All @@ -50,8 +50,8 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
// $last_property = $property;
// }
//
// return clone $last_property;
return clone $array_argument_type->getGenericKeyType();
// return $last_property;
return $array_argument_type->getGenericKeyType();
}

return null;
Expand Down
Expand Up @@ -28,9 +28,6 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
return null;
}

$clone = clone $argument_type;
$clone->possibly_undefined = true;

return $clone;
return $argument_type->setPossiblyUndefined(true);
}
}
4 changes: 2 additions & 2 deletions src/EventHandler/Type/Shape/FunctionReturnTypeProvider.php
Expand Up @@ -57,8 +57,8 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
return null;
}

$property_type = clone $type->type_params[0];
$property_type->possibly_undefined = $value->possibly_undefined;
$property_type = $type->type_params[0];
$property_type = $property_type->setPossiblyUndefined($value->possibly_undefined);

$properties[$name] = $property_type;
}
Expand Down

0 comments on commit bf223f6

Please sign in to comment.