| Conditions | 20 |
| Paths | 20 |
| Total Lines | 42 |
| Code Lines | 32 |
| 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 |
||
| 52 | public function calculate($filename) |
||
| 53 | { |
||
| 54 | |||
| 55 | $info = new Result; |
||
| 56 | $tokens = $this->tokenizer->tokenize($filename); |
||
| 57 | |||
| 58 | $ccn = 1; // default path |
||
| 59 | foreach($tokens as $token) { |
||
| 60 | |||
| 61 | switch($token->getType()) { |
||
| 62 | case T_IF: |
||
| 63 | case T_ELSEIF: |
||
| 64 | case T_FOREACH: |
||
| 65 | case T_FOR: |
||
| 66 | case T_WHILE: |
||
| 67 | case T_DO: |
||
| 68 | case T_BOOLEAN_AND: |
||
| 69 | case T_LOGICAL_AND: |
||
| 70 | case T_BOOLEAN_OR: |
||
| 71 | case T_LOGICAL_OR: |
||
| 72 | case T_SPACESHIP: |
||
| 73 | case T_CASE: |
||
| 74 | case T_DEFAULT: |
||
| 75 | case T_CATCH: |
||
| 76 | case T_CONTINUE: |
||
| 77 | $ccn++; |
||
| 78 | break; |
||
| 79 | case T_STRING: |
||
| 80 | if('?' == $token->getValue()) { |
||
| 81 | $ccn = $ccn + 2; |
||
| 82 | } |
||
| 83 | break; |
||
| 84 | case T_COALESCE: |
||
| 85 | $ccn = $ccn + 2; |
||
| 86 | break; |
||
| 87 | } |
||
| 88 | |||
| 89 | } |
||
| 90 | |||
| 91 | $info->setCyclomaticComplexityNumber(max(1, $ccn)); |
||
| 92 | return $info; |
||
| 93 | } |
||
| 94 | } |