Skip to content

Commit

Permalink
Include configuration settings that affect source code parsing in sta…
Browse files Browse the repository at this point in the history
…tic analysis cache keys
  • Loading branch information
sebastianbergmann committed Jun 25, 2023
1 parent 2ca4e89 commit e82f3f7
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
7 changes: 7 additions & 0 deletions ChangeLog-9.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

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

## [9.2.27] - 2023-MM-DD

### Fixed

* Static analysis cache keys do not include configuration settings that affect source code parsing

## [9.2.26] - 2023-03-06

### Changed
Expand Down Expand Up @@ -476,6 +482,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt

* This component is no longer supported on PHP 7.1

[9.2.27]: https://github.com/sebastianbergmann/php-code-coverage/compare/9.2.26...9.2
[9.2.26]: https://github.com/sebastianbergmann/php-code-coverage/compare/9.2.25...9.2.26
[9.2.25]: https://github.com/sebastianbergmann/php-code-coverage/compare/9.2.24...9.2.25
[9.2.24]: https://github.com/sebastianbergmann/php-code-coverage/compare/9.2.23...9.2.24
Expand Down
4 changes: 3 additions & 1 deletion src/CodeCoverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,9 @@ private function analyser(): FileAnalyser
if ($this->cachesStaticAnalysis()) {
$this->analyser = new CachingFileAnalyser(
$this->cacheDirectory,
$this->analyser
$this->analyser,
$this->useAnnotationsForIgnoringCode,
$this->ignoreDeprecatedCode
);
}

Expand Down
4 changes: 3 additions & 1 deletion src/StaticAnalysis/CacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public function warmCache(string $cacheDirectory, bool $useAnnotationsForIgnorin
new ParsingFileAnalyser(
$useAnnotationsForIgnoringCode,
$ignoreDeprecatedCode
)
),
$useAnnotationsForIgnoringCode,
$ignoreDeprecatedCode,
);

foreach ($filter->files() as $file) {
Expand Down
41 changes: 33 additions & 8 deletions src/StaticAnalysis/CachingFileAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,39 @@ final class CachingFileAnalyser implements FileAnalyser
*/
private static $cacheVersion;

/**
* @var string
*/
private $directory;

/**
* @var FileAnalyser
*/
private $analyser;

/**
* @var array
* @var bool
*/
private $cache = [];
private $useAnnotationsForIgnoringCode;

/**
* @var string
* @var bool
*/
private $directory;
private $ignoreDeprecatedCode;

/**
* @var array
*/
private $cache = [];

public function __construct(string $directory, FileAnalyser $analyser)
public function __construct(string $directory, FileAnalyser $analyser, bool $useAnnotationsForIgnoringCode, bool $ignoreDeprecatedCode)
{
Filesystem::createDirectory($directory);

$this->analyser = $analyser;
$this->directory = $directory;
$this->analyser = $analyser;
$this->directory = $directory;
$this->useAnnotationsForIgnoringCode = $useAnnotationsForIgnoringCode;
$this->ignoreDeprecatedCode = $ignoreDeprecatedCode;
}

public function classesIn(string $filename): array
Expand Down Expand Up @@ -161,7 +173,20 @@ private function write(string $filename, $data): void

private function cacheFile(string $filename): string
{
return $this->directory . DIRECTORY_SEPARATOR . md5($filename . "\0" . file_get_contents($filename) . "\0" . self::cacheVersion());
$cacheKey = md5(
implode(
"\0",
[
$filename,
file_get_contents($filename),
self::cacheVersion(),
$this->useAnnotationsForIgnoringCode,
$this->ignoreDeprecatedCode,
]
)
);

return $this->directory . DIRECTORY_SEPARATOR . $cacheKey;
}

private static function cacheVersion(): string
Expand Down

0 comments on commit e82f3f7

Please sign in to comment.