| Conditions | 12 | 
| Paths | 16 | 
| Total Lines | 51 | 
| Code Lines | 29 | 
| Lines | 0 | 
| Ratio | 0 % | 
| 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 | ||
| 49 | private static function formatValue(mixed $value): string | ||
| 50 |     { | ||
| 51 |         if ($value === null) { | ||
| 52 | return 'NULL'; | ||
| 53 | } | ||
| 54 | |||
| 55 |         if (\is_int($value) || \is_float($value)) { | ||
| 56 | return (string) $value; | ||
| 57 | } | ||
| 58 | |||
| 59 |         if (\is_bool($value)) { | ||
| 60 | return $value ? 'true' : 'false'; | ||
| 61 | } | ||
| 62 | |||
| 63 |         if (\is_object($value)) { | ||
| 64 |             if (\method_exists($value, '__toString')) { | ||
| 65 | $stringValue = $value->__toString(); | ||
| 66 |             } else { | ||
| 67 | // For objects without __toString, use a default representation | ||
| 68 | $stringValue = $value::class; | ||
| 69 | } | ||
| 70 |         } elseif (\is_resource($value)) { | ||
| 71 | $stringValue = '(resource)'; | ||
| 72 |         } else { | ||
| 73 | $valueType = \get_debug_type($value); | ||
| 74 | |||
| 75 |             if ($valueType === 'string') { | ||
| 76 | $stringValue = $value; | ||
| 77 |             } elseif (\in_array($valueType, ['int', 'float', 'bool'], true)) { | ||
| 78 | /** @var bool|float|int $value */ | ||
| 79 | $stringValue = (string) $value; | ||
| 80 |             } else { | ||
| 81 | $stringValue = $valueType; | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | \assert(\is_string($stringValue)); | ||
| 86 | |||
| 87 |         if ($stringValue === '') { | ||
| 88 | return '""'; | ||
| 89 | } | ||
| 90 | |||
| 91 | // Make sure strings are quoted, PostgreSQL will handle this gracefully | ||
| 92 | // Double the backslashes and escape quotes | ||
| 93 | $escaped = \str_replace( | ||
| 94 | ['\\', '"'], | ||
| 95 | ['\\\\', '\"'], | ||
| 96 | $stringValue | ||
| 97 | ); | ||
| 98 | |||
| 99 | return '"'.$escaped.'"'; | ||
| 100 | } | ||
| 102 |