| Conditions | 10 |
| Paths | 24 |
| Total Lines | 47 |
| 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 |
||
| 21 | public static function readClassDefinition($tokens) |
||
| 22 | { |
||
| 23 | $type = $class = null; |
||
| 24 | $allTokensCount = \count($tokens); |
||
| 25 | $parent = null; |
||
| 26 | $interfaces = $namespace = ''; |
||
| 27 | |||
| 28 | for ($i = 1; $i < $allTokensCount; $i++) { |
||
| 29 | if (! $namespace) { |
||
| 30 | [$i, $namespace,] = self::collectAfterKeyword($tokens, $i, T_NAMESPACE); |
||
| 31 | } |
||
| 32 | |||
| 33 | // if we reach a double colon before a class keyword |
||
| 34 | // it means that, it is not a psr-4 class. |
||
| 35 | if (! $class && $tokens[$i][0] == T_DOUBLE_COLON) { |
||
| 36 | return [$namespace, null, null, null, null]; |
||
| 37 | } |
||
| 38 | |||
| 39 | // when we reach the first "class", or "interface" or "trait" keyword |
||
| 40 | if (! $class && \in_array($tokens[$i][0], [T_CLASS, T_INTERFACE, T_TRAIT])) { |
||
| 41 | $class = $tokens[$i + 2][1]; |
||
| 42 | $type = $tokens[$i][0]; |
||
| 43 | $i = $i + 2; |
||
| 44 | continue; |
||
| 45 | } |
||
| 46 | |||
| 47 | if (! $parent) { |
||
| 48 | [$i, $parent] = self::collectAfterKeyword($tokens, $i, T_EXTENDS, [T_IMPLEMENTS], ','); |
||
| 49 | } |
||
| 50 | |||
| 51 | if (! $interfaces) { |
||
| 52 | [$i, $interfaces] = self::collectAfterKeyword($tokens, $i, T_IMPLEMENTS, [], ','); |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 56 | if ($class == 'extends') { |
||
| 57 | $class = null; |
||
| 58 | } |
||
| 59 | |||
| 60 | return [ |
||
| 61 | \ltrim($namespace, '\\'), |
||
| 62 | $class, |
||
| 63 | $type, |
||
| 64 | $parent, |
||
| 65 | $interfaces, |
||
| 66 | ]; |
||
| 67 | } |
||
| 68 | |||
| 116 |