Conditions | 17 |
Paths | 92 |
Total Lines | 30 |
Lines | 6 |
Ratio | 20 % |
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 |
||
35 | public static function mylinks_cleanVars(&$global, $key, $default = '', $type = 'int', $limit = null) |
||
36 | { |
||
37 | switch ($type) { |
||
38 | case 'string': |
||
39 | $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_MAGIC_QUOTES) : $default; |
||
40 | break; |
||
41 | case 'email': |
||
42 | $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_EMAIL) : $default; |
||
43 | break; |
||
44 | case 'url': |
||
45 | $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_URL) : $default; |
||
46 | break; |
||
47 | case 'int': |
||
48 | default: |
||
49 | $default = (int)$default; |
||
50 | $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_NUMBER_INT) : false; |
||
51 | if (isset($limit) && is_array($limit) && (false !== $ret)) { |
||
52 | View Code Duplication | if (array_key_exists('min', $limit)) { |
|
53 | $ret = ($ret >= $limit['min']) ? $ret : false; |
||
54 | } |
||
55 | View Code Duplication | if (array_key_exists('max', $limit)) { |
|
56 | $ret = ($ret <= $limit['max']) ? $ret : false; |
||
57 | } |
||
58 | } |
||
59 | break; |
||
60 | } |
||
61 | $ret = ($ret === false) ? $default : $ret; |
||
62 | |||
63 | return $ret; |
||
64 | } |
||
65 | |||
97 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.