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

api-platform / core / 19337755357

13 Nov 2025 04:03PM UTC coverage: 0.0%. Remained the same
19337755357

push

github

soyuka
Merge 4.2

0 of 298 new or added lines in 18 files covered. (0.0%)

61 existing lines in 11 files now uncovered.

0 of 56962 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/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
        // }
UNCOV
39
    }
×
40

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

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

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

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