iterable_separate()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 1
dl 0
loc 15
ccs 8
cts 8
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Improved;
6
7
/**
8
 * Get both keys and values of iterable in separate arrays.
9
 *
10
 * @param iterable $iterable
11
 * @return array[]  ['keys' => array, 'values' => array]
12
 */
13
function iterable_separate(iterable $iterable): array
0 ignored issues
show
introduced by
Function Improved\iterable_separate() has parameter $iterable with no value type specified in iterable type iterable.
Loading history...
14
{
15 7
    if (is_array($iterable)) {
16 1
        return ['keys' => array_keys($iterable), 'values' => array_values($iterable)];
17
    }
18
19 6
    $keys = [];
20 6
    $values = [];
21
22 6
    foreach ($iterable as $key => $value) {
23 5
        $keys[] = $key;
24 5
        $values[] = $value;
25
    }
26
27 6
    return compact('keys', 'values');
28
}
29