|
60 | 60 | use PHPStan\Type\StringType; |
61 | 61 | use PHPStan\Type\Type; |
62 | 62 | use PHPStan\Type\TypeCombinator; |
63 | | -use PHPStan\Type\TypeTraverser; |
64 | 63 | use PHPStan\Type\UnionType; |
65 | 64 | use Throwable; |
66 | 65 | use function array_filter; |
@@ -462,7 +461,7 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex |
462 | 461 | $storage, |
463 | 462 | $stmt, |
464 | 463 | $arrayArg, |
465 | | - new NativeTypeExpr($this->getArraySortPreserveListFunctionType($scope->getType($arrayArg)), $this->getArraySortPreserveListFunctionType($scope->getNativeType($arrayArg))), |
| 464 | + new NativeTypeExpr($scope->getType($arrayArg)->sortArray(), $scope->getNativeType($arrayArg)->sortArray()), |
466 | 465 | $nodeCallback, |
467 | 466 | )->getScope(); |
468 | 467 | } |
@@ -722,31 +721,6 @@ static function (?Type $offsetType, Type $valueType, bool $optional) use (&$arra |
722 | 721 | return $arrayType; |
723 | 722 | } |
724 | 723 |
|
725 | | - private function getArraySortPreserveListFunctionType(Type $type): Type |
726 | | - { |
727 | | - $isIterableAtLeastOnce = $type->isIterableAtLeastOnce(); |
728 | | - if ($isIterableAtLeastOnce->no()) { |
729 | | - return $type; |
730 | | - } |
731 | | - |
732 | | - return TypeTraverser::map($type, static function (Type $type, callable $traverse) use ($isIterableAtLeastOnce): Type { |
733 | | - if ($type instanceof UnionType || $type instanceof IntersectionType) { |
734 | | - return $traverse($type); |
735 | | - } |
736 | | - |
737 | | - if (!$type instanceof ArrayType && !$type instanceof ConstantArrayType) { |
738 | | - return $type; |
739 | | - } |
740 | | - |
741 | | - $newArrayType = new IntersectionType([new ArrayType(IntegerRangeType::createAllGreaterThanOrEqualTo(0), $type->getIterableValueType()), new AccessoryArrayListType()]); |
742 | | - if ($isIterableAtLeastOnce->yes()) { |
743 | | - $newArrayType = TypeCombinator::intersect($newArrayType, new NonEmptyArrayType()); |
744 | | - } |
745 | | - |
746 | | - return $newArrayType; |
747 | | - }); |
748 | | - } |
749 | | - |
750 | 724 | private function getArraySortDoNotPreserveListFunctionType(Type $type): Type |
751 | 725 | { |
752 | 726 | return $type->makeListMaybe(); |
|
0 commit comments