mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-14 23:22:22 +00:00
Enable changed files cache by default (#270)
This commit is contained in:
parent
b7359eda29
commit
697c20ec33
|
@ -124,9 +124,6 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
|||
// is your PHP version different from the one your refactor to? [default: your PHP version], uses PHP_VERSION_ID format
|
||||
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_72);
|
||||
|
||||
// Run Rector only on changed files
|
||||
$parameters->set(Option::ENABLE_CACHE, true);
|
||||
|
||||
// Path to phpstan with extensions, that PHPSTan in Rector uses to determine types
|
||||
$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, getcwd() . '/phpstan-for-config.neon');
|
||||
};
|
||||
|
|
|
@ -28,6 +28,5 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
|||
$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, null);
|
||||
|
||||
// cache
|
||||
$parameters->set(Option::ENABLE_CACHE, false);
|
||||
$parameters->set(Option::CACHE_DIR, sys_get_temp_dir() . '/rector_cached_files');
|
||||
};
|
||||
|
|
|
@ -25,7 +25,7 @@ final class CachedFileInfoFilterAndReporter
|
|||
public function filterFileInfos(array $phpFileInfos): array
|
||||
{
|
||||
// cache stuff
|
||||
if (! $this->configuration->isCacheEnabled() || $this->configuration->shouldClearCache()) {
|
||||
if ($this->configuration->shouldClearCache()) {
|
||||
$this->changedFilesDetector->clear();
|
||||
return $phpFileInfos;
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ final class PHPStanNodeScopeResolver
|
|||
/** @var MutatingScope $scope */
|
||||
$this->nodeScopeResolver->processNodes($nodes, $scope, $nodeCallback);
|
||||
|
||||
$this->reportCacheDebugAndSaveDependentFiles($smartFileInfo, $this->dependentFiles);
|
||||
$this->changedFilesDetector->addFileWithDependencies($smartFileInfo, $this->dependentFiles);
|
||||
|
||||
return $nodes;
|
||||
}
|
||||
|
@ -139,10 +139,6 @@ final class PHPStanNodeScopeResolver
|
|||
|
||||
private function resolveDependentFiles(Node $node, MutatingScope $mutatingScope): void
|
||||
{
|
||||
if (! $this->configuration->isCacheEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$dependentFiles = $this->dependencyResolver->resolveDependencies($node, $mutatingScope);
|
||||
foreach ($dependentFiles as $dependentFile) {
|
||||
|
@ -153,19 +149,6 @@ final class PHPStanNodeScopeResolver
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $dependentFiles
|
||||
*/
|
||||
private function reportCacheDebugAndSaveDependentFiles(SmartFileInfo $smartFileInfo, array $dependentFiles): void
|
||||
{
|
||||
if (! $this->configuration->isCacheEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// save for cache
|
||||
$this->changedFilesDetector->addFileWithDependencies($smartFileInfo, $dependentFiles);
|
||||
}
|
||||
|
||||
private function resolveClassName(Class_ | Interface_ | Trait_ $classLike): string
|
||||
{
|
||||
if (property_exists($classLike, 'namespacedName')) {
|
||||
|
|
|
@ -110,5 +110,4 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
|||
]);
|
||||
|
||||
$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, __DIR__ . '/phpstan-for-rector.neon');
|
||||
$parameters->set(Option::ENABLE_CACHE, true);
|
||||
};
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
namespace Rector\Tests\CodeQuality\Rector\Foreach_\ForeachItemsAssignToEmptyArrayToAssignRector\Fixture;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PHPStan\Analyser\MutatingScope;
|
||||
use PHPStan\Dependency\DependencyResolver;
|
||||
|
||||
class SkipForeachAssign
|
||||
{
|
||||
/**
|
||||
|
@ -14,13 +18,12 @@ class SkipForeachAssign
|
|||
$this->dependentFiles = [];
|
||||
}
|
||||
|
||||
private function resolveDependentFiles(Node $node, MutatingScope $mutatingScope): void
|
||||
{
|
||||
if (! $this->configuration->isCacheEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->dependencyResolver->resolveDependencies($node, $mutatingScope) as $dependentFile) {
|
||||
private function resolveDependentFiles(
|
||||
DependencyResolver $dependencyResolver,
|
||||
Node $node,
|
||||
MutatingScope $mutatingScope
|
||||
): void {
|
||||
foreach ($dependencyResolver->resolveDependencies($node, $mutatingScope) as $dependentFile) {
|
||||
$this->dependentFiles[] = $dependentFile;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,6 @@ final class Configuration
|
|||
|
||||
private string $outputFormat;
|
||||
|
||||
private bool $isCacheEnabled = false;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
|
@ -41,7 +39,6 @@ final class Configuration
|
|||
|
||||
public function __construct(ParameterProvider $parameterProvider)
|
||||
{
|
||||
$this->isCacheEnabled = (bool) $parameterProvider->provideParameter(Option::ENABLE_CACHE);
|
||||
$this->fileExtensions = (array) $parameterProvider->provideParameter(Option::FILE_EXTENSIONS);
|
||||
$this->paths = (array) $parameterProvider->provideParameter(Option::PATHS);
|
||||
$this->parameterProvider = $parameterProvider;
|
||||
|
@ -92,11 +89,6 @@ final class Configuration
|
|||
return $this->shouldClearCache;
|
||||
}
|
||||
|
||||
public function isCacheEnabled(): bool
|
||||
{
|
||||
return $this->isCacheEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
|
|
|
@ -74,6 +74,7 @@ final class Option
|
|||
public const CLEAR_CACHE = 'clear-cache';
|
||||
|
||||
/**
|
||||
* @deprecated Cache is enabled by default
|
||||
* @var string
|
||||
*/
|
||||
public const ENABLE_CACHE = 'enable_cache';
|
||||
|
|
|
@ -166,10 +166,6 @@ final class ProcessCommand extends Command
|
|||
|
||||
private function invalidateCacheChangedFiles(ProcessResult $processResult): void
|
||||
{
|
||||
if (! $this->configuration->isCacheEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($processResult->getChangedFileInfos() as $changedFileInfo) {
|
||||
$this->changedFilesDetector->invalidateFile($changedFileInfo);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Rector\Core\FileSystem;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use Rector\Caching\UnchangedFilesFilter;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\Finder\SplFileInfo;
|
||||
use Symplify\Skipper\SkipCriteriaResolver\SkippedPathsResolver;
|
||||
|
@ -34,6 +35,7 @@ final class FilesFinder
|
|||
private FinderSanitizer $finderSanitizer,
|
||||
private FileSystemFilter $fileSystemFilter,
|
||||
private SkippedPathsResolver $skippedPathsResolver,
|
||||
private UnchangedFilesFilter $unchangedFilesFilter
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -46,14 +48,17 @@ final class FilesFinder
|
|||
{
|
||||
$filesAndDirectories = $this->filesystemTweaker->resolveWithFnmatch($source);
|
||||
|
||||
$files = $this->fileSystemFilter->filterFiles($filesAndDirectories);
|
||||
$filePaths = $this->fileSystemFilter->filterFiles($filesAndDirectories);
|
||||
$directories = $this->fileSystemFilter->filterDirectories($filesAndDirectories);
|
||||
|
||||
|
||||
$smartFileInfos = [];
|
||||
foreach ($files as $file) {
|
||||
$smartFileInfos[] = new SmartFileInfo($file);
|
||||
foreach ($filePaths as $filePath) {
|
||||
$smartFileInfos[] = new SmartFileInfo($filePath);
|
||||
}
|
||||
|
||||
$smartFileInfos = $this->unchangedFilesFilter->filterAndJoinWithDependentFileInfos($smartFileInfos);
|
||||
|
||||
return array_merge($smartFileInfos, $this->findInDirectories($directories, $suffixes));
|
||||
}
|
||||
|
||||
|
@ -81,7 +86,9 @@ final class FilesFinder
|
|||
|
||||
$this->addFilterWithExcludedPaths($finder);
|
||||
|
||||
return $this->finderSanitizer->sanitize($finder);
|
||||
$smartFileInfos = $this->finderSanitizer->sanitize($finder);
|
||||
|
||||
return $this->unchangedFilesFilter->filterAndJoinWithDependentFileInfos($smartFileInfos);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user