Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/Configuration/ConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,19 @@ private function resolvePaths(InputInterface $input): array
if ($commandLinePaths !== []) {
// mark the run as narrowed, so unused skip reporting can be disabled to avoid false positives
SimpleParameterProvider::setParameter(Option::IS_RUN_NARROWED, true);
$this->setFilesWithoutExtensionParameter($commandLinePaths);
return $commandLinePaths;
$paths = $commandLinePaths;
} else {
// fallback to parameter
$paths = SimpleParameterProvider::provideArrayParameter(Option::PATHS);
}

// fallback to parameter
$configPaths = SimpleParameterProvider::provideArrayParameter(Option::PATHS);
$this->setFilesWithoutExtensionParameter($configPaths);
$this->setFilesWithoutExtensionParameter($paths);

// extensions read the processed paths from here; without this only the test harness
// sets it, so the parameter is empty in a real run
SimpleParameterProvider::setParameter(Option::SOURCE, $paths);

return $configPaths;
return $paths;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Configuration/Parameter/SimpleParameterProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ final class SimpleParameterProvider
* @var array<Option::*>
*/
private const array CACHE_IGNORED_PARAMETER_NAMES = [
Option::SOURCE,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

@SanderMuller SanderMuller Sep 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without it, the new setParameter() call puts the resolved paths into hashForCacheInvalidation(). They differ per invocation, so rector process src/Foo.php followed by rector process would produce two different hashes and drop the unchanged-files cache each time. With it, the hash is the same as it is today, the parameter becomes visible without changing caching at all.

It also matches what the list already describes: the target narrows which files are visited, it does not change how any file is refactored.

Removing just this line fails testSourceParameterIsOutsideTheCacheInvalidationHash.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see 👍

Option::PARALLEL,
Option::PARALLEL_JOB_SIZE,
Option::PARALLEL_MAX_NUMBER_OF_PROCESSES,
Expand Down
56 changes: 56 additions & 0 deletions tests/Configuration/ConfigurationFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
namespace Rector\Tests\Configuration;

use Rector\Configuration\ConfigurationFactory;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\Console\ProcessConfigureDecorator;
use Rector\FileSystem\FilesFinder;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;

final class ConfigurationFactoryTest extends AbstractLazyTestCase
{
Expand Down Expand Up @@ -42,4 +47,55 @@ public function test(): void
realpath($thirdFilePath),
);
}

public function testPublishesCommandLinePathsAsSourceParameter(): void
{
SimpleParameterProvider::setParameter(Option::PATHS, [__DIR__ . '/config']);

$this->make(ConfigurationFactory::class)
->createFromInput($this->createInput([__DIR__ . '/Source']));

$this->assertSame(
[__DIR__ . '/Source'],
SimpleParameterProvider::provideArrayParameter(Option::SOURCE)
);
}

public function testPublishesConfiguredPathsAsSourceParameterWhenNoneGivenOnTheCommandLine(): void
{
SimpleParameterProvider::setParameter(Option::PATHS, [__DIR__ . '/config']);

$this->make(ConfigurationFactory::class)
->createFromInput($this->createInput([]));

$this->assertSame(
[__DIR__ . '/config'],
SimpleParameterProvider::provideArrayParameter(Option::SOURCE)
);
}

public function testSourceParameterIsOutsideTheCacheInvalidationHash(): void
{
// The processed paths change per invocation. Were they hashed, running Rector on a
// single file and then on the whole project would drop the cache each time.
SimpleParameterProvider::setParameter(Option::SOURCE, ['src']);
$hashForOnePath = SimpleParameterProvider::hashForCacheInvalidation();

SimpleParameterProvider::setParameter(Option::SOURCE, ['tests', 'src/Some/Other.php']);

$this->assertSame($hashForOnePath, SimpleParameterProvider::hashForCacheInvalidation());
}

/**
* @param string[] $paths
*/
private function createInput(array $paths): ArrayInput
{
$command = new Command('process');
ProcessConfigureDecorator::decorate($command);

return new ArrayInput([
Option::SOURCE => $paths,
], $command->getDefinition());
}
}