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

api-platform / core / 9838795518

08 Jul 2024 11:33AM UTC coverage: 64.239% (+0.07%) from 64.173%
9838795518

push

github

web-flow
Merge pull request #6459 from soyuka/main

Merge 3.4

154 of 179 new or added lines in 24 files covered. (86.03%)

36 existing lines in 12 files now uncovered.

11326 of 17631 relevant lines covered (64.24%)

68.24 hits per line

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

71.26
/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
 * @internal
20
 */
21
abstract class Metadata
22
{
23
    protected ?Parameters $parameters = null;
24

25
    /**
26
     * @param string|null                                                                       $deprecationReason       https://api-platform.com/docs/core/deprecations/#deprecating-resource-classes-operations-and-properties
27
     * @param string|\Stringable|null                                                           $security                https://api-platform.com/docs/core/security
28
     * @param string|\Stringable|null                                                           $securityPostDenormalize https://api-platform.com/docs/core/security/#executing-access-control-rules-after-denormalization
29
     * @param mixed|null                                                                        $mercure
30
     * @param mixed|null                                                                        $messenger
31
     * @param mixed|null                                                                        $input
32
     * @param mixed|null                                                                        $output
33
     * @param mixed|null                                                                        $provider
34
     * @param mixed|null                                                                        $processor
35
     * @param Parameters|array<string, Parameter>                                               $parameters
36
     * @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
37
     */
38
    public function __construct(
39
        protected ?string $shortName = null,
40
        protected ?string $class = null,
41
        protected ?string $description = null,
42
        protected ?int $urlGenerationStrategy = null,
43
        protected ?string $deprecationReason = null,
44
        protected ?array $normalizationContext = null,
45
        protected ?array $denormalizationContext = null,
46
        protected ?bool $collectDenormalizationErrors = null,
47
        protected ?array $validationContext = null,
48
        protected ?array $filters = null,
49
        protected ?bool $elasticsearch = 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 ?bool $queryParameterValidationEnabled = null,
82
        protected array $extraProperties = []
83
    ) {
84
        if (\is_array($parameters) && $parameters) {
1,271✔
85
            $parameters = new Parameters($parameters);
4✔
86
        }
87

88
        $this->parameters = $parameters;
1,271✔
89
    }
90

91
    public function getShortName(): ?string
92
    {
93
        return $this->shortName;
615✔
94
    }
95

96
    public function withShortName(string $shortName): static
97
    {
98
        $self = clone $this;
240✔
99
        $self->shortName = $shortName;
240✔
100

101
        return $self;
240✔
102
    }
103

104
    public function getClass(): ?string
105
    {
106
        return $this->class;
611✔
107
    }
108

109
    public function withClass(string $class): static
110
    {
111
        $self = clone $this;
403✔
112
        $self->class = $class;
403✔
113

114
        return $self;
403✔
115
    }
116

117
    public function getDescription(): ?string
118
    {
119
        return $this->description;
275✔
120
    }
121

122
    public function withDescription(?string $description = null): static
123
    {
124
        $self = clone $this;
28✔
125
        $self->description = $description;
28✔
126

127
        return $self;
28✔
128
    }
129

130
    public function getUrlGenerationStrategy(): ?int
131
    {
132
        return $this->urlGenerationStrategy;
483✔
133
    }
134

135
    public function withUrlGenerationStrategy(int $urlGenerationStrategy): static
136
    {
137
        $self = clone $this;
4✔
138
        $self->urlGenerationStrategy = $urlGenerationStrategy;
4✔
139

140
        return $self;
4✔
141
    }
142

143
    public function getDeprecationReason(): ?string
144
    {
145
        return $this->deprecationReason;
275✔
146
    }
147

148
    public function withDeprecationReason($deprecationReason): static
149
    {
150
        $self = clone $this;
4✔
151
        $self->deprecationReason = $deprecationReason;
4✔
152

153
        return $self;
4✔
154
    }
155

156
    public function getNormalizationContext(): ?array
157
    {
158
        return $this->normalizationContext;
627✔
159
    }
160

161
    public function withNormalizationContext(array $normalizationContext): static
162
    {
163
        $self = clone $this;
108✔
164
        $self->normalizationContext = $normalizationContext;
108✔
165

166
        return $self;
108✔
167
    }
168

169
    public function getDenormalizationContext(): ?array
170
    {
171
        return $this->denormalizationContext;
375✔
172
    }
173

174
    public function withDenormalizationContext(array $denormalizationContext): static
175
    {
176
        $self = clone $this;
4✔
177
        $self->denormalizationContext = $denormalizationContext;
4✔
178

179
        return $self;
4✔
180
    }
181

182
    public function getCollectDenormalizationErrors(): ?bool
183
    {
184
        return $this->collectDenormalizationErrors;
444✔
185
    }
186

187
    public function withCollectDenormalizationErrors(?bool $collectDenormalizationErrors = null): static
188
    {
189
        $self = clone $this;
4✔
190
        $self->collectDenormalizationErrors = $collectDenormalizationErrors;
4✔
191

192
        return $self;
4✔
193
    }
194

195
    public function getValidationContext(): ?array
196
    {
197
        return $this->validationContext;
268✔
198
    }
199

200
    public function withValidationContext(array $validationContext): static
201
    {
202
        $self = clone $this;
×
203
        $self->validationContext = $validationContext;
×
204

205
        return $self;
×
206
    }
207

208
    /**
209
     * @return string[]|null
210
     */
211
    public function getFilters(): ?array
212
    {
213
        return $this->filters;
519✔
214
    }
215

216
    public function withFilters(array $filters): static
217
    {
218
        $self = clone $this;
36✔
219
        $self->filters = $filters;
36✔
220

221
        return $self;
36✔
222
    }
223

224
    /**
225
     * @deprecated this will be removed in v4
226
     */
227
    public function getElasticsearch(): ?bool
228
    {
229
        return $this->elasticsearch;
24✔
230
    }
231

232
    /**
233
     * @deprecated this will be removed in v4
234
     */
235
    public function withElasticsearch(bool $elasticsearch): static
236
    {
237
        $self = clone $this;
×
238
        $self->elasticsearch = $elasticsearch;
×
239

240
        return $self;
×
241
    }
242

243
    /**
244
     * @return array|bool|mixed|null
245
     */
246
    public function getMercure()
247
    {
248
        return $this->mercure;
479✔
249
    }
250

251
    public function withMercure($mercure): static
252
    {
253
        $self = clone $this;
16✔
254
        $self->mercure = $mercure;
16✔
255

256
        return $self;
16✔
257
    }
258

259
    public function getMessenger()
260
    {
261
        return $this->messenger;
24✔
262
    }
263

264
    public function withMessenger($messenger): static
265
    {
266
        $self = clone $this;
×
267
        $self->messenger = $messenger;
×
268

269
        return $self;
×
270
    }
271

272
    public function getInput()
273
    {
274
        return $this->input;
519✔
275
    }
276

277
    public function withInput($input): static
278
    {
279
        $self = clone $this;
76✔
280
        $self->input = $input;
76✔
281

282
        return $self;
76✔
283
    }
284

285
    public function getOutput()
286
    {
287
        return $this->output;
611✔
288
    }
289

290
    public function withOutput($output): static
291
    {
292
        $self = clone $this;
24✔
293
        $self->output = $output;
24✔
294

295
        return $self;
24✔
296
    }
297

298
    public function getOrder(): ?array
299
    {
300
        return $this->order;
83✔
301
    }
302

303
    public function withOrder(array $order): static
304
    {
305
        $self = clone $this;
4✔
306
        $self->order = $order;
4✔
307

308
        return $self;
4✔
309
    }
310

311
    public function getFetchPartial(): ?bool
312
    {
313
        return $this->fetchPartial;
107✔
314
    }
315

316
    public function withFetchPartial(bool $fetchPartial): static
317
    {
318
        $self = clone $this;
×
319
        $self->fetchPartial = $fetchPartial;
×
320

321
        return $self;
×
322
    }
323

324
    public function getForceEager(): ?bool
325
    {
326
        return $this->forceEager;
107✔
327
    }
328

329
    public function withForceEager(bool $forceEager): static
330
    {
331
        $self = clone $this;
4✔
332
        $self->forceEager = $forceEager;
4✔
333

334
        return $self;
4✔
335
    }
336

337
    public function getPaginationEnabled(): ?bool
338
    {
339
        return $this->paginationEnabled;
139✔
340
    }
341

342
    public function withPaginationEnabled(bool $paginationEnabled): static
343
    {
344
        $self = clone $this;
×
345
        $self->paginationEnabled = $paginationEnabled;
×
346

347
        return $self;
×
348
    }
349

350
    public function getPaginationType(): ?string
351
    {
352
        return $this->paginationType;
55✔
353
    }
354

355
    public function withPaginationType(string $paginationType): static
356
    {
357
        $self = clone $this;
×
358
        $self->paginationType = $paginationType;
×
359

360
        return $self;
×
361
    }
362

363
    public function getPaginationItemsPerPage(): ?int
364
    {
365
        return $this->paginationItemsPerPage;
111✔
366
    }
367

368
    public function withPaginationItemsPerPage(int $paginationItemsPerPage): static
369
    {
370
        $self = clone $this;
12✔
371
        $self->paginationItemsPerPage = $paginationItemsPerPage;
12✔
372

373
        return $self;
12✔
374
    }
375

376
    public function getPaginationMaximumItemsPerPage(): ?int
377
    {
378
        return $this->paginationMaximumItemsPerPage;
111✔
379
    }
380

381
    public function withPaginationMaximumItemsPerPage(int $paginationMaximumItemsPerPage): static
382
    {
383
        $self = clone $this;
×
384
        $self->paginationMaximumItemsPerPage = $paginationMaximumItemsPerPage;
×
385

386
        return $self;
×
387
    }
388

389
    public function getPaginationPartial(): ?bool
390
    {
391
        return $this->paginationPartial;
83✔
392
    }
393

394
    public function withPaginationPartial(bool $paginationPartial): static
395
    {
396
        $self = clone $this;
4✔
397
        $self->paginationPartial = $paginationPartial;
4✔
398

399
        return $self;
4✔
400
    }
401

402
    public function getPaginationClientEnabled(): ?bool
403
    {
404
        return $this->paginationClientEnabled;
108✔
405
    }
406

407
    public function withPaginationClientEnabled(bool $paginationClientEnabled): static
408
    {
409
        $self = clone $this;
12✔
410
        $self->paginationClientEnabled = $paginationClientEnabled;
12✔
411

412
        return $self;
12✔
413
    }
414

415
    public function getPaginationClientItemsPerPage(): ?bool
416
    {
417
        return $this->paginationClientItemsPerPage;
111✔
418
    }
419

420
    public function withPaginationClientItemsPerPage(bool $paginationClientItemsPerPage): static
421
    {
422
        $self = clone $this;
12✔
423
        $self->paginationClientItemsPerPage = $paginationClientItemsPerPage;
12✔
424

425
        return $self;
12✔
426
    }
427

428
    public function getPaginationClientPartial(): ?bool
429
    {
430
        return $this->paginationClientPartial;
83✔
431
    }
432

433
    public function withPaginationClientPartial(bool $paginationClientPartial): static
434
    {
435
        $self = clone $this;
12✔
436
        $self->paginationClientPartial = $paginationClientPartial;
12✔
437

438
        return $self;
12✔
439
    }
440

441
    public function getPaginationFetchJoinCollection(): ?bool
442
    {
443
        return $this->paginationFetchJoinCollection;
83✔
444
    }
445

446
    public function withPaginationFetchJoinCollection(bool $paginationFetchJoinCollection): static
447
    {
448
        $self = clone $this;
×
449
        $self->paginationFetchJoinCollection = $paginationFetchJoinCollection;
×
450

451
        return $self;
×
452
    }
453

454
    public function getPaginationUseOutputWalkers(): ?bool
455
    {
456
        return $this->paginationUseOutputWalkers;
83✔
457
    }
458

459
    public function withPaginationUseOutputWalkers(bool $paginationUseOutputWalkers): static
460
    {
461
        $self = clone $this;
×
462
        $self->paginationUseOutputWalkers = $paginationUseOutputWalkers;
×
463

464
        return $self;
×
465
    }
466

467
    public function getSecurity(): ?string
468
    {
469
        return $this->security instanceof \Stringable ? (string) $this->security : $this->security;
495✔
470
    }
471

472
    public function withSecurity($security): static
473
    {
474
        $self = clone $this;
4✔
475
        $self->security = $security;
4✔
476

477
        return $self;
4✔
478
    }
479

480
    public function getSecurityMessage(): ?string
481
    {
482
        return $this->securityMessage;
488✔
483
    }
484

485
    public function withSecurityMessage(string $securityMessage): static
486
    {
487
        $self = clone $this;
×
488
        $self->securityMessage = $securityMessage;
×
489

490
        return $self;
×
491
    }
492

493
    public function getSecurityPostDenormalize(): ?string
494
    {
495
        return $this->securityPostDenormalize instanceof \Stringable ? (string) $this->securityPostDenormalize : $this->securityPostDenormalize;
471✔
496
    }
497

498
    public function withSecurityPostDenormalize($securityPostDenormalize): static
499
    {
500
        $self = clone $this;
×
501
        $self->securityPostDenormalize = $securityPostDenormalize;
×
502

503
        return $self;
×
504
    }
505

506
    public function getSecurityPostDenormalizeMessage(): ?string
507
    {
508
        return $this->securityPostDenormalizeMessage;
464✔
509
    }
510

511
    public function withSecurityPostDenormalizeMessage(string $securityPostDenormalizeMessage): static
512
    {
513
        $self = clone $this;
×
514
        $self->securityPostDenormalizeMessage = $securityPostDenormalizeMessage;
×
515

516
        return $self;
×
517
    }
518

519
    public function getSecurityPostValidation(): ?string
520
    {
521
        return $this->securityPostValidation instanceof \Stringable ? (string) $this->securityPostValidation : $this->securityPostValidation;
464✔
522
    }
523

524
    public function withSecurityPostValidation(string|\Stringable|null $securityPostValidation = null): static
525
    {
526
        $self = clone $this;
×
527
        $self->securityPostValidation = $securityPostValidation;
×
528

529
        return $self;
×
530
    }
531

532
    public function getSecurityPostValidationMessage(): ?string
533
    {
534
        return $this->securityPostValidationMessage;
464✔
535
    }
536

537
    public function withSecurityPostValidationMessage(?string $securityPostValidationMessage = null): static
538
    {
539
        $self = clone $this;
×
540
        $self->securityPostValidationMessage = $securityPostValidationMessage;
×
541

542
        return $self;
×
543
    }
544

545
    public function getProcessor(): callable|string|null
546
    {
547
        return $this->processor;
92✔
548
    }
549

550
    public function withProcessor(callable|string|null $processor): static
551
    {
552
        $self = clone $this;
32✔
553
        $self->processor = $processor;
32✔
554

555
        return $self;
32✔
556
    }
557

558
    public function getProvider(): callable|string|null
559
    {
560
        return $this->provider;
467✔
561
    }
562

563
    public function withProvider(callable|string|null $provider): static
564
    {
565
        $self = clone $this;
16✔
566
        $self->provider = $provider;
16✔
567

568
        return $self;
16✔
569
    }
570

571
    public function getStateOptions(): ?OptionsInterface
572
    {
573
        return $this->stateOptions;
499✔
574
    }
575

576
    public function withStateOptions(?OptionsInterface $stateOptions): static
577
    {
578
        $self = clone $this;
8✔
579
        $self->stateOptions = $stateOptions;
8✔
580

581
        return $self;
8✔
582
    }
583

584
    /**
585
     * @return string|callable|array<string, \Illuminate\Contracts\Validation\Rule|array|string>
586
     */
587
    public function getRules(): mixed
588
    {
589
        return $this->rules;
24✔
590
    }
591

592
    /**
593
     * @param string|callable|array<string, \Illuminate\Contracts\Validation\Rule|array|string> $rules
594
     */
595
    public function withRules(mixed $rules): static
596
    {
597
        $self = clone $this;
×
598
        $self->rules = $rules;
×
599

600
        return $self;
×
601
    }
602

603
    public function getParameters(): ?Parameters
604
    {
605
        return $this->parameters;
495✔
606
    }
607

608
    public function withParameters(array|Parameters $parameters): static
609
    {
610
        $self = clone $this;
160✔
611
        $self->parameters = \is_array($parameters) ? new Parameters($parameters) : $parameters;
160✔
612

613
        return $self;
160✔
614
    }
615

616
    public function getQueryParameterValidationEnabled(): ?bool
617
    {
618
        return $this->queryParameterValidationEnabled;
436✔
619
    }
620

621
    public function withQueryParameterValidationEnabled(bool $queryParameterValidationEnabled): static
622
    {
NEW
623
        $self = clone $this;
×
NEW
624
        $self->queryParameterValidationEnabled = $queryParameterValidationEnabled;
×
625

UNCOV
626
        return $self;
×
627
    }
628

629
    public function getExtraProperties(): ?array
630
    {
631
        return $this->extraProperties;
536✔
632
    }
633

634
    public function withExtraProperties(array $extraProperties = []): static
635
    {
636
        $self = clone $this;
24✔
637
        $self->extraProperties = $extraProperties;
24✔
638

639
        return $self;
24✔
640
    }
641
}
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