| Conditions | 10 |
| Paths | 10 |
| Total Lines | 70 |
| Code Lines | 42 |
| 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 |
||
| 20 | public function match(CharBufferInterface $buffer, TokenFactoryInterface $tokenFactory): bool |
||
| 21 | { |
||
| 22 | $context = $this->createContext($buffer, $tokenFactory); |
||
| 23 | goto state1; |
||
| 24 | |||
| 25 | state1: |
||
| 26 | if ($context->getBuffer()->isEnd()) { |
||
| 27 | goto error; |
||
| 28 | } |
||
| 29 | $char = $context->getBuffer()->getSymbol(); |
||
| 30 | if (0x3E == $char) { |
||
| 31 | $context->getBuffer()->nextSymbol(); |
||
| 32 | // > |
||
| 33 | $context->setNewToken(TokenType::NEXT); |
||
| 34 | |||
| 35 | return true; |
||
| 36 | } |
||
| 37 | if (0x3C == $char) { |
||
| 38 | $context->getBuffer()->nextSymbol(); |
||
| 39 | // < |
||
| 40 | $context->setNewToken(TokenType::PREV); |
||
| 41 | |||
| 42 | return true; |
||
| 43 | } |
||
| 44 | if (0x2B == $char) { |
||
| 45 | $context->getBuffer()->nextSymbol(); |
||
| 46 | // \+ |
||
| 47 | $context->setNewToken(TokenType::INC); |
||
| 48 | |||
| 49 | return true; |
||
| 50 | } |
||
| 51 | if (0x2D == $char) { |
||
| 52 | $context->getBuffer()->nextSymbol(); |
||
| 53 | // - |
||
| 54 | $context->setNewToken(TokenType::DEC); |
||
| 55 | |||
| 56 | return true; |
||
| 57 | } |
||
| 58 | if (0x2E == $char) { |
||
| 59 | $context->getBuffer()->nextSymbol(); |
||
| 60 | // \. |
||
| 61 | $context->setNewToken(TokenType::OUTPUT); |
||
| 62 | |||
| 63 | return true; |
||
| 64 | } |
||
| 65 | if (0x2C == $char) { |
||
| 66 | $context->getBuffer()->nextSymbol(); |
||
| 67 | // , |
||
| 68 | $context->setNewToken(TokenType::INPUT); |
||
| 69 | |||
| 70 | return true; |
||
| 71 | } |
||
| 72 | if (0x5B == $char) { |
||
| 73 | $context->getBuffer()->nextSymbol(); |
||
| 74 | // \[ |
||
| 75 | $context->setNewToken(TokenType::LOOP); |
||
| 76 | |||
| 77 | return true; |
||
| 78 | } |
||
| 79 | if (0x5D == $char) { |
||
| 80 | $context->getBuffer()->nextSymbol(); |
||
| 81 | // ] |
||
| 82 | $context->setNewToken(TokenType::END_LOOP); |
||
| 83 | |||
| 84 | return true; |
||
| 85 | } |
||
| 86 | goto error; |
||
| 87 | |||
| 88 | error: |
||
| 89 | return false; |
||
| 90 | } |
||
| 92 |