CheckHealthCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 44
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 37
dl 0
loc 44
ccs 0
cts 44
cp 0
rs 9.328
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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\RunnerManager;
19
use Tvi\MonitorBundle\Reporter\ReporterManager;
20
21
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
22
 * @author Vladimir Turnaev <[email protected]>
23
 */
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...
24
class CheckHealthCommand extends Command
25
{
26
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
27
     * @var RunnerManager
28
     */
29
    private $runnerManager;
0 ignored issues
show
Coding Style introduced by
Private member variable "runnerManager" must be prefixed with an underscore
Loading history...
30
31
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
32
     * @var ReporterManager
33
     */
34
    private $reporterManager;
0 ignored issues
show
Coding Style introduced by
Private member variable "reporterManager" must be prefixed with an underscore
Loading history...
35
36
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $reporterRunnerManager should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $runnerManager should have a doc-comment as per coding-style.
Loading history...
37
     * @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 $reporterRunnerManager
Loading history...
38
     */
39
    public function __construct(ReporterManager $reporterRunnerManager, RunnerManager $runnerManager, string $name = null)
40
    {
41
        $this->reporterManager = $reporterRunnerManager;
42
        $this->runnerManager = $runnerManager;
43
44
        parent::__construct($name);
45
    }
46
47
    protected function configure()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function configure()
Loading history...
48
    {
49
        $reporterAliases = $this->reporterManager->getReporterAliases('console');
50
        $reporterAliases = implode(', ', $reporterAliases);
51
        $this
52
            ->setName(
53
                'tvi:monitor:check:run'
54
            )
55
            ->setDescription(
56
                'Runs health checks'
57
            )
58
            ->addOption(
59
                'check',
60
                'c',
61
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
62
                'Check filter'
63
            )
64
            ->addOption(
65
                'reporter',
66
                'r',
67
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
68
                "Additional reporters to run. Use reporter(s) [{$reporterAliases}].",
69
                ['console']
70
            )
71
            ->addOption(
72
                'group',
73
                'g',
74
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
75
                'Groups filter'
76
            )
77
            ->addOption(
78
                'tag',
79
                't',
80
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
81
                'Tag(s) filter'
82
            )
83
            ->addOption(
84
                'break-on-failure',
85
                'b',
86
                InputOption::VALUE_NONE,
87
                'Break checking on any check failure.'
88
            )
89
            ->setHelp(
90
                <<<'EOT'
91
The <info>%command.name%</info> get check info
92
93
* INfo Checks:
94
95
  <info>php %command.full_name% [--check=... ,] [--group=... ,] [--tag==... ,]  [--break-on-failure]</info>
96
97
EOT
98
            );
99
    }
100
101
    /**
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...
102
     * @return int|null|void
103
     */
104
    protected function execute(InputInterface $input, OutputInterface $output)
105
    {
106
        $checkFilter = $input->getOption('check');
107
        $groupFilter = $input->getOption('group');
108
        $tagFilter = $input->getOption('tag');
109
        $breakOnFailure = $input->getOption('break-on-failure', false);
0 ignored issues
show
Unused Code introduced by
The call to Symfony\Component\Consol...tInterface::getOption() has too many arguments starting with false. ( 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
        $breakOnFailure = $input->getOption('break-on-failure', false);

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
        $runner = $this->runnerManager->getRunner($checkFilter, $groupFilter, $tagFilter);
112
        $runner->setBreakOnFailure($breakOnFailure);
113
114
        $reporters = $input->getOption('reporter');
115
        foreach ($reporters as $reporterAlias) {
116
            $reporter = $this->reporterManager->getReporter($reporterAlias);
117
            if ($reporter) {
118
                $runner->addReporter($reporter);
119
            } else {
120
                $output->writeln(sprintf('Reporter <info>"%s"</info> not found, skip it.', $reporterAlias));
121
            }
122
        }
123
124
        $runner->run();
125
    }
126
}
127