Conditions | 12 |
Paths | 18 |
Total Lines | 27 |
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 |
||
51 | public static function convert($value, $options = null) |
||
52 | { |
||
53 | if ($options === null) { |
||
54 | $options = self::$options; |
||
55 | } |
||
56 | |||
57 | switch (strtolower($value)) { |
||
58 | case 'true': |
||
59 | return ($options & self::CONVERT_BOOL) ? true : $value; |
||
60 | |||
61 | case 'false': |
||
62 | return ($options & self::CONVERT_BOOL) ? false : $value; |
||
63 | |||
64 | case 'null': |
||
65 | return ($options & self::CONVERT_NULL) ? null : $value; |
||
66 | } |
||
67 | |||
68 | if (($options & self::CONVERT_INT) && ctype_digit($value)) { |
||
69 | return (int) $value; |
||
70 | } |
||
71 | |||
72 | if (($options & self::STRIP_QUOTES) && !empty($value)) { |
||
73 | return self::stripQuotes($value); |
||
74 | } |
||
75 | |||
76 | return $value; |
||
77 | } |
||
78 | |||
98 |