Completed
Push — master ( 27d2f2...3153a3 )
by Changwan
04:10
created

Route::domains()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
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
    /** @var string */
24
    protected $name;
25
26
    /**
27
     * @param string $className
28
     * @param string $methodName
29
     * @param array $middlewares
30
     * @param array $domains
31
     */
32 32
    public function __construct($className, $methodName, array $middlewares = [], array $domains = [])
33
    {
34 32
        $this->className = $className;
35 32
        $this->methodName = $methodName;
36 32
        $this->middlewares = $middlewares;
37 32
        $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...
38 32
    }
39
40
    /**
41
     * @param string|array $middlewares
42
     * @param bool $overwrite
43
     * @return \Wandu\Router\Contracts\Route|self
44
     */
45 1
    public function middleware($middlewares, $overwrite = false): RouteContract
46
    {
47 1
        if (is_string($middlewares)) {
48 1
            $middlewares = [$middlewares];
49
        }
50 1
        $this->middlewares = $overwrite
51
            ? $middlewares
52 1
            : array_merge($this->middlewares, $middlewares);
53 1
        return $this;
54
    }
55
56
    /**
57
     * @param string $name
58
     * @return \Wandu\Router\Contracts\Route|self
59
     */
60 1
    public function name(string $name): RouteContract
61
    {
62 1
        $this->name = $name;
63 1
        return $this;
64
    }
65
66
    /**
67
     * @internal
68
     * @return string
69
     */
70 25
    public function getName()
71
    {
72 25
        return $this->name;
73
    }
74
75
    /**
76
     * @param string $domains
77
     * @return \Wandu\Router\Route|self
78
     */
79
    public function domains(string $domains)
80
    {
81
        $this->domains = $domains;
82
        return $this;
83
    }
84
85
    /**
86
     * @return array
87
     */
88 23
    public function getDomains()
89
    {
90 23
        return $this->domains;
91
    }
92
    
93
    /**
94
     * @param \Psr\Http\Message\ServerRequestInterface $request
95
     * @param \Wandu\Router\Contracts\LoaderInterface|null $loader
96
     * @param \Wandu\Router\Contracts\ResponsifierInterface|null $responsifier
97
     * @return \Psr\Http\Message\ResponseInterface
98
     */
99 28
    public function execute(
100
        ServerRequestInterface $request,
101
        LoaderInterface $loader = null,
102
        ResponsifierInterface $responsifier = null
103
    ) {
104 28
        $pipeline = new RouteExecutor($loader, $responsifier);
105 28
        return $pipeline->execute($request, $this->className, $this->methodName, $this->middlewares);
106
    }
107
}
108