| Conditions | 10 |
| Paths | 43 |
| Total Lines | 37 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 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 |
||
| 41 | protected function loadExtensions(ContainerBuilder $container) |
||
| 42 | { |
||
| 43 | $taggedServices = $container->findTaggedServiceIds(self::TAG); |
||
| 44 | $extensions = []; |
||
| 45 | foreach ($taggedServices as $id => $tagAttributes) { |
||
| 46 | if ($container->hasDefinition($id)) { |
||
| 47 | $container->getDefinition($id)->setPublic(false); |
||
| 48 | } |
||
| 49 | $priority = 0; |
||
| 50 | $extensionName = null; |
||
| 51 | foreach ($tagAttributes as $attributes) { |
||
| 52 | if (!empty($attributes['priority'])) { |
||
| 53 | $priority = (int)$attributes['priority']; |
||
| 54 | } |
||
| 55 | if (!isset($attributes['extension_name']) || empty($attributes['extension_name'])) { |
||
| 56 | throw new InvalidConfigurationException( |
||
| 57 | sprintf('Tag attribute "extension_name" is required for "%s" service', $id) |
||
| 58 | ); |
||
| 59 | } |
||
| 60 | $extensionName = $attributes['extension_name']; |
||
| 61 | } |
||
| 62 | if (!isset($extensions[$extensionName])) { |
||
| 63 | $extensions[$extensionName] = []; |
||
| 64 | } |
||
| 65 | $extensions[$extensionName][$priority] = $id; |
||
| 66 | } |
||
| 67 | |||
| 68 | $result = []; |
||
| 69 | foreach ($extensions as $name => $extension) { |
||
| 70 | if (count($extension) > 1) { |
||
| 71 | krsort($extension); |
||
| 72 | } |
||
| 73 | $result[$name] = array_pop($extension); |
||
| 74 | } |
||
| 75 | |||
| 76 | return $result; |
||
| 77 | } |
||
| 78 | } |
||
| 79 |