rector/packages/PhpDocParser/TypeAwareNodeFinder.php
Tomas Votruba 5edd3689a8 Updated Rector to commit bb59a7c99ad30770689fe011c89377402bf6c7ba
bb59a7c99a [DX] Inline symplify/astral to use only active classes (#2851)
2022-08-29 20:49:28 +00:00

47 lines
1.1 KiB
PHP

<?php
declare (strict_types=1);
namespace Rector\PhpDocParser;
use PhpParser\Node;
use PhpParser\NodeFinder;
/**
* @todo remove after https://github.com/nikic/PHP-Parser/pull/869 is released
* @api
*/
final class TypeAwareNodeFinder
{
/**
* @readonly
* @var \PhpParser\NodeFinder
*/
private $nodeFinder;
public function __construct()
{
// to avoid duplicated services on inject
$this->nodeFinder = new NodeFinder();
}
/**
* @template TNode as Node
*
* @param mixed[]|\PhpParser\Node $nodes
* @param class-string<TNode> $type
* @return TNode|null
*/
public function findFirstInstanceOf($nodes, string $type) : ?Node
{
return $this->nodeFinder->findFirstInstanceOf($nodes, $type);
}
/**
* @template TNode as Node
*
* @param mixed[]|\PhpParser\Node $nodes
* @param class-string<TNode> $type
* @return TNode[]
*/
public function findInstanceOf($nodes, string $type) : array
{
return $this->nodeFinder->findInstanceOf($nodes, $type);
}
}