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

ConsoleReporter::onAfterRun()   B

Complexity

Conditions 9
Paths 60

Size

Total Lines 43
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 43
ccs 0
cts 38
cp 0
rs 8.0555
c 0
b 0
f 0
cc 9
nc 60
nop 3
crap 90
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\Collection as ResultsCollection;
18
use ZendDiagnostics\Result\ResultInterface;
19
20
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
21
 * @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...
22
 */
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...
23
class ConsoleReporter extends AbstractReporter
24
{
25
    private const STATUS_TAG_SUCCESS = '<fg=green;options=bold>';
26
    private const STATUS_TAG_WARNING = '<fg=yellow;options=bold>';
27
    private const STATUS_TAG_SKIP = '<fg=blue;options=bold>';
28
    private const STATUS_TAG_FAILUR = '<fg=red;options=bold>';
29
    private const STATUS_TAG_UNKNOWN = '<fg=white;options=bold>';
30
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
31
     * @var OutputInterface
32
     */
33
    protected $output;
34
35
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
36
     * @var bool
37
     */
38
    protected $withData;
39
40
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $withData should have a doc-comment as per coding-style.
Loading history...
41
     * @param OutputInterface $output
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
42
     */
43
    public function __construct(OutputInterface $output = null, $withData = false)
44
    {
45
        if (null === $output) {
46
            $output = new ConsoleOutput();
47
        }
48
        $this->output = $output;
49
50
        $this->withData = $withData;
51
    }
52
53
    /**
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...
54
     * {@inheritdoc}
55
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
56
    public function onAfterRun(CheckInterface $check, ResultInterface $result, $checkAlias = null)
57
    {
58
        list($status, $code) = $this->getStatusByResul($result);
59
60
        switch ($code) {
61
            case self::STATUS_CODE_SUCCESS:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
62
                $tag = self::STATUS_TAG_SUCCESS;
63
                break;
64
            case self::STATUS_CODE_WARNING:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
65
                $tag = self::STATUS_TAG_WARNING;
66
                break;
67
            case self::STATUS_CODE_SKIP:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
68
                $tag = self::STATUS_TAG_SKIP;
69
                break;
70
            case self::STATUS_CODE_FAILURE:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
71
                $tag = self::STATUS_TAG_FAILUR;
72
                break;
73
            default:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
74
                $tag = self::STATUS_TAG_UNKNOWN;
75
        }
76
77
        $groupTag = $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

77
        /** @scrutinizer ignore-call */ 
78
        $groupTag = $check->getGroup();
Loading history...
78
        $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

78
        /** @scrutinizer ignore-call */ 
79
        $tags = $check->getTags();
Loading history...
79
80
        if ($tags) {
81
            $tags = implode(', ', $tags);
82
            $tags = "[$tags]";
83
            $groupTag .= ' / '.$tags;
84
        } else {
85
            $tags = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $tags is dead and can be removed.
Loading history...
86
        }
87
88
        $message = $result->getMessage();
89
        if ($message) {
90
            $message = ", {$message}";
91
        }
92
        $this->output->writeln(sprintf('<info>%-30s</info> %-40s %s%-10s</> %s%s',
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...
93
            $check->getId(), $groupTag, $tag, $status, $check->getLabel(), $message));
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\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

93
            $check->/** @scrutinizer ignore-call */ 
94
                    getId(), $groupTag, $tag, $status, $check->getLabel(), $message));
Loading history...
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 8 spaces, but found 12.
Loading history...
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...
94
95
        if ($this->withData) {
96
            $dataOut = $this->getDataOut($result);
97
            if ($dataOut) {
98
                $this->output->writeln(sprintf('%-71s < %s >', ' ', $dataOut));
99
            }
100
        }
101
    }
102
103
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $checks should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $runnerConfig should have a doc-comment as per coding-style.
Loading history...
104
     * {@inheritdoc}
105
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
106
    public function onStart(\ArrayObject $checks, $runnerConfig)
107
    {
108
        $this->output->writeln(sprintf('<info>%-30s %-40s %-10s %s, %s</info>', 'Check', 'Group / Tag(s)', 'Status', 'Info', 'Message'));
109
    }
110
111
    /**
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 $checkAlias should have a doc-comment as per coding-style.
Loading history...
112
     * {@inheritdoc}
113
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
114
    public function onBeforeRun(CheckInterface $check, $checkAlias = null)
115
    {
116
    }
117
118
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $results should have a doc-comment as per coding-style.
Loading history...
119
     * {@inheritdoc}
120
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
121
    public function onStop(ResultsCollection $results)
122
    {
123
    }
124
125
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $results should have a doc-comment as per coding-style.
Loading history...
126
     * {@inheritdoc}
127
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
128
    public function onFinish(ResultsCollection $results)
129
    {
130
        $this->output->writeln('--------');
131
        $this->output->writeln(sprintf('%s: %s', 'total', $results->count()));
132
        $this->output->writeln('');
133
        $this->output->writeln(sprintf('%s%-10s</>: %s', self::STATUS_TAG_SUCCESS, 'SUCCESSES', $results->getSuccessCount()));
134
        $this->output->writeln(sprintf('%s%-10s</>: %s', self::STATUS_TAG_WARNING, 'WARNINGS', $results->getWarningCount()));
135
        $this->output->writeln(sprintf('%s%-10s</>: %s', self::STATUS_TAG_SKIP, 'SKIP', $results->getSkipCount()));
136
        $this->output->writeln(sprintf('%s%-10s</>: %s', self::STATUS_TAG_FAILUR, 'FAILURES', $results->getFailureCount()));
137
        $this->output->writeln(sprintf('%s%-10s</>: %s', self::STATUS_TAG_UNKNOWN, 'UNKNOWNS', $results->getUnknownCount()));
138
    }
139
140
    /**
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...
141
     * @return null|string
142
     */
143
    protected function getDataOut(ResultInterface $result)
144
    {
145
        $dataOut = null;
146
        $message = $result->getMessage();
147
        if ($message) {
148
            $data = $result->getData();
149
            if (null !== $data) {
150
                $dataOut = json_encode($data);
151
152
                if (\mb_strlen($dataOut) > 100) {
153
                    $dataOut .= "\n";
154
                }
155
            }
156
        }
157
158
        return $dataOut;
159
    }
160
}
161