1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Liip\MonitorBundle\Helper; |
4
|
|
|
|
5
|
|
|
use Laminas\Diagnostics\Check\CheckInterface; |
6
|
|
|
use Laminas\Diagnostics\Result\Collection as ResultsCollection; |
7
|
|
|
use Laminas\Diagnostics\Result\ResultInterface; |
8
|
|
|
use Laminas\Diagnostics\Result\SkipInterface; |
9
|
|
|
use Laminas\Diagnostics\Result\SuccessInterface; |
10
|
|
|
use Laminas\Diagnostics\Result\WarningInterface; |
11
|
|
|
use Laminas\Diagnostics\Runner\Reporter\ReporterInterface; |
12
|
|
|
use Symfony\Component\Console\Output\ConsoleOutput; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @author Kevin Bond <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
class ConsoleReporter implements ReporterInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var OutputInterface |
22
|
|
|
*/ |
23
|
|
|
protected $output; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param OutputInterface $output |
27
|
|
|
*/ |
28
|
|
View Code Duplication |
public function __construct(OutputInterface $output = null) |
29
|
|
|
{ |
30
|
|
|
if (null === $output) { |
31
|
|
|
$output = new ConsoleOutput(); |
32
|
|
|
} |
33
|
|
|
$this->output = $output; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function setOutput(OutputInterface $output) |
37
|
|
|
{ |
38
|
|
|
$this->output = $output; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function onAfterRun(CheckInterface $check, ResultInterface $result, $checkAlias = null) |
42
|
|
|
{ |
43
|
|
View Code Duplication |
switch (true) { |
|
|
|
|
44
|
|
|
case $result instanceof SuccessInterface: |
45
|
|
|
$this->output->write('<info>OK</info>'); |
46
|
|
|
break; |
47
|
|
|
|
48
|
|
|
case $result instanceof WarningInterface: |
49
|
|
|
$this->output->write('<comment>WARNING</comment>'); |
50
|
|
|
break; |
51
|
|
|
|
52
|
|
|
case $result instanceof SkipInterface: |
53
|
|
|
$this->output->write('<question>SKIP</question>'); |
54
|
|
|
break; |
55
|
|
|
|
56
|
|
|
default: |
57
|
|
|
$this->output->write('<error>FAIL</error>'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$this->output->write(sprintf(' %s', $check->getLabel())); |
61
|
|
|
|
62
|
|
|
if ($message = $result->getMessage()) { |
63
|
|
|
$this->output->write(sprintf(': %s', $message)); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$this->output->writeln(''); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function onStart(\ArrayObject $checks, $runnerConfig) |
70
|
|
|
{ |
71
|
|
|
return; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function onBeforeRun(CheckInterface $check, $checkAlias = null) |
75
|
|
|
{ |
76
|
|
|
return; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function onStop(ResultsCollection $results) |
80
|
|
|
{ |
81
|
|
|
return; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function onFinish(ResultsCollection $results) |
85
|
|
|
{ |
86
|
|
|
return; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.