Completed
Push — master ( 70065c...f2406b )
by Kevin
13:52 queued 12:36
created

ArrayReporter::prepareResult()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 0
cts 29
cp 0
rs 9.392
c 0
b 0
f 0
cc 4
nc 4
nop 3
crap 20

3 Methods

Rating   Name   Duplication   Size   Complexity  
A ArrayReporter::onBeforeRun() 0 4 1
A ArrayReporter::onStop() 0 4 1
A ArrayReporter::onFinish() 0 4 1
1
<?php
2
3
namespace Liip\MonitorBundle\Helper;
4
5
use ZendDiagnostics\Check\CheckInterface;
6
use ZendDiagnostics\Result\Collection as ResultsCollection;
7
use ZendDiagnostics\Result\ResultInterface;
8
use ZendDiagnostics\Result\SkipInterface;
9
use ZendDiagnostics\Result\SuccessInterface;
10
use ZendDiagnostics\Result\WarningInterface;
11
use ZendDiagnostics\Runner\Reporter\ReporterInterface;
12
13
/**
14
 * @author Kevin Bond <[email protected]>
15
 */
16
class ArrayReporter implements ReporterInterface
17
{
18
    const STATUS_OK = 'OK';
19
    const STATUS_KO = 'KO';
20
21
    private $globalStatus = self::STATUS_OK;
22
    private $results = [];
23
24
    /**
25
     * @return array
26
     */
27
    public function getResults()
28
    {
29
        return $this->results;
30
    }
31
32
    /**
33
     * @return string
34
     */
35
    public function getGlobalStatus()
36
    {
37
        return $this->globalStatus;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function onAfterRun(CheckInterface $check, ResultInterface $result, $checkAlias = null)
44
    {
45
        switch (true) {
46
            case $result instanceof SuccessInterface:
47
                $status = 0;
48
                $statusName = 'check_result_ok';
49
                break;
50
51
            case $result instanceof WarningInterface:
52
                $status = 1;
53
                $statusName = 'check_result_warning';
54
                $this->globalStatus = self::STATUS_KO;
55
                break;
56
57
            case $result instanceof SkipInterface:
58
                $status = 2;
59
                $statusName = 'check_result_skip';
60
                break;
61
62
            default:
63
                $status = 3;
64
                $statusName = 'check_result_critical';
65
                $this->globalStatus = self::STATUS_KO;
66
        }
67
68
        $this->results[] = [
69
            'checkName' => $check->getLabel(),
70
            'message' => $result->getMessage(),
71
            'status' => $status,
72
            'status_name' => $statusName,
73
            'service_id' => $checkAlias,
74
        ];
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function onStart(\ArrayObject $checks, $runnerConfig)
81
    {
82
        return;
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88
    public function onBeforeRun(CheckInterface $check, $checkAlias = null)
89
    {
90
        return;
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96
    public function onStop(ResultsCollection $results)
97
    {
98
        return;
99
    }
100
101
    /**
102
     * {@inheritdoc}
103
     */
104
    public function onFinish(ResultsCollection $results)
105
    {
106
        return;
107
    }
108
}
109