| Conditions | 8 |
| Paths | 4 |
| Total Lines | 18 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 8 |
| Changes | 0 | ||
| 1 | <?php /** @noinspection PhpVariableVariableInspection */ |
||
| 14 | 12 | function iterable_project(iterable $iterable, array $mapping): \Generator |
|
| 15 | { |
||
| 16 | 11 | foreach ($iterable as $key => $value) { |
|
| 17 | 10 | $projected = []; |
|
| 18 | |||
| 19 | 10 | if (is_array($value) || $value instanceof \ArrayAccess) { |
|
| 20 | 7 | foreach ($mapping as $to => $from) { |
|
| 21 | 7 | $projected[$to] = $value[$from] ?? null; |
|
| 22 | } |
||
| 23 | 7 | } elseif (is_object($value) && !$value instanceof \DateTimeInterface) { |
|
| 24 | 7 | foreach ($mapping as $to => $from) { |
|
| 25 | 7 | $projected[$to] = $value->$from ?? null; |
|
| 26 | } |
||
| 27 | } else { |
||
| 28 | 1 | $projected = array_fill_keys(array_keys($mapping), null); |
|
| 29 | } |
||
| 30 | |||
| 31 | 10 | yield $key => $projected; |
|
| 32 | } |
||
| 34 |