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

api-platform / core / 15955912273

29 Jun 2025 01:51PM UTC coverage: 22.057% (-0.03%) from 22.082%
15955912273

Pull #7249

github

web-flow
Merge d9904d788 into a42034dc3
Pull Request #7249: chore: solve some phpstan issues

0 of 9 new or added lines in 8 files covered. (0.0%)

11540 existing lines in 372 files now uncovered.

11522 of 52237 relevant lines covered (22.06%)

11.08 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
    ) {
UNCOV
55
    }
64✔
56

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

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

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

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

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

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

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

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

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

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

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

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

123
    public function getSecurityMessage(): ?string
124
    {
UNCOV
125
        return $this->securityMessage;
4✔
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
    {
UNCOV
133
        return $this->extraProperties['_api_values'] ?? $default;
201✔
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
    {
UNCOV
144
        $this->extraProperties['_api_values'] = $value;
201✔
145

UNCOV
146
        return $this;
201✔
147
    }
148

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

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

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

UNCOV
167
        return $self;
98✔
168
    }
169

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

UNCOV
175
        return $self;
14✔
176
    }
177

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

UNCOV
186
        return $self;
9✔
187
    }
188

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

UNCOV
197
        return $self;
5✔
198
    }
199

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

UNCOV
208
        return $self;
3✔
209
    }
210

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

219
        return $self;
×
220
    }
221

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

227
        return $self;
×
228
    }
229

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

UNCOV
235
        return $self;
10✔
236
    }
237

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

243
        return $self;
×
244
    }
245

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

251
        return $self;
×
252
    }
253

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

259
        return $self;
×
260
    }
261

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

UNCOV
267
        return $self;
6✔
268
    }
269

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

275
        return $self;
×
276
    }
277

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

283
        return $self;
×
284
    }
285

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

UNCOV
294
        return $self;
5✔
295
    }
296

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

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

307
        return $self;
×
308
    }
309

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

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

UNCOV
320
        return $self;
12✔
321
    }
322

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

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

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