ArrayFunctions::arrayValuesMerge()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
ccs 4
cts 4
cp 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of the FabienCrassat\CurriculumVitaeBundle Symfony bundle.
5
 *
6
 * (c) Fabien Crassat <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FabienCrassat\CurriculumVitaeBundle\Utility;
13
14
class ArrayFunctions
15
{
16
    /**
17
     * @param array $array
18
     */
19 3
    public function arrayValuesRecursive(array $array)
20
    {
21 3
        $result = [];
22 3
        foreach ($array as $value) {
23 3
            $result = $this->arrayValuesMerge($result, $value);
24
        }
25 3
        return $result;
26
    }
27
28 3
    private function arrayValuesMerge(array $array, $value)
29
    {
30 3
        if (is_array($value)) {
31 3
            return array_merge($array, $this->arrayValuesRecursive($value));
0 ignored issues
show
Bug introduced by
It seems like $this->arrayValuesRecursive($value) can also be of type mixed; however, parameter $array2 of array_merge() does only seem to accept null|array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
            return array_merge($array, /** @scrutinizer ignore-type */ $this->arrayValuesRecursive($value));
Loading history...
32
        }
33
34 3
        return array_merge($array, [$value]);
35
    }
36
}
37