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

api-platform / core / 17054069864

18 Aug 2025 10:27PM UTC coverage: 21.952% (+0.2%) from 21.769%
17054069864

Pull #7151

github

web-flow
Merge 0da010d8d into 6491bfc7a
Pull Request #7151: fix: 7119 parameter array shape uses invalid syntax

11524 of 52497 relevant lines covered (21.95%)

11.86 hits per line

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

61.45
/src/Metadata/Metadata.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\State\OptionsInterface;
17

18
/**
19
 * @psalm-inheritors ApiResource|Operation
20
 */
21
abstract class Metadata
22
{
23
    protected ?Parameters $parameters = null;
24

25
    /**
26
     * @param class-string                                                                      $class
27
     * @param string|null                                                                       $deprecationReason       https://api-platform.com/docs/core/deprecations/#deprecating-resource-classes-operations-and-properties
28
     * @param string|\Stringable|null                                                           $security                https://api-platform.com/docs/core/security
29
     * @param string|\Stringable|null                                                           $securityPostDenormalize https://api-platform.com/docs/core/security/#executing-access-control-rules-after-denormalization
30
     * @param mixed|null                                                                        $mercure
31
     * @param mixed|null                                                                        $messenger
32
     * @param mixed|null                                                                        $input
33
     * @param mixed|null                                                                        $output
34
     * @param mixed|null                                                                        $provider
35
     * @param mixed|null                                                                        $processor
36
     * @param Parameters|array<string, Parameter>                                               $parameters
37
     * @param callable|string|array<string, \Illuminate\Contracts\Validation\Rule|array|string> $rules                   Laravel rules can be a FormRequest class, a callable or an array of rules
38
     */
39
    public function __construct(
40
        protected ?string $shortName = null,
41
        protected ?string $class = null,
42
        protected ?string $description = null,
43
        protected ?int $urlGenerationStrategy = null,
44
        protected ?string $deprecationReason = null,
45
        protected ?array $normalizationContext = null,
46
        protected ?array $denormalizationContext = null,
47
        protected ?bool $collectDenormalizationErrors = null,
48
        protected ?array $validationContext = null,
49
        protected ?array $filters = null,
50
        protected $mercure = null,
51
        protected $messenger = null,
52
        protected $input = null,
53
        protected $output = null,
54
        protected ?array $order = null,
55
        protected ?bool $fetchPartial = null,
56
        protected ?bool $forceEager = null,
57
        protected ?bool $paginationEnabled = null,
58
        protected ?string $paginationType = null,
59
        protected ?int $paginationItemsPerPage = null,
60
        protected ?int $paginationMaximumItemsPerPage = null,
61
        protected ?bool $paginationPartial = null,
62
        protected ?bool $paginationClientEnabled = null,
63
        protected ?bool $paginationClientItemsPerPage = null,
64
        protected ?bool $paginationClientPartial = null,
65
        protected ?bool $paginationFetchJoinCollection = null,
66
        protected ?bool $paginationUseOutputWalkers = null,
67
        protected string|\Stringable|null $security = null,
68
        protected ?string $securityMessage = null,
69
        protected string|\Stringable|null $securityPostDenormalize = null,
70
        protected ?string $securityPostDenormalizeMessage = null,
71
        protected string|\Stringable|null $securityPostValidation = null,
72
        protected ?string $securityPostValidationMessage = null,
73
        protected $provider = null,
74
        protected $processor = null,
75
        protected ?OptionsInterface $stateOptions = null,
76
        /*
77
         * @experimental
78
         */
79
        array|Parameters|null $parameters = null,
80
        protected mixed $rules = null,
81
        protected ?string $policy = null,
82
        protected array|string|null $middleware = null,
83
        protected ?bool $queryParameterValidationEnabled = null,
84
        protected ?bool $strictQueryParameterValidation = null,
85
        protected ?bool $hideHydraOperation = null,
86
        protected array $extraProperties = [],
87
    ) {
88
        if (\is_array($parameters) && $parameters) {
388✔
89
            $parameters = new Parameters($parameters);
14✔
90
        }
91

92
        $this->parameters = $parameters;
388✔
93
    }
94

95
    public function getShortName(): ?string
96
    {
97
        return $this->shortName;
307✔
98
    }
99

100
    public function withShortName(string $shortName): static
101
    {
102
        $self = clone $this;
87✔
103
        $self->shortName = $shortName;
87✔
104

105
        return $self;
87✔
106
    }
107

108
    /**
109
     * @return class-string|null
110
     */
111
    public function getClass(): ?string
112
    {
113
        return $this->class;
358✔
114
    }
115

116
    /**
117
     * @param class-string $class
118
     */
119
    public function withClass(string $class): static
120
    {
121
        $self = clone $this;
272✔
122
        $self->class = $class;
272✔
123

124
        return $self;
272✔
125
    }
126

127
    public function getDescription(): ?string
128
    {
129
        return $this->description;
109✔
130
    }
131

132
    public function withDescription(?string $description = null): static
133
    {
134
        $self = clone $this;
47✔
135
        $self->description = $description;
47✔
136

137
        return $self;
47✔
138
    }
139

140
    public function getUrlGenerationStrategy(): ?int
141
    {
142
        return $this->urlGenerationStrategy;
319✔
143
    }
144

145
    public function withUrlGenerationStrategy(int $urlGenerationStrategy): static
146
    {
147
        $self = clone $this;
×
148
        $self->urlGenerationStrategy = $urlGenerationStrategy;
×
149

150
        return $self;
×
151
    }
152

153
    public function getDeprecationReason(): ?string
154
    {
155
        return $this->deprecationReason;
109✔
156
    }
157

158
    /**
159
     * @param string $deprecationReason
160
     */
161
    public function withDeprecationReason($deprecationReason): static
162
    {
163
        $self = clone $this;
×
164
        $self->deprecationReason = $deprecationReason;
×
165

166
        return $self;
×
167
    }
168

169
    public function getNormalizationContext(): ?array
170
    {
171
        return $this->normalizationContext;
347✔
172
    }
173

174
    public function withNormalizationContext(array $normalizationContext): static
175
    {
176
        $self = clone $this;
102✔
177
        $self->normalizationContext = $normalizationContext;
102✔
178

179
        return $self;
102✔
180
    }
181

182
    public function getDenormalizationContext(): ?array
183
    {
184
        return $this->denormalizationContext;
344✔
185
    }
186

187
    public function withDenormalizationContext(array $denormalizationContext): static
188
    {
189
        $self = clone $this;
14✔
190
        $self->denormalizationContext = $denormalizationContext;
14✔
191

192
        return $self;
14✔
193
    }
194

195
    public function getCollectDenormalizationErrors(): ?bool
196
    {
197
        return $this->collectDenormalizationErrors;
303✔
198
    }
199

200
    public function withCollectDenormalizationErrors(?bool $collectDenormalizationErrors = null): static
201
    {
202
        $self = clone $this;
1✔
203
        $self->collectDenormalizationErrors = $collectDenormalizationErrors;
1✔
204

205
        return $self;
1✔
206
    }
207

208
    public function getValidationContext(): ?array
209
    {
210
        return $this->validationContext;
108✔
211
    }
212

213
    public function withValidationContext(array $validationContext): static
214
    {
215
        $self = clone $this;
×
216
        $self->validationContext = $validationContext;
×
217

218
        return $self;
×
219
    }
220

221
    /**
222
     * @return string[]|null
223
     */
224
    public function getFilters(): ?array
225
    {
226
        return $this->filters;
323✔
227
    }
228

229
    public function withFilters(array $filters): static
230
    {
231
        $self = clone $this;
54✔
232
        $self->filters = $filters;
54✔
233

234
        return $self;
54✔
235
    }
236

237
    public function getMercure(): mixed
238
    {
239
        return $this->mercure;
315✔
240
    }
241

242
    public function withMercure(mixed $mercure): static
243
    {
244
        $self = clone $this;
1✔
245
        $self->mercure = $mercure;
1✔
246

247
        return $self;
1✔
248
    }
249

250
    public function getMessenger(): mixed
251
    {
252
        return $this->messenger;
55✔
253
    }
254

255
    public function withMessenger(mixed $messenger): static
256
    {
257
        $self = clone $this;
×
258
        $self->messenger = $messenger;
×
259

260
        return $self;
×
261
    }
262

263
    public function getInput(): mixed
264
    {
265
        return $this->input;
326✔
266
    }
267

268
    public function withInput(mixed $input): static
269
    {
270
        $self = clone $this;
66✔
271
        $self->input = $input;
66✔
272

273
        return $self;
66✔
274
    }
275

276
    public function getOutput(): mixed
277
    {
278
        return $this->output;
339✔
279
    }
280

281
    public function withOutput(mixed $output): static
282
    {
283
        $self = clone $this;
52✔
284
        $self->output = $output;
52✔
285

286
        return $self;
52✔
287
    }
288

289
    public function getOrder(): ?array
290
    {
291
        return $this->order;
142✔
292
    }
293

294
    public function withOrder(array $order): static
295
    {
296
        $self = clone $this;
×
297
        $self->order = $order;
×
298

299
        return $self;
×
300
    }
301

302
    public function getFetchPartial(): ?bool
303
    {
304
        return $this->fetchPartial;
163✔
305
    }
306

307
    public function withFetchPartial(bool $fetchPartial): static
308
    {
309
        $self = clone $this;
×
310
        $self->fetchPartial = $fetchPartial;
×
311

312
        return $self;
×
313
    }
314

315
    public function getForceEager(): ?bool
316
    {
317
        return $this->forceEager;
163✔
318
    }
319

320
    public function withForceEager(bool $forceEager): static
321
    {
322
        $self = clone $this;
×
323
        $self->forceEager = $forceEager;
×
324

325
        return $self;
×
326
    }
327

328
    public function getPaginationEnabled(): ?bool
329
    {
330
        return $this->paginationEnabled;
165✔
331
    }
332

333
    public function withPaginationEnabled(bool $paginationEnabled): static
334
    {
335
        $self = clone $this;
×
336
        $self->paginationEnabled = $paginationEnabled;
×
337

338
        return $self;
×
339
    }
340

341
    public function getPaginationType(): ?string
342
    {
343
        return $this->paginationType;
60✔
344
    }
345

346
    public function withPaginationType(string $paginationType): static
347
    {
348
        $self = clone $this;
×
349
        $self->paginationType = $paginationType;
×
350

351
        return $self;
×
352
    }
353

354
    public function getPaginationItemsPerPage(): ?int
355
    {
356
        return $this->paginationItemsPerPage;
161✔
357
    }
358

359
    public function withPaginationItemsPerPage(int $paginationItemsPerPage): static
360
    {
361
        $self = clone $this;
52✔
362
        $self->paginationItemsPerPage = $paginationItemsPerPage;
52✔
363

364
        return $self;
52✔
365
    }
366

367
    public function getPaginationMaximumItemsPerPage(): ?int
368
    {
369
        return $this->paginationMaximumItemsPerPage;
161✔
370
    }
371

372
    public function withPaginationMaximumItemsPerPage(int $paginationMaximumItemsPerPage): static
373
    {
374
        $self = clone $this;
×
375
        $self->paginationMaximumItemsPerPage = $paginationMaximumItemsPerPage;
×
376

377
        return $self;
×
378
    }
379

380
    public function getPaginationPartial(): ?bool
381
    {
382
        return $this->paginationPartial;
152✔
383
    }
384

385
    public function withPaginationPartial(bool $paginationPartial): static
386
    {
387
        $self = clone $this;
×
388
        $self->paginationPartial = $paginationPartial;
×
389

390
        return $self;
×
391
    }
392

393
    public function getPaginationClientEnabled(): ?bool
394
    {
395
        return $this->paginationClientEnabled;
159✔
396
    }
397

398
    public function withPaginationClientEnabled(bool $paginationClientEnabled): static
399
    {
400
        $self = clone $this;
52✔
401
        $self->paginationClientEnabled = $paginationClientEnabled;
52✔
402

403
        return $self;
52✔
404
    }
405

406
    public function getPaginationClientItemsPerPage(): ?bool
407
    {
408
        return $this->paginationClientItemsPerPage;
161✔
409
    }
410

411
    public function withPaginationClientItemsPerPage(bool $paginationClientItemsPerPage): static
412
    {
413
        $self = clone $this;
52✔
414
        $self->paginationClientItemsPerPage = $paginationClientItemsPerPage;
52✔
415

416
        return $self;
52✔
417
    }
418

419
    public function getPaginationClientPartial(): ?bool
420
    {
421
        return $this->paginationClientPartial;
161✔
422
    }
423

424
    public function withPaginationClientPartial(bool $paginationClientPartial): static
425
    {
426
        $self = clone $this;
52✔
427
        $self->paginationClientPartial = $paginationClientPartial;
52✔
428

429
        return $self;
52✔
430
    }
431

432
    public function getPaginationFetchJoinCollection(): ?bool
433
    {
434
        return $this->paginationFetchJoinCollection;
152✔
435
    }
436

437
    public function withPaginationFetchJoinCollection(bool $paginationFetchJoinCollection): static
438
    {
439
        $self = clone $this;
×
440
        $self->paginationFetchJoinCollection = $paginationFetchJoinCollection;
×
441

442
        return $self;
×
443
    }
444

445
    public function getPaginationUseOutputWalkers(): ?bool
446
    {
447
        return $this->paginationUseOutputWalkers;
152✔
448
    }
449

450
    public function withPaginationUseOutputWalkers(bool $paginationUseOutputWalkers): static
451
    {
452
        $self = clone $this;
×
453
        $self->paginationUseOutputWalkers = $paginationUseOutputWalkers;
×
454

455
        return $self;
×
456
    }
457

458
    public function getSecurity(): ?string
459
    {
460
        return $this->security instanceof \Stringable ? (string) $this->security : $this->security;
323✔
461
    }
462

463
    public function withSecurity(string|\Stringable|null $security = null): static
464
    {
465
        $self = clone $this;
1✔
466
        $self->security = $security;
1✔
467

468
        return $self;
1✔
469
    }
470

471
    public function getSecurityMessage(): ?string
472
    {
473
        return $this->securityMessage;
319✔
474
    }
475

476
    public function withSecurityMessage(string $securityMessage): static
477
    {
478
        $self = clone $this;
×
479
        $self->securityMessage = $securityMessage;
×
480

481
        return $self;
×
482
    }
483

484
    public function getSecurityPostDenormalize(): ?string
485
    {
486
        return $this->securityPostDenormalize instanceof \Stringable ? (string) $this->securityPostDenormalize : $this->securityPostDenormalize;
317✔
487
    }
488

489
    public function withSecurityPostDenormalize(string|\Stringable|null $securityPostDenormalize = null): static
490
    {
491
        $self = clone $this;
×
492
        $self->securityPostDenormalize = $securityPostDenormalize;
×
493

494
        return $self;
×
495
    }
496

497
    public function getSecurityPostDenormalizeMessage(): ?string
498
    {
499
        return $this->securityPostDenormalizeMessage;
317✔
500
    }
501

502
    public function withSecurityPostDenormalizeMessage(string $securityPostDenormalizeMessage): static
503
    {
504
        $self = clone $this;
×
505
        $self->securityPostDenormalizeMessage = $securityPostDenormalizeMessage;
×
506

507
        return $self;
×
508
    }
509

510
    public function getSecurityPostValidation(): ?string
511
    {
512
        return $this->securityPostValidation instanceof \Stringable ? (string) $this->securityPostValidation : $this->securityPostValidation;
317✔
513
    }
514

515
    public function withSecurityPostValidation(string|\Stringable|null $securityPostValidation = null): static
516
    {
517
        $self = clone $this;
×
518
        $self->securityPostValidation = $securityPostValidation;
×
519

520
        return $self;
×
521
    }
522

523
    public function getSecurityPostValidationMessage(): ?string
524
    {
525
        return $this->securityPostValidationMessage;
317✔
526
    }
527

528
    public function withSecurityPostValidationMessage(?string $securityPostValidationMessage = null): static
529
    {
530
        $self = clone $this;
×
531
        $self->securityPostValidationMessage = $securityPostValidationMessage;
×
532

533
        return $self;
×
534
    }
535

536
    public function getProcessor(): callable|string|null
537
    {
538
        return $this->processor;
74✔
539
    }
540

541
    public function withProcessor(callable|string|null $processor): static
542
    {
543
        $self = clone $this;
28✔
544
        $self->processor = $processor;
28✔
545

546
        return $self;
28✔
547
    }
548

549
    public function getProvider(): callable|string|null
550
    {
551
        return $this->provider;
309✔
552
    }
553

554
    public function withProvider(callable|string|null $provider): static
555
    {
556
        $self = clone $this;
33✔
557
        $self->provider = $provider;
33✔
558

559
        return $self;
33✔
560
    }
561

562
    public function getStateOptions(): ?OptionsInterface
563
    {
564
        return $this->stateOptions;
319✔
565
    }
566

567
    public function withStateOptions(?OptionsInterface $stateOptions): static
568
    {
569
        $self = clone $this;
26✔
570
        $self->stateOptions = $stateOptions;
26✔
571

572
        return $self;
26✔
573
    }
574

575
    /**
576
     * @return string|callable|array<string, \Illuminate\Contracts\Validation\Rule|array|string>
577
     */
578
    public function getRules(): mixed
579
    {
580
        return $this->rules;
55✔
581
    }
582

583
    /**
584
     * @param string|callable|array<string, \Illuminate\Contracts\Validation\Rule|array|string> $rules
585
     */
586
    public function withRules(mixed $rules): static
587
    {
588
        $self = clone $this;
×
589
        $self->rules = $rules;
×
590

591
        return $self;
×
592
    }
593

594
    public function getParameters(): ?Parameters
595
    {
596
        return $this->parameters;
323✔
597
    }
598

599
    public function withParameters(array|Parameters $parameters): static
600
    {
601
        $self = clone $this;
179✔
602
        $self->parameters = \is_array($parameters) ? new Parameters($parameters) : $parameters;
179✔
603

604
        return $self;
179✔
605
    }
606

607
    public function getQueryParameterValidationEnabled(): ?bool
608
    {
609
        return $this->queryParameterValidationEnabled;
304✔
610
    }
611

612
    public function withQueryParameterValidationEnabled(bool $queryParameterValidationEnabled): static
613
    {
614
        $self = clone $this;
×
615
        $self->queryParameterValidationEnabled = $queryParameterValidationEnabled;
×
616

617
        return $self;
×
618
    }
619

620
    public function getPolicy(): ?string
621
    {
622
        return $this->policy;
55✔
623
    }
624

625
    public function withPolicy(string $policy): static
626
    {
627
        $self = clone $this;
×
628
        $self->policy = $policy;
×
629

630
        return $self;
×
631
    }
632

633
    public function getMiddleware(): mixed
634
    {
635
        return $this->middleware;
55✔
636
    }
637

638
    public function withMiddleware(string|array $middleware): static
639
    {
640
        $self = clone $this;
×
641
        $self->middleware = $middleware;
×
642

643
        return $self;
×
644
    }
645

646
    public function getExtraProperties(): ?array
647
    {
648
        return $this->extraProperties;
176✔
649
    }
650

651
    public function withExtraProperties(array $extraProperties = []): static
652
    {
653
        $self = clone $this;
55✔
654
        $self->extraProperties = $extraProperties;
55✔
655

656
        return $self;
55✔
657
    }
658

659
    public function getStrictQueryParameterValidation(): ?bool
660
    {
661
        return $this->strictQueryParameterValidation;
304✔
662
    }
663

664
    public function withStrictQueryParameterValidation(bool $strictQueryParameterValidation): static
665
    {
666
        $self = clone $this;
×
667
        $self->strictQueryParameterValidation = $strictQueryParameterValidation;
×
668

669
        return $self;
×
670
    }
671

672
    public function getHideHydraOperation(): ?bool
673
    {
674
        return $this->hideHydraOperation;
59✔
675
    }
676

677
    public function withHideHydraOperation(bool $hideHydraOperation): static
678
    {
679
        $self = clone $this;
1✔
680
        $self->hideHydraOperation = $hideHydraOperation;
1✔
681

682
        return $self;
1✔
683
    }
684
}
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