Passed
Pull Request — develop (#167)
by Daniel
04:59
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
class ArrayUtility
25
{
26
    /**
27
     * Recursively removes empty array elements.
28
     *
29
     * @see \TYPO3\CMS\Extbase\Utility\ArrayUtility::removeEmptyElementsRecursively Removed in TYPO3 v9
30
     */
31 2
    public static function removeEmptyElementsRecursively(array $array): array
32
    {
33 2
        $result = $array;
34 2
        foreach ($result as $key => $value) {
35 2
            if (is_array($value)) {
36
                $result[$key] = self::removeEmptyElementsRecursively($value);
37
                if ($result[$key] === []) {
38
                    unset($result[$key]);
39
                }
40 2
            } elseif ($value === null) {
41 2
                unset($result[$key]);
42
            }
43
        }
44 2
        return $result;
45
    }
46
}
47