• 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

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
    }
270✔
36

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

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

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

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

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

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

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

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

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

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

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

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

UNCOV
82
        return $resourceMetadataCollection;
40✔
83
    }
84

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

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

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

UNCOV
101
        return $operation;
20✔
102
    }
103

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

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

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

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

© 2025 Coveralls, Inc