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 98cd09c + 614e84a commit a99602d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Expand Up @@ -24,6 +24,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
### Changed

* [#928](https://github.com/sebastianbergmann/php-code-coverage/pull/928): Avoid unnecessary `is_file()` calls
* [#931](https://github.com/sebastianbergmann/php-code-coverage/pull/931): Use MD5 instead of CRC32 for static analysis cache file identifier

### Fixed

Expand Down
12 changes: 7 additions & 5 deletions src/StaticAnalysis/CachingFileAnalyser.php
Expand Up @@ -9,10 +9,11 @@
*/
namespace SebastianBergmann\CodeCoverage\StaticAnalysis;

use function crc32;
use function file_get_contents;
use function file_put_contents;
use function implode;
use function is_file;
use function md5;
use function serialize;
use SebastianBergmann\CodeCoverage\Util\Filesystem;
use SebastianBergmann\FileIterator\Facade as FileIteratorFacade;
Expand Down Expand Up @@ -144,7 +145,7 @@ 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 . md5($filename . "\0" . file_get_contents($filename) . "\0" . self::cacheVersion());
}

private static function cacheVersion(): string
Expand All @@ -153,13 +154,14 @@ private static function cacheVersion(): string
return self::$cacheVersion;
}

$buffer = '';
$buffer = [];

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

self::$cacheVersion = (string) crc32($buffer);
self::$cacheVersion = md5(implode("\0", $buffer));

return self::$cacheVersion;
}
Expand Down

0 comments on commit a99602d

Please sign in to comment.