• 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

15.38
/src/Psl/Dict/slice.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Psl\Dict;
6

7
use function array_slice;
8
use function is_array;
9

10
/**
11
 * Takes a slice from an iterable.
12
 *
13
 * Examples:
14
 *
15
 *      Dict\slice(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4], 2)
16
 *      => Dict('c' => 3, 'd' => 4)
17
 *
18
 *      Dict\slice(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4], 1, 2)
19
 *      => Dict('b' => 2, 'c' => 3)
20
 *
21
 * @template Tk of array-key
22
 * @template Tv
23
 *
24
 * @param iterable<Tk, Tv> $iterable Iterable to take the slice from
25
 * @param int<0, max> $start Start offset
26
 * @param null|int<0, max> $length Length (if not specified all remaining values from the array are used)
27
 *
28
 * @return array<Tk, Tv>
29
 */
30
function slice(iterable $iterable, int $start, null|int $length = null): array
31
{
32
    if (is_array($iterable)) {
29✔
33
        return array_slice($iterable, $start, $length, true);
29✔
34
    }
35

UNCOV
36
    $result = [];
×
UNCOV
37
    if (0 === $length) {
×
UNCOV
38
        return $result;
×
39
    }
40

UNCOV
41
    $i = 0;
×
UNCOV
42
    foreach ($iterable as $key => $value) {
×
UNCOV
43
        if ($i++ < $start) {
×
UNCOV
44
            continue;
×
45
        }
46

UNCOV
47
        $result[$key] = $value;
×
UNCOV
48
        if (null !== $length && $i >= ($start + $length)) {
×
UNCOV
49
            break;
×
50
        }
51
    }
52

UNCOV
53
    return $result;
×
54
}
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