Completed
Push — master ( 3ccb4d...f0ec0e )
by Vladimir
05:12
created

ArrayReporter::onStart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 0
dl 0
loc 2
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
/**
4
 * This file is part of the `tvi/monitor-bundle` project.
5
 *
6
 * (c) https://github.com/turnaev/monitor-bundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
Coding Style introduced by
Missing @link tag in file comment
Loading history...
11
12
namespace Tvi\MonitorBundle\Reporter;
13
14
use Tvi\MonitorBundle\Check\CheckInterface;
15
use ZendDiagnostics\Result\Collection as ResultsCollection;
16
use ZendDiagnostics\Result\ResultInterface;
17
18
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
19
 * @author Kevin Bond <[email protected]>, Vladimir Turnaev <[email protected]>
0 ignored issues
show
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
20
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
21
class ArrayReporter extends AbstractReporter
22
{
23
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
24
     * @var int
25
     */
26
    protected $statusCode = self::STATUS_CODE_SUCCESS;
27
28
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
29
     * @var string
30
     */
31
    protected $statusName = self::STATUS_NAME_SUCCESS;
32
33
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
34
     * @var array
35
     */
36
    protected $checkResults = [];
37
38
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
39
     * @var ResultsCollection
40
     */
41
    protected $results;
42
43
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $check should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $result should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $checkAlias should have a doc-comment as per coding-style.
Loading history...
44
     * {@inheritdoc}
45
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
46
    public function onAfterRun(CheckInterface $check, ResultInterface $result, $checkAlias = null)
47
    {
48
        list($statusName, $statusCode) = $this->getStatusByResul($result);
49
50
        $this->statusCode = max($this->statusCode, $statusCode);
51
52
        $res = [
53
            'statusCode' => $statusCode,
54
            'statusName' => $statusName,
55
            'label' => $check->getLabel(),
56
            'check' => $checkAlias,
57
            'message' => $result->getMessage(),
58
            'tags' => $check->getTags(),
59
            'group' => $check->getGroup(),
60
        ];
61
62
        $data = $result->getData();
63
        if (null !== $data) {
64
            if ($data instanceof \Exception) {
65
                $res['data'] = $data->getMessage();
66
            } else {
67
                $res['data'] = $data;
68
            }
69
        }
70
71
        $res = array_filter($res, static function ($v) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
72
            return \is_array($v) ? !empty($v) : (null !== $v);
73
        });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
74
75
        $this->checkResults[] = $res;
76
    }
77
78
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
79
     * @return int
80
     */
81
    public function getStatusCode()
82
    {
83
        return $this->statusCode;
84
    }
85
86
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
87
     * @return string
88
     */
89
    public function getStatusName()
90
    {
91
        return $this->statusName;
92
    }
93
94
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
95
     * @return int
96
     */
97
    public function getSuccessCount()
98
    {
99
        return $this->results ? $this->results->getSuccessCount() : null;
100
    }
101
102
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
103
     * @return int
104
     */
105
    public function getWarningCount()
106
    {
107
        return $this->results ? $this->results->getWarningCount() : null;
108
    }
109
110
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
111
     * @return int
112
     */
113
    public function getFailureCount()
114
    {
115
        return $this->results ? $this->results->getFailureCount() : null;
116
    }
117
118
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
119
     * @return int
120
     */
121
    public function getSkipCount()
122
    {
123
        return $this->results ? $this->results->getSkipCount() : null;
124
    }
125
126
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
127
     * @return int
128
     */
129
    public function getUnknownCount()
130
    {
131
        return $this->results ? $this->results->getUnknownCount() : null;
132
    }
133
134
    public function getCheckResults(): array
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getCheckResults()
Loading history...
135
    {
136
        return $this->checkResults;
137
    }
138
139
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $checks should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $runnerConfig should have a doc-comment as per coding-style.
Loading history...
140
     * {@inheritdoc}
141
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
142
    public function onStart(\ArrayObject $checks, $runnerConfig)
143
    {
144
    }
145
146
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $check should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $checkAlias should have a doc-comment as per coding-style.
Loading history...
147
     * {@inheritdoc}
148
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
149
    public function onBeforeRun(CheckInterface $check, $checkAlias = null)
150
    {
151
    }
152
153
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $results should have a doc-comment as per coding-style.
Loading history...
154
     * {@inheritdoc}
155
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
156
    public function onStop(ResultsCollection $results)
157
    {
158
    }
159
160
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $results should have a doc-comment as per coding-style.
Loading history...
161
     * {@inheritdoc}
162
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
163
    public function onFinish(ResultsCollection $results)
164
    {
165
        $this->results = $results;
166
167
        $this->statusName = self::getStatusNameByCode($this->statusCode);
168
    }
169
}
170