• 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

40.0
/src/Psl/Str/replace_every.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Psl\Str;
6

7
use function array_keys;
8
use function array_values;
9
use function str_replace;
10

11
/**
12
 * Returns the '$haystack' string with all occurrences of the keys of
13
 * `$replacements` replaced by the corresponding values.
14
 *
15
 * @param array<string, string> $replacements
16
 *
17
 * @pure
18
 */
19
function replace_every(string $haystack, array $replacements, Encoding $encoding = Encoding::Utf8): string
20
{
21
    if ($encoding === Encoding::Ascii || $encoding === Encoding::Utf8) {
519✔
22
        return str_replace(array_keys($replacements), array_values($replacements), $haystack);
519✔
23
    }
24

UNCOV
25
    foreach ($replacements as $needle => $replacement) {
×
UNCOV
26
        $haystack = replace($haystack, $needle, $replacement, $encoding);
×
27
    }
28

UNCOV
29
    return $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