Skip to content

Commit

Permalink
[Php81] Skip has default value on ReadOnlyPropertyRector (#1355)
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Nov 30, 2021
1 parent 58c8a93 commit 59e9222
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Rector\Tests\Php81\Rector\Property\ReadOnlyPropertyRector\Fixture;

final class SkipHasDefaultValue
{
private string $name = 'default';

public function __construct(string $name)
{
$this->name = $name;
}

public function getName()
{
return $this->name;
}
}
3 changes: 2 additions & 1 deletion rules/Php81/Rector/Property/ReadOnlyPropertyRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\Php81\Rector\Property;

use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\Property;
use Rector\Core\NodeManipulator\PropertyManipulator;
Expand Down Expand Up @@ -88,7 +89,7 @@ public function refactor(Node $node): ?Node
return null;
}

if ($node->isReadonly()) {
if ($node->isReadonly() || $node->props[0]->default instanceof Expr) {
return null;
}

Expand Down

0 comments on commit 59e9222

Please sign in to comment.