Skip to content

Commit

Permalink
[DeadCode] Skip property not exists on RemoveTypedPropertyDeadInstanc…
Browse files Browse the repository at this point in the history
…eOfRector (#4481)
  • Loading branch information
samsonasik authored Jul 11, 2023
1 parent db16e33 commit dd6a1fb
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Rector\Tests\DeadCode\Rector\If_\RemoveTypedPropertyDeadInstanceOfRector\Fixture;

/**
* @property Document|Course|Book $target
*/
class SearchResultClickedResource
{
/**
* @return 'document'|'course'|'book'|'unknown'
*/
private function getType(): string
{
if ($this->target instanceof Document) {
return 'document';
}

if ($this->target instanceof Course) {
return 'course';
}

if ($this->target instanceof Book) {
return 'book';
}

return 'unknown';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\DeadCode\Rector\If_\RemoveTypedPropertyDeadInstanceOfRector\Source;

class Book
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\DeadCode\Rector\If_\RemoveTypedPropertyDeadInstanceOfRector\Source;

class Course
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\DeadCode\Rector\If_\RemoveTypedPropertyDeadInstanceOfRector\Source;

class Document
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ private function isSkippedPropertyFetch(Class_ $class, PropertyFetch|StaticPrope

$property = $class->getProperty($propertyName);
if (! $property instanceof Property) {
return false;
return true;
}

return $property->type === null;
Expand Down

0 comments on commit dd6a1fb

Please sign in to comment.