Passed
Push — master ( cf27e8...f24788 )
by Harry
02:00
created

SequentialTrait::areSequential()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 4
nc 3
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
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
    protected function isSequential(array $array)
15
    {
16
        if (!empty($array) && !array_key_exists(0, $array)) {
17
            return false;
18
        }
19
        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
    protected function areSequential(array $arrays)
28
    {
29
        foreach ($arrays as $array) {
30
            if (!is_array($array) || !$this->isSequential($array)) {
31
                return false;
32
            }
33
        }
34
35
        return true;
36
    }
37
}
38