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