Skip to content

Commit

Permalink
[DeadCode] Skip RemoveAlwaysTrueIfConditionRector on property use by @…
Browse files Browse the repository at this point in the history
…var docblock on Trait (#2729)

* [DeadCode] Skip RemoveAlwaysTrueIfConditionRector on property use by @var docblock on Trait

* Fixed 🎉
  • Loading branch information
samsonasik committed Aug 3, 2022
1 parent 3fba7c6 commit 61b6e86
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

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

trait SkipPropertyByVarDocInTrait
{
/** @var Formatter|null */
private $formatter;

public function verify()
{
// if we don't have a formatter, make one
if (! isset($this->formatter)) {
// if no formatter, use the default
$this->formatter = new Formatter();
}

$this->formatter->format();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ private function shouldSkipPropertyFetch(Expr $expr): bool
$classReflection = $this->reflectionResolver->resolveClassReflectionSourceObject($propertyFetch);

if (! $classReflection instanceof ClassReflection) {
continue;
// cannot get parent Trait_ from Property Fetch
return true;
}

$propertyName = (string) $this->nodeNameResolver->getName($propertyFetch);
Expand Down

0 comments on commit 61b6e86

Please sign in to comment.