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

azjezz / psl / 22680186990

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

Pull #610

github

azjezz
perf: replace PSL calls with native PHP builtins and fix O(n2) algorithms

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

70.0
/src/Psl/Dict/sort_by_key.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Psl\Dict;
6

7
use Closure;
8

9
use function is_array;
10
use function ksort;
11
use function uksort;
12

13
/**
14
 * Returns a new dict sorted by the keys of the given iterable.
15
 *
16
 * If the optional comparator function isn't provided, the keys will be sorted in
17
 * ascending order.
18
 *
19
 * @template Tk of array-key
20
 * @template Tv
21
 *
22
 * @param iterable<Tk, Tv> $iterable
23
 * @param (Closure(Tk, Tk): int)|null $comparator
24
 *
25
 * @return array<Tk, Tv>
26
 */
27
function sort_by_key(iterable $iterable, null|Closure $comparator = null): array
28
{
29
    if (is_array($iterable)) {
2✔
30
        $result = $iterable;
2✔
31
    } else {
NEW
32
        $result = [];
×
NEW
33
        foreach ($iterable as $k => $v) {
×
NEW
34
            $result[$k] = $v;
×
35
        }
36
    }
37

38
    if ($comparator) {
2✔
39
        uksort($result, $comparator);
1✔
40
        return $result;
1✔
41
    }
42

43
    ksort($result);
1✔
44
    return $result;
1✔
45
}
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