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

api-platform / core / 16051339889

03 Jul 2025 01:10PM UTC coverage: 22.566% (+0.3%) from 22.272%
16051339889

push

github

soyuka
docs: changelog 4.1.18

11120 of 49277 relevant lines covered (22.57%)

23.24 hits per line

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

64.29
/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
     * @param ?bool                                                              $castToNativeType whether API Platform should cast your parameter to the nativeType declared
35
     * @param ?callable(mixed): mixed                                            $castFn           the closure used to cast your parameter, this gets called only when $castToNativeType is set
36
     */
37
    public function __construct(
38
        protected ?string $key = null,
39
        protected ?array $schema = null,
40
        protected OpenApiParameter|array|false|null $openApi = null,
41
        protected mixed $provider = null,
42
        protected mixed $filter = null,
43
        protected ?string $property = null,
44
        protected ?string $description = null,
45
        protected ?array $properties = null,
46
        protected ?bool $required = null,
47
        protected ?int $priority = null,
48
        protected ?false $hydra = null,
49
        protected mixed $constraints = null,
50
        protected string|\Stringable|null $security = null,
51
        protected ?string $securityMessage = null,
52
        protected ?array $extraProperties = [],
53
        protected array|string|null $filterContext = null,
54
        protected ?Type $nativeType = null,
55
        protected ?bool $castToArray = null,
56
        protected ?bool $castToNativeType = null,
57
        protected mixed $castFn = null,
58
    ) {
59
    }
116✔
60

61
    public function getKey(): ?string
62
    {
63
        return $this->key;
358✔
64
    }
65

66
    /**
67
     * @return (array<string, mixed>&array{type?: string, default?: string})|null $schema
68
     */
69
    public function getSchema(): ?array
70
    {
71
        return $this->schema;
480✔
72
    }
73

74
    /**
75
     * @return OpenApiParameter[]|OpenApiParameter|bool|null
76
     */
77
    public function getOpenApi(): OpenApiParameter|array|bool|null
78
    {
79
        return $this->openApi;
48✔
80
    }
81

82
    public function getProvider(): mixed
83
    {
84
        return $this->provider;
450✔
85
    }
86

87
    public function getProperty(): ?string
88
    {
89
        return $this->property;
216✔
90
    }
91

92
    public function getFilter(): mixed
93
    {
94
        return $this->filter;
220✔
95
    }
96

97
    public function getDescription(): ?string
98
    {
99
        return $this->description;
18✔
100
    }
101

102
    public function getRequired(): ?bool
103
    {
104
        return $this->required;
210✔
105
    }
106

107
    public function getPriority(): ?int
108
    {
109
        return $this->priority;
28✔
110
    }
111

112
    public function getHydra(): ?bool
113
    {
114
        return $this->hydra;
206✔
115
    }
116

117
    public function getConstraints(): mixed
118
    {
119
        return $this->constraints;
468✔
120
    }
121

122
    public function getSecurity(): string|\Stringable|null
123
    {
124
        return $this->security;
292✔
125
    }
126

127
    public function getSecurityMessage(): ?string
128
    {
129
        return $this->securityMessage;
8✔
130
    }
131

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

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

150
        return $this;
470✔
151
    }
152

153
    /**
154
     * @return array<string, mixed>
155
     */
156
    public function getExtraProperties(): array
157
    {
158
        return $this->extraProperties;
472✔
159
    }
160

161
    public function getFilterContext(): array|string|null
162
    {
163
        return $this->filterContext;
154✔
164
    }
165

166
    public function withKey(string $key): static
167
    {
168
        $self = clone $this;
220✔
169
        $self->key = $key;
220✔
170

171
        return $self;
220✔
172
    }
173

174
    public function withPriority(int $priority): static
175
    {
176
        $self = clone $this;
28✔
177
        $self->priority = $priority;
28✔
178

179
        return $self;
28✔
180
    }
181

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

190
        return $self;
18✔
191
    }
192

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

201
        return $self;
10✔
202
    }
203

204
    /**
205
     * @param ParameterProviderInterface|string $provider
206
     */
207
    public function withProvider(mixed $provider): static
208
    {
209
        $self = clone $this;
6✔
210
        $self->provider = $provider;
6✔
211

212
        return $self;
6✔
213
    }
214

215
    /**
216
     * @param FilterInterface|string $filter
217
     */
218
    public function withFilter(mixed $filter): static
219
    {
220
        $self = clone $this;
×
221
        $self->filter = $filter;
×
222

223
        return $self;
×
224
    }
225

226
    public function withFilterContext(array|string $filterContext): static
227
    {
228
        $self = clone $this;
×
229
        $self->filterContext = $filterContext;
×
230

231
        return $self;
×
232
    }
233

234
    public function withProperty(string $property): static
235
    {
236
        $self = clone $this;
20✔
237
        $self->property = $property;
20✔
238

239
        return $self;
20✔
240
    }
241

242
    public function withDescription(string $description): static
243
    {
244
        $self = clone $this;
×
245
        $self->description = $description;
×
246

247
        return $self;
×
248
    }
249

250
    public function withRequired(bool $required): static
251
    {
252
        $self = clone $this;
×
253
        $self->required = $required;
×
254

255
        return $self;
×
256
    }
257

258
    public function withHydra(false $hydra): static
259
    {
260
        $self = clone $this;
×
261
        $self->hydra = $hydra;
×
262

263
        return $self;
×
264
    }
265

266
    public function withConstraints(mixed $constraints): static
267
    {
268
        $self = clone $this;
14✔
269
        $self->constraints = $constraints;
14✔
270

271
        return $self;
14✔
272
    }
273

274
    public function withSecurity(string|\Stringable|null $security): static
275
    {
276
        $self = clone $this;
×
277
        $self->security = $security;
×
278

279
        return $self;
×
280
    }
281

282
    public function withSecurityMessage(?string $securityMessage): static
283
    {
284
        $self = clone $this;
×
285
        $self->securityMessage = $securityMessage;
×
286

287
        return $self;
×
288
    }
289

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

298
        return $self;
10✔
299
    }
300

301
    public function getProperties(): ?array
302
    {
303
        return $this->properties;
58✔
304
    }
305

306
    public function withProperties(?array $properties): self
307
    {
308
        $self = clone $this;
×
309
        $self->properties = $properties;
×
310

311
        return $self;
×
312
    }
313

314
    public function getNativeType(): ?Type
315
    {
316
        return $this->nativeType;
336✔
317
    }
318

319
    public function withNativeType(Type $nativeType): self
320
    {
321
        $self = clone $this;
24✔
322
        $self->nativeType = $nativeType;
24✔
323

324
        return $self;
24✔
325
    }
326

327
    public function getCastToArray(): ?bool
328
    {
329
        return $this->castToArray;
106✔
330
    }
331

332
    public function withCastToArray(bool $castToArray): self
333
    {
334
        $self = clone $this;
×
335
        $self->castToArray = $castToArray;
×
336

337
        return $self;
×
338
    }
339

340
    public function getCastToNativeType(): ?bool
341
    {
342
        return $this->castToNativeType;
334✔
343
    }
344

345
    public function withCastToNativeType(bool $castToNativeType): self
346
    {
347
        $self = clone $this;
×
348
        $self->castToNativeType = $castToNativeType;
×
349

350
        return $self;
×
351
    }
352

353
    public function getCastFn(): ?callable
354
    {
355
        return $this->castFn;
62✔
356
    }
357

358
    /**
359
     * @param callable(mixed): mixed $castFn
360
     */
361
    public function withCastFn(mixed $castFn): self
362
    {
363
        $self = clone $this;
2✔
364
        $self->castFn = $castFn;
2✔
365

366
        return $self;
2✔
367
    }
368
}
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