Skip to content

Commit

Permalink
fix(rules): Skip readonly classes from restoring default null value. (#…
Browse files Browse the repository at this point in the history
…4479)

* fix(rules): Skip readonly classes from restoring default null value.

* Update rules-tests/Php74/Rector/Property/RestoreDefaultNullToNullableTypePropertyRector/Fixture/skip_readonly_class.php.inc

---------

Co-authored-by: Marcin Czarnecki <marcin.czarnecki@westwing.pl>
Co-authored-by: Abdul Malik Ikhsan <samsonasik@gmail.com>
  • Loading branch information
3 people authored Jul 11, 2023
1 parent dd6a1fb commit 4fbeab8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Rector\Tests\Php74\Rector\Property\RestoreDefaultNullToNullableTypePropertyRector\Fixture;

final readonly class SkipReadonlyClass
{
public string|null $display;
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
if ($node->isReadonly()) {
return null;
}

$hasChanged = false;

foreach ($node->getProperties() as $property) {
Expand Down

0 comments on commit 4fbeab8

Please sign in to comment.