move CurrentFileProvider to NodeTraverserQueue

This commit is contained in:
TomasVotruba 2017-09-30 16:15:59 +02:00
parent 65d5bce779
commit 50477e0a60
2 changed files with 12 additions and 14 deletions

View File

@ -4,6 +4,7 @@ namespace Rector\NodeTraverserQueue;
use PhpParser\Lexer;
use Rector\Contract\Parser\ParserInterface;
use Rector\FileSystem\CurrentFileProvider;
use Rector\NodeTraverser\CloningNodeTraverser;
use Rector\NodeTraverser\RectorNodeTraverser;
use Rector\NodeTraverser\ShutdownNodeTraverser;
@ -47,13 +48,19 @@ final class NodeTraverserQueue
*/
private $standaloneTraverseNodeTraverser;
/**
* @var CurrentFileProvider
*/
private $currentFileProvider;
public function __construct(
ParserInterface $parser,
Lexer $lexer,
CloningNodeTraverser $cloningNodeTraverser,
RectorNodeTraverser $rectorNodeTraverser,
ShutdownNodeTraverser $shutdownNodeTraverser,
StandaloneTraverseNodeTraverser $standaloneTraverseNodeTraverser
StandaloneTraverseNodeTraverser $standaloneTraverseNodeTraverser,
CurrentFileProvider $currentFileProvider
) {
$this->parser = $parser;
$this->lexer = $lexer;
@ -61,6 +68,7 @@ final class NodeTraverserQueue
$this->cloningNodeTraverser = $cloningNodeTraverser;
$this->shutdownNodeTraverser = $shutdownNodeTraverser;
$this->standaloneTraverseNodeTraverser = $standaloneTraverseNodeTraverser;
$this->currentFileProvider = $currentFileProvider;
}
/**
@ -68,6 +76,8 @@ final class NodeTraverserQueue
*/
public function processFileInfo(SplFileInfo $fileInfo): array
{
$this->currentFileProvider->setCurrentFile($fileInfo);
try {
$oldStmts = $this->parser->parseFile($fileInfo->getRealPath());
$oldTokens = $this->lexer->getTokens();

View File

@ -2,7 +2,6 @@
namespace Rector\Application;
use Rector\FileSystem\CurrentFileProvider;
use Rector\NodeTraverser\RectorNodeTraverser;
use Rector\NodeTraverserQueue\NodeTraverserQueue;
use Rector\Printer\FormatPerservingPrinter;
@ -25,21 +24,14 @@ final class FileProcessor
*/
private $rectorNodeTraverser;
/**
* @var CurrentFileProvider
*/
private $currentFileProvider;
public function __construct(
FormatPerservingPrinter $codeStyledPrinter,
NodeTraverserQueue $nodeTraverserQueue,
RectorNodeTraverser $rectorNodeTraverser,
CurrentFileProvider $currentFileProvider
RectorNodeTraverser $rectorNodeTraverser
) {
$this->formatPerservingPrinter = $codeStyledPrinter;
$this->nodeTraverserQueue = $nodeTraverserQueue;
$this->rectorNodeTraverser = $rectorNodeTraverser;
$this->currentFileProvider = $currentFileProvider;
}
/**
@ -54,8 +46,6 @@ final class FileProcessor
public function processFile(SplFileInfo $fileInfo): void
{
$this->currentFileProvider->setCurrentFile($fileInfo);
[$newStmts, $oldStmts, $oldTokens] = $this->nodeTraverserQueue->processFileInfo($fileInfo);
$this->formatPerservingPrinter->printToFile($fileInfo, $newStmts, $oldStmts, $oldTokens);
@ -66,8 +56,6 @@ final class FileProcessor
*/
private function processFileToString(SplFileInfo $fileInfo): string
{
$this->currentFileProvider->setCurrentFile($fileInfo);
[$newStmts, $oldStmts, $oldTokens] = $this->nodeTraverserQueue->processFileInfo($fileInfo);
return $this->formatPerservingPrinter->printToString($newStmts, $oldStmts, $oldTokens);