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

api-platform / core / 17487610263

05 Sep 2025 08:12AM UTC coverage: 22.608% (+0.3%) from 22.319%
17487610263

push

github

web-flow
chore: remove @experimental flag from parameters (#7357)

12049 of 53296 relevant lines covered (22.61%)

26.21 hits per line

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

94.74
/src/State/Provider/ObjectMapperProvider.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\State\Provider;
15

16
use ApiPlatform\Doctrine\Odm\State\Options as OdmOptions;
17
use ApiPlatform\Doctrine\Orm\State\Options;
18
use ApiPlatform\Metadata\Operation;
19
use ApiPlatform\Metadata\Util\CloneTrait;
20
use ApiPlatform\State\Pagination\ArrayPaginator;
21
use ApiPlatform\State\Pagination\PaginatorInterface;
22
use ApiPlatform\State\ProviderInterface;
23
use Symfony\Component\ObjectMapper\Attribute\Map;
24
use Symfony\Component\ObjectMapper\ObjectMapperInterface;
25

26
/**
27
 * @implements ProviderInterface<object>
28
 */
29
final class ObjectMapperProvider implements ProviderInterface
30
{
31
    use CloneTrait;
32

33
    /**
34
     * @param ProviderInterface<object> $decorated
35
     */
36
    public function __construct(
37
        private readonly ?ObjectMapperInterface $objectMapper,
38
        private readonly ProviderInterface $decorated,
39
    ) {
40
    }
654✔
41

42
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
43
    {
44
        $data = $this->decorated->provide($operation, $uriVariables, $context);
626✔
45

46
        if (!$this->objectMapper || !\is_object($data)) {
624✔
47
            return $data;
74✔
48
        }
49

50
        $request = $context['request'] ?? null;
570✔
51
        $entityClass = null;
570✔
52
        if (($options = $operation->getStateOptions()) && $options instanceof Options && $options->getEntityClass()) {
570✔
53
            $entityClass = $options->getEntityClass();
12✔
54
        }
55

56
        if (($options = $operation->getStateOptions()) && $options instanceof OdmOptions && $options->getDocumentClass()) {
570✔
57
            $entityClass = $options->getDocumentClass();
×
58
        }
59

60
        $entityClass ??= $data::class;
570✔
61

62
        if (!(new \ReflectionClass($entityClass))->getAttributes(Map::class)) {
570✔
63
            return $data;
564✔
64
        }
65

66
        if ($data instanceof PaginatorInterface) {
6✔
67
            $data = new ArrayPaginator(array_map(fn ($v) => $this->objectMapper->map($v, $operation->getClass()), iterator_to_array($data)), 0, \count($data));
4✔
68
        } else {
69
            $data = $this->objectMapper->map($data, $operation->getClass());
4✔
70
        }
71

72
        $request?->attributes->set('data', $data);
6✔
73
        $request?->attributes->set('previous_data', $this->clone($data));
6✔
74

75
        return $data;
6✔
76
    }
77
}
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