Completed
Push — master ( 13df09...be473f )
by Vladimir
04:26
created

CheckInfoCommand::execute()   B

Complexity

Conditions 8
Paths 56

Size

Total Lines 45
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 0
Metric Value
cc 8
eloc 30
nc 56
nop 2
dl 0
loc 45
ccs 0
cts 36
cp 0
crap 72
rs 8.1954
c 0
b 0
f 0
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\TableSeparator;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Input\InputOption;
18
use Symfony\Component\Console\Output\OutputInterface;
19
use Symfony\Component\Console\Helper\Table;
20
use Tvi\MonitorBundle\Runner\Manager;
21
22
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
23
 * @author Vladimir Turnaev <[email protected]>
24
 */
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...
25
class CheckInfoCommand extends Command
26
{
27
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
28
     * @var Manager
29
     */
30
    private $manager;
0 ignored issues
show
Coding Style introduced by
Private member variable "manager" must be prefixed with an underscore
Loading history...
31
32
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $manager should have a doc-comment as per coding-style.
Loading history...
33
     * @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 $manager
Loading history...
34
     */
35
    public function __construct(Manager $manager, string $name = null)
36
    {
37
        parent::__construct($name);
38
        $this->manager = $manager;
39
    }
40
41
    protected function configure()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function configure()
Loading history...
42
    {
43
        $this
44
            ->setName('tvi:monitor:check:info')
45
            ->setDescription('Info Health Checkers')
46
            ->addOption(
47
                'name',
48
                'i',
49
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
50
                'Groups filter'
51
            )
52
            ->addOption(
53
                'groups',
54
                'g',
55
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
56
                'Groups filter'
57
            )
58
            ->addOption(
59
                'tags',
60
                't',
61
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
62
                'Tags filter'
63
            )
64
            ->setHelp(
65
                <<<'EOT'
66
The <info>%command.name%</info> get check info
67
68
* INfo Checks:
69
70
  <info>php %command.full_name% [--alias=... ,] [--groups=... ,] [--tags==... ,] </info>
71
72
EOT
73
            );
74
    }
75
76
    /**
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...
77
     * @return int|null|void
78
     */
79
    protected function execute(InputInterface $input, OutputInterface $output)
80
    {
81
        $namesFilter = $input->getOption('name');
82
        $namesFilter = ($namesFilter) ? $namesFilter : null;
83
84
        $groupsFilter = $input->getOption('groups');
85
        $groupsFilter = ($groupsFilter) ? $groupsFilter : null;
86
87
        $tagsFilter = $input->getOption('tags');
88
        $tagsFilter = ($tagsFilter) ? $tagsFilter : null;
89
90
        $manager = $this->manager;
91
        $checks = $manager->findChecks($namesFilter, $groupsFilter, $tagsFilter);
0 ignored issues
show
Bug introduced by
It seems like $groupsFilter can also be of type true; however, parameter $groups of Tvi\MonitorBundle\Runner\Manager::findChecks() does only seem to accept null|string|string[], maybe add an additional type check? ( Ignorable by Annotation )

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

91
        $checks = $manager->findChecks($namesFilter, /** @scrutinizer ignore-type */ $groupsFilter, $tagsFilter);
Loading history...
Bug introduced by
It seems like $tagsFilter can also be of type true; however, parameter $tags of Tvi\MonitorBundle\Runner\Manager::findChecks() does only seem to accept null|string|string[], maybe add an additional type check? ( Ignorable by Annotation )

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

91
        $checks = $manager->findChecks($namesFilter, $groupsFilter, /** @scrutinizer ignore-type */ $tagsFilter);
Loading history...
Bug introduced by
It seems like $namesFilter can also be of type true; however, parameter $alias of Tvi\MonitorBundle\Runner\Manager::findChecks() does only seem to accept null|string|string[], maybe add an additional type check? ( Ignorable by Annotation )

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

91
        $checks = $manager->findChecks(/** @scrutinizer ignore-type */ $namesFilter, $groupsFilter, $tagsFilter);
Loading history...
92
93
        $table = new Table($output);
94
        $table->setHeaders(['Group', 'Tag(s)', 'Check', 'Label']);
95
96
        $groupOld = null;
97
        foreach ($checks as $check) {
98
99
            $tags = $check->getTags();
100
            if ($tags) {
101
                $tags = $manager->findTags($check->getTags());
102
                $tags = array_map(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...
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
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=yellow;options=bold>%-8s</>', $check->getGroup());
113
            if($groupOld != $groupNew) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
114
                if($groupOld) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
115
                    $table->addRow(new TableSeparator());
116
                }
117
                $group = $groupOld = $groupNew;
118
            }
119
            $checkAlias = sprintf('<info>%s</info>', $check->getId());
120
            $table->addRow([$group, $tags, $checkAlias, $check->getLabel()]);
121
        }
122
123
        $table->render();
124
    }
125
}
126