mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-19 06:18:07 +01:00
503a6059f8
a8922f7431
skip temporarily match + throws downagrade in symfony/console, very unlikely to run
50 lines
1.7 KiB
PHP
50 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\FileSystemRector\Parser;
|
|
|
|
use RectorPrefix202306\Nette\Utils\FileSystem;
|
|
use PhpParser\Node\Stmt;
|
|
use Rector\Core\PhpParser\NodeTraverser\FileWithoutNamespaceNodeTraverser;
|
|
use Rector\Core\PhpParser\Parser\RectorParser;
|
|
use Rector\Core\ValueObject\Application\File;
|
|
use Rector\NodeTypeResolver\NodeScopeAndMetadataDecorator;
|
|
/**
|
|
* Only for testing, @todo move to testing
|
|
*/
|
|
final class FileInfoParser
|
|
{
|
|
/**
|
|
* @readonly
|
|
* @var \Rector\NodeTypeResolver\NodeScopeAndMetadataDecorator
|
|
*/
|
|
private $nodeScopeAndMetadataDecorator;
|
|
/**
|
|
* @readonly
|
|
* @var \Rector\Core\PhpParser\NodeTraverser\FileWithoutNamespaceNodeTraverser
|
|
*/
|
|
private $fileWithoutNamespaceNodeTraverser;
|
|
/**
|
|
* @readonly
|
|
* @var \Rector\Core\PhpParser\Parser\RectorParser
|
|
*/
|
|
private $rectorParser;
|
|
public function __construct(NodeScopeAndMetadataDecorator $nodeScopeAndMetadataDecorator, FileWithoutNamespaceNodeTraverser $fileWithoutNamespaceNodeTraverser, RectorParser $rectorParser)
|
|
{
|
|
$this->nodeScopeAndMetadataDecorator = $nodeScopeAndMetadataDecorator;
|
|
$this->fileWithoutNamespaceNodeTraverser = $fileWithoutNamespaceNodeTraverser;
|
|
$this->rectorParser = $rectorParser;
|
|
}
|
|
/**
|
|
* @api tests only
|
|
* @return Stmt[]
|
|
*/
|
|
public function parseFileInfoToNodesAndDecorate(string $filePath) : array
|
|
{
|
|
$stmts = $this->rectorParser->parseFile($filePath);
|
|
$stmts = $this->fileWithoutNamespaceNodeTraverser->traverse($stmts);
|
|
$file = new File($filePath, FileSystem::read($filePath));
|
|
return $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($file, $stmts);
|
|
}
|
|
}
|