Json::output()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 6
nop 3
dl 0
loc 19
rs 9.8333
c 0
b 0
f 0
1
<?php
2
namespace exussum12\CoverageChecker\Outputs;
3
4
use exussum12\CoverageChecker\Output;
5
6
class Json implements Output
7
{
8
9
    public function output(array $coverage, float $percent, float $minimumPercent)
10
    {
11
        $violations = [];
12
        foreach ($coverage as $file => $lines) {
13
            foreach ($lines as $line => $error) {
14
                $violations[$file][] = (object) [
15
                    'lineNumber' => $line,
16
                    'message' => $error
17
                ];
18
            }
19
        }
20
        $output = (object) [
21
            'coverage' => number_format($percent, 2),
22
            'status' => $percent >= $minimumPercent ?
23
                'Passed':
24
                'Failed',
25
            'violations' => $violations
26
        ];
27
        echo json_encode($output) . "\n";
28
    }
29
}
30