| Conditions | 14 |
| Paths | 24 |
| Total Lines | 58 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 70 | public function getNextToken(): Token |
||
| 71 | { |
||
| 72 | while ($this->currentChar !== null) { |
||
| 73 | if ($this->isAlpha($this->currentChar)) { |
||
| 74 | return $this->identifier(); |
||
| 75 | } |
||
| 76 | |||
| 77 | if ($this->currentChar === ' ') { |
||
| 78 | $this->skipWhitespace(); |
||
| 79 | } |
||
| 80 | |||
| 81 | if ($this->currentChar === ',') { |
||
| 82 | $this->advance(); |
||
| 83 | return new Token(Token::COMMA, ','); |
||
| 84 | } |
||
| 85 | |||
| 86 | if ($this->currentChar === '+') { |
||
| 87 | $this->advance(); |
||
| 88 | return new Token(Token::PLUS, '+'); |
||
| 89 | } |
||
| 90 | if ($this->currentChar === '-') { |
||
| 91 | $this->advance(); |
||
| 92 | return new Token(Token::MINUS, '-'); |
||
| 93 | } |
||
| 94 | if ($this->currentChar === '^') { |
||
| 95 | $this->advance(); |
||
| 96 | return new Token(Token::POWER, '^'); |
||
| 97 | } |
||
| 98 | if ($this->currentChar === '*') { |
||
| 99 | if ($this->peek() === '*') { |
||
| 100 | $this->advance(); |
||
| 101 | $this->advance(); |
||
| 102 | return new Token(Token::POWER, '**'); |
||
| 103 | } |
||
| 104 | |||
| 105 | $this->advance(); |
||
| 106 | return new Token(Token::MUL, '*'); |
||
| 107 | } |
||
| 108 | if ($this->currentChar === '/') { |
||
| 109 | $this->advance(); |
||
| 110 | return new Token(Token::REALDIV, '/'); |
||
| 111 | } |
||
| 112 | |||
| 113 | if ($this->currentChar === '(') { |
||
| 114 | $this->advance(); |
||
| 115 | return new Token(Token::LPAREN, '('); |
||
| 116 | } |
||
| 117 | if ($this->currentChar === ')') { |
||
| 118 | $this->advance(); |
||
| 119 | return new Token(Token::RPAREN, ')'); |
||
| 120 | } |
||
| 121 | |||
| 122 | if (is_numeric($this->currentChar)) { |
||
| 123 | return $this->parseNumber(); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | return new Token(Token::EOF, Token::EOF); |
||
| 128 | } |
||
| 179 | } |