Conditions | 12 |
Paths | 11 |
Total Lines | 31 |
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 |
||
30 | public static function format($param) |
||
31 | { |
||
32 | if (is_int($param) || is_float($param)) { |
||
33 | return $param; |
||
34 | |||
35 | } elseif (is_string($param)) { |
||
36 | return "'" . addslashes($param) . "'"; |
||
37 | |||
38 | } elseif (is_null($param)) { |
||
39 | return "NULL"; |
||
40 | |||
41 | } elseif (is_bool($param)) { |
||
42 | return $param ? "TRUE" : "FALSE"; |
||
43 | |||
44 | } elseif (is_array($param)) { |
||
45 | $formatted = []; |
||
46 | foreach ($param as $value) { |
||
47 | $formatted[] = self::format($value); |
||
48 | } |
||
49 | return implode(', ', $formatted); |
||
50 | |||
51 | } elseif ($param instanceof \DateTime) { |
||
52 | return "'" . $param->format('Y-m-d H:i:s') . "'"; |
||
53 | |||
54 | } elseif (is_object($param)) { |
||
55 | return get_class($param) . (method_exists($param, 'getId') ? '(' . $param->getId() . ')' : ''); |
||
56 | |||
57 | } else { |
||
58 | return @"'$param'"; |
||
59 | } |
||
60 | } |
||
61 | |||
63 |