Completed
Branch master (f24788)
by Harry
02:03
created

SequentialTrait::isSequential()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

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