Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
clxmstaab committed Mar 23, 2022
1 parent 495e9c2 commit 8e42b32
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php
Expand Up @@ -10,10 +10,11 @@
use PHPStan\Analyser\TypeSpecifierContext;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Type\Accessory\NonEmptyArrayType;
use PHPStan\Type\Constant\ConstantArrayType;
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\FunctionTypeSpecifyingExtension;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypeUtils;
use PHPStan\Type\UnionType;
use function count;
use function strtolower;

Expand Down Expand Up @@ -47,12 +48,14 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n
$arrayValueType = $arrayType->getIterableValueType();

$specifiedTypes = new SpecifiedTypes([], []);
if ($context->true() && $arrayType->isArray()->yes() && !$arrayType->isIterableAtLeastOnce()->yes()) {
$arrayType = TypeCombinator::intersect($arrayType, new NonEmptyArrayType());

if ($context->true()
&& $arrayType->isArray()->yes()
&& !$arrayType->isIterableAtLeastOnce()->yes()
&& !($arrayType instanceof ConstantArrayType && $arrayType->isEmpty())
&& !$arrayType instanceof UnionType) {
$specifiedTypes = $specifiedTypes->unionWith($this->typeSpecifier->create(
$node->getArgs()[1]->value,
$arrayType,
new NonEmptyArrayType(),
$context,
false,
$scope,
Expand Down

0 comments on commit 8e42b32

Please sign in to comment.