Passed
Push — master ( e07c1c...1a2cd1 )
by Alexey
04:26
created

RoutePathProcessor::process()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1.125

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
ccs 3
cts 6
cp 0.5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1.125
1
<?php declare(strict_types = 1);
2
3
namespace Venta\Routing;
4
5
use Venta\Contracts\Routing\Route as RouteContract;
6
use Venta\Contracts\Routing\RoutePathProcessor as RoutePathProcessorContract;
7
8
/**
9
 * Class RoutePathProcessor
10
 *
11
 * @package Venta\Routing
12
 */
13
class RoutePathProcessor implements RoutePathProcessorContract
14
{
15
16
    /**
17
     * @var string[]
18
     */
19
    private $patterns = ['/{\?(.+?)}/' => '[{$1}]'];
20
21
    /**
22
     * @inheritDoc
23
     */
24 2
    public function addPattern(string $placeholder, string $regex): RoutePathProcessorContract
25
    {
26 2
        $this->patterns["/{{$placeholder}}/"] = "{{$placeholder}:{$regex}}";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $placeholder instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $regex instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
27
28 2
        return $this;
29
    }
30
31
    /**
32
     * @inheritDoc
33
     */
34 2
    public function process(RouteContract $route): RouteContract
35
    {
36 2
        return $route->withPath(
37 2
            preg_replace(array_keys($this->patterns), array_values($this->patterns), $route->getPath())
38
        );
39
    }
40
41
42
}