mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-25 12:14:02 +01:00
Merge pull request #314 from rectorphp/file-diff
add FileDiff object over array
This commit is contained in:
commit
d08b5a0ba9
@ -64,8 +64,8 @@ vendor/bin/rector
|
||||
|
||||
### Extra Autoloading
|
||||
|
||||
Rector relies on project and autoloading of its classes. To specify own autoload file, use `--autoload-file` option:
|
||||
|
||||
Rector relies on project and autoloading of its classes. To specify own autoload file, use `--autoload-file` option:
|
||||
|
||||
```bash
|
||||
vendor/bin/rector process ../project --autoload-file ../project/vendor/autoload.php
|
||||
```
|
||||
|
@ -25,6 +25,7 @@ checkers:
|
||||
- 'Rector\DeprecationExtractor\Deprecation\*'
|
||||
- 'Rector\BetterReflection\SourceLocator\Located\LocatedSource'
|
||||
- 'phpDocumentor\Reflection\Types\*'
|
||||
- 'Rector\Reporting\FileDiff'
|
||||
|
||||
Symplify\CodingStandard\Fixer\Naming\PropertyNameMatchingTypeFixer:
|
||||
extra_skipped_classes:
|
||||
|
@ -13,6 +13,7 @@ use Rector\Exception\NoRectorsLoadedException;
|
||||
use Rector\FileSystem\PhpFilesFinder;
|
||||
use Rector\Naming\CommandNaming;
|
||||
use Rector\Rector\RectorCollector;
|
||||
use Rector\Reporting\FileDiff;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
@ -65,9 +66,9 @@ final class ProcessCommand extends Command
|
||||
private $changedFiles = [];
|
||||
|
||||
/**
|
||||
* @var string[][]
|
||||
* @var FileDiff[]
|
||||
*/
|
||||
private $diffFiles = [];
|
||||
private $fileDiffs = [];
|
||||
|
||||
/**
|
||||
* @var AdditionalAutoloader
|
||||
@ -136,7 +137,7 @@ final class ProcessCommand extends Command
|
||||
|
||||
$this->processFiles($files);
|
||||
|
||||
$this->processCommandReporter->reportDiffFiles($this->diffFiles);
|
||||
$this->processCommandReporter->reportFileDiffs($this->fileDiffs);
|
||||
$this->processCommandReporter->reportChangedFiles($this->changedFiles);
|
||||
$this->consoleStyle->success('Rector is done!');
|
||||
|
||||
@ -189,10 +190,10 @@ final class ProcessCommand extends Command
|
||||
if ($this->parameterProvider->provideParameter(Option::OPTION_DRY_RUN)) {
|
||||
$newContent = $this->fileProcessor->processFileToString($fileInfo);
|
||||
if ($newContent !== $oldContent) {
|
||||
$this->diffFiles[] = [
|
||||
'file' => $fileInfo->getPathname(),
|
||||
'diff' => $this->differAndFormatter->diffAndFormat($oldContent, $newContent),
|
||||
];
|
||||
$this->fileDiffs[] = new FileDiff(
|
||||
$fileInfo->getPathname(),
|
||||
$this->differAndFormatter->diffAndFormat($oldContent, $newContent)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$newContent = $this->fileProcessor->processFile($fileInfo);
|
||||
|
@ -5,6 +5,7 @@ namespace Rector\Console\Output;
|
||||
use Rector\Console\ConsoleStyle;
|
||||
use Rector\Contract\Rector\RectorInterface;
|
||||
use Rector\Rector\RectorCollector;
|
||||
use Rector\Reporting\FileDiff;
|
||||
|
||||
final class ProcessCommandReporter
|
||||
{
|
||||
@ -57,25 +58,25 @@ final class ProcessCommandReporter
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[][] $diffFiles
|
||||
* @param FileDiff[] $fileDiffs
|
||||
*/
|
||||
public function reportDiffFiles(array $diffFiles): void
|
||||
public function reportFileDiffs(array $fileDiffs): void
|
||||
{
|
||||
if (count($diffFiles) <= 0) {
|
||||
if (count($fileDiffs) <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->consoleStyle->title(sprintf(
|
||||
'%d file%s with changes',
|
||||
count($diffFiles),
|
||||
count($diffFiles) === 1 ? '' : 's'
|
||||
count($fileDiffs),
|
||||
count($fileDiffs) === 1 ? '' : 's'
|
||||
));
|
||||
|
||||
$i = 0;
|
||||
foreach ($diffFiles as $diffFile) {
|
||||
$this->consoleStyle->writeln(sprintf('<options=bold>%d) %s</>', ++$i, $diffFile['file']));
|
||||
foreach ($fileDiffs as $fileDiff) {
|
||||
$this->consoleStyle->writeln(sprintf('<options=bold>%d) %s</>', ++$i, $fileDiff->getFile()));
|
||||
$this->consoleStyle->newLine();
|
||||
$this->consoleStyle->writeln($diffFile['diff']);
|
||||
$this->consoleStyle->writeln($fileDiff->getDiff());
|
||||
$this->consoleStyle->newLine();
|
||||
}
|
||||
}
|
||||
|
32
src/Reporting/FileDiff.php
Normal file
32
src/Reporting/FileDiff.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Reporting;
|
||||
|
||||
final class FileDiff
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $diff;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $file;
|
||||
|
||||
public function __construct(string $file, string $diff)
|
||||
{
|
||||
$this->file = $file;
|
||||
$this->diff = $diff;
|
||||
}
|
||||
|
||||
public function getDiff(): string
|
||||
{
|
||||
return $this->diff;
|
||||
}
|
||||
|
||||
public function getFile(): string
|
||||
{
|
||||
return $this->file;
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ services:
|
||||
|
||||
Rector\:
|
||||
resource: '../'
|
||||
exclude: '../{Node/Attribute.php,Rector/Contrib/**/*Rector.php,Rector/Dynamic,Rector/MagicDisclosure,Testing}'
|
||||
exclude: '../{Node/Attribute.php,Rector/Contrib/**/*Rector.php,Rector/Dynamic,Rector/MagicDisclosure,Reporting/FileDiff.php,Testing}'
|
||||
|
||||
Rector\Rector\Contrib\Symfony\Form\Helper\FormTypeStringToTypeProvider: ~
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user