| Conditions | 11 |
| Paths | 12 |
| Total Lines | 28 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 3 | function checkAllowedIp($remoteAddress) |
||
| 4 | { |
||
| 5 | if(in_array($remoteAddress, array('127.0.0.1', 'fe80::1', '::1'))) { |
||
| 6 | return true; |
||
| 7 | } |
||
| 8 | |||
| 9 | $matches = array(); |
||
| 10 | |||
| 11 | // http://en.wikipedia.org/wiki/Private_network |
||
| 12 | if(preg_match('/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/', $remoteAddress, $matches) === 1) { |
||
| 13 | for($i=1;$i<5;$i++) { |
||
| 14 | $matches[$i] = (int) $matches[$i]; |
||
| 15 | } |
||
| 16 | // localhost |
||
| 17 | if($matches[1] === 127) { |
||
| 18 | return true; |
||
| 19 | } |
||
| 20 | if($matches[1] === 10) { |
||
| 21 | return true; |
||
| 22 | } |
||
| 23 | if($matches[1] === 172 && $matches[2] >= 16 && $matches[2] <= 31) { |
||
| 24 | return true; |
||
| 25 | } |
||
| 26 | if($matches[1] === 192 && $matches[2] === 168) { |
||
| 27 | return true; |
||
| 28 | } |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 49 |