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

api-platform / core / 18974957045

31 Oct 2025 02:04PM UTC coverage: 24.541% (-0.06%) from 24.603%
18974957045

push

github

web-flow
Merge 4.1 (#7499)

Co-authored-by: Nicolas LAURENT <aegypius@users.noreply.github.com>
Co-authored-by: Javier Sampedro <jsampedro77@gmail.com>
fix(laravel): serializer attributes on Eloquent methods (#7416)
fixes #7289
fixes #7338
fix(validator): custom message was not translated (#7424)
fixes #7336
fix(serializer): resilient denormalizeRelation capability (#7474)
fix(doctrine): properly set properties according to interface (#7487)
fix(graphql): stateOptions to get filter class (#7485)

11 of 232 new or added lines in 20 files covered. (4.74%)

28 existing lines in 6 files now uncovered.

14064 of 57309 relevant lines covered (24.54%)

26.35 hits per line

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

73.33
/src/State/ObjectMapper/ObjectMapper.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\ObjectMapper;
15

16
use ApiPlatform\Metadata\Exception\RuntimeException;
17
use Symfony\Component\ObjectMapper\ObjectMapperAwareInterface;
18
use Symfony\Component\ObjectMapper\ObjectMapperInterface;
19

20
final class ObjectMapper implements ObjectMapperInterface, ClearObjectMapInterface, ObjectMapperAwareInterface
21
{
22
    private ?\SplObjectStorage $objectMap = null;
23

24
    public function __construct(private ObjectMapperInterface $decorated)
25
    {
26
        if (null === $this->objectMap) {
702✔
27
            $this->objectMap = new \SplObjectStorage();
702✔
28
        }
29

30
        if ($this->decorated instanceof ObjectMapperAwareInterface) {
702✔
31
            $this->decorated = $this->decorated->withObjectMapper($this);
702✔
32
        }
33
    }
34

35
    public function map(object $source, object|string|null $target = null): object
36
    {
37
        if (!\is_object($target) && isset($this->objectMap[$source])) {
10✔
38
            $target = $this->objectMap[$source];
6✔
39
        }
40
        $mapped = $this->decorated->map($source, $target);
10✔
41
        $this->objectMap[$mapped] = $source;
10✔
42

43
        return $mapped;
10✔
44
    }
45

46
    public function clearObjectMap(): void
47
    {
48
        foreach ($this->objectMap as $k) {
6✔
49
            $this->objectMap->detach($k);
6✔
50
        }
51
    }
52

53
    public function withObjectMapper(ObjectMapperInterface $objectMapper): static
54
    {
UNCOV
55
        if (!$this->decorated instanceof ObjectMapperAwareInterface) {
×
UNCOV
56
            throw new RuntimeException(\sprintf('Given object mapper "%s" does not implements %s.', get_debug_type($this->decorated), ObjectMapperAwareInterface::class));
×
57
        }
58

UNCOV
59
        $this->decorated->withObjectMapper($objectMapper);
×
60

UNCOV
61
        return $this;
×
62
    }
63
}
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