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

api-platform / core / 20001323174

07 Dec 2025 08:10AM UTC coverage: 25.292% (+0.001%) from 25.291%
20001323174

push

github

soyuka
chore: bump metadata to 4.3.x-dev

14642 of 57891 relevant lines covered (25.29%)

28.94 hits per line

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

62.5
/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
abstract class Parameter
22
{
23
    /**
24
     * @param array<string, mixed>|null                       $schema
25
     * @param array<string, mixed>                            $extraProperties
26
     * @param ParameterProviderInterface|callable|string|null $provider
27
     * @param list<string>                                    $properties       a list of properties this parameter applies to (works with the :property placeholder)
28
     * @param FilterInterface|string|null                     $filter
29
     * @param mixed                                           $constraints      an array of Symfony constraints, or an array of Laravel rules
30
     * @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)
31
     * @param ?bool                                           $castToNativeType whether API Platform should cast your parameter to the nativeType declared
32
     * @param ?callable(mixed): mixed                         $castFn           the closure used to cast your parameter, this gets called only when $castToNativeType is set
33
     *
34
     * @phpstan-param array<string, mixed>|null $schema
35
     *
36
     * @psalm-param array{type?: string, default?: mixed, ...<string, mixed>}|null $schema
37
     */
38
    public function __construct(
39
        protected ?string $key = null,
40
        protected ?array $schema = null,
41
        protected OpenApiParameter|array|false|null $openApi = null,
42
        protected mixed $provider = null,
43
        protected mixed $filter = null,
44
        protected ?string $property = null,
45
        protected ?string $description = null,
46
        protected ?array $properties = null,
47
        protected ?bool $required = null,
48
        protected ?int $priority = null,
49
        protected ?false $hydra = null,
50
        protected mixed $constraints = null,
51
        protected string|\Stringable|null $security = null,
52
        protected ?string $securityMessage = null,
53
        protected ?array $extraProperties = [],
54
        protected array|string|null $filterContext = null,
55
        protected ?Type $nativeType = null,
56
        protected ?bool $castToArray = null,
57
        protected ?bool $castToNativeType = null,
58
        protected mixed $castFn = null,
59
        protected mixed $default = null,
60
    ) {
61
    }
156✔
62

63
    public function getKey(): ?string
64
    {
65
        return $this->key;
432✔
66
    }
67

68
    /**
69
     * @return array<string, mixed>|null
70
     *
71
     * @phpstan-return array<string, mixed>|null
72
     *
73
     * @psalm-return array{type?: string, default?: string, ...<string, mixed>}|null
74
     */
75
    public function getSchema(): ?array
76
    {
77
        return $this->schema;
606✔
78
    }
79

80
    /**
81
     * @return OpenApiParameter[]|OpenApiParameter|bool|null
82
     */
83
    public function getOpenApi(): OpenApiParameter|array|bool|null
84
    {
85
        return $this->openApi;
146✔
86
    }
87

88
    public function getProvider(): mixed
89
    {
90
        return $this->provider;
540✔
91
    }
92

93
    public function getProperty(): ?string
94
    {
95
        return $this->property;
274✔
96
    }
97

98
    public function getFilter(): mixed
99
    {
100
        return $this->filter;
274✔
101
    }
102

103
    public function getDescription(): ?string
104
    {
105
        return $this->description;
46✔
106
    }
107

108
    public function getRequired(): ?bool
109
    {
110
        return $this->required;
286✔
111
    }
112

113
    public function getPriority(): ?int
114
    {
115
        return $this->priority;
36✔
116
    }
117

118
    public function getHydra(): ?bool
119
    {
120
        return $this->hydra;
252✔
121
    }
122

123
    public function getConstraints(): mixed
124
    {
125
        return $this->constraints;
586✔
126
    }
127

128
    public function getSecurity(): string|\Stringable|null
129
    {
130
        return $this->security;
358✔
131
    }
132

133
    public function getSecurityMessage(): ?string
134
    {
135
        return $this->securityMessage;
8✔
136
    }
137

138
    /**
139
     * The computed value of this parameter, located into extraProperties['_api_values'].
140
     */
141
    public function getValue(mixed $default = new ParameterNotFound()): mixed
142
    {
143
        return $this->extraProperties['_api_values'] ?? $this->default ?? $default;
584✔
144
    }
145

146
    /**
147
     * Only use this in a parameter provider, the ApiPlatform\State\Provider\ParameterProvider
148
     * resets this value to extract the correct value on each request.
149
     * It's also possible to set the `_api_query_parameters` request attribute directly and
150
     * API Platform will extract the value from there.
151
     */
152
    public function setValue(mixed $value): static
153
    {
154
        $this->extraProperties['_api_values'] = $value;
584✔
155

156
        return $this;
584✔
157
    }
158

159
    /**
160
     * @return array<string, mixed>
161
     */
162
    public function getExtraProperties(): array
163
    {
164
        return $this->extraProperties;
584✔
165
    }
166

167
    public function getFilterContext(): array|string|null
168
    {
169
        return $this->filterContext;
158✔
170
    }
171

172
    public function withKey(string $key): static
173
    {
174
        $self = clone $this;
276✔
175
        $self->key = $key;
276✔
176

177
        return $self;
276✔
178
    }
179

180
    public function withPriority(int $priority): static
181
    {
182
        $self = clone $this;
36✔
183
        $self->priority = $priority;
36✔
184

185
        return $self;
36✔
186
    }
187

188
    /**
189
     * @param array{type?: string} $schema
190
     */
191
    public function withSchema(array $schema): static
192
    {
193
        $self = clone $this;
18✔
194
        $self->schema = $schema;
18✔
195

196
        return $self;
18✔
197
    }
198

199
    /**
200
     * @param OpenApiParameter[]|OpenApiParameter|bool $openApi
201
     */
202
    public function withOpenApi(OpenApiParameter|array|bool $openApi): static
203
    {
204
        $self = clone $this;
12✔
205
        $self->openApi = $openApi;
12✔
206

207
        return $self;
12✔
208
    }
209

210
    /**
211
     * @param ParameterProviderInterface|string $provider
212
     */
213
    public function withProvider(mixed $provider): static
214
    {
215
        $self = clone $this;
8✔
216
        $self->provider = $provider;
8✔
217

218
        return $self;
8✔
219
    }
220

221
    /**
222
     * @param FilterInterface|string $filter
223
     */
224
    public function withFilter(mixed $filter): static
225
    {
226
        $self = clone $this;
×
227
        $self->filter = $filter;
×
228

229
        return $self;
×
230
    }
231

232
    public function withFilterContext(array|string $filterContext): static
233
    {
234
        $self = clone $this;
×
235
        $self->filterContext = $filterContext;
×
236

237
        return $self;
×
238
    }
239

240
    public function withProperty(string $property): static
241
    {
242
        $self = clone $this;
34✔
243
        $self->property = $property;
34✔
244

245
        return $self;
34✔
246
    }
247

248
    public function withDescription(string $description): static
249
    {
250
        $self = clone $this;
×
251
        $self->description = $description;
×
252

253
        return $self;
×
254
    }
255

256
    public function withRequired(bool $required): static
257
    {
258
        $self = clone $this;
×
259
        $self->required = $required;
×
260

261
        return $self;
×
262
    }
263

264
    public function withHydra(false $hydra): static
265
    {
266
        $self = clone $this;
×
267
        $self->hydra = $hydra;
×
268

269
        return $self;
×
270
    }
271

272
    public function withConstraints(mixed $constraints): static
273
    {
274
        $self = clone $this;
14✔
275
        $self->constraints = $constraints;
14✔
276

277
        return $self;
14✔
278
    }
279

280
    public function withSecurity(string|\Stringable|null $security): static
281
    {
282
        $self = clone $this;
×
283
        $self->security = $security;
×
284

285
        return $self;
×
286
    }
287

288
    public function withSecurityMessage(?string $securityMessage): static
289
    {
290
        $self = clone $this;
×
291
        $self->securityMessage = $securityMessage;
×
292

293
        return $self;
×
294
    }
295

296
    /**
297
     * @param array<string, mixed> $extraProperties
298
     */
299
    public function withExtraProperties(array $extraProperties): static
300
    {
301
        $self = clone $this;
×
302
        $self->extraProperties = $extraProperties;
×
303

304
        return $self;
×
305
    }
306

307
    public function getProperties(): ?array
308
    {
309
        return $this->properties;
198✔
310
    }
311

312
    public function withProperties(?array $properties): self
313
    {
314
        $self = clone $this;
8✔
315
        $self->properties = $properties;
8✔
316

317
        return $self;
8✔
318
    }
319

320
    public function getNativeType(): ?Type
321
    {
322
        return $this->nativeType;
390✔
323
    }
324

325
    public function withNativeType(Type $nativeType): self
326
    {
327
        $self = clone $this;
32✔
328
        $self->nativeType = $nativeType;
32✔
329

330
        return $self;
32✔
331
    }
332

333
    public function getCastToArray(): ?bool
334
    {
335
        return $this->castToArray;
152✔
336
    }
337

338
    public function withCastToArray(bool $castToArray): self
339
    {
340
        $self = clone $this;
×
341
        $self->castToArray = $castToArray;
×
342

343
        return $self;
×
344
    }
345

346
    public function getCastToNativeType(): ?bool
347
    {
348
        return $this->castToNativeType;
386✔
349
    }
350

351
    public function withCastToNativeType(bool $castToNativeType): self
352
    {
353
        $self = clone $this;
×
354
        $self->castToNativeType = $castToNativeType;
×
355

356
        return $self;
×
357
    }
358

359
    public function getCastFn(): ?callable
360
    {
361
        return $this->castFn;
68✔
362
    }
363

364
    /**
365
     * @param callable(mixed): mixed $castFn
366
     */
367
    public function withCastFn(mixed $castFn): self
368
    {
369
        $self = clone $this;
4✔
370
        $self->castFn = $castFn;
4✔
371

372
        return $self;
4✔
373
    }
374

375
    public function getDefault(): mixed
376
    {
377
        return $this->default;
562✔
378
    }
379

380
    public function withDefault(mixed $default): self
381
    {
382
        $self = clone $this;
×
383
        $self->default = $default;
×
384

385
        return $self;
×
386
    }
387
}
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