| Conditions | 10 |
| Paths | 10 |
| Total Lines | 18 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 9 | public function checkLink($href) |
||
| 10 | { |
||
| 11 | switch ($href) { |
||
| 12 | case 'http://www.working.com': |
||
| 13 | return 200; |
||
| 14 | case 'http://www.broken.com': |
||
| 15 | return 403; |
||
| 16 | case 'http://www.nodomain.com': |
||
| 17 | return 0; |
||
| 18 | case '/internal/link': |
||
| 19 | case '[sitetree_link,id=9999]': |
||
| 20 | case 'home': |
||
| 21 | case 'broken-internal': |
||
| 22 | case '[sitetree_link,id=1]': |
||
| 23 | return null; |
||
| 24 | case 'http://www.broken.com/url/thing': |
||
| 25 | default: |
||
| 26 | return 404; |
||
| 27 | } |
||
| 30 |