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

InfoMessagePrinter   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 75
ccs 36
cts 36
cp 1
rs 10
c 1
b 0
f 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A printFoundErrorsStatus() 0 9 2
A printUnfixedErrors() 0 20 3
A printErrors() 0 8 1
A printFixingNote() 0 14 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\Output;
9
10
use Symplify\PHP7_CodeSniffer\Console\Style\CodeSnifferStyle;
11
use Symplify\PHP7_CodeSniffer\Report\ErrorDataCollector;
12
13
final class InfoMessagePrinter
14
{
15
    /**
16
     * @var CodeSnifferStyle
17
     */
18
    private $codeSnifferStyle;
19
20
    /**
21
     * @var ErrorDataCollector
22
     */
23
    private $errorDataCollector;
24
25 4
    public function __construct(
26
        CodeSnifferStyle $codeSnifferStyle,
27
        ErrorDataCollector $errorDataCollector
28
    ) {
29 4
        $this->codeSnifferStyle = $codeSnifferStyle;
30 4
        $this->errorDataCollector = $errorDataCollector;
31 4
    }
32
33 4
    public function printFoundErrorsStatus(bool $isFixer)
34
    {
35 4
        if ($isFixer) {
36 3
            $this->printUnfixedErrors();
37
        } else {
38 1
            $this->printErrors();
39 1
            $this->printFixingNote();
40
        }
41 4
    }
42
43 3
    private function printUnfixedErrors()
44
    {
45 3
        $this->codeSnifferStyle->writeErrorReports(
46 3
            $this->errorDataCollector->getUnfixableErrorMessages()
47
        );
48
49 3
        if ($this->errorDataCollector->getFixableErrorCount()) {
50 1
            $this->codeSnifferStyle->success(sprintf(
51 1
                'Congrats! %d error(s) were fixed.',
52 1
                $this->errorDataCollector->getFixableErrorCount()
53
            ));
54
        }
55
56 3
        if ($this->errorDataCollector->getUnfixableErrorCount()) {
57 2
            $this->codeSnifferStyle->error(sprintf(
58 2
                '%d error(s) could not be fixed. You have to do it manually.',
59 2
                $this->errorDataCollector->getUnfixableErrorCount()
60
            ));
61
        }
62 3
    }
63
64 1
    private function printErrors()
65
    {
66 1
        $this->codeSnifferStyle->writeErrorReports($this->errorDataCollector->getErrorMessages());
67 1
        $this->codeSnifferStyle->error(sprintf(
68 1
            '%d error(s) found.',
69 1
            $this->errorDataCollector->getErrorCount()
70
        ));
71 1
    }
72
73 1
    private function printFixingNote()
74
    {
75 1
        if ($fixableCount = $this->errorDataCollector->getFixableErrorCount()) {
76 1
            $howMany = $fixableCount;
77 1
            if ($fixableCount === $this->errorDataCollector->getErrorCount()) {
78 1
                $howMany = 'ALL';
79
            }
80
81 1
            $this->codeSnifferStyle->success(sprintf(
82 1
                'Good news is, we can fix %s of them for you. Just add "--fix".',
83
                $howMany
84
            ));
85
        }
86 1
    }
87
}
88