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

api-platform / core / 3904303394

pending completion
3904303394

Pull #5332

github

GitHub
Merge 2e0a3ceae into 965332bc8
Pull Request #5332: Revert "chore(deprecation): Only use ValueResolverInterface if it exists"

2 of 2 new or added lines in 1 file covered. (100.0%)

7939 of 12085 relevant lines covered (65.69%)

81.77 hits per line

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

0.0
/src/Doctrine/Odm/Metadata/Resource/DoctrineMongoDbOdmResourceCollectionMetadataFactory.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\Odm\Metadata\Resource;
15

16
use ApiPlatform\Doctrine\Odm\State\CollectionProvider;
17
use ApiPlatform\Doctrine\Odm\State\ItemProvider;
18
use ApiPlatform\Metadata\ApiResource;
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 Doctrine\ODM\MongoDB\DocumentManager;
25
use Doctrine\Persistence\ManagerRegistry;
26

27
final class DoctrineMongoDbOdmResourceCollectionMetadataFactory implements ResourceMetadataCollectionFactoryInterface
28
{
29
    public function __construct(private readonly ManagerRegistry $managerRegistry, private readonly ResourceMetadataCollectionFactoryInterface $decorated)
30
    {
31
    }
32

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

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

44
            if ($operations) {
×
45
                /** @var Operation $operation */
46
                foreach ($resourceMetadata->getOperations() as $operationName => $operation) {
×
47
                    if (!$this->managerRegistry->getManagerForClass($operation->getClass()) instanceof DocumentManager) {
×
48
                        continue;
×
49
                    }
50

51
                    $operations->add($operationName, $this->addDefaults($operation));
×
52
                }
53

54
                $resourceMetadata = $resourceMetadata->withOperations($operations);
×
55
            }
56

57
            $graphQlOperations = $resourceMetadata->getGraphQlOperations();
×
58

59
            if ($graphQlOperations) {
×
60
                foreach ($graphQlOperations as $operationName => $graphQlOperation) {
×
61
                    if (!$this->managerRegistry->getManagerForClass($graphQlOperation->getClass()) instanceof DocumentManager) {
×
62
                        continue;
×
63
                    }
64

65
                    $graphQlOperations[$operationName] = $this->addDefaults($graphQlOperation);
×
66
                }
67

68
                $resourceMetadata = $resourceMetadata->withGraphQlOperations($graphQlOperations);
×
69
            }
70

71
            $resourceMetadataCollection[$i] = $resourceMetadata;
×
72
        }
73

74
        return $resourceMetadataCollection;
×
75
    }
76

77
    private function addDefaults(Operation $operation): Operation
78
    {
79
        if (null === $operation->getProvider()) {
×
80
            $operation = $operation->withProvider($this->getProvider($operation));
×
81
        }
82

83
        if (null === $operation->getProcessor()) {
×
84
            $operation = $operation->withProcessor($this->getProcessor($operation));
×
85
        }
86

87
        return $operation;
×
88
    }
89

90
    private function getProvider(Operation $operation): string
91
    {
92
        if ($operation instanceof CollectionOperationInterface) {
×
93
            return CollectionProvider::class;
×
94
        }
95

96
        return ItemProvider::class;
×
97
    }
98

99
    private function getProcessor(Operation $operation): string
100
    {
101
        if ($operation instanceof DeleteOperationInterface) {
×
102
            return 'api_platform.doctrine_mongodb.odm.state.remove_processor';
×
103
        }
104

105
        return 'api_platform.doctrine_mongodb.odm.state.persist_processor';
×
106
    }
107
}
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