Skip to content

Commit

Permalink
[DeadCode] Skip with magic __get() on RemoveUnusedPromotedPropertyRec…
Browse files Browse the repository at this point in the history
…tor (#5573)

* [DeadCode] Skip with magic __get() on RemoveUnusedPromotedPropertyRector

* clean up
  • Loading branch information
samsonasik committed Feb 7, 2024
1 parent af4d3db commit bd37496
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector\Fixture;

class SkipWithMagicGet
{
private function __construct(
private readonly int $id,
private string $name,
private array $email,
private string $country,
private readonly ?Time $created_at,
private readonly ?Time $updated_at,
) {
}

public function __get(string $name)
{
if (! property_exists($this, $name)) {
throw new \LogicException('No such property: ' . $name);
}

return $this->{$name};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ private function shouldSkipClass(Class_ $class): bool
return true;
}

$magicGetMethod = $class->getMethod(MethodName::__GET);
if ($magicGetMethod instanceof ClassMethod) {
return true;
}

foreach ($class->stmts as $stmt) {
if ($stmt instanceof TraitUse) {
return true;
Expand Down

0 comments on commit bd37496

Please sign in to comment.