Passed
Push — master ( d4332b...caf529 )
by Melech
01:23
created

Parameter::getValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Valkyrja Framework package.
7
 *
8
 * (c) Melech Mizrachi <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Valkyrja\Http\Routing\Data;
15
16
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Valkyrja\Http\Routing\Data\Contract\Parameter as Contract;
18
use Valkyrja\Type\Data\Cast;
19
20
/**
21
 * Class Parameter.
22
 *
23
 * @author Melech Mizrachi
24
 */
25
class Parameter implements Contract
26
{
27
    /**
28
     * @param non-empty-string                        $name    The parameter's name
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
29
     * @param non-empty-string                        $regex   The parameter's regex
30
     * @param array<scalar|object>|scalar|object|null $default The default value
31
     * @param array<scalar|object>|scalar|object|null $value   The value
32
     */
33
    public function __construct(
34
        protected string $name,
35
        protected string $regex,
36
        protected Cast|null $cast = null,
37
        protected bool $isOptional = false,
38
        protected bool $shouldCapture = true,
39
        protected array|string|int|bool|float|object|null $default = null,
40
        protected array|string|int|bool|float|object|null $value = null,
41
    ) {
42
    }
43
44
    /**
45
     * @inheritDoc
46
     */
47
    #[Override]
48
    public function getName(): string
49
    {
50
        return $this->name;
51
    }
52
53
    /**
54
     * @inheritDoc
55
     */
56
    #[Override]
57
    public function withName(string $name): static
58
    {
59
        $new = clone $this;
60
61
        $new->name = $name;
62
63
        return $new;
64
    }
65
66
    /**
67
     * @inheritDoc
68
     */
69
    #[Override]
70
    public function getRegex(): string
71
    {
72
        return $this->regex;
73
    }
74
75
    /**
76
     * @inheritDoc
77
     */
78
    #[Override]
79
    public function withRegex(string $regex): static
80
    {
81
        $new = clone $this;
82
83
        $new->regex = $regex;
84
85
        return $new;
86
    }
87
88
    /**
89
     * @inheritDoc
90
     */
91
    #[Override]
92
    public function getCast(): Cast|null
93
    {
94
        return $this->cast;
95
    }
96
97
    /**
98
     * @inheritDoc
99
     */
100
    #[Override]
101
    public function withCast(Cast|null $cast = null): static
102
    {
103
        $new = clone $this;
104
105
        $new->cast = $cast;
106
107
        return $new;
108
    }
109
110
    /**
111
     * @inheritDoc
112
     */
113
    #[Override]
114
    public function isOptional(): bool
115
    {
116
        return $this->isOptional;
117
    }
118
119
    /**
120
     * @inheritDoc
121
     */
122
    #[Override]
123
    public function withIsOptional(bool $isOptional): static
124
    {
125
        $new = clone $this;
126
127
        $new->isOptional = $isOptional;
128
129
        return $new;
130
    }
131
132
    /**
133
     * @inheritDoc
134
     */
135
    #[Override]
136
    public function shouldCapture(): bool
137
    {
138
        return $this->shouldCapture;
139
    }
140
141
    /**
142
     * @inheritDoc
143
     */
144
    #[Override]
145
    public function withShouldCapture(bool $shouldCapture): static
146
    {
147
        $new = clone $this;
148
149
        $new->shouldCapture = $shouldCapture;
150
151
        return $new;
152
    }
153
154
    /**
155
     * @inheritDoc
156
     */
157
    #[Override]
158
    public function getDefault(): array|string|int|bool|float|object|null
159
    {
160
        return $this->default;
161
    }
162
163
    /**
164
     * @inheritDoc
165
     */
166
    #[Override]
167
    public function withDefault(array|string|int|bool|float|object|null $default = null): static
168
    {
169
        $new = clone $this;
170
171
        $new->default = $default;
172
173
        return $new;
174
    }
175
176
    /**
177
     * @inheritDoc
178
     */
179
    #[Override]
180
    public function getValue(): array|string|int|bool|float|object|null
181
    {
182
        return $this->value;
183
    }
184
185
    /**
186
     * @inheritDoc
187
     */
188
    #[Override]
189
    public function withValue(array|string|int|bool|float|object|null $value = null): static
190
    {
191
        $new = clone $this;
192
193
        $new->value = $value;
194
195
        return $new;
196
    }
197
}
198