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

api-platform / core / 20969151198

13 Jan 2026 07:07PM UTC coverage: 0.0% (-29.1%) from 29.095%
20969151198

Pull #7669

github

web-flow
Merge 872bbc755 into c8493bbe7
Pull Request #7669: ci - fix testMapPutAllowCreate

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

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

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

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

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

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

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

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

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

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

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

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

81
        return $resourceMetadataCollection;
×
82
    }
83

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

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