Json   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A output() 0 19 4
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