PatternReplacer   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 7
c 1
b 0
f 0
dl 0
loc 11
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A replace() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Furious\Router\Pattern;
6
7
final class PatternReplacer
8
{
9
    private const REGEXP = "#\{([^\}]+)\}#";
10
11
    public function replace(string $pattern, array $tokens): string
12
    {
13
        return preg_replace_callback(self::REGEXP, function ($matches) use ($tokens) {
14
            $argument = $matches[1];
15
            $replace = $tokens[$argument] ?? '[^}]+';
16
            return '(?P<' . $argument . '>' . $replace . ')';
17
        }, $pattern);
18
    }
19
}