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
![]() |
|||||||
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
|
|||||||
22 | * @author Vladimir Turnaev <[email protected]> |
||||||
23 | */ |
||||||
0 ignored issues
–
show
|
|||||||
24 | class CheckHealthCommand extends Command |
||||||
25 | { |
||||||
26 | /** |
||||||
0 ignored issues
–
show
|
|||||||
27 | * @var RunnerManager |
||||||
28 | */ |
||||||
29 | private $runnerManager; |
||||||
0 ignored issues
–
show
|
|||||||
30 | |||||||
31 | /** |
||||||
0 ignored issues
–
show
|
|||||||
32 | * @var ReporterManager |
||||||
33 | */ |
||||||
34 | private $reporterManager; |
||||||
0 ignored issues
–
show
|
|||||||
35 | |||||||
36 | /** |
||||||
0 ignored issues
–
show
|
|||||||
37 | * @param ?string $name |
||||||
0 ignored issues
–
show
|
|||||||
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
|
|||||||
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
|
|||||||
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
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
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. ![]() |
|||||||
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 |