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
|
|
|
public function __construct( |
26
|
|
|
CodeSnifferStyle $codeSnifferStyle, |
27
|
|
|
ErrorDataCollector $errorDataCollector |
28
|
|
|
) { |
29
|
|
|
$this->codeSnifferStyle = $codeSnifferStyle; |
30
|
|
|
$this->errorDataCollector = $errorDataCollector; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function printFoundErrorsStatus(bool $isFixer) |
34
|
|
|
{ |
35
|
|
|
if ($isFixer) { |
36
|
|
|
$this->printUnfixedErrors(); |
37
|
|
|
} else { |
38
|
|
|
$this->printErrors(); |
39
|
|
|
$this->printFixingNote(); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
private function printUnfixedErrors() |
44
|
|
|
{ |
45
|
|
|
$this->codeSnifferStyle->writeErrorReports( |
46
|
|
|
$this->errorDataCollector->getUnfixableErrorMessages() |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
if ($this->errorDataCollector->getFixableErrorCount()) { |
50
|
|
|
$this->codeSnifferStyle->success(sprintf( |
51
|
|
|
'Congrats! %d error(s) were fixed.', |
52
|
|
|
$this->errorDataCollector->getFixableErrorCount() |
53
|
|
|
)); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
if ($this->errorDataCollector->getUnfixableErrorCount()) { |
57
|
|
|
$this->codeSnifferStyle->error(sprintf( |
58
|
|
|
'%d error(s) could not be fixed. You have to do it manually.', |
59
|
|
|
$this->errorDataCollector->getUnfixableErrorCount() |
60
|
|
|
)); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
private function printErrors() |
65
|
|
|
{ |
66
|
|
|
$this->codeSnifferStyle->writeErrorReports($this->errorDataCollector->getErrorMessages()); |
67
|
|
|
$this->codeSnifferStyle->error(sprintf( |
68
|
|
|
'%d error(s) found.', |
69
|
|
|
$this->errorDataCollector->getErrorCount() |
70
|
|
|
)); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
private function printFixingNote() |
74
|
|
|
{ |
75
|
|
|
if ($fixableCount = $this->errorDataCollector->getFixableErrorCount()) { |
76
|
|
|
$howMany = $fixableCount; |
77
|
|
|
if ($fixableCount === $this->errorDataCollector->getErrorCount()) { |
78
|
|
|
$howMany = 'all'; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$this->codeSnifferStyle->success(sprintf( |
82
|
|
|
'Good news is, we can fix %s of them for you. Just add "--fix".', |
83
|
|
|
$howMany |
84
|
|
|
)); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|