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

api-platform / core / 13944674159

19 Mar 2025 10:47AM UTC coverage: 7.275% (-0.01%) from 7.289%
13944674159

push

github

soyuka
Merge 3.4

6 of 23 new or added lines in 4 files covered. (26.09%)

2380 existing lines in 154 files now uncovered.

12415 of 170643 relevant lines covered (7.28%)

12.04 hits per line

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

92.68
/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
     * }|null $cacheHeaders {@see https://api-platform.com/docs/core/performance/#setting-custom-http-cache-headers}
60
     * @param array<string, string>|null $headers
61
     * @param array{
62
     *     field: string,
63
     *     direction: string,
64
     * }|null $paginationViaCursor {@see https://api-platform.com/docs/core/pagination/#cursor-based-pagination}
65
     * @param array|null $normalizationContext   {@see https://api-platform.com/docs/core/serialization/#using-serialization-groups}
66
     * @param array|null $denormalizationContext {@see https://api-platform.com/docs/core/serialization/#using-serialization-groups}
67
     * @param array|null $hydraContext           {@see https://api-platform.com/docs/core/extending-jsonld-context/#hydra}
68
     * @param array{
69
     *     class?: string|null,
70
     *     name?: string,
71
     * }|string|false|null $input {@see https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation}
72
     * @param array{
73
     *     class?: string|null,
74
     *     name?: string,
75
     * }|string|false|null $output {@see https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation}
76
     * @param string|array|bool|null                              $mercure   {@see https://api-platform.com/docs/core/mercure}
77
     * @param string|bool|null                                    $messenger {@see https://api-platform.com/docs/core/messenger/#dispatching-a-resource-through-the-message-bus}
78
     * @param string|callable|null                                $provider  {@see https://api-platform.com/docs/core/state-providers/#state-providers}
79
     * @param string|callable|null                                $processor {@see https://api-platform.com/docs/core/state-processors/#state-processors}
80
     * @param WebLink[]|null                                      $links
81
     * @param array<class-string<ProblemExceptionInterface>>|null $errors
82
     */
83
    public function __construct(
84
        protected string $method = 'GET',
85
        protected ?string $uriTemplate = null,
86
        protected ?array $types = null,
87
        protected $formats = null,
88
        protected $inputFormats = null,
89
        protected $outputFormats = null,
90
        protected $uriVariables = null,
91
        protected ?string $routePrefix = null,
92
        protected ?string $routeName = null,
93
        protected ?array $defaults = null,
94
        protected ?array $requirements = null,
95
        protected ?array $options = null,
96
        protected ?bool $stateless = null,
97
        /**
98
         * The `sunset` option indicates when a deprecated operation will be removed.
99
         *
100
         * <div data-code-selector>
101
         *
102
         * ```php
103
         * <?php
104
         * // api/src/Entity/Parchment.php
105
         * use ApiPlatform\Metadata\Get;
106
         *
107
         * #[Get(deprecationReason: 'Create a Book instead', sunset: '01/01/2020')]
108
         * class Parchment
109
         * {
110
         *     // ...
111
         * }
112
         * ```
113
         *
114
         * ```yaml
115
         * # api/config/api_platform/resources.yaml
116
         * resources:
117
         *     App\Entity\Parchment:
118
         *         - operations:
119
         *               ApiPlatform\Metadata\Get:
120
         *                   deprecationReason: 'Create a Book instead'
121
         *                   sunset: '01/01/2020'
122
         * ```
123
         *
124
         * ```xml
125
         * <?xml version="1.0" encoding="UTF-8" ?>
126
         * <!-- api/config/api_platform/resources.xml -->
127
         *
128
         * <resources
129
         *         xmlns="https://api-platform.com/schema/metadata/resources-3.0"
130
         *         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
131
         *         xsi:schemaLocation="https://api-platform.com/schema/metadata/resources-3.0
132
         *         https://api-platform.com/schema/metadata/resources-3.0.xsd">
133
         *     <resource class="App\Entity\Parchment">
134
         *         <operations>
135
         *             <operation class="ApiPlatform\Metadata\Get" deprecationReason="Create a Book instead" sunset="01/01/2020" />
136
         *         <operations>
137
         *     </resource>
138
         * </resources>
139
         * ```
140
         *
141
         * </div>
142
         */
143
        protected ?string $sunset = null,
144
        protected ?string $acceptPatch = null,
145
        protected $status = null,
146
        protected ?string $host = null,
147
        protected ?array $schemes = null,
148
        protected ?string $condition = null,
149
        protected ?string $controller = null,
150
        protected ?array $headers = null,
151
        protected ?array $cacheHeaders = null,
152
        protected ?array $paginationViaCursor = null,
153
        protected ?array $hydraContext = null,
154
        protected bool|OpenApiOperation|Webhook|null $openapi = null,
155
        protected ?array $exceptionToStatus = null,
156
        protected ?array $links = null,
157
        protected ?array $errors = null,
158

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

264
    public function getMethod(): string
265
    {
266
        return $this->method;
1,310✔
267
    }
268

269
    public function withMethod(string $method): self
270
    {
271
        $self = clone $this;
3✔
272
        $self->method = $method;
3✔
273

274
        return $self;
3✔
275
    }
276

277
    public function getUriTemplate(): ?string
278
    {
279
        return $this->uriTemplate;
1,186✔
280
    }
281

282
    public function withUriTemplate(?string $uriTemplate = null)
283
    {
284
        $self = clone $this;
118✔
285
        $self->uriTemplate = $uriTemplate;
118✔
286

287
        return $self;
118✔
288
    }
289

290
    public function getTypes(): ?array
291
    {
292
        return $this->types;
1,020✔
293
    }
294

295
    /**
296
     * @param string[]|string $types
297
     */
298
    public function withTypes($types): self
299
    {
300
        $self = clone $this;
9✔
301
        $self->types = (array) $types;
9✔
302

303
        return $self;
9✔
304
    }
305

306
    public function getFormats()
307
    {
308
        return $this->formats;
116✔
309
    }
310

311
    public function withFormats($formats = null): self
312
    {
313
        $self = clone $this;
4✔
314
        $self->formats = $formats;
4✔
315

316
        return $self;
4✔
317
    }
318

319
    public function getInputFormats()
320
    {
321
        return $this->inputFormats;
340✔
322
    }
323

324
    public function withInputFormats($inputFormats = null): self
325
    {
326
        $self = clone $this;
113✔
327
        $self->inputFormats = $inputFormats;
113✔
328

329
        return $self;
113✔
330
    }
331

332
    public function getOutputFormats()
333
    {
334
        return $this->outputFormats;
992✔
335
    }
336

337
    public function withOutputFormats($outputFormats = null): self
338
    {
339
        $self = clone $this;
107✔
340
        $self->outputFormats = $outputFormats;
107✔
341

342
        return $self;
107✔
343
    }
344

345
    public function getUriVariables()
346
    {
347
        return $this->uriVariables;
1,169✔
348
    }
349

350
    public function withUriVariables($uriVariables): self
351
    {
352
        $self = clone $this;
116✔
353
        $self->uriVariables = $uriVariables;
116✔
354

355
        return $self;
116✔
356
    }
357

358
    public function getRoutePrefix(): ?string
359
    {
360
        return $this->routePrefix;
158✔
361
    }
362

363
    public function withRoutePrefix(string $routePrefix): self
364
    {
365
        $self = clone $this;
4✔
366
        $self->routePrefix = $routePrefix;
4✔
367

368
        return $self;
4✔
369
    }
370

371
    public function getRouteName(): ?string
372
    {
373
        return $this->routeName;
1,098✔
374
    }
375

376
    public function withRouteName(?string $routeName): self
377
    {
378
        $self = clone $this;
×
379
        $self->routeName = $routeName;
×
380

381
        return $self;
×
382
    }
383

384
    public function getDefaults(): ?array
385
    {
386
        return $this->defaults;
155✔
387
    }
388

389
    public function withDefaults(array $defaults): self
390
    {
391
        $self = clone $this;
6✔
392
        $self->defaults = $defaults;
6✔
393

394
        return $self;
6✔
395
    }
396

397
    public function getRequirements(): ?array
398
    {
399
        return $this->requirements;
155✔
400
    }
401

402
    public function withRequirements(array $requirements): self
403
    {
404
        $self = clone $this;
6✔
405
        $self->requirements = $requirements;
6✔
406

407
        return $self;
6✔
408
    }
409

410
    public function getOptions(): ?array
411
    {
412
        return $this->options;
155✔
413
    }
414

415
    public function withOptions(array $options): self
416
    {
417
        $self = clone $this;
3✔
418
        $self->options = $options;
3✔
419

420
        return $self;
3✔
421
    }
422

423
    public function getStateless(): ?bool
424
    {
425
        return $this->stateless;
155✔
426
    }
427

428
    public function withStateless($stateless): self
429
    {
430
        $self = clone $this;
3✔
431
        $self->stateless = $stateless;
3✔
432

433
        return $self;
3✔
434
    }
435

436
    public function getSunset(): ?string
437
    {
438
        return $this->sunset;
957✔
439
    }
440

441
    public function withSunset(string $sunset): self
442
    {
443
        $self = clone $this;
4✔
444
        $self->sunset = $sunset;
4✔
445

446
        return $self;
4✔
447
    }
448

449
    public function getAcceptPatch(): ?string
450
    {
451
        return $this->acceptPatch;
957✔
452
    }
453

454
    public function withAcceptPatch(string $acceptPatch): self
455
    {
456
        $self = clone $this;
42✔
457
        $self->acceptPatch = $acceptPatch;
42✔
458

459
        return $self;
42✔
460
    }
461

462
    public function getStatus(): ?int
463
    {
464
        return $this->status;
1,132✔
465
    }
466

467
    public function withStatus(int $status): self
468
    {
469
        $self = clone $this;
164✔
470
        $self->status = $status;
164✔
471

472
        return $self;
164✔
473
    }
474

475
    public function getHost(): ?string
476
    {
477
        return $this->host;
155✔
478
    }
479

480
    public function withHost(string $host): self
481
    {
482
        $self = clone $this;
3✔
483
        $self->host = $host;
3✔
484

485
        return $self;
3✔
486
    }
487

488
    public function getSchemes(): ?array
489
    {
490
        return $this->schemes;
155✔
491
    }
492

493
    public function withSchemes(array $schemes): self
494
    {
495
        $self = clone $this;
3✔
496
        $self->schemes = $schemes;
3✔
497

498
        return $self;
3✔
499
    }
500

501
    public function getCondition(): ?string
502
    {
503
        return $this->condition;
155✔
504
    }
505

506
    public function withCondition(string $condition): self
507
    {
508
        $self = clone $this;
3✔
509
        $self->condition = $condition;
3✔
510

511
        return $self;
3✔
512
    }
513

514
    public function getController(): ?string
515
    {
516
        return $this->controller;
182✔
517
    }
518

519
    public function withController(string $controller): self
520
    {
521
        $self = clone $this;
85✔
522
        $self->controller = $controller;
85✔
523

524
        return $self;
85✔
525
    }
526

527
    public function getHeaders(): ?array
528
    {
529
        return $this->headers;
957✔
530
    }
531

532
    public function withHeaders(array $headers): self
533
    {
UNCOV
534
        $self = clone $this;
1✔
UNCOV
535
        $self->headers = $headers;
1✔
536

UNCOV
537
        return $self;
1✔
538
    }
539

540
    public function getCacheHeaders(): ?array
541
    {
542
        return $this->cacheHeaders;
686✔
543
    }
544

545
    public function withCacheHeaders(array $cacheHeaders): self
546
    {
547
        $self = clone $this;
107✔
548
        $self->cacheHeaders = $cacheHeaders;
107✔
549

550
        return $self;
107✔
551
    }
552

553
    public function getPaginationViaCursor(): ?array
554
    {
555
        return $this->paginationViaCursor;
232✔
556
    }
557

558
    public function withPaginationViaCursor(array $paginationViaCursor): self
559
    {
UNCOV
560
        $self = clone $this;
1✔
UNCOV
561
        $self->paginationViaCursor = $paginationViaCursor;
1✔
562

UNCOV
563
        return $self;
1✔
564
    }
565

566
    public function getHydraContext(): ?array
567
    {
568
        return $this->hydraContext;
120✔
569
    }
570

571
    public function withHydraContext(array $hydraContext): self
572
    {
UNCOV
573
        $self = clone $this;
1✔
UNCOV
574
        $self->hydraContext = $hydraContext;
1✔
575

UNCOV
576
        return $self;
1✔
577
    }
578

579
    public function getOpenapi(): bool|OpenApiOperation|Webhook|null
580
    {
581
        return $this->openapi;
146✔
582
    }
583

584
    public function withOpenapi(bool|OpenApiOperation|Webhook $openapi): self
585
    {
586
        $self = clone $this;
6✔
587
        $self->openapi = $openapi;
6✔
588

589
        return $self;
6✔
590
    }
591

592
    public function getExceptionToStatus(): ?array
593
    {
594
        return $this->exceptionToStatus;
243✔
595
    }
596

597
    public function withExceptionToStatus(array $exceptionToStatus): self
598
    {
599
        $self = clone $this;
×
600
        $self->exceptionToStatus = $exceptionToStatus;
×
601

602
        return $self;
×
603
    }
604

605
    public function getLinks(): ?array
606
    {
607
        return $this->links;
962✔
608
    }
609

610
    /**
611
     * @param WebLink[] $links
612
     */
613
    public function withLinks(array $links): self
614
    {
615
        $self = clone $this;
×
616
        $self->links = $links;
×
617

618
        return $self;
×
619
    }
620

621
    public function getErrors(): ?array
622
    {
623
        return $this->errors;
33✔
624
    }
625

626
    /**
627
     * @param class-string<ProblemExceptionInterface>[] $errors
628
     */
629
    public function withErrors(array $errors): self
630
    {
631
        $self = clone $this;
×
632
        $self->errors = $errors;
×
633

634
        return $self;
×
635
    }
636
}
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