| 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 | } |
||
| 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 | |||
| 79 | /** |
||
| 80 | * Strip quotes. |
||
| 81 | * |
||
| 82 | * @param string $value |
||
| 83 | * |
||
| 84 | * @return string |
||
| 85 | */ |
||
| 86 | private static function stripQuotes($value) |
||
| 87 | { |
||
| 88 | if ( |
||
| 89 | ($value[0] === '"' && substr($value, -1) === '"') |
||
| 90 | || ($value[0] === "'" && substr($value, -1) === "'") |
||
| 91 | ) { |
||
| 92 | return substr($value, 1, -1); |
||
| 93 | } |
||
| 98 |