Conditions | 13 |
Paths | 10 |
Total Lines | 52 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
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 |
||
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 | switch (true) { |
||
80 | case isset($attributeDefinitions[$name]): |
||
81 | $attributeDefinition = $attributeDefinitions[$name]; |
||
82 | break; |
||
83 | case isset($lcIdOrAliasMap[$name], $attributeDefinitions[$lcIdOrAliasMap[$name]]): |
||
84 | $attributeDefinition = $attributeDefinitions[$lcIdOrAliasMap[$name]]; |
||
85 | break; |
||
86 | default: |
||
87 | continue 2; // switch is considered a looping structure, we have to continue the foreach |
||
88 | } |
||
89 | $id = $attributeDefinition['id']; |
||
90 | $aliases = $attributeDefinition['aliases']; |
||
91 | $server->set($id, (string)$value); |
||
92 | foreach ($aliases as $alias) { |
||
93 | $server->set($alias, (string)$value); |
||
94 | } |
||
95 | } |
||
96 | } |
||
97 | } |
||
98 | } |
||
99 | } |
||
100 |