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

Phpcs   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 51
rs 10
wmc 6
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A output() 0 15 3
A displayErrors() 0 20 2
A addTotal() 0 8 1
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