|
15 | 15 | use function fopen; |
16 | 16 | use function is_array; |
17 | 17 | use function is_bool; |
| 18 | +use function is_int; |
18 | 19 | use function is_string; |
19 | 20 | use function preg_match; |
20 | 21 | use function restore_error_handler; |
21 | 22 | use function set_error_handler; |
22 | 23 | use function trim; |
23 | 24 | use SebastianBergmann\CodeCoverage\Data\ProcessedCodeCoverageData; |
24 | | -use SebastianBergmann\CodeCoverage\Version; |
25 | 25 |
|
26 | 26 | /** |
27 | 27 | * @phpstan-import-type SerializedCoverage from Serializer |
@@ -55,14 +55,14 @@ public function unserialize(string $path): array |
55 | 55 | throw new FileCouldNotBeReadException('Cannot read from file: ' . $path); |
56 | 56 | } |
57 | 57 |
|
58 | | - if (preg_match('/^<\?php \/\/ phpunit\/php-code-coverage version (.+)$/', trim($firstLine), $matches) !== 1) { |
59 | | - throw new FileCouldNotBeReadException('File does not contain phpunit/php-code-coverage version information: ' . $path); |
| 58 | + if (preg_match('/^<\?php \/\/ phpunit\/php-code-coverage serialization format (\d+)$/', trim($firstLine), $matches) !== 1) { |
| 59 | + throw new FileCouldNotBeReadException('File does not contain phpunit/php-code-coverage serialization format information: ' . $path); |
60 | 60 | } |
61 | 61 |
|
62 | | - $storedVersion = $matches[1]; |
| 62 | + $storedFormat = (int) $matches[1]; |
63 | 63 |
|
64 | | - if ($storedVersion !== Version::id()) { |
65 | | - throw new VersionMismatchException($storedVersion, Version::id()); |
| 64 | + if ($storedFormat !== Serializer::SERIALIZATION_FORMAT) { |
| 65 | + throw new VersionMismatchException($storedFormat, Serializer::SERIALIZATION_FORMAT); |
66 | 66 | } |
67 | 67 |
|
68 | 68 | set_error_handler( |
@@ -126,6 +126,10 @@ private function validate(mixed $data): void |
126 | 126 | throw new InvalidCoverageDataException('Coverage data is missing valid \'buildInformation.phpCodeCoverage.version\' key'); |
127 | 127 | } |
128 | 128 |
|
| 129 | + if (!array_key_exists('serializationFormat', $phpCodeCoverage) || !is_int($phpCodeCoverage['serializationFormat'])) { |
| 130 | + throw new InvalidCoverageDataException('Coverage data is missing valid \'buildInformation.phpCodeCoverage.serializationFormat\' key'); |
| 131 | + } |
| 132 | + |
129 | 133 | if (!array_key_exists('driverInformation', $phpCodeCoverage) || !is_array($phpCodeCoverage['driverInformation'])) { |
130 | 134 | throw new InvalidCoverageDataException('Coverage data is missing valid \'buildInformation.phpCodeCoverage.driverInformation\' key'); |
131 | 135 | } |
|
0 commit comments