mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 21:38:22 +01:00
Fixes #3930 : TypedPropertyRector should not remove DocBlock comment when it specifies the values contained in an array (#4102)
This commit is contained in:
parent
108c6fd52f
commit
9465173276
1
.gitignore
vendored
1
.gitignore
vendored
@ -21,3 +21,4 @@ rector-recipe.php
|
||||
|
||||
# testing
|
||||
abz
|
||||
/rector-temp-phpstan*.neon
|
@ -16,6 +16,8 @@ use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\NullType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareArrayTypeNode;
|
||||
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareUnionTypeNode;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
@ -250,6 +252,14 @@ PHP
|
||||
|
||||
private function isNonBasicArrayType(Property $property, VarTagValueNode $varTagValueNode): bool
|
||||
{
|
||||
if ($varTagValueNode->type instanceof AttributeAwareUnionTypeNode) {
|
||||
foreach ($varTagValueNode->type->types as $type) {
|
||||
if ($type instanceof AttributeAwareArrayTypeNode && class_exists((string) $type->type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! $this->isArrayTypeNode($varTagValueNode)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture;
|
||||
|
||||
final class DonotRemoveClassDocblockArray
|
||||
{
|
||||
/**
|
||||
* @var \DateTime[]|null
|
||||
*/
|
||||
private $times2;
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture;
|
||||
|
||||
final class DonotRemoveClassDocblockArray
|
||||
{
|
||||
/**
|
||||
* @var \DateTime[]|null
|
||||
*/
|
||||
private ?array $times2 = null;
|
||||
}
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user