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

api-platform / core / 13814824526

12 Mar 2025 03:11PM UTC coverage: 7.289%. Remained the same
13814824526

push

github

web-flow
doc: comment typo in ApiResource.php

12437 of 170624 relevant lines covered (7.29%)

11.99 hits per line

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

100.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
    }
709✔
33

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

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

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

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

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

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

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

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

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

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

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

80
        return $resourceMetadataCollection;
29✔
81
    }
82

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

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

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

99
        return $operation;
21✔
100
    }
101

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

108
        return ItemProvider::class;
21✔
109
    }
110

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

117
        return 'api_platform.doctrine_mongodb.odm.state.persist_processor';
21✔
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

© 2026 Coveralls, Inc