Passed
Pull Request — develop (#167)
by
unknown
20:25
created

ArrayUtility::removeEmptyElementsRecursively()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 14
rs 9.6111
c 0
b 0
f 0
cc 5
nc 5
nop 1
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
    public static function removeEmptyElementsRecursively(array $array): array
20
    {
21
        $result = $array;
22
        foreach ($result as $key => $value) {
23
            if (is_array($value)) {
24
                $result[$key] = self::removeEmptyElementsRecursively($value);
25
                if ($result[$key] === []) {
26
                    unset($result[$key]);
27
                }
28
            } elseif ($value === null) {
29
                unset($result[$key]);
30
            }
31
        }
32
        return $result;
33
    }
34
}
35