Completed
Push — master ( d4d654...40e20e )
by Vladimir
04:35
created

CheckInfoCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 0
cts 6
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the `tvi/monitor-bundle` project.
4
 *
5
 * (c) https://github.com/turnaev/monitor-bundle/graphs/contributors
6
 *
7
 * For the full copyright and license information, please view the LICENSE.md
8
 * file that was distributed with this source code.
9
 */
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...
10
11
namespace Tvi\MonitorBundle\Command;
12
13
use Symfony\Component\Console\Command\Command;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Input\InputOption;
16
use Symfony\Component\Console\Output\OutputInterface;
17
use Tvi\MonitorBundle\Runner\Manager;
18
19
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
20
 * @author Vladimir Turnaev <[email protected]>
21
 */
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...
22
class CheckInfoCommand extends Command
23
{
24
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
25
     * @var Manager
26
     */
27
    private $manager;
0 ignored issues
show
Coding Style introduced by
Private member variable "manager" must be prefixed with an underscore
Loading history...
28
29
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
30
     * @param Manager $manager
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
31
     * @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...
32
     */
33
    public function __construct(Manager $manager, string $name = null)
34
    {
35
        parent::__construct($name);
36
        $this->manager = $manager;
37
    }
38
39
    /**
0 ignored issues
show
Coding Style introduced by
Doc comment is empty
Loading history...
40
     *
41
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
42
    protected function configure()
43
    {
44
        $this
45
            ->setName('tvi:monitor:check:info')
46
            ->setDescription('Info Health Checkers')
47
            ->addOption('group', 'g',InputOption::VALUE_OPTIONAL, 'Check group')
0 ignored issues
show
Coding Style introduced by
Space after closing parenthesis of function call prohibited
Loading history...
48
        ;
49
    }
50
51
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
52
     * @param InputInterface  $input
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
53
     * @param OutputInterface $output
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
54
     *
55
     * @return int|null|void
56
     */
57
    protected function execute(InputInterface $input, OutputInterface $output)
58
    {
59
        $runner = $this->manager->getRunner();
60
        v($runner->getReporters());
0 ignored issues
show
Bug introduced by
The function v was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

60
        /** @scrutinizer ignore-call */ 
61
        v($runner->getReporters());
Loading history...
61
//        switch (true) {
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
62
//            case $input->getOption('reporters'):
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
63
//                $this->listReporters($input, $output);
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
64
//                break;
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
65
//            case $input->getOption('groups'):
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
66
//                $this->listGroups($input, $output);
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
67
//                break;
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
68
//            default:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
69
//                $this->listChecks($input, $output);
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
70
//                break;
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
71
//        }
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
72
    }
73
74
    protected function listChecks(InputInterface $input, OutputInterface $output)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function listChecks()
Loading history...
75
    {
76
        $group = $input->getOption('group');
77
78
        $checkMetadatas = $this->manager->getCheckMetadatas($group);
0 ignored issues
show
Bug introduced by
The method getCheckMetadatas() does not exist on Tvi\MonitorBundle\Runner\Manager. ( Ignorable by Annotation )

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

78
        /** @scrutinizer ignore-call */ 
79
        $checkMetadatas = $this->manager->getCheckMetadatas($group);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
79
80
        if (0 === count($checkMetadatas)) {
81
            if(empty($group)) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
82
                $output->writeln(sprintf('<error>No checks configured.</error>'));
83
            } else {
84
                $output->writeln(sprintf('<error>No checks configured for group %s.</error>', $group));
85
            }
86
        }
87
88
        $showGroup = null;
89
        foreach ($checkMetadatas as $checkMetadata) {
90
91
            $currentGroup = $checkMetadata->getGroup();
92
            if(empty($group) && $showGroup != $currentGroup) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
93
                $output->writeln(sprintf('<fg=yellow;options=bold>%s</>', $currentGroup));
94
                $showGroup = $currentGroup;
95
            }
96
97
            $check = $checkMetadata->getCheck();
98
            $alias = $checkMetadata->getAlias();
99
            $output->writeln(sprintf('<info>%s</info> %s', $alias, $check->getLabel()));
100
        }
101
    }
102
103
    /**
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...
104
     * @param OutputInterface $output
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Doc comment for parameter $output does not match actual variable name $input
Loading history...
105
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
106
    protected function listReporters(InputInterface $input, OutputInterface $output)
107
    {
108
        $group = $input->getOption('group');
109
        $runner = $this->manager->getRunner($group);
0 ignored issues
show
Unused Code introduced by
The call to Tvi\MonitorBundle\Runner\Manager::getRunner() has too many arguments starting with $group. ( Ignorable by Annotation )

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

109
        /** @scrutinizer ignore-call */ 
110
        $runner = $this->manager->getRunner($group);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
110
111
        if (null === $runner) {
112
            $output->writeln('<error>No such group.</error>');
113
            return;
114
        }
115
116
        $reporters = $runner->getAdditionalReporters();
0 ignored issues
show
Bug introduced by
The method getAdditionalReporters() does not exist on Tvi\MonitorBundle\Runner\Runner. ( Ignorable by Annotation )

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

116
        /** @scrutinizer ignore-call */ 
117
        $reporters = $runner->getAdditionalReporters();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
117
        if (0 === count($reporters)) {
118
            $output->writeln('<error>No additional reporters configured.</error>');
119
        }
120
        foreach (array_keys($reporters) as $reporter) {
121
            $output->writeln($reporter);
122
        }
123
    }
124
125
    /**
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...
126
     * @param OutputInterface $output
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Doc comment for parameter $output does not match actual variable name $input
Loading history...
127
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
128
    protected function listGroups(InputInterface $input, OutputInterface $output)
0 ignored issues
show
Unused Code introduced by
The parameter $input is not used and could be removed. ( Ignorable by Annotation )

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

128
    protected function listGroups(/** @scrutinizer ignore-unused */ InputInterface $input, OutputInterface $output)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
129
    {
130
        foreach ($this->manager->getGroups() as $group) {
0 ignored issues
show
Bug introduced by
The method getGroups() does not exist on Tvi\MonitorBundle\Runner\Manager. ( Ignorable by Annotation )

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

130
        foreach ($this->manager->/** @scrutinizer ignore-call */ getGroups() as $group) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
131
            $output->writeln(sprintf('<fg=yellow;options=bold>%s</>', $group));
132
        }
133
    }
134
}
135