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

ArrayUtility   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 70%

Importance

Changes 0
Metric Value
wmc 5
eloc 10
dl 0
loc 21
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
 * Copyright (C) 2018 Benjamin Serfhos <[email protected]>
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21
 * 02110-1301, USA.
22
 */
23
24
use TYPO3\CMS\Core\Utility\ArrayUtility as Typo3ArrayUtility;
25
26
class ArrayUtility extends Typo3ArrayUtility
27
{
28
    /**
29
     * Recursively removes empty array elements.
30
     *
31
     * @see \TYPO3\CMS\Extbase\Utility\ArrayUtility::removeEmptyElementsRecursively Removed in TYPO3 v9
32
     */
33 2
    public static function removeEmptyElementsRecursively(array $array): array
34
    {
35 2
        $result = $array;
36 2
        foreach ($result as $key => $value) {
37 2
            if (is_array($value)) {
38
                $result[$key] = self::removeEmptyElementsRecursively($value);
39
                if ($result[$key] === []) {
40
                    unset($result[$key]);
41
                }
42 2
            } elseif ($value === null) {
43 2
                unset($result[$key]);
44
            }
45
        }
46 2
        return $result;
47
    }
48
}
49