Description
On some configuration changes the cache is not properly invalidated.
For example this fixer:
$ecsConfig->ruleWithConfiguration(FinalInternalClassFixer::class, [
'annotation_exclude' => ['@not-fix'],
'consider_absent_docblock_as_internal_class' => \true
]);
When running it with the configuration array empty, it marks a lot of files as shiny.
But then, if I change it to this:
$ecsConfig->ruleWithConfiguration(FinalInternalClassFixer::class, [
'annotation_exclude' => ['@not-fix'],
'annotation_include' => [],
'consider_absent_docblock_as_internal_class' => \true
]);
It becomes applicable to a lot more files (the default for annotation_include
is to require an @internal
entry). But rerunning ECS doesn't work discover those.
If I run it with ecs --clear-cache
it does work correctly. Note that going the other way is not an issue since faulty files are always (re)checked.
A simple solution would be to take a "hash" of the ECSConfig
instance and always fully invalidate the cache when it has changed.
Since I'm not familiar with Symfony's DI configurator stuff I don't know if this is supported by default. Of course an easy naive implementation is to just log all calls to the ECSConfig
to create a hash:
private string $liveHash = '';
public function ruleWithConfiguration(string $checkerClass, array $configuration) : void
{
$this->liveHash = md5($this->liveHash . $checkClass . json_encode($configuration));
}
This would then need to be done for every function on ECS config. Note that even doing this partially improves the situation, since currently all changes are ignored.