Completed
Push — master ( 90174b...a197f9 )
by Changwan
03:50
created

Route::name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Wandu\Router;
3
4
use Psr\Http\Message\ServerRequestInterface;
5
use Wandu\Router\Contracts\LoaderInterface;
6
use Wandu\Router\Contracts\ResponsifierInterface;
7
use Wandu\Router\Contracts\Route as RouteContract;
8
9
class Route implements RouteContract
10
{
11
    /** @var string */
12
    protected $className;
13
14
    /** @var string */
15
    protected $methodName;
16
17
    /** @var array */
18
    protected $middlewares;
19
20
    /** @var string */
21
    protected $domains;
22
23
    /**
24
     * @param string $className
25
     * @param string $methodName
26
     * @param array $middlewares
27
     * @param array $domains
28
     */
29 31
    public function __construct($className, $methodName, array $middlewares = [], array $domains = [])
30
    {
31 31
        $this->className = $className;
32 31
        $this->methodName = $methodName;
33 31
        $this->middlewares = $middlewares;
34 31
        $this->domains = $domains;
0 ignored issues
show
Documentation Bug introduced by
It seems like $domains of type array is incompatible with the declared type string of property $domains.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
35 31
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 1
    public function middleware($middlewares, $overwrite = false): RouteContract
41
    {
42 1
        if (is_string($middlewares)) {
43 1
            $middlewares = [$middlewares];
44
        }
45 1
        $this->middlewares = $overwrite
46
            ? $middlewares
47 1
            : array_merge($this->middlewares, $middlewares);
48 1
        return $this;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function domains($domains): RouteContract
55
    {
56
        if (is_string($domains)) {
57
            $domains = [$domains];
58
        }
59
        $this->domains = $domains;
0 ignored issues
show
Documentation Bug introduced by
It seems like $domains of type array is incompatible with the declared type string of property $domains.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
60
        return $this;
61
    }
62
63
    /**
64
     * @return array
65
     */
66 24
    public function getDomains()
67
    {
68 24
        return $this->domains;
69
    }
70
    
71
    /**
72
     * @param \Psr\Http\Message\ServerRequestInterface $request
73
     * @param \Wandu\Router\Contracts\LoaderInterface|null $loader
74
     * @param \Wandu\Router\Contracts\ResponsifierInterface|null $responsifier
75
     * @return \Psr\Http\Message\ResponseInterface
76
     */
77 28
    public function execute(
78
        ServerRequestInterface $request,
79
        LoaderInterface $loader = null,
80
        ResponsifierInterface $responsifier = null
81
    ) {
82 28
        $pipeline = new RouteExecutor($loader, $responsifier);
83 28
        return $pipeline->execute($request, $this->className, $this->methodName, $this->middlewares);
84
    }
85
}
86