diff --git a/rules-tests/DeadCode/Rector/ClassMethod/RemoveUnusedPromotedPropertyRector/Fixture/skip_public_some_property_readonly.php.inc b/rules-tests/DeadCode/Rector/ClassMethod/RemoveUnusedPromotedPropertyRector/Fixture/skip_public_some_property_readonly.php.inc new file mode 100644 index 00000000000..cc17bc37988 --- /dev/null +++ b/rules-tests/DeadCode/Rector/ClassMethod/RemoveUnusedPromotedPropertyRector/Fixture/skip_public_some_property_readonly.php.inc @@ -0,0 +1,12 @@ + +----- + diff --git a/rules/DeadCode/Rector/ClassMethod/RemoveUnusedPromotedPropertyRector.php b/rules/DeadCode/Rector/ClassMethod/RemoveUnusedPromotedPropertyRector.php index 538d6c8c13d..014c88cd8ae 100644 --- a/rules/DeadCode/Rector/ClassMethod/RemoveUnusedPromotedPropertyRector.php +++ b/rules/DeadCode/Rector/ClassMethod/RemoveUnusedPromotedPropertyRector.php @@ -13,6 +13,8 @@ use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\MethodName; use Rector\Core\ValueObject\PhpVersionFeature; +use Rector\Core\ValueObject\Visibility; +use Rector\Privatization\NodeManipulator\VisibilityManipulator; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -25,6 +27,7 @@ final class RemoveUnusedPromotedPropertyRector extends AbstractRector implements public function __construct( private readonly PropertyFetchFinder $propertyFetchFinder, private readonly PropertyManipulator $propertyManipulator, + private readonly VisibilityManipulator $visibilityManipulator ) { } @@ -93,7 +96,7 @@ public function refactor(Node $node): ?Node foreach ($node->getParams() as $param) { // only private local scope; removing public property might be dangerous - if ($param->flags !== Class_::MODIFIER_PRIVATE) { + if (! $this->visibilityManipulator->hasVisibility($param, Visibility::PRIVATE)) { continue; }