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

azjezz / psl / 22686750471

04 Mar 2026 07:58PM UTC coverage: 97.813% (-0.6%) from 98.375%
22686750471

Pull #610

github

azjezz
add more tests for slow paths

Signed-off-by: azjezz <azjezz@protonmail.com>
Pull Request #610: perf: replace PSL calls with native PHP builtins and fix O(n2) algorithms

340 of 355 new or added lines in 90 files covered. (95.77%)

42 existing lines in 8 files now uncovered.

9303 of 9511 relevant lines covered (97.81%)

35.01 hits per line

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

92.86
/src/Psl/Dict/flatten.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Psl\Dict;
6

7
use function array_replace;
8
use function is_array;
9

10
/**
11
 * Returns a new dict formed by merging the iterable elements of the
12
 * given iterable.
13
 *
14
 * In the case of duplicate keys, later values will overwrite
15
 * the previous ones.
16
 *
17
 * Example:
18
 *      Dict\flatten([[1, 2], [9, 8]])
19
 *      => Dict(0 => 9, 1 => 8)
20
 *
21
 *      Dict\flatten([[0 => 1, 1 => 2], [2 => 9, 3 => 8]])
22
 *      => Dict(0 => 1, 1 => 2, 2 => 9, 3 => 8)
23
 *
24
 * @template Tk of array-key
25
 * @template Tv
26
 *
27
 * @param iterable<iterable<Tk, Tv>> $iterables
28
 *
29
 * @return array<Tk, Tv>
30
 */
31
function flatten(iterable $iterables): array
32
{
33
    if (is_array($iterables)) {
2✔
34
        $all_arrays = true;
2✔
35
        foreach ($iterables as $inner) {
2✔
36
            if (is_array($inner)) {
2✔
37
                continue;
1✔
38
            }
39

40
            $all_arrays = false;
2✔
41
            break;
2✔
42
        }
43

44
        if ($all_arrays) {
2✔
45
            /** @var array<array<Tk, Tv>> $iterables */
NEW
46
            return [] === $iterables ? [] : array_replace(...$iterables);
×
47
        }
48
    }
49

50
    $result = [];
2✔
51
    foreach ($iterables as $iterable) {
2✔
52
        foreach ($iterable as $key => $value) {
2✔
53
            $result[$key] = $value;
2✔
54
        }
55
    }
56

57
    return $result;
2✔
58
}
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