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

SequentialTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isSequential() 0 6 3
A areSequential() 0 9 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
    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