rector/packages/ReadWrite/NodeAnalyzer/ReadExprAnalyzer.php
Tomas Votruba bdc1df40d9 Updated Rector to commit 1cc465b4d508238445494313f04a6a56d4e8ca1d
1cc465b4d5 [CodingStyle] Skip RemoveUnusedAliasRector when same class in use statement exists, but not used (#732)
2021-08-22 21:22:18 +00:00

36 lines
1.0 KiB
PHP

<?php
declare (strict_types=1);
namespace Rector\ReadWrite\NodeAnalyzer;
use PhpParser\Node\Expr;
use Rector\Core\Exception\NotImplementedYetException;
use Rector\ReadWrite\Contract\ReadNodeAnalyzerInterface;
final class ReadExprAnalyzer
{
/**
* @var \Rector\ReadWrite\Contract\ReadNodeAnalyzerInterface[]
*/
private $readNodeAnalyzers;
/**
* @param ReadNodeAnalyzerInterface[] $readNodeAnalyzers
*/
public function __construct(array $readNodeAnalyzers)
{
$this->readNodeAnalyzers = $readNodeAnalyzers;
}
/**
* Is the value read or used for read purpose (at least, not only)
*/
public function isExprRead(\PhpParser\Node\Expr $expr) : bool
{
foreach ($this->readNodeAnalyzers as $readNodeAnalyzer) {
if (!$readNodeAnalyzer->supports($expr)) {
continue;
}
return $readNodeAnalyzer->isRead($expr);
}
throw new \Rector\Core\Exception\NotImplementedYetException(\get_class($expr));
}
}