Conditions | 11 |
Paths | 12 |
Total Lines | 26 |
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 |
||
5 | function checkAllowedIp($remoteAddress) |
||
6 | { |
||
7 | if(in_array($remoteAddress, array('127.0.0.1', 'fe80::1', '::1'), true)) { |
||
8 | return true; |
||
9 | } |
||
10 | $matches = array(); |
||
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 | |||
48 |