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