Conditions | 23 |
Paths | 32 |
Total Lines | 68 |
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 |
||
35 | public static function parseUseStatements($tokens, $forClass = null) |
||
36 | { |
||
37 | $namespace = $class = $classLevel = $level = null; |
||
38 | $output = $uses = []; |
||
39 | while ($token = \current($tokens)) { |
||
40 | \next($tokens); |
||
41 | switch (\is_array($token) ? $token[0] : $token) { |
||
42 | case T_NAMESPACE: |
||
43 | $namespace = ltrim(self::FetchNS($tokens).'\\', '\\'); |
||
44 | $uses = []; |
||
45 | break; |
||
46 | |||
47 | case T_CLASS: |
||
48 | case T_INTERFACE: |
||
49 | case T_TRAIT: |
||
50 | if ($name = self::fetch($tokens, T_STRING)) { |
||
51 | $class = $namespace.$name; |
||
52 | $classLevel = $level + 1; |
||
53 | $output[$class] = $uses; |
||
54 | if ($class === $forClass) { |
||
55 | return [$output, $uses]; |
||
56 | } |
||
57 | } |
||
58 | break; |
||
59 | |||
60 | case T_USE: |
||
61 | while (! $class && ($name = self::FetchNS($tokens))) { |
||
62 | $name = ltrim($name, '\\'); |
||
63 | if (self::fetch($tokens, '{')) { |
||
64 | while ($suffix = self::FetchNS($tokens)) { |
||
65 | if (self::fetch($tokens, T_AS)) { |
||
66 | $uses[self::fetch($tokens, T_STRING)] = [$name.$suffix, $token[2]]; |
||
67 | } else { |
||
68 | $tmp = \explode('\\', $suffix); |
||
69 | $uses[end($tmp)] = [$name.$suffix, $token[2]]; |
||
70 | } |
||
71 | if (! self::fetch($tokens, ',')) { |
||
72 | break; |
||
73 | } |
||
74 | } |
||
75 | } elseif (self::fetch($tokens, T_AS)) { |
||
76 | $uses[self::fetch($tokens, T_STRING)] = [$name, $token[2]]; |
||
77 | } else { |
||
78 | $tmp = \explode('\\', $name); |
||
79 | $uses[\end($tmp)] = [$name, $token[2]]; |
||
80 | } |
||
81 | if (! self::fetch($tokens, ',')) { |
||
82 | break; |
||
83 | } |
||
84 | } |
||
85 | break; |
||
86 | |||
87 | case T_CURLY_OPEN: |
||
88 | case T_DOLLAR_OPEN_CURLY_BRACES: |
||
89 | case '{': |
||
90 | $level++; |
||
91 | break; |
||
92 | |||
93 | case '}': |
||
94 | if ($level === $classLevel) { |
||
95 | $class = $classLevel = null; |
||
96 | } |
||
97 | $level--; |
||
98 | } |
||
99 | } |
||
100 | |||
101 | return [$output, $uses]; |
||
102 | } |
||
103 | |||
143 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.