Skip to content

Commit

Permalink
[ci-review] Rector Rectify
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizen-ci authored and TomasVotruba committed Apr 12, 2021
1 parent 99c6490 commit 2093c5b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment;
use Symplify\ComposerJsonManipulator\ComposerJsonFactory;
use Symplify\ComposerJsonManipulator\Printer\ComposerJsonPrinter;
use Symplify\SmartFileSystem\SmartFileInfo;

final class ComposerFileProcessor implements FileProcessorInterface
{
Expand Down Expand Up @@ -89,8 +90,11 @@ private function processFile(File $file): void
$file->changeFileContent($changeFileContent);
}

private function isJsonInTests(\Symplify\SmartFileSystem\SmartFileInfo $fileInfo): bool
private function isJsonInTests(SmartFileInfo $fileInfo): bool
{
return StaticPHPUnitEnvironment::isPHPUnitRun() && $fileInfo->hasSuffixes(['json']);
if (! StaticPHPUnitEnvironment::isPHPUnitRun()) {
return false;
}
return $fileInfo->hasSuffixes(['json']);
}
}
95 changes: 1 addition & 94 deletions src/Application/FileProcessor/PhpFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,19 @@

namespace Rector\Core\Application\FileProcessor;

use PhpParser\Lexer;
use PHPStan\AnalysedCodeException;
use Rector\ChangesReporting\Application\ErrorAndDiffCollector;
use Rector\ChangesReporting\Collector\AffectedFilesCollector;
use Rector\Core\Application\FileDecorator\FileDiffFileDecorator;
use Rector\Core\Application\FileProcessor;
use Rector\Core\Application\FileSystem\RemovedAndAddedFilesCollector;
use Rector\Core\Application\FileSystem\RemovedAndAddedFilesProcessor;
use Rector\Core\Application\TokensByFilePathStorage;
use Rector\Core\Configuration\Configuration;
use Rector\Core\Contract\Processor\FileProcessorInterface;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\PhpParser\NodeTraverser\RectorNodeTraverser;
use Rector\Core\PhpParser\Parser\Parser;
use Rector\Core\ValueObject\Application\File;
use Rector\Core\ValueObject\Application\ParsedStmtsAndTokens;
use Rector\NodeTypeResolver\FileSystem\CurrentFileInfoProvider;
use Rector\NodeTypeResolver\NodeScopeAndMetadataDecorator;
use Rector\PostRector\Application\PostFileProcessor;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symplify\PackageBuilder\Reflection\PrivatesAccessor;
use Symplify\SmartFileSystem\SmartFileInfo;
use Throwable;

final class PhpFileProcessor implements FileProcessorInterface
Expand All @@ -43,46 +33,6 @@ final class PhpFileProcessor implements FileProcessorInterface
*/
private const PROGRESS_BAR_STEP_MULTIPLIER = 4;

/**
* @var Parser
*/
private $parser;

/**
* @var Lexer
*/
private $lexer;

/**
* @var RectorNodeTraverser
*/
private $rectorNodeTraverser;

/**
* @var NodeScopeAndMetadataDecorator
*/
private $nodeScopeAndMetadataDecorator;

/**
* @var CurrentFileInfoProvider
*/
private $currentFileInfoProvider;

/**
* @var AffectedFilesCollector
*/
private $affectedFilesCollector;

/**
* @var PostFileProcessor
*/
private $postFileProcessor;

/**
* @var TokensByFilePathStorage
*/
private $tokensByFilePathStorage;

/**
* @var Configuration
*/
Expand Down Expand Up @@ -136,15 +86,7 @@ public function __construct(
RemovedAndAddedFilesProcessor $removedAndAddedFilesProcessor,
SymfonyStyle $symfonyStyle,
PrivatesAccessor $privatesAccessor,
FileDiffFileDecorator $fileDiffFileDecorator,
AffectedFilesCollector $affectedFilesCollector,
CurrentFileInfoProvider $currentFileInfoProvider,
Lexer $lexer,
NodeScopeAndMetadataDecorator $nodeScopeAndMetadataDecorator,
Parser $parser,
PostFileProcessor $postFileProcessor,
RectorNodeTraverser $rectorNodeTraverser,
TokensByFilePathStorage $tokensByFilePathStorage
FileDiffFileDecorator $fileDiffFileDecorator
) {
$this->symfonyStyle = $symfonyStyle;
$this->errorAndDiffCollector = $errorAndDiffCollector;
Expand All @@ -155,14 +97,6 @@ public function __construct(
$this->privatesAccessor = $privatesAccessor;
$this->fileDiffFileDecorator = $fileDiffFileDecorator;
$this->configuration = $configuration;
$this->parser = $parser;
$this->lexer = $lexer;
$this->rectorNodeTraverser = $rectorNodeTraverser;
$this->nodeScopeAndMetadataDecorator = $nodeScopeAndMetadataDecorator;
$this->currentFileInfoProvider = $currentFileInfoProvider;
$this->affectedFilesCollector = $affectedFilesCollector;
$this->postFileProcessor = $postFileProcessor;
$this->tokensByFilePathStorage = $tokensByFilePathStorage;
}

/**
Expand Down Expand Up @@ -333,31 +267,4 @@ private function advance(File $file, string $phase): void
$this->symfonyStyle->progressAdvance();
}
}

private function parseFileInfoToLocalCache(SmartFileInfo $fileInfo): void
{
if ($this->tokensByFilePathStorage->hasForFileInfo($fileInfo)) {
return;
}

$this->currentFileInfoProvider->setCurrentFileInfo($fileInfo);

// store tokens by absolute path, so we don't have to print them right now
$parsedStmtsAndTokens = $this->parseAndTraverseFileInfoToNodes($fileInfo);
$this->tokensByFilePathStorage->addForRealPath($fileInfo, $parsedStmtsAndTokens);
}

private function parseAndTraverseFileInfoToNodes(SmartFileInfo $smartFileInfo): ParsedStmtsAndTokens
{
$oldStmts = $this->parser->parseFileInfo($smartFileInfo);
$oldTokens = $this->lexer->getTokens();

// needed for \Rector\NodeTypeResolver\PHPStan\Scope\NodeScopeResolver
$parsedStmtsAndTokens = new ParsedStmtsAndTokens($oldStmts, $oldStmts, $oldTokens);
$this->tokensByFilePathStorage->addForRealPath($smartFileInfo, $parsedStmtsAndTokens);

$newStmts = $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($oldStmts, $smartFileInfo);

return new ParsedStmtsAndTokens($newStmts, $oldStmts, $oldTokens);
}
}
1 change: 1 addition & 0 deletions src/PhpParser/NodeTraverser/RectorNodeTraverser.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function __construct(
$phpRectors = $activeRectorsProvider->provideByType(PhpRectorInterface::class);

$this->phpRectors = $phpRectors;

$this->nodeFinder = $nodeFinder;
$this->currentFileInfoProvider = $currentFileInfoProvider;
}
Expand Down

0 comments on commit 2093c5b

Please sign in to comment.