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
|
|
|
|