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

azjezz / psl / 22680264557

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

Pull #610

github

azjezz
perf: optimizations

Signed-off-by: azjezz <azjezz@protonmail.com>
Pull Request #610: perf: replace PSL calls with native PHP builtins and fix O(n2) algorithms

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

42.86
/src/Psl/Str/replace.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Psl\Str;
6

7
use function str_replace;
8

9
/**
10
 * Returns the 'haystack' string with all occurrences of `$needle` replaced by
11
 * `$replacement`.
12
 *
13
 * @pure
14
 */
15
function replace(string $haystack, string $needle, string $replacement, Encoding $encoding = Encoding::Utf8): string
16
{
17
    if ('' === $needle) {
17✔
NEW
18
        return $haystack;
×
19
    }
20

21
    if ($encoding === Encoding::Ascii || $encoding === Encoding::Utf8) {
17✔
22
        return str_replace($needle, $replacement, $haystack);
17✔
23
    }
24

NEW
25
    if (null === search($haystack, $needle, 0, $encoding)) {
×
UNCOV
26
        return $haystack;
×
27
    }
28

UNCOV
29
    return str_replace($needle, $replacement, $haystack);
×
30
}
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