• 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

28.57
/src/Psl/Str/ends_with.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Psl\Str;
6

7
use function str_ends_with;
8

9
/**
10
 * Returns whether the string ends with the given suffix.
11
 *
12
 * Example:
13
 *
14
 *      Str\ends_with('Hello, World', 'd')
15
 *      => Bool(true)
16
 *
17
 *      Str\ends_with('Hello, World', 'D')
18
 *      => Bool(false)
19
 *
20
 *      Str\ends_with('Hello, World', 'world')
21
 *      => Bool(false)
22
 *
23
 *      Str\ends_with('Hello, World', 'World')
24
 *      => Bool(true)
25
 *
26
 *      Str\ends_with('Tunisia', 'e')
27
 *      => Bool(false)
28
 *
29
 *      Str\ends_with('تونس', 'س')
30
 *      => Bool(true)
31
 *
32
 *      Str\ends_with('تونس', 'ش')
33
 *      => Bool(false)
34
 *
35
 * @pure
36
 */
37
function ends_with(string $string, string $suffix, Encoding $encoding = Encoding::Utf8): bool
38
{
39
    if ('' === $suffix) {
44✔
40
        return false;
1✔
41
    }
42

43
    if ($encoding === Encoding::Ascii || $encoding === Encoding::Utf8) {
43✔
44
        return str_ends_with($string, $suffix);
43✔
45
    }
46

UNCOV
47
    if ($suffix === $string) {
×
UNCOV
48
        return true;
×
49
    }
50

UNCOV
51
    $suffix_length = length($suffix, $encoding);
×
UNCOV
52
    $total_length = length($string, $encoding);
×
UNCOV
53
    if ($suffix_length > $total_length) {
×
UNCOV
54
        return false;
×
55
    }
56

UNCOV
57
    $position = search_last($string, $suffix, 0, $encoding);
×
UNCOV
58
    if (null === $position) {
×
UNCOV
59
        return false;
×
60
    }
61

UNCOV
62
    return ($position + $suffix_length) === $total_length;
×
63
}
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