Completed
Push — master ( 1bbe04...d4d654 )
by Vladimir
05:33
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 MonitorBundle\Command;
12
13
use MonitorBundle\Runner\RunnerManager;
0 ignored issues
show
Bug introduced by
The type MonitorBundle\Runner\RunnerManager 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...
14
use MonitorBundle\Runner\Runner;
0 ignored issues
show
Bug introduced by
The type MonitorBundle\Runner\Runner 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...
15
use Symfony\Component\Console\Command\Command;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Input\InputOption;
18
use Symfony\Component\Console\Output\OutputInterface;
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
    private $runnerManager;
0 ignored issues
show
Coding Style introduced by
Private member variable "runnerManager" must be prefixed with an underscore
Loading history...
26
27
    public function __construct(RunnerManager $runnerManager, $name = null)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
28
    {
29
        $this->runnerManager = $runnerManager;
30
31
        parent::__construct($name);
32
    }
33
34
    protected function configure()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function configure()
Loading history...
35
    {
36
        $this
37
            ->setName('tvi:monitor:check:info')
38
            ->setDescription('Info Health Checkers')
39
            ->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...
40
        ;
41
    }
42
43
    protected function execute(InputInterface $input, OutputInterface $output)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function execute()
Loading history...
44
    {
45
        v(1);
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

45
        /** @scrutinizer ignore-call */ 
46
        v(1);
Loading history...
46
//        switch (true) {
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
47
//            case $input->getOption('reporters'):
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
48
//                $this->listReporters($input, $output);
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
49
//                break;
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
50
//            case $input->getOption('groups'):
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
51
//                $this->listGroups($input, $output);
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
52
//                break;
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
53
//            default:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
54
//                $this->listChecks($input, $output);
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
55
//                break;
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
56
//        }
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
57
    }
58
59
    protected function listChecks(InputInterface $input, OutputInterface $output)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function listChecks()
Loading history...
60
    {
61
        $group = $input->getOption('group');
62
63
        $checkMetadatas = $this->runnerManager->getCheckMetadatas($group);
64
65
        if (0 === count($checkMetadatas)) {
66
            if(empty($group)) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
67
                $output->writeln(sprintf('<error>No checks configured.</error>'));
68
            } else {
69
                $output->writeln(sprintf('<error>No checks configured for group %s.</error>', $group));
70
            }
71
        }
72
73
        $showGroup = null;
74
        foreach ($checkMetadatas as $checkMetadata) {
75
76
            $currentGroup = $checkMetadata->getGroup();
77
            if(empty($group) && $showGroup != $currentGroup) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
78
                $output->writeln(sprintf('<fg=yellow;options=bold>%s</>', $currentGroup));
79
                $showGroup = $currentGroup;
80
            }
81
82
            $check = $checkMetadata->getCheck();
83
            $alias = $checkMetadata->getAlias();
84
            $output->writeln(sprintf('<info>%s</info> %s', $alias, $check->getLabel()));
85
        }
86
    }
87
88
    /**
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...
89
     * @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...
90
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
91
    protected function listReporters(InputInterface $input, OutputInterface $output)
92
    {
93
        $group = $input->getOption('group');
94
        $runner = $this->runnerManager->getRunner($group);
95
96
        if (null === $runner) {
97
            $output->writeln('<error>No such group.</error>');
98
            return;
99
        }
100
101
        $reporters = $runner->getAdditionalReporters();
102
        if (0 === count($reporters)) {
103
            $output->writeln('<error>No additional reporters configured.</error>');
104
        }
105
        foreach (array_keys($reporters) as $reporter) {
106
            $output->writeln($reporter);
107
        }
108
    }
109
110
    /**
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...
111
     * @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...
112
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
113
    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

113
    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...
114
    {
115
        foreach ($this->runnerManager->getGroups() as $group) {
116
            $output->writeln(sprintf('<fg=yellow;options=bold>%s</>', $group));
117
        }
118
    }
119
}
120