rector/packages/FileSystemRector/Parser/FileInfoParser.php
Tomas Votruba 6981c70c9a Updated Rector to commit 9ed8c21b127cdd45a28307d5fc41668f867f4ef4
9ed8c21b12 [DeadCode] Remove findFirstPrevious() usage on UselessIfCondBeforeForeachDetector (#4388)
2023-07-01 09:41:56 +00:00

52 lines
1.6 KiB
PHP

<?php
declare (strict_types=1);
namespace Rector\FileSystemRector\Parser;
use RectorPrefix202307\Nette\Utils\FileSystem;
use PhpParser\Node\Stmt;
use Rector\Core\PhpParser\Parser\RectorParser;
use Rector\Core\Provider\CurrentFileProvider;
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\Parser\RectorParser
*/
private $rectorParser;
/**
* @readonly
* @var \Rector\Core\Provider\CurrentFileProvider
*/
private $currentFileProvider;
public function __construct(NodeScopeAndMetadataDecorator $nodeScopeAndMetadataDecorator, RectorParser $rectorParser, CurrentFileProvider $currentFileProvider)
{
$this->nodeScopeAndMetadataDecorator = $nodeScopeAndMetadataDecorator;
$this->rectorParser = $rectorParser;
$this->currentFileProvider = $currentFileProvider;
}
/**
* @api tests only
* @return Stmt[]
*/
public function parseFileInfoToNodesAndDecorate(string $filePath) : array
{
$stmts = $this->rectorParser->parseFile($filePath);
$file = new File($filePath, FileSystem::read($filePath));
$stmts = $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($file, $stmts);
$file->hydrateStmtsAndTokens($stmts, $stmts, []);
$this->currentFileProvider->setFile($file);
return $stmts;
}
}