Completed
Push — master ( 295638...aca6e3 )
by Vladimir
05:35
created

ArrayReporter::onFinish()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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
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...
39
     * {@inheritdoc}
40
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
41
    public function onAfterRun(CheckInterface $check, ResultInterface $result, $checkAlias = null)
42
    {
43
        list($statusName, $statusCode) = $this->getStatusByResul($result);
44
45
        $this->statusCode = max($this->statusCode, $statusCode);
46
47
        $res = [
48
            'statusCode' => $statusCode,
49
            'statusName' => $statusName,
50
            'label' => $check->getLabel(),
51
            'check' => $checkAlias,
52
            'message' => $result->getMessage(),
53
            'tags' => $check->getTags(),
54
            'group' => $check->getGroup(),
55
        ];
56
57
        $data = $result->getData();
58
        if (null !== $data) {
59
            if ($data instanceof \Exception) {
60
                $res['data'] = $data->getMessage();
61
            } else {
62
                $res['data'] = $data;
63
            }
64
        }
65
66
        $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...
67
            return \is_array($v) ? !empty($v) : (null !== $v);
68
        });
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...
69
70
        $this->checkResults[] = $res;
71
    }
72
73
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
74
     * @return int
75
     */
76
    public function getStatusCode()
77
    {
78
        return $this->statusCode;
79
    }
80
81
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
82
     * @return string
83
     */
84
    public function getStatusName()
85
    {
86
        return $this->statusName;
87
    }
88
89
    public function getCheckResults(): array
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getCheckResults()
Loading history...
90
    {
91
        return $this->checkResults;
92
    }
93
94
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $results should have a doc-comment as per coding-style.
Loading history...
95
     * {@inheritdoc}
96
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
97
    public function onFinish(ResultsCollection $results)
98
    {
99
        parent::onFinish($results);
100
101
        $this->statusName = self::getStatusNameByCode($this->statusCode);
102
    }
103
}
104