mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-07 11:50:51 +00:00
727b9f46f0
bfa1891c50
[cleanup] Remove 73 unused public methods (#3245)
47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\Core\PhpParser\Parser;
|
|
|
|
use RectorPrefix202212\Nette\Utils\FileSystem;
|
|
use PhpParser\Node\Stmt;
|
|
use PhpParser\NodeTraverser;
|
|
use PhpParser\NodeVisitor\NodeConnectingVisitor;
|
|
use PhpParser\Parser;
|
|
use PhpParser\ParserFactory;
|
|
final class SimplePhpParser
|
|
{
|
|
/**
|
|
* @readonly
|
|
* @var \PhpParser\Parser
|
|
*/
|
|
private $phpParser;
|
|
public function __construct()
|
|
{
|
|
$parserFactory = new ParserFactory();
|
|
$this->phpParser = $parserFactory->create(ParserFactory::PREFER_PHP7);
|
|
}
|
|
/**
|
|
* @api tests
|
|
* @return Stmt[]
|
|
*/
|
|
public function parseFile(string $filePath) : array
|
|
{
|
|
$fileContent = FileSystem::read($filePath);
|
|
return $this->parseString($fileContent);
|
|
}
|
|
/**
|
|
* @return Stmt[]
|
|
*/
|
|
public function parseString(string $fileContent) : array
|
|
{
|
|
$stmts = $this->phpParser->parse($fileContent);
|
|
if ($stmts === null) {
|
|
return [];
|
|
}
|
|
$nodeTraverser = new NodeTraverser();
|
|
$nodeTraverser->addVisitor(new NodeConnectingVisitor());
|
|
return $nodeTraverser->traverse($stmts);
|
|
}
|
|
}
|