| Conditions | 13 |
| Paths | 46 |
| Total Lines | 31 |
| Code Lines | 19 |
| 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 if (!defined('BB2_CORE')) die('I said no cheating!'); |
||
| 3 | function bb2_run_whitelist($package) |
||
| 4 | { |
||
| 5 | # FIXME: Transitional, until port maintainters implement bb2_read_whitelist |
||
| 6 | if (function_exists('bb2_read_whitelist')) { |
||
| 7 | $whitelists = bb2_read_whitelist(); |
||
| 8 | } else { |
||
| 9 | $whitelists = @parse_ini_file(dirname(BB2_CORE) . "/whitelist.ini"); |
||
| 10 | } |
||
| 11 | |||
| 12 | if (@!empty($whitelists['ip'])) { |
||
| 13 | foreach (array_filter($whitelists['ip']) as $range) { |
||
| 14 | if (match_cidr($package['ip'], $range)) return true; |
||
| 15 | } |
||
| 16 | } |
||
| 17 | if (@!empty($whitelists['useragent'])) { |
||
| 18 | foreach (array_filter($whitelists['useragent']) as $user_agent) { |
||
| 19 | if (!strcmp($package['headers_mixed']['User-Agent'], $user_agent)) return true; |
||
| 20 | } |
||
| 21 | } |
||
| 22 | if (@!empty($whitelists['url'])) { |
||
| 23 | if (strpos($package['request_uri'], "?") === FALSE) { |
||
| 24 | $request_uri = $package['request_uri']; |
||
| 25 | } else { |
||
| 26 | $request_uri = substr($package['request_uri'], 0, strpos($package['request_uri'], "?")); |
||
| 27 | } |
||
| 28 | foreach (array_filter($whitelists['url']) as $url) { |
||
| 29 | $pos = strpos($request_uri, $url); |
||
| 30 | if ($pos !== false && $pos == 0) return true; |
||
| 31 | } |
||
| 32 | } |
||
| 33 | return false; |
||
| 34 | } |
||
| 35 |