Completed
Push — master ( 495169...b31514 )
by Changwan
10:11
created

Route::middleware()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 4
nop 2
dl 0
loc 10
ccs 7
cts 7
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Wandu\Router;
3
4
use Wandu\Router\Contracts\RouteFluent;
5
use Wandu\Router\Contracts\RouteInformation;
6
7
class Route implements RouteFluent, RouteInformation
8
{
9
    /** @var string */
10
    protected $className;
11
12
    /** @var string */
13
    protected $methodName;
14
15
    /** @var array */
16
    protected $middlewares;
17
18
    /** @var array */
19
    protected $domains;
20
21
    /**
22
     * @param string $className
23
     * @param string $methodName
24
     * @param string|array $middlewares
25
     * @param string|array $domains
26
     */
27 23
    public function __construct($className, $methodName, $middlewares = [], $domains = [])
28
    {
29 23
        $this->className = $className;
30 23
        $this->methodName = $methodName;
31 23
        $this->middlewares = is_array($middlewares) ? $middlewares : [$middlewares];
32 23
        $this->domains = is_array($domains) ? $domains : [$domains];
33 23
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 1
    public function middleware($middlewares, $overwrite = false): RouteFluent
39
    {
40 1
        if (is_string($middlewares)) {
41 1
            $middlewares = [$middlewares];
42
        }
43 1
        $this->middlewares = $overwrite
44 1
            ? $middlewares
45 1
            : array_merge($this->middlewares, $middlewares);
46 1
        return $this;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 1
    public function domains($domains = []): RouteFluent
53
    {
54 1
        if (is_string($domains)) {
55
            $domains = [$domains];
56
        }
57 1
        $this->domains = $domains;
58 1
        return $this;
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 19
    public function getDomains(): array
65
    {
66 19
        return $this->domains;
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72 21
    public function getClassName(): string
73
    {
74 21
        return $this->className;
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80 21
    public function getMethodName(): string
81
    {
82 21
        return $this->methodName;
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88 22
    public function getMiddlewares(): array
89
    {
90 22
        return $this->middlewares;
91
    }
92
}
93