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

azjezz / psl / 22680098232

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

push

github

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

Signed-off-by: azjezz <azjezz@protonmail.com>

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

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

3
declare(strict_types=1);
4

5
namespace Psl\Vec;
6

7
use function array_slice;
8
use function array_values;
9
use function is_array;
10

11
/**
12
 * Takes a slice from an iterable.
13
 *
14
 * Examples:
15
 *
16
 *      Vec\slice([-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5], 5)
17
 *      => Vec(0, 1, 2, 3, 4, 5)
18
 *
19
 *      Vec\slice([-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5], 5, 3)
20
 *      => Vec(0, 1, 2)
21
 *
22
 * @template T
23
 *
24
 * @param iterable<T> $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 list<T>
29
 */
30
function slice(iterable $iterable, int $start, null|int $length = null): array
31
{
32
    if (is_array($iterable)) {
10✔
33
        return array_values(array_slice($iterable, $start, $length));
10✔
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 $value) {
×
UNCOV
43
        if ($i++ < $start) {
×
UNCOV
44
            continue;
×
45
        }
46

UNCOV
47
        $result[] = $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