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

api-platform / core / 19799301771

30 Nov 2025 01:04PM UTC coverage: 25.229% (-0.03%) from 25.257%
19799301771

push

github

web-flow
fix(metadata): repeatable attribute mutators (#7542)

14557 of 57700 relevant lines covered (25.23%)

28.11 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\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
    {
34
    }
814✔
35

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

43
        foreach ($resourceMetadataCollection as $i => $resourceMetadata) {
124✔
44
            $operations = $resourceMetadata->getOperations();
122✔
45

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

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

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

57
                $resourceMetadata = $resourceMetadata->withOperations($operations);
122✔
58
            }
59

60
            $graphQlOperations = $resourceMetadata->getGraphQlOperations();
122✔
61

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

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

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

73
                $resourceMetadata = $resourceMetadata->withGraphQlOperations($graphQlOperations);
88✔
74
            }
75

76
            $resourceMetadataCollection[$i] = $resourceMetadata;
122✔
77
        }
78

79
        return $resourceMetadataCollection;
124✔
80
    }
81

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

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

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

98
        return $operation;
60✔
99
    }
100

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

107
        return ItemProvider::class;
58✔
108
    }
109

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

116
        return 'api_platform.doctrine.orm.state.persist_processor';
60✔
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

© 2026 Coveralls, Inc