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

api-platform / core / 14402097517

11 Apr 2025 11:27AM UTC coverage: 8.485% (-0.003%) from 8.488%
14402097517

Pull #7082

github

web-flow
Merge c9ffe27af into 83d005a2b
Pull Request #7082: feat(openapi): manage error resources in global

23 of 27 new or added lines in 12 files covered. (85.19%)

1 existing line in 1 file now uncovered.

13397 of 157884 relevant lines covered (8.49%)

22.89 hits per line

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

67.91
/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\Metadata\Exception\ProblemExceptionInterface;
17
use ApiPlatform\State\OptionsInterface;
18

19
/**
20
 * @internal
21
 */
22
abstract class Metadata
23
{
24
    protected ?Parameters $parameters = null;
25

26
    /**
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
     * @param array<class-string<ProblemExceptionInterface>>|null                               $errors
39
     */
40
    public function __construct(
41
        protected ?string $shortName = null,
42
        protected ?string $class = null,
43
        protected ?string $description = null,
44
        protected ?int $urlGenerationStrategy = null,
45
        protected ?string $deprecationReason = null,
46
        protected ?array $normalizationContext = null,
47
        protected ?array $denormalizationContext = null,
48
        protected ?bool $collectDenormalizationErrors = null,
49
        protected ?array $validationContext = null,
50
        protected ?array $filters = null,
51
        protected ?bool $elasticsearch = null,
52
        protected $mercure = null,
53
        protected $messenger = null,
54
        protected $input = null,
55
        protected $output = null,
56
        protected ?array $order = null,
57
        protected ?bool $fetchPartial = null,
58
        protected ?bool $forceEager = null,
59
        protected ?bool $paginationEnabled = null,
60
        protected ?string $paginationType = null,
61
        protected ?int $paginationItemsPerPage = null,
62
        protected ?int $paginationMaximumItemsPerPage = null,
63
        protected ?bool $paginationPartial = null,
64
        protected ?bool $paginationClientEnabled = null,
65
        protected ?bool $paginationClientItemsPerPage = null,
66
        protected ?bool $paginationClientPartial = null,
67
        protected ?bool $paginationFetchJoinCollection = null,
68
        protected ?bool $paginationUseOutputWalkers = null,
69
        protected string|\Stringable|null $security = null,
70
        protected ?string $securityMessage = null,
71
        protected string|\Stringable|null $securityPostDenormalize = null,
72
        protected ?string $securityPostDenormalizeMessage = null,
73
        protected string|\Stringable|null $securityPostValidation = null,
74
        protected ?string $securityPostValidationMessage = null,
75
        protected $provider = null,
76
        protected $processor = null,
77
        protected ?OptionsInterface $stateOptions = null,
78
        protected ?array $errors = null,
79
        /*
80
         * @experimental
81
         */
82
        array|Parameters|null $parameters = null,
83
        protected mixed $rules = null,
84
        protected ?string $policy = null,
85
        protected array|string|null $middleware = null,
86
        protected ?bool $queryParameterValidationEnabled = null,
87
        protected ?bool $strictQueryParameterValidation = null,
88
        protected ?bool $hideHydraOperation = null,
89
        protected array $extraProperties = [],
90
    ) {
91
        if (\is_array($parameters) && $parameters) {
2,087✔
92
            $parameters = new Parameters($parameters);
29✔
93
        }
94

95
        $this->parameters = $parameters;
2,087✔
96
    }
97

98
    public function getShortName(): ?string
99
    {
100
        return $this->shortName;
1,859✔
101
    }
102

103
    public function withShortName(string $shortName): static
104
    {
105
        $self = clone $this;
207✔
106
        $self->shortName = $shortName;
207✔
107

108
        return $self;
207✔
109
    }
110

111
    public function getClass(): ?string
112
    {
113
        return $this->class;
2,096✔
114
    }
115

116
    public function withClass(string $class): static
117
    {
118
        $self = clone $this;
1,754✔
119
        $self->class = $class;
1,754✔
120

121
        return $self;
1,754✔
122
    }
123

124
    public function getDescription(): ?string
125
    {
126
        return $this->description;
542✔
127
    }
128

129
    public function withDescription(?string $description = null): static
130
    {
131
        $self = clone $this;
159✔
132
        $self->description = $description;
159✔
133

134
        return $self;
159✔
135
    }
136

137
    public function getUrlGenerationStrategy(): ?int
138
    {
139
        return $this->urlGenerationStrategy;
1,933✔
140
    }
141

142
    public function withUrlGenerationStrategy(int $urlGenerationStrategy): static
143
    {
144
        $self = clone $this;
2✔
145
        $self->urlGenerationStrategy = $urlGenerationStrategy;
2✔
146

147
        return $self;
2✔
148
    }
149

150
    public function getDeprecationReason(): ?string
151
    {
152
        return $this->deprecationReason;
542✔
153
    }
154

155
    public function withDeprecationReason($deprecationReason): static
156
    {
157
        $self = clone $this;
2✔
158
        $self->deprecationReason = $deprecationReason;
2✔
159

160
        return $self;
2✔
161
    }
162

163
    public function getNormalizationContext(): ?array
164
    {
165
        return $this->normalizationContext;
2,077✔
166
    }
167

168
    public function withNormalizationContext(array $normalizationContext): static
169
    {
170
        $self = clone $this;
337✔
171
        $self->normalizationContext = $normalizationContext;
337✔
172

173
        return $self;
337✔
174
    }
175

176
    public function getDenormalizationContext(): ?array
177
    {
178
        return $this->denormalizationContext;
1,621✔
179
    }
180

181
    public function withDenormalizationContext(array $denormalizationContext): static
182
    {
183
        $self = clone $this;
7✔
184
        $self->denormalizationContext = $denormalizationContext;
7✔
185

186
        return $self;
7✔
187
    }
188

189
    public function getCollectDenormalizationErrors(): ?bool
190
    {
191
        return $this->collectDenormalizationErrors;
1,727✔
192
    }
193

194
    public function withCollectDenormalizationErrors(?bool $collectDenormalizationErrors = null): static
195
    {
196
        $self = clone $this;
1✔
197
        $self->collectDenormalizationErrors = $collectDenormalizationErrors;
1✔
198

199
        return $self;
1✔
200
    }
201

202
    public function getValidationContext(): ?array
203
    {
204
        return $this->validationContext;
691✔
205
    }
206

207
    public function withValidationContext(array $validationContext): static
208
    {
209
        $self = clone $this;
×
210
        $self->validationContext = $validationContext;
×
211

212
        return $self;
×
213
    }
214

215
    /**
216
     * @return string[]|null
217
     */
218
    public function getFilters(): ?array
219
    {
220
        return $this->filters;
2,044✔
221
    }
222

223
    public function withFilters(array $filters): static
224
    {
225
        $self = clone $this;
130✔
226
        $self->filters = $filters;
130✔
227

228
        return $self;
130✔
229
    }
230

231
    /**
232
     * @deprecated this will be removed in v4
233
     */
234
    public function getElasticsearch(): ?bool
235
    {
236
        return $this->elasticsearch;
132✔
237
    }
238

239
    /**
240
     * @deprecated this will be removed in v4
241
     */
242
    public function withElasticsearch(bool $elasticsearch): static
243
    {
244
        $self = clone $this;
×
245
        $self->elasticsearch = $elasticsearch;
×
246

247
        return $self;
×
248
    }
249

250
    /**
251
     * @return array|bool|mixed|null
252
     */
253
    public function getMercure()
254
    {
255
        return $this->mercure;
2,020✔
256
    }
257

258
    public function withMercure($mercure): static
259
    {
260
        $self = clone $this;
4✔
261
        $self->mercure = $mercure;
4✔
262

263
        return $self;
4✔
264
    }
265

266
    public function getMessenger()
267
    {
268
        return $this->messenger;
132✔
269
    }
270

271
    public function withMessenger($messenger): static
272
    {
273
        $self = clone $this;
×
274
        $self->messenger = $messenger;
×
275

276
        return $self;
×
277
    }
278

279
    public function getInput()
280
    {
281
        return $this->input;
2,046✔
282
    }
283

284
    public function withInput($input): static
285
    {
286
        $self = clone $this;
154✔
287
        $self->input = $input;
154✔
288

289
        return $self;
154✔
290
    }
291

292
    public function getOutput()
293
    {
294
        return $this->output;
2,066✔
295
    }
296

297
    public function withOutput($output): static
298
    {
299
        $self = clone $this;
126✔
300
        $self->output = $output;
126✔
301

302
        return $self;
126✔
303
    }
304

305
    public function getOrder(): ?array
306
    {
307
        return $this->order;
800✔
308
    }
309

310
    public function withOrder(array $order): static
311
    {
312
        $self = clone $this;
2✔
313
        $self->order = $order;
2✔
314

315
        return $self;
2✔
316
    }
317

318
    public function getFetchPartial(): ?bool
319
    {
320
        return $this->fetchPartial;
851✔
321
    }
322

323
    public function withFetchPartial(bool $fetchPartial): static
324
    {
325
        $self = clone $this;
×
326
        $self->fetchPartial = $fetchPartial;
×
327

328
        return $self;
×
329
    }
330

331
    public function getForceEager(): ?bool
332
    {
333
        return $this->forceEager;
851✔
334
    }
335

336
    public function withForceEager(bool $forceEager): static
337
    {
338
        $self = clone $this;
2✔
339
        $self->forceEager = $forceEager;
2✔
340

341
        return $self;
2✔
342
    }
343

344
    public function getPaginationEnabled(): ?bool
345
    {
346
        return $this->paginationEnabled;
1,078✔
347
    }
348

349
    public function withPaginationEnabled(bool $paginationEnabled): static
350
    {
351
        $self = clone $this;
×
352
        $self->paginationEnabled = $paginationEnabled;
×
353

354
        return $self;
×
355
    }
356

357
    public function getPaginationType(): ?string
358
    {
359
        return $this->paginationType;
417✔
360
    }
361

362
    public function withPaginationType(string $paginationType): static
363
    {
364
        $self = clone $this;
×
365
        $self->paginationType = $paginationType;
×
366

367
        return $self;
×
368
    }
369

370
    public function getPaginationItemsPerPage(): ?int
371
    {
372
        return $this->paginationItemsPerPage;
885✔
373
    }
374

375
    public function withPaginationItemsPerPage(int $paginationItemsPerPage): static
376
    {
377
        $self = clone $this;
125✔
378
        $self->paginationItemsPerPage = $paginationItemsPerPage;
125✔
379

380
        return $self;
125✔
381
    }
382

383
    public function getPaginationMaximumItemsPerPage(): ?int
384
    {
385
        return $this->paginationMaximumItemsPerPage;
885✔
386
    }
387

388
    public function withPaginationMaximumItemsPerPage(int $paginationMaximumItemsPerPage): static
389
    {
390
        $self = clone $this;
×
391
        $self->paginationMaximumItemsPerPage = $paginationMaximumItemsPerPage;
×
392

393
        return $self;
×
394
    }
395

396
    public function getPaginationPartial(): ?bool
397
    {
398
        return $this->paginationPartial;
593✔
399
    }
400

401
    public function withPaginationPartial(bool $paginationPartial): static
402
    {
403
        $self = clone $this;
2✔
404
        $self->paginationPartial = $paginationPartial;
2✔
405

406
        return $self;
2✔
407
    }
408

409
    public function getPaginationClientEnabled(): ?bool
410
    {
411
        return $this->paginationClientEnabled;
840✔
412
    }
413

414
    public function withPaginationClientEnabled(bool $paginationClientEnabled): static
415
    {
416
        $self = clone $this;
125✔
417
        $self->paginationClientEnabled = $paginationClientEnabled;
125✔
418

419
        return $self;
125✔
420
    }
421

422
    public function getPaginationClientItemsPerPage(): ?bool
423
    {
424
        return $this->paginationClientItemsPerPage;
885✔
425
    }
426

427
    public function withPaginationClientItemsPerPage(bool $paginationClientItemsPerPage): static
428
    {
429
        $self = clone $this;
125✔
430
        $self->paginationClientItemsPerPage = $paginationClientItemsPerPage;
125✔
431

432
        return $self;
125✔
433
    }
434

435
    public function getPaginationClientPartial(): ?bool
436
    {
437
        return $this->paginationClientPartial;
593✔
438
    }
439

440
    public function withPaginationClientPartial(bool $paginationClientPartial): static
441
    {
442
        $self = clone $this;
125✔
443
        $self->paginationClientPartial = $paginationClientPartial;
125✔
444

445
        return $self;
125✔
446
    }
447

448
    public function getPaginationFetchJoinCollection(): ?bool
449
    {
450
        return $this->paginationFetchJoinCollection;
593✔
451
    }
452

453
    public function withPaginationFetchJoinCollection(bool $paginationFetchJoinCollection): static
454
    {
455
        $self = clone $this;
×
456
        $self->paginationFetchJoinCollection = $paginationFetchJoinCollection;
×
457

458
        return $self;
×
459
    }
460

461
    public function getPaginationUseOutputWalkers(): ?bool
462
    {
463
        return $this->paginationUseOutputWalkers;
593✔
464
    }
465

466
    public function withPaginationUseOutputWalkers(bool $paginationUseOutputWalkers): static
467
    {
468
        $self = clone $this;
×
469
        $self->paginationUseOutputWalkers = $paginationUseOutputWalkers;
×
470

471
        return $self;
×
472
    }
473

474
    public function getSecurity(): ?string
475
    {
476
        return $this->security instanceof \Stringable ? (string) $this->security : $this->security;
1,996✔
477
    }
478

479
    public function withSecurity($security): static
480
    {
481
        $self = clone $this;
8✔
482
        $self->security = $security;
8✔
483

484
        return $self;
8✔
485
    }
486

487
    public function getSecurityMessage(): ?string
488
    {
489
        return $this->securityMessage;
1,984✔
490
    }
491

492
    public function withSecurityMessage(string $securityMessage): static
493
    {
494
        $self = clone $this;
×
495
        $self->securityMessage = $securityMessage;
×
496

497
        return $self;
×
498
    }
499

500
    public function getSecurityPostDenormalize(): ?string
501
    {
502
        return $this->securityPostDenormalize instanceof \Stringable ? (string) $this->securityPostDenormalize : $this->securityPostDenormalize;
1,807✔
503
    }
504

505
    public function withSecurityPostDenormalize($securityPostDenormalize): static
506
    {
507
        $self = clone $this;
×
508
        $self->securityPostDenormalize = $securityPostDenormalize;
×
509

510
        return $self;
×
511
    }
512

513
    public function getSecurityPostDenormalizeMessage(): ?string
514
    {
515
        return $this->securityPostDenormalizeMessage;
1,807✔
516
    }
517

518
    public function withSecurityPostDenormalizeMessage(string $securityPostDenormalizeMessage): static
519
    {
520
        $self = clone $this;
×
521
        $self->securityPostDenormalizeMessage = $securityPostDenormalizeMessage;
×
522

523
        return $self;
×
524
    }
525

526
    public function getSecurityPostValidation(): ?string
527
    {
528
        return $this->securityPostValidation instanceof \Stringable ? (string) $this->securityPostValidation : $this->securityPostValidation;
1,975✔
529
    }
530

531
    public function withSecurityPostValidation(string|\Stringable|null $securityPostValidation = null): static
532
    {
533
        $self = clone $this;
×
534
        $self->securityPostValidation = $securityPostValidation;
×
535

536
        return $self;
×
537
    }
538

539
    public function getSecurityPostValidationMessage(): ?string
540
    {
541
        return $this->securityPostValidationMessage;
1,975✔
542
    }
543

544
    public function withSecurityPostValidationMessage(?string $securityPostValidationMessage = null): static
545
    {
546
        $self = clone $this;
×
547
        $self->securityPostValidationMessage = $securityPostValidationMessage;
×
548

549
        return $self;
×
550
    }
551

552
    public function getProcessor(): callable|string|null
553
    {
554
        return $this->processor;
642✔
555
    }
556

557
    public function withProcessor(callable|string|null $processor): static
558
    {
559
        $self = clone $this;
89✔
560
        $self->processor = $processor;
89✔
561

562
        return $self;
89✔
563
    }
564

565
    public function getProvider(): callable|string|null
566
    {
567
        return $this->provider;
1,722✔
568
    }
569

570
    public function withProvider(callable|string|null $provider): static
571
    {
572
        $self = clone $this;
98✔
573
        $self->provider = $provider;
98✔
574

575
        return $self;
98✔
576
    }
577

578
    public function getStateOptions(): ?OptionsInterface
579
    {
580
        return $this->stateOptions;
2,002✔
581
    }
582

583
    public function withStateOptions(?OptionsInterface $stateOptions): static
584
    {
585
        $self = clone $this;
83✔
586
        $self->stateOptions = $stateOptions;
83✔
587

588
        return $self;
83✔
589
    }
590

591
    /**
592
     * @return string|callable|array<string, \Illuminate\Contracts\Validation\Rule|array|string>
593
     */
594
    public function getRules(): mixed
595
    {
596
        return $this->rules;
132✔
597
    }
598

599
    /**
600
     * @param string|callable|array<string, \Illuminate\Contracts\Validation\Rule|array|string> $rules
601
     */
602
    public function withRules(mixed $rules): static
603
    {
604
        $self = clone $this;
×
605
        $self->rules = $rules;
×
606

607
        return $self;
×
608
    }
609

610
    public function getParameters(): ?Parameters
611
    {
612
        return $this->parameters;
2,039✔
613
    }
614

615
    public function withParameters(array|Parameters $parameters): static
616
    {
617
        $self = clone $this;
749✔
618
        $self->parameters = \is_array($parameters) ? new Parameters($parameters) : $parameters;
749✔
619

620
        return $self;
749✔
621
    }
622

623
    public function getQueryParameterValidationEnabled(): ?bool
624
    {
625
        return $this->queryParameterValidationEnabled;
1,725✔
626
    }
627

628
    public function withQueryParameterValidationEnabled(bool $queryParameterValidationEnabled): static
629
    {
630
        $self = clone $this;
×
631
        $self->queryParameterValidationEnabled = $queryParameterValidationEnabled;
×
632

633
        return $self;
×
634
    }
635

636
    public function getPolicy(): ?string
637
    {
638
        return $this->policy;
132✔
639
    }
640

641
    public function withPolicy(string $policy): static
642
    {
643
        $self = clone $this;
×
644
        $self->policy = $policy;
×
645

646
        return $self;
×
647
    }
648

649
    public function getMiddleware(): mixed
650
    {
651
        return $this->middleware;
132✔
652
    }
653

654
    public function withMiddleware(string|array $middleware): static
655
    {
656
        $self = clone $this;
×
657
        $self->middleware = $middleware;
×
658

659
        return $self;
×
660
    }
661

662
    public function getExtraProperties(): ?array
663
    {
664
        return $this->extraProperties;
1,317✔
665
    }
666

667
    public function withExtraProperties(array $extraProperties = []): static
668
    {
669
        $self = clone $this;
132✔
670
        $self->extraProperties = $extraProperties;
132✔
671

672
        return $self;
132✔
673
    }
674

675
    public function getStrictQueryParameterValidation(): ?bool
676
    {
677
        return $this->strictQueryParameterValidation;
1,725✔
678
    }
679

680
    public function withStrictQueryParameterValidation(bool $strictQueryParameterValidation): static
681
    {
682
        $self = clone $this;
×
683
        $self->strictQueryParameterValidation = $strictQueryParameterValidation;
×
684

685
        return $self;
×
686
    }
687

688
    public function getHideHydraOperation(): ?bool
689
    {
690
        return $this->hideHydraOperation;
150✔
691
    }
692

693
    public function withHideHydraOperation(bool $hideHydraOperation): static
694
    {
695
        $self = clone $this;
4✔
696
        $self->hideHydraOperation = $hideHydraOperation;
4✔
697

698
        return $self;
4✔
699
    }
700

701
    public function getErrors(): ?array
702
    {
703
        return $this->errors;
175✔
704
    }
705

706
    /**
707
     * @param class-string<ProblemExceptionInterface>[] $errors
708
     */
709
    public function withErrors(array $errors): static
710
    {
NEW
711
        $self = clone $this;
×
NEW
712
        $self->errors = $errors;
×
713

NEW
714
        return $self;
×
715
    }
716
}
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