move AffectedFilesCollector to ChangesReporting

This commit is contained in:
TomasVotruba 2020-03-19 13:03:29 +01:00
parent 3b57181603
commit ddf8de2e17
8 changed files with 52 additions and 20 deletions

View File

@ -149,7 +149,8 @@ final class ErrorAndDiffCollector
if ($rectorClass) {
$this->addErrorWithRectorClassMessageAndFileInfo($rectorClass, $throwable->getMessage(), $fileInfo);
} else {
$this->addError(new Error($fileInfo, $throwable->getMessage(), $throwable->getCode()));
$error = new Error($fileInfo, $throwable->getMessage(), $throwable->getCode());
$this->addError($error);
}
}
}

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Core\Report;
namespace Rector\ChangesReporting\Collector;
use Symplify\SmartFileSystem\SmartFileInfo;

View File

@ -6,6 +6,8 @@ namespace Rector\ChangesReporting\Collector;
use PhpParser\Node;
use Rector\ChangesReporting\ValueObject\RectorWithFileAndLineChange;
use Rector\Core\Contract\Rector\RectorInterface;
use Rector\Core\Exception\NotRectorException;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -18,6 +20,10 @@ final class RectorChangeCollector
public function addRectorClassWithLine(string $rectorClass, SmartFileInfo $smartFileInfo, int $line): void
{
if (! is_a($rectorClass, RectorInterface::class, true)) {
throw new NotRectorException($rectorClass);
}
$this->rectorWithFileAndLineChanges[] = new RectorWithFileAndLineChange(
$rectorClass,
$smartFileInfo->getRealPath(),

View File

@ -57,6 +57,22 @@ final class CheckstyleOutputFormatter implements OutputFormatterInterface
return htmlspecialchars($string, ENT_XML1 | ENT_COMPAT, 'UTF-8');
}
private function writeFileErrors(FileDiff $fileDiff): void
{
$this->symfonyStyle->writeln(sprintf('<file name="%s">', $this->escape($fileDiff->getRelativeFilePath())));
foreach ($fileDiff->getRectorChanges() as $rectorChange) {
$error = sprintf(
' <error line="%d" column="1" severity="error" message="%s" />',
$this->escape((string) $rectorChange->getLine()),
$this->escape((string) $rectorChange->getRectorClass())
);
$this->symfonyStyle->writeln($error);
}
$this->symfonyStyle->writeln('</file>');
}
private function writeNonFileErrors(ErrorAndDiffCollector $errorAndDiffCollector): void
{
if ($errorAndDiffCollector->getErrors() !== []) {
@ -73,20 +89,4 @@ final class CheckstyleOutputFormatter implements OutputFormatterInterface
$this->symfonyStyle->writeln('</file>');
}
}
private function writeFileErrors(FileDiff $fileDiff): void
{
$this->symfonyStyle->writeln(sprintf('<file name="%s">', $this->escape($fileDiff->getRelativeFilePath())));
foreach ($fileDiff->getRectorChanges() as $rectorChange) {
$error = sprintf(
' <error line="%d" column="1" severity="error" message="%s" />',
$this->escape((string) $rectorChange->getLine()),
$this->escape((string) $rectorChange->getRectorClass())
);
$this->symfonyStyle->writeln($error);
}
$this->symfonyStyle->writeln('</file>');
}
}

View File

@ -4,6 +4,9 @@ declare(strict_types=1);
namespace Rector\ChangesReporting\ValueObject;
use Rector\Core\Contract\Rector\RectorInterface;
use Rector\Core\Exception\NotRectorException;
final class RectorWithFileAndLineChange
{
/**
@ -23,6 +26,10 @@ final class RectorWithFileAndLineChange
public function __construct(string $rectorClass, string $realPath, int $line)
{
if (! is_a($rectorClass, RectorInterface::class, true)) {
throw new NotRectorException($rectorClass);
}
$this->rectorClass = $rectorClass;
$this->line = $line;
$this->realPath = $realPath;

View File

@ -6,11 +6,11 @@ namespace Rector\Core\Application;
use PhpParser\Lexer;
use PhpParser\Node;
use Rector\ChangesReporting\Collector\AffectedFilesCollector;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\PhpParser\NodeTraverser\RectorNodeTraverser;
use Rector\Core\PhpParser\Parser\Parser;
use Rector\Core\PhpParser\Printer\FormatPerservingPrinter;
use Rector\Core\Report\AffectedFilesCollector;
use Rector\Core\Stubs\StubLoader;
use Rector\NodeTypeResolver\FileSystem\CurrentFileInfoProvider;
use Rector\NodeTypeResolver\NodeScopeAndMetadataDecorator;

View File

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace Rector\Core\Exception;
use Exception;
use Rector\Core\Contract\Rector\RectorInterface;
final class NotRectorException extends Exception
{
public function __construct(string $class)
{
$message = sprintf('"%s" should be type of "%s"', $class, RectorInterface::class);
parent::__construct($message);
}
}

View File

@ -9,10 +9,10 @@ use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Expression;
use PhpParser\NodeTraverser;
use Rector\ChangesReporting\Collector\AffectedFilesCollector;
use Rector\Core\Contract\PhpParser\Node\CommanderInterface;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\PhpParser\Node\NodeVisitorFactory\NodeRemovingNodeVisitorFactory;
use Rector\Core\Report\AffectedFilesCollector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\SmartFileSystem\SmartFileInfo;