Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DeadCode] Add support for removal readonly property on RemoveUnusedPromotedPropertyRector #1741

Merged
merged 5 commits into from
Jan 29, 2022
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,12 @@
<?php

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector\Fixture;

use stdClass;

class SkipPublicSomePropertyReadonly
{
public function __construct(public readonly stdClass $someUnusedDependency)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector\Fixture;

use stdClass;

class SomePrivatePropertyReadonly
{
public function __construct(private readonly stdClass $someUnusedDependency)
{
}
}

?>
-----
<?php

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector\Fixture;

use stdClass;

class SomePrivatePropertyReadonly
{
public function __construct()
{
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
) {
}

Expand Down Expand Up @@ -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;
}

Expand Down