Completed
Push — master ( 20d667...bbf4c7 )
by Lukas Kahwe
9s
created

RawConsoleReporter::onAfterRun()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 23
rs 9.552
c 2
b 0
f 0
cc 4
nc 4
nop 3
1
<?php
2
3
namespace Liip\MonitorBundle\Helper;
4
5
use Symfony\Component\Console\Output\ConsoleOutput;
6
use Symfony\Component\Console\Output\OutputInterface;
7
use ZendDiagnostics\Check\CheckInterface;
8
use ZendDiagnostics\Result\ResultInterface;
9
use ZendDiagnostics\Result\SkipInterface;
10
use ZendDiagnostics\Result\SuccessInterface;
11
use ZendDiagnostics\Result\WarningInterface;
12
use ZendDiagnostics\Runner\Reporter\ReporterInterface;
13
use ZendDiagnostics\Result\Collection as ResultsCollection;
14
15
/**
16
 * Like ConsoleReporter, but without coloration, and no message.
17
 */
18
class RawConsoleReporter implements ReporterInterface
19
{
20
    /**
21
     * @var OutputInterface
22
     */
23
    protected $output;
24
25
    /**
26
     * @param OutputInterface $output
27
     */
28
    public function __construct(OutputInterface $output = null)
29
    {
30
        if (null === $output) {
31
            $output = new ConsoleOutput();
32
        }
33
        $this->output = $output;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function onAfterRun(CheckInterface $check, ResultInterface $result, $checkAlias = null)
40
    {
41
        switch (true) {
42
            case $result instanceof SuccessInterface:
43
                $this->output->write('OK');
44
                break;
45
46
            case $result instanceof WarningInterface:
47
                $this->output->write('WARNING');
48
                break;
49
50
            case $result instanceof SkipInterface:
51
                $this->output->write('SKIP');
52
                break;
53
54
            default:
55
                $this->output->write('FAIL');
56
        }
57
58
        $performanceData = $this->getNagiosPerformanceData();
59
60
        $this->output->writeln(sprintf(' %s', $check->getLabel().$performanceData));
61
    }
62
63
    /**
64
     * @return string
65
     */
66
    protected function getNagiosPerformanceData()
67
    {
68
        return '';
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function onStart(\ArrayObject $checks, $runnerConfig)
75
    {
76
        return;
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function onBeforeRun(CheckInterface $check, $checkAlias = null)
83
    {
84
        return;
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function onStop(ResultsCollection $results)
91
    {
92
        return;
93
    }
94
95
    /**
96
     * {@inheritdoc}
97
     */
98
    public function onFinish(ResultsCollection $results)
99
    {
100
        return;
101
    }
102
}
103