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

letsdrink / ouzo / 5387077385

pending completion
5387077385

push

github

web-flow
Fix StrSubstitutor for php 8.2 (#313)

3 of 3 new or added lines in 1 file covered. (100.0%)

4978 of 5788 relevant lines covered (86.01%)

101.21 hits per line

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

90.0
/src/Ouzo/Goodies/Utilities/StrSubstitutor.php
1
<?php
2
/*
3
 * Copyright (c) Ouzo contributors, https://github.com/letsdrink/ouzo
4
 * This file is made available under the MIT License (view the LICENSE file for more information).
5
 */
6

7
namespace Ouzo\Utilities;
8

9
readonly class StrSubstitutor
10
{
11
    private const START = '{{';
12
    private const END = '}}';
13

14
    public function __construct(
15
        private array $values = [],
16
        private ?string $default = null
17
    )
18
    {
19
    }
45✔
20

21
    public function replace(?string $string): string
22
    {
23
        if (is_null($string)) {
45✔
24
            return Strings::EMPTY;
×
25
        }
26

27
        $start = preg_quote(self::START);
45✔
28
        $end = preg_quote(self::END);
45✔
29
        return preg_replace_callback("/{$start}(.+?){$end}/u", [$this, 'replaceVars'], $string);
45✔
30
    }
31

32
    private function replaceVars(array $match): string
33
    {
34
        $matched = $match[0];
45✔
35
        $name = $match[1];
45✔
36
        $default = is_null($this->default) ? $matched : $this->default;
45✔
37
        return $this->values[$name] ?? $default;
45✔
38
    }
39
}
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