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

azjezz / psl / 22680264557

04 Mar 2026 05:06PM UTC coverage: 97.34% (-1.0%) from 98.375%
22680264557

Pull #610

github

azjezz
perf: optimizations

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

319 of 355 new or added lines in 90 files covered. (89.86%)

64 existing lines in 12 files now uncovered.

9258 of 9511 relevant lines covered (97.34%)

34.97 hits per line

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

0.0
/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
{
NEW
33
    if (is_array($iterables)) {
×
NEW
34
        $all_arrays = true;
×
NEW
35
        foreach ($iterables as $inner) {
×
NEW
36
            if (is_array($inner)) {
×
NEW
37
                continue;
×
38
            }
39

NEW
40
            $all_arrays = false;
×
NEW
41
            break;
×
42
        }
43

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

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

UNCOV
57
    return $result;
×
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