| Conditions | 6 |
| Paths | 32 |
| Total Lines | 23 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 15 |
| CRAP Score | 6 |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | 9 | function iterable_sort_keys(iterable $iterable, $compare): \Generator |
|
| 15 | { |
||
| 16 | 8 | type_check($compare, ['callable', 'int'], new \TypeError("Expected compare to be callable or integer, %s given")); |
|
| 17 | |||
| 18 | 8 | $comparator = is_int($compare) ? null : $compare; |
|
| 19 | 8 | $flags = is_int($compare) ? $compare : 0; |
|
| 20 | |||
| 21 | 8 | $keys = []; |
|
| 22 | 8 | $values = []; |
|
| 23 | |||
| 24 | 8 | foreach ($iterable as $key => $value) { |
|
| 25 | 7 | $keys[] = $key; |
|
| 26 | 7 | $values[] = $value; |
|
| 27 | } |
||
| 28 | |||
| 29 | 8 | unset($iterable); |
|
| 30 | |||
| 31 | 8 | isset($comparator) |
|
| 32 | 2 | ? uasort($keys, $comparator) |
|
| 33 | 6 | : asort($keys, $flags); |
|
| 34 | |||
| 35 | 8 | foreach ($keys as $index => $key) { |
|
| 36 | 7 | yield $key => $values[$index]; |
|
| 37 | } |
||
| 39 |