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

AbstractReporter::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 1
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 ZendDiagnostics\Result\FailureInterface;
15
use ZendDiagnostics\Result\ResultInterface;
16
use ZendDiagnostics\Result\SkipInterface;
17
use ZendDiagnostics\Result\SuccessInterface;
18
use ZendDiagnostics\Result\WarningInterface;
19
use ZendDiagnostics\Runner\Reporter\ReporterInterface;
20
use ArrayObject;
21
use ZendDiagnostics\Check\CheckInterface;
22
use ZendDiagnostics\Result\Collection as ResultsCollection;
23
24
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
25
 * @author Vladimir Turnaev <[email protected]>
26
 */
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...
27
abstract class AbstractReporter implements ReporterInterface
28
{
29
    public const STATUS_CODE_SUCCESS = 0;
30
    public const STATUS_CODE_WARNING = 100;
31
    public const STATUS_CODE_SKIP = 200;
32
    public const STATUS_CODE_UNKNOWN = 300;
33
    public const STATUS_CODE_FAILURE = 1000;
34
35
    public const STATUS_NAME_SUCCESS = 'SUCCESS';
36
    public const STATUS_NAME_WARNING = 'WARNING';
37
    public const STATUS_NAME_SKIP = 'SKIP';
38
    public const STATUS_NAME_UNKNOWN = 'UNKNOWN';
39
    public const STATUS_NAME_FAILURE = 'FAILURE';
40
41
    public static $STATUS_MAP = [
42
        self::STATUS_CODE_SUCCESS => self::STATUS_NAME_SUCCESS,
43
        self::STATUS_CODE_WARNING => self::STATUS_NAME_WARNING,
44
        self::STATUS_CODE_SKIP => self::STATUS_NAME_SKIP,
45
        self::STATUS_CODE_UNKNOWN => self::STATUS_NAME_UNKNOWN,
46
        self::STATUS_CODE_FAILURE => self::STATUS_NAME_FAILURE,
47
    ];
48
49
    public static function getStatusNameByCode(int $statusCode): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getStatusNameByCode()
Loading history...
50
    {
51
        return isset(self::$STATUS_MAP[$statusCode]) ? self::$STATUS_MAP[$statusCode] : self::STATUS_NAME_UNKNOWN;
52
    }
53
54
    /**
55
     * This method is called right after Reporter starts running, via Runner::run().
56
     *
57
     * @param ArrayObject $checks       A collection of Checks that will be performed
58
     * @param array       $runnerConfig Complete Runner configuration, obtained via Runner::getConfig()
59
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
60
    public function onStart(ArrayObject $checks, $runnerConfig)
61
    {
62
    }
63
64
    /**
65
     * This method is called before each individual Check is performed. If this
66
     * method returns false, the Check will not be performed (will be skipped).
67
     *
68
     * @param CheckInterface $check      check instance that is about to be performed
69
     * @param string|null    $checkAlias The alias for the check that is about to be performed
70
     *
71
     * @return bool|void Return false to prevent check from happening
72
     */
73
    public function onBeforeRun(CheckInterface $check, $checkAlias = null)
74
    {
75
    }
76
77
    /**
78
     * This method is called every time a Check has been performed. If this method
79
     * returns false, the Runner will not perform any additional checks and stop
80
     * its run.
81
     *
82
     * @param CheckInterface  $check      A Check instance that has just finished running
83
     * @param ResultInterface $result     Result for that particular check instance
84
     * @param string|null     $checkAlias The alias for the check that has just finished
85
     *
86
     * @return bool|void Return false to prevent from running additional Checks
87
     */
88
    public function onAfterRun(CheckInterface $check, ResultInterface $result, $checkAlias = null)
89
    {
90
    }
91
92
    /**
93
     * This method is called when Runner has been aborted and could not finish the
94
     * whole run().
95
     *
96
     * @param ResultsCollection $results collection of Results for performed Checks
97
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
98
    public function onStop(ResultsCollection $results)
99
    {
100
    }
101
102
    /**
103
     * This method is called when Runner has finished its run.
104
     *
105
     * @param ResultsCollection $results collection of Results for performed Checks
106
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
107
    public function onFinish(ResultsCollection $results)
108
    {
109
    }
110
111
    /**
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...
112
     * @return array [name, code]
113
     */
114
    protected function getStatusByResul(ResultInterface $result)
115
    {
116
        switch (true) {
117
            case $result instanceof SuccessInterface:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
118
                $name = self::STATUS_NAME_SUCCESS;
119
                $code = self::STATUS_CODE_SUCCESS;
120
                break;
121
122
            case $result instanceof WarningInterface:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
123
                $name = self::STATUS_NAME_WARNING;
124
                $code = self::STATUS_CODE_WARNING;
125
                break;
126
127
            case $result instanceof SkipInterface:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
128
                $name = self::STATUS_NAME_SKIP;
129
                $code = self::STATUS_CODE_SKIP;
130
                break;
131
132
            case $result instanceof FailureInterface:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
133
                $name = self::STATUS_NAME_FAILURE;
134
                $code = self::STATUS_CODE_FAILURE;
135
                break;
136
137
            default:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
138
                $name = self::STATUS_NAME_UNKNOWN;
139
                $code = self::STATUS_CODE_UNKNOWN;
140
                break;
141
        }
142
143
        return [$name, $code];
144
    }
145
}
146