forked from sebastianbergmann/php-code-coverage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessedCodeCoverageDataMapper.php
More file actions
49 lines (41 loc) · 1.64 KB
/
ProcessedCodeCoverageDataMapper.php
File metadata and controls
49 lines (41 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php declare(strict_types=1);
/*
* This file is part of phpunit/php-code-coverage.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeCoverage\Data;
use function json_decode;
use function json_encode;
/**
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
*
* @psalm-import-type XdebugFunctionCoverageType from \SebastianBergmann\CodeCoverage\Driver\XdebugDriver
*
* @psalm-type TestIdType = string
*/
final class ProcessedCodeCoverageDataMapper
{
public const KEY_LINE_COVERAGE = 'lineCoverage';
public const KEY_FUNCTION_COVERAGE = 'functionCoverage';
public function toJson(ProcessedCodeCoverageData $processedCodeCoverageData): string
{
$arrayMapping = [
self::KEY_LINE_COVERAGE => $processedCodeCoverageData->lineCoverage(),
self::KEY_FUNCTION_COVERAGE => $processedCodeCoverageData->functionCoverage(),
];
return json_encode($arrayMapping);
}
public function fromJson(string $json): ProcessedCodeCoverageData
{
/** @var array<array-key, array<array-key, mixed>> */
$unserializedData = json_decode($json, true);
$processedCodeCoverageData = new ProcessedCodeCoverageData;
$processedCodeCoverageData->setLineCoverage($unserializedData[self::KEY_LINE_COVERAGE]);
$processedCodeCoverageData->setFunctionCoverage($unserializedData[self::KEY_FUNCTION_COVERAGE]);
return $processedCodeCoverageData;
}
}