Completed
Pull Request — develop (#167)
by Daniel
25:11
created

ArrayUtility   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 10
dl 0
loc 21
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
     * Recursively removes empty array elements.
13
     *
14
     * @see \TYPO3\CMS\Extbase\Utility\ArrayUtility::removeEmptyElementsRecursively Removed in TYPO3 v9
15
     */
16
    public static function removeEmptyElementsRecursively(array $array): array
17
    {
18
        $result = $array;
19
        foreach ($result as $key => $value) {
20
            if (is_array($value)) {
21
                $result[$key] = self::removeEmptyElementsRecursively($value);
22
                if ($result[$key] === []) {
23
                    unset($result[$key]);
24
                }
25
            } elseif ($value === null) {
26
                unset($result[$key]);
27
            }
28
        }
29
        return $result;
30
    }
31
}
32