| Conditions | 33 | 
| Paths | 751 | 
| Total Lines | 126 | 
| Lines | 0 | 
| Ratio | 0 % | 
| 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  | 
            ||
| 160 | protected function doGrammar()  | 
            ||
| 161 |     { | 
            ||
| 162 | $attribute = [];  | 
            ||
| 163 | $buffer = [null];  | 
            ||
| 164 |         $production = new Production('', 0); | 
            ||
| 165 | |||
| 166 | $production->body = [$this->startPrime];  | 
            ||
| 167 | $this->context->addGram($production);  | 
            ||
| 168 | |||
| 169 | $token = $this->lexer->getToken();  | 
            ||
| 170 | |||
| 171 |         while ($token->getType() !== Token::T_MARK && $token->getType() !== Token::T_EOF) { | 
            ||
| 172 |             if ($token->getType() === Token::T_NAME) { | 
            ||
| 173 |                 if ($this->lexer->peek()->getValue()[0] === '@') { | 
            ||
| 174 | $attribute[0] = $token->getValue();  | 
            ||
| 175 | $this->lexer->getToken();  | 
            ||
| 176 | $token = $this->lexer->getToken();  | 
            ||
| 177 |                 } else { | 
            ||
| 178 | $attribute[0] = null;  | 
            ||
| 179 | }  | 
            ||
| 180 | $buffer[0] = $this->context->internSymbol($token->getValue(), false);  | 
            ||
| 181 | $attribute[1] = null;  | 
            ||
| 182 |                 if ($buffer[0]->isTerminal) { | 
            ||
| 183 |                     throw new \RuntimeException("Non terminal symbol expected: $token"); | 
            ||
| 184 |                 } elseif (($tmp = $this->lexer->getToken())->getType() !== Token::T_COLON) { | 
            ||
| 185 |                     throw new \RuntimeException("':' expected, $tmp found"); | 
            ||
| 186 | }  | 
            ||
| 187 |                 if ($this->context->startSymbol === null) { | 
            ||
| 188 | $this->context->startSymbol = $buffer[0];  | 
            ||
| 189 | }  | 
            ||
| 190 |             } elseif ($token->getValue()[0] === '|') { | 
            ||
| 191 |                 if (!$buffer[0]) { | 
            ||
| 192 |                     throw new \RuntimeException("Syntax Error, unexpected $token"); | 
            ||
| 193 | }  | 
            ||
| 194 | $attribute[1] = null;  | 
            ||
| 195 |             } elseif ($token->getType() === Token::T_BEGIN_INC) { | 
            ||
| 196 | $this->doCopy();  | 
            ||
| 197 | $token = $this->lexer->getToken();  | 
            ||
| 198 | continue;  | 
            ||
| 199 |             } else { | 
            ||
| 200 |                 throw new \RuntimeException("Syntax Error, unexpected $token"); | 
            ||
| 201 | }  | 
            ||
| 202 | |||
| 203 | $lastTerm = $this->startPrime;  | 
            ||
| 204 | $action = null;  | 
            ||
| 205 | $pos = 0;  | 
            ||
| 206 | $i = 1;  | 
            ||
| 207 |             while (true) { | 
            ||
| 208 | $token = $this->lexer->getToken();  | 
            ||
| 209 | |||
| 210 |                 if ($token->getValue()[0] === '=') { | 
            ||
| 211 | $pos = $token->getLine();  | 
            ||
| 212 |                     if (($token = $this->lexer->getToken())->getValue()[0] === '{') { | 
            ||
| 213 | $pos = $token->getLine();  | 
            ||
| 214 | $action = $this->copyAction($buffer, $i - 1, '}', $attribute);  | 
            ||
| 215 |                     } else { | 
            ||
| 216 | $this->lexer->ungetToken();  | 
            ||
| 217 | $action = $this->copyAction($buffer, $i - 1, ';', $attribute);  | 
            ||
| 218 | }  | 
            ||
| 219 |                 } elseif ($token->getValue()[0] === '{') { | 
            ||
| 220 | $pos = $token->getLine();  | 
            ||
| 221 | $action = $this->copyAction($buffer, $i - 1, '}', $attribute);  | 
            ||
| 222 |                 } elseif ($token->getType() === Token::T_PRECTOK) { | 
            ||
| 223 | $lastTerm = $this->context->internSymbol($this->lexer->getToken()->getValue(), false);  | 
            ||
| 224 |                 } elseif ($token->getType() === Token::T_NAME && $this->lexer->peek()->getType() === Token::T_COLON) { | 
            ||
| 225 | break;  | 
            ||
| 226 |                 } elseif ($token->getType() === Token::T_NAME && $this->lexer->peek()->getValue()[0] === '@') { | 
            ||
| 227 | $attribute[$i] = $token->getValue();  | 
            ||
| 228 | $this->lexer->getToken();  | 
            ||
| 229 |                 } elseif ($token->getType() === Token::T_NAME || $token->getType() === Token::T_STRING) { | 
            ||
| 230 |                     if ($action) { | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 231 | $g = $this->context->genNonTerminal();  | 
            ||
| 232 | $production = new Production($action, $pos);  | 
            ||
| 233 | $production->body = [$g];  | 
            ||
| 234 | $buffer[$i++] = $g;  | 
            ||
| 235 | $attribute[$i] = null;  | 
            ||
| 236 | $production->link = $production->body[0]->value;  | 
            ||
| 237 | $g->value = $this->context->addGram($production);  | 
            ||
| 238 | }  | 
            ||
| 239 | $buffer[$i++] = $w = $this->context->internSymbol($token->getValue(), false);  | 
            ||
| 240 | $attribute[$i] = null;  | 
            ||
| 241 |                     if ($w->isTerminal) { | 
            ||
| 242 | $lastTerm = $w;  | 
            ||
| 243 | }  | 
            ||
| 244 | $action = null;  | 
            ||
| 245 |                 } else { | 
            ||
| 246 | break;  | 
            ||
| 247 | }  | 
            ||
| 248 | }  | 
            ||
| 249 |             if (!$action) { | 
            ||
| 250 |                 if ($i > 1 && $buffer[0]->type !== null && $buffer[0]->type !== $buffer[1]->type) { | 
            ||
| 251 |                     throw new ParseException('Stack types are different'); | 
            ||
| 252 | }  | 
            ||
| 253 | }  | 
            ||
| 254 | $production = new Production($action, $pos);  | 
            ||
| 255 | |||
| 256 | $production->body = \array_slice($buffer, 0, $i);  | 
            ||
| 257 | $production->precedence = $lastTerm->precedence;  | 
            ||
| 258 | $production->associativity = $lastTerm->associativity & Symbol::MASK;  | 
            ||
| 259 | $production->link = $production->body[0]->value;  | 
            ||
| 260 | $buffer[0]->value = $this->context->addGram($production);  | 
            ||
| 261 | |||
| 262 |             if ($token->getType() === Token::T_SEMICOLON) { | 
            ||
| 263 | $token = $this->lexer->getToken();  | 
            ||
| 264 | }  | 
            ||
| 265 | }  | 
            ||
| 266 | |||
| 267 | $this->context->gram(0)->body[] = $this->context->startSymbol;  | 
            ||
| 268 | $this->startPrime->value = null;  | 
            ||
| 269 |         foreach ($this->context->nonterminals as $key => $symbol) { | 
            ||
| 270 |             if ($symbol === $this->startPrime) { | 
            ||
| 271 | continue;  | 
            ||
| 272 | }  | 
            ||
| 273 |             if (($j = $symbol->value) === null) { | 
            ||
| 274 |                 throw new ParseException("Non terminal {$symbol->name} used, but not defined"); | 
            ||
| 275 | }  | 
            ||
| 276 | $k = null;  | 
            ||
| 277 |             while ($j) { | 
            ||
| 278 | $w = $j->link;  | 
            ||
| 279 | $j->link = $k;  | 
            ||
| 280 | $k = $j;  | 
            ||
| 281 | $j = $w;  | 
            ||
| 282 | }  | 
            ||
| 283 | $symbol->value = $k;  | 
            ||
| 284 | }  | 
            ||
| 285 | }  | 
            ||
| 286 | |||
| 474 | 
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: