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

api-platform / core / 16705318661

03 Aug 2025 01:05PM UTC coverage: 0.0% (-21.9%) from 21.944%
16705318661

Pull #7317

github

web-flow
Merge 1ca8642ff into d06b1a0a0
Pull Request #7317: Fix/4372 skip null values in hal

0 of 14 new or added lines in 3 files covered. (0.0%)

11680 existing lines in 376 files now uncovered.

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

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

32
    public function __construct(private readonly ManagerRegistry $managerRegistry, private readonly ResourceMetadataCollectionFactoryInterface $decorated)
33
    {
UNCOV
34
    }
×
35

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

UNCOV
43
        foreach ($resourceMetadataCollection as $i => $resourceMetadata) {
×
UNCOV
44
            $operations = $resourceMetadata->getOperations();
×
45

UNCOV
46
            if ($operations) {
×
UNCOV
47
                foreach ($resourceMetadata->getOperations() as $operationName => $operation) {
×
UNCOV
48
                    $entityClass = $this->getStateOptionsClass($operation, $operation->getClass(), Options::class);
×
49

UNCOV
50
                    if (!$this->managerRegistry->getManagerForClass($entityClass) instanceof EntityManagerInterface) {
×
UNCOV
51
                        continue;
×
52
                    }
53

UNCOV
54
                    $operations->add($operationName, $this->addDefaults($operation));
×
55
                }
56

UNCOV
57
                $resourceMetadata = $resourceMetadata->withOperations($operations);
×
58
            }
59

UNCOV
60
            $graphQlOperations = $resourceMetadata->getGraphQlOperations();
×
61

UNCOV
62
            if ($graphQlOperations) {
×
UNCOV
63
                foreach ($graphQlOperations as $operationName => $graphQlOperation) {
×
UNCOV
64
                    $entityClass = $this->getStateOptionsClass($graphQlOperation, $graphQlOperation->getClass(), Options::class);
×
65

UNCOV
66
                    if (!$this->managerRegistry->getManagerForClass($entityClass) instanceof EntityManagerInterface) {
×
UNCOV
67
                        continue;
×
68
                    }
69

UNCOV
70
                    $graphQlOperations[$operationName] = $this->addDefaults($graphQlOperation);
×
71
                }
72

UNCOV
73
                $resourceMetadata = $resourceMetadata->withGraphQlOperations($graphQlOperations);
×
74
            }
75

UNCOV
76
            $resourceMetadataCollection[$i] = $resourceMetadata;
×
77
        }
78

UNCOV
79
        return $resourceMetadataCollection;
×
80
    }
81

82
    private function addDefaults(Operation $operation): Operation
83
    {
UNCOV
84
        if (null === $operation->getProvider()) {
×
UNCOV
85
            $operation = $operation->withProvider($this->getProvider($operation));
×
86
        }
87

UNCOV
88
        $options = $operation->getStateOptions() ?: new Options();
×
UNCOV
89
        if ($options instanceof Options && null === $options->getHandleLinks()) {
×
UNCOV
90
            $options = $options->withHandleLinks('api_platform.doctrine.orm.links_handler');
×
UNCOV
91
            $operation = $operation->withStateOptions($options);
×
92
        }
93

UNCOV
94
        if (null === $operation->getProcessor()) {
×
UNCOV
95
            $operation = $operation->withProcessor($this->getProcessor($operation));
×
96
        }
97

UNCOV
98
        return $operation;
×
99
    }
100

101
    private function getProvider(Operation $operation): string
102
    {
UNCOV
103
        if ($operation instanceof CollectionOperationInterface) {
×
UNCOV
104
            return CollectionProvider::class;
×
105
        }
106

UNCOV
107
        return ItemProvider::class;
×
108
    }
109

110
    private function getProcessor(Operation $operation): string
111
    {
UNCOV
112
        if ($operation instanceof DeleteOperationInterface) {
×
UNCOV
113
            return 'api_platform.doctrine.orm.state.remove_processor';
×
114
        }
115

UNCOV
116
        return 'api_platform.doctrine.orm.state.persist_processor';
×
117
    }
118
}
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