[DeadCode] Fix RemoveUnusedPrivatePropertyRector in foreach (#5507)

Co-authored-by: Oliver Nybroe <oliver@worksome.com>
This commit is contained in:
Tomas Votruba 2021-02-11 16:01:41 +01:00 committed by GitHub
parent 65dfaca287
commit 82208c0730
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 6 deletions

View File

@ -10,7 +10,6 @@ use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Return_;
use Rector\Core\Exception\NotImplementedYetException;
use Rector\NodeNestingScope\ParentScopeFinder;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\ReadWrite\NodeFinder\NodeUsageFinder;
@ -58,10 +57,7 @@ abstract class AbstractReadNodeAnalyzer
return $parentParent->var !== $parent;
}
if ($parent instanceof Expression) {
return false;
}
throw new NotImplementedYetException();
// assume it's used by default
return ! $parent instanceof Expression;
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace Rector\DeadCode\Tests\Rector\Property\RemoveUnusedPrivatePropertyRector\Fixture;
class RemoveMagicProperty
{
private $unusedProp;
public function buildMailData(object $recipient)
{
$this->mails_to_send[$recipient->email] = "";
foreach ($this->mails_to_send as $email) {
}
}
}
?>
-----
<?php
namespace Rector\DeadCode\Tests\Rector\Property\RemoveUnusedPrivatePropertyRector\Fixture;
class RemoveMagicProperty
{
public function buildMailData(object $recipient)
{
$this->mails_to_send[$recipient->email] = "";
foreach ($this->mails_to_send as $email) {
}
}
}
?>