| Conditions | 11 |
| Paths | 11 |
| Total Lines | 45 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 28 | public function resolve($token) |
||
| 29 | { |
||
| 30 | |||
| 31 | if(strlen($token) == 0) { |
||
| 32 | return Token::T_VALUE_VOID; |
||
| 33 | } |
||
| 34 | |||
| 35 | if (in_array($token, array(Token::T_VALUE_BOOLEAN, Token::T_VALUE_FLOAT, Token::T_VALUE_STRING, Token::T_VALUE_INTEGER, Token::T_VALUE_NULL))) { |
||
| 36 | return $token; |
||
| 37 | } |
||
| 38 | |||
| 39 | if(preg_match('!^\d+$!', $token)) { |
||
| 40 | return Token::T_VALUE_INTEGER; |
||
| 41 | } |
||
| 42 | |||
| 43 | if(preg_match('!^\d+\.\d+$!', $token)) { |
||
| 44 | return Token::T_VALUE_FLOAT; |
||
| 45 | } |
||
| 46 | |||
| 47 | if('null' == $token) { |
||
| 48 | return Token::T_VALUE_NULL; |
||
| 49 | } |
||
| 50 | |||
| 51 | if(preg_match('!^\$\w+$!', $token)) { |
||
| 52 | return Token::T_VAR; |
||
| 53 | } |
||
| 54 | |||
| 55 | if(preg_match('!(^\[|^array\()!', $token)) { |
||
| 56 | return Token::T_VALUE_ARRAY; |
||
| 57 | } |
||
| 58 | |||
| 59 | if(preg_match('!^(true|false)!', $token)) { |
||
| 60 | return Token::T_VALUE_BOOLEAN; |
||
| 61 | } |
||
| 62 | |||
| 63 | if(preg_match('!^function!', $token)) { |
||
| 64 | return Token::T_FUNCTION; |
||
| 65 | } |
||
| 66 | |||
| 67 | if(preg_match('!^["\']!', $token)) { |
||
| 68 | return Token::T_VALUE_STRING; |
||
| 69 | } |
||
| 70 | |||
| 71 | return Token::T_VALUE_UNKNWON; |
||
| 72 | } |
||
| 73 | |||
| 92 | } |