diff --git a/rules-tests/TypeDeclarationDocblocks/Rector/Class_/DocblockVarArrayFromPropertyDefaultsRector/Fixture/int_key_inside.php.inc b/rules-tests/TypeDeclarationDocblocks/Rector/Class_/DocblockVarArrayFromPropertyDefaultsRector/Fixture/int_key_inside.php.inc new file mode 100644 index 00000000000..5c16a52841d --- /dev/null +++ b/rules-tests/TypeDeclarationDocblocks/Rector/Class_/DocblockVarArrayFromPropertyDefaultsRector/Fixture/int_key_inside.php.inc @@ -0,0 +1,38 @@ + [ + 'b' => [ + ['c' => 'e', 'f' => 1], + ['d' => 2], + ], + ], + ]; +} + +?> +----- +>>> + */ + private array $array = [ + 'a' => [ + 'b' => [ + ['c' => 'e', 'f' => 1], + ['d' => 2], + ], + ], + ]; +} + +?> \ No newline at end of file diff --git a/rules/Privatization/TypeManipulator/TypeNormalizer.php b/rules/Privatization/TypeManipulator/TypeNormalizer.php index b1b47fcec2d..fae0c78b942 100644 --- a/rules/Privatization/TypeManipulator/TypeNormalizer.php +++ b/rules/Privatization/TypeManipulator/TypeNormalizer.php @@ -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(); } @@ -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()); }