Conditions | 24 |
Paths | > 20000 |
Total Lines | 71 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
148 | private function createRoute( |
||
149 | MetadataInterface $metadata, |
||
150 | array $configuration, |
||
151 | string $path, |
||
152 | string $actionName, |
||
153 | array $methods, |
||
154 | bool $isApi = false |
||
155 | ): Route { |
||
156 | $defaults = [ |
||
157 | '_controller' => $metadata->getServiceId('controller') . sprintf(':%sAction', $actionName), |
||
158 | ]; |
||
159 | |||
160 | if ($isApi && 'index' === $actionName) { |
||
161 | $defaults['_sylius']['serialization_groups'] = ['Default']; |
||
162 | } |
||
163 | if ($isApi && in_array($actionName, ['show', 'create', 'update'], true)) { |
||
164 | $defaults['_sylius']['serialization_groups'] = ['Default', 'Detailed']; |
||
165 | } |
||
166 | if ($isApi && 'delete' === $actionName) { |
||
167 | $defaults['_sylius']['csrf_protection'] = false; |
||
168 | } |
||
169 | if (isset($configuration['grid']) && 'index' === $actionName) { |
||
170 | $defaults['_sylius']['grid'] = $configuration['grid']; |
||
171 | } |
||
172 | if (isset($configuration['form']) && in_array($actionName, ['create', 'update'], true)) { |
||
173 | $defaults['_sylius']['form'] = $configuration['form']; |
||
174 | } |
||
175 | if (isset($configuration['serialization_version'])) { |
||
176 | $defaults['_sylius']['serialization_version'] = $configuration['serialization_version']; |
||
177 | } |
||
178 | if (isset($configuration['section'])) { |
||
179 | $defaults['_sylius']['section'] = $configuration['section']; |
||
180 | } |
||
181 | if (!empty($configuration['criteria'])) { |
||
182 | $defaults['_sylius']['criteria'] = $configuration['criteria']; |
||
183 | } |
||
184 | if (array_key_exists('filterable', $configuration)) { |
||
185 | $defaults['_sylius']['filterable'] = $configuration['filterable']; |
||
186 | } |
||
187 | if (isset($configuration['templates']) && in_array($actionName, ['show', 'index', 'create', 'update'], true)) { |
||
188 | $defaults['_sylius']['template'] = sprintf( |
||
189 | false === strpos($configuration['templates'], ':') ? '%s/%s.html.twig' : '%s:%s.html.twig', |
||
190 | $configuration['templates'], |
||
191 | $actionName |
||
192 | ); |
||
193 | } |
||
194 | if (isset($configuration['redirect']) && in_array($actionName, ['create', 'update'], true)) { |
||
195 | $defaults['_sylius']['redirect'] = $this->getRouteName($metadata, $configuration, $configuration['redirect']); |
||
196 | } |
||
197 | if (isset($configuration['permission'])) { |
||
198 | $defaults['_sylius']['permission'] = $configuration['permission']; |
||
199 | } |
||
200 | if (isset($configuration['vars']['all'])) { |
||
201 | $defaults['_sylius']['vars'] = $configuration['vars']['all']; |
||
202 | } |
||
203 | |||
204 | if (isset($configuration['vars'][$actionName])) { |
||
205 | $vars = $configuration['vars']['all'] ?? []; |
||
206 | $defaults['_sylius']['vars'] = array_merge($vars, $configuration['vars'][$actionName]); |
||
207 | } |
||
208 | |||
209 | if ($actionName === 'bulkDelete') { |
||
210 | $defaults['_sylius']['paginate'] = false; |
||
211 | $defaults['_sylius']['repository'] = [ |
||
212 | 'method' => 'findById', |
||
213 | 'arguments' => ['$ids'], |
||
214 | ]; |
||
215 | } |
||
216 | |||
217 | return $this->routeFactory->createRoute($path, $defaults, [], [], '', [], $methods); |
||
218 | } |
||
219 | |||
234 |