| Conditions | 11 |
| Paths | 16 |
| Total Lines | 27 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 14 |
| CRAP Score | 11 |
| 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 |
||
| 25 | 32 | public static function formatValue($value, bool $addQuotes = true) |
|
| 26 | { |
||
| 27 | 32 | if ($value instanceof DateTimeInterface) { |
|
| 28 | 2 | $value = $value->format('Y-m-d H:i:s'); |
|
| 29 | } |
||
| 30 | |||
| 31 | 32 | if (is_float($value) || is_int($value) || is_bool($value) || $value === null) { |
|
| 32 | 18 | return $value; |
|
| 33 | } |
||
| 34 | |||
| 35 | 27 | if ($value instanceof Type) { |
|
| 36 | 1 | return $value->getValue(); |
|
| 37 | } |
||
| 38 | |||
| 39 | 27 | if (is_object($value) && is_callable([$value, '__toString'])) { |
|
| 40 | 1 | $value = (string) $value; |
|
| 41 | } |
||
| 42 | |||
| 43 | 27 | if (is_string($value)) { |
|
| 44 | 26 | if ($addQuotes) { |
|
| 45 | 17 | return self::formatStringParameter(self::escapeString($value)); |
|
| 46 | } |
||
| 47 | |||
| 48 | 9 | return $value; |
|
| 49 | } |
||
| 50 | |||
| 51 | 1 | throw UnsupportedValueType::new($value); |
|
| 52 | } |
||
| 73 |