Completed
Push — master ( 56185f...c80cc1 )
by Scott
13s
created

Phpcs::addTotal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 8
rs 9.4285
1
<?php
2
namespace exussum12\CoverageChecker\Outputs;
3
4
use exussum12\CoverageChecker\Output;
5
6
class Phpcs implements Output
7
{
8
9
    private $violations;
10
11
    public function output($coverage, $percent, $minimumPercent)
12
    {
13
        $this->violations = ['files' => []];
14
        $total = 0;
15
        foreach ($coverage as $file => $lines) {
16
            foreach ($lines as $line => $errors) {
17
                $this->displayErrors($errors, $file, $line);
18
            }
19
            $total++;
20
        }
21
22
        $this->addTotal($total);
23
24
        echo json_encode($this->violations) . "\n";
25
    }
26
27
    protected function displayErrors($errors, $file, $line)
28
    {
29
        foreach ($errors as $error) {
30
            $current = &$this->violations['files'][$file];
31
            $current['messages'][] = [
32
                'message' => $error,
33
                'source' => 'diffFilter',
34
                'severity' => 1,
35
                'type' => 'ERROR',
36
                'line' => $line,
37
                'column' => 1,
38
                'fixable' => 'false',
39
            ];
40
41
            $current['errors'] = count(
42
                $current['messages']
43
            );
44
            $current['warnings'] = 0;
45
        }
46
    }
47
48
    protected function addTotal($total)
49
    {
50
        $this->violations['totals'] = [
51
            'errors' => $total,
52
            'fixable' => 0,
53
            'warnings' => 0,
54
        ];
55
    }
56
}
57