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

api-platform / core / 20894952430

11 Jan 2026 12:14PM UTC coverage: 20.145% (-8.7%) from 28.875%
20894952430

Pull #7667

github

VincentLanglet
Add failing test
Pull Request #7667: POC NameConverterAwareInterface

11577 of 57467 relevant lines covered (20.15%)

27.48 hits per line

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

18.52
/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\Metadata\Operation;
17
use ApiPlatform\Metadata\Util\CloneTrait;
18
use ApiPlatform\State\Pagination\MappedObjectPaginator;
19
use ApiPlatform\State\Pagination\PaginatorInterface;
20
use ApiPlatform\State\ProviderInterface;
21
use Symfony\Component\ObjectMapper\ObjectMapperInterface;
22

23
/**
24
 * @implements ProviderInterface<object>
25
 */
26
final class ObjectMapperProvider implements ProviderInterface
27
{
28
    use CloneTrait;
29

30
    /**
31
     * @param ProviderInterface<object> $decorated
32
     */
33
    public function __construct(
34
        private readonly ?ObjectMapperInterface $objectMapper,
35
        private readonly ProviderInterface $decorated,
36
    ) {
37
    }
824✔
38

39
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
40
    {
41
        $data = $this->decorated->provide($operation, $uriVariables, $context);
675✔
42
        $class = $operation->getOutput()['class'] ?? $operation->getClass();
674✔
43

44
        if (!$this->objectMapper || !$operation->canMap()) {
674✔
45
            return $data;
674✔
46
        }
47

48
        if (!\is_object($data) && !\is_array($data)) {
×
49
            return $data;
×
50
        }
51

52
        $request = $context['request'] ?? null;
×
53
        $request?->attributes->set('mapped_data', $data);
×
54

55
        if ($data instanceof PaginatorInterface) {
×
56
            $data = new MappedObjectPaginator(
×
57
                iterator_to_array($data),
×
58
                $this->objectMapper,
×
59
                $class,
×
60
                $data->getTotalItems(),
×
61
                $data->getCurrentPage(),
×
62
                $data->getLastPage(),
×
63
                $data->getItemsPerPage(),
×
64
            );
×
65
        } elseif (\is_array($data)) {
×
66
            foreach ($data as &$v) {
×
67
                if (\is_object($v)) {
×
68
                    $v = $this->objectMapper->map($v, $class);
×
69
                }
70
            }
71
        } else {
72
            $data = $this->objectMapper->map($data, $class);
×
73
        }
74

75
        $request?->attributes->set('data', $data);
×
76
        $request?->attributes->set('previous_data', $this->clone($data));
×
77

78
        return $data;
×
79
    }
80
}
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