Skip to content

Commit 89e6947

Browse files
Use Version::id() instead of "MD5 over source code" for encoding static analysis cache format in cache keys for static analysis cache
This means that cached static analysis results will be treated as outdated when a new/different version of php-code-coverage is used even if the static analysis code has not changed. Optimizing this edge case for performance is not worth risking errors in the code for calculating the "MD5 over source code" that we previously used for this.
1 parent bac9f42 commit 89e6947

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

ChangeLog-10.1.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
44

5+
## [10.1.17] - 2025-MM-DD
6+
7+
### Changed
8+
9+
* Changed version identifier for static analysis cache from "MD5 over source code" to `Version::id()`
10+
511
## [10.1.16] - 2024-08-22
612

713
### Changed
@@ -113,6 +119,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
113119

114120
* The `SebastianBergmann\CodeCoverage\Filter::includeDirectory()`, `SebastianBergmann\CodeCoverage\Filter::excludeDirectory()`, and `SebastianBergmann\CodeCoverage\Filter::excludeFile()` methods are now deprecated
115121

122+
[10.1.17]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.16...10.1
116123
[10.1.16]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.15...10.1.16
117124
[10.1.15]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.14...10.1.15
118125
[10.1.14]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.13...10.1.14

src/StaticAnalysis/CachingFileAnalyser.php

+2-21
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use function serialize;
1818
use function unserialize;
1919
use SebastianBergmann\CodeCoverage\Util\Filesystem;
20-
use SebastianBergmann\FileIterator\Facade as FileIteratorFacade;
20+
use SebastianBergmann\CodeCoverage\Version;
2121

2222
/**
2323
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
@@ -26,7 +26,6 @@
2626
*/
2727
final class CachingFileAnalyser implements FileAnalyser
2828
{
29-
private static ?string $cacheVersion = null;
3029
private readonly string $directory;
3130
private readonly FileAnalyser $analyser;
3231
private readonly bool $useAnnotationsForIgnoringCode;
@@ -152,7 +151,7 @@ private function cacheFile(string $filename): string
152151
[
153152
$filename,
154153
file_get_contents($filename),
155-
self::cacheVersion(),
154+
Version::id(),
156155
$this->useAnnotationsForIgnoringCode,
157156
$this->ignoreDeprecatedCode,
158157
],
@@ -161,22 +160,4 @@ private function cacheFile(string $filename): string
161160

162161
return $this->directory . DIRECTORY_SEPARATOR . $cacheKey;
163162
}
164-
165-
private static function cacheVersion(): string
166-
{
167-
if (self::$cacheVersion !== null) {
168-
return self::$cacheVersion;
169-
}
170-
171-
$buffer = [];
172-
173-
foreach ((new FileIteratorFacade)->getFilesAsArray(__DIR__, '.php') as $file) {
174-
$buffer[] = $file;
175-
$buffer[] = file_get_contents($file);
176-
}
177-
178-
self::$cacheVersion = md5(implode("\0", $buffer));
179-
180-
return self::$cacheVersion;
181-
}
182163
}

0 commit comments

Comments
 (0)