| Conditions | 12 |
| Paths | 11 |
| Total Lines | 39 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 24 |
| CRAP Score | 12.0654 |
| 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 |
||
| 29 | 44 | private function normalizeUse(array $tokens): array |
|
| 30 | { |
||
| 31 | 44 | $commonNamespace = '\\'; |
|
| 32 | 44 | $current = ''; |
|
| 33 | 44 | $alias = null; |
|
| 34 | 44 | $uses = []; |
|
| 35 | |||
| 36 | 44 | foreach ($tokens as $token) { |
|
| 37 | 44 | if (!isset($token[0])) { |
|
| 38 | continue; |
||
| 39 | } |
||
| 40 | 44 | if ($token[0] === T_STRING || $token[0] === T_NS_SEPARATOR) { |
|
| 41 | 44 | $current .= $token[1]; |
|
| 42 | 44 | continue; |
|
| 43 | } |
||
| 44 | 44 | if ($token === ',' || $token === ';') { |
|
| 45 | 44 | if ($current !== '') { |
|
| 46 | 44 | if ($alias === null) { |
|
| 47 | 44 | $uses[] = $commonNamespace . $current; |
|
| 48 | } else { |
||
| 49 | $uses[$alias] = $commonNamespace . $current; |
||
| 50 | } |
||
| 51 | 44 | $current = ''; |
|
| 52 | } |
||
| 53 | } |
||
| 54 | 44 | if ($token === ';') { |
|
| 55 | 44 | break; |
|
| 56 | } |
||
| 57 | 44 | if ($token === '{') { |
|
| 58 | 1 | $commonNamespace .= $current; |
|
| 59 | 1 | $current = ''; |
|
| 60 | 1 | continue; |
|
| 61 | } |
||
| 62 | 44 | if ($token[0] === T_AS) { |
|
| 63 | 41 | $current .= '@'; |
|
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 67 | 44 | return $this->replaceAliases($uses); |
|
| 68 | } |
||
| 86 |