Conditions | 42 |
Paths | > 20000 |
Total Lines | 154 |
Code Lines | 87 |
Lines | 85 |
Ratio | 55.19 % |
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 |
||
137 | private function parseDefinition($id, $service, $file) |
||
138 | { |
||
139 | View Code Duplication | if (is_string($service) && 0 === strpos($service, '@')) { |
|
140 | $this->container->setAlias($id, substr($service, 1)); |
||
141 | |||
142 | return; |
||
143 | } |
||
144 | |||
145 | View Code Duplication | if (!is_array($service)) { |
|
146 | throw new InvalidArgumentException(sprintf('A service definition must be an array or a string starting with "@" but %s found for service "%s" in %s. Check your YAML syntax.', gettype($service), $id, $file)); |
||
147 | } |
||
148 | |||
149 | View Code Duplication | if (isset($service['alias'])) { |
|
150 | $public = !array_key_exists('public', $service) || (bool) $service['public']; |
||
151 | $this->container->setAlias($id, new Alias($service['alias'], $public)); |
||
152 | |||
153 | return; |
||
154 | } |
||
155 | |||
156 | View Code Duplication | if (isset($service['parent'])) { |
|
157 | $definition = new DefinitionDecorator($service['parent']); |
||
158 | } else { |
||
159 | $definition = new Definition(); |
||
160 | } |
||
161 | |||
162 | if (isset($service['class'])) { |
||
163 | $definition->setClass($service['class']); |
||
164 | } |
||
165 | |||
166 | if (isset($service['scope'])) { |
||
167 | $definition->setScope($service['scope']); |
||
168 | } |
||
169 | |||
170 | if (isset($service['synthetic'])) { |
||
171 | $definition->setSynthetic($service['synthetic']); |
||
172 | } |
||
173 | |||
174 | if (isset($service['synchronized'])) { |
||
175 | trigger_error(sprintf('The "synchronized" key in file "%s" is deprecated since version 2.7 and will be removed in 3.0.', $file), E_USER_DEPRECATED); |
||
176 | $definition->setSynchronized($service['synchronized'], 'request' !== $id); |
||
177 | } |
||
178 | |||
179 | if (isset($service['lazy'])) { |
||
180 | $definition->setLazy($service['lazy']); |
||
181 | } |
||
182 | |||
183 | if (isset($service['public'])) { |
||
184 | $definition->setPublic($service['public']); |
||
185 | } |
||
186 | |||
187 | if (isset($service['abstract'])) { |
||
188 | $definition->setAbstract($service['abstract']); |
||
189 | } |
||
190 | |||
191 | View Code Duplication | if (isset($service['factory'])) { |
|
192 | if (is_string($service['factory'])) { |
||
193 | if (strpos($service['factory'], ':') !== false && strpos($service['factory'], '::') === false) { |
||
194 | $parts = explode(':', $service['factory']); |
||
195 | $definition->setFactory(array($this->resolveServices('@'.$parts[0]), $parts[1])); |
||
196 | } else { |
||
197 | $definition->setFactory($service['factory']); |
||
198 | } |
||
199 | } else { |
||
200 | $definition->setFactory(array($this->resolveServices($service['factory'][0]), $service['factory'][1])); |
||
201 | } |
||
202 | } |
||
203 | |||
204 | if (isset($service['factory_class'])) { |
||
205 | trigger_error(sprintf('The "factory_class" key in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use "factory" instead.', $file), E_USER_DEPRECATED); |
||
206 | $definition->setFactoryClass($service['factory_class']); |
||
207 | } |
||
208 | |||
209 | if (isset($service['factory_method'])) { |
||
210 | trigger_error(sprintf('The "factory_method" key in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use "factory" instead.', $file), E_USER_DEPRECATED); |
||
211 | $definition->setFactoryMethod($service['factory_method']); |
||
212 | } |
||
213 | |||
214 | if (isset($service['factory_service'])) { |
||
215 | trigger_error(sprintf('The "factory_service" key in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use "factory" instead.', $file), E_USER_DEPRECATED); |
||
216 | $definition->setFactoryService($service['factory_service']); |
||
217 | } |
||
218 | |||
219 | if (isset($service['file'])) { |
||
220 | $definition->setFile($service['file']); |
||
221 | } |
||
222 | |||
223 | if (isset($service['arguments'])) { |
||
224 | $definition->setArguments($this->resolveServices($service['arguments'])); |
||
225 | } |
||
226 | |||
227 | if (isset($service['properties'])) { |
||
228 | $definition->setProperties($this->resolveServices($service['properties'])); |
||
229 | } |
||
230 | |||
231 | View Code Duplication | if (isset($service['configurator'])) { |
|
232 | if (is_string($service['configurator'])) { |
||
233 | $definition->setConfigurator($service['configurator']); |
||
234 | } else { |
||
235 | $definition->setConfigurator(array($this->resolveServices($service['configurator'][0]), $service['configurator'][1])); |
||
236 | } |
||
237 | } |
||
238 | |||
239 | View Code Duplication | if (isset($service['calls'])) { |
|
240 | if (!is_array($service['calls'])) { |
||
241 | throw new InvalidArgumentException(sprintf('Parameter "calls" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file)); |
||
242 | } |
||
243 | |||
244 | foreach ($service['calls'] as $call) { |
||
245 | if (isset($call['method'])) { |
||
246 | $method = $call['method']; |
||
247 | $args = isset($call['arguments']) ? $this->resolveServices($call['arguments']) : array(); |
||
248 | } else { |
||
249 | $method = $call[0]; |
||
250 | $args = isset($call[1]) ? $this->resolveServices($call[1]) : array(); |
||
251 | } |
||
252 | |||
253 | $definition->addMethodCall($method, $args); |
||
254 | } |
||
255 | } |
||
256 | |||
257 | View Code Duplication | if (isset($service['tags'])) { |
|
258 | if (!is_array($service['tags'])) { |
||
259 | throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file)); |
||
260 | } |
||
261 | |||
262 | foreach ($service['tags'] as $tag) { |
||
263 | if (!is_array($tag)) { |
||
264 | throw new InvalidArgumentException(sprintf('A "tags" entry must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file)); |
||
265 | } |
||
266 | |||
267 | if (!isset($tag['name'])) { |
||
268 | throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file)); |
||
269 | } |
||
270 | |||
271 | $name = $tag['name']; |
||
272 | unset($tag['name']); |
||
273 | |||
274 | foreach ($tag as $attribute => $value) { |
||
275 | if (!is_scalar($value) && null !== $value) { |
||
276 | throw new InvalidArgumentException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s" in %s. Check your YAML syntax.', $id, $name, $attribute, $file)); |
||
277 | } |
||
278 | } |
||
279 | |||
280 | $definition->addTag($name, $tag); |
||
281 | } |
||
282 | } |
||
283 | |||
284 | View Code Duplication | if (isset($service['decorates'])) { |
|
285 | $renameId = isset($service['decoration_inner_name']) ? $service['decoration_inner_name'] : null; |
||
286 | $definition->setDecoratedService($service['decorates'], $renameId); |
||
287 | } |
||
288 | |||
289 | $this->container->setDefinition($id, $definition); |
||
290 | } |
||
291 | |||
422 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.