| Conditions | 21 |
| Paths | 40 |
| Total Lines | 57 |
| Code Lines | 44 |
| 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 |
||
| 29 | public static function getSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") |
||
| 30 | { |
||
| 31 | |||
| 32 | $theValue = function_exists("htmlspecialchars") ? htmlspecialchars($theValue) : $theValue; |
||
| 33 | |||
| 34 | switch ($theType) { |
||
| 35 | case "string": |
||
| 36 | if (!is_string($theValue)) { |
||
| 37 | return null; |
||
| 38 | } |
||
| 39 | return strip_tags("$theValue"); |
||
| 40 | case "email": |
||
| 41 | if (!is_string($theValue)) { |
||
| 42 | return null; |
||
| 43 | } |
||
| 44 | return filter_var($theValue, FILTER_VALIDATE_EMAIL); |
||
| 45 | break; |
||
|
|
|||
| 46 | case "long": |
||
| 47 | case "int": |
||
| 48 | if (!is_numeric($theValue)) { |
||
| 49 | return null; |
||
| 50 | } |
||
| 51 | return intval($theValue); |
||
| 52 | break; |
||
| 53 | case "double": |
||
| 54 | if (!is_double($theValue)) { |
||
| 55 | return null; |
||
| 56 | } |
||
| 57 | return floatval($theValue); |
||
| 58 | break; |
||
| 59 | case "date": |
||
| 60 | |||
| 61 | $theValue = ($theValue != "") ? "" . $theValue . "" : null; |
||
| 62 | break; |
||
| 63 | case "url": |
||
| 64 | if (!is_string($theValue)) { |
||
| 65 | return null; |
||
| 66 | } |
||
| 67 | return filter_var($theValue, FILTER_VALIDATE_URL); |
||
| 68 | break; |
||
| 69 | case "domain": |
||
| 70 | if (!is_string($theValue)) { |
||
| 71 | return null; |
||
| 72 | } |
||
| 73 | return filter_var($theValue, FILTER_VALIDATE_DOMAIN); |
||
| 74 | break; |
||
| 75 | case "ip": |
||
| 76 | if (!is_double($theValue)) { |
||
| 77 | return null; |
||
| 78 | } |
||
| 79 | return filter_var($theValue, FILTER_VALIDATE_IP); |
||
| 80 | break; |
||
| 81 | case "defined": |
||
| 82 | $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; |
||
| 83 | break; |
||
| 84 | } |
||
| 85 | return $theValue; |
||
| 86 | } |
||
| 89 | } |
The
breakstatement is not necessary if it is preceded for example by areturnstatement:If you would like to keep this construct to be consistent with other
casestatements, you can safely mark this issue as a false-positive.