• 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/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\ArrayPaginator;
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
    ) {
UNCOV
37
    }
×
38

39
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
40
    {
41
        $data = $this->decorated->provide($operation, $uriVariables, $context);
×
42

NEW
43
        if (!$this->objectMapper || !\is_object($data) || !$operation->canMap()) {
×
44
            return $data;
×
45
        }
46

47
        $request = $context['request'] ?? null;
×
NEW
48
        $request?->attributes->set('mapped_data', $data);
×
49

50
        if ($data instanceof PaginatorInterface) {
×
51
            $data = new ArrayPaginator(array_map(fn ($v) => $this->objectMapper->map($v, $operation->getClass()), iterator_to_array($data)), 0, \count($data));
×
52
        } else {
53
            $data = $this->objectMapper->map($data, $operation->getClass());
×
54
        }
55

56
        $request?->attributes->set('data', $data);
×
57
        $request?->attributes->set('previous_data', $this->clone($data));
×
58

59
        return $data;
×
60
    }
61
}
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