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

api-platform / core / 13814792797

12 Mar 2025 03:09PM UTC coverage: 5.889% (-1.4%) from 7.289%
13814792797

Pull #7012

github

web-flow
Merge 199d44919 into 284937039
Pull Request #7012: doc: comment typo in ApiResource.php

10048 of 170615 relevant lines covered (5.89%)

5.17 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\Doctrine\Odm\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\ODM\MongoDB\DocumentManager;
26
use Doctrine\Persistence\ManagerRegistry;
27

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

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

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

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

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

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

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

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

65
            if ($graphQlOperations) {
×
66
                foreach ($graphQlOperations as $operationName => $graphQlOperation) {
×
67
                    if (!$this->managerRegistry->getManagerForClass($graphQlOperation->getClass()) instanceof DocumentManager) {
×
68
                        continue;
×
69
                    }
70

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

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

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

80
        return $resourceMetadataCollection;
×
81
    }
82

83
    private function addDefaults(Operation $operation): Operation
84
    {
85
        $options = $operation->getStateOptions() ?: new Options();
×
86
        if ($options instanceof Options && null === $options->getHandleLinks()) {
×
87
            $options = $options->withHandleLinks('api_platform.doctrine.odm.links_handler');
×
88
            $operation = $operation->withStateOptions($options);
×
89
        }
90

91
        if (null === $operation->getProvider()) {
×
92
            $operation = $operation->withProvider($this->getProvider($operation));
×
93
        }
94

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

99
        return $operation;
×
100
    }
101

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

108
        return ItemProvider::class;
×
109
    }
110

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

117
        return 'api_platform.doctrine_mongodb.odm.state.persist_processor';
×
118
    }
119
}
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