Skip to content

Commit 6fb6a41

Browse files
authored
Fix uniquate types in union (#7286)
* add fixture * fix uniquate
1 parent 5d0efae commit 6fb6a41

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\DocblockReturnArrayFromDirectArrayInstanceRector\Fixture\Nesting;
4+
5+
final class AvoidExtremeNesting
6+
{
7+
public function run(): array
8+
{
9+
return [
10+
'key1' => 123,
11+
'key2' => '456.7',
12+
'key3' => 89.0,
13+
'key4' => -42,
14+
'key5' => '12%',
15+
'key6' => -9999,
16+
];
17+
}
18+
}
19+
20+
?>
21+
-----
22+
<?php
23+
24+
namespace Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\DocblockReturnArrayFromDirectArrayInstanceRector\Fixture\Nesting;
25+
26+
final class AvoidExtremeNesting
27+
{
28+
/**
29+
* @return array<string, int|string|float>
30+
*/
31+
public function run(): array
32+
{
33+
return [
34+
'key1' => 123,
35+
'key2' => '456.7',
36+
'key3' => 89.0,
37+
'key4' => -42,
38+
'key5' => '12%',
39+
'key6' => -9999,
40+
];
41+
}
42+
}
43+
44+
?>

rules/Privatization/TypeManipulator/TypeNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function generalizeConstantTypes(Type $type): Type
9898
$uniqueGeneralizedUnionTypes = $this->typeFactory->uniquateTypes($generalizedUnionedTypes);
9999

100100
if (count($uniqueGeneralizedUnionTypes) > 1) {
101-
$generalizedUnionType = new UnionType($generalizedUnionedTypes);
101+
$generalizedUnionType = new UnionType($uniqueGeneralizedUnionTypes);
102102
// avoid too huge print in docblock
103103
$unionedDocType = $this->staticTypeMapper->mapPHPStanTypeToPHPStanPhpDocTypeNode(
104104
$generalizedUnionType

0 commit comments

Comments
 (0)