CompareResults   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 12
lcom 0
cbo 0
dl 0
loc 58
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A buildKey() 0 8 2
A emptyIfNotSet() 0 9 2
C mergeArraysIntoFirstSecond() 0 35 8
1
<?php
2
3
/*
4
 * The MIT License
5
 *
6
 * Copyright 2016 Daniel Popiniuc
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9
 * of this software and associated documentation files (the "Software"), to deal
10
 * in the Software without restriction, including without limitation the rights
11
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
 * copies of the Software, and to permit persons to whom the Software is
13
 * furnished to do so, subject to the following conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
 * THE SOFTWARE.
25
 */
26
27
namespace danielgp\info_compare;
28
29
trait CompareResults
30
{
31
32
    private function buildKey($inArray)
33
    {
34
        $aReturn = [];
35
        foreach ($inArray as $key => $val) {
36
            $aReturn[] = str_repeat('_', $key) . $val;
37
        }
38
        return implode('', $aReturn);
39
    }
40
41
    private function emptyIfNotSet($inValue)
42
    {
43
        if (isset($inValue)) {
44
            $sReturn = $inValue;
45
        } else {
46
            $sReturn = '';
47
        }
48
        return $sReturn;
49
    }
50
51
    protected function mergeArraysIntoFirstSecond($stAry, $ndAry, $pSq = ['first', 'second'])
52
    {
53
        $row = [];
54
        foreach ($stAry as $key => $val) {
55
            if (is_array($val)) {
56
                foreach ($val as $ky2 => $vl2) {
57
                    if (is_array($vl2)) {
58
                        foreach ($vl2 as $ky3 => $vl3) {
59
                            if (is_array($vl3)) {
60
                                foreach ($vl3 as $ky4 => $vl4) {
61
                                    $row[$this->buildKey([$key, $ky2, $ky3, $ky4])] = [
62
                                        $pSq[0] => $vl4,
63
                                        $pSq[1] => $this->emptyIfNotSet($ndAry[$key][$ky2][$ky3][$ky4]),
64
                                    ];
65
                                }
66
                            } else {
67
                                $row[$this->buildKey([$key, $ky2, $ky3])] = [
68
                                    $pSq[0] => $vl3,
69
                                    $pSq[1] => $this->emptyIfNotSet($ndAry[$key][$ky2][$ky3]),
70
                                ];
71
                            }
72
                        }
73
                    } else {
74
                        $row[$this->buildKey([$key, $ky2])] = [
75
                            $pSq[0] => $vl2,
76
                            $pSq[1] => $this->emptyIfNotSet($ndAry[$key][$ky2]),
77
                        ];
78
                    }
79
                }
80
            } else {
81
                $row[$key] = [$pSq[0] => $val, $pSq[1] => $this->emptyIfNotSet($ndAry[$key])];
82
            }
83
        }
84
        return $row;
85
    }
86
}
87