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

ArrayUtility   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 70%

Importance

Changes 0
Metric Value
wmc 5
eloc 10
dl 0
loc 24
ccs 7
cts 10
cp 0.7
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A removeEmptyElementsRecursively() 0 14 5
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