Test Failed
Push — master ( ec8ff1...24c3c9 )
by Vladimir
05:33
created

CheckInfoCommand::listChecks()   A

Complexity

Conditions 6
Paths 9

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
cc 6
eloc 16
nc 9
nop 2
dl 0
loc 25
ccs 0
cts 21
cp 0
crap 42
rs 9.1111
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\Input\InputInterface;
16
use Symfony\Component\Console\Input\InputOption;
17
use Symfony\Component\Console\Output\OutputInterface;
18
use Tvi\MonitorBundle\Runner\Manager;
19
20
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
21
 * @author Vladimir Turnaev <[email protected]>
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 CheckInfoCommand extends Command
24
{
25
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
26
     * @var Manager
27
     */
28
    private $manager;
0 ignored issues
show
Coding Style introduced by
Private member variable "manager" must be prefixed with an underscore
Loading history...
29
30
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
31
     * @param Manager $manager
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
32
     * @param null    $name
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $name is correct as it would always require null to be passed?
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
33
     */
34
    public function __construct(Manager $manager, string $name = null)
35
    {
36
        parent::__construct($name);
37
        $this->manager = $manager;
38
    }
39
40
    protected function configure()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function configure()
Loading history...
41
    {
42
        $this
43
            ->setName('tvi:monitor:check:info')
44
            ->setDescription('Info Health Checkers')
45
            ->addOption(
46
                'name',
47
                'i',
48
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
49
                'Groups filter'
50
            )
51
            ->addOption(
52
                'groups',
53
                'g',
54
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
55
                'Groups filter'
56
            )
57
            ->addOption(
58
                'tags',
59
                't',
60
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
61
                'Tags filter'
62
0 ignored issues
show
Coding Style introduced by
There should be no empty lines in a multi-line function call.
Loading history...
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...
77
     * @param InputInterface  $input
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
78
     * @param OutputInterface $output
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
79
     *
80
     * @return int|null|void
81
     */
82
    protected function execute(InputInterface $input, OutputInterface $output)
83
    {
84
        $namesFilter = $input->getOption('name');
85
        $namesFilter = ($namesFilter) ? $namesFilter : null;
86
87
        $groupsFilter = $input->getOption('groups');
88
        $groupsFilter = ($groupsFilter) ? $groupsFilter : null;
89
90
        $tagsFilter = $input->getOption('tags');
91
        $tagsFilter = ($tagsFilter) ? $tagsFilter : null;
92
93
        $manager = $this->manager;
94
        $checks = $manager->findChecks($namesFilter, $groupsFilter, $tagsFilter);
0 ignored issues
show
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

94
        $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

94
        $checks = $manager->findChecks(/** @scrutinizer ignore-type */ $namesFilter, $groupsFilter, $tagsFilter);
Loading history...
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

94
        $checks = $manager->findChecks($namesFilter, /** @scrutinizer ignore-type */ $groupsFilter, $tagsFilter);
Loading history...
95
96
        //            $output->writeln('');
97
        foreach ($checks as $check) {
98
            $tags = $check->getTags();
99
            if ($tags) {
100
                $tags = implode(', ',$check->getTags());
101
                $tags = "[$tags]";
102
            } else {
103
                $tags = null;
104
            }
105
            $output->writeln(sprintf('<fg=yellow;options=bold>%-8s</> %-20s <info>%-40s</info> %s', $check->getGroup(), $tags, $check->getId(), $check->getLabel()));
106
        }
107
    }
108
}
109