Completed
Push — master ( f51f9e...b04c6e )
by Vladimir
05:26
created

Console   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Test Coverage

Coverage 10.34%

Importance

Changes 0
Metric Value
wmc 14
eloc 58
dl 0
loc 124
ccs 6
cts 58
cp 0.1034
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getDataOut() 0 16 4
A tagByCode() 0 11 1
A onAfterRun() 0 28 5
A onStart() 0 5 1
A onFinish() 0 12 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\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 Console extends ReporterAbstract
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 5
    public function __construct(OutputInterface $output = null, $withData = false)
44
    {
45 5
        if (null === $output) {
46 5
            $output = new ConsoleOutput();
47
        }
48 5
        $this->output = $output;
49
50 5
        $this->withData = $withData;
51 5
    }
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
        $tag = $this->tagByCode($code);
61
62
        $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\C...\TestSuccessCheck\Check or Tvi\MonitorBundle\Check\php\Expression\Check or Tvi\MonitorBundle\Test\C...\TestWarningCheck\Check or Tvi\MonitorBundle\Test\Check\TestSkipCheck\Check or Tvi\MonitorBundle\Test\C...\TestFailureCheck\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

62
        /** @scrutinizer ignore-call */ 
63
        $groupTag = $check->getGroup();
Loading history...
63
        $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\C...\TestSuccessCheck\Check or Tvi\MonitorBundle\Check\php\Expression\Check or Tvi\MonitorBundle\Test\C...\TestWarningCheck\Check or Tvi\MonitorBundle\Test\Check\TestSkipCheck\Check or Tvi\MonitorBundle\Test\C...\TestFailureCheck\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

63
        /** @scrutinizer ignore-call */ 
64
        $tags = $check->getTags();
Loading history...
64
65
        if ($tags) {
66
            $tags = implode(', ', $tags);
67
            $tags = "[$tags]";
68
            $groupTag .= ' / '.$tags;
69
        } else {
70
            $tags = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $tags is dead and can be removed.
Loading history...
71
        }
72
73
        $message = $result->getMessage();
74
        if ($message) {
75
            $message = ", {$message}";
76
        }
77
        $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...
78
            $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\C...\TestSuccessCheck\Check or Tvi\MonitorBundle\Check\php\Expression\Check or Tvi\MonitorBundle\Test\C...\TestWarningCheck\Check or Tvi\MonitorBundle\Test\Check\TestSkipCheck\Check or Tvi\MonitorBundle\Test\C...\TestFailureCheck\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
            $check->/** @scrutinizer ignore-call */ 
79
                    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...
79
80
        if ($this->withData) {
81
            $dataOut = $this->getDataOut($result);
82
            if ($dataOut) {
83
                $this->output->writeln(sprintf('%-71s < %s >', ' ', $dataOut));
84
            }
85
        }
86
    }
87
88
    /**
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...
89
     * {@inheritdoc}
90
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
91
    public function onStart(\ArrayObject $checks, $runnerConfig)
92
    {
93
        parent::onStart($checks, $runnerConfig);
94
95
        $this->output->writeln(sprintf('<info>%-30s %-40s %-10s %s, %s</info>', 'Check', 'Group / Tag(s)', 'Status', 'Info', 'Message'));
96
    }
97
98
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $results should have a doc-comment as per coding-style.
Loading history...
99
     * {@inheritdoc}
100
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
101
    public function onFinish(ResultsCollection $results)
102
    {
103
        parent::onFinish($results);
104
105
        $this->output->writeln('---------------------------------');
106
        $this->output->writeln(sprintf('%s: %s', 'total', $this->getTotalCount()));
107
        $this->output->writeln('');
108
        $this->output->writeln(sprintf('%s%-10s</>: %s', self::STATUS_TAG_SUCCESS, 'SUCCESSES', $this->getSuccessCount()));
109
        $this->output->writeln(sprintf('%s%-10s</>: %s', self::STATUS_TAG_WARNING, 'WARNINGS', $this->getWarningCount()));
110
        $this->output->writeln(sprintf('%s%-10s</>: %s', self::STATUS_TAG_SKIP, 'SKIP', $this->getSkipCount()));
111
        $this->output->writeln(sprintf('%s%-10s</>: %s', self::STATUS_TAG_FAILUR, 'FAILURES', $this->getFailureCount()));
112
        $this->output->writeln(sprintf('%s%-10s</>: %s', self::STATUS_TAG_UNKNOWN, 'UNKNOWNS', $this->getUnknownCount()));
113
    }
114
115
    protected function tagByCode($code): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function tagByCode()
Loading history...
116
    {
117
        $tags = [
118
            self::STATUS_CODE_SUCCESS => self::STATUS_TAG_SUCCESS,
119
            self::STATUS_CODE_WARNING => self::STATUS_TAG_WARNING,
120
            self::STATUS_CODE_SKIP => self::STATUS_TAG_SKIP,
121
            self::STATUS_CODE_FAILURE => self::STATUS_TAG_FAILUR,
122
            'default' => self::STATUS_TAG_UNKNOWN,
123
        ];
124
125
        return $tags[$code] ?? $tags['default'];
126
    }
127
128
    /**
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...
129
     * @return null|string
130
     */
131
    protected function getDataOut(ResultInterface $result)
132
    {
133
        $dataOut = null;
134
        $message = $result->getMessage();
135
        if ($message) {
136
            $data = $result->getData();
137
            if (null !== $data) {
138
                $dataOut = json_encode($data);
139
140
                if (\mb_strlen($dataOut) > 100) {
141
                    $dataOut .= "\n";
142
                }
143
            }
144
        }
145
146
        return $dataOut;
147
    }
148
}
149