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

api-platform / core / 15133993414

20 May 2025 09:30AM UTC coverage: 26.313% (-1.2%) from 27.493%
15133993414

Pull #7161

github

web-flow
Merge e2c03d45f into 5459ba375
Pull Request #7161: fix(metadata): infer parameter string type from schema

0 of 2 new or added lines in 1 file covered. (0.0%)

11019 existing lines in 363 files now uncovered.

12898 of 49018 relevant lines covered (26.31%)

34.33 hits per line

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

91.89
/src/Symfony/Controller/MainController.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\Symfony\Controller;
15

16
use ApiPlatform\Metadata\Exception\InvalidIdentifierException;
17
use ApiPlatform\Metadata\Exception\InvalidUriVariableException;
18
use ApiPlatform\Metadata\Exception\RuntimeException;
19
use ApiPlatform\Metadata\HttpOperation;
20
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
21
use ApiPlatform\Metadata\UriVariablesConverterInterface;
22
use ApiPlatform\State\ProcessorInterface;
23
use ApiPlatform\State\ProviderInterface;
24
use ApiPlatform\State\UriVariablesResolverTrait;
25
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
26
use Psr\Log\LoggerInterface;
27
use Symfony\Component\HttpFoundation\Request;
28
use Symfony\Component\HttpFoundation\Response;
29
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
30

31
final class MainController
32
{
33
    use OperationRequestInitiatorTrait;
34
    use UriVariablesResolverTrait;
35

36
    public function __construct(
37
        ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory,
38
        private readonly ProviderInterface $provider,
39
        private readonly ProcessorInterface $processor,
40
        ?UriVariablesConverterInterface $uriVariablesConverter = null,
41
        private readonly ?LoggerInterface $logger = null,
42
    ) {
UNCOV
43
        $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
767✔
UNCOV
44
        $this->uriVariablesConverter = $uriVariablesConverter;
767✔
45
    }
46

47
    public function __invoke(Request $request): Response
48
    {
UNCOV
49
        $operation = $this->initializeOperation($request);
767✔
50

UNCOV
51
        if (!$operation) {
767✔
UNCOV
52
            throw new RuntimeException('Not an API operation.');
1✔
53
        }
54

UNCOV
55
        $uriVariables = [];
766✔
UNCOV
56
        if (!$request->attributes->has('exception')) {
766✔
57
            try {
UNCOV
58
                $uriVariables = $this->getOperationUriVariables($operation, $request->attributes->all(), $operation->getClass());
758✔
UNCOV
59
                $request->attributes->set('_api_uri_variables', $uriVariables);
756✔
UNCOV
60
            } catch (InvalidIdentifierException|InvalidUriVariableException $e) {
2✔
UNCOV
61
                throw new NotFoundHttpException('Invalid uri variables.', $e);
2✔
62
            }
63
        }
64

UNCOV
65
        $context = [
765✔
UNCOV
66
            'request' => $request,
765✔
UNCOV
67
            'uri_variables' => $uriVariables,
765✔
UNCOV
68
            'resource_class' => $operation->getClass(),
765✔
UNCOV
69
        ];
765✔
70

UNCOV
71
        if (null === $operation->canValidate()) {
765✔
UNCOV
72
            $operation = $operation->withValidate(!$request->isMethodSafe() && !$request->isMethod('DELETE'));
765✔
73
        }
74

UNCOV
75
        if (null === $operation->canRead() && $operation instanceof HttpOperation) {
765✔
UNCOV
76
            $operation = $operation->withRead($operation->getUriVariables() || $request->isMethodSafe());
764✔
77
        }
78

UNCOV
79
        if (null === $operation->canDeserialize() && $operation instanceof HttpOperation) {
765✔
UNCOV
80
            $operation = $operation->withDeserialize(\in_array($operation->getMethod(), ['POST', 'PUT', 'PATCH'], true));
765✔
81
        }
82

UNCOV
83
        $body = $this->provider->provide($operation, $uriVariables, $context);
765✔
84

85
        // The provider can change the Operation, extract it again from the Request attributes
UNCOV
86
        if ($request->attributes->get('_api_operation') !== $operation) {
758✔
UNCOV
87
            $operation = $this->initializeOperation($request);
343✔
88

UNCOV
89
            if (!$request->attributes->has('exception')) {
343✔
90
                try {
UNCOV
91
                    $uriVariables = $this->getOperationUriVariables($operation, $request->attributes->all(), $operation->getClass());
341✔
92
                } catch (InvalidIdentifierException|InvalidUriVariableException $e) {
×
93
                    // if this occurs with our base operation we throw above so log instead of throw here
94
                    if ($this->logger) {
×
95
                        $this->logger->error($e->getMessage(), ['operation' => $operation]);
×
96
                    }
97
                }
98
            }
99
        }
100

UNCOV
101
        $context['previous_data'] = $request->attributes->get('previous_data');
758✔
UNCOV
102
        $context['data'] = $request->attributes->get('data');
758✔
103

UNCOV
104
        if (null === $operation->canWrite()) {
758✔
UNCOV
105
            $operation = $operation->withWrite(!$request->isMethodSafe());
755✔
106
        }
107

UNCOV
108
        if (null === $operation->canSerialize()) {
758✔
UNCOV
109
            $operation = $operation->withSerialize(true);
758✔
110
        }
111

UNCOV
112
        return $this->processor->process($body, $operation, $uriVariables, $context);
758✔
113
    }
114
}
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