Completed
Push — master ( 38c692...e0ba21 )
by Vladimir
06:20
created

Nagius::onAfterRun()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
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 Symfony\Component\Console\Output\ConsoleOutput;
15
use Symfony\Component\Console\Output\OutputInterface;
16
use ZendDiagnostics\Check\CheckInterface;
17
use ZendDiagnostics\Result\ResultInterface;
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 Nagius extends ReporterAbstract
23
{
24
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
25
     * @var OutputInterface
26
     */
27
    protected $output;
28
29
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
30
     * @param OutputInterface $output
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
31
     */
32 100
    public function __construct(OutputInterface $output = null)
33
    {
34 100
        if (null === $output) {
35 99
            $output = new ConsoleOutput();
36
        }
37 100
        $this->output = $output;
38 100
    }
39
40
    /**
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...
41
     * {@inheritdoc}
42
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
43 1
    public function onAfterRun(CheckInterface $check, ResultInterface $result, $checkAlias = null)
44
    {
45 1
        list($_, $code) = $this->getStatusByResul($result);
46
47 1
        $statusOut = $this->statusByCode($code);
48 1
        $this->output->writeln(sprintf("%-8s\t%-25s\t%s", $statusOut, $check->getId(), $check->getLabel()));
0 ignored issues
show
Bug introduced by
The method getId() 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

48
        $this->output->writeln(sprintf("%-8s\t%-25s\t%s", $statusOut, $check->/** @scrutinizer ignore-call */ getId(), $check->getLabel()));
Loading history...
49 1
    }
50
51 1
    protected function statusByCode($code): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function statusByCode()
Loading history...
52
    {
53
        $tags = [
54 1
            self::STATUS_CODE_SUCCESS => 'OK',
55 1
            self::STATUS_CODE_WARNING => 'WARNING',
56 1
            self::STATUS_CODE_SKIP => 'SKIP',
57 1
            self::STATUS_CODE_FAILURE => 'FAIL',
58 1
            'default' => 'FAIL',
59
        ];
60
61 1
        return $tags[$code] ?? $tags['default'];
62
    }
63
}
64