Conditions | 14 |
Paths | 17 |
Total Lines | 70 |
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 | $rows = []; |
||
86 | foreach ($data as $event => $listeners) { |
||
87 | $rows[] = [ |
||
88 | $event, |
||
89 | is_countable($listeners) ? count($listeners) : 0, |
||
90 | implode( |
||
91 | "\n", |
||
92 | array_map(function ($listener) { |
||
93 | if (is_array($listener)) { |
||
94 | return sprintf( |
||
95 | '%s::%s', |
||
96 | $listener[0], |
||
97 | $listener[1] |
||
98 | ); |
||
99 | } |
||
100 | return $this->export($listener); |
||
101 | }, $listeners) |
||
102 | ), |
||
103 | ]; |
||
104 | } |
||
105 | $table = new Table($output); |
||
106 | $table |
||
107 | ->setHeaders(['Event', 'Count', 'Listeners']) |
||
108 | ->setRows($rows); |
||
109 | $table->render(); |
||
110 | |||
111 | return ExitCode::OK; |
||
112 | } |
||
127 |