Conditions | 12 |
Paths | 12 |
Total Lines | 45 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
72 | public function getNextToken(): Token |
||
73 | { |
||
74 | while ($this->currentChar !== null) { |
||
75 | $this->skipWhitespace(); |
||
76 | if ($this->isAlpha($this->currentChar)) { |
||
77 | return $this->identifier(); |
||
78 | } |
||
79 | if ($this->currentChar === ',') { |
||
80 | $this->advance(); |
||
81 | return new Token(Token::COMMA, ','); |
||
82 | } |
||
83 | if ($this->currentChar === '+') { |
||
84 | $this->advance(); |
||
85 | return new Token(Token::PLUS, '+'); |
||
86 | } |
||
87 | if ($this->currentChar === '-') { |
||
88 | $this->advance(); |
||
89 | return new Token(Token::MINUS, '-'); |
||
90 | } |
||
91 | if ($this->currentChar === '^') { |
||
92 | $this->advance(); |
||
93 | return new Token(Token::POWER, '^'); |
||
94 | } |
||
95 | if ($this->currentChar === '*') { |
||
96 | return $this->analyzeAsterisk(); |
||
97 | } |
||
98 | if ($this->currentChar === '/') { |
||
99 | $this->advance(); |
||
100 | return new Token(Token::REALDIV, '/'); |
||
101 | } |
||
102 | if ($this->currentChar === '(') { |
||
103 | $this->advance(); |
||
104 | return new Token(Token::LPAREN, '('); |
||
105 | } |
||
106 | if ($this->currentChar === ')') { |
||
107 | $this->advance(); |
||
108 | return new Token(Token::RPAREN, ')'); |
||
109 | } |
||
110 | |||
111 | if (is_numeric($this->currentChar)) { |
||
112 | return $this->parseNumber(); |
||
113 | } |
||
114 | } |
||
115 | |||
116 | return new Token(Token::EOF, Token::EOF); |
||
117 | } |
||
183 | } |