SequentialTrait::areSequential()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 4
nc 3
nop 1
crap 4
1
<?php
2
3
namespace Graze\ArrayMerger;
4
5
trait SequentialTrait
6
{
7
    /**
8
     * Check if the provided array is sequential or not
9
     *
10
     * @param array $array
11
     *
12
     * @return bool
13
     */
14 61
    protected function isSequential(array $array)
15
    {
16 61
        if (!empty($array) && !array_key_exists(0, $array)) {
17 41
            return false;
18
        }
19 22
        return array_values($array) === $array;
20
    }
21
22
    /**
23
     * @param array $arrays Collection of arrays to check
24
     *
25
     * @return bool True if all the arrays are sequential
26
     */
27 43
    protected function areSequential(array $arrays)
28
    {
29 43
        foreach ($arrays as $array) {
30 43
            if (!is_array($array) || !$this->isSequential($array)) {
31 43
                return false;
32
            }
33
        }
34
35 9
        return true;
36
    }
37
}
38