Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Rector\Tests\TypeDeclarationDocblocks\Rector\Class_\ClassMethodArrayDocblockParamFromLocalCallsRector\Fixture;

final class SkipMixedMixed
{
public function go($mixed)
{
$this->run(['item1', 'item2']);

$this->run([$mixed, $mixed]);
}

private function run(array $items)
{
}
}
2 changes: 1 addition & 1 deletion rules/Privatization/TypeManipulator/TypeNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class TypeNormalizer
* @deprecated This method is deprecated and will be removed in the next major release.
* Use @see generalizeConstantTypes() instead.
*/
public function generalizeConstantBoolTypes(\PHPStan\Type\Type $type): Type
public function generalizeConstantBoolTypes(Type $type): Type
{
return $this->generalizeConstantTypes($type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,9 @@ public function refactor(Node $node): ?Node
if ($yields !== []) {
$yieldType = $this->yieldTypeResolver->resolveFromYieldNodes($yields, $dataProviderClassMethod);

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

$this->addGeneratedTypeReturnDocblockType($yieldType, $classMethodPhpDocInfo, $dataProviderClassMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use PHPStan\Type\ArrayType;
use PHPStan\Type\IntegerType;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
Expand Down Expand Up @@ -119,6 +122,12 @@ public function refactor(Node $node): ?Node
$normalizedResolvedParameterType = $this->typeNormalizer->generalizeConstantTypes(
$resolvedParameterType
);

// most likely mixed, skip
if ($this->isArrayMixed($normalizedResolvedParameterType)) {
continue;
}

$arrayDocTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPHPStanPhpDocTypeNode(
$normalizedResolvedParameterType
);
Expand All @@ -137,4 +146,17 @@ public function refactor(Node $node): ?Node

return $node;
}

private function isArrayMixed(Type $type): bool
{
if (! $type instanceof ArrayType) {
return false;
}

if (! $type->getItemType() instanceof MixedType) {
return false;
}

return $type->getKeyType() instanceof IntegerType;
}
}
Loading