| Conditions | 10 |
| Paths | 10 |
| Total Lines | 20 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 27 | public static function getProcessCount($prefix) |
||
| 28 | { |
||
| 29 | switch ($prefix) { |
||
| 30 | case 32: // 1 IP |
||
| 31 | case 31: // 2 IPs |
||
| 32 | throw new RuntimeException('not enough available IPs in range'); |
||
| 33 | case 30: // 4 IPs (1 usable for client, no splitting) |
||
| 34 | case 29: // 8 IPs (5 usable for clients, no splitting) |
||
| 35 | return 1; |
||
| 36 | case 28: // 16 IPs (12 usable for clients) |
||
|
|
|||
| 37 | case 27: // 32 IPs |
||
| 38 | case 26: // 64 IPs |
||
| 39 | case 25: // 128 IPs |
||
| 40 | return 2; |
||
| 41 | case 24: |
||
| 42 | return 4; |
||
| 43 | } |
||
| 44 | |||
| 45 | return 8; |
||
| 46 | } |
||
| 47 | } |
||
| 48 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.