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

namespace Rector\Tests\DeadCode\Rector\Property\RemoveDefaultValueFromAssignedPropertyRector\Fixture;

class SkipProtectedPropertyOnNonFinalClass
{
protected int $value = 5;

public function __construct(int $value)
{
$this->value = $value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Return_;
use Rector\Configuration\Parameter\FeatureFlags;
use Rector\NodeAnalyzer\PropertyFetchAnalyzer;
use Rector\PhpParser\Node\BetterNodeFinder;
use Rector\Rector\AbstractRector;
Expand Down Expand Up @@ -89,6 +90,7 @@ public function refactor(Node $node): ?Node
}

$hasChanged = false;
$isFinal = $node->isFinal() || FeatureFlags::treatClassesAsFinal($node);

foreach ($node->getProperties() as $property) {
// untyped properties are handled by RemoveNullPropertyInitializationRector
Expand All @@ -100,6 +102,10 @@ public function refactor(Node $node): ?Node
continue;
}

if (! $property->isPrivate() && ! $isFinal) {
continue;
}

foreach ($property->props as $propertyProperty) {
if (! $propertyProperty->default instanceof Expr) {
continue;
Expand Down
Loading