Skip to content

Commit

Permalink
chore: add compatibility with psalm 5
Browse files Browse the repository at this point in the history
Signed-off-by: azjezz <azjezz@protonmail.com>
  • Loading branch information
azjezz committed Feb 6, 2022
1 parent 99304b6 commit dce3fe8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
11 changes: 7 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"require": {
"php": "^7.4 || ^8.0",
"vimeo/psalm": "^4.6"
"vimeo/psalm": "^4.20 || ^5.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.18",
Expand Down Expand Up @@ -44,12 +44,15 @@
},
"config": {
"process-timeout": 1200,
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"composer/package-versions-deprecated": false
}
},
"extra": {
"psalm": {
"pluginClass": "Psl\\Psalm\\Plugin"
}
},
"minimum-stability": "dev"
}
"minimum-stability": "alpha"
}
2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<psalm totallyTyped="true" resolveFromConfigFile="true" forbidEcho="true" strictBinaryOperands="true" phpVersion="7.4" allowPhpStormGenerics="true" allowStringToStandInForClass="true" rememberPropertyAssignmentsAfterCall="false" skipChecksOnUnresolvableIncludes="false" checkForThrowsDocblock="true" checkForThrowsInGlobalScope="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd">
<psalm totallyTyped="true" resolveFromConfigFile="true" strictBinaryOperands="true" phpVersion="7.4" allowStringToStandInForClass="true" rememberPropertyAssignmentsAfterCall="false" skipChecksOnUnresolvableIncludes="false" checkForThrowsDocblock="true" checkForThrowsInGlobalScope="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd">
<projectFiles>
<directory name="src" />
<ignoreFiles>
Expand Down
12 changes: 5 additions & 7 deletions src/EventHandler/Iter/Count/FunctionReturnTypeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
if ($array_argument_type instanceof Type\Atomic\TNonEmptyList) {
$count = $array_argument_type->count;
if (null === $count) {
return Type::getPositiveInt();
return new Type\Union([new Type\Atomic\TIntRange(1, null)]);
}

return Type::getInt(false, $count);
Expand All @@ -48,7 +48,7 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
if ($array_argument_type instanceof Type\Atomic\TNonEmptyArray) {
$count = $array_argument_type->count;
if (null === $count) {
return Type::getPositiveInt();
return new Type\Union([new Type\Atomic\TIntRange(1, null)]);
}

return Type::getInt(false, $count);
Expand All @@ -62,16 +62,14 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
// return Type::getInt(false, count($array_argument_type->properties));

if (count($array_argument_type->properties) >= 1) {
return Type::getPositiveInt();
return new Type\Union([new Type\Atomic\TIntRange(1, null)]);
}

return Type::getInt();
}

if ($array_argument_type instanceof Type\Atomic\TArray) {
if ($array_argument_type->type_params[0]->isEmpty() && $array_argument_type->type_params[1]->isEmpty()) {
return Type::getInt(false, 0);
}
if (($array_argument_type instanceof Type\Atomic\TArray) && $array_argument_type->type_params[0]->isNever() && $array_argument_type->type_params[1]->isNever()) {
return Type::getInt(false, 0);
}

return Type::getInt();
Expand Down

0 comments on commit dce3fe8

Please sign in to comment.