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

codeigniter4 / CodeIgniter4 / 37986190232

09 Oct 2026 08:19PM UTC coverage: 50.703% (-39.5%) from 90.183%
37986190232

Pull #10606

github

web-flow
Merge 2cebb1efa into 7822cde17
Pull Request #10606: fix: refresh REQUEST after URI GET normalization

17 of 30 new or added lines in 2 files covered. (56.67%)

10012 existing lines in 288 files now uncovered.

12871 of 25385 relevant lines covered (50.7%)

87.05 hits per line

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

50.0
/system/Validation/DotArrayFilter.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of CodeIgniter 4 framework.
7
 *
8
 * (c) CodeIgniter Foundation <admin@codeigniter.com>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace CodeIgniter\Validation;
15

16
/**
17
 * @see \CodeIgniter\Validation\DotArrayFilterTest
18
 */
19
final class DotArrayFilter
20
{
21
    /**
22
     * Creates a new array with only the elements specified in dot array syntax.
23
     *
24
     * @param list<string>            $indexes The dot array syntax pattern to use for filtering.
25
     * @param array<array-key, mixed> $array   The array to filter.
26
     *
27
     * @return array<array-key, mixed> The filtered array.
28
     */
29
    public static function run(array $indexes, array $array): array
30
    {
31
        $result = [];
38 ✔
32

33
        foreach ($indexes as $index) {
38 ✔
34
            $segments = preg_split('/(?<!\\\\)\./', $index, -1, PREG_SPLIT_NO_EMPTY);
38 ✔
35
            $segments = array_map(static fn ($key): string => str_replace('\.', '.', $key), $segments);
38 ✔
36

37
            $filteredArray = self::filter($segments, $array);
38 ✔
38

39
            if ($filteredArray !== []) {
38 ✔
40
                $result = array_replace_recursive($result, $filteredArray);
38 ✔
41
            }
42
        }
43

44
        return $result;
38 ✔
45
    }
46

47
    /**
48
     * Used by `run()` to recursively filter the array with wildcards.
49
     *
50
     * @param list<string>            $indexes The dot array syntax pattern to use for filtering.
51
     * @param array<array-key, mixed> $array   The array to filter.
52
     *
53
     * @return array<array-key, mixed> The filtered array.
54
     */
55
    private static function filter(array $indexes, array $array): array
56
    {
57
        // If there are no indexes left, return an empty array
58
        if ($indexes === []) {
38 ✔
UNCOV
59
            return [];
×
60
        }
61

62
        // Get the current index
63
        $currentIndex = array_shift($indexes);
38 ✔
64

65
        // If the current index doesn't exist and is not a wildcard, return an empty array.
66
        // Use array_key_exists() so explicit null values are preserved.
67
        if ($currentIndex !== '*' && ! array_key_exists($currentIndex, $array)) {
38 ✔
68
            return [];
7 ✔
69
        }
70

71
        // Handle the wildcard '*' at the current level
72
        if ($currentIndex === '*') {
38 ✔
UNCOV
73
            $result = [];
×
74

75
            // Iterate over all keys at this level
UNCOV
76
            foreach ($array as $key => $value) {
×
UNCOV
77
                if ($indexes === []) {
×
78
                    // If no indexes are left, capture the entire value
UNCOV
79
                    $result[$key] = $value;
×
UNCOV
80
                } elseif (is_array($value)) {
×
81
                    // If there are still indexes left, continue filtering recursively
UNCOV
82
                    $filtered = self::filter($indexes, $value);
×
UNCOV
83
                    if ($filtered !== []) {
×
UNCOV
84
                        $result[$key] = $filtered;
×
85
                    }
86
                }
87
            }
88

UNCOV
89
            return $result;
×
90
        }
91

92
        // If this is the last index, return the value as-is, including null.
93
        if ($indexes === []) {
38 ✔
94
            return [$currentIndex => $array[$currentIndex]];
38 ✔
95
        }
96

97
        // If the current value is an array, recursively filter it
UNCOV
98
        if (is_array($array[$currentIndex])) {
×
UNCOV
99
            $filtered = self::filter($indexes, $array[$currentIndex]);
×
100

UNCOV
101
            if ($filtered !== []) {
×
UNCOV
102
                return [$currentIndex => $filtered];
×
103
            }
104
        }
105

UNCOV
106
        return [];
×
107
    }
108
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc