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

api-platform / core / 16000879782

01 Jul 2025 01:34PM UTC coverage: 22.06% (+0.2%) from 21.821%
16000879782

Pull #7269

github

web-flow
Merge bfd1fa933 into 82ab5ef14
Pull Request #7269: chore: introduce phpstan level 6

11 of 14 new or added lines in 7 files covered. (78.57%)

20 existing lines in 1 file now uncovered.

11513 of 52189 relevant lines covered (22.06%)

22.04 hits per line

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

87.27
/src/Metadata/HttpOperation.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\OpenApi\Attributes\Webhook;
18
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
19
use ApiPlatform\State\OptionsInterface;
20
use Symfony\Component\WebLink\Link as WebLink;
21

22
class HttpOperation extends Operation
23
{
24
    public const METHOD_GET = 'GET';
25
    public const METHOD_POST = 'POST';
26
    public const METHOD_PUT = 'PUT';
27
    public const METHOD_PATCH = 'PATCH';
28
    public const METHOD_DELETE = 'DELETE';
29
    public const METHOD_HEAD = 'HEAD';
30
    public const METHOD_OPTIONS = 'OPTIONS';
31

32
    /**
33
     * @param string[]|null                                  $types         the RDF types of this property
34
     * @param array<int|string, string|string[]>|string|null $formats       {@see https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation}
35
     * @param array<int|string, string|string[]>|string|null $inputFormats  {@see https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation}
36
     * @param array<int|string, string|string[]>|string|null $outputFormats {@see https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation}
37
     * @param array<string,array{
38
     *     0: string,
39
     *     1: string
40
     * }|array{
41
     *     from_property?: string,
42
     *     to_property?: string,
43
     *     from_class?: string,
44
     *     to_class?: string,
45
     *     identifiers?: string[],
46
     *     composite_identifier?: bool,
47
     *     expanded_value?: string,
48
     * }|Link>|string[]|string|null $uriVariables {@see https://api-platform.com/docs/core/subresources/}
49
     * @param string|null     $routePrefix {@see https://api-platform.com/docs/core/operations/#prefixing-all-routes-of-all-operations}
50
     * @param string|null     $sunset      {@see https://api-platform.com/docs/core/deprecations/#setting-the-sunset-http-header-to-indicate-when-a-resource-or-an-operation-will-be-removed}
51
     * @param string|int|null $status      {@see https://api-platform.com/docs/core/operations/#configuring-operations}
52
     * @param array{
53
     *     max_age?: int,
54
     *     vary?: string|string[],
55
     *     public?: bool,
56
     *     shared_max_age?: int,
57
     *     stale_while_revalidate?: int,
58
     *     stale_if_error?: int,
59
     *     must_revalidate?: bool,
60
     *     proxy_revalidate?: bool,
61
     *     no_cache?: bool,
62
     *     no_store?: bool,
63
     *     no_transform?: bool,
64
     *     immutable?: bool,
65
     * }|null $cacheHeaders {@see https://api-platform.com/docs/core/performance/#setting-custom-http-cache-headers}
66
     * @param array<string, string>|null $headers
67
     * @param array{
68
     *     field: string,
69
     *     direction: string,
70
     * }|null $paginationViaCursor {@see https://api-platform.com/docs/core/pagination/#cursor-based-pagination}
71
     * @param array|null $normalizationContext   {@see https://api-platform.com/docs/core/serialization/#using-serialization-groups}
72
     * @param array|null $denormalizationContext {@see https://api-platform.com/docs/core/serialization/#using-serialization-groups}
73
     * @param array|null $hydraContext           {@see https://api-platform.com/docs/core/extending-jsonld-context/#hydra}
74
     * @param array{
75
     *     class?: string|null,
76
     *     name?: string,
77
     * }|string|false|null $input {@see https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation}
78
     * @param array{
79
     *     class?: string|null,
80
     *     name?: string,
81
     * }|string|false|null $output {@see https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation}
82
     * @param string|array|bool|null                              $mercure   {@see https://api-platform.com/docs/core/mercure}
83
     * @param string|bool|null                                    $messenger {@see https://api-platform.com/docs/core/messenger/#dispatching-a-resource-through-the-message-bus}
84
     * @param string|callable|null                                $provider  {@see https://api-platform.com/docs/core/state-providers/#state-providers}
85
     * @param string|callable|null                                $processor {@see https://api-platform.com/docs/core/state-processors/#state-processors}
86
     * @param WebLink[]|null                                      $links
87
     * @param array<class-string<ProblemExceptionInterface>>|null $errors
88
     */
89
    public function __construct(
90
        protected string $method = 'GET',
91
        protected ?string $uriTemplate = null,
92
        protected ?array $types = null,
93
        protected $formats = null,
94
        protected $inputFormats = null,
95
        protected $outputFormats = null,
96
        protected $uriVariables = null,
97
        protected ?string $routePrefix = null,
98
        protected ?string $routeName = null,
99
        protected ?array $defaults = null,
100
        protected ?array $requirements = null,
101
        protected ?array $options = null,
102
        protected ?bool $stateless = null,
103
        /**
104
         * The `sunset` option indicates when a deprecated operation will be removed.
105
         *
106
         * <div data-code-selector>
107
         *
108
         * ```php
109
         * <?php
110
         * // api/src/Entity/Parchment.php
111
         * use ApiPlatform\Metadata\Get;
112
         *
113
         * #[Get(deprecationReason: 'Create a Book instead', sunset: '01/01/2020')]
114
         * class Parchment
115
         * {
116
         *     // ...
117
         * }
118
         * ```
119
         *
120
         * ```yaml
121
         * # api/config/api_platform/resources.yaml
122
         * resources:
123
         *     App\Entity\Parchment:
124
         *         - operations:
125
         *               ApiPlatform\Metadata\Get:
126
         *                   deprecationReason: 'Create a Book instead'
127
         *                   sunset: '01/01/2020'
128
         * ```
129
         *
130
         * ```xml
131
         * <?xml version="1.0" encoding="UTF-8" ?>
132
         * <!-- api/config/api_platform/resources.xml -->
133
         *
134
         * <resources
135
         *         xmlns="https://api-platform.com/schema/metadata/resources-3.0"
136
         *         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
137
         *         xsi:schemaLocation="https://api-platform.com/schema/metadata/resources-3.0
138
         *         https://api-platform.com/schema/metadata/resources-3.0.xsd">
139
         *     <resource class="App\Entity\Parchment">
140
         *         <operations>
141
         *             <operation class="ApiPlatform\Metadata\Get" deprecationReason="Create a Book instead" sunset="01/01/2020" />
142
         *         <operations>
143
         *     </resource>
144
         * </resources>
145
         * ```
146
         *
147
         * </div>
148
         */
149
        protected ?string $sunset = null,
150
        protected ?string $acceptPatch = null,
151
        protected $status = null,
152
        protected ?string $host = null,
153
        protected ?array $schemes = null,
154
        protected ?string $condition = null,
155
        protected ?string $controller = null,
156
        protected ?array $headers = null,
157
        protected ?array $cacheHeaders = null,
158
        protected ?array $paginationViaCursor = null,
159
        protected ?array $hydraContext = null,
160
        protected bool|OpenApiOperation|Webhook|null $openapi = null,
161
        protected ?array $exceptionToStatus = null,
162
        protected ?array $links = null,
163
        protected ?array $errors = null,
164
        protected ?bool $strictQueryParameterValidation = null,
165
        protected ?bool $hideHydraOperation = null,
166

167
        ?string $shortName = null,
168
        ?string $class = null,
169
        ?bool $paginationEnabled = null,
170
        ?string $paginationType = null,
171
        ?int $paginationItemsPerPage = null,
172
        ?int $paginationMaximumItemsPerPage = null,
173
        ?bool $paginationPartial = null,
174
        ?bool $paginationClientEnabled = null,
175
        ?bool $paginationClientItemsPerPage = null,
176
        ?bool $paginationClientPartial = null,
177
        ?bool $paginationFetchJoinCollection = null,
178
        ?bool $paginationUseOutputWalkers = null,
179
        ?array $order = null,
180
        ?string $description = null,
181
        ?array $normalizationContext = null,
182
        ?array $denormalizationContext = null,
183
        ?bool $collectDenormalizationErrors = null,
184
        string|\Stringable|null $security = null,
185
        ?string $securityMessage = null,
186
        string|\Stringable|null $securityPostDenormalize = null,
187
        ?string $securityPostDenormalizeMessage = null,
188
        string|\Stringable|null $securityPostValidation = null,
189
        ?string $securityPostValidationMessage = null,
190
        ?string $deprecationReason = null,
191
        ?array $filters = null,
192
        ?array $validationContext = null,
193
        $input = null,
194
        $output = null,
195
        $mercure = null,
196
        $messenger = null,
197
        ?int $urlGenerationStrategy = null,
198
        ?bool $read = null,
199
        ?bool $deserialize = null,
200
        ?bool $validate = null,
201
        ?bool $write = null,
202
        ?bool $serialize = null,
203
        ?bool $fetchPartial = null,
204
        ?bool $forceEager = null,
205
        ?int $priority = null,
206
        ?string $name = null,
207
        $provider = null,
208
        $processor = null,
209
        ?OptionsInterface $stateOptions = null,
210
        array|Parameters|null $parameters = null,
211
        array|string|null $rules = null,
212
        ?string $policy = null,
213
        array|string|null $middleware = null,
214
        ?bool $queryParameterValidationEnabled = null,
215
        array $extraProperties = [],
216
    ) {
217
        parent::__construct(
717✔
218
            shortName: $shortName,
717✔
219
            class: $class,
717✔
220
            paginationEnabled: $paginationEnabled,
717✔
221
            paginationType: $paginationType,
717✔
222
            paginationItemsPerPage: $paginationItemsPerPage,
717✔
223
            paginationMaximumItemsPerPage: $paginationMaximumItemsPerPage,
717✔
224
            paginationPartial: $paginationPartial,
717✔
225
            paginationClientEnabled: $paginationClientEnabled,
717✔
226
            paginationClientItemsPerPage: $paginationClientItemsPerPage,
717✔
227
            paginationClientPartial: $paginationClientPartial,
717✔
228
            paginationFetchJoinCollection: $paginationFetchJoinCollection,
717✔
229
            paginationUseOutputWalkers: $paginationUseOutputWalkers,
717✔
230
            order: $order,
717✔
231
            description: $description,
717✔
232
            normalizationContext: $normalizationContext,
717✔
233
            denormalizationContext: $denormalizationContext,
717✔
234
            collectDenormalizationErrors: $collectDenormalizationErrors,
717✔
235
            security: $security,
717✔
236
            securityMessage: $securityMessage,
717✔
237
            securityPostDenormalize: $securityPostDenormalize,
717✔
238
            securityPostDenormalizeMessage: $securityPostDenormalizeMessage,
717✔
239
            securityPostValidation: $securityPostValidation,
717✔
240
            securityPostValidationMessage: $securityPostValidationMessage,
717✔
241
            deprecationReason: $deprecationReason,
717✔
242
            filters: $filters,
717✔
243
            validationContext: $validationContext,
717✔
244
            input: $input,
717✔
245
            output: $output,
717✔
246
            mercure: $mercure,
717✔
247
            messenger: $messenger,
717✔
248
            urlGenerationStrategy: $urlGenerationStrategy,
717✔
249
            read: $read,
717✔
250
            deserialize: $deserialize,
717✔
251
            validate: $validate,
717✔
252
            write: $write,
717✔
253
            serialize: $serialize,
717✔
254
            fetchPartial: $fetchPartial,
717✔
255
            forceEager: $forceEager,
717✔
256
            priority: $priority,
717✔
257
            name: $name,
717✔
258
            provider: $provider,
717✔
259
            processor: $processor,
717✔
260
            stateOptions: $stateOptions,
717✔
261
            parameters: $parameters,
717✔
262
            rules: $rules,
717✔
263
            policy: $policy,
717✔
264
            middleware: $middleware,
717✔
265
            queryParameterValidationEnabled: $queryParameterValidationEnabled,
717✔
266
            strictQueryParameterValidation: $strictQueryParameterValidation,
717✔
267
            hideHydraOperation: $hideHydraOperation,
717✔
268
            extraProperties: $extraProperties
717✔
269
        );
717✔
270
    }
271

272
    public function getMethod(): string
273
    {
274
        return $this->method;
682✔
275
    }
276

277
    public function withMethod(string $method): static
278
    {
279
        $self = clone $this;
2✔
280
        $self->method = $method;
2✔
281

282
        return $self;
2✔
283
    }
284

285
    public function getUriTemplate(): ?string
286
    {
287
        return $this->uriTemplate;
594✔
288
    }
289

290
    public function withUriTemplate(?string $uriTemplate = null): static
291
    {
292
        $self = clone $this;
104✔
293
        $self->uriTemplate = $uriTemplate;
104✔
294

295
        return $self;
104✔
296
    }
297

298
    public function getTypes(): ?array
299
    {
300
        return $this->types;
566✔
301
    }
302

303
    /**
304
     * @param string[]|string $types
305
     */
306
    public function withTypes($types): static
307
    {
308
        $self = clone $this;
4✔
309
        $self->types = (array) $types;
4✔
310

311
        return $self;
4✔
312
    }
313

314
    /**
315
     * @return array<int|string, string|string[]>|string|null
316
     */
317
    public function getFormats()
318
    {
319
        return $this->formats;
106✔
320
    }
321

322
    /**
323
     * @param array<int|string, string|string[]>|string|null $formats
324
     */
325
    public function withFormats($formats = null): static
326
    {
327
        $self = clone $this;
2✔
328
        $self->formats = $formats;
2✔
329

330
        return $self;
2✔
331
    }
332

333
    /**
334
     * @return array<int|string, string|string[]>|string|null
335
     */
336
    public function getInputFormats()
337
    {
338
        return $this->inputFormats;
139✔
339
    }
340

341
    /**
342
     * @param array<int|string, string|string[]>|string|null $inputFormats
343
     */
344
    public function withInputFormats($inputFormats = null): static
345
    {
346
        $self = clone $this;
104✔
347
        $self->inputFormats = $inputFormats;
104✔
348

349
        return $self;
104✔
350
    }
351

352
    /**
353
     * @return array<int|string, string|string[]>|string|null
354
     */
355
    public function getOutputFormats()
356
    {
357
        return $this->outputFormats;
560✔
358
    }
359

360
    /**
361
     * @param array<int|string, string|string[]>|string|null $outputFormats
362
     */
363
    public function withOutputFormats($outputFormats = null): static
364
    {
365
        $self = clone $this;
100✔
366
        $self->outputFormats = $outputFormats;
100✔
367

368
        return $self;
100✔
369
    }
370

371
    /**
372
     * @return array<string, mixed>|array<int, Link>|list<string>|null
373
     */
374
    public function getUriVariables()
375
    {
376
        return $this->uriVariables;
590✔
377
    }
378

379
    /**
380
     * @param array<string, mixed>|array<int, Link>|list<string> $uriVariables
381
     */
382
    public function withUriVariables($uriVariables): static
383
    {
384
        $self = clone $this;
106✔
385
        $self->uriVariables = $uriVariables;
106✔
386

387
        return $self;
106✔
388
    }
389

390
    public function getRoutePrefix(): ?string
391
    {
392
        return $this->routePrefix;
134✔
393
    }
394

395
    public function withRoutePrefix(string $routePrefix): static
396
    {
397
        $self = clone $this;
2✔
398
        $self->routePrefix = $routePrefix;
2✔
399

400
        return $self;
2✔
401
    }
402

403
    public function getRouteName(): ?string
404
    {
405
        return $this->routeName;
563✔
406
    }
407

408
    public function withRouteName(?string $routeName): static
409
    {
UNCOV
410
        $self = clone $this;
×
UNCOV
411
        $self->routeName = $routeName;
×
412

UNCOV
413
        return $self;
×
414
    }
415

416
    public function getDefaults(): ?array
417
    {
418
        return $this->defaults;
132✔
419
    }
420

421
    public function withDefaults(array $defaults): static
422
    {
423
        $self = clone $this;
4✔
424
        $self->defaults = $defaults;
4✔
425

426
        return $self;
4✔
427
    }
428

429
    public function getRequirements(): ?array
430
    {
431
        return $this->requirements;
132✔
432
    }
433

434
    public function withRequirements(array $requirements): static
435
    {
436
        $self = clone $this;
6✔
437
        $self->requirements = $requirements;
6✔
438

439
        return $self;
6✔
440
    }
441

442
    public function getOptions(): ?array
443
    {
444
        return $this->options;
132✔
445
    }
446

447
    public function withOptions(array $options): static
448
    {
449
        $self = clone $this;
2✔
450
        $self->options = $options;
2✔
451

452
        return $self;
2✔
453
    }
454

455
    public function getStateless(): ?bool
456
    {
457
        return $this->stateless;
132✔
458
    }
459

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

465
        return $self;
2✔
466
    }
467

468
    public function getSunset(): ?string
469
    {
470
        return $this->sunset;
514✔
471
    }
472

473
    public function withSunset(string $sunset): static
474
    {
475
        $self = clone $this;
2✔
476
        $self->sunset = $sunset;
2✔
477

478
        return $self;
2✔
479
    }
480

481
    public function getAcceptPatch(): ?string
482
    {
483
        return $this->acceptPatch;
514✔
484
    }
485

486
    public function withAcceptPatch(string $acceptPatch): static
487
    {
488
        $self = clone $this;
30✔
489
        $self->acceptPatch = $acceptPatch;
30✔
490

491
        return $self;
30✔
492
    }
493

494
    public function getStatus(): ?int
495
    {
496
        return $this->status;
575✔
497
    }
498

499
    public function withStatus(int $status): static
500
    {
501
        $self = clone $this;
84✔
502
        $self->status = $status;
84✔
503

504
        return $self;
84✔
505
    }
506

507
    public function getHost(): ?string
508
    {
509
        return $this->host;
132✔
510
    }
511

512
    public function withHost(string $host): static
513
    {
514
        $self = clone $this;
2✔
515
        $self->host = $host;
2✔
516

517
        return $self;
2✔
518
    }
519

520
    public function getSchemes(): ?array
521
    {
522
        return $this->schemes;
132✔
523
    }
524

525
    public function withSchemes(array $schemes): static
526
    {
527
        $self = clone $this;
2✔
528
        $self->schemes = $schemes;
2✔
529

530
        return $self;
2✔
531
    }
532

533
    public function getCondition(): ?string
534
    {
535
        return $this->condition;
132✔
536
    }
537

538
    public function withCondition(string $condition): static
539
    {
540
        $self = clone $this;
2✔
541
        $self->condition = $condition;
2✔
542

543
        return $self;
2✔
544
    }
545

546
    public function getController(): ?string
547
    {
548
        return $this->controller;
150✔
549
    }
550

551
    public function withController(string $controller): static
552
    {
553
        $self = clone $this;
54✔
554
        $self->controller = $controller;
54✔
555

556
        return $self;
54✔
557
    }
558

559
    public function getHeaders(): ?array
560
    {
561
        return $this->headers;
514✔
562
    }
563

564
    public function withHeaders(array $headers): static
565
    {
UNCOV
566
        $self = clone $this;
×
UNCOV
567
        $self->headers = $headers;
×
568

UNCOV
569
        return $self;
×
570
    }
571

572
    public function getCacheHeaders(): ?array
573
    {
574
        return $this->cacheHeaders;
453✔
575
    }
576

577
    public function withCacheHeaders(array $cacheHeaders): static
578
    {
579
        $self = clone $this;
100✔
580
        $self->cacheHeaders = $cacheHeaders;
100✔
581

582
        return $self;
100✔
583
    }
584

585
    public function getPaginationViaCursor(): ?array
586
    {
587
        return $this->paginationViaCursor;
284✔
588
    }
589

590
    public function withPaginationViaCursor(array $paginationViaCursor): static
591
    {
UNCOV
592
        $self = clone $this;
×
UNCOV
593
        $self->paginationViaCursor = $paginationViaCursor;
×
594

UNCOV
595
        return $self;
×
596
    }
597

598
    public function getHydraContext(): ?array
599
    {
600
        return $this->hydraContext;
106✔
601
    }
602

603
    public function withHydraContext(array $hydraContext): static
604
    {
UNCOV
605
        $self = clone $this;
×
606
        $self->hydraContext = $hydraContext;
×
607

UNCOV
608
        return $self;
×
609
    }
610

611
    public function getOpenapi(): bool|OpenApiOperation|Webhook|null
612
    {
613
        return $this->openapi;
134✔
614
    }
615

616
    public function withOpenapi(bool|OpenApiOperation|Webhook $openapi): static
617
    {
618
        $self = clone $this;
4✔
619
        $self->openapi = $openapi;
4✔
620

621
        return $self;
4✔
622
    }
623

624
    public function getExceptionToStatus(): ?array
625
    {
626
        return $this->exceptionToStatus;
164✔
627
    }
628

629
    public function withExceptionToStatus(array $exceptionToStatus): static
630
    {
UNCOV
631
        $self = clone $this;
×
UNCOV
632
        $self->exceptionToStatus = $exceptionToStatus;
×
633

UNCOV
634
        return $self;
×
635
    }
636

637
    public function getLinks(): ?array
638
    {
639
        return $this->links;
517✔
640
    }
641

642
    /**
643
     * @param WebLink[] $links
644
     */
645
    public function withLinks(array $links): static
646
    {
UNCOV
647
        $self = clone $this;
×
UNCOV
648
        $self->links = $links;
×
649

UNCOV
650
        return $self;
×
651
    }
652

653
    public function getErrors(): ?array
654
    {
655
        return $this->errors;
22✔
656
    }
657

658
    /**
659
     * @param class-string<ProblemExceptionInterface>[] $errors
660
     */
661
    public function withErrors(array $errors): static
662
    {
UNCOV
663
        $self = clone $this;
×
UNCOV
664
        $self->errors = $errors;
×
665

UNCOV
666
        return $self;
×
667
    }
668
}
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