Completed
Push — master ( 23bc19...2eec4d )
by Tomáš
11:42
created

CodeSnifferStyle   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 68.97%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 61
ccs 20
cts 29
cp 0.6897
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A text() 0 4 1
A success() 0 4 1
A error() 0 4 1
A note() 0 4 1
A newLine() 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 4
    public function __construct(InputInterface $input, OutputInterface $output)
22
    {
23 4
        $this->symfonyStyle = new SymfonyStyle($input, $output);
24 4
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function text(string $message)
30
    {
31
        $this->symfonyStyle->text($message);
32
    }
33
34 2
    public function success(string $message)
35
    {
36 2
        $this->symfonyStyle->success($message);
37 2
    }
38
39 3
    public function error(string $message)
40
    {
41 3
        $this->symfonyStyle->error($message);
42 3
    }
43
44
    public function note(string $message)
45
    {
46
        $this->symfonyStyle->note($message);
47
    }
48
49
    public function newLine()
50
    {
51
        $this->symfonyStyle->newLine();
52
    }
53
54 4
    public function writeErrorReports(array $errorReports)
55
    {
56 4
        foreach ($errorReports as $file => $errors) {
57 3
            $this->symfonyStyle->section('FILE: ' . $file);
58
59 3
            $tableRows = $this->formatErrorsToTableRows($errors);
60 3
            $this->symfonyStyle->table(['Line', 'Error', 'Sniff Code', 'Fixable'], $tableRows);
61
62 3
            $this->symfonyStyle->newLine();
63
        }
64 4
    }
65
66 3
    private function formatErrorsToTableRows(array $errors) : array
67
    {
68 3
        foreach ($errors as $key => $error) {
69 3
            $errors[$key]['isFixable'] = $error['isFixable'] ? 'YES' : 'No';
70
        }
71
72 3
        return $errors;
73
    }
74
}
75