mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-01 08:50:50 +00:00
[Php80] Do not remove array<mixed> inside Union type on UnionTypesRector (#2358)
* [Php80] Do not remove array<mixed> inside Union type on UnionTypesRector
* Fixed 🎉
* also allow mixed[]
* clean up
* clean up
This commit is contained in:
parent
e1ecbe90fc
commit
4c53b206a4
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Rector\Tests\Php80\Rector\FunctionLike\UnionTypesRector\Fixture;
|
||||
|
||||
final class RemoveDocArrayTyped
|
||||
final class DoNotRemoveDocArrayTypedMixed
|
||||
{
|
||||
/**
|
||||
* @return bool|float|int|string|array<mixed>
|
||||
|
@ -19,8 +19,11 @@ final class RemoveDocArrayTyped
|
|||
|
||||
namespace Rector\Tests\Php80\Rector\FunctionLike\UnionTypesRector\Fixture;
|
||||
|
||||
final class RemoveDocArrayTyped
|
||||
final class DoNotRemoveDocArrayTypedMixed
|
||||
{
|
||||
/**
|
||||
* @return bool|float|int|string|array<mixed>
|
||||
*/
|
||||
public function normalizeNodeValue($value): bool|float|int|string|array
|
||||
{
|
||||
return $value;
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Rector\Tests\Php80\Rector\FunctionLike\UnionTypesRector\Fixture;
|
||||
|
||||
final class RemoveDocArrayTyped2
|
||||
final class DoNotRemoveDocArrayTypedMixed2
|
||||
{
|
||||
/**
|
||||
* @param bool|float|int|string|array<mixed> $value
|
||||
|
@ -19,8 +19,11 @@ final class RemoveDocArrayTyped2
|
|||
|
||||
namespace Rector\Tests\Php80\Rector\FunctionLike\UnionTypesRector\Fixture;
|
||||
|
||||
final class RemoveDocArrayTyped2
|
||||
final class DoNotRemoveDocArrayTypedMixed2
|
||||
{
|
||||
/**
|
||||
* @param bool|float|int|string|array<mixed> $value
|
||||
*/
|
||||
public function normalizeNodeValue(bool|float|int|string|array $value)
|
||||
{
|
||||
return $value;
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Php80\Rector\FunctionLike\UnionTypesRector\Fixture;
|
||||
|
||||
final class DoNotRemoveDocArrayTypedMixed3
|
||||
{
|
||||
/**
|
||||
* @param bool|float|int|string|mixed[] $value
|
||||
*/
|
||||
public function normalizeNodeValue($value)
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Php80\Rector\FunctionLike\UnionTypesRector\Fixture;
|
||||
|
||||
final class DoNotRemoveDocArrayTypedMixed3
|
||||
{
|
||||
/**
|
||||
* @param bool|float|int|string|mixed[] $value
|
||||
*/
|
||||
public function normalizeNodeValue(bool|float|int|string|array $value)
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Php80\Rector\FunctionLike\UnionTypesRector\Fixture;
|
||||
|
||||
final class SkipWithArrayMixed
|
||||
{
|
||||
/**
|
||||
* @param object|array<mixed> $foo
|
||||
* @param array<mixed> $bar
|
||||
*/
|
||||
public function run(object|array $foo, array $bar): int
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@ use Rector\BetterPhpDocParser\ValueObject\PhpDoc\VariadicAwareParamTagValueNode;
|
|||
use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey;
|
||||
use Rector\BetterPhpDocParser\ValueObject\Type\BracketsAwareUnionTypeNode;
|
||||
use Rector\DeadCode\TypeNodeAnalyzer\GenericTypeNodeAnalyzer;
|
||||
use Rector\DeadCode\TypeNodeAnalyzer\MixedArrayTypeNodeAnalyzer;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\TypeComparator\TypeComparator;
|
||||
|
||||
|
@ -29,6 +30,7 @@ final class DeadParamTagValueNodeAnalyzer
|
|||
private readonly NodeNameResolver $nodeNameResolver,
|
||||
private readonly TypeComparator $typeComparator,
|
||||
private readonly GenericTypeNodeAnalyzer $genericTypeNodeAnalyzer,
|
||||
private readonly MixedArrayTypeNodeAnalyzer $mixedArrayTypeNodeAnalyzer
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -63,6 +65,10 @@ final class DeadParamTagValueNodeAnalyzer
|
|||
return $this->isEmptyDescription($paramTagValueNode, $param->type);
|
||||
}
|
||||
|
||||
if ($this->mixedArrayTypeNodeAnalyzer->hasMixedArrayType($paramTagValueNode->type)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->genericTypeNodeAnalyzer->hasGenericType($paramTagValueNode->type)) {
|
||||
return $this->isEmptyDescription($paramTagValueNode, $param->type);
|
||||
}
|
||||
|
|
|
@ -15,10 +15,6 @@ final class GenericTypeNodeAnalyzer
|
|||
|
||||
foreach ($types as $type) {
|
||||
if ($type instanceof GenericTypeNode) {
|
||||
if ($type->type->name === 'array') {
|
||||
continue;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user