Skip to content

Commit

Permalink
Merge branch '9.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Aug 30, 2022
2 parents f87b8bf + 2e94d03 commit b807765
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
7 changes: 7 additions & 0 deletions ChangeLog.md
Expand Up @@ -19,6 +19,12 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
* This component is no longer supported on PHP 7.3, PHP 7.4 and PHP 8.0
* This component no longer supports Xdebug 2

## [9.2.17] - 2022-MM-DD

### Fixed

* [#926](https://github.com/sebastianbergmann/php-code-coverage/pull/926): Static Analysis cache does not work with `open_basedir`

## [9.2.16] - 2022-08-20

### Fixed
Expand Down Expand Up @@ -422,6 +428,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

[10.0.0]: https://github.com/sebastianbergmann/php-code-coverage/compare/9.2...master
[9.2.17]: https://github.com/sebastianbergmann/php-code-coverage/compare/9.2.16...9.2
[9.2.16]: https://github.com/sebastianbergmann/php-code-coverage/compare/9.2.15...9.2.16
[9.2.15]: https://github.com/sebastianbergmann/php-code-coverage/compare/9.2.14...9.2.15
[9.2.14]: https://github.com/sebastianbergmann/php-code-coverage/compare/9.2.13...9.2.14
Expand Down
24 changes: 11 additions & 13 deletions src/StaticAnalysis/CachingFileAnalyser.php
Expand Up @@ -9,15 +9,13 @@
*/
namespace SebastianBergmann\CodeCoverage\StaticAnalysis;

use function assert;
use function crc32;
use function file_get_contents;
use function file_put_contents;
use function is_file;
use function serialize;
use GlobIterator;
use SebastianBergmann\CodeCoverage\Util\Filesystem;
use SplFileInfo;
use SebastianBergmann\FileIterator\Facade as FileIteratorFacade;

/**
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
Expand All @@ -38,10 +36,6 @@ public function __construct(string $directory, FileAnalyser $analyser)

$this->analyser = $analyser;
$this->directory = $directory;

if (self::$cacheVersion === null) {
$this->calculateCacheVersion();
}
}

public function classesIn(string $filename): array
Expand Down Expand Up @@ -150,19 +144,23 @@ private function write(string $filename, array $data): void

private function cacheFile(string $filename): string
{
return $this->directory . DIRECTORY_SEPARATOR . hash('sha256', $filename . crc32(file_get_contents($filename)) . self::$cacheVersion);
return $this->directory . DIRECTORY_SEPARATOR . hash('sha256', $filename . crc32(file_get_contents($filename)) . self::cacheVersion());
}

private function calculateCacheVersion(): void
private static function cacheVersion(): string
{
$buffer = '';
if (self::$cacheVersion !== null) {
return self::$cacheVersion;
}

foreach (new GlobIterator(__DIR__ . '/*.php') as $file) {
assert($file instanceof SplFileInfo);
$buffer = '';

$buffer .= file_get_contents($file->getPathname());
foreach ((new FileIteratorFacade)->getFilesAsArray(__DIR__, '.php') as $file) {
$buffer .= file_get_contents($file);
}

self::$cacheVersion = (string) crc32($buffer);

return self::$cacheVersion;
}
}

0 comments on commit b807765

Please sign in to comment.