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

api-platform / core / 20847864477

09 Jan 2026 09:47AM UTC coverage: 29.1% (+0.005%) from 29.095%
20847864477

Pull #7649

github

web-flow
Merge b342dd5db into d640d106b
Pull Request #7649: feat(validator): uuid/ulid parameter validation

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

15050 existing lines in 491 files now uncovered.

16996 of 58406 relevant lines covered (29.1%)

81.8 hits per line

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

88.24
/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
    }
2,474✔
29

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

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

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

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

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

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

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

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

UNCOV
70
                    if (!$found) {
5✔
UNCOV
71
                        continue;
4✔
72
                    }
73

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

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

UNCOV
81
        return $resourceMetadataCollection;
211✔
82
    }
83

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

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