mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-18 09:02:26 +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
|
// 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);
|
$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
|
// 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');
|
$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);
|
$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, null);
|
||||||
|
|
||||||
// cache
|
// cache
|
||||||
$parameters->set(Option::ENABLE_CACHE, false);
|
|
||||||
$parameters->set(Option::CACHE_DIR, sys_get_temp_dir() . '/rector_cached_files');
|
$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
|
public function filterFileInfos(array $phpFileInfos): array
|
||||||
{
|
{
|
||||||
// cache stuff
|
// cache stuff
|
||||||
if (! $this->configuration->isCacheEnabled() || $this->configuration->shouldClearCache()) {
|
if ($this->configuration->shouldClearCache()) {
|
||||||
$this->changedFilesDetector->clear();
|
$this->changedFilesDetector->clear();
|
||||||
return $phpFileInfos;
|
return $phpFileInfos;
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ final class PHPStanNodeScopeResolver
|
||||||
/** @var MutatingScope $scope */
|
/** @var MutatingScope $scope */
|
||||||
$this->nodeScopeResolver->processNodes($nodes, $scope, $nodeCallback);
|
$this->nodeScopeResolver->processNodes($nodes, $scope, $nodeCallback);
|
||||||
|
|
||||||
$this->reportCacheDebugAndSaveDependentFiles($smartFileInfo, $this->dependentFiles);
|
$this->changedFilesDetector->addFileWithDependencies($smartFileInfo, $this->dependentFiles);
|
||||||
|
|
||||||
return $nodes;
|
return $nodes;
|
||||||
}
|
}
|
||||||
|
@ -139,10 +139,6 @@ final class PHPStanNodeScopeResolver
|
||||||
|
|
||||||
private function resolveDependentFiles(Node $node, MutatingScope $mutatingScope): void
|
private function resolveDependentFiles(Node $node, MutatingScope $mutatingScope): void
|
||||||
{
|
{
|
||||||
if (! $this->configuration->isCacheEnabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$dependentFiles = $this->dependencyResolver->resolveDependencies($node, $mutatingScope);
|
$dependentFiles = $this->dependencyResolver->resolveDependencies($node, $mutatingScope);
|
||||||
foreach ($dependentFiles as $dependentFile) {
|
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
|
private function resolveClassName(Class_ | Interface_ | Trait_ $classLike): string
|
||||||
{
|
{
|
||||||
if (property_exists($classLike, 'namespacedName')) {
|
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::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;
|
namespace Rector\Tests\CodeQuality\Rector\Foreach_\ForeachItemsAssignToEmptyArrayToAssignRector\Fixture;
|
||||||
|
|
||||||
|
use PhpParser\Node;
|
||||||
|
use PHPStan\Analyser\MutatingScope;
|
||||||
|
use PHPStan\Dependency\DependencyResolver;
|
||||||
|
|
||||||
class SkipForeachAssign
|
class SkipForeachAssign
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -14,13 +18,12 @@ class SkipForeachAssign
|
||||||
$this->dependentFiles = [];
|
$this->dependentFiles = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function resolveDependentFiles(Node $node, MutatingScope $mutatingScope): void
|
private function resolveDependentFiles(
|
||||||
{
|
DependencyResolver $dependencyResolver,
|
||||||
if (! $this->configuration->isCacheEnabled()) {
|
Node $node,
|
||||||
return;
|
MutatingScope $mutatingScope
|
||||||
}
|
): void {
|
||||||
|
foreach ($dependencyResolver->resolveDependencies($node, $mutatingScope) as $dependentFile) {
|
||||||
foreach ($this->dependencyResolver->resolveDependencies($node, $mutatingScope) as $dependentFile) {
|
|
||||||
$this->dependentFiles[] = $dependentFile;
|
$this->dependentFiles[] = $dependentFile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,6 @@ final class Configuration
|
||||||
|
|
||||||
private string $outputFormat;
|
private string $outputFormat;
|
||||||
|
|
||||||
private bool $isCacheEnabled = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
|
@ -41,7 +39,6 @@ final class Configuration
|
||||||
|
|
||||||
public function __construct(ParameterProvider $parameterProvider)
|
public function __construct(ParameterProvider $parameterProvider)
|
||||||
{
|
{
|
||||||
$this->isCacheEnabled = (bool) $parameterProvider->provideParameter(Option::ENABLE_CACHE);
|
|
||||||
$this->fileExtensions = (array) $parameterProvider->provideParameter(Option::FILE_EXTENSIONS);
|
$this->fileExtensions = (array) $parameterProvider->provideParameter(Option::FILE_EXTENSIONS);
|
||||||
$this->paths = (array) $parameterProvider->provideParameter(Option::PATHS);
|
$this->paths = (array) $parameterProvider->provideParameter(Option::PATHS);
|
||||||
$this->parameterProvider = $parameterProvider;
|
$this->parameterProvider = $parameterProvider;
|
||||||
|
@ -92,11 +89,6 @@ final class Configuration
|
||||||
return $this->shouldClearCache;
|
return $this->shouldClearCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isCacheEnabled(): bool
|
|
||||||
{
|
|
||||||
return $this->isCacheEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -74,6 +74,7 @@ final class Option
|
||||||
public const CLEAR_CACHE = 'clear-cache';
|
public const CLEAR_CACHE = 'clear-cache';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @deprecated Cache is enabled by default
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const ENABLE_CACHE = 'enable_cache';
|
public const ENABLE_CACHE = 'enable_cache';
|
||||||
|
|
|
@ -166,10 +166,6 @@ final class ProcessCommand extends Command
|
||||||
|
|
||||||
private function invalidateCacheChangedFiles(ProcessResult $processResult): void
|
private function invalidateCacheChangedFiles(ProcessResult $processResult): void
|
||||||
{
|
{
|
||||||
if (! $this->configuration->isCacheEnabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($processResult->getChangedFileInfos() as $changedFileInfo) {
|
foreach ($processResult->getChangedFileInfos() as $changedFileInfo) {
|
||||||
$this->changedFilesDetector->invalidateFile($changedFileInfo);
|
$this->changedFilesDetector->invalidateFile($changedFileInfo);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||||
namespace Rector\Core\FileSystem;
|
namespace Rector\Core\FileSystem;
|
||||||
|
|
||||||
use Nette\Utils\Strings;
|
use Nette\Utils\Strings;
|
||||||
|
use Rector\Caching\UnchangedFilesFilter;
|
||||||
use Symfony\Component\Finder\Finder;
|
use Symfony\Component\Finder\Finder;
|
||||||
use Symfony\Component\Finder\SplFileInfo;
|
use Symfony\Component\Finder\SplFileInfo;
|
||||||
use Symplify\Skipper\SkipCriteriaResolver\SkippedPathsResolver;
|
use Symplify\Skipper\SkipCriteriaResolver\SkippedPathsResolver;
|
||||||
|
@ -34,6 +35,7 @@ final class FilesFinder
|
||||||
private FinderSanitizer $finderSanitizer,
|
private FinderSanitizer $finderSanitizer,
|
||||||
private FileSystemFilter $fileSystemFilter,
|
private FileSystemFilter $fileSystemFilter,
|
||||||
private SkippedPathsResolver $skippedPathsResolver,
|
private SkippedPathsResolver $skippedPathsResolver,
|
||||||
|
private UnchangedFilesFilter $unchangedFilesFilter
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,14 +48,17 @@ final class FilesFinder
|
||||||
{
|
{
|
||||||
$filesAndDirectories = $this->filesystemTweaker->resolveWithFnmatch($source);
|
$filesAndDirectories = $this->filesystemTweaker->resolveWithFnmatch($source);
|
||||||
|
|
||||||
$files = $this->fileSystemFilter->filterFiles($filesAndDirectories);
|
$filePaths = $this->fileSystemFilter->filterFiles($filesAndDirectories);
|
||||||
$directories = $this->fileSystemFilter->filterDirectories($filesAndDirectories);
|
$directories = $this->fileSystemFilter->filterDirectories($filesAndDirectories);
|
||||||
|
|
||||||
|
|
||||||
$smartFileInfos = [];
|
$smartFileInfos = [];
|
||||||
foreach ($files as $file) {
|
foreach ($filePaths as $filePath) {
|
||||||
$smartFileInfos[] = new SmartFileInfo($file);
|
$smartFileInfos[] = new SmartFileInfo($filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$smartFileInfos = $this->unchangedFilesFilter->filterAndJoinWithDependentFileInfos($smartFileInfos);
|
||||||
|
|
||||||
return array_merge($smartFileInfos, $this->findInDirectories($directories, $suffixes));
|
return array_merge($smartFileInfos, $this->findInDirectories($directories, $suffixes));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +86,9 @@ final class FilesFinder
|
||||||
|
|
||||||
$this->addFilterWithExcludedPaths($finder);
|
$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