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

azjezz / psl / 17432557268

03 Sep 2025 11:52AM UTC coverage: 98.446% (-0.07%) from 98.513%
17432557268

push

github

web-flow
chore: migrate from `psalm` to `mago` (#527)

232 of 241 new or added lines in 81 files covered. (96.27%)

14 existing lines in 12 files now uncovered.

5510 of 5597 relevant lines covered (98.45%)

52.23 hits per line

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

90.91
/src/Psl/Str/Byte/range.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Psl\Str\Byte;
6

7
use Psl\Range\LowerBoundRangeInterface;
8
use Psl\Range\RangeInterface;
9
use Psl\Range\UpperBoundRangeInterface;
10
use Psl\Str\Exception;
11

12
/**
13
 * Slice a string using a range.
14
 *
15
 * If the range doesn't have an upper range, the slice will contain the
16
 * rest of the string. If the upper-bound is equal to the lower-bound,
17
 * then an empty string will be returned.
18
 *
19
 * Example:
20
 *
21
 * ```php
22
 * use Psl\Range;
23
 * use Psl\Str\Byte;
24
 *
25
 * $string = 'Hello, World!';
26
 *
27
 * Byte\range($string, Range\between(0, 3, upper_inclusive: true)); // 'Hell'
28
 * Byte\range($string, Range\between(0, 3, upper_inclusive: false)); // 'Hel'
29
 * Byte\range($string, Range\from(3)); // 'lo, World!'
30
 * Byte\range($string, Range\to(3, true)); // 'Hell'
31
 * Byte\range($string, Range\to(3, false)); // 'Hel'
32
 * Byte\range($string, Range\full()); // 'Hello, World!'
33
 * Byte\range($string, Range\between(7, 5, true)); // 'World'
34
 * ```
35
 *
36
 * @param RangeInterface $range
37
 *
38
 * @throws Exception\OutOfBoundsException If the $offset is out-of-bounds.
39
 *
40
 * @pure
41
 */
42
function range(string $string, RangeInterface $range): string
43
{
44
    $offset = 0;
15✔
45
    $length = null;
15✔
46
    if ($range instanceof LowerBoundRangeInterface) {
15✔
47
        $offset = $range->getLowerBound();
13✔
48
    }
49

50
    if ($range instanceof UpperBoundRangeInterface) {
15✔
51
        $length = $range->getUpperBound() - $offset;
11✔
52
        if ($range->isUpperInclusive()) {
11✔
53
            $length += 1;
4✔
54
        }
55

56
        if ($length < 0) {
11✔
NEW
57
            $length = 0;
×
58
        }
59
    }
60

61
    return slice($string, $offset, $length);
15✔
62
}
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