| Conditions | 11 |
| Paths | 112 |
| Total Lines | 55 |
| Code Lines | 33 |
| 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 |
||
| 73 | protected function processBlock(\SimpleXMLElement $element, ContainerBuilder $container, $parent = null) { |
||
| 74 | $blockDefinition = []; |
||
| 75 | |||
| 76 | if ($parent) { |
||
| 77 | $blockDefinition['parent'] = $parent; |
||
| 78 | } |
||
| 79 | |||
| 80 | if (isset($element->attributes()['component'])) { |
||
| 81 | $blockDefinition['component'] = (string) $element->attributes()['component']; |
||
| 82 | } else { |
||
| 83 | $blockDefinition['extends'] = (string) $element['@attributes']['extends']; |
||
| 84 | } |
||
| 85 | |||
| 86 | if (isset($element->attributes()['alias'])) { |
||
| 87 | $blockDefinition['alias'] = (string) $element->attributes()['alias']; |
||
| 88 | } |
||
| 89 | |||
| 90 | foreach ($element->argument as $argument) { |
||
| 91 | $name = (string) $argument->attributes()['name']; |
||
| 92 | |||
| 93 | switch ($this->getXsiType($argument)) { |
||
| 94 | case "expr": |
||
| 95 | $blockDefinition['config']['expr'][$name] = (string) $argument; |
||
| 96 | break; |
||
| 97 | |||
| 98 | case "action": |
||
| 99 | $blockDefinition['config']['action'][$name]['method'] = (string)$argument->method[0]; |
||
| 100 | if (isset($argument->service[0])) { |
||
| 101 | // Use symfony to actually get a reference. |
||
| 102 | $blockDefinition['config']['action'][$name]['service'] = new Reference((string)$argument->service[0]); |
||
| 103 | } |
||
| 104 | break; |
||
| 105 | |||
| 106 | case "args": |
||
| 107 | $blockDefinition['config']['args'][$name] = []; |
||
| 108 | foreach ($argument->arg as $arg) { |
||
| 109 | $blockDefinition['config']['args'][$name][] = (string) $arg; |
||
| 110 | } |
||
| 111 | break; |
||
| 112 | |||
| 113 | default: |
||
| 114 | $blockDefinition['config']['def'][$name] = (string) $argument; |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | $blockDefinitions = [ |
||
| 119 | (string) $element->attributes()['id'] => $blockDefinition, |
||
| 120 | ]; |
||
| 121 | |||
| 122 | foreach ($element->block as $block) { |
||
| 123 | $blockDefinitions += $this->processBlock($block, $container, (string) $element->attributes()['id']); |
||
| 124 | } |
||
| 125 | |||
| 126 | return $blockDefinitions; |
||
| 127 | } |
||
| 128 | |||
| 140 | } |