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

api-platform / core / 19435070704

17 Nov 2025 03:32PM UTC coverage: 0.0%. First build
19435070704

Pull #7541

github

web-flow
Merge 4a77fb186 into c28c624a8
Pull Request #7541: fix(state): object mapper flag

0 of 85 new or added lines in 26 files covered. (0.0%)

0 of 56904 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/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\ObjectMapperMetadataFactoryInterface;
20

21
class ObjectMapperMetadataCollectionFactory implements ResourceMetadataCollectionFactoryInterface
22
{
23
    public function __construct(
24
        private readonly ResourceMetadataCollectionFactoryInterface $decorated,
25
        private readonly ObjectMapperMetadataFactoryInterface $objectMapperMetadata,
26
    ) {
NEW
27
    }
×
28

29
    public function create(string $resourceClass): ResourceMetadataCollection
30
    {
NEW
31
        $resourceMetadataCollection = $this->decorated->create($resourceClass);
×
32

NEW
33
        foreach ($resourceMetadataCollection as $key => $resourceMetadata) {
×
NEW
34
            $operations = $resourceMetadata->getOperations();
×
35

NEW
36
            if (!$operations) {
×
NEW
37
                continue;
×
38
            }
39

NEW
40
            foreach ($operations as $operationKey => $operation) {
×
NEW
41
                if (null !== $operation->canMap()) {
×
NEW
42
                    continue;
×
43
                }
44

NEW
45
                $entityClass = null;
×
NEW
46
                if (($options = $operation->getStateOptions()) && $options instanceof Options && $options->getEntityClass()) {
×
NEW
47
                    $entityClass = $options->getEntityClass();
×
48
                }
49

NEW
50
                if (($options = $operation->getStateOptions()) && $options instanceof OdmOptions && $options->getDocumentClass()) {
×
NEW
51
                    $entityClass = $options->getDocumentClass();
×
52
                }
53

NEW
54
                $class = $operation->getInput()['class'] ?? $operation->getClass();
×
55

56
                // Look for Mapping metadata
NEW
57
                if ($this->canBeMapped($class) || ($entityClass && $this->canBeMapped($entityClass))) {
×
NEW
58
                    $operations->add($operationKey, $operation->withMap(true));
×
59
                }
60
            }
61

NEW
62
            $resourceMetadataCollection[$key] = $resourceMetadata->withOperations($operations);
×
63
        }
64

NEW
65
        return $resourceMetadataCollection;
×
66
    }
67

68
    private function canBeMapped(string $class): bool
69
    {
70
        try {
NEW
71
            $r = new \ReflectionClass($class);
×
NEW
72
            if (!$r->isInstantiable() || !$this->objectMapperMetadata->create($r->newInstanceWithoutConstructor(), null, ['_api_check_can_be_mapped' => true])) {
×
NEW
73
                return false;
×
74
            }
NEW
75
        } catch (\ReflectionException $e) {
×
NEW
76
            return false;
×
77
        }
78

NEW
79
        return true;
×
80
    }
81
}
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