Completed
Push — master ( e9a9f0...13c004 )
by Vladimir
06:49
created

Api::onAfterRun()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 31
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 4.002

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 31
ccs 19
cts 20
cp 0.95
rs 9.6
c 0
b 0
f 0
cc 4
nc 3
nop 3
crap 4.002
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 ZendDiagnostics\Result\Collection as ResultsCollection;
15
use ZendDiagnostics\Result\ResultInterface;
16
use ZendDiagnostics\Check\CheckInterface;
17
use Tvi\MonitorBundle\Check\CheckInterface as TviCheckInterface;
18
19
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
20
 * @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...
21
 */
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...
22
class Api extends ReporterAbstract
23
{
24
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
25
     * @var int
26
     */
27
    protected $statusCode = self::STATUS_CODE_SUCCESS;
28
29
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
30
     * @var string
31
     */
32
    protected $statusName = self::STATUS_NAME_SUCCESS;
33
34
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
35
     * @var array
36
     */
37
    protected $checkResults = [];
38
39
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $result should have a doc-comment as per coding-style.
Loading history...
40
     * @param CheckInterface|TviCheckInterface $check
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
41
     * @param null|mixed                       $checkAlias
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Doc comment for parameter $checkAlias does not match actual variable name $result
Loading history...
42
     *
43
     * @return bool|void
44
     */
45 46
    public function onAfterRun(CheckInterface $check, ResultInterface $result, $checkAlias = null)
46
    {
47 46
        list($statusName, $statusCode) = $this->getStatusByResul($result);
48
49 46
        $this->statusCode = max($this->statusCode, $statusCode);
50
51
        $res = [
52 46
            'statusCode' => $statusCode,
53 46
            'statusName' => $statusName,
54 46
            'label' => $check->getLabel(),
55 46
            'check' => $checkAlias,
56 46
            'message' => $result->getMessage(),
57 46
            'importance' => $check->getImportance(),
0 ignored issues
show
Bug introduced by
The method getImportance() does not exist on ZendDiagnostics\Check\CheckInterface. It seems like you code against a sub-type of ZendDiagnostics\Check\CheckInterface such as Tvi\MonitorBundle\Check\CheckAbstract. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
            'importance' => $check->/** @scrutinizer ignore-call */ getImportance(),
Loading history...
58 46
            'tags' => $check->getTags(),
0 ignored issues
show
Bug introduced by
The method getTags() does not exist on ZendDiagnostics\Check\CheckInterface. It seems like you code against a sub-type of ZendDiagnostics\Check\CheckInterface such as Tvi\MonitorBundle\Check\CheckAbstract. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
            'tags' => $check->/** @scrutinizer ignore-call */ getTags(),
Loading history...
59 46
            'group' => $check->getGroup(),
0 ignored issues
show
Bug introduced by
The method getGroup() does not exist on ZendDiagnostics\Check\CheckInterface. It seems like you code against a sub-type of ZendDiagnostics\Check\CheckInterface such as Tvi\MonitorBundle\Check\CheckAbstract. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
            'group' => $check->/** @scrutinizer ignore-call */ getGroup(),
Loading history...
60
        ];
61
62 46
        $data = $result->getData();
63 46
        if (null !== $data) {
64 46
            if ($data instanceof \Exception) {
65
                $res['data'] = $data->getMessage();
66
            } else {
67 46
                $res['data'] = $data;
68
            }
69
        }
70
71 46
        $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 46
            return \is_array($v) ? !empty($v) : (null !== $v);
73 46
        });
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 46
        $this->checkResults[] = $res;
76 46
    }
77
78
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
79
     * @return int
80
     */
81 33
    public function getStatusCode()
82
    {
83 33
        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 33
    public function getStatusName()
90
    {
91 33
        return $this->statusName;
92
    }
93
94 38
    public function getCheckResults(): array
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getCheckResults()
Loading history...
95
    {
96 38
        return $this->checkResults;
97
    }
98
99
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $results should have a doc-comment as per coding-style.
Loading history...
100
     * {@inheritdoc}
101
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
102 56
    public function onFinish(ResultsCollection $results)
103
    {
104 56
        parent::onFinish($results);
105
106 56
        $this->statusName = self::getStatusNameByCode($this->statusCode);
107 56
    }
108
}
109