• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 15775135891

20 Jun 2025 08:42AM UTC coverage: 22.065% (+0.2%) from 21.876%
15775135891

push

github

soyuka
Merge 4.1

13 of 103 new or added lines in 10 files covered. (12.62%)

868 existing lines in 35 files now uncovered.

11487 of 52060 relevant lines covered (22.06%)

21.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

64.47
/src/Metadata/Parameter.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\Metadata;
15

16
use ApiPlatform\OpenApi\Model\Parameter as OpenApiParameter;
17
use ApiPlatform\State\ParameterNotFound;
18
use ApiPlatform\State\ParameterProviderInterface;
19
use Symfony\Component\TypeInfo\Type;
20

21
/**
22
 * @experimental
23
 */
24
abstract class Parameter
25
{
26
    /**
27
     * @param (array<string, mixed>&array{type?: string, default?: string})|null $schema
28
     * @param array<string, mixed>                                               $extraProperties
29
     * @param ParameterProviderInterface|callable|string|null                    $provider
30
     * @param list<string>                                                       $properties      a list of properties this parameter applies to (works with the :property placeholder)
31
     * @param FilterInterface|string|null                                        $filter
32
     * @param mixed                                                              $constraints     an array of Symfony constraints, or an array of Laravel rules
33
     * @param Type                                                               $nativeType      the PHP native type, we cast values to an array if its a CollectionType, if not and it's an array with a single value we use it (eg: HTTP Header)
34
     */
35
    public function __construct(
36
        protected ?string $key = null,
37
        protected ?array $schema = null,
38
        protected OpenApiParameter|array|false|null $openApi = null,
39
        protected mixed $provider = null,
40
        protected mixed $filter = null,
41
        protected ?string $property = null,
42
        protected ?string $description = null,
43
        protected ?array $properties = null,
44
        protected ?bool $required = null,
45
        protected ?int $priority = null,
46
        protected ?false $hydra = null,
47
        protected mixed $constraints = null,
48
        protected string|\Stringable|null $security = null,
49
        protected ?string $securityMessage = null,
50
        protected ?array $extraProperties = [],
51
        protected array|string|null $filterContext = null,
52
        protected ?Type $nativeType = null,
53
        protected ?bool $castToArray = null,
54
    ) {
55
    }
126✔
56

57
    public function getKey(): ?string
58
    {
59
        return $this->key;
290✔
60
    }
61

62
    /**
63
     * @return (array<string, mixed>&array{type?: string, default?: string})|null $schema
64
     */
65
    public function getSchema(): ?array
66
    {
67
        return $this->schema;
410✔
68
    }
69

70
    /**
71
     * @return OpenApiParameter[]|OpenApiParameter|bool|null
72
     */
73
    public function getOpenApi(): OpenApiParameter|array|bool|null
74
    {
75
        return $this->openApi;
50✔
76
    }
77

78
    public function getProvider(): mixed
79
    {
80
        return $this->provider;
386✔
81
    }
82

83
    public function getProperty(): ?string
84
    {
85
        return $this->property;
216✔
86
    }
87

88
    public function getFilter(): mixed
89
    {
90
        return $this->filter;
220✔
91
    }
92

93
    public function getDescription(): ?string
94
    {
95
        return $this->description;
18✔
96
    }
97

98
    public function getRequired(): ?bool
99
    {
100
        return $this->required;
210✔
101
    }
102

103
    public function getPriority(): ?int
104
    {
105
        return $this->priority;
28✔
106
    }
107

108
    public function getHydra(): ?bool
109
    {
110
        return $this->hydra;
206✔
111
    }
112

113
    public function getConstraints(): mixed
114
    {
115
        return $this->constraints;
398✔
116
    }
117

118
    public function getSecurity(): string|\Stringable|null
119
    {
120
        return $this->security;
248✔
121
    }
122

123
    public function getSecurityMessage(): ?string
124
    {
125
        return $this->securityMessage;
8✔
126
    }
127

128
    /**
129
     * The computed value of this parameter, located into extraProperties['_api_values'].
130
     */
131
    public function getValue(mixed $default = new ParameterNotFound()): mixed
132
    {
133
        return $this->extraProperties['_api_values'] ?? $default;
400✔
134
    }
135

136
    /**
137
     * Only use this in a parameter provider, the ApiPlatform\State\Provider\ParameterProvider
138
     * resets this value to extract the correct value on each request.
139
     * It's also possible to set the `_api_query_parameters` request attribute directly and
140
     * API Platform will extract the value from there.
141
     */
142
    public function setValue(mixed $value): static
143
    {
144
        $this->extraProperties['_api_values'] = $value;
400✔
145

146
        return $this;
400✔
147
    }
148

149
    /**
150
     * @return array<string, mixed>
151
     */
152
    public function getExtraProperties(): array
153
    {
154
        return $this->extraProperties;
402✔
155
    }
156

157
    public function getFilterContext(): array|string|null
158
    {
159
        return $this->filterContext;
154✔
160
    }
161

162
    public function withKey(string $key): static
163
    {
164
        $self = clone $this;
194✔
165
        $self->key = $key;
194✔
166

167
        return $self;
194✔
168
    }
169

170
    public function withPriority(int $priority): static
171
    {
172
        $self = clone $this;
28✔
173
        $self->priority = $priority;
28✔
174

175
        return $self;
28✔
176
    }
177

178
    /**
179
     * @param array{type?: string} $schema
180
     */
181
    public function withSchema(array $schema): static
182
    {
183
        $self = clone $this;
18✔
184
        $self->schema = $schema;
18✔
185

186
        return $self;
18✔
187
    }
188

189
    /**
190
     * @param OpenApiParameter[]|OpenApiParameter|bool $openApi
191
     */
192
    public function withOpenApi(OpenApiParameter|array|bool $openApi): static
193
    {
194
        $self = clone $this;
10✔
195
        $self->openApi = $openApi;
10✔
196

197
        return $self;
10✔
198
    }
199

200
    /**
201
     * @param ParameterProviderInterface|string $provider
202
     */
203
    public function withProvider(mixed $provider): static
204
    {
205
        $self = clone $this;
6✔
206
        $self->provider = $provider;
6✔
207

208
        return $self;
6✔
209
    }
210

211
    /**
212
     * @param FilterInterface|string $filter
213
     */
214
    public function withFilter(mixed $filter): static
215
    {
UNCOV
216
        $self = clone $this;
×
UNCOV
217
        $self->filter = $filter;
×
218

219
        return $self;
×
220
    }
221

222
    public function withFilterContext(array|string $filterContext): static
223
    {
UNCOV
224
        $self = clone $this;
×
UNCOV
225
        $self->filterContext = $filterContext;
×
226

UNCOV
227
        return $self;
×
228
    }
229

230
    public function withProperty(string $property): static
231
    {
232
        $self = clone $this;
20✔
233
        $self->property = $property;
20✔
234

235
        return $self;
20✔
236
    }
237

238
    public function withDescription(string $description): static
239
    {
UNCOV
240
        $self = clone $this;
×
UNCOV
241
        $self->description = $description;
×
242

243
        return $self;
×
244
    }
245

246
    public function withRequired(bool $required): static
247
    {
UNCOV
248
        $self = clone $this;
×
UNCOV
249
        $self->required = $required;
×
250

251
        return $self;
×
252
    }
253

254
    public function withHydra(false $hydra): static
255
    {
UNCOV
256
        $self = clone $this;
×
UNCOV
257
        $self->hydra = $hydra;
×
258

UNCOV
259
        return $self;
×
260
    }
261

262
    public function withConstraints(mixed $constraints): static
263
    {
264
        $self = clone $this;
12✔
265
        $self->constraints = $constraints;
12✔
266

267
        return $self;
12✔
268
    }
269

270
    public function withSecurity(string|\Stringable|null $security): static
271
    {
UNCOV
272
        $self = clone $this;
×
UNCOV
273
        $self->security = $security;
×
274

275
        return $self;
×
276
    }
277

278
    public function withSecurityMessage(?string $securityMessage): static
279
    {
UNCOV
280
        $self = clone $this;
×
UNCOV
281
        $self->securityMessage = $securityMessage;
×
282

UNCOV
283
        return $self;
×
284
    }
285

286
    /**
287
     * @param array<string, mixed> $extraProperties
288
     */
289
    public function withExtraProperties(array $extraProperties): static
290
    {
291
        $self = clone $this;
10✔
292
        $self->extraProperties = $extraProperties;
10✔
293

294
        return $self;
10✔
295
    }
296

297
    public function getProperties(): ?array
298
    {
299
        return $this->properties;
58✔
300
    }
301

302
    public function withProperties(?array $properties): self
303
    {
UNCOV
304
        $self = clone $this;
×
UNCOV
305
        $self->properties = $properties;
×
306

UNCOV
307
        return $self;
×
308
    }
309

310
    public function getNativeType(): ?Type
311
    {
312
        return $this->nativeType;
276✔
313
    }
314

315
    public function withNativeType(Type $nativeType): self
316
    {
317
        $self = clone $this;
24✔
318
        $self->nativeType = $nativeType;
24✔
319

320
        return $self;
24✔
321
    }
322

323
    public function getCastToArray(): ?bool
324
    {
325
        return $this->castToArray;
128✔
326
    }
327

328
    public function withCastToArray(bool $castToArray): self
329
    {
UNCOV
330
        $self = clone $this;
×
UNCOV
331
        $self->castToArray = $castToArray;
×
332

UNCOV
333
        return $self;
×
334
    }
335
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc