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