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

api-platform / core / 16050929464

03 Jul 2025 12:51PM UTC coverage: 22.065% (+0.2%) from 21.821%
16050929464

push

github

soyuka
chore: todo improvement

11516 of 52192 relevant lines covered (22.06%)

22.08 hits per line

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

87.5
/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
    /** @var array<int|string, string|string[]>|null */
33
    protected $formats;
34
    /** @var array<int|string, string|string[]>|null */
35
    protected $inputFormats;
36
    /** @var array<int|string, string|string[]>|null */
37
    protected $outputFormats;
38

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

174
        ?string $shortName = null,
175
        ?string $class = null,
176
        ?bool $paginationEnabled = null,
177
        ?string $paginationType = null,
178
        ?int $paginationItemsPerPage = null,
179
        ?int $paginationMaximumItemsPerPage = null,
180
        ?bool $paginationPartial = null,
181
        ?bool $paginationClientEnabled = null,
182
        ?bool $paginationClientItemsPerPage = null,
183
        ?bool $paginationClientPartial = null,
184
        ?bool $paginationFetchJoinCollection = null,
185
        ?bool $paginationUseOutputWalkers = null,
186
        ?array $order = null,
187
        ?string $description = null,
188
        ?array $normalizationContext = null,
189
        ?array $denormalizationContext = null,
190
        ?bool $collectDenormalizationErrors = null,
191
        string|\Stringable|null $security = null,
192
        ?string $securityMessage = null,
193
        string|\Stringable|null $securityPostDenormalize = null,
194
        ?string $securityPostDenormalizeMessage = null,
195
        string|\Stringable|null $securityPostValidation = null,
196
        ?string $securityPostValidationMessage = null,
197
        ?string $deprecationReason = null,
198
        ?array $filters = null,
199
        ?array $validationContext = null,
200
        $input = null,
201
        $output = null,
202
        $mercure = null,
203
        $messenger = null,
204
        ?int $urlGenerationStrategy = null,
205
        ?bool $read = null,
206
        ?bool $deserialize = null,
207
        ?bool $validate = null,
208
        ?bool $write = null,
209
        ?bool $serialize = null,
210
        ?bool $fetchPartial = null,
211
        ?bool $forceEager = null,
212
        ?int $priority = null,
213
        ?string $name = null,
214
        $provider = null,
215
        $processor = null,
216
        ?OptionsInterface $stateOptions = null,
217
        array|Parameters|null $parameters = null,
218
        array|string|null $rules = null,
219
        ?string $policy = null,
220
        array|string|null $middleware = null,
221
        ?bool $queryParameterValidationEnabled = null,
222
        array $extraProperties = [],
223
    ) {
224
        $this->formats = (null === $formats || \is_array($formats)) ? $formats : [$formats];
717✔
225
        $this->inputFormats = (null === $inputFormats || \is_array($inputFormats)) ? $inputFormats : [$inputFormats];
717✔
226
        $this->outputFormats = (null === $outputFormats || \is_array($outputFormats)) ? $outputFormats : [$outputFormats];
717✔
227

228
        parent::__construct(
717✔
229
            shortName: $shortName,
717✔
230
            class: $class,
717✔
231
            paginationEnabled: $paginationEnabled,
717✔
232
            paginationType: $paginationType,
717✔
233
            paginationItemsPerPage: $paginationItemsPerPage,
717✔
234
            paginationMaximumItemsPerPage: $paginationMaximumItemsPerPage,
717✔
235
            paginationPartial: $paginationPartial,
717✔
236
            paginationClientEnabled: $paginationClientEnabled,
717✔
237
            paginationClientItemsPerPage: $paginationClientItemsPerPage,
717✔
238
            paginationClientPartial: $paginationClientPartial,
717✔
239
            paginationFetchJoinCollection: $paginationFetchJoinCollection,
717✔
240
            paginationUseOutputWalkers: $paginationUseOutputWalkers,
717✔
241
            order: $order,
717✔
242
            description: $description,
717✔
243
            normalizationContext: $normalizationContext,
717✔
244
            denormalizationContext: $denormalizationContext,
717✔
245
            collectDenormalizationErrors: $collectDenormalizationErrors,
717✔
246
            security: $security,
717✔
247
            securityMessage: $securityMessage,
717✔
248
            securityPostDenormalize: $securityPostDenormalize,
717✔
249
            securityPostDenormalizeMessage: $securityPostDenormalizeMessage,
717✔
250
            securityPostValidation: $securityPostValidation,
717✔
251
            securityPostValidationMessage: $securityPostValidationMessage,
717✔
252
            deprecationReason: $deprecationReason,
717✔
253
            filters: $filters,
717✔
254
            validationContext: $validationContext,
717✔
255
            input: $input,
717✔
256
            output: $output,
717✔
257
            mercure: $mercure,
717✔
258
            messenger: $messenger,
717✔
259
            urlGenerationStrategy: $urlGenerationStrategy,
717✔
260
            read: $read,
717✔
261
            deserialize: $deserialize,
717✔
262
            validate: $validate,
717✔
263
            write: $write,
717✔
264
            serialize: $serialize,
717✔
265
            fetchPartial: $fetchPartial,
717✔
266
            forceEager: $forceEager,
717✔
267
            priority: $priority,
717✔
268
            name: $name,
717✔
269
            provider: $provider,
717✔
270
            processor: $processor,
717✔
271
            stateOptions: $stateOptions,
717✔
272
            parameters: $parameters,
717✔
273
            rules: $rules,
717✔
274
            policy: $policy,
717✔
275
            middleware: $middleware,
717✔
276
            queryParameterValidationEnabled: $queryParameterValidationEnabled,
717✔
277
            strictQueryParameterValidation: $strictQueryParameterValidation,
717✔
278
            hideHydraOperation: $hideHydraOperation,
717✔
279
            extraProperties: $extraProperties
717✔
280
        );
717✔
281
    }
282

283
    public function getMethod(): string
284
    {
285
        return $this->method;
682✔
286
    }
287

288
    public function withMethod(string $method): static
289
    {
290
        $self = clone $this;
2✔
291
        $self->method = $method;
2✔
292

293
        return $self;
2✔
294
    }
295

296
    public function getUriTemplate(): ?string
297
    {
298
        return $this->uriTemplate;
594✔
299
    }
300

301
    public function withUriTemplate(?string $uriTemplate = null): static
302
    {
303
        $self = clone $this;
104✔
304
        $self->uriTemplate = $uriTemplate;
104✔
305

306
        return $self;
104✔
307
    }
308

309
    public function getTypes(): ?array
310
    {
311
        return $this->types;
566✔
312
    }
313

314
    /**
315
     * @param string[]|string $types
316
     */
317
    public function withTypes($types): static
318
    {
319
        $self = clone $this;
4✔
320
        $self->types = (array) $types;
4✔
321

322
        return $self;
4✔
323
    }
324

325
    /**
326
     * @return array<int|string, string|string[]>|null
327
     */
328
    public function getFormats()
329
    {
330
        return $this->formats;
106✔
331
    }
332

333
    /**
334
     * @param array<int|string, string|string[]>|string|null $formats
335
     */
336
    public function withFormats($formats = null): static
337
    {
338
        $self = clone $this;
2✔
339
        $self->formats = (null === $formats || \is_array($formats)) ? $formats : [$formats];
2✔
340

341
        return $self;
2✔
342
    }
343

344
    /**
345
     * @return array<int|string, string|string[]>|null
346
     */
347
    public function getInputFormats()
348
    {
349
        return $this->inputFormats;
139✔
350
    }
351

352
    /**
353
     * @param array<int|string, string|string[]>|string|null $inputFormats
354
     */
355
    public function withInputFormats($inputFormats = null): static
356
    {
357
        $self = clone $this;
104✔
358
        $self->inputFormats = (null === $inputFormats || \is_array($inputFormats)) ? $inputFormats : [$inputFormats];
104✔
359

360
        return $self;
104✔
361
    }
362

363
    /**
364
     * @return array<int|string, string|string[]>|null
365
     */
366
    public function getOutputFormats()
367
    {
368
        return $this->outputFormats;
560✔
369
    }
370

371
    /**
372
     * @param array<int|string, string|string[]>|string|null $outputFormats
373
     */
374
    public function withOutputFormats($outputFormats = null): static
375
    {
376
        $self = clone $this;
100✔
377
        $self->outputFormats = (null === $outputFormats || \is_array($outputFormats)) ? $outputFormats : [$outputFormats];
100✔
378

379
        return $self;
100✔
380
    }
381

382
    /**
383
     * @return array<string, mixed>|array<int, Link>|list<string>|null
384
     */
385
    public function getUriVariables()
386
    {
387
        return $this->uriVariables;
590✔
388
    }
389

390
    /**
391
     * @param array<string, mixed>|array<int, Link>|list<string> $uriVariables
392
     */
393
    public function withUriVariables($uriVariables): static
394
    {
395
        $self = clone $this;
106✔
396
        $self->uriVariables = $uriVariables;
106✔
397

398
        return $self;
106✔
399
    }
400

401
    public function getRoutePrefix(): ?string
402
    {
403
        return $this->routePrefix;
134✔
404
    }
405

406
    public function withRoutePrefix(string $routePrefix): static
407
    {
408
        $self = clone $this;
2✔
409
        $self->routePrefix = $routePrefix;
2✔
410

411
        return $self;
2✔
412
    }
413

414
    public function getRouteName(): ?string
415
    {
416
        return $this->routeName;
563✔
417
    }
418

419
    public function withRouteName(?string $routeName): static
420
    {
421
        $self = clone $this;
×
422
        $self->routeName = $routeName;
×
423

424
        return $self;
×
425
    }
426

427
    public function getDefaults(): ?array
428
    {
429
        return $this->defaults;
132✔
430
    }
431

432
    public function withDefaults(array $defaults): static
433
    {
434
        $self = clone $this;
4✔
435
        $self->defaults = $defaults;
4✔
436

437
        return $self;
4✔
438
    }
439

440
    public function getRequirements(): ?array
441
    {
442
        return $this->requirements;
132✔
443
    }
444

445
    public function withRequirements(array $requirements): static
446
    {
447
        $self = clone $this;
6✔
448
        $self->requirements = $requirements;
6✔
449

450
        return $self;
6✔
451
    }
452

453
    public function getOptions(): ?array
454
    {
455
        return $this->options;
132✔
456
    }
457

458
    public function withOptions(array $options): static
459
    {
460
        $self = clone $this;
2✔
461
        $self->options = $options;
2✔
462

463
        return $self;
2✔
464
    }
465

466
    public function getStateless(): ?bool
467
    {
468
        return $this->stateless;
132✔
469
    }
470

471
    public function withStateless($stateless): static
472
    {
473
        $self = clone $this;
2✔
474
        $self->stateless = $stateless;
2✔
475

476
        return $self;
2✔
477
    }
478

479
    public function getSunset(): ?string
480
    {
481
        return $this->sunset;
514✔
482
    }
483

484
    public function withSunset(string $sunset): static
485
    {
486
        $self = clone $this;
2✔
487
        $self->sunset = $sunset;
2✔
488

489
        return $self;
2✔
490
    }
491

492
    public function getAcceptPatch(): ?string
493
    {
494
        return $this->acceptPatch;
514✔
495
    }
496

497
    public function withAcceptPatch(string $acceptPatch): static
498
    {
499
        $self = clone $this;
30✔
500
        $self->acceptPatch = $acceptPatch;
30✔
501

502
        return $self;
30✔
503
    }
504

505
    public function getStatus(): ?int
506
    {
507
        return $this->status;
575✔
508
    }
509

510
    public function withStatus(int $status): static
511
    {
512
        $self = clone $this;
84✔
513
        $self->status = $status;
84✔
514

515
        return $self;
84✔
516
    }
517

518
    public function getHost(): ?string
519
    {
520
        return $this->host;
132✔
521
    }
522

523
    public function withHost(string $host): static
524
    {
525
        $self = clone $this;
2✔
526
        $self->host = $host;
2✔
527

528
        return $self;
2✔
529
    }
530

531
    public function getSchemes(): ?array
532
    {
533
        return $this->schemes;
132✔
534
    }
535

536
    public function withSchemes(array $schemes): static
537
    {
538
        $self = clone $this;
2✔
539
        $self->schemes = $schemes;
2✔
540

541
        return $self;
2✔
542
    }
543

544
    public function getCondition(): ?string
545
    {
546
        return $this->condition;
132✔
547
    }
548

549
    public function withCondition(string $condition): static
550
    {
551
        $self = clone $this;
2✔
552
        $self->condition = $condition;
2✔
553

554
        return $self;
2✔
555
    }
556

557
    public function getController(): ?string
558
    {
559
        return $this->controller;
150✔
560
    }
561

562
    public function withController(string $controller): static
563
    {
564
        $self = clone $this;
54✔
565
        $self->controller = $controller;
54✔
566

567
        return $self;
54✔
568
    }
569

570
    public function getHeaders(): ?array
571
    {
572
        return $this->headers;
514✔
573
    }
574

575
    public function withHeaders(array $headers): static
576
    {
577
        $self = clone $this;
×
578
        $self->headers = $headers;
×
579

580
        return $self;
×
581
    }
582

583
    public function getCacheHeaders(): ?array
584
    {
585
        return $this->cacheHeaders;
453✔
586
    }
587

588
    public function withCacheHeaders(array $cacheHeaders): static
589
    {
590
        $self = clone $this;
100✔
591
        $self->cacheHeaders = $cacheHeaders;
100✔
592

593
        return $self;
100✔
594
    }
595

596
    public function getPaginationViaCursor(): ?array
597
    {
598
        return $this->paginationViaCursor;
284✔
599
    }
600

601
    public function withPaginationViaCursor(array $paginationViaCursor): static
602
    {
603
        $self = clone $this;
×
604
        $self->paginationViaCursor = $paginationViaCursor;
×
605

606
        return $self;
×
607
    }
608

609
    public function getHydraContext(): ?array
610
    {
611
        return $this->hydraContext;
106✔
612
    }
613

614
    public function withHydraContext(array $hydraContext): static
615
    {
616
        $self = clone $this;
×
617
        $self->hydraContext = $hydraContext;
×
618

619
        return $self;
×
620
    }
621

622
    public function getOpenapi(): bool|OpenApiOperation|Webhook|null
623
    {
624
        return $this->openapi;
134✔
625
    }
626

627
    public function withOpenapi(bool|OpenApiOperation|Webhook $openapi): static
628
    {
629
        $self = clone $this;
4✔
630
        $self->openapi = $openapi;
4✔
631

632
        return $self;
4✔
633
    }
634

635
    public function getExceptionToStatus(): ?array
636
    {
637
        return $this->exceptionToStatus;
164✔
638
    }
639

640
    public function withExceptionToStatus(array $exceptionToStatus): static
641
    {
642
        $self = clone $this;
×
643
        $self->exceptionToStatus = $exceptionToStatus;
×
644

645
        return $self;
×
646
    }
647

648
    public function getLinks(): ?array
649
    {
650
        return $this->links;
517✔
651
    }
652

653
    /**
654
     * @param WebLink[] $links
655
     */
656
    public function withLinks(array $links): static
657
    {
658
        $self = clone $this;
×
659
        $self->links = $links;
×
660

661
        return $self;
×
662
    }
663

664
    public function getErrors(): ?array
665
    {
666
        return $this->errors;
22✔
667
    }
668

669
    /**
670
     * @param class-string<ProblemExceptionInterface>[] $errors
671
     */
672
    public function withErrors(array $errors): static
673
    {
674
        $self = clone $this;
×
675
        $self->errors = $errors;
×
676

677
        return $self;
×
678
    }
679
}
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