Skip to content

Commit 3c893e7

Browse files
Return the number of cache hits and cache misses
1 parent da73248 commit 3c893e7

File tree

6 files changed

+39
-7
lines changed

6 files changed

+39
-7
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
name: CI
88

99
env:
10-
COMPOSER_ROOT_VERSION: "12.0.x-dev"
10+
COMPOSER_ROOT_VERSION: "12.1.x-dev"
1111

1212
jobs:
1313
coding-guidelines:

ChangeLog-12.0.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+
## [12.1.0] - 2025-MM-DD
6+
7+
### Changed
8+
9+
* `CacheWarmer::warmCache()` now returns the number of cache hits and cache misses
10+
511
## [12.0.5] - 2025-03-15
612

713
### Fixed
@@ -45,6 +51,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
4551
* This component is no longer supported on PHP 8.2
4652
* This component no longer supports Xdebug versions before Xdebug 3.1
4753

54+
[12.1.0]: https://github.com/sebastianbergmann/php-code-coverage/compare/12.0.5...main
4855
[12.0.5]: https://github.com/sebastianbergmann/php-code-coverage/compare/12.0.4...12.0.5
4956
[12.0.4]: https://github.com/sebastianbergmann/php-code-coverage/compare/12.0.3...12.0.4
5057
[12.0.3]: https://github.com/sebastianbergmann/php-code-coverage/compare/12.0.2...12.0.3

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
},
6262
"extra": {
6363
"branch-alias": {
64-
"dev-main": "12.0.x-dev"
64+
"dev-main": "12.1.x-dev"
6565
}
6666
}
6767
}

src/StaticAnalysis/CacheWarmer.php

+16-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313

1414
final class CacheWarmer
1515
{
16-
public function warmCache(string $cacheDirectory, bool $useAnnotationsForIgnoringCode, bool $ignoreDeprecatedCode, Filter $filter): void
16+
/**
17+
* @return array{cacheHits: non-negative-int, cacheMisses: non-negative-int}
18+
*/
19+
public function warmCache(string $cacheDirectory, bool $useAnnotationsForIgnoringCode, bool $ignoreDeprecatedCode, Filter $filter): array
1720
{
1821
$analyser = new CachingFileAnalyser(
1922
$cacheDirectory,
@@ -25,8 +28,19 @@ public function warmCache(string $cacheDirectory, bool $useAnnotationsForIgnorin
2528
$ignoreDeprecatedCode,
2629
);
2730

31+
$cacheHits = 0;
32+
$cacheMisses = 0;
33+
2834
foreach ($filter->files() as $file) {
29-
$analyser->process($file);
35+
$statistics = $analyser->process($file);
36+
37+
$cacheHits += $statistics['cacheHits'];
38+
$cacheMisses += $statistics['cacheMisses'];
3039
}
40+
41+
return [
42+
'cacheHits' => $cacheHits,
43+
'cacheMisses' => $cacheMisses,
44+
];
3145
}
3246
}

src/StaticAnalysis/CachingFileAnalyser.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,20 @@ public function ignoredLinesFor(string $filename): array
138138
return $this->cache[$filename]['ignoredLinesFor'];
139139
}
140140

141-
public function process(string $filename): void
141+
/**
142+
* @return array{cacheHits: non-negative-int, cacheMisses: non-negative-int}
143+
*/
144+
public function process(string $filename): array
142145
{
143146
$cache = $this->read($filename);
144147

145148
if ($cache !== false) {
146149
$this->cache[$filename] = $cache;
147150

148-
return;
151+
return [
152+
'cacheHits' => 1,
153+
'cacheMisses' => 0,
154+
];
149155
}
150156

151157
$this->cache[$filename] = [
@@ -159,6 +165,11 @@ public function process(string $filename): void
159165
];
160166

161167
$this->write($filename, $this->cache[$filename]);
168+
169+
return [
170+
'cacheHits' => 0,
171+
'cacheMisses' => 1,
172+
];
162173
}
163174

164175
/**

src/Version.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class Version
1919
public static function id(): string
2020
{
2121
if (self::$version === '') {
22-
self::$version = (new VersionId('12.0.5', dirname(__DIR__)))->asString();
22+
self::$version = (new VersionId('12.1', dirname(__DIR__)))->asString();
2323
}
2424

2525
return self::$version;

0 commit comments

Comments
 (0)