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

api-platform / core / 13200284839

07 Feb 2025 12:56PM UTC coverage: 0.0% (-8.2%) from 8.164%
13200284839

Pull #6952

github

web-flow
Merge 519fbf8cc into 62377f880
Pull Request #6952: fix: errors retrieval and documentation

0 of 206 new or added lines in 17 files covered. (0.0%)

10757 existing lines in 366 files now uncovered.

0 of 47781 relevant lines covered (0.0%)

0.0 hits per line

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

0.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 Doctrine\ORM\EntityManagerInterface;
26
use Doctrine\Persistence\ManagerRegistry;
27

28
final class DoctrineOrmResourceCollectionMetadataFactory implements ResourceMetadataCollectionFactoryInterface
29
{
30
    public function __construct(private readonly ManagerRegistry $managerRegistry, private readonly ResourceMetadataCollectionFactoryInterface $decorated)
31
    {
UNCOV
32
    }
×
33

34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function create(string $resourceClass): ResourceMetadataCollection
38
    {
UNCOV
39
        $resourceMetadataCollection = $this->decorated->create($resourceClass);
×
40

41
        /** @var ApiResource $resourceMetadata */
UNCOV
42
        foreach ($resourceMetadataCollection as $i => $resourceMetadata) {
×
UNCOV
43
            $operations = $resourceMetadata->getOperations();
×
44

UNCOV
45
            if ($operations) {
×
46
                /** @var Operation $operation */
UNCOV
47
                foreach ($resourceMetadata->getOperations() as $operationName => $operation) {
×
UNCOV
48
                    $entityClass = $operation->getClass();
×
UNCOV
49
                    if (($options = $operation->getStateOptions()) && $options instanceof Options && $options->getEntityClass()) {
×
UNCOV
50
                        $entityClass = $options->getEntityClass();
×
51
                    }
52

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

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

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

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

UNCOV
65
            if ($graphQlOperations) {
×
UNCOV
66
                foreach ($graphQlOperations as $operationName => $graphQlOperation) {
×
UNCOV
67
                    $entityClass = $graphQlOperation->getClass();
×
UNCOV
68
                    if (($options = $graphQlOperation->getStateOptions()) && $options instanceof Options && $options->getEntityClass()) {
×
UNCOV
69
                        $entityClass = $options->getEntityClass();
×
70
                    }
71

UNCOV
72
                    if (!$this->managerRegistry->getManagerForClass($entityClass) instanceof EntityManagerInterface) {
×
UNCOV
73
                        continue;
×
74
                    }
75

UNCOV
76
                    $graphQlOperations[$operationName] = $this->addDefaults($graphQlOperation);
×
77
                }
78

UNCOV
79
                $resourceMetadata = $resourceMetadata->withGraphQlOperations($graphQlOperations);
×
80
            }
81

UNCOV
82
            $resourceMetadataCollection[$i] = $resourceMetadata;
×
83
        }
84

UNCOV
85
        return $resourceMetadataCollection;
×
86
    }
87

88
    private function addDefaults(Operation $operation): Operation
89
    {
UNCOV
90
        if (null === $operation->getProvider()) {
×
UNCOV
91
            $operation = $operation->withProvider($this->getProvider($operation));
×
92
        }
93

UNCOV
94
        $options = $operation->getStateOptions() ?: new Options();
×
UNCOV
95
        if ($options instanceof Options && null === $options->getHandleLinks()) {
×
UNCOV
96
            $options = $options->withHandleLinks('api_platform.doctrine.orm.links_handler');
×
UNCOV
97
            $operation = $operation->withStateOptions($options);
×
98
        }
99

UNCOV
100
        if (null === $operation->getProcessor()) {
×
UNCOV
101
            $operation = $operation->withProcessor($this->getProcessor($operation));
×
102
        }
103

UNCOV
104
        return $operation;
×
105
    }
106

107
    private function getProvider(Operation $operation): string
108
    {
UNCOV
109
        if ($operation instanceof CollectionOperationInterface) {
×
UNCOV
110
            return CollectionProvider::class;
×
111
        }
112

UNCOV
113
        return ItemProvider::class;
×
114
    }
115

116
    private function getProcessor(Operation $operation): string
117
    {
UNCOV
118
        if ($operation instanceof DeleteOperationInterface) {
×
UNCOV
119
            return 'api_platform.doctrine.orm.state.remove_processor';
×
120
        }
121

UNCOV
122
        return 'api_platform.doctrine.orm.state.persist_processor';
×
123
    }
124
}
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