| Conditions | 3 |
| Paths | 2 |
| Total Lines | 20 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 27 | public static function mapProperties(object $target, array $excludeNames = [], bool $excludeEmpty = true): array |
||
| 28 | { |
||
| 29 | try { |
||
| 30 | $rClass = new \ReflectionClass($target); |
||
| 31 | } catch (\Throwable) { |
||
| 32 | return []; |
||
| 33 | } |
||
| 34 | |||
| 35 | return ArrayList::collect($rClass->getProperties()) |
||
| 36 | ->filter( |
||
| 37 | static fn (\ReflectionProperty $property) => $excludeEmpty |
||
| 38 | ? !empty($property->getValue($target)) |
||
| 39 | : null !== $property->getValue($target) |
||
| 40 | ) |
||
| 41 | ->filter(static fn (\ReflectionProperty $property) => !\in_array($property->getName(), $excludeNames, true)) |
||
| 42 | ->map(static fn (\ReflectionProperty $property) => match (true) { |
||
| 43 | \is_array($property->getValue($target)) => $property->getValue($target), |
||
| 44 | default => [$property->getName() => $property->getValue($target)], |
||
| 45 | }) |
||
| 46 | ->toMergedArray() |
||
| 47 | ; |
||
| 50 |