| Conditions | 14 |
| Paths | 5 |
| Total Lines | 91 |
| Code Lines | 47 |
| Lines | 39 |
| Ratio | 42.86 % |
| 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 |
||
| 117 | public function parse(Parser $parser, TokensList $list) |
||
| 118 | { |
||
| 119 | ++$list->idx; // Skipping `REPLACE`. |
||
| 120 | |||
| 121 | // parse any options if provided |
||
| 122 | $this->options = OptionsArray::parse( |
||
| 123 | $parser, |
||
| 124 | $list, |
||
| 125 | static::$OPTIONS |
||
| 126 | ); |
||
| 127 | ++$list->idx; |
||
| 128 | |||
| 129 | $token = $list->tokens[$list->idx]; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * The state of the parser. |
||
| 133 | * |
||
| 134 | * Below are the states of the parser. |
||
| 135 | * |
||
| 136 | * 0 ---------------------------------[ INTO ]----------------------------------> 1 |
||
| 137 | * |
||
| 138 | * 1 -------------------------[ VALUES/VALUE/SET/SELECT ]-----------------------> 2 |
||
| 139 | * |
||
| 140 | * @var int $state |
||
| 141 | */ |
||
| 142 | $state = 0; |
||
| 143 | |||
| 144 | for (; $list->idx < $list->count; ++$list->idx) { |
||
| 145 | /** |
||
| 146 | * Token parsed at this moment. |
||
| 147 | * |
||
| 148 | * @var Token $token |
||
| 149 | */ |
||
| 150 | $token = $list->tokens[$list->idx]; |
||
| 151 | |||
| 152 | // End of statement. |
||
| 153 | if ($token->type === Token::TYPE_DELIMITER) { |
||
| 154 | break; |
||
| 155 | } |
||
| 156 | |||
| 157 | // Skipping whitespaces and comments. |
||
| 158 | if (($token->type === Token::TYPE_WHITESPACE) || ($token->type === Token::TYPE_COMMENT)) { |
||
| 159 | continue; |
||
| 160 | } |
||
| 161 | |||
| 162 | if ($state === 0) { |
||
| 163 | View Code Duplication | if ($token->type === Token::TYPE_KEYWORD |
|
| 164 | && $token->value !== 'INTO' |
||
| 165 | ) { |
||
| 166 | $parser->error(__('Unexpected keyword.'), $token); |
||
| 167 | break; |
||
| 168 | } else { |
||
| 169 | ++$list->idx; |
||
| 170 | $this->into = IntoKeyword::parse($parser, $list); |
||
| 171 | } |
||
| 172 | |||
| 173 | $state = 1; |
||
| 174 | View Code Duplication | } elseif ($state === 1) { |
|
| 175 | if ($token->type === Token::TYPE_KEYWORD) { |
||
| 176 | if ($token->value === 'VALUE' |
||
| 177 | || $token->value === 'VALUES' |
||
| 178 | ) { |
||
| 179 | ++$list->idx; // skip VALUES |
||
| 180 | |||
| 181 | $this->values = Array2d::parse($parser, $list); |
||
| 182 | } elseif ($token->value === 'SET') { |
||
| 183 | ++$list->idx; // skip SET |
||
| 184 | |||
| 185 | $this->set = SetOperation::parse($parser, $list); |
||
| 186 | } elseif ($token->value === 'SELECT') { |
||
| 187 | $this->select = new SelectStatement($parser, $list); |
||
| 188 | } else { |
||
| 189 | $parser->error( |
||
| 190 | __('Unexpected keyword.'), |
||
| 191 | $token |
||
| 192 | ); |
||
| 193 | break; |
||
| 194 | } |
||
| 195 | $state = 2; |
||
| 196 | } else { |
||
| 197 | $parser->error( |
||
| 198 | __('Unexpected token.'), |
||
| 199 | $token |
||
| 200 | ); |
||
| 201 | break; |
||
| 202 | } |
||
| 203 | } |
||
| 204 | } |
||
| 205 | |||
| 206 | --$list->idx; |
||
| 207 | } |
||
| 208 | } |
||
| 209 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: