| Conditions | 19 |
| Paths | 62 |
| Total Lines | 110 |
| Code Lines | 69 |
| 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 |
||
| 47 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 48 | { |
||
| 49 | $this->debugger->stop(); |
||
| 50 | $config = $this->container->get(ConfigInterface::class); |
||
| 51 | |||
| 52 | $io = new SymfonyStyle($input, $output); |
||
| 53 | |||
| 54 | if ($input->hasArgument('id') && !empty($ids = $input->getArgument('id'))) { |
||
| 55 | $build = $this->getConfigBuild($config); |
||
| 56 | foreach ($ids as $id) { |
||
| 57 | $definition = null; |
||
| 58 | foreach ($build as $definitions) { |
||
| 59 | if (array_key_exists($id, $definitions)) { |
||
| 60 | $definition = $definitions[$id]; |
||
| 61 | } |
||
| 62 | } |
||
| 63 | if ($definition === null) { |
||
| 64 | $io->error( |
||
| 65 | sprintf( |
||
| 66 | 'Service "%s" not found.', |
||
| 67 | $id, |
||
| 68 | ) |
||
| 69 | ); |
||
| 70 | continue; |
||
| 71 | } |
||
| 72 | $io->title($id); |
||
| 73 | |||
| 74 | $normalizedDefinition = DefinitionNormalizer::normalize($definition, $id); |
||
| 75 | if ($normalizedDefinition instanceof ArrayDefinition) { |
||
| 76 | $definitionList = ['ID' => $id]; |
||
| 77 | if (class_exists($normalizedDefinition->getClass())) { |
||
| 78 | $definitionList[] = ['Class' => $normalizedDefinition->getClass()]; |
||
| 79 | } |
||
| 80 | if (!empty($normalizedDefinition->getConstructorArguments())) { |
||
| 81 | $definitionList[] = [ |
||
| 82 | 'Constructor' => $this->export( |
||
| 83 | $normalizedDefinition->getConstructorArguments() |
||
| 84 | ), |
||
| 85 | ]; |
||
| 86 | } |
||
| 87 | if (!empty($normalizedDefinition->getMethodsAndProperties())) { |
||
| 88 | $definitionList[] = [ |
||
| 89 | 'Methods' => $this->export( |
||
| 90 | $normalizedDefinition->getMethodsAndProperties() |
||
| 91 | ), |
||
| 92 | ]; |
||
| 93 | } |
||
| 94 | if (isset($definition['tags'])) { |
||
| 95 | $definitionList[] = ['Tags' => $this->export($definition['tags'])]; |
||
| 96 | } |
||
| 97 | |||
| 98 | $io->definitionList(...$definitionList); |
||
| 99 | |||
| 100 | continue; |
||
| 101 | } |
||
| 102 | if ($normalizedDefinition instanceof CallableDefinition || $normalizedDefinition instanceof ValueDefinition) { |
||
| 103 | $io->text( |
||
| 104 | $this->export($definition) |
||
| 105 | ); |
||
| 106 | continue; |
||
| 107 | } |
||
| 108 | |||
| 109 | $output->writeln([ |
||
| 110 | $id, |
||
| 111 | VarDumper::create($normalizedDefinition)->asString(), |
||
| 112 | ]); |
||
| 113 | } |
||
| 114 | |||
| 115 | return ExitCode::OK; |
||
| 116 | } |
||
| 117 | |||
| 118 | if ($input->hasOption('groups') && $input->getOption('groups')) { |
||
| 119 | $build = $this->getConfigBuild($config); |
||
| 120 | $groups = array_keys($build); |
||
| 121 | sort($groups); |
||
| 122 | |||
| 123 | $io->table(['Groups'], array_map(static fn ($group) => [$group], $groups)); |
||
| 124 | |||
| 125 | return ExitCode::OK; |
||
| 126 | } |
||
| 127 | if ($input->hasOption('group') && !empty($group = $input->getOption('group'))) { |
||
| 128 | $data = $config->get($group); |
||
| 129 | ksort($data); |
||
| 130 | |||
| 131 | $rows = $this->getGroupServices($data); |
||
| 132 | |||
| 133 | $table = new Table($output); |
||
| 134 | $table |
||
| 135 | ->setHeaderTitle($group) |
||
| 136 | ->setHeaders(['Service', 'Definition']) |
||
| 137 | ->setRows($rows); |
||
| 138 | $table->render(); |
||
| 139 | |||
| 140 | return ExitCode::OK; |
||
| 141 | } |
||
| 142 | |||
| 143 | $build = $this->getConfigBuild($config); |
||
| 144 | |||
| 145 | foreach ($build as $group => $data) { |
||
| 146 | $rows = $this->getGroupServices($data); |
||
| 147 | |||
| 148 | $table = new Table($output); |
||
| 149 | $table |
||
| 150 | ->setHeaderTitle($group) |
||
| 151 | ->setHeaders(['Group', 'Services']) |
||
| 152 | ->setRows($rows); |
||
| 153 | $table->render(); |
||
| 154 | } |
||
| 155 | |||
| 156 | return ExitCode::OK; |
||
| 157 | } |
||
| 195 |