Skip to content

Removing a skip after a --clear-cache run does not invalidate the cache #9970

Closed
rectorphp/rector-src
#8934

Description

@cyppe

Bug Report

Subject Details
Rector version 2.8.5

--clear-cache also deletes the configuration snapshot that ChangedFilesDetector::setFirstResolvedConfigFileInfo() has just stored. The snapshot is saved while the container is created (RectorContainerFactory), and FilesFinder::findFilesInPaths() then calls ChangedFilesDetector::clear(), which empties the whole cache. The run then caches every file as unchanged, but no snapshot is left. On the next run invalidateCacheIfConfigurationChanged() finds no previous snapshot, treats it as the first run, and keeps those entries. A rule that was skipped or not registered before that run therefore never reaches the cached files.

Minimal PHP Code Causing Issue

src/Foo.php:

<?php

final class Foo
{
    public function run(): void
    {
        $value = (bool) 1;
    }
}

rector.php:

<?php

use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector;

return RectorConfig::configure()
    ->withPaths([__DIR__ . '/src'])
    ->withCache(__DIR__ . '/.cache')
    ->withRules([RemoveUnusedVariableAssignRector::class, RemoveEmptyClassMethodRector::class])
    ->withSkip([RemoveUnusedVariableAssignRector::class]);
  1. vendor/bin/rector process --dry-run --clear-cache reports no change, as expected.
  2. Remove the ->withSkip(...) call.
  3. vendor/bin/rector process --dry-run still reports no change.

Without --clear-cache in step 1, step 3 reports the change. With --clear-cache in step 3, it reports it too.

Expected Behaviour

Step 3 reports src/Foo.php (RemoveUnusedVariableAssignRector), as it does when step 1 runs without --clear-cache.

A possible fix: store the snapshot again after clear() in FilesFinder::findFilesInPaths(), or let ChangedFilesDetector::clear() keep the configuration snapshot it stored for this run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions