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

api-platform / core / 14992745685

13 May 2025 09:09AM UTC coverage: 27.459% (+3.8%) from 23.685%
14992745685

push

github

web-flow
fix(metadata): xml PHPize HTTP cache headers (#7140)

0 of 1 new or added line in 1 file covered. (0.0%)

2013 existing lines in 145 files now uncovered.

13449 of 48979 relevant lines covered (27.46%)

74.47 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 ApiPlatform\State\Util\StateOptionsTrait;
26
use Doctrine\ODM\MongoDB\DocumentManager;
27
use Doctrine\Persistence\ManagerRegistry;
28

29
final class DoctrineMongoDbOdmResourceCollectionMetadataFactory implements ResourceMetadataCollectionFactoryInterface
30
{
31
    use StateOptionsTrait;
32

33
    public function __construct(private readonly ManagerRegistry $managerRegistry, private readonly ResourceMetadataCollectionFactoryInterface $decorated)
34
    {
UNCOV
35
    }
708✔
36

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

44
        /** @var ApiResource $resourceMetadata */
UNCOV
45
        foreach ($resourceMetadataCollection as $i => $resourceMetadata) {
29✔
UNCOV
46
            $operations = $resourceMetadata->getOperations();
26✔
47

UNCOV
48
            if ($operations) {
26✔
49
                /** @var Operation $operation */
UNCOV
50
                foreach ($resourceMetadata->getOperations() as $operationName => $operation) {
26✔
UNCOV
51
                    $documentClass = $this->getStateOptionsClass($operation, $operation->getClass(), Options::class);
26✔
UNCOV
52
                    if (!$this->managerRegistry->getManagerForClass($documentClass) instanceof DocumentManager) {
26✔
UNCOV
53
                        continue;
6✔
54
                    }
55

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

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

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

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

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

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

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

UNCOV
79
        return $resourceMetadataCollection;
29✔
80
    }
81

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

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

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

UNCOV
98
        return $operation;
21✔
99
    }
100

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

UNCOV
107
        return ItemProvider::class;
21✔
108
    }
109

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

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

© 2025 Coveralls, Inc