Conditions | 14 |
Paths | 12 |
Total Lines | 79 |
Code Lines | 44 |
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( |
||
73 | $parser, |
||
74 | $list, |
||
75 | static::$OPTIONS |
||
76 | ); |
||
77 | ++$list->idx; |
||
78 | |||
79 | $state = 0; |
||
80 | $wither = null; |
||
81 | |||
82 | for (; $list->idx < $list->count; ++$list->idx) { |
||
83 | /** |
||
84 | * Token parsed at this moment. |
||
85 | * |
||
86 | * @var Token |
||
87 | */ |
||
88 | $token = $list->tokens[$list->idx]; |
||
89 | |||
90 | // Skipping whitespaces and comments. |
||
91 | if ($token->type === Token::TYPE_WHITESPACE || $token->type === Token::TYPE_COMMENT) { |
||
92 | continue; |
||
93 | } |
||
94 | |||
95 | if ($token->type === Token::TYPE_NONE) { |
||
96 | $wither = $token->value; |
||
97 | $this->withers[$wither] = new WithKeyword($wither); |
||
98 | $state = 1; |
||
99 | continue; |
||
100 | } |
||
101 | |||
102 | if ($state === 1) { |
||
103 | if ($token->value === '(') { |
||
104 | $this->withers[$wither]->columns = Array2d::parse($parser, $list); |
||
105 | continue; |
||
106 | } |
||
107 | |||
108 | if ($token->keyword === 'AS') { |
||
109 | ++$list->idx; |
||
110 | $state = 2; |
||
111 | continue; |
||
112 | } |
||
113 | } elseif ($state === 2) { |
||
114 | if ($token->value === '(') { |
||
115 | ++$list->idx; |
||
116 | $subList = $this->getSubTokenList($list); |
||
117 | if ($subList instanceof ParserException) { |
||
118 | $parser->errors[] = $subList; |
||
119 | continue; |
||
120 | } |
||
121 | |||
122 | $subParser = new Parser($subList); |
||
123 | |||
124 | if (count($subParser->errors)) { |
||
125 | foreach ($subParser->errors as $error) { |
||
126 | $parser->errors[] = $error; |
||
127 | } |
||
128 | } |
||
129 | |||
130 | $this->withers[$wither]->statement = $subParser; |
||
131 | continue; |
||
132 | } |
||
133 | |||
134 | if ($token->value === ',') { |
||
135 | $list->idx++; |
||
136 | $state = 0; |
||
137 | continue; |
||
138 | } |
||
139 | |||
140 | // nothing else |
||
141 | break; |
||
142 | } |
||
143 | } |
||
144 | |||
145 | --$list->idx; |
||
146 | } |
||
205 |