Completed
Push — master ( be473f...8253c0 )
by Vladimir
05:20
created

CheckInfoCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 52
dl 0
loc 94
ccs 0
cts 68
cp 0
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 25 1
A __construct() 0 4 1
A execute() 0 40 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\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 checks')
46
            ->addOption(
47
                'check',
48
                'c',
49
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
50
                'Check filter'
51
            )
52
            ->addOption(
53
                'group',
54
                'g',
55
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
56
                'Groups filter'
57
            )
58
            ->addOption(
59
                'tag',
60
                't',
61
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
62
                'Tag(s) 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% [--check=... ,] [--group=... ,] [--tag==... ,] </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
        $checkFilter = $input->getOption('check');
82
        $groupFilter = $input->getOption('group');
83
        $tagFilter = $input->getOption('tag');
84
85
        $checks = $this->manager->findChecks($checkFilter, $groupFilter, $tagFilter);
86
87
        $table = new Table($output);
88
        $table->setHeaders(['Group', 'Tag(s)', 'Check', 'Label']);
89
90
        $groupOld = null;
91
        foreach ($checks as $check) {
92
            $tags = $check->getTags();
93
94
            if ($tags) {
95
                $tags = $this->manager->findTags($check->getTags());
96
                $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...
97
                    return $t->getLabel();
98
                }, $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...
99
100
                $tags = implode(', ', $tags);
101
            } else {
102
                $tags = null;
103
            }
104
105
            $group = null;
106
            $groupNew = sprintf('<fg=yellow;options=bold>%-8s</>', $check->getGroup());
107
108
            if ($groupOld !== $groupNew) {
109
                if ($groupOld) {
110
                    $table->addRow(new TableSeparator());
111
                }
112
                $group = $groupOld = $groupNew;
113
            }
114
            $checkAlias = sprintf('<info>%s</info>', $check->getId());
115
            $table->addRow([$group, $tags, $checkAlias, $check->getLabel()]);
116
        }
117
118
        $table->render();
119
    }
120
}
121