• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FluidTYPO3 / flux / 27757675993

18 Jun 2026 11:55AM UTC coverage: 89.162% (-3.5%) from 92.646%
27757675993

push

github

NamelessCoder
[TASK] Address last phpstan warnings

6228 of 6985 relevant lines covered (89.16%)

40.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.78
/Classes/Utility/RecursiveArrayUtility.php
1
<?php
2
namespace FluidTYPO3\Flux\Utility;
3

4
/*
5
 * This file is part of the FluidTYPO3/Flux project under GPLv2 or later.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.md file that was distributed with this source code.
9
 */
10

11
use TYPO3\CMS\Core\Utility\ArrayUtility;
12

13
class RecursiveArrayUtility
14
{
15
    public static function merge(array $array1, array $array2): array
16
    {
17
        $array1 = (array) $array1;
38✔
18
        $array2 = (array) $array2;
38✔
19
        foreach ($array2 as $key => $val) {
38✔
20
            if (is_array($array1[$key] ?? null)) {
14✔
21
                if (is_array($array2[$key] ?? null)) {
8✔
22
                    $val = static::merge($array1[$key], $array2[$key]);
8✔
23
                }
24
            }
25
            $array1[$key] = $val;
14✔
26
        }
27
        reset($array1);
38✔
28
        return $array1;
38✔
29
    }
30

31
    public static function diff(array $array1, array $array2): array
32
    {
33
        $array1 = (array) $array1;
4✔
34
        $array2 = (array) $array2;
4✔
35
        foreach ($array1 as $key => $value) {
4✔
36
            if (isset($array2[$key])) {
4✔
37
                if (is_array($value) && is_array($array2[$key])) {
4✔
38
                    $diff = static::diff($value, $array2[$key]);
4✔
39
                    if (0 === count($diff)) {
4✔
40
                        unset($array1[$key]);
4✔
41
                    } else {
42
                        $array1[$key] = $diff;
4✔
43
                    }
44
                } elseif ($value == $array2[$key]) {
4✔
45
                    unset($array1[$key]);
4✔
46
                }
47
                unset($array2[$key]);
4✔
48
            }
49
        }
50
        foreach ($array2 as $key => $value) {
4✔
51
            if (!isset($array1[$key])) {
4✔
52
                $array1[$key] = $value;
4✔
53
            }
54
        }
55
        return $array1;
4✔
56
    }
57

58
    /**
59
     * This method convert a string like "Some.long.tree" into an array ["Some"=>["long"=>["tree"=> $value]]]
60
     *
61
     * @param mixed $value
62
     */
63
    public static function convertPathToArray(string $path, $value = null): array
64
    {
65
        $array = [];
236✔
66
        if (strpos($path, '.') === false) {
236✔
67
            $array[$path] = $value;
228✔
68
        } else {
69
            /** @var array|mixed $target */
70
            $target = &$array;
8✔
71
            foreach (explode('.', $path) as $segment) {
8✔
72
                if (!is_array($target)) {
8✔
73
                    break;
×
74
                }
75
                if (!array_key_exists($segment, $target) || !is_array($target[$segment])) {
8✔
76
                    $target[$segment] = [];
8✔
77
                }
78
                $target = &$target[$segment];
8✔
79
            }
80
            $target = $value;
8✔
81
        }
82

83
        return $array;
236✔
84
    }
85

86
    /**
87
     * @param array $firstArray First array
88
     * @param array $secondArray Second array, overruling the first array
89
     * @param boolean $notAddKeys If set, keys that are NOT found in $firstArray will not be set. Thus only existing
90
     *                            value can/will be overruled from second array.
91
     * @param boolean $includeEmptyValues If set, values from $secondArray will overrule if they are empty or zero.
92
     *                                    Default: TRUE
93
     * @param boolean $enableUnsetFeature If set, special values "__UNSET" can be used in the second array in order to
94
     *                                    unset array keys in the resulting array.
95
     * @return array Resulting array where $secondArray values has overruled $firstArray values
96
     */
97
    public static function mergeRecursiveOverrule(
98
        array $firstArray,
99
        array $secondArray,
100
        bool $notAddKeys = false,
101
        bool $includeEmptyValues = true,
102
        bool $enableUnsetFeature = true
103
    ): array {
104
        ArrayUtility::mergeRecursiveWithOverrule(
292✔
105
            $firstArray,
292✔
106
            $secondArray,
292✔
107
            !$notAddKeys,
292✔
108
            $includeEmptyValues,
292✔
109
            $enableUnsetFeature
292✔
110
        );
292✔
111
        return $firstArray;
292✔
112
    }
113
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc