Conditions | 14 |
Paths | 12 |
Total Lines | 87 |
Code Lines | 41 |
Lines | 0 |
Ratio | 0 % |
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 |
||
67 | public function parse(Parser $parser, TokensList $list) |
||
68 | { |
||
69 | ++$list->idx; // Skipping `WITH`. |
||
70 | |||
71 | // parse any options if provided |
||
72 | $this->options = OptionsArray::parse($parser, $list, static::$OPTIONS); |
||
73 | ++$list->idx; |
||
74 | |||
75 | /** |
||
76 | * The state of the parser. |
||
77 | * |
||
78 | * Below are the states of the parser. |
||
79 | * |
||
80 | * 0 ---------------- [ name ] -----------------> 1 |
||
81 | * 1 -------------- [( columns )] AS ----------------> 2 |
||
82 | * 2 ------------------ [ , ] --------------------> 0 |
||
83 | * |
||
84 | * @var int |
||
85 | */ |
||
86 | $state = 0; |
||
87 | $wither = null; |
||
88 | |||
89 | for (; $list->idx < $list->count; ++$list->idx) { |
||
90 | /** |
||
91 | * Token parsed at this moment. |
||
92 | * |
||
93 | * @var Token |
||
94 | */ |
||
95 | $token = $list->tokens[$list->idx]; |
||
96 | |||
97 | // Skipping whitespaces and comments. |
||
98 | if ($token->type === Token::TYPE_WHITESPACE || $token->type === Token::TYPE_COMMENT) { |
||
99 | continue; |
||
100 | } |
||
101 | |||
102 | if ($token->type === Token::TYPE_NONE) { |
||
103 | $wither = $token->value; |
||
104 | $this->withers[$wither] = new WithKeyword($wither); |
||
105 | $state = 1; |
||
106 | continue; |
||
107 | } |
||
108 | |||
109 | if ($state === 1) { |
||
110 | if ($token->value === '(') { |
||
111 | $this->withers[$wither]->columns = Array2d::parse($parser, $list); |
||
112 | continue; |
||
113 | } |
||
114 | |||
115 | if ($token->keyword === 'AS') { |
||
116 | ++$list->idx; |
||
117 | $state = 2; |
||
118 | continue; |
||
119 | } |
||
120 | } elseif ($state === 2) { |
||
121 | if ($token->value === '(') { |
||
122 | ++$list->idx; |
||
123 | $subList = $this->getSubTokenList($list); |
||
124 | if ($subList instanceof ParserException) { |
||
125 | $parser->errors[] = $subList; |
||
126 | continue; |
||
127 | } |
||
128 | |||
129 | $subParser = new Parser($subList); |
||
130 | |||
131 | if (count($subParser->errors)) { |
||
132 | foreach ($subParser->errors as $error) { |
||
133 | $parser->errors[] = $error; |
||
134 | } |
||
135 | } |
||
136 | |||
137 | $this->withers[$wither]->statement = $subParser; |
||
138 | continue; |
||
139 | } |
||
140 | |||
141 | // There's another WITH expression to parse, go back to state=0 |
||
142 | if ($token->value === ',') { |
||
143 | $list->idx++; |
||
144 | $state = 0; |
||
145 | continue; |
||
146 | } |
||
147 | |||
148 | // No more WITH expressions, we're done with this statement |
||
149 | break; |
||
150 | } |
||
151 | } |
||
152 | |||
153 | --$list->idx; |
||
154 | } |
||
215 |