• 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

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

3
declare(strict_types=1);
4

5
namespace Psl\Dict;
6

7
use Closure;
8

9
use function asort;
10
use function is_array;
11
use function uasort;
12

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

38
    if (null !== $comparator) {
9✔
39
        uasort($array, $comparator);
7✔
40

41
        return $array;
7✔
42
    }
43

44
    asort($array);
2✔
45

46
    return $array;
2✔
47
}
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