From cf6265db8c9355f1d6830c963f044c5b4a3e31cd Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 16 Sep 2025 21:34:39 +0700 Subject: [PATCH 1/3] [TypeDeclarationDocblocks] Handle multiple objects on AddReturnDocblockDataProviderRector --- .../Fixture/multi_objects.php.inc | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 rules-tests/TypeDeclarationDocblocks/Rector/Class_/AddReturnDocblockDataProviderRector/Fixture/multi_objects.php.inc diff --git a/rules-tests/TypeDeclarationDocblocks/Rector/Class_/AddReturnDocblockDataProviderRector/Fixture/multi_objects.php.inc b/rules-tests/TypeDeclarationDocblocks/Rector/Class_/AddReturnDocblockDataProviderRector/Fixture/multi_objects.php.inc new file mode 100644 index 00000000000..37c86c19b2b --- /dev/null +++ b/rules-tests/TypeDeclarationDocblocks/Rector/Class_/AddReturnDocblockDataProviderRector/Fixture/multi_objects.php.inc @@ -0,0 +1,52 @@ + +----- +>> + */ + public static function provideData(): iterable + { + yield [[new DateTime(), 'format']]; + yield [[new DateTimeImmutable(), 'format']]; + } +} + +?> From 32add879ed9a878b2e66273dbf224126c6411f9a Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 17 Sep 2025 02:51:48 +0700 Subject: [PATCH 2/3] Fix --- rules/Privatization/TypeManipulator/TypeNormalizer.php | 2 +- src/NodeTypeResolver/PHPStan/Type/TypeFactory.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/rules/Privatization/TypeManipulator/TypeNormalizer.php b/rules/Privatization/TypeManipulator/TypeNormalizer.php index ab33a99bf4e..f46bdfe70ff 100644 --- a/rules/Privatization/TypeManipulator/TypeNormalizer.php +++ b/rules/Privatization/TypeManipulator/TypeNormalizer.php @@ -27,7 +27,7 @@ /** * @var int */ - private const MAX_PRINTED_UNION_DOC_LENGHT = 60; + private const MAX_PRINTED_UNION_DOC_LENGHT = 77; public function __construct( private TypeFactory $typeFactory, diff --git a/src/NodeTypeResolver/PHPStan/Type/TypeFactory.php b/src/NodeTypeResolver/PHPStan/Type/TypeFactory.php index 5889ff42534..67f344fa8cb 100644 --- a/src/NodeTypeResolver/PHPStan/Type/TypeFactory.php +++ b/src/NodeTypeResolver/PHPStan/Type/TypeFactory.php @@ -205,6 +205,16 @@ private function unwrapConstantArrayTypes(ConstantArrayType $constantArrayType): $nestedFlattenKeyType = new MixedType(); } + if ($nestedFlattenItemType instanceof ConstantArrayType) { + $innerArrayTypes = $this->unwrapConstantArrayTypes($nestedFlattenItemType); + foreach ($innerArrayTypes as $innerArrayType) { + // preserve outer array -> inner array structure: array + $unwrappedTypes[] = new ArrayType($nestedFlattenKeyType, $innerArrayType); + } + + continue; + } + $unwrappedTypes[] = new ArrayType($nestedFlattenKeyType, $nestedFlattenItemType); } From 23b96e19296f8afc4cec181a5b82635a46c86f5f Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 17 Sep 2025 02:57:00 +0700 Subject: [PATCH 3/3] update complex array --- .../Fixture/Nesting/complex_array.php.inc | 12 ++++++++++++ .../Fixture/multi_objects.php.inc | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockReturnArrayFromDirectArrayInstanceRector/Fixture/Nesting/complex_array.php.inc b/rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockReturnArrayFromDirectArrayInstanceRector/Fixture/Nesting/complex_array.php.inc index 6fa70b2cf4e..3fa83eabde8 100644 --- a/rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockReturnArrayFromDirectArrayInstanceRector/Fixture/Nesting/complex_array.php.inc +++ b/rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockReturnArrayFromDirectArrayInstanceRector/Fixture/Nesting/complex_array.php.inc @@ -8,6 +8,7 @@ class ComplexArray { return [ 'id' => new \stdClass(), + 'other' => false, 'context' => [ 'id' => 1, 'data' => [ @@ -17,6 +18,11 @@ class ComplexArray ], 'values' => [ 'name' => '111', + 'age' => 1, + ], + 'values_other' => [ + 'name' => '111', + 'age' => 1, ], ]; } @@ -37,6 +43,7 @@ class ComplexArray { return [ 'id' => new \stdClass(), + 'other' => false, 'context' => [ 'id' => 1, 'data' => [ @@ -46,6 +53,11 @@ class ComplexArray ], 'values' => [ 'name' => '111', + 'age' => 1, + ], + 'values_other' => [ + 'name' => '111', + 'age' => 1, ], ]; } diff --git a/rules-tests/TypeDeclarationDocblocks/Rector/Class_/AddReturnDocblockDataProviderRector/Fixture/multi_objects.php.inc b/rules-tests/TypeDeclarationDocblocks/Rector/Class_/AddReturnDocblockDataProviderRector/Fixture/multi_objects.php.inc index 37c86c19b2b..8143dbd0569 100644 --- a/rules-tests/TypeDeclarationDocblocks/Rector/Class_/AddReturnDocblockDataProviderRector/Fixture/multi_objects.php.inc +++ b/rules-tests/TypeDeclarationDocblocks/Rector/Class_/AddReturnDocblockDataProviderRector/Fixture/multi_objects.php.inc @@ -40,7 +40,7 @@ final class MultiObjects extends TestCase } /** - * @return \Iterator>> + * @return \Iterator>> */ public static function provideData(): iterable {