| Conditions | 22 |
| Paths | 16384 |
| Total Lines | 58 |
| Code Lines | 40 |
| 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 |
||
| 143 | private function createRoute( |
||
| 144 | MetadataInterface $metadata, |
||
| 145 | array $configuration, |
||
| 146 | string $path, |
||
| 147 | string $actionName, |
||
| 148 | array $methods, |
||
| 149 | bool $isApi = false |
||
| 150 | ): Route { |
||
| 151 | $defaults = [ |
||
| 152 | '_controller' => $metadata->getServiceId('controller') . sprintf(':%sAction', $actionName), |
||
| 153 | ]; |
||
| 154 | |||
| 155 | if ($isApi && 'index' === $actionName) { |
||
| 156 | $defaults['_sylius']['serialization_groups'] = ['Default']; |
||
| 157 | } |
||
| 158 | if ($isApi && in_array($actionName, ['show', 'create', 'update'], true)) { |
||
| 159 | $defaults['_sylius']['serialization_groups'] = ['Default', 'Detailed']; |
||
| 160 | } |
||
| 161 | if ($isApi && 'delete' === $actionName) { |
||
| 162 | $defaults['_sylius']['csrf_protection'] = false; |
||
| 163 | } |
||
| 164 | if (isset($configuration['grid']) && 'index' === $actionName) { |
||
| 165 | $defaults['_sylius']['grid'] = $configuration['grid']; |
||
| 166 | } |
||
| 167 | if (isset($configuration['form']) && in_array($actionName, ['create', 'update'], true)) { |
||
| 168 | $defaults['_sylius']['form'] = $configuration['form']; |
||
| 169 | } |
||
| 170 | if (isset($configuration['serialization_version'])) { |
||
| 171 | $defaults['_sylius']['serialization_version'] = $configuration['serialization_version']; |
||
| 172 | } |
||
| 173 | if (isset($configuration['section'])) { |
||
| 174 | $defaults['_sylius']['section'] = $configuration['section']; |
||
| 175 | } |
||
| 176 | if (!empty($configuration['criteria'])) { |
||
| 177 | $defaults['_sylius']['criteria'] = $configuration['criteria']; |
||
| 178 | } |
||
| 179 | if (array_key_exists('filterable', $configuration)) { |
||
| 180 | $defaults['_sylius']['filterable'] = $configuration['filterable']; |
||
| 181 | } |
||
| 182 | if (isset($configuration['templates']) && in_array($actionName, ['show', 'index', 'create', 'update'], true)) { |
||
| 183 | $defaults['_sylius']['template'] = sprintf('%s:%s.html.twig', $configuration['templates'], $actionName); |
||
| 184 | } |
||
| 185 | if (isset($configuration['redirect']) && in_array($actionName, ['create', 'update'], true)) { |
||
| 186 | $defaults['_sylius']['redirect'] = $this->getRouteName($metadata, $configuration, $configuration['redirect']); |
||
| 187 | } |
||
| 188 | if (isset($configuration['permission'])) { |
||
| 189 | $defaults['_sylius']['permission'] = $configuration['permission']; |
||
| 190 | } |
||
| 191 | if (isset($configuration['vars']['all'])) { |
||
| 192 | $defaults['_sylius']['vars'] = $configuration['vars']['all']; |
||
| 193 | } |
||
| 194 | if (isset($configuration['vars'][$actionName])) { |
||
| 195 | $vars = $configuration['vars']['all'] ?? []; |
||
| 196 | $defaults['_sylius']['vars'] = array_merge($vars, $configuration['vars'][$actionName]); |
||
| 197 | } |
||
| 198 | |||
| 199 | return $this->routeFactory->createRoute($path, $defaults, [], [], '', [], $methods); |
||
| 200 | } |
||
| 201 | |||
| 216 |