Conditions | 12 |
Paths | 9 |
Total Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
60 | public function getUserInfo(UserAccount $userAccount, array $claims, array $claimLocales): array |
||
61 | { |
||
62 | $result = []; |
||
63 | $claimLocales[] = null; |
||
64 | foreach ($claims as $claimName => $config) { |
||
65 | if ($this->has($claimName)) { |
||
66 | $claim = $this->get($claimName); |
||
67 | foreach ($claimLocales as $claimLocale) { |
||
68 | if ($claim->isAvailableForUserAccount($userAccount, $claimLocale)) { |
||
69 | $value = $claim->getForUserAccount($userAccount, $claimLocale); |
||
70 | switch (true) { |
||
71 | case \is_array($config) && \array_key_exists('value', $config): |
||
72 | if ($claim === $config['value']) { |
||
73 | $result[$claimName] = $value; |
||
74 | } |
||
75 | |||
76 | break; |
||
77 | case \is_array($config) && \array_key_exists('values', $config) && \is_array($config['values']): |
||
78 | if (\in_array($claim, $config['values'], true)) { |
||
79 | $result[$claimName] = $value; |
||
80 | } |
||
81 | |||
82 | break; |
||
83 | default: |
||
84 | $result[$claimName] = $value; |
||
85 | } |
||
86 | } |
||
87 | } |
||
88 | } |
||
89 | } |
||
90 | |||
91 | return $result; |
||
92 | } |
||
93 | } |
||
94 |