Skip to content

Commit

Permalink
[DX] simplify --debug output to the proccessed file path (#1933)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Mar 15, 2022
1 parent dc8e8ff commit 117af55
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 79 deletions.
12 changes: 3 additions & 9 deletions src/Application/FileProcessor/PhpFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Rector\Core\Application\FileSystem\RemovedAndAddedFilesCollector;
use Rector\Core\Contract\Console\OutputStyleInterface;
use Rector\Core\Contract\Processor\FileProcessorInterface;
use Rector\Core\Enum\ApplicationPhase;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\PhpParser\Printer\FormatPerservingPrinter;
use Rector\Core\Provider\CurrentFileProvider;
Expand Down Expand Up @@ -53,7 +52,6 @@ public function process(File $file, Configuration $configuration): array
if ($parsingSystemErrors !== []) {
// we cannot process this file as the parsing and type resolving itself went wrong
$systemErrorsAndFileDiffs[Bridge::SYSTEM_ERRORS] = $parsingSystemErrors;
$this->notifyPhase($file, ApplicationPhase::PRINT_SKIP());

return $systemErrorsAndFileDiffs;
}
Expand All @@ -64,7 +62,6 @@ public function process(File $file, Configuration $configuration): array
$this->refactorNodesWithRectors($file, $configuration);

// 3. apply post rectors
$this->notifyPhase($file, ApplicationPhase::POST_RECTORS());
$newStmts = $this->postFileProcessor->traverse($file->getNewStmts());
// this is needed for new tokens added in "afterTraverse()"
$file->changeNewStmts($newStmts);
Expand All @@ -73,7 +70,6 @@ public function process(File $file, Configuration $configuration): array
$this->currentFileProvider->setFile($file);

// important to detect if file has changed
$this->notifyPhase($file, ApplicationPhase::PRINT());
$this->printFile($file, $configuration);
} while ($file->hasChanged());

Expand Down Expand Up @@ -104,8 +100,6 @@ public function getSupportedFileExtensions(): array
private function refactorNodesWithRectors(File $file, Configuration $configuration): void
{
$this->currentFileProvider->setFile($file);
$this->notifyPhase($file, ApplicationPhase::REFACTORING());

$this->fileProcessor->refactor($file, $configuration);
}

Expand All @@ -115,7 +109,7 @@ private function refactorNodesWithRectors(File $file, Configuration $configurati
private function parseFileAndDecorateNodes(File $file): array
{
$this->currentFileProvider->setFile($file);
$this->notifyPhase($file, ApplicationPhase::PARSING());
$this->notifyFile($file);

try {
$this->fileProcessor->parseFileInfoToLocalCache($file);
Expand Down Expand Up @@ -165,15 +159,15 @@ private function printFile(File $file, Configuration $configuration): void
$this->fileDiffFileDecorator->decorate([$file]);
}

private function notifyPhase(File $file, ApplicationPhase $applicationPhase): void
private function notifyFile(File $file): void
{
if (! $this->rectorOutputStyle->isVerbose()) {
return;
}

$smartFileInfo = $file->getSmartFileInfo();
$relativeFilePath = $smartFileInfo->getRelativeFilePathFromDirectory(getcwd());
$message = sprintf('[%s] %s', $applicationPhase, $relativeFilePath);
$message = $relativeFilePath;
$this->rectorOutputStyle->writeln($message);
}
}
42 changes: 0 additions & 42 deletions src/Enum/ApplicationPhase.php

This file was deleted.

28 changes: 0 additions & 28 deletions src/Rector/AbstractRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
use Rector\Core\Application\FileSystem\RemovedAndAddedFilesCollector;
use Rector\Core\Configuration\CurrentNodeProvider;
use Rector\Core\Contract\Console\OutputStyleInterface;
use Rector\Core\Contract\Rector\PhpRectorInterface;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\Exclusion\ExclusionManager;
Expand Down Expand Up @@ -118,8 +117,6 @@ abstract class AbstractRector extends NodeVisitorAbstract implements PhpRectorIn

private SimpleCallableNodeTraverser $simpleCallableNodeTraverser;

private OutputStyleInterface $rectorOutputStyle;

private ExclusionManager $exclusionManager;

private CurrentRectorProvider $currentRectorProvider;
Expand All @@ -128,8 +125,6 @@ abstract class AbstractRector extends NodeVisitorAbstract implements PhpRectorIn

private Skipper $skipper;

private string|null $previousAppliedClass = null;

private CurrentFileProvider $currentFileProvider;

/**
Expand All @@ -153,7 +148,6 @@ public function autowire(
SimpleCallableNodeTraverser $simpleCallableNodeTraverser,
NodeFactory $nodeFactory,
PhpDocInfoFactory $phpDocInfoFactory,
OutputStyleInterface $rectorOutputStyle,
PhpVersionProvider $phpVersionProvider,
ExclusionManager $exclusionManager,
StaticTypeMapper $staticTypeMapper,
Expand All @@ -178,7 +172,6 @@ public function autowire(
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
$this->nodeFactory = $nodeFactory;
$this->phpDocInfoFactory = $phpDocInfoFactory;
$this->rectorOutputStyle = $rectorOutputStyle;
$this->phpVersionProvider = $phpVersionProvider;
$this->exclusionManager = $exclusionManager;
$this->staticTypeMapper = $staticTypeMapper;
Expand All @@ -199,8 +192,6 @@ public function autowire(
*/
public function beforeTraverse(array $nodes): ?array
{
$this->previousAppliedClass = null;

// workaround for file around refactor()
$file = $this->currentFileProvider->getFile();
if (! $file instanceof File) {
Expand Down Expand Up @@ -240,9 +231,6 @@ final public function enterNode(Node $node)
// for PHP doc info factory and change notifier
$this->currentNodeProvider->setNode($node);

// show current Rector class on --debug
$this->printDebugApplying();

$originalAttributes = $node->getAttributes();

$node = $this->refactor($node);
Expand Down Expand Up @@ -439,22 +427,6 @@ private function shouldSkipCurrentNode(Node $node): bool
return $rectifiedNode instanceof RectifiedNode;
}

private function printDebugApplying(): void
{
if (! $this->rectorOutputStyle->isDebug()) {
return;
}

if ($this->previousAppliedClass === static::class) {
return;
}

// prevent spamming with the same class over and over
// indented on purpose to improve log nesting under [refactoring]
$this->rectorOutputStyle->writeln(' [applying] ' . static::class);
$this->previousAppliedClass = static::class;
}

/**
* @param array<string, mixed> $originalAttributes
*/
Expand Down

0 comments on commit 117af55

Please sign in to comment.