Skip to content
Open
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,35 @@
<?php

namespace Rector\Tests\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector\Fixture;

final class AsymmetricVisibility
{
protected protected(set) string $name = 'a';

protected private(set) string $other = 'b';

public function __construct(
protected protected(set) int $promoted,
) {
}
}

?>
-----
<?php

namespace Rector\Tests\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector\Fixture;

final class AsymmetricVisibility
{
private string $name = 'a';

private string $other = 'b';

public function __construct(
private int $promoted,
) {
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Rector\Tests\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector\Fixture;

final class SkipPublicAsymmetricVisibility
{
public protected(set) string $name = 'a';

protected(set) string $other = 'b';

public function __construct(
public protected(set) int $promoted,
) {
}
}
5 changes: 5 additions & 0 deletions rules/Privatization/NodeManipulator/VisibilityManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ public function makePrivate(ClassMethod|Property|ClassConst|Param $node): void
{
$this->replaceVisibilityFlag($node, Visibility::PRIVATE);

// private property cannot have wider set visibility, and private(set) is redundant
if ($node instanceof Property || $node instanceof Param) {
$node->flags &= ~Modifiers::VISIBILITY_SET_MASK;
}

// only constructor can be both private and final
if ($node instanceof ClassMethod && $this->nodeNameResolver->isName($node, MethodName::CONSTRUCT)) {
return;
Expand Down
Loading