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

api-platform / core / 20306196173

17 Dec 2025 02:27PM UTC coverage: 25.294% (-0.002%) from 25.296%
20306196173

push

github

web-flow
feat: enable to skip autoconfiguration with new `SkipAutoconfigure` attribute (#7467)

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

7803 existing lines in 234 files now uncovered.

14672 of 58006 relevant lines covered (25.29%)

29.35 hits per line

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

87.88
/src/Metadata/Resource/Factory/ObjectMapperMetadataCollectionFactory.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\Metadata\Resource\Factory;
15

16
use ApiPlatform\Doctrine\Odm\State\Options as OdmOptions;
17
use ApiPlatform\Doctrine\Orm\State\Options;
18
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
19
use Symfony\Component\ObjectMapper\Metadata\Mapping;
20
use Symfony\Component\ObjectMapper\Metadata\ObjectMapperMetadataFactoryInterface;
21

22
class ObjectMapperMetadataCollectionFactory implements ResourceMetadataCollectionFactoryInterface
23
{
24
    public function __construct(
25
        private readonly ResourceMetadataCollectionFactoryInterface $decorated,
26
        private readonly ObjectMapperMetadataFactoryInterface $objectMapperMetadata,
27
    ) {
UNCOV
28
    }
848✔
29

30
    public function create(string $resourceClass): ResourceMetadataCollection
31
    {
UNCOV
32
        $resourceMetadataCollection = $this->decorated->create($resourceClass);
132✔
33

UNCOV
34
        foreach ($resourceMetadataCollection as $key => $resourceMetadata) {
132✔
UNCOV
35
            $operations = $resourceMetadata->getOperations();
130✔
36

UNCOV
37
            if (!$operations) {
130✔
38
                continue;
×
39
            }
40

UNCOV
41
            foreach ($operations as $operationKey => $operation) {
130✔
UNCOV
42
                if (null !== $operation->canMap()) {
130✔
UNCOV
43
                    continue;
2✔
44
                }
45

UNCOV
46
                $entityClass = null;
130✔
UNCOV
47
                if (($options = $operation->getStateOptions()) && $options instanceof Options && $options->getEntityClass()) {
130✔
UNCOV
48
                    $entityClass = $options->getEntityClass();
10✔
49
                }
50

UNCOV
51
                if (($options = $operation->getStateOptions()) && $options instanceof OdmOptions && $options->getDocumentClass()) {
130✔
UNCOV
52
                    $entityClass = $options->getDocumentClass();
4✔
53
                }
54

UNCOV
55
                $class = $operation->getInput()['class'] ?? $operation->getClass();
130✔
UNCOV
56
                $entityMap = null;
130✔
57

58
                // Look for Mapping metadata
UNCOV
59
                if ($this->canBeMapped($class) || ($entityClass && ($entityMap = $this->canBeMapped($entityClass)))) {
130✔
UNCOV
60
                    $found = true;
2✔
UNCOV
61
                    if ($entityMap) {
2✔
UNCOV
62
                        foreach ($entityMap as $mapping) {
2✔
UNCOV
63
                            if ($found = ($mapping->source === $operation->getClass() || $mapping->target === $operation->getClass())) {
2✔
64
                                break;
×
65
                            }
66
                        }
67
                    }
68

UNCOV
69
                    if (!$found) {
2✔
UNCOV
70
                        continue;
2✔
71
                    }
72

UNCOV
73
                    $operations->add($operationKey, $operation->withMap(true));
2✔
74
                }
75
            }
76

UNCOV
77
            $resourceMetadataCollection[$key] = $resourceMetadata->withOperations($operations);
130✔
78
        }
79

UNCOV
80
        return $resourceMetadataCollection;
132✔
81
    }
82

83
    /**
84
     * @return bool|list<Mapping>
85
     */
86
    private function canBeMapped(string $class): bool|array
87
    {
88
        try {
UNCOV
89
            $r = new \ReflectionClass($class);
130✔
UNCOV
90
            if (!$r->isInstantiable() || !($mapping = $this->objectMapperMetadata->create($r->newInstanceWithoutConstructor(), null, ['_api_check_can_be_mapped' => true]))) {
130✔
UNCOV
91
                return false;
130✔
92
            }
93
        } catch (\ReflectionException $e) {
×
94
            return false;
×
95
        }
96

UNCOV
97
        return $mapping;
2✔
98
    }
99
}
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