CheckInfoCommand   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
eloc 57
dl 0
loc 103
ccs 0
cts 75
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A configure() 0 29 1
A execute() 0 45 5
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\Command;
13
14
use Symfony\Component\Console\Command\Command;
15
use Symfony\Component\Console\Helper\TableCell;
16
use Symfony\Component\Console\Helper\TableSeparator;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Input\InputOption;
19
use Symfony\Component\Console\Output\OutputInterface;
20
use Symfony\Component\Console\Helper\Table;
21
use Tvi\MonitorBundle\Reporter\Console;
22
use Tvi\MonitorBundle\Runner\RunnerManager;
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
class CheckInfoCommand extends Command
28
{
29
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
30
     * @var Manager
0 ignored issues
show
Bug introduced by
The type Tvi\MonitorBundle\Command\Manager was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
     */
32
    private $runnerManager;
0 ignored issues
show
Coding Style introduced by
Private member variable "runnerManager" must be prefixed with an underscore
Loading history...
33
34
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $runnerManager should have a doc-comment as per coding-style.
Loading history...
35
     * @param ?string $name
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Doc comment for parameter $name does not match actual variable name $runnerManager
Loading history...
36
     */
37
    public function __construct(RunnerManager $runnerManager, string $name = null)
38
    {
39
        parent::__construct($name);
40
        $this->runnerManager = $runnerManager;
0 ignored issues
show
Documentation Bug introduced by
It seems like $runnerManager of type Tvi\MonitorBundle\Runner\RunnerManager is incompatible with the declared type Tvi\MonitorBundle\Command\Manager of property $runnerManager.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
41
    }
42
43
    protected function configure()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function configure()
Loading history...
44
    {
45
        $this
46
            ->setName(
47
                'tvi:monitor:check:info'
48
            )
49
            ->setDescription(
50
                'Info health checks'
51
            )
52
            ->addOption(
53
                'check',
54
                'c',
55
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
56
                'Check filter'
57
            )
58
            ->addOption(
59
                'group',
60
                'g',
61
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
62
                'Groups filter'
63
            )
64
            ->addOption(
65
                'tag',
66
                't',
67
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
68
                'Tag(s) filter'
69
            )
70
            ->setHelp(
71
                <<<'EOT'
72
The <info>%command.name%</info> get check info
73
74
* INfo Checks:
75
76
  <info>php %command.full_name% [--check=... ,] [--group=... ,] [--tag==... ,] </info>
77
78
EOT
79
            );
80
    }
81
82
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $input should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $output should have a doc-comment as per coding-style.
Loading history...
83
     * @return int|null|void
84
     */
85
    protected function execute(InputInterface $input, OutputInterface $output)
86
    {
87
        $checkFilter = $input->getOption('check');
88
        $groupFilter = $input->getOption('group');
89
        $tagFilter = $input->getOption('tag');
90
91
        $checks = $this->runnerManager->findChecksSorted($checkFilter, $groupFilter, $tagFilter);
92
93
        $table = new Table($output);
94
        $table->setHeaders(['Check', 'Tag(s)', 'Label']);
95
96
        $groupOld = null;
97
        foreach ($checks as $check) {
98
            $tags = $check->getTags();
99
100
            if ($tags) {
101
                $tags = $this->runnerManager->findTags($check->getTags());
102
                $tags = array_map(static function ($t) {
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...
103
                    return $t->getLabel();
104
                }, $tags);
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...
105
106
                $tags = implode(', ', $tags);
107
            } else {
108
                $tags = null;
109
            }
110
111
            $group = null;
112
            $groupNew = sprintf('<fg=default;options=bold>%s</>', $check->getGroup());
113
114
            if ($groupOld !== $groupNew) {
115
                if ($groupOld) {
116
                    $table->addRow(new TableSeparator());
117
                }
118
                $table->addRow([new TableCell($groupNew, ['colspan' => 3])]);
119
                $table->addRow(new TableSeparator());
120
121
                $group = $groupOld = $groupNew;
0 ignored issues
show
Unused Code introduced by
The assignment to $group is dead and can be removed.
Loading history...
122
            }
123
124
            $importanceTag = Console::tagByImportance($check->getImportance());
125
            $id = sprintf('%s%s</>', $importanceTag, $check->getId());
126
            $table->addRow([$id, $tags, $check->getLabel()]);
127
        }
128
129
        $table->render();
130
    }
131
}
132