| Conditions | 10 |
| Paths | 58 |
| Total Lines | 46 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 9 | ||
| Bugs | 1 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 47 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 48 | { |
||
| 49 | $checkName = $input->getArgument('checkName'); |
||
| 50 | $group = $input->getOption('group'); |
||
| 51 | |||
| 52 | if (is_null($group)) { |
||
| 53 | $group = $this->getContainer()->getParameter('liip_monitor.default_group'); |
||
| 54 | } |
||
| 55 | |||
| 56 | $runnerServiceId = 'liip_monitor.runner_'.$group; |
||
| 57 | |||
| 58 | if (!$this->getContainer()->has($runnerServiceId)) { |
||
| 59 | $output->writeln('<error>No such group.</error>'); |
||
| 60 | |||
| 61 | return 1; |
||
| 62 | } |
||
| 63 | |||
| 64 | $runner = $this->getContainer()->get('liip_monitor.runner_'.$group); |
||
| 65 | |||
| 66 | if ($input->getOption('nagios')) { |
||
| 67 | $reporter = $this->getContainer()->get('liip_monitor.helper.raw_console_reporter'); |
||
| 68 | } else { |
||
| 69 | $reporter = $this->getContainer()->get('liip_monitor.helper.console_reporter'); |
||
| 70 | } |
||
| 71 | |||
| 72 | $runner->addReporter($reporter); |
||
| 73 | $runner->useAdditionalReporters($input->getOption('reporter')); |
||
| 74 | |||
| 75 | if (0 === count($runner->getChecks())) { |
||
| 76 | $output->writeln('<error>No checks configured.</error>'); |
||
| 77 | } |
||
| 78 | |||
| 79 | /** @var \ZendDiagnostics\Result\Collection $results */ |
||
| 80 | $results = $runner->run($checkName); |
||
| 81 | if ($input->getOption('nagios')) { |
||
| 82 | if ($results->getUnknownCount()) { |
||
| 83 | return 3; |
||
| 84 | } elseif ($results->getFailureCount()) { |
||
| 85 | return 2; |
||
| 86 | } elseif ($results->getWarningCount()) { |
||
| 87 | return 1; |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | return $results->getFailureCount() ? 1 : 0; |
||
| 92 | } |
||
| 93 | } |
||
| 94 |