PHP_CodeSniffer icon indicating copy to clipboard operation
PHP_CodeSniffer copied to clipboard

Allow phpcbf to use the cache

Open fredden opened this issue 2 months ago • 3 comments

Is your feature request related to a problem?

Yes and no. When using phpcs --cache, subsequent runs are fast. When using phpcbf --cache, every run takes the same amount of time as the first.

Describe the solution you'd like

When using phpcbf --cache, subsequent runs should be faster - as they already are with phpcs --cache. Also, when using both phpcs and phpcbf, the cache generated by one should be usable by the other.

The following table shows the behaviour that I expect. Here "empty cache" means that the file being scanned either has no entry in the cache, or its entry is somehow invalid (eg, the file content has changed).

Scenario phpcs (cache miss) phpcbf (cache miss) phpcs (cache hit) phpcbf (cache hit)
No errors Run ruleset, find no errors, save result in cache Run ruleset (with fixers), find no errors, save result in cache Report (no) errors, do nothing with cache Detect that there are no fixable errors (in cache entry), no other action
Only fixable errors Run ruleset, find some errors, save result in cache Run ruleset, find some fixable errors, fix errors, do nothing with cache Report errors, do nothing with cache Detect that there are fixable errors (in cache entry), run ruleset (with fixers), do nothing with cache (or maybe actively remove the now-stale entry)
Fixable and unfixable errors Run ruleset, find some errors, save result in cache Run ruleset, find some fixable errors, fix errors, do nothing with cache Report errors, do nothing with cache Detect that there are fixable errors (in cache entry), run ruleset (with fixers), do nothing with cache (or maybe actively remove the now-stale entry)
Only unfixable errors Run ruleset, find some errors, save result in cache Run ruleset (with fixers), save result in cache Report errors, do nothing with cache Detect that there are no fixable errors (in cache entry), no other action

Additional context (optional)

Given the low test coverage of the areas in question here, making changes to this functionality is risky. Therefore this feature is likely blocked by https://github.com/PHPCSStandards/PHP_CodeSniffer/issues/146 and/or https://github.com/PHPCSStandards/PHP_CodeSniffer/issues/147

Some initial work can be seen here: https://github.com/PHPCSStandards/PHP_CodeSniffer/pull/481

  • [x] I intend to create a pull request to implement this feature.

fredden avatar May 08 '24 09:05 fredden