Skip to content

Commit

Permalink
Updated Rector to commit 5b59337cedccda38caff556b0acfbe2c4a741d2d
Browse files Browse the repository at this point in the history
rectorphp/rector-src@5b59337 Use Type->getIterableKeyType() over ArrayType->getKeyType() (#6480)
  • Loading branch information
TomasVotruba committed Nov 23, 2024
1 parent 678fcae commit 0f5e5b9
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private function shouldSkipArrayForInvalidTypeOrKeys(Expr $expr) : bool
*/
private function isArrayKeyTypeAllowed($arrayType) : bool
{
if ($arrayType->getKeyType()->isInteger()->yes()) {
if ($arrayType->getIterableKeyType()->isInteger()->yes()) {
return \true;
}
// php 8.1+ allow mixed key: int, string, and null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ private function shouldAddReturnArrayDocType($arrayType) : bool
return \false;
}
// handle only simple arrays
if (!$arrayType->getKeyType()->isInteger()->yes()) {
if (!$arrayType->getIterableKeyType()->isInteger()->yes()) {
return \false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions rules/TypeDeclaration/TypeNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function normalizeArrayOfUnionToUnionArray(Type $type, int $arrayNesting
} elseif ($type->getIterableValueType() instanceof UnionType) {
$this->collectNestedArrayTypeFromUnionType($type->getIterableValueType(), $arrayNesting);
} else {
$this->collectedNestedArrayTypes[] = new NestedArrayType($type->getIterableValueType(), $arrayNesting, $type->getKeyType());
$this->collectedNestedArrayTypes[] = new NestedArrayType($type->getIterableValueType(), $arrayNesting, $type->getIterableKeyType());
}
return $this->createUnionedTypesFromArrayTypes($this->collectedNestedArrayTypes);
}
Expand All @@ -80,7 +80,7 @@ public function normalizeArrayTypeAndArrayNever(Type $type) : Type
}
private function isConstantArrayNever(Type $type) : bool
{
return $type instanceof ConstantArrayType && $type->getKeyType() instanceof NeverType && $type->getIterableValueType() instanceof NeverType;
return $type instanceof ConstantArrayType && $type->getIterableKeyType() instanceof NeverType && $type->getIterableValueType() instanceof NeverType;
}
private function collectNestedArrayTypeFromUnionType(UnionType $unionType, int $arrayNesting) : void
{
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'a83117ba14a73c8915e6f4fb79c2d4a417eeb946';
public const PACKAGE_VERSION = '5b59337cedccda38caff556b0acfbe2c4a741d2d';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-11-23 09:54:33';
public const RELEASE_DATE = '2024-11-23 17:32:02';
/**
* @var int
*/
Expand Down
2 changes: 1 addition & 1 deletion src/NodeTypeResolver/PHPStan/Type/TypeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private function removeValueFromConstantType(Type $type) : Type
private function unwrapConstantArrayTypes(ConstantArrayType $constantArrayType) : array
{
$unwrappedTypes = [];
$flattenKeyTypes = TypeUtils::flattenTypes($constantArrayType->getKeyType());
$flattenKeyTypes = TypeUtils::flattenTypes($constantArrayType->getIterableKeyType());
$flattenItemTypes = TypeUtils::flattenTypes($constantArrayType->getIterableValueType());
foreach ($flattenItemTypes as $position => $nestedFlattenItemType) {
$nestedFlattenKeyType = $flattenKeyTypes[$position] ?? null;
Expand Down
2 changes: 1 addition & 1 deletion src/NodeTypeResolver/PHPStan/TypeHasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function createTypeHash(Type $type) : string
return $type->describe(VerbosityLevel::precise()) . $type->isExplicitMixed();
}
if ($type instanceof ArrayType) {
return $this->createTypeHash($type->getIterableValueType()) . $this->createTypeHash($type->getKeyType()) . '[]';
return $this->createTypeHash($type->getIterableValueType()) . $this->createTypeHash($type->getIterableKeyType()) . '[]';
}
if ($type instanceof GenericObjectType) {
return $type->describe(VerbosityLevel::precise());
Expand Down
4 changes: 2 additions & 2 deletions src/NodeTypeResolver/TypeComparator/ArrayTypeComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public function isSubtype($checkedType, $mainType) : bool
if (!$checkedType instanceof ConstantArrayType && !$mainType instanceof ConstantArrayType) {
return $mainType->isSuperTypeOf($checkedType)->yes();
}
$checkedKeyType = $checkedType->getKeyType();
$mainKeyType = $mainType->getKeyType();
$checkedKeyType = $checkedType->getIterableKeyType();
$mainKeyType = $mainType->getIterableKeyType();
if (!$mainKeyType instanceof MixedType && $mainKeyType->isSuperTypeOf($checkedKeyType)->yes()) {
return \true;
}
Expand Down

0 comments on commit 0f5e5b9

Please sign in to comment.