Completed
Push — master ( 8801ad...e19554 )
by Alexpts
02:50
created

RouteService   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 20
ccs 0
cts 10
cp 0
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
    public function makeRegExp(Route $route) : string
10
    {
11
        $regexp = $route->getPath();
12
        $restrictions = $route->getRestrictions();
13
14
        if (preg_match_all('~{(.*)}~Uu', $regexp, $placeholders)) {
15
            foreach ($placeholders[0] as $index => $match) {
16
                $name = $placeholders[1][$index];
17
                $replace = array_key_exists($name, $restrictions) ? $restrictions[$name] : '.*';
18
                $replace = '(?<'.$name.'>'.$replace.')';
19
                $regexp = str_replace($match, $replace, $regexp);
20
            }
21
        }
22
23
        return $regexp;
24
    }
25
}
26