ConsistencyChecker   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 16
c 1
b 0
f 0
dl 0
loc 45
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isElementValid() 0 23 6
A isValid() 0 9 3
1
<?php
2
/**
3
 * This file is part of the ArrayQuery package.
4
 *
5
 * (c) Mauro Cassani<https://github.com/mauretto78>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace ArrayQuery\Helpers;
12
13
class ConsistencyChecker
14
{
15
    /**
16
     * @param $element
17
     * @param $array
18
     * @return bool
19
     */
20
    public static function isElementValid($element, $array)
21
    {
22
        foreach ($array as $key => $item) {
23
            if (is_object($item)) {
24
                $array[$key] = ArrayHelper::convertToPlainArray($item);
25
            }
26
        }
27
28
        if (is_object($element)) {
29
            $element = ArrayHelper::convertToPlainArray($element);
30
        }
31
32
        $firstItem = current($array);
33
34
        if (false === ArrayHelper::checkIfTwoArraysAreConsistent(array_keys($firstItem), array_keys($element))) {
35
            return false;
36
        }
37
38
        if(false === ArrayHelper::compareElementToItemKeyMap($firstItem, $element)) {
39
            return false;
40
        }
41
42
        return true;
43
    }
44
45
    /**
46
     * @param $array
47
     * @return bool
48
     */
49
    public static function isValid($array)
50
    {
51
        foreach ($array as $element) {
52
            if (false === self::isElementValid($element, $array)) {
53
                return false;
54
            }
55
        }
56
57
        return true;
58
    }
59
}
60