Completed
Push — master ( 033231...4a0dad )
by Kevin
12s queued 10s
created

StreamedReporter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Liip\MonitorBundle\Helper;
4
5
use ArrayObject;
6
use ZendDiagnostics\Check\CheckInterface;
7
use ZendDiagnostics\Result\Collection as ResultsCollection;
8
use ZendDiagnostics\Result\ResultInterface;
9
use ZendDiagnostics\Runner\Reporter\ReporterInterface;
10
11
class StreamedReporter implements ReporterInterface
12
{
13
    /**
14
     * @var ArrayReporter
15
     */
16
    private $arrayReporter;
17
18
    public function __construct()
19
    {
20
        $this->arrayReporter = new ArrayReporter();
21
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function onStart(ArrayObject $checks, $runnerConfig)
27
    {
28
        echo '{"checks":[';
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function onBeforeRun(CheckInterface $check, $checkAlias = null)
35
    {
36
        static $comma = '';
37
        echo $comma;
38
        $comma = ',';
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function onAfterRun(CheckInterface $check, ResultInterface $result, $checkAlias = null)
45
    {
46
        echo json_encode($this->arrayReporter->prepareResult($check, $result, $checkAlias));
47
        ob_flush();
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function onStop(ResultsCollection $results)
54
    {
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function onFinish(ResultsCollection $results)
61
    {
62
        echo '],"globalStatus":"'.$this->arrayReporter->getGlobalStatus().'"}';
63
    }
64
}
65