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

api-platform / core / 10903050455

17 Sep 2024 12:29PM UTC coverage: 7.684% (+0.7%) from 6.96%
10903050455

push

github

web-flow
fix: swagger ui with route identifier (#6616)

2 of 6 new or added lines in 6 files covered. (33.33%)

9000 existing lines in 286 files now uncovered.

12668 of 164863 relevant lines covered (7.68%)

22.93 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
    {
UNCOV
32
    }
1,414✔
33

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

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

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

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

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

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

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

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

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

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

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

UNCOV
80
        return $resourceMetadataCollection;
10✔
81
    }
82

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

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

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

UNCOV
99
        return $operation;
2✔
100
    }
101

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

UNCOV
108
        return ItemProvider::class;
2✔
109
    }
110

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

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