Skip to content

Commit 77b0f25

Browse files
authored
skip mixed[] on ClassMethodArrayDocblockParamFromLocalCallsRector as no extra value (#7270)
1 parent 87b1e0d commit 77b0f25

4 files changed

Lines changed: 43 additions & 6 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclarationDocblocks\Rector\Class_\ClassMethodArrayDocblockParamFromLocalCallsRector\Fixture;
4+
5+
final class SkipMixedMixed
6+
{
7+
public function go($mixed)
8+
{
9+
$this->run(['item1', 'item2']);
10+
11+
$this->run([$mixed, $mixed]);
12+
}
13+
14+
private function run(array $items)
15+
{
16+
}
17+
}

rules/Privatization/TypeManipulator/TypeNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class TypeNormalizer
2525
* @deprecated This method is deprecated and will be removed in the next major release.
2626
* Use @see generalizeConstantTypes() instead.
2727
*/
28-
public function generalizeConstantBoolTypes(\PHPStan\Type\Type $type): Type
28+
public function generalizeConstantBoolTypes(Type $type): Type
2929
{
3030
return $this->generalizeConstantTypes($type);
3131
}

rules/TypeDeclarationDocblocks/Rector/Class_/AddReturnDocblockDataProviderRector.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,9 @@ public function refactor(Node $node): ?Node
154154
if ($yields !== []) {
155155
$yieldType = $this->yieldTypeResolver->resolveFromYieldNodes($yields, $dataProviderClassMethod);
156156

157-
if ($yieldType instanceof FullyQualifiedGenericObjectType) {
158-
if ($yieldType->getClassName() === 'Generator') {
159-
// most likely, a static iterator is used in data test fixtures
160-
$yieldType = new FullyQualifiedGenericObjectType('Iterator', $yieldType->getTypes());
161-
}
157+
if ($yieldType instanceof FullyQualifiedGenericObjectType && $yieldType->getClassName() === 'Generator') {
158+
// most likely, a static iterator is used in data test fixtures
159+
$yieldType = new FullyQualifiedGenericObjectType('Iterator', $yieldType->getTypes());
162160
}
163161

164162
$this->addGeneratedTypeReturnDocblockType($yieldType, $classMethodPhpDocInfo, $dataProviderClassMethod);

rules/TypeDeclarationDocblocks/Rector/Class_/ClassMethodArrayDocblockParamFromLocalCallsRector.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
use PhpParser\Node;
88
use PhpParser\Node\Stmt\Class_;
99
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
10+
use PHPStan\Type\ArrayType;
11+
use PHPStan\Type\IntegerType;
12+
use PHPStan\Type\MixedType;
1013
use PHPStan\Type\Type;
1114
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
1215
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
@@ -119,6 +122,12 @@ public function refactor(Node $node): ?Node
119122
$normalizedResolvedParameterType = $this->typeNormalizer->generalizeConstantTypes(
120123
$resolvedParameterType
121124
);
125+
126+
// most likely mixed, skip
127+
if ($this->isArrayMixed($normalizedResolvedParameterType)) {
128+
continue;
129+
}
130+
122131
$arrayDocTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPHPStanPhpDocTypeNode(
123132
$normalizedResolvedParameterType
124133
);
@@ -137,4 +146,17 @@ public function refactor(Node $node): ?Node
137146

138147
return $node;
139148
}
149+
150+
private function isArrayMixed(Type $type): bool
151+
{
152+
if (! $type instanceof ArrayType) {
153+
return false;
154+
}
155+
156+
if (! $type->getItemType() instanceof MixedType) {
157+
return false;
158+
}
159+
160+
return $type->getKeyType() instanceof IntegerType;
161+
}
140162
}

0 commit comments

Comments
 (0)