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

api-platform / core / 16524130380

25 Jul 2025 02:14PM UTC coverage: 22.07% (+0.03%) from 22.039%
16524130380

push

github

web-flow
feat(metadata): introduce metadata mutators for resource & operations (#7213)

Co-authored-by: Antoine Bluchet <soyuka@users.noreply.github.com>

40 of 106 new or added lines in 9 files covered. (37.74%)

112 existing lines in 2 files now uncovered.

11573 of 52437 relevant lines covered (22.07%)

23.46 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) {
739✔
89
            $parameters = new Parameters($parameters);
28✔
90
        }
91

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

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

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

105
        return $self;
172✔
106
    }
107

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

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

124
        return $self;
507✔
125
    }
126

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

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

137
        return $self;
92✔
138
    }
139

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

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

UNCOV
150
        return $self;
×
151
    }
152

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

158
    public function withDeprecationReason($deprecationReason): static
159
    {
UNCOV
160
        $self = clone $this;
×
UNCOV
161
        $self->deprecationReason = $deprecationReason;
×
162

UNCOV
163
        return $self;
×
164
    }
165

166
    public function getNormalizationContext(): ?array
167
    {
168
        return $this->normalizationContext;
686✔
169
    }
170

171
    public function withNormalizationContext(array $normalizationContext): static
172
    {
173
        $self = clone $this;
202✔
174
        $self->normalizationContext = $normalizationContext;
202✔
175

176
        return $self;
202✔
177
    }
178

179
    public function getDenormalizationContext(): ?array
180
    {
181
        return $this->denormalizationContext;
679✔
182
    }
183

184
    public function withDenormalizationContext(array $denormalizationContext): static
185
    {
186
        $self = clone $this;
25✔
187
        $self->denormalizationContext = $denormalizationContext;
25✔
188

189
        return $self;
25✔
190
    }
191

192
    public function getCollectDenormalizationErrors(): ?bool
193
    {
194
        return $this->collectDenormalizationErrors;
598✔
195
    }
196

197
    public function withCollectDenormalizationErrors(?bool $collectDenormalizationErrors = null): static
198
    {
199
        $self = clone $this;
2✔
200
        $self->collectDenormalizationErrors = $collectDenormalizationErrors;
2✔
201

202
        return $self;
2✔
203
    }
204

205
    public function getValidationContext(): ?array
206
    {
207
        return $this->validationContext;
206✔
208
    }
209

210
    public function withValidationContext(array $validationContext): static
211
    {
UNCOV
212
        $self = clone $this;
×
UNCOV
213
        $self->validationContext = $validationContext;
×
214

UNCOV
215
        return $self;
×
216
    }
217

218
    /**
219
     * @return string[]|null
220
     */
221
    public function getFilters(): ?array
222
    {
223
        return $this->filters;
638✔
224
    }
225

226
    public function withFilters(array $filters): static
227
    {
228
        $self = clone $this;
106✔
229
        $self->filters = $filters;
106✔
230

231
        return $self;
106✔
232
    }
233

234
    public function getMercure(): mixed
235
    {
236
        return $this->mercure;
595✔
237
    }
238

239
    public function withMercure(mixed $mercure): static
240
    {
241
        $self = clone $this;
2✔
242
        $self->mercure = $mercure;
2✔
243

244
        return $self;
2✔
245
    }
246

247
    public function getMessenger(): mixed
248
    {
249
        return $this->messenger;
108✔
250
    }
251

252
    public function withMessenger(mixed $messenger): static
253
    {
UNCOV
254
        $self = clone $this;
×
UNCOV
255
        $self->messenger = $messenger;
×
256

UNCOV
257
        return $self;
×
258
    }
259

260
    public function getInput(): mixed
261
    {
262
        return $this->input;
644✔
263
    }
264

265
    public function withInput(mixed $input): static
266
    {
267
        $self = clone $this;
130✔
268
        $self->input = $input;
130✔
269

270
        return $self;
130✔
271
    }
272

273
    public function getOutput(): mixed
274
    {
275
        return $this->output;
670✔
276
    }
277

278
    public function withOutput(mixed $output): static
279
    {
280
        $self = clone $this;
102✔
281
        $self->output = $output;
102✔
282

283
        return $self;
102✔
284
    }
285

286
    public function getOrder(): ?array
287
    {
288
        return $this->order;
280✔
289
    }
290

291
    public function withOrder(array $order): static
292
    {
UNCOV
293
        $self = clone $this;
×
UNCOV
294
        $self->order = $order;
×
295

UNCOV
296
        return $self;
×
297
    }
298

299
    public function getFetchPartial(): ?bool
300
    {
301
        return $this->fetchPartial;
320✔
302
    }
303

304
    public function withFetchPartial(bool $fetchPartial): static
305
    {
UNCOV
306
        $self = clone $this;
×
UNCOV
307
        $self->fetchPartial = $fetchPartial;
×
308

UNCOV
309
        return $self;
×
310
    }
311

312
    public function getForceEager(): ?bool
313
    {
314
        return $this->forceEager;
320✔
315
    }
316

317
    public function withForceEager(bool $forceEager): static
318
    {
UNCOV
319
        $self = clone $this;
×
UNCOV
320
        $self->forceEager = $forceEager;
×
321

UNCOV
322
        return $self;
×
323
    }
324

325
    public function getPaginationEnabled(): ?bool
326
    {
327
        return $this->paginationEnabled;
326✔
328
    }
329

330
    public function withPaginationEnabled(bool $paginationEnabled): static
331
    {
UNCOV
332
        $self = clone $this;
×
UNCOV
333
        $self->paginationEnabled = $paginationEnabled;
×
334

UNCOV
335
        return $self;
×
336
    }
337

338
    public function getPaginationType(): ?string
339
    {
340
        return $this->paginationType;
118✔
341
    }
342

343
    public function withPaginationType(string $paginationType): static
344
    {
UNCOV
345
        $self = clone $this;
×
UNCOV
346
        $self->paginationType = $paginationType;
×
347

UNCOV
348
        return $self;
×
349
    }
350

351
    public function getPaginationItemsPerPage(): ?int
352
    {
353
        return $this->paginationItemsPerPage;
318✔
354
    }
355

356
    public function withPaginationItemsPerPage(int $paginationItemsPerPage): static
357
    {
358
        $self = clone $this;
102✔
359
        $self->paginationItemsPerPage = $paginationItemsPerPage;
102✔
360

361
        return $self;
102✔
362
    }
363

364
    public function getPaginationMaximumItemsPerPage(): ?int
365
    {
366
        return $this->paginationMaximumItemsPerPage;
318✔
367
    }
368

369
    public function withPaginationMaximumItemsPerPage(int $paginationMaximumItemsPerPage): static
370
    {
UNCOV
371
        $self = clone $this;
×
UNCOV
372
        $self->paginationMaximumItemsPerPage = $paginationMaximumItemsPerPage;
×
373

UNCOV
374
        return $self;
×
375
    }
376

377
    public function getPaginationPartial(): ?bool
378
    {
379
        return $this->paginationPartial;
300✔
380
    }
381

382
    public function withPaginationPartial(bool $paginationPartial): static
383
    {
UNCOV
384
        $self = clone $this;
×
UNCOV
385
        $self->paginationPartial = $paginationPartial;
×
386

UNCOV
387
        return $self;
×
388
    }
389

390
    public function getPaginationClientEnabled(): ?bool
391
    {
392
        return $this->paginationClientEnabled;
314✔
393
    }
394

395
    public function withPaginationClientEnabled(bool $paginationClientEnabled): static
396
    {
397
        $self = clone $this;
102✔
398
        $self->paginationClientEnabled = $paginationClientEnabled;
102✔
399

400
        return $self;
102✔
401
    }
402

403
    public function getPaginationClientItemsPerPage(): ?bool
404
    {
405
        return $this->paginationClientItemsPerPage;
318✔
406
    }
407

408
    public function withPaginationClientItemsPerPage(bool $paginationClientItemsPerPage): static
409
    {
410
        $self = clone $this;
102✔
411
        $self->paginationClientItemsPerPage = $paginationClientItemsPerPage;
102✔
412

413
        return $self;
102✔
414
    }
415

416
    public function getPaginationClientPartial(): ?bool
417
    {
418
        return $this->paginationClientPartial;
318✔
419
    }
420

421
    public function withPaginationClientPartial(bool $paginationClientPartial): static
422
    {
423
        $self = clone $this;
102✔
424
        $self->paginationClientPartial = $paginationClientPartial;
102✔
425

426
        return $self;
102✔
427
    }
428

429
    public function getPaginationFetchJoinCollection(): ?bool
430
    {
431
        return $this->paginationFetchJoinCollection;
300✔
432
    }
433

434
    public function withPaginationFetchJoinCollection(bool $paginationFetchJoinCollection): static
435
    {
UNCOV
436
        $self = clone $this;
×
UNCOV
437
        $self->paginationFetchJoinCollection = $paginationFetchJoinCollection;
×
438

UNCOV
439
        return $self;
×
440
    }
441

442
    public function getPaginationUseOutputWalkers(): ?bool
443
    {
444
        return $this->paginationUseOutputWalkers;
300✔
445
    }
446

447
    public function withPaginationUseOutputWalkers(bool $paginationUseOutputWalkers): static
448
    {
UNCOV
449
        $self = clone $this;
×
UNCOV
450
        $self->paginationUseOutputWalkers = $paginationUseOutputWalkers;
×
451

UNCOV
452
        return $self;
×
453
    }
454

455
    public function getSecurity(): ?string
456
    {
457
        return $this->security instanceof \Stringable ? (string) $this->security : $this->security;
631✔
458
    }
459

460
    public function withSecurity($security): static
461
    {
462
        $self = clone $this;
2✔
463
        $self->security = $security;
2✔
464

465
        return $self;
2✔
466
    }
467

468
    public function getSecurityMessage(): ?string
469
    {
470
        return $this->securityMessage;
618✔
471
    }
472

473
    public function withSecurityMessage(string $securityMessage): static
474
    {
UNCOV
475
        $self = clone $this;
×
UNCOV
476
        $self->securityMessage = $securityMessage;
×
477

UNCOV
478
        return $self;
×
479
    }
480

481
    public function getSecurityPostDenormalize(): ?string
482
    {
483
        return $this->securityPostDenormalize instanceof \Stringable ? (string) $this->securityPostDenormalize : $this->securityPostDenormalize;
385✔
484
    }
485

486
    public function withSecurityPostDenormalize($securityPostDenormalize): static
487
    {
UNCOV
488
        $self = clone $this;
×
UNCOV
489
        $self->securityPostDenormalize = $securityPostDenormalize;
×
490

UNCOV
491
        return $self;
×
492
    }
493

494
    public function getSecurityPostDenormalizeMessage(): ?string
495
    {
496
        return $this->securityPostDenormalizeMessage;
385✔
497
    }
498

499
    public function withSecurityPostDenormalizeMessage(string $securityPostDenormalizeMessage): static
500
    {
UNCOV
501
        $self = clone $this;
×
UNCOV
502
        $self->securityPostDenormalizeMessage = $securityPostDenormalizeMessage;
×
503

UNCOV
504
        return $self;
×
505
    }
506

507
    public function getSecurityPostValidation(): ?string
508
    {
509
        return $this->securityPostValidation instanceof \Stringable ? (string) $this->securityPostValidation : $this->securityPostValidation;
586✔
510
    }
511

512
    public function withSecurityPostValidation(string|\Stringable|null $securityPostValidation = null): static
513
    {
UNCOV
514
        $self = clone $this;
×
UNCOV
515
        $self->securityPostValidation = $securityPostValidation;
×
516

UNCOV
517
        return $self;
×
518
    }
519

520
    public function getSecurityPostValidationMessage(): ?string
521
    {
522
        return $this->securityPostValidationMessage;
586✔
523
    }
524

525
    public function withSecurityPostValidationMessage(?string $securityPostValidationMessage = null): static
526
    {
UNCOV
527
        $self = clone $this;
×
UNCOV
528
        $self->securityPostValidationMessage = $securityPostValidationMessage;
×
529

UNCOV
530
        return $self;
×
531
    }
532

533
    public function getProcessor(): callable|string|null
534
    {
535
        return $this->processor;
142✔
536
    }
537

538
    public function withProcessor(callable|string|null $processor): static
539
    {
540
        $self = clone $this;
56✔
541
        $self->processor = $processor;
56✔
542

543
        return $self;
56✔
544
    }
545

546
    public function getProvider(): callable|string|null
547
    {
548
        return $this->provider;
610✔
549
    }
550

551
    public function withProvider(callable|string|null $provider): static
552
    {
553
        $self = clone $this;
66✔
554
        $self->provider = $provider;
66✔
555

556
        return $self;
66✔
557
    }
558

559
    public function getStateOptions(): ?OptionsInterface
560
    {
561
        return $this->stateOptions;
618✔
562
    }
563

564
    public function withStateOptions(?OptionsInterface $stateOptions): static
565
    {
566
        $self = clone $this;
52✔
567
        $self->stateOptions = $stateOptions;
52✔
568

569
        return $self;
52✔
570
    }
571

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

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

UNCOV
588
        return $self;
×
589
    }
590

591
    public function getParameters(): ?Parameters
592
    {
593
        return $this->parameters;
632✔
594
    }
595

596
    public function withParameters(array|Parameters $parameters): static
597
    {
598
        $self = clone $this;
358✔
599
        $self->parameters = \is_array($parameters) ? new Parameters($parameters) : $parameters;
358✔
600

601
        return $self;
358✔
602
    }
603

604
    public function getQueryParameterValidationEnabled(): ?bool
605
    {
606
        return $this->queryParameterValidationEnabled;
588✔
607
    }
608

609
    public function withQueryParameterValidationEnabled(bool $queryParameterValidationEnabled): static
610
    {
UNCOV
611
        $self = clone $this;
×
UNCOV
612
        $self->queryParameterValidationEnabled = $queryParameterValidationEnabled;
×
613

UNCOV
614
        return $self;
×
615
    }
616

617
    public function getPolicy(): ?string
618
    {
619
        return $this->policy;
108✔
620
    }
621

622
    public function withPolicy(string $policy): static
623
    {
UNCOV
624
        $self = clone $this;
×
UNCOV
625
        $self->policy = $policy;
×
626

UNCOV
627
        return $self;
×
628
    }
629

630
    public function getMiddleware(): mixed
631
    {
632
        return $this->middleware;
108✔
633
    }
634

635
    public function withMiddleware(string|array $middleware): static
636
    {
UNCOV
637
        $self = clone $this;
×
UNCOV
638
        $self->middleware = $middleware;
×
639

UNCOV
640
        return $self;
×
641
    }
642

643
    public function getExtraProperties(): ?array
644
    {
645
        return $this->extraProperties;
346✔
646
    }
647

648
    public function withExtraProperties(array $extraProperties = []): static
649
    {
650
        $self = clone $this;
108✔
651
        $self->extraProperties = $extraProperties;
108✔
652

653
        return $self;
108✔
654
    }
655

656
    public function getStrictQueryParameterValidation(): ?bool
657
    {
658
        return $this->strictQueryParameterValidation;
588✔
659
    }
660

661
    public function withStrictQueryParameterValidation(bool $strictQueryParameterValidation): static
662
    {
UNCOV
663
        $self = clone $this;
×
UNCOV
664
        $self->strictQueryParameterValidation = $strictQueryParameterValidation;
×
665

UNCOV
666
        return $self;
×
667
    }
668

669
    public function getHideHydraOperation(): ?bool
670
    {
671
        return $this->hideHydraOperation;
116✔
672
    }
673

674
    public function withHideHydraOperation(bool $hideHydraOperation): static
675
    {
676
        $self = clone $this;
2✔
677
        $self->hideHydraOperation = $hideHydraOperation;
2✔
678

679
        return $self;
2✔
680
    }
681
}
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