| Conditions | 17 |
| Paths | 17 |
| Total Lines | 60 |
| Code Lines | 46 |
| Lines | 15 |
| Ratio | 25 % |
| 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 |
||
| 52 | protected function parse($file) { |
||
| 53 | $tokens = $this->getTokens($file); |
||
| 54 | $currentClass = false; |
||
| 55 | $currentBlock = false; |
||
| 56 | $max = count($tokens); |
||
| 57 | $i = 0; |
||
| 58 | while($i < $max) { |
||
| 59 | $token = $tokens[$i]; |
||
| 60 | if(is_array($token)) { |
||
| 61 | list($code, $value) = $token; |
||
| 62 | switch($code) { |
||
| 63 | case T_DOC_COMMENT: |
||
| 64 | $comment = $value; |
||
| 65 | break; |
||
| 66 | |||
| 67 | case T_CLASS: |
||
| 68 | $class = $this->getString($tokens, $i, $max); |
||
| 69 | if($comment !== false) { |
||
| 70 | self::$classes[$class] = $comment; |
||
| 71 | $comment = false; |
||
| 72 | } |
||
| 73 | break; |
||
| 74 | |||
| 75 | case T_VARIABLE: |
||
| 76 | if($comment !== false) { |
||
| 77 | $field = substr($token[1], 1); |
||
| 78 | self::$fields[$class][$field] = $comment; |
||
| 79 | $comment = false; |
||
| 80 | } |
||
| 81 | break; |
||
| 82 | |||
| 83 | case T_FUNCTION: |
||
| 84 | if($comment !== false) { |
||
| 85 | $function = $this->getString($tokens, $i, $max); |
||
| 86 | self::$methods[$class][$function] = $comment; |
||
| 87 | $comment = false; |
||
| 88 | } |
||
| 89 | |||
| 90 | break; |
||
| 91 | |||
| 92 | // ignore |
||
| 93 | case T_WHITESPACE: |
||
| 94 | case T_PUBLIC: |
||
| 95 | case T_PROTECTED: |
||
| 96 | case T_PRIVATE: |
||
| 97 | case T_ABSTRACT: |
||
| 98 | case T_FINAL: |
||
| 99 | case T_VAR: |
||
| 100 | break; |
||
| 101 | |||
| 102 | default: |
||
| 103 | $comment = false; |
||
| 104 | break; |
||
| 105 | } |
||
| 106 | } else { |
||
| 107 | $comment = false; |
||
| 108 | } |
||
| 109 | $i++; |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 130 |