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