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

api-platform / core / 19438754788

17 Nov 2025 05:34PM UTC coverage: 0.0%. Remained the same
19438754788

push

github

soyuka
Merge 4.2

0 of 95 new or added lines in 28 files covered. (0.0%)

19 existing lines in 18 files now uncovered.

0 of 57020 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\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
    ) {
NEW
28
    }
×
29

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

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

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

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

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

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

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

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

NEW
69
                    if (!$found) {
×
NEW
70
                        continue;
×
71
                    }
72

NEW
73
                    $operations->add($operationKey, $operation->withMap(true));
×
74
                }
75
            }
76

NEW
77
            $resourceMetadataCollection[$key] = $resourceMetadata->withOperations($operations);
×
78
        }
79

NEW
80
        return $resourceMetadataCollection;
×
81
    }
82

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

NEW
97
        return $mapping;
×
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

© 2025 Coveralls, Inc