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 |
||
66 | * @return mixed |
||
67 | */ |
||
68 | public static function convert($value, $options = null) |
||
69 | { |
||
70 | if ($options === null) { |
||
71 | $options = self::$options; |
||
72 | } |
||
73 | |||
74 | switch (strtolower($value)) { |
||
75 | case 'true': |
||
76 | return ($options & self::CONVERT_BOOL) ? true : $value; |
||
77 | |||
78 | case 'false': |
||
79 | return ($options & self::CONVERT_BOOL) ? false : $value; |
||
80 | |||
81 | case 'null': |
||
82 | return ($options & self::CONVERT_NULL) ? null : $value; |
||
83 | } |
||
84 | |||
85 | if (($options & self::CONVERT_INT) && ctype_digit($value)) { |
||
86 | return (int) $value; |
||
87 | } |
||
88 | |||
89 | if (($options & self::STRIP_QUOTES) && !empty($value)) { |
||
90 | return self::stripQuotes($value); |
||
91 | } |
||
92 | |||
93 | return $value; |
||
115 |