mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-01 08:50:50 +00:00
[CodingStyle] Skip readonly type property on AddArrayDefaultToArrayPropertyRector (#2196)
* Add failing test fixture for AddArrayDefaultToArrayPropertyRector # Failing Test for AddArrayDefaultToArrayPropertyRector Based on https://getrector.org/demo/0cb77e6c-9502-44fa-9ecd-e4d46838e7a2 * Closes #2195 * clean up Co-authored-by: Martin Kluska <martin@kluska.cz>
This commit is contained in:
parent
b33f8a529d
commit
3e685a63ee
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\CodingStyle\Rector\Class_\AddArrayDefaultToArrayPropertyRector\Fixture;
|
||||
|
||||
abstract class SkipReadonlyProperty
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public readonly array $changes;
|
||||
|
||||
public function __construct(Model $model)
|
||||
{
|
||||
$this->changes = $model->getChanges();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -22,6 +22,7 @@ use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
|
|||
use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\Privatization\NodeManipulator\VisibilityManipulator;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
|
@ -34,7 +35,8 @@ final class AddArrayDefaultToArrayPropertyRector extends AbstractRector
|
|||
public function __construct(
|
||||
private readonly PropertyFetchAnalyzer $propertyFetchAnalyzer,
|
||||
private readonly IterableTypeAnalyzer $iterableTypeAnalyzer,
|
||||
private readonly ArgsAnalyzer $argsAnalyzer
|
||||
private readonly ArgsAnalyzer $argsAnalyzer,
|
||||
private readonly VisibilityManipulator $visibilityManipulator
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -127,6 +129,15 @@ CODE_SAMPLE
|
|||
return null;
|
||||
}
|
||||
|
||||
$property = $node->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if (! $property instanceof Property) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->visibilityManipulator->isReadonly($property)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$propertyNames[] = $this->getName($node);
|
||||
|
||||
return null;
|
||||
|
|
Loading…
Reference in New Issue
Block a user