| Conditions | 11 |
| Paths | 39 |
| Total Lines | 46 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 41 | public function resolveResources(FilterControllerEvent $event) |
||
| 42 | { |
||
| 43 | $request = $event->getRequest(); |
||
| 44 | $resources = []; |
||
| 45 | |||
| 46 | foreach ($request->attributes->get('_resources', []) as $resourceKey => $resourceValue) { |
||
| 47 | $resourceValue = $this->parse($resourceValue) ?: $resourceValue; |
||
| 48 | $resources[$resourceKey] = $resourceValue; |
||
| 49 | } |
||
| 50 | |||
| 51 | foreach ($resources as $resourceKey => $resourceDetails) { |
||
| 52 | $resourceDetails = $this->normalizer->normalizeDeclaration($resourceDetails); |
||
| 53 | $parameters = []; |
||
| 54 | |||
| 55 | foreach ($resourceDetails['arguments'] as $parameter) { |
||
| 56 | $parameter = $this->castParameter($parameter) ?: $parameter; |
||
| 57 | $parameters[] = $parameter; |
||
| 58 | } |
||
| 59 | |||
| 60 | $resource = $this |
||
| 61 | ->resolver |
||
| 62 | ->resolveResource( |
||
| 63 | $resourceDetails['service'], |
||
| 64 | $resourceDetails['method'], |
||
| 65 | $parameters |
||
| 66 | ) |
||
| 67 | ; |
||
| 68 | |||
| 69 | if (false !== $resourceDetails['required'] && null === $resource) { |
||
| 70 | if (!array_key_exists('on-missing', $resourceDetails)) { |
||
| 71 | throw new NotFoundHttpException(sprintf('The resource %s could not be found', $resourceKey)); |
||
| 72 | } |
||
| 73 | |||
| 74 | if (!is_array($resourceDetails['on-missing']) || !array_key_exists('throw', $resourceDetails['on-missing'])) { |
||
| 75 | throw new \InvalidArgumentException('"on-missing" must be an array and contain "throw" parameter.'); |
||
| 76 | } |
||
| 77 | $this->throwMissingException($resourceDetails['on-missing'], $resourceKey); |
||
| 78 | } |
||
| 79 | |||
| 80 | $request->attributes->set($resourceKey, $resource); |
||
| 81 | |||
| 82 | $this->container->addResource($resourceKey, $resource); |
||
| 83 | } |
||
| 84 | |||
| 85 | return $event; |
||
| 86 | } |
||
| 87 | |||
| 147 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: