Skip to content

Commit baf9e84

Browse files
committed
Stop using deprecated method
1 parent 2674577 commit baf9e84

7 files changed

+12
-16
lines changed

src/Analyser/MutatingScope.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ private function resolveType(Expr $node): Type
11351135
foreach ($rightTypes as $rightType) {
11361136
$resultType = $this->calculateFromScalars($node, $leftType, $rightType);
11371137
if ($generalize) {
1138-
$resultType = TypeUtils::generalizeType($resultType, GeneralizePrecision::lessSpecific());
1138+
$resultType = $resultType->generalize(GeneralizePrecision::lessSpecific());
11391139
}
11401140
$resultTypes[] = $resultType;
11411141
}
@@ -5193,7 +5193,7 @@ private static function generalizeType(Type $a, Type $b): Type
51935193
continue;
51945194
}
51955195

5196-
$resultTypes[] = TypeUtils::generalizeType(TypeCombinator::union(...$constantTypes['a'], ...$constantTypes['b']), GeneralizePrecision::moreSpecific());
5196+
$resultTypes[] = TypeCombinator::union(...$constantTypes['a'], ...$constantTypes['b'])->generalize(GeneralizePrecision::moreSpecific());
51975197
}
51985198

51995199
if (count($constantArrays['a']) > 0) {

src/Reflection/Php/PhpClassReflectionExtension.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
use PHPStan\Type\Type;
4848
use PHPStan\Type\TypeCombinator;
4949
use PHPStan\Type\TypehintHelper;
50-
use PHPStan\Type\TypeUtils;
5150
use ReflectionClass;
5251
use ReflectionParameter;
5352
use function array_key_exists;
@@ -974,7 +973,7 @@ private function inferAndCachePropertyTypes(
974973
continue;
975974
}
976975

977-
$propertyType = TypeUtils::generalizeType($propertyType, GeneralizePrecision::lessSpecific());
976+
$propertyType = $propertyType->generalize(GeneralizePrecision::lessSpecific());
978977
if ($propertyType instanceof ConstantArrayType) {
979978
$propertyType = new ArrayType(new MixedType(true), new MixedType(true));
980979
}

src/Type/ArrayType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ function () use ($level, $isMixedKeyType, $isMixedItemType): string {
155155

156156
public function generalizeValues(): self
157157
{
158-
return new self($this->keyType, TypeUtils::generalizeType($this->itemType, GeneralizePrecision::lessSpecific()));
158+
return new self($this->keyType, $this->itemType->generalize(GeneralizePrecision::lessSpecific()));
159159
}
160160

161161
public function getKeysArray(): self

src/Type/Constant/ConstantArrayType.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
use PHPStan\Type\StringType;
3030
use PHPStan\Type\Type;
3131
use PHPStan\Type\TypeCombinator;
32-
use PHPStan\Type\TypeUtils;
3332
use PHPStan\Type\UnionType;
3433
use PHPStan\Type\VerbosityLevel;
3534
use function array_keys;
@@ -499,7 +498,7 @@ public function unsetOffset(Type $offsetType): Type
499498
$arrays[] = new self($tmp->keyTypes, $tmp->valueTypes, $tmp->nextAutoIndex, array_keys($tmp->keyTypes));
500499
}
501500

502-
return TypeUtils::generalizeType(TypeCombinator::union(...$arrays), GeneralizePrecision::moreSpecific());
501+
return TypeCombinator::union(...$arrays)->generalize(GeneralizePrecision::moreSpecific());
503502
}
504503

505504
public function isIterableAtLeastOnce(): TrinaryLogic
@@ -630,8 +629,8 @@ public function generalize(GeneralizePrecision $precision): Type
630629
}
631630

632631
$arrayType = new ArrayType(
633-
TypeUtils::generalizeType($this->getKeyType(), $precision),
634-
TypeUtils::generalizeType($this->getItemType(), $precision),
632+
$this->getKeyType()->generalize($precision),
633+
$this->getItemType()->generalize($precision),
635634
);
636635

637636
if (count($this->keyTypes) > count($this->optionalKeys)) {
@@ -648,7 +647,7 @@ public function generalizeValues(): ArrayType
648647
{
649648
$valueTypes = [];
650649
foreach ($this->valueTypes as $valueType) {
651-
$valueTypes[] = TypeUtils::generalizeType($valueType, GeneralizePrecision::lessSpecific());
650+
$valueTypes[] = $valueType->generalize(GeneralizePrecision::lessSpecific());
652651
}
653652

654653
return new self($this->keyTypes, $valueTypes, $this->nextAutoIndex, $this->optionalKeys);

src/Type/IntersectionType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function () use ($level): string {
156156
if ($type instanceof AccessoryType) {
157157
continue;
158158
}
159-
$typeNames[] = TypeUtils::generalizeType($type, GeneralizePrecision::lessSpecific())->describe($level);
159+
$typeNames[] = $type->generalize(GeneralizePrecision::lessSpecific())->describe($level);
160160
}
161161

162162
return implode('&', $typeNames);

src/Type/Php/ArgumentBasedFunctionReturnTypeExtension.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
1111
use PHPStan\Type\GeneralizePrecision;
1212
use PHPStan\Type\Type;
13-
use PHPStan\Type\TypeUtils;
1413

1514
class ArgumentBasedFunctionReturnTypeExtension implements DynamicFunctionReturnTypeExtension
1615
{
@@ -55,8 +54,8 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
5554
$argumentKeyType = $argumentType->getIterableKeyType();
5655
$argumentValueType = $argumentType->getIterableValueType();
5756
if ($argument->unpack) {
58-
$argumentKeyType = TypeUtils::generalizeType($argumentKeyType, GeneralizePrecision::moreSpecific());
59-
$argumentValueType = TypeUtils::generalizeType($argumentValueType->getIterableValueType(), GeneralizePrecision::moreSpecific());
57+
$argumentKeyType = $argumentKeyType->generalize(GeneralizePrecision::moreSpecific());
58+
$argumentValueType = $argumentValueType->getIterableValueType()->generalize(GeneralizePrecision::moreSpecific());
6059
}
6160

6261
return new ArrayType(

src/Type/Php/ArrayMergeFunctionDynamicReturnTypeExtension.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use PHPStan\Type\GeneralizePrecision;
1313
use PHPStan\Type\Type;
1414
use PHPStan\Type\TypeCombinator;
15-
use PHPStan\Type\TypeUtils;
1615
use PHPStan\Type\UnionType;
1716

1817
class ArrayMergeFunctionDynamicReturnTypeExtension implements DynamicFunctionReturnTypeExtension
@@ -43,7 +42,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
4342
}
4443
}
4544

46-
$keyTypes[] = TypeUtils::generalizeType($argType->getIterableKeyType(), GeneralizePrecision::moreSpecific());
45+
$keyTypes[] = $argType->getIterableKeyType()->generalize(GeneralizePrecision::moreSpecific());
4746
$valueTypes[] = $argType->getIterableValueType();
4847

4948
if (!$argType->isIterableAtLeastOnce()->yes()) {

0 commit comments

Comments
 (0)