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

api-platform / core / 17327553156

29 Aug 2025 03:13PM UTC coverage: 22.588% (-0.03%) from 22.622%
17327553156

push

github

web-flow
fix(laravel): serialization issue with camelCase relation (#7356)

fixes #7344

0 of 76 new or added lines in 9 files covered. (0.0%)

11415 existing lines in 372 files now uncovered.

11181 of 49499 relevant lines covered (22.59%)

23.68 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
    }
646✔
36

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

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

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

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

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

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

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

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

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

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

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

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

UNCOV
82
        return $resourceMetadataCollection;
90✔
83
    }
84

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

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

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

UNCOV
101
        return $operation;
46✔
102
    }
103

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

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

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

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