RouteService   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 20
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A makeRegExp() 0 16 4
1
<?php
2
declare(strict_types = 1);
3
4
namespace PTS\Routing;
5
6
class RouteService
7
{
8
9 7
    public function makeRegExp(Route $route): string
10
    {
11 7
        $regexp = $route->getPath();
12 7
        $restrictions = $route->getRestrictions();
13
14 7
        if (preg_match_all('~{(.*)}~Uu', $regexp, $placeholders)) {
15 6
            foreach ($placeholders[0] as $index => $match) {
16 6
                $name = $placeholders[1][$index];
17 6
                $replace = array_key_exists($name, $restrictions) ? $restrictions[$name] : '[^\/]+';
18 6
                $replace = '(?<'.$name.'>'.$replace.')';
19 6
                $regexp = str_replace($match, $replace, $regexp);
20
            }
21
        }
22
23 7
        return $regexp;
24
    }
25
}
26