mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-31 16:30:51 +00:00
drop --match-git-diff, not reliable for dependencies; use enable_cache instead (#5609)
Co-authored-by: kaizen-ci <info@kaizen-ci.org>
This commit is contained in:
parent
19459b80fb
commit
ddfeae3391
|
@ -71,7 +71,6 @@ It supports all versions of PHP from 5.3 and major open-source projects:
|
|||
|
||||
- [How to Ignore Rule or Paths](/docs/how_to_ignore_rule_or_paths.md)
|
||||
- [How to Configure Rule](/docs/how_to_configure_rules.md)
|
||||
- [How to Run Rector on Changed Files Only](/docs/how_to_run_rector_on_changed_files_only.md)
|
||||
|
||||
### Contributing
|
||||
|
||||
|
@ -229,7 +228,7 @@ Or with Xdebug:
|
|||
vendor/bin/rector process src/Controller --dry-run --xdebug
|
||||
```
|
||||
|
||||
To assist with echo-style debugging rector provides a [`print_node()` helper](tests/debug_functions.php) method
|
||||
To assist with echo-style debugging rector provides a [`print_node()` helper](tests/debug_functions.php) method
|
||||
which is useful to pretty-print AST-nodes:
|
||||
|
||||
```php
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
# How To Run Rector on Changed Files Only
|
||||
|
||||
Execution can be limited to changed files using the `process` option `--match-git-diff`.
|
||||
This option will filter the files included by the configuration, creating an intersection with the files listed in `git diff`.
|
||||
|
||||
```bash
|
||||
vendor/bin/rector process src --match-git-diff
|
||||
```
|
||||
|
||||
This option is useful in CI with pull-requests that only change few files.
|
|
@ -6,7 +6,6 @@ namespace Rector\CodeQuality\Rector\ClassMethod;
|
|||
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeInterface;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
|
|
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace Rector\CodingStyle\Rector\ClassMethod;
|
||||
|
||||
use Iterator;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
|
|
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace Rector\DoctrineCodeQuality\Rector\Class_;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
|
|
|
@ -8,7 +8,6 @@ use PhpParser\Node;
|
|||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use Ramsey\Uuid\UuidInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\DeadCode\Doctrine\DoctrineEntityManipulator;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
|
|
|
@ -15,7 +15,6 @@ use PhpParser\Node\Stmt\ClassMethod;
|
|||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
use Rector\Core\PhpParser\Node\NodeFactory;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
final class ActionWithFormProcessClassMethodFactory
|
||||
|
@ -35,7 +34,9 @@ final class ActionWithFormProcessClassMethodFactory
|
|||
$classMethod = $this->nodeFactory->createPublicMethod('actionSomeForm');
|
||||
|
||||
$requestVariable = new Variable('request');
|
||||
$classMethod->params[] = new Param($requestVariable, null, new FullyQualified('Symfony\Component\HttpFoundation\Request'));
|
||||
$classMethod->params[] = new Param($requestVariable, null, new FullyQualified(
|
||||
'Symfony\Component\HttpFoundation\Request'
|
||||
));
|
||||
$classMethod->returnType = new FullyQualified(Response::class);
|
||||
|
||||
$formVariable = new Variable('form');
|
||||
|
|
|
@ -22,7 +22,6 @@ use Rector\Nette\NodeFactory\ActionRenderFactory;
|
|||
use Rector\NetteToSymfony\NodeAnalyzer\ClassMethodRenderAnalyzer;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
|
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace Rector\PHPUnit\NodeFactory;
|
||||
|
||||
use Iterator;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\ArrayItem;
|
||||
use PhpParser\Node\Expr\Yield_;
|
||||
|
|
|
@ -7,7 +7,6 @@ namespace Rector\Removing\Rector\FuncCall;
|
|||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Removing\ValueObject\RemoveFuncCallArg;
|
||||
|
|
|
@ -29,11 +29,6 @@ final class Configuration
|
|||
*/
|
||||
private $areAnyPhpRectorsLoaded = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $mustMatchGitDiff = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
|
@ -104,7 +99,6 @@ final class Configuration
|
|||
{
|
||||
$this->isDryRun = (bool) $input->getOption(Option::OPTION_DRY_RUN);
|
||||
$this->shouldClearCache = (bool) $input->getOption(Option::OPTION_CLEAR_CACHE);
|
||||
$this->mustMatchGitDiff = (bool) $input->getOption(Option::MATCH_GIT_DIFF);
|
||||
$this->showProgressBar = $this->canShowProgressBar($input);
|
||||
$this->showDiffs = ! (bool) $input->getOption(Option::OPTION_NO_DIFFS);
|
||||
$this->isCacheDebug = (bool) $input->getOption(Option::CACHE_DEBUG);
|
||||
|
@ -181,11 +175,6 @@ final class Configuration
|
|||
$this->areAnyPhpRectorsLoaded = $areAnyPhpRectorsLoaded;
|
||||
}
|
||||
|
||||
public function mustMatchGitDiff(): bool
|
||||
{
|
||||
return $this->mustMatchGitDiff;
|
||||
}
|
||||
|
||||
public function getOutputFile(): ?string
|
||||
{
|
||||
return $this->outputFile;
|
||||
|
|
|
@ -53,11 +53,6 @@ final class Option
|
|||
*/
|
||||
public const IMPORT_DOC_BLOCKS = 'import_doc_blocks';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const MATCH_GIT_DIFF = 'match-git-diff';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
|
|
@ -154,13 +154,6 @@ final class ProcessCommand extends AbstractCommand
|
|||
'File with extra autoload'
|
||||
);
|
||||
|
||||
$this->addOption(
|
||||
Option::MATCH_GIT_DIFF,
|
||||
null,
|
||||
InputOption::VALUE_NONE,
|
||||
'Execute only on file(s) matching the git diff.'
|
||||
);
|
||||
|
||||
$names = $this->outputFormatterCollector->getNames();
|
||||
|
||||
$description = sprintf('Select output format: "%s".', implode('", "', $names));
|
||||
|
@ -264,8 +257,7 @@ final class ProcessCommand extends AbstractCommand
|
|||
{
|
||||
$phpFileInfos = $this->filesFinder->findInDirectoriesAndFiles(
|
||||
$paths,
|
||||
$this->configuration->getFileExtensions(),
|
||||
$this->configuration->mustMatchGitDiff()
|
||||
$this->configuration->getFileExtensions()
|
||||
);
|
||||
|
||||
// filter out non-PHP php files, e.g. blade templates in Laravel
|
||||
|
|
|
@ -71,9 +71,9 @@ final class FilesFinder
|
|||
* @param string[] $suffixes
|
||||
* @return SmartFileInfo[]
|
||||
*/
|
||||
public function findInDirectoriesAndFiles(array $source, array $suffixes, bool $matchDiff = false): array
|
||||
public function findInDirectoriesAndFiles(array $source, array $suffixes): array
|
||||
{
|
||||
$cacheKey = md5(serialize($source) . serialize($suffixes) . (int) $matchDiff);
|
||||
$cacheKey = md5(serialize($source) . serialize($suffixes));
|
||||
if (isset($this->fileInfosBySourceAndSuffixes[$cacheKey])) {
|
||||
return $this->fileInfosBySourceAndSuffixes[$cacheKey];
|
||||
}
|
||||
|
@ -87,19 +87,6 @@ final class FilesFinder
|
|||
}
|
||||
|
||||
$smartFileInfos = array_merge($smartFileInfos, $this->findInDirectories($directories, $suffixes));
|
||||
|
||||
if ($matchDiff) {
|
||||
$gitDiffFiles = $this->getGitDiff();
|
||||
|
||||
$smartFileInfos = array_filter($smartFileInfos, function (SmartFileInfo $fileInfo) use (
|
||||
$gitDiffFiles
|
||||
): bool {
|
||||
return in_array($fileInfo->getRealPath(), $gitDiffFiles, true);
|
||||
});
|
||||
|
||||
$smartFileInfos = array_values($smartFileInfos);
|
||||
}
|
||||
|
||||
return $this->fileInfosBySourceAndSuffixes[$cacheKey] = $smartFileInfos;
|
||||
}
|
||||
|
||||
|
@ -135,27 +122,6 @@ final class FilesFinder
|
|||
return $this->finderSanitizer->sanitize($finder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[] The absolute path to the file matching the git diff shell command.
|
||||
*/
|
||||
private function getGitDiff(): array
|
||||
{
|
||||
$plainDiff = shell_exec('git diff --name-only') ?: '';
|
||||
$relativePaths = explode(PHP_EOL, trim($plainDiff));
|
||||
|
||||
$realPaths = [];
|
||||
foreach ($relativePaths as $relativePath) {
|
||||
$realPath = realpath($relativePath);
|
||||
if ($realPath === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$realPaths[] = $realPath;
|
||||
}
|
||||
|
||||
return $realPaths;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $suffixes
|
||||
*/
|
||||
|
|
|
@ -9,7 +9,6 @@ use Rector\Core\FileSystem\FilesFinder;
|
|||
use Rector\Core\HttpKernel\RectorKernel;
|
||||
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
use Symplify\SmartFileSystem\SmartFileSystem;
|
||||
|
||||
final class FilesFinderTest extends AbstractKernelTestCase
|
||||
{
|
||||
|
@ -18,16 +17,10 @@ final class FilesFinderTest extends AbstractKernelTestCase
|
|||
*/
|
||||
private $filesFinder;
|
||||
|
||||
/**
|
||||
* @var SmartFileSystem
|
||||
*/
|
||||
private $smartFileSystem;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->bootKernel(RectorKernel::class);
|
||||
$this->filesFinder = $this->getService(FilesFinder::class);
|
||||
$this->smartFileSystem = $this->getService(SmartFileSystem::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,26 +60,4 @@ final class FilesFinderTest extends AbstractKernelTestCase
|
|||
sort($expectedFoundFileNames);
|
||||
$this->assertSame($expectedFoundFileNames, $foundFileNames);
|
||||
}
|
||||
|
||||
public function testMatchGitDiff(): void
|
||||
{
|
||||
$dir = sys_get_temp_dir() . '/' . mt_rand();
|
||||
mkdir($dir);
|
||||
chdir($dir);
|
||||
shell_exec('git init');
|
||||
|
||||
$filename = $dir . '/tmp.php';
|
||||
touch($filename);
|
||||
touch($dir . '/tmp.yml');
|
||||
|
||||
shell_exec('git add --all && git commit -m "first commit"');
|
||||
|
||||
$this->smartFileSystem->dumpFile($filename, '<?php echo ' . mt_rand() . ';');
|
||||
$this->smartFileSystem->dumpFile($dir . '/tmp.yml', '');
|
||||
|
||||
$foundFiles = $this->filesFinder->findInDirectoriesAndFiles([$dir], ['php'], true);
|
||||
$this->assertCount(1, $foundFiles);
|
||||
|
||||
$this->smartFileSystem->remove($filename);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user