Passed
Pull Request — master (#60)
by
unknown
10:40
created

Definition::getPort()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Router\Route;
6
7
final class Definition implements DefinitionInterface
8
{
9
    private string $path;
10
    private array $methods;
11
    private ?string $name;
12
    private ?string $host;
13
    private array $schemes;
14
    private ?int $port;
15
    private array $accepts;
16
    private array $defaults;
17
18
    public function __construct(
19
        string $path,
20
        array $methods = [],
21
        ?string $name = null,
22
        ?string $host = null,
23
        array $schemes = [],
24
        ?int $port = null,
25
        array $accepts = [],
26
        array $defaults = []
27
    ) {
28
        $this->path = $path;
29
        $this->methods = $methods;
30
        $this->name = $name;
31
        $this->host = $host;
32
        $this->schemes = $schemes;
33
        $this->port = $port;
34
        $this->accepts = $accepts;
35
        $this->defaults = $defaults;
36
    }
37
38
    public function serialize(): string
39
    {
40
        // TODO: Implement serialize() method.
41
        return '';
42
    }
43
44
    public function unserialize($serialized): void
45
    {
46
        // TODO: Implement unserialize() method.
47
    }
48
49
    public function getPath(): string
50
    {
51
        return $this->path;
52
    }
53
54
    public function withPath(string $path): self
55
    {
56
        $definition = clone $this;
57
        $definition->path = $path;
58
        return $definition;
59
    }
60
61
    public function getHost(): ?string
62
    {
63
        return $this->host;
64
    }
65
66
    public function withHost(?string $host): self
67
    {
68
        $definition = clone $this;
69
        $definition->host = $host;
70
        return $definition;
71
    }
72
73
    public function getSchemes(): array
74
    {
75
        return $this->schemes;
76
    }
77
78
    public function withSchemes(array $schemes): self
79
    {
80
        $definition = clone $this;
81
        $definition->schemes = $schemes;
82
        return $definition;
83
    }
84
85
    public function getDefaults(): array
86
    {
87
        return $this->defaults;
88
    }
89
90
    public function withDefaults(array $defaults): self
91
    {
92
        $definition = clone $this;
93
        $definition->defaults = $defaults;
94
        return $definition;
95
    }
96
97
    public function getMethods(): array
98
    {
99
        return $this->methods;
100
    }
101
102
    public function withMethods(array $methods): self
103
    {
104
        $definition = clone $this;
105
        $definition->methods = $methods;
106
        return $definition;
107
    }
108
109
    public function getName(): string
110
    {
111
        return $this->name;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->name could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
112
    }
113
114
    public function withName(string $name): self
115
    {
116
        $definition = clone $this;
117
        $definition->name = $name;
118
        return $definition;
119
    }
120
121
    public function getPort(): ?int
122
    {
123
        return $this->port;
124
    }
125
126
    public function withPort(?int $port): self
127
    {
128
        $definition = clone $this;
129
        $definition->port = $port;
130
        return $definition;
131
    }
132
133
    public function getAccepts(): ?array
134
    {
135
        return $this->accepts;
136
    }
137
138
    public function withAccepts(array $accepts): self
139
    {
140
        $definition = clone $this;
141
        $definition->accepts = $accepts;
142
        return $definition;
143
    }
144
}
145