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

api-platform / core / 14967870200

12 May 2025 08:47AM UTC coverage: 23.685% (+15.2%) from 8.477%
14967870200

push

github

web-flow
fix(serializer): invalid uri variable 400 response (#7135)

1 of 2 new or added lines in 2 files covered. (50.0%)

2825 existing lines in 152 files now uncovered.

11409 of 48169 relevant lines covered (23.69%)

54.89 hits per line

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

100.0
/src/Doctrine/Orm/Metadata/Resource/DoctrineOrmResourceCollectionMetadataFactory.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\Doctrine\Orm\Metadata\Resource;
15

16
use ApiPlatform\Doctrine\Orm\State\CollectionProvider;
17
use ApiPlatform\Doctrine\Orm\State\ItemProvider;
18
use ApiPlatform\Doctrine\Orm\State\Options;
19
use ApiPlatform\Metadata\ApiResource;
20
use ApiPlatform\Metadata\CollectionOperationInterface;
21
use ApiPlatform\Metadata\DeleteOperationInterface;
22
use ApiPlatform\Metadata\Operation;
23
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
24
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
25
use ApiPlatform\State\Util\StateOptionsTrait;
26
use Doctrine\ORM\EntityManagerInterface;
27
use Doctrine\Persistence\ManagerRegistry;
28

29
final class DoctrineOrmResourceCollectionMetadataFactory implements ResourceMetadataCollectionFactoryInterface
30
{
31
    use StateOptionsTrait;
32

33
    public function __construct(private readonly ManagerRegistry $managerRegistry, private readonly ResourceMetadataCollectionFactoryInterface $decorated)
34
    {
UNCOV
35
    }
845✔
36

37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function create(string $resourceClass): ResourceMetadataCollection
41
    {
UNCOV
42
        $resourceMetadataCollection = $this->decorated->create($resourceClass);
32✔
43

44
        /** @var ApiResource $resourceMetadata */
UNCOV
45
        foreach ($resourceMetadataCollection as $i => $resourceMetadata) {
32✔
UNCOV
46
            $operations = $resourceMetadata->getOperations();
30✔
47

UNCOV
48
            if ($operations) {
30✔
49
                /** @var Operation $operation */
UNCOV
50
                foreach ($resourceMetadata->getOperations() as $operationName => $operation) {
30✔
UNCOV
51
                    $entityClass = $this->getStateOptionsClass($operation, $operation->getClass(), Options::class);
30✔
52

UNCOV
53
                    if (!$this->managerRegistry->getManagerForClass($entityClass) instanceof EntityManagerInterface) {
30✔
UNCOV
54
                        continue;
5✔
55
                    }
56

UNCOV
57
                    $operations->add($operationName, $this->addDefaults($operation));
28✔
58
                }
59

UNCOV
60
                $resourceMetadata = $resourceMetadata->withOperations($operations);
30✔
61
            }
62

UNCOV
63
            $graphQlOperations = $resourceMetadata->getGraphQlOperations();
30✔
64

UNCOV
65
            if ($graphQlOperations) {
30✔
UNCOV
66
                foreach ($graphQlOperations as $operationName => $graphQlOperation) {
27✔
UNCOV
67
                    $entityClass = $this->getStateOptionsClass($graphQlOperation, $graphQlOperation->getClass(), Options::class);
27✔
68

UNCOV
69
                    if (!$this->managerRegistry->getManagerForClass($entityClass) instanceof EntityManagerInterface) {
27✔
UNCOV
70
                        continue;
3✔
71
                    }
72

UNCOV
73
                    $graphQlOperations[$operationName] = $this->addDefaults($graphQlOperation);
26✔
74
                }
75

UNCOV
76
                $resourceMetadata = $resourceMetadata->withGraphQlOperations($graphQlOperations);
27✔
77
            }
78

UNCOV
79
            $resourceMetadataCollection[$i] = $resourceMetadata;
30✔
80
        }
81

UNCOV
82
        return $resourceMetadataCollection;
32✔
83
    }
84

85
    private function addDefaults(Operation $operation): Operation
86
    {
UNCOV
87
        if (null === $operation->getProvider()) {
28✔
UNCOV
88
            $operation = $operation->withProvider($this->getProvider($operation));
28✔
89
        }
90

UNCOV
91
        $options = $operation->getStateOptions() ?: new Options();
28✔
UNCOV
92
        if ($options instanceof Options && null === $options->getHandleLinks()) {
28✔
UNCOV
93
            $options = $options->withHandleLinks('api_platform.doctrine.orm.links_handler');
27✔
UNCOV
94
            $operation = $operation->withStateOptions($options);
27✔
95
        }
96

UNCOV
97
        if (null === $operation->getProcessor()) {
28✔
UNCOV
98
            $operation = $operation->withProcessor($this->getProcessor($operation));
28✔
99
        }
100

UNCOV
101
        return $operation;
28✔
102
    }
103

104
    private function getProvider(Operation $operation): string
105
    {
UNCOV
106
        if ($operation instanceof CollectionOperationInterface) {
28✔
UNCOV
107
            return CollectionProvider::class;
27✔
108
        }
109

UNCOV
110
        return ItemProvider::class;
27✔
111
    }
112

113
    private function getProcessor(Operation $operation): string
114
    {
UNCOV
115
        if ($operation instanceof DeleteOperationInterface) {
28✔
UNCOV
116
            return 'api_platform.doctrine.orm.state.remove_processor';
24✔
117
        }
118

UNCOV
119
        return 'api_platform.doctrine.orm.state.persist_processor';
28✔
120
    }
121
}
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

© 2026 Coveralls, Inc