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