Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Rector\Tests\TypeDeclarationDocblocks\Rector\Class_\DocblockVarArrayFromPropertyDefaultsRector\Fixture;

final class IntKeyInside
{
private array $array = [
'a' => [
'b' => [
['c' => 'e', 'f' => 1],
['d' => 2],
],
],
];
}

?>
-----
<?php

namespace Rector\Tests\TypeDeclarationDocblocks\Rector\Class_\DocblockVarArrayFromPropertyDefaultsRector\Fixture;

final class IntKeyInside
{
/**
* @var array<string, array<string, array<int, array<string, string|int>>>>
*/
private array $array = [
'a' => [
'b' => [
['c' => 'e', 'f' => 1],
['d' => 2],
],
],
];
}

?>
6 changes: 4 additions & 2 deletions rules/Privatization/TypeManipulator/TypeNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ public function generalizeConstantBoolTypes(Type $type): Type
*/
public function generalizeConstantTypes(Type $type): Type
{
return TypeTraverser::map($type, function (Type $type, callable $traverseCallback): Type {
$deep = 0;
return TypeTraverser::map($type, function (Type $type, callable $traverseCallback) use (&$deep): Type {
++$deep;
if ($type instanceof AccessoryNonFalsyStringType || $type instanceof AccessoryLiteralStringType || $type instanceof AccessoryNonEmptyStringType) {
return new StringType();
}
Expand All @@ -81,7 +83,7 @@ public function generalizeConstantTypes(Type $type): Type
if ($type instanceof ConstantArrayType) {
// is relevant int constantArrayType?
if ($this->isImplicitNumberedListKeyType($type)) {
$keyType = new MixedType();
$keyType = $deep === 1 ? new MixedType() : new IntegerType();
} else {
$keyType = $this->generalizeConstantTypes($type->getKeyType());
}
Expand Down