| Conditions | 14 |
| Paths | 17 |
| Total Lines | 73 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
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 |
||
| 42 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 43 | { |
||
| 44 | $this->debugger->stop(); |
||
| 45 | $config = $this->container->get(ConfigInterface::class); |
||
| 46 | |||
| 47 | $io = new SymfonyStyle($input, $output); |
||
| 48 | |||
| 49 | if ($input->hasOption('groups') && $input->getOption('groups')) { |
||
| 50 | $build = $this->getConfigBuild($config); |
||
| 51 | $groups = array_keys($build); |
||
| 52 | ksort($groups); |
||
| 53 | |||
| 54 | $io->table(['Group'], array_map(fn ($group) => [$group], $groups)); |
||
| 55 | |||
| 56 | return ExitCode::OK; |
||
| 57 | } |
||
| 58 | if ($input->hasOption('group') && !empty($group = $input->getOption('group'))) { |
||
| 59 | $data = $config->get($group); |
||
| 60 | ksort($data); |
||
| 61 | $table = new Table($output); |
||
| 62 | |||
| 63 | foreach ($data as $event => $listeners) { |
||
| 64 | $io->title($event); |
||
| 65 | foreach ($listeners as $listener) { |
||
| 66 | if (is_callable($listener) && !is_array($listener)) { |
||
| 67 | SymfonyVarDumper::dump($this->export($listener)); |
||
| 68 | } else { |
||
| 69 | SymfonyVarDumper::dump($listener); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | $table->render(); |
||
| 73 | $io->newLine(); |
||
| 74 | } |
||
| 75 | return ExitCode::OK; |
||
| 76 | } |
||
| 77 | |||
| 78 | $data = []; |
||
| 79 | if ($config->has('events')) { |
||
| 80 | $data = array_merge($data, $config->get('events')); |
||
| 81 | } |
||
| 82 | if ($config->has('events-console')) { |
||
| 83 | $data = array_merge($data, $config->get('events-console')); |
||
| 84 | } |
||
| 85 | //if ($config->has('events-web')) { |
||
| 86 | // $data = array_merge($data, $config->get('events-web')); |
||
| 87 | //} |
||
| 88 | $rows = []; |
||
| 89 | foreach ($data as $event => $listeners) { |
||
| 90 | $rows[] = [ |
||
| 91 | $event, |
||
| 92 | is_countable($listeners) ? count($listeners) : 0, |
||
| 93 | implode( |
||
| 94 | "\n", |
||
| 95 | array_map(function ($listener) { |
||
| 96 | if (is_array($listener)) { |
||
| 97 | return sprintf( |
||
| 98 | '%s::%s', |
||
| 99 | $listener[0], |
||
| 100 | $listener[1] |
||
| 101 | ); |
||
| 102 | } |
||
| 103 | return $this->export($listener); |
||
| 104 | }, $listeners) |
||
| 105 | ), |
||
| 106 | ]; |
||
| 107 | } |
||
| 108 | $table = new Table($output); |
||
| 109 | $table |
||
| 110 | ->setHeaders(['Event', 'Count', 'Listeners']) |
||
| 111 | ->setRows($rows); |
||
| 112 | $table->render(); |
||
| 113 | |||
| 114 | return ExitCode::OK; |
||
| 115 | } |
||
| 129 |