Completed
Push — master ( aca6e3...e7aa24 )
by Vladimir
05:21
created

Api::getStatusCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
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\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
    /**
40
     * {@inheritdoc}
41
     */
42
43
    /**
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...
Coding Style introduced by
Parameter $checkAlias should have a doc-comment as per coding-style.
Loading history...
44
     * @param CheckInterface|TviCheckInterface $check
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
45
     *
46
     * @return bool|void
47
     */
48
    public function onAfterRun(CheckInterface $check, ResultInterface $result, $checkAlias = null)
49
    {
50
        list($statusName, $statusCode) = $this->getStatusByResul($result);
51
52
        $this->statusCode = max($this->statusCode, $statusCode);
53
54
        $res = [
55
            'statusCode' => $statusCode,
56
            'statusName' => $statusName,
57
            'label' => $check->getLabel(),
58
            'check' => $checkAlias,
59
            'message' => $result->getMessage(),
60
            '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\CheckInterface or Tvi\MonitorBundle\Check\fs\DiskUsage\Check or Tvi\MonitorBundle\Check\php\PhpFlag\Check or Tvi\MonitorBundle\Check\fs\DirWritable\Check or Tvi\MonitorBundle\Check\php\ApcMemory\Check or Tvi\MonitorBundle\Check\php\OpCacheMemory\Check or Tvi\MonitorBundle\Check\php\ClassExists\Check or Tvi\MonitorBundle\Check\sys\CpuPerformance\Check or Tvi\MonitorBundle\Check\db\PDOCheck\Check or Tvi\MonitorBundle\Check\fs\DirReadable\Check or Tvi\MonitorBundle\Check\fs\DiskFree\Check or Tvi\MonitorBundle\Check\...xtensionNotLoaded\Check or Tvi\MonitorBundle\Check\php\ExtensionLoaded\Check or Tvi\MonitorBundle\Check\php\ApcFragmentation\Check or Tvi\MonitorBundle\Check\php\PhpVersion\Check or Tvi\MonitorBundle\Check\...reamWrapperExists\Check or Tvi\MonitorBundle\Test\Check\TestCheck\Check or Tvi\MonitorBundle\Check\php\Expression\Check or Tvi\MonitorBundle\Check\fs\IniFile\Check or Tvi\MonitorBundle\Check\fs\XmlFile\Check or Tvi\MonitorBundle\Check\fs\YamlFile\Check or Tvi\MonitorBundle\Check\fs\JsonFile\Check or Tvi\MonitorBundle\Check\fs\DiskUsage\Check or Tvi\MonitorBundle\Check\php\PhpFlag\Check or Tvi\MonitorBundle\Check\fs\DirWritable\Check or Tvi\MonitorBundle\Check\php\ApcMemory\Check or Tvi\MonitorBundle\Check\php\OpCacheMemory\Check or Tvi\MonitorBundle\Check\php\ClassExists\Check or Tvi\MonitorBundle\Check\redis\Redis\Check or Tvi\MonitorBundle\Check\php\SecurityAdvisory\Check or Tvi\MonitorBundle\Check\sys\CpuPerformance\Check or Tvi\MonitorBundle\Check\sys\ProcessRunning\Check or Tvi\MonitorBundle\Check\fs\DirReadable\Check or Tvi\MonitorBundle\Check\mongo\Mongo\Check or Tvi\MonitorBundle\Check\fs\DiskFree\Check or Tvi\MonitorBundle\Check\memcache\Memcached\Check or Tvi\MonitorBundle\Check\...xtensionNotLoaded\Check or Tvi\MonitorBundle\Check\php\ExtensionLoaded\Check or Tvi\MonitorBundle\Check\php\ApcFragmentation\Check or Tvi\MonitorBundle\Check\php\PhpVersion\Check or Tvi\MonitorBundle\Check\memcache\Memcache\Check or Tvi\MonitorBundle\Check\http\HttpService\Check or Tvi\MonitorBundle\Check\...GuzzleHttpService\Check or Tvi\MonitorBundle\Check\...reamWrapperExists\Check or Tvi\MonitorBundle\Check\rabbitmq\RabbitMQ\Check. ( Ignorable by Annotation )

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

60
            'tags' => $check->/** @scrutinizer ignore-call */ getTags(),
Loading history...
61
            '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\CheckInterface or Tvi\MonitorBundle\Check\fs\DiskUsage\Check or Tvi\MonitorBundle\Check\php\PhpFlag\Check or Tvi\MonitorBundle\Check\fs\DirWritable\Check or Tvi\MonitorBundle\Check\php\ApcMemory\Check or Tvi\MonitorBundle\Check\php\OpCacheMemory\Check or Tvi\MonitorBundle\Check\php\ClassExists\Check or Tvi\MonitorBundle\Check\sys\CpuPerformance\Check or Tvi\MonitorBundle\Check\db\PDOCheck\Check or Tvi\MonitorBundle\Check\fs\DirReadable\Check or Tvi\MonitorBundle\Check\fs\DiskFree\Check or Tvi\MonitorBundle\Check\...xtensionNotLoaded\Check or Tvi\MonitorBundle\Check\php\ExtensionLoaded\Check or Tvi\MonitorBundle\Check\php\ApcFragmentation\Check or Tvi\MonitorBundle\Check\php\PhpVersion\Check or Tvi\MonitorBundle\Check\...reamWrapperExists\Check or Tvi\MonitorBundle\Test\Check\TestCheck\Check or Tvi\MonitorBundle\Check\php\Expression\Check or Tvi\MonitorBundle\Check\fs\IniFile\Check or Tvi\MonitorBundle\Check\fs\XmlFile\Check or Tvi\MonitorBundle\Check\fs\YamlFile\Check or Tvi\MonitorBundle\Check\fs\JsonFile\Check or Tvi\MonitorBundle\Check\fs\DiskUsage\Check or Tvi\MonitorBundle\Check\php\PhpFlag\Check or Tvi\MonitorBundle\Check\fs\DirWritable\Check or Tvi\MonitorBundle\Check\php\ApcMemory\Check or Tvi\MonitorBundle\Check\php\OpCacheMemory\Check or Tvi\MonitorBundle\Check\php\ClassExists\Check or Tvi\MonitorBundle\Check\redis\Redis\Check or Tvi\MonitorBundle\Check\php\SecurityAdvisory\Check or Tvi\MonitorBundle\Check\sys\CpuPerformance\Check or Tvi\MonitorBundle\Check\sys\ProcessRunning\Check or Tvi\MonitorBundle\Check\fs\DirReadable\Check or Tvi\MonitorBundle\Check\mongo\Mongo\Check or Tvi\MonitorBundle\Check\fs\DiskFree\Check or Tvi\MonitorBundle\Check\memcache\Memcached\Check or Tvi\MonitorBundle\Check\...xtensionNotLoaded\Check or Tvi\MonitorBundle\Check\php\ExtensionLoaded\Check or Tvi\MonitorBundle\Check\php\ApcFragmentation\Check or Tvi\MonitorBundle\Check\php\PhpVersion\Check or Tvi\MonitorBundle\Check\memcache\Memcache\Check or Tvi\MonitorBundle\Check\http\HttpService\Check or Tvi\MonitorBundle\Check\...GuzzleHttpService\Check or Tvi\MonitorBundle\Check\...reamWrapperExists\Check or Tvi\MonitorBundle\Check\rabbitmq\RabbitMQ\Check. ( Ignorable by Annotation )

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

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