ArrayUtility::isIndexed()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php declare(strict_types=1);
2
3
4
namespace Pitchart\Phlunit\Constraint\Arrays;
5
6
class ArrayUtility
7
{
8 36
    public static function isAssociative(array $array): bool
9
    {
10 36
        $size = \count($array);
11 36
        $filteredKeys = \array_filter(\array_keys($array), function($int) {return $int === (int) $int; });
12 36
        return \count($filteredKeys) !== $size;
13
    }
14
15 4
    public static function isIndexed(array $array): bool
16
    {
17 4
        return !self::isAssociative($array);
18
    }
19
20 66
    public static function toArray(iterable $iterable): array
21
    {
22 66
        if ($iterable instanceof \Traversable) {
23 27
            return \iterator_to_array($iterable);
24
        }
25
26 57
        return $iterable;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $iterable returns the type iterable which is incompatible with the type-hinted return array.
Loading history...
27
    }
28
}
29