Completed
Push — master ( 2eec4d...df0d5e )
by Tomáš
03:19
created

CodeSnifferStyle   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 43
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A success() 0 4 1
A error() 0 4 1
A writeErrorReports() 0 11 2
A formatErrorsToTableRows() 0 8 3
1
<?php
2
3
/*
4
 * This file is part of Symplify
5
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
6
 */
7
8
namespace Symplify\PHP7_CodeSniffer\Console\Style;
9
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
use Symfony\Component\Console\Style\SymfonyStyle;
13
14
final class CodeSnifferStyle
15
{
16
    /**
17
     * @var SymfonyStyle
18
     */
19
    private $symfonyStyle;
20
21 7
    public function __construct(InputInterface $input, OutputInterface $output)
22
    {
23 7
        $this->symfonyStyle = new SymfonyStyle($input, $output);
24 7
    }
25
26 3
    public function success(string $message)
27
    {
28 3
        $this->symfonyStyle->success($message);
29 3
    }
30
31 4
    public function error(string $message)
32
    {
33 4
        $this->symfonyStyle->error($message);
34 4
    }
35
36 5
    public function writeErrorReports(array $errorReports)
37
    {
38 5
        foreach ($errorReports as $file => $errors) {
39 4
            $this->symfonyStyle->section('FILE: ' . $file);
40
41 4
            $tableRows = $this->formatErrorsToTableRows($errors);
42 4
            $this->symfonyStyle->table(['Line', 'Error', 'Sniff Code', 'Fixable'], $tableRows);
43
44 4
            $this->symfonyStyle->newLine();
45
        }
46 5
    }
47
48 4
    private function formatErrorsToTableRows(array $errors) : array
49
    {
50 4
        foreach ($errors as $key => $error) {
51 4
            $errors[$key]['isFixable'] = $error['isFixable'] ? 'YES' : 'No';
52
        }
53
54 4
        return $errors;
55
    }
56
}
57