Description
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.
phpcbf
should be able to use the cache to determine if the sniffs need to be run or not on a particular file. When the cache is valid for a file, and there are no fixable errors reported, then the file can be skipped. When the cache is invalid, or there are fixable errors reported, then the file needs to be run through the sniffs as normal.
Internally when phpcbf
runs, there is actually a run of (the equivalent of) phpcs
first, and if there are any fixable errors reported then the fixer is enabled and run through the file. When the fixer is enabled, the cache should be temporarily disabled to avoid any negative performance overhead as it runs the sniffs up to 50 times.
At the end of a run of phpcbf
, the cache does not need to be in a perfect state. If there were no changes made, then the cache should still be valid for the files it was valid for to start with. If any changes were made, then the state of the cache is undefined. The next time the cache is read, it will be validated as normal.
phpcs
This is the existing behaviour for phpcs --cache
.
flowchart
A[Load ruleset]
A --> B{Caching enabled?}
B -->|Yes| C[Load cache]
B -->|No| D[Run sniffs]
D --> F
C --> E{Cache entry valid?}
E -->|No| D
E -->|Yes| F[Report results]
phpcbf
This is the proposed behaviour for phpcbf --cache
.
flowchart
A[Load ruleset] --> B{Caching enabled?}
B -->|Yes| C[Load cache]
B -->|No| D[Run sniffs]
C --> E{Cache entry valid?}
E -->|Yes| H{Fixable errors?}
H -->|No| F[Report results]
H -->|Yes| D
E -->|No| D
D --> G[Run fixer]
G -->|1-50x| G
G --> F
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 #146 and/or #147
The proposed changes have been implemented in #481
- I intend to create a pull request to implement this feature.