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

api-platform / core / 21006071786

14 Jan 2026 06:53PM UTC coverage: 21.366% (-7.7%) from 29.097%
21006071786

Pull #7675

github

web-flow
Merge 5c98a7330 into 73402fc61
Pull Request #7675: feat(doctrine): Add caseInsensitive option to PartialSearchFilter

0 of 11 new or added lines in 2 files covered. (0.0%)

15054 existing lines in 491 files now uncovered.

12306 of 57596 relevant lines covered (21.37%)

49.15 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\CollectionOperationInterface;
20
use ApiPlatform\Metadata\DeleteOperationInterface;
21
use ApiPlatform\Metadata\Operation;
22
use ApiPlatform\Metadata\Patch;
23
use ApiPlatform\Metadata\Put;
24
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
25
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
26
use ApiPlatform\State\Util\StateOptionsTrait;
27
use Doctrine\ORM\EntityManagerInterface;
28
use Doctrine\Persistence\ManagerRegistry;
29

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

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

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

UNCOV
45
        foreach ($resourceMetadataCollection as $i => $resourceMetadata) {
33✔
UNCOV
46
            $operations = $resourceMetadata->getOperations();
30✔
47

UNCOV
48
            if ($operations) {
30✔
UNCOV
49
                foreach ($operations as $operationName => $operation) {
30✔
UNCOV
50
                    $entityClass = $this->getStateOptionsClass($operation, $operation->getClass(), Options::class);
30✔
51

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

UNCOV
57
                    $classMetadata = $manager->getClassMetadata($entityClass);
27✔
58
                    // @see https://www.doctrine-project.org/projects/doctrine-orm/en/3.5/reference/improving-performance.html#read-only-entities
59
                    // Read-Only allows to persist new entities of a kind and remove existing ones, they are just not considered for updates.
UNCOV
60
                    if ($classMetadata->isReadOnly && ($operation instanceof Put || $operation instanceof Patch)) {
27✔
UNCOV
61
                        $operations->remove($operationName);
1✔
UNCOV
62
                        continue;
1✔
63
                    }
64

UNCOV
65
                    $operations->add($operationName, $this->addDefaults($operation));
27✔
66
                }
67

UNCOV
68
                $resourceMetadata = $resourceMetadata->withOperations($operations);
30✔
69
            }
70

UNCOV
71
            $graphQlOperations = $resourceMetadata->getGraphQlOperations();
30✔
72

UNCOV
73
            if ($graphQlOperations) {
30✔
UNCOV
74
                foreach ($graphQlOperations as $operationName => $graphQlOperation) {
28✔
UNCOV
75
                    $entityClass = $this->getStateOptionsClass($graphQlOperation, $graphQlOperation->getClass(), Options::class);
28✔
76

UNCOV
77
                    if (!$this->managerRegistry->getManagerForClass($entityClass) instanceof EntityManagerInterface) {
28✔
UNCOV
78
                        continue;
4✔
79
                    }
80

UNCOV
81
                    $graphQlOperations[$operationName] = $this->addDefaults($graphQlOperation);
26✔
82
                }
83

UNCOV
84
                $resourceMetadata = $resourceMetadata->withGraphQlOperations($graphQlOperations);
28✔
85
            }
86

UNCOV
87
            $resourceMetadataCollection[$i] = $resourceMetadata;
30✔
88
        }
89

UNCOV
90
        return $resourceMetadataCollection;
33✔
91
    }
92

93
    private function addDefaults(Operation $operation): Operation
94
    {
UNCOV
95
        if (null === $operation->getProvider()) {
27✔
UNCOV
96
            $operation = $operation->withProvider($this->getProvider($operation));
27✔
97
        }
98

UNCOV
99
        $options = $operation->getStateOptions() ?: new Options();
27✔
UNCOV
100
        if ($options instanceof Options && null === $options->getHandleLinks()) {
27✔
UNCOV
101
            $options = $options->withHandleLinks('api_platform.doctrine.orm.links_handler');
26✔
UNCOV
102
            $operation = $operation->withStateOptions($options);
26✔
103
        }
104

UNCOV
105
        if (null === $operation->getProcessor()) {
27✔
UNCOV
106
            $operation = $operation->withProcessor($this->getProcessor($operation));
27✔
107
        }
108

UNCOV
109
        return $operation;
27✔
110
    }
111

112
    private function getProvider(Operation $operation): string
113
    {
UNCOV
114
        if ($operation instanceof CollectionOperationInterface) {
27✔
UNCOV
115
            return CollectionProvider::class;
26✔
116
        }
117

UNCOV
118
        return ItemProvider::class;
27✔
119
    }
120

121
    private function getProcessor(Operation $operation): string
122
    {
UNCOV
123
        if ($operation instanceof DeleteOperationInterface) {
27✔
UNCOV
124
            return 'api_platform.doctrine.orm.state.remove_processor';
24✔
125
        }
126

UNCOV
127
        return 'api_platform.doctrine.orm.state.persist_processor';
27✔
128
    }
129
}
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