2019-10-13 05:59:52 +00:00
|
|
|
<?php
|
|
|
|
|
2021-05-09 20:15:43 +00:00
|
|
|
declare (strict_types=1);
|
2022-06-06 17:12:56 +00:00
|
|
|
namespace Rector\FileSystemRector\Parser;
|
2019-08-26 09:37:02 +00:00
|
|
|
|
2023-06-01 08:56:46 +00:00
|
|
|
use RectorPrefix202306\Nette\Utils\FileSystem;
|
2022-06-06 17:12:56 +00:00
|
|
|
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;
|
2022-08-30 16:19:25 +00:00
|
|
|
/**
|
|
|
|
* Only for testing, @todo move to testing
|
|
|
|
*/
|
2019-08-26 09:37:02 +00:00
|
|
|
final class FileInfoParser
|
|
|
|
{
|
|
|
|
/**
|
2021-12-04 12:47:17 +00:00
|
|
|
* @readonly
|
2021-05-10 23:39:21 +00:00
|
|
|
* @var \Rector\NodeTypeResolver\NodeScopeAndMetadataDecorator
|
2019-08-26 09:37:02 +00:00
|
|
|
*/
|
2021-05-10 23:39:21 +00:00
|
|
|
private $nodeScopeAndMetadataDecorator;
|
2022-04-25 07:10:07 +00:00
|
|
|
/**
|
|
|
|
* @readonly
|
|
|
|
* @var \Rector\Core\PhpParser\NodeTraverser\FileWithoutNamespaceNodeTraverser
|
|
|
|
*/
|
|
|
|
private $fileWithoutNamespaceNodeTraverser;
|
2019-08-26 09:37:02 +00:00
|
|
|
/**
|
2021-12-04 12:47:17 +00:00
|
|
|
* @readonly
|
2021-10-25 18:49:32 +00:00
|
|
|
* @var \Rector\Core\PhpParser\Parser\RectorParser
|
2019-08-26 09:37:02 +00:00
|
|
|
*/
|
2021-10-25 18:49:32 +00:00
|
|
|
private $rectorParser;
|
2022-06-07 08:22:29 +00:00
|
|
|
public function __construct(NodeScopeAndMetadataDecorator $nodeScopeAndMetadataDecorator, FileWithoutNamespaceNodeTraverser $fileWithoutNamespaceNodeTraverser, RectorParser $rectorParser)
|
2019-08-26 09:37:02 +00:00
|
|
|
{
|
|
|
|
$this->nodeScopeAndMetadataDecorator = $nodeScopeAndMetadataDecorator;
|
2022-04-25 07:10:07 +00:00
|
|
|
$this->fileWithoutNamespaceNodeTraverser = $fileWithoutNamespaceNodeTraverser;
|
2021-10-25 18:49:32 +00:00
|
|
|
$this->rectorParser = $rectorParser;
|
2019-08-26 09:37:02 +00:00
|
|
|
}
|
|
|
|
/**
|
2022-12-23 17:10:25 +00:00
|
|
|
* @api tests only
|
2022-05-22 07:24:14 +00:00
|
|
|
* @return Stmt[]
|
2019-08-26 09:37:02 +00:00
|
|
|
*/
|
2022-09-01 09:30:44 +00:00
|
|
|
public function parseFileInfoToNodesAndDecorate(string $filePath) : array
|
2019-08-26 09:37:02 +00:00
|
|
|
{
|
2022-09-01 09:30:44 +00:00
|
|
|
$stmts = $this->rectorParser->parseFile($filePath);
|
2022-04-25 07:10:07 +00:00
|
|
|
$stmts = $this->fileWithoutNamespaceNodeTraverser->traverse($stmts);
|
2022-09-01 09:30:44 +00:00
|
|
|
$file = new File($filePath, FileSystem::read($filePath));
|
2021-10-25 18:49:32 +00:00
|
|
|
return $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($file, $stmts);
|
2019-08-26 09:37:02 +00:00
|
|
|
}
|
|
|
|
}
|