| Conditions | 13 |
| Paths | 10 |
| Total Lines | 53 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 0 | Features | 2 |
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 |
||
| 47 | public function onKernelRequest(GetResponseEvent $event) |
||
| 48 | { |
||
| 49 | if (!$event->isMasterRequest()) { |
||
| 50 | return; |
||
| 51 | } |
||
| 52 | |||
| 53 | if (!empty($this->providerPropertiesCollection)) { |
||
| 54 | $attributeDefinitions = $this->attributeDefinitionsProvider->getAttributeDefinitions(); |
||
| 55 | $lcIdOrAliasMap = []; |
||
| 56 | foreach ($attributeDefinitions as $idOrAlias => $attributeDefinition) { |
||
| 57 | $lcIdOrAliasMap[strtolower($idOrAlias)] = $idOrAlias; |
||
| 58 | } |
||
| 59 | $server = $event->getRequest()->server; |
||
| 60 | $providerPropertiesCollectionIterator = $this->providerPropertiesCollection->getIterator(); |
||
| 61 | $providerPropertiesCollectionIterator->uasort(function ($first, $second) { |
||
| 62 | // Place highest priority first |
||
| 63 | if ($first['priority'] === $second['priority']) { |
||
| 64 | return 0; |
||
| 65 | } |
||
| 66 | return (int)$first['priority'] > (int)$second['priority'] ? -1 : 1; |
||
| 67 | }); |
||
| 68 | foreach ($providerPropertiesCollectionIterator as $providerProperties) { |
||
| 69 | /** @var AttributesInjectionProviderInterface $provider */ |
||
| 70 | $provider = $providerProperties['provider']; |
||
| 71 | if (!$provider->isEnabled()) { |
||
| 72 | continue; |
||
| 73 | } |
||
| 74 | $attributes = $provider->getAttributes(); |
||
| 75 | if (empty($attributes)) { |
||
| 76 | continue; |
||
| 77 | } |
||
| 78 | foreach ($attributes as $name => $value) { |
||
| 79 | $attributeDefinition = null; |
||
|
|
|||
| 80 | switch (true) { |
||
| 81 | case isset($attributeDefinitions[$name]): |
||
| 82 | $attributeDefinition = $attributeDefinitions[$name]; |
||
| 83 | break; |
||
| 84 | case isset($lcIdOrAliasMap[$name], $attributeDefinitions[$lcIdOrAliasMap[$name]]): |
||
| 85 | $attributeDefinition = $attributeDefinitions[$lcIdOrAliasMap[$name]]; |
||
| 86 | break; |
||
| 87 | default: |
||
| 88 | continue 2; // switch is considered a looping structure, we have to continue the foreach |
||
| 89 | } |
||
| 90 | $id = $attributeDefinition['id']; |
||
| 91 | $aliases = $attributeDefinition['aliases']; |
||
| 92 | $server->set($id, (string)$value); |
||
| 93 | foreach ($aliases as $alias) { |
||
| 94 | $server->set($alias, (string)$value); |
||
| 95 | } |
||
| 96 | } |
||
| 97 | } |
||
| 98 | } |
||
| 99 | } |
||
| 100 | } |
||
| 101 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.