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