Passed
Pull Request — develop (#167)
by Daniel
04:48
created

ArrayUtility::removeEmptyElementsRecursively()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5.675

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 14
ccs 7
cts 10
cp 0.7
rs 9.6111
c 0
b 0
f 0
cc 5
nc 5
nop 1
crap 5.675
1
<?php
2
3
namespace Codappix\SearchCore\Utility;
4
5
/**
6
 * Utility: Array
7
 * @package Codappix\SearchCore\Utility
8
 */
9
class ArrayUtility
10
{
11
12
    /**
13
     * Recursively removes empty array elements.
14
     *
15
     * @param array $array
16
     * @return array the modified array
17
     * @see \TYPO3\CMS\Extbase\Utility\ArrayUtility::removeEmptyElementsRecursively Removed in TYPO3 v9
18
     */
19 2
    public static function removeEmptyElementsRecursively(array $array): array
20
    {
21 2
        $result = $array;
22 2
        foreach ($result as $key => $value) {
23 2
            if (is_array($value)) {
24
                $result[$key] = self::removeEmptyElementsRecursively($value);
25
                if ($result[$key] === []) {
26
                    unset($result[$key]);
27
                }
28 2
            } elseif ($value === null) {
29 2
                unset($result[$key]);
30
            }
31
        }
32 2
        return $result;
33
    }
34
}
35