| Conditions | 29 |
| Paths | > 20000 |
| Total Lines | 100 |
| Code Lines | 66 |
| Lines | 28 |
| Ratio | 28 % |
| 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 |
||
| 111 | private function addService($definition, $id, \DOMElement $parent) |
||
| 112 | { |
||
| 113 | $service = $this->document->createElement('service'); |
||
| 114 | if (null !== $id) { |
||
| 115 | $service->setAttribute('id', $id); |
||
| 116 | } |
||
| 117 | if ($definition->getClass()) { |
||
| 118 | $service->setAttribute('class', $definition->getClass()); |
||
| 119 | } |
||
| 120 | if ($definition->getFactoryMethod(false)) { |
||
| 121 | $service->setAttribute('factory-method', $definition->getFactoryMethod(false)); |
||
| 122 | } |
||
| 123 | if ($definition->getFactoryClass(false)) { |
||
| 124 | $service->setAttribute('factory-class', $definition->getFactoryClass(false)); |
||
| 125 | } |
||
| 126 | if ($definition->getFactoryService(false)) { |
||
| 127 | $service->setAttribute('factory-service', $definition->getFactoryService(false)); |
||
| 128 | } |
||
| 129 | if (ContainerInterface::SCOPE_CONTAINER !== $scope = $definition->getScope()) { |
||
| 130 | $service->setAttribute('scope', $scope); |
||
| 131 | } |
||
| 132 | if (!$definition->isPublic()) { |
||
| 133 | $service->setAttribute('public', 'false'); |
||
| 134 | } |
||
| 135 | if ($definition->isSynthetic()) { |
||
| 136 | $service->setAttribute('synthetic', 'true'); |
||
| 137 | } |
||
| 138 | if ($definition->isSynchronized(false)) { |
||
| 139 | $service->setAttribute('synchronized', 'true'); |
||
| 140 | } |
||
| 141 | if ($definition->isLazy()) { |
||
| 142 | $service->setAttribute('lazy', 'true'); |
||
| 143 | } |
||
| 144 | if (null !== $decorated = $definition->getDecoratedService()) { |
||
| 145 | list($decorated, $renamedId) = $decorated; |
||
| 146 | $service->setAttribute('decorates', $decorated); |
||
| 147 | if (null !== $renamedId) { |
||
| 148 | $service->setAttribute('decoration-inner-name', $renamedId); |
||
| 149 | } |
||
| 150 | } |
||
| 151 | |||
| 152 | foreach ($definition->getTags() as $name => $tags) { |
||
| 153 | foreach ($tags as $attributes) { |
||
| 154 | $tag = $this->document->createElement('tag'); |
||
| 155 | $tag->setAttribute('name', $name); |
||
| 156 | foreach ($attributes as $key => $value) { |
||
| 157 | $tag->setAttribute($key, $value); |
||
| 158 | } |
||
| 159 | $service->appendChild($tag); |
||
| 160 | } |
||
| 161 | } |
||
| 162 | |||
| 163 | if ($definition->getFile()) { |
||
| 164 | $file = $this->document->createElement('file'); |
||
| 165 | $file->appendChild($this->document->createTextNode($definition->getFile())); |
||
| 166 | $service->appendChild($file); |
||
| 167 | } |
||
| 168 | |||
| 169 | if ($parameters = $definition->getArguments()) { |
||
| 170 | $this->convertParameters($parameters, 'argument', $service); |
||
| 171 | } |
||
| 172 | |||
| 173 | if ($parameters = $definition->getProperties()) { |
||
| 174 | $this->convertParameters($parameters, 'property', $service, 'name'); |
||
| 175 | } |
||
| 176 | |||
| 177 | $this->addMethodCalls($definition->getMethodCalls(), $service); |
||
| 178 | |||
| 179 | View Code Duplication | if ($callable = $definition->getFactory()) { |
|
| 180 | $factory = $this->document->createElement('factory'); |
||
| 181 | |||
| 182 | if (is_array($callable) && $callable[0] instanceof Definition) { |
||
| 183 | $this->addService($callable[0], null, $factory); |
||
| 184 | $factory->setAttribute('method', $callable[1]); |
||
| 185 | } elseif (is_array($callable)) { |
||
| 186 | $factory->setAttribute($callable[0] instanceof Reference ? 'service' : 'class', $callable[0]); |
||
| 187 | $factory->setAttribute('method', $callable[1]); |
||
| 188 | } else { |
||
| 189 | $factory->setAttribute('function', $callable); |
||
| 190 | } |
||
| 191 | $service->appendChild($factory); |
||
| 192 | } |
||
| 193 | |||
| 194 | View Code Duplication | if ($callable = $definition->getConfigurator()) { |
|
| 195 | $configurator = $this->document->createElement('configurator'); |
||
| 196 | |||
| 197 | if (is_array($callable) && $callable[0] instanceof Definition) { |
||
| 198 | $this->addService($callable[0], null, $configurator); |
||
| 199 | $configurator->setAttribute('method', $callable[1]); |
||
| 200 | } elseif (is_array($callable)) { |
||
| 201 | $configurator->setAttribute($callable[0] instanceof Reference ? 'service' : 'class', $callable[0]); |
||
| 202 | $configurator->setAttribute('method', $callable[1]); |
||
| 203 | } else { |
||
| 204 | $configurator->setAttribute('function', $callable); |
||
| 205 | } |
||
| 206 | $service->appendChild($configurator); |
||
| 207 | } |
||
| 208 | |||
| 209 | $parent->appendChild($service); |
||
| 210 | } |
||
| 211 | |||
| 357 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.