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

api-platform / core / 19250029811

10 Nov 2025 11:56PM UTC coverage: 24.566% (+24.6%) from 0.0%
19250029811

push

github

soyuka
ci: ignore no-unnecessary-combinator

14095 of 57375 relevant lines covered (24.57%)

26.48 hits per line

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

90.48
/src/State/Processor/ObjectMapperProcessor.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\Processor;
15

16
use ApiPlatform\Metadata\Operation;
17
use ApiPlatform\State\ProcessorInterface;
18
use Symfony\Component\ObjectMapper\Attribute\Map;
19
use Symfony\Component\ObjectMapper\Metadata\ObjectMapperMetadataFactoryInterface;
20
use Symfony\Component\ObjectMapper\ObjectMapperInterface;
21

22
/**
23
 * @implements ProcessorInterface<mixed,mixed>
24
 */
25
final class ObjectMapperProcessor implements ProcessorInterface
26
{
27
    /**
28
     * @param ProcessorInterface<mixed,mixed> $decorated
29
     */
30
    public function __construct(
31
        private readonly ?ObjectMapperInterface $objectMapper,
32
        private readonly ProcessorInterface $decorated,
33
        private readonly ?ObjectMapperMetadataFactoryInterface $objectMapperMetadata = null,
34
    ) {
35
        // TODO: 4.3 add this deprecation
36
        // if (!$objectMapperMetadata) {
37
        //     trigger_deprecation('api-platform/state', '4.3', 'Not injecting "%s" in "%s" will not be possible anymore in 5.0.', ObjectMapperMetadataFactoryInterface::class, __CLASS__);
38
        // }
39
    }
665✔
40

41
    public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): object|array|null
42
    {
43
        $class = $operation->getInput()['class'] ?? $operation->getClass();
38✔
44

45
        if (
46
            !$this->objectMapper
38✔
47
            || !$operation->canWrite()
38✔
48
            || null === $data
38✔
49
            || !is_a($data, $class, true)
38✔
50
        ) {
51
            return $this->decorated->process($data, $operation, $uriVariables, $context);
2✔
52
        }
53

54
        if ($this->objectMapperMetadata) {
36✔
55
            if (!$this->objectMapperMetadata->create($data)) {
36✔
56
                return $this->decorated->process($data, $operation, $uriVariables, $context);
30✔
57
            }
58
        } elseif (!(new \ReflectionClass($operation->getClass()))->getAttributes(Map::class)) {
×
59
            return $this->decorated->process($data, $operation, $uriVariables, $context);
×
60
        }
61

62
        // return the Resource representation of the persisted entity
63
        return $this->objectMapper->map(
6✔
64
            // persist the entity
65
            $this->decorated->process(
6✔
66
                // maps the Resource to an Entity
67
                $this->objectMapper->map($data),
6✔
68
                $operation,
6✔
69
                $uriVariables,
6✔
70
                $context,
6✔
71
            ),
6✔
72
            $operation->getClass()
6✔
73
        );
6✔
74
    }
75
}
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