From 4b02caa187605f4b9714030f76f8bdecb6ca1589 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 15 Sep 2025 12:48:29 +0200 Subject: [PATCH 1/2] add fixture --- .../Fixture/Nesting/not_too_complex.php.inc | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockReturnArrayFromDirectArrayInstanceRector/Fixture/Nesting/not_too_complex.php.inc diff --git a/rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockReturnArrayFromDirectArrayInstanceRector/Fixture/Nesting/not_too_complex.php.inc b/rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockReturnArrayFromDirectArrayInstanceRector/Fixture/Nesting/not_too_complex.php.inc new file mode 100644 index 00000000000..8d8b4db6c97 --- /dev/null +++ b/rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockReturnArrayFromDirectArrayInstanceRector/Fixture/Nesting/not_too_complex.php.inc @@ -0,0 +1,45 @@ + 1000, + 'bookStock' => '1000.0', + 'dipStock' => 100.5, + 'lossGain' => -1000, + 'lossGainPercentage' => '1000%', + 'accumulatedLossGain' => -135000, + ]; + } +} + +?> +----- + + */ + public function run(): array + { + return [ + 'receipts' => 1000, + 'sales' => 1000, + 'bookStock' => '1000.0', + 'dipStock' => 100.5, + 'lossGain' => -1000, + 'lossGainPercentage' => '1000%', + 'accumulatedLossGain' => -135000, + ]; + } +} + +?> From 2f5acd9daeef3d5d9355661422a81a32f8ffca77 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 15 Sep 2025 12:50:08 +0200 Subject: [PATCH 2/2] fix uniquate --- .../Fixture/Nesting/not_too_complex.php.inc | 25 +++++++++---------- .../TypeManipulator/TypeNormalizer.php | 2 +- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockReturnArrayFromDirectArrayInstanceRector/Fixture/Nesting/not_too_complex.php.inc b/rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockReturnArrayFromDirectArrayInstanceRector/Fixture/Nesting/not_too_complex.php.inc index 8d8b4db6c97..20f86cb5131 100644 --- a/rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockReturnArrayFromDirectArrayInstanceRector/Fixture/Nesting/not_too_complex.php.inc +++ b/rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockReturnArrayFromDirectArrayInstanceRector/Fixture/Nesting/not_too_complex.php.inc @@ -7,12 +7,12 @@ final class AvoidExtremeNesting public function run(): array { return [ - 'receipts' => 1000, - 'bookStock' => '1000.0', - 'dipStock' => 100.5, - 'lossGain' => -1000, - 'lossGainPercentage' => '1000%', - 'accumulatedLossGain' => -135000, + 'key1' => 123, + 'key2' => '456.7', + 'key3' => 89.0, + 'key4' => -42, + 'key5' => '12%', + 'key6' => -9999, ]; } } @@ -31,13 +31,12 @@ final class AvoidExtremeNesting public function run(): array { return [ - 'receipts' => 1000, - 'sales' => 1000, - 'bookStock' => '1000.0', - 'dipStock' => 100.5, - 'lossGain' => -1000, - 'lossGainPercentage' => '1000%', - 'accumulatedLossGain' => -135000, + 'key1' => 123, + 'key2' => '456.7', + 'key3' => 89.0, + 'key4' => -42, + 'key5' => '12%', + 'key6' => -9999, ]; } } diff --git a/rules/Privatization/TypeManipulator/TypeNormalizer.php b/rules/Privatization/TypeManipulator/TypeNormalizer.php index cf395806d90..90664309bdd 100644 --- a/rules/Privatization/TypeManipulator/TypeNormalizer.php +++ b/rules/Privatization/TypeManipulator/TypeNormalizer.php @@ -98,7 +98,7 @@ public function generalizeConstantTypes(Type $type): Type $uniqueGeneralizedUnionTypes = $this->typeFactory->uniquateTypes($generalizedUnionedTypes); if (count($uniqueGeneralizedUnionTypes) > 1) { - $generalizedUnionType = new UnionType($generalizedUnionedTypes); + $generalizedUnionType = new UnionType($uniqueGeneralizedUnionTypes); // avoid too huge print in docblock $unionedDocType = $this->staticTypeMapper->mapPHPStanTypeToPHPStanPhpDocTypeNode( $generalizedUnionType