Conditions | 38 |
Paths | 900 |
Total Lines | 138 |
Code Lines | 76 |
Lines | 6 |
Ratio | 4.35 % |
Changes | 2 | ||
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 |
||
145 | private function parseDefinition($id, $service) |
||
146 | { |
||
147 | if (is_string($service) && 0 === strpos($service, '@')) { |
||
148 | return new AliasDefinition($id, substr($service, 1)); |
||
149 | } |
||
150 | |||
151 | View Code Duplication | if (!is_array($service)) { |
|
152 | 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, $this->fileName)); |
||
153 | } |
||
154 | |||
155 | if (isset($service['alias'])) { |
||
156 | if (isset($service['public'])) { |
||
157 | throw new InvalidArgumentException('The "public" key is not supported by YamlDefinitionLoader. This is a Symfony specific feature.'); |
||
158 | } |
||
159 | return new AliasDefinition($id, $service['alias']); |
||
160 | } |
||
161 | |||
162 | if (isset($service['parent'])) { |
||
163 | throw new InvalidArgumentException('Definition decorators via the "parent" key are not supported by YamlDefinitionLoader. This is a Symfony specific feature.'); |
||
164 | } |
||
165 | |||
166 | $definition = null; |
||
167 | |||
168 | if (isset($service['class'])) { |
||
169 | $definition = new InstanceDefinition($id, $service['class']); |
||
170 | |||
171 | if (isset($service['arguments'])) { |
||
172 | $arguments = $this->resolveServices($service['arguments']); |
||
173 | foreach ($arguments as $argument) { |
||
174 | $definition->addConstructorArgument($argument); |
||
175 | } |
||
176 | } |
||
177 | |||
178 | if (isset($service['properties'])) { |
||
179 | $properties = $this->resolveServices($service['properties']); |
||
180 | foreach ($properties as $name => $property) { |
||
181 | $definition->addPropertyAssignment($name, $property); |
||
182 | } |
||
183 | } |
||
184 | |||
185 | if (isset($service['calls'])) { |
||
186 | View Code Duplication | if (!is_array($service['calls'])) { |
|
187 | throw new InvalidArgumentException(sprintf('Parameter "calls" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $this->fileName)); |
||
188 | } |
||
189 | |||
190 | foreach ($service['calls'] as $call) { |
||
191 | if (isset($call['method'])) { |
||
192 | $method = $call['method']; |
||
193 | $args = isset($call['arguments']) ? $this->resolveServices($call['arguments']) : array(); |
||
194 | } else { |
||
195 | $method = $call[0]; |
||
196 | $args = isset($call[1]) ? $this->resolveServices($call[1]) : array(); |
||
197 | } |
||
198 | |||
199 | array_unshift($args, $method); |
||
200 | call_user_func_array([$definition, 'addMethodCall'], $args); |
||
201 | } |
||
202 | } |
||
203 | |||
204 | } |
||
205 | |||
206 | if (isset($service['factory'])) { |
||
207 | if (is_string($service['factory'])) { |
||
208 | if (strpos($service['factory'], ':') !== false && strpos($service['factory'], '::') === false) { |
||
209 | $parts = explode(':', $service['factory']); |
||
210 | $definition = new FactoryDefinition($id, $this->resolveServices('@'.$parts[0]), $parts[1]); |
||
211 | } elseif (strpos($service['factory'], ':') !== false && strpos($service['factory'], '::') !== false) { |
||
212 | $parts = explode('::', $service['factory']); |
||
213 | $definition = new FactoryDefinition($id, $parts[0], $parts[1]); |
||
214 | } else { |
||
215 | throw new InvalidArgumentException('A "factory" must be in the format "service_name:method_name" or "class_name::method_name".Got "'.$service['factory'].'"'); |
||
216 | } |
||
217 | } else { |
||
218 | $definition = new FactoryDefinition($id, $this->resolveServices($service['factory'][0]), $service['factory'][1]); |
||
219 | } |
||
220 | |||
221 | if (isset($service['arguments'])) { |
||
222 | $arguments = $this->resolveServices($service['arguments']); |
||
223 | call_user_func_array([$definition, 'setArguments'], $arguments); |
||
224 | } |
||
225 | } |
||
226 | |||
227 | if (isset($service['shared'])) { |
||
228 | throw new InvalidArgumentException('The "shared" key in instance definitions is not supported by YamlDefinitionLoader. This is a Symfony specific feature.'); |
||
229 | } |
||
230 | |||
231 | if (isset($service['synthetic'])) { |
||
232 | throw new InvalidArgumentException('The "synthetic" key in instance definitions is not supported by YamlDefinitionLoader. This is a Symfony specific feature.'); |
||
233 | } |
||
234 | |||
235 | if (isset($service['lazy'])) { |
||
236 | throw new InvalidArgumentException('The "lazy" key in instance definitions is not supported by YamlDefinitionLoader. This is a Symfony specific feature.'); |
||
237 | } |
||
238 | |||
239 | if (isset($service['public'])) { |
||
240 | throw new InvalidArgumentException('The "public" key in instance definitions is not supported by YamlDefinitionLoader. This is a Symfony specific feature.'); |
||
241 | } |
||
242 | |||
243 | if (isset($service['abstract'])) { |
||
244 | throw new InvalidArgumentException('The "abstract" key in instance definitions is not supported by YamlDefinitionLoader. This is a Symfony specific feature.'); |
||
245 | } |
||
246 | |||
247 | if (array_key_exists('deprecated', $service)) { |
||
248 | throw new InvalidArgumentException('The "deprecated" key in instance definitions is not supported by YamlDefinitionLoader. This is a Symfony specific feature.'); |
||
249 | } |
||
250 | |||
251 | if (isset($service['file'])) { |
||
252 | throw new InvalidArgumentException('The "file" key in instance definitions is not supported by YamlDefinitionLoader. This is a Symfony specific feature.'); |
||
253 | } |
||
254 | |||
255 | |||
256 | if (isset($service['configurator'])) { |
||
257 | throw new InvalidArgumentException('The "configurator" key in instance definitions is not supported by YamlDefinitionLoader. This is a Symfony specific feature.'); |
||
258 | } |
||
259 | |||
260 | |||
261 | if (isset($service['tags'])) { |
||
262 | throw new InvalidArgumentException('The "tags" key in instance definitions is not supported by YamlDefinitionLoader. This is a Symfony specific feature.'); |
||
263 | } |
||
264 | |||
265 | if (isset($service['decorates'])) { |
||
266 | throw new InvalidArgumentException('The "decorates" key in instance definitions is not supported by YamlDefinitionLoader. This is a Symfony specific feature.'); |
||
267 | } |
||
268 | |||
269 | if (isset($service['autowire'])) { |
||
270 | throw new InvalidArgumentException('The "autowire" key in instance definitions is not supported by YamlDefinitionLoader. This is a Symfony specific feature.'); |
||
271 | } |
||
272 | |||
273 | if (isset($service['autowiring_types'])) { |
||
274 | throw new InvalidArgumentException('The "autowiring_types" key in instance definitions is not supported by YamlDefinitionLoader. This is a Symfony specific feature.'); |
||
275 | } |
||
276 | |||
277 | if ($definition === null) { |
||
278 | throw new InvalidArgumentException(sprintf('Invalid service declaration for "%s" (in %s). You should specify at least a "class", "alias" or "factory" key.', $id, $this->fileName)); |
||
279 | } |
||
280 | |||
281 | return $definition; |
||
282 | } |
||
283 | |||
379 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.