Skip to content

Commit

Permalink
Fix/do not inline constructor default when readonly (#2720)
Browse files Browse the repository at this point in the history
* fix: inline constructor default readonly

* test: inline constructor default readonly
  • Loading branch information
kpn13 committed Jul 28, 2022
1 parent d94353a commit ec291c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
@@ -0,0 +1,13 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector\Fixture;

final class DoNotChangeReadonly
{
private readonly string $name;

public function __construct()
{
$this->name = 'John';
}
}
Expand Up @@ -83,6 +83,10 @@ public function refactor(Node $node): ?Node
continue;
}

if ($property->isReadonly()) {
continue;
}

$propertyProperty = $property->props[0];
$propertyProperty->default = $defaultPropertyExprAssign->getDefaultExpr();

Expand Down

0 comments on commit ec291c4

Please sign in to comment.