| Conditions | 18 |
| Paths | 74 |
| Total Lines | 110 |
| Code Lines | 78 |
| 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 |
||
| 21 | public function match(CharBufferInterface $buffer, TokenFactoryInterface $tokenFactory): bool |
||
| 22 | { |
||
| 23 | $context = $this->createContext($buffer, $tokenFactory); |
||
| 24 | $context->setRegExps( |
||
| 25 | '>', |
||
| 26 | '<', |
||
| 27 | '\\+', |
||
| 28 | '-', |
||
| 29 | '\\.', |
||
| 30 | ',', |
||
| 31 | '\\[', |
||
| 32 | ']' |
||
| 33 | ); |
||
| 34 | goto state1; |
||
| 35 | |||
| 36 | state1: |
||
| 37 | if ($context->getBuffer()->isEnd()) { |
||
| 38 | goto error; |
||
| 39 | } |
||
| 40 | $char = $context->getBuffer()->getSymbol(); |
||
| 41 | if (0x3E == $char) { |
||
| 42 | $context->getBuffer()->nextSymbol(); |
||
| 43 | $context->allowRegExps('>'); |
||
| 44 | goto state2; |
||
| 45 | } |
||
| 46 | if (0x3C == $char) { |
||
| 47 | $context->getBuffer()->nextSymbol(); |
||
| 48 | $context->allowRegExps('<'); |
||
| 49 | goto state2; |
||
| 50 | } |
||
| 51 | if (0x2B == $char) { |
||
| 52 | $context->getBuffer()->nextSymbol(); |
||
| 53 | $context->allowRegExps('\\+'); |
||
| 54 | goto state2; |
||
| 55 | } |
||
| 56 | if (0x2D == $char) { |
||
| 57 | $context->getBuffer()->nextSymbol(); |
||
| 58 | $context->allowRegExps('-'); |
||
| 59 | goto state2; |
||
| 60 | } |
||
| 61 | if (0x2E == $char) { |
||
| 62 | $context->getBuffer()->nextSymbol(); |
||
| 63 | $context->allowRegExps('\\.'); |
||
| 64 | goto state2; |
||
| 65 | } |
||
| 66 | if (0x2C == $char) { |
||
| 67 | $context->getBuffer()->nextSymbol(); |
||
| 68 | $context->allowRegExps(','); |
||
| 69 | goto state2; |
||
| 70 | } |
||
| 71 | if (0x5B == $char) { |
||
| 72 | $context->getBuffer()->nextSymbol(); |
||
| 73 | $context->allowRegExps('\\['); |
||
| 74 | goto state2; |
||
| 75 | } |
||
| 76 | if (0x5D == $char) { |
||
| 77 | $context->getBuffer()->nextSymbol(); |
||
| 78 | $context->allowRegExps(']'); |
||
| 79 | goto state2; |
||
| 80 | } |
||
| 81 | goto error; |
||
| 82 | |||
| 83 | state2: |
||
| 84 | switch ($context->getRegExp()) { |
||
| 85 | case '>': |
||
| 86 | $context->setNewToken(TokenType::NEXT); |
||
| 87 | |||
| 88 | return true; |
||
| 89 | |||
| 90 | case '<': |
||
| 91 | $context->setNewToken(TokenType::PREV); |
||
| 92 | |||
| 93 | return true; |
||
| 94 | |||
| 95 | case '\\+': |
||
| 96 | $context->setNewToken(TokenType::INC); |
||
| 97 | |||
| 98 | return true; |
||
| 99 | |||
| 100 | case '-': |
||
| 101 | $context->setNewToken(TokenType::DEC); |
||
| 102 | |||
| 103 | return true; |
||
| 104 | |||
| 105 | case '\\.': |
||
| 106 | $context->setNewToken(TokenType::OUTPUT); |
||
| 107 | |||
| 108 | return true; |
||
| 109 | |||
| 110 | case ',': |
||
| 111 | $context->setNewToken(TokenType::INPUT); |
||
| 112 | |||
| 113 | return true; |
||
| 114 | |||
| 115 | case '\\[': |
||
| 116 | $context->setNewToken(TokenType::LOOP); |
||
| 117 | |||
| 118 | return true; |
||
| 119 | |||
| 120 | case ']': |
||
| 121 | $context->setNewToken(TokenType::END_LOOP); |
||
| 122 | |||
| 123 | return true; |
||
| 124 | |||
| 125 | default: |
||
| 126 | goto error; |
||
| 127 | } |
||
| 128 | |||
| 129 | error: |
||
| 130 | return false; |
||
| 131 | } |
||
| 133 |