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

api-platform / core / 17545966872

08 Sep 2025 09:18AM UTC coverage: 22.312% (-0.3%) from 22.604%
17545966872

push

github

web-flow
fix(metadata): wrong method name in resource mutator

0 of 1 new or added line in 1 file covered. (0.0%)

12092 existing lines in 401 files now uncovered.

11916 of 53406 relevant lines covered (22.31%)

13.09 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
    ) {
UNCOV
40
    }
330✔
41

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

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

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

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

UNCOV
60
        $entityClass ??= $data::class;
288✔
61

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

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

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

UNCOV
75
        return $data;
3✔
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