| Conditions | 15 |
| Paths | 9 |
| Total Lines | 44 |
| Code Lines | 37 |
| 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 |
||
| 83 | public function parseUseStatement() |
||
| 84 | { |
||
| 85 | |||
| 86 | $groupRoot = ''; |
||
| 87 | $class = ''; |
||
| 88 | $alias = ''; |
||
| 89 | $statements = []; |
||
| 90 | $explicitAlias = false; |
||
| 91 | while (($token = $this->next())) { |
||
| 92 | if (!$explicitAlias && $token[0] === T_STRING) { |
||
| 93 | $class .= $token[1]; |
||
| 94 | $alias = $token[1]; |
||
| 95 | } else if ($explicitAlias && $token[0] === T_STRING) { |
||
| 96 | $alias = $token[1]; |
||
| 97 | } else if (\PHP_VERSION_ID >= 80000 && ($token[0] === T_NAME_QUALIFIED || $token[0] === T_NAME_FULLY_QUALIFIED)) { |
||
| 98 | $class .= $token[1]; |
||
| 99 | |||
| 100 | $classSplit = explode('\\', $token[1]); |
||
| 101 | $alias = $classSplit[count($classSplit) - 1]; |
||
| 102 | } else if ($token[0] === T_NS_SEPARATOR) { |
||
| 103 | $class .= '\\'; |
||
| 104 | $alias = ''; |
||
| 105 | } else if ($token[0] === T_AS) { |
||
| 106 | $explicitAlias = true; |
||
| 107 | $alias = ''; |
||
| 108 | } else if ($token === ',') { |
||
| 109 | $statements[strtolower($alias)] = $groupRoot . $class; |
||
| 110 | $class = ''; |
||
| 111 | $alias = ''; |
||
| 112 | $explicitAlias = false; |
||
| 113 | } else if ($token === ';') { |
||
| 114 | $statements[strtolower($alias)] = $groupRoot . $class; |
||
| 115 | break; |
||
| 116 | } else if ($token === '{' ) { |
||
| 117 | $groupRoot = $class; |
||
| 118 | $class = ''; |
||
| 119 | } else if ($token === '}' ) { |
||
| 120 | continue; |
||
| 121 | } else { |
||
| 122 | break; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | return $statements; |
||
| 127 | } |
||
| 188 |