| Conditions | 12 |
| Paths | 36 |
| Total Lines | 57 |
| Code Lines | 34 |
| 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 |
||
| 88 | public static function locateArguments(array $tokens): array |
||
| 89 | { |
||
| 90 | $definition = null; |
||
| 91 | $level = 0; |
||
| 92 | |||
| 93 | $result = []; |
||
| 94 | foreach ($tokens as $token) { |
||
| 95 | if ($token[ReflectionFile::TOKEN_TYPE] == T_WHITESPACE) { |
||
| 96 | continue; |
||
| 97 | } |
||
| 98 | |||
| 99 | if (empty($definition)) { |
||
| 100 | $definition = ['type' => self::EXPRESSION, 'value' => '', 'tokens' => []]; |
||
| 101 | } |
||
| 102 | |||
| 103 | if ( |
||
| 104 | $token[ReflectionFile::TOKEN_TYPE] == '(' |
||
| 105 | || $token[ReflectionFile::TOKEN_TYPE] == '[' |
||
| 106 | ) { |
||
| 107 | ++$level; |
||
| 108 | $definition['value'] .= $token[ReflectionFile::TOKEN_CODE]; |
||
| 109 | continue; |
||
| 110 | } |
||
| 111 | |||
| 112 | if ( |
||
| 113 | $token[ReflectionFile::TOKEN_TYPE] == ')' |
||
| 114 | || $token[ReflectionFile::TOKEN_TYPE] == ']' |
||
| 115 | ) { |
||
| 116 | --$level; |
||
| 117 | $definition['value'] .= $token[ReflectionFile::TOKEN_CODE]; |
||
| 118 | continue; |
||
| 119 | } |
||
| 120 | |||
| 121 | if ($level) { |
||
| 122 | $definition['value'] .= $token[ReflectionFile::TOKEN_CODE]; |
||
| 123 | continue; |
||
| 124 | } |
||
| 125 | |||
| 126 | if ($token[ReflectionFile::TOKEN_TYPE] == ',') { |
||
| 127 | $result[] = self::createArgument($definition); |
||
| 128 | $definition = null; |
||
| 129 | continue; |
||
| 130 | } |
||
| 131 | |||
| 132 | $definition['tokens'][] = $token; |
||
| 133 | $definition['value'] .= $token[ReflectionFile::TOKEN_CODE]; |
||
| 134 | } |
||
| 135 | |||
| 136 | //Last argument |
||
| 137 | if (is_array($definition)) { |
||
| 138 | $definition = self::createArgument($definition); |
||
| 139 | if (!empty($definition->getType())) { |
||
| 140 | $result[] = $definition; |
||
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 144 | return $result; |
||
| 145 | } |
||
| 177 |