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

api-platform / core / 15133993414

20 May 2025 09:30AM UTC coverage: 26.313% (-1.2%) from 27.493%
15133993414

Pull #7161

github

web-flow
Merge e2c03d45f into 5459ba375
Pull Request #7161: fix(metadata): infer parameter string type from schema

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

11019 existing lines in 363 files now uncovered.

12898 of 49018 relevant lines covered (26.31%)

34.33 hits per line

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

92.31
/src/JsonApi/Serializer/ReservedAttributeNameConverter.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\JsonApi\Serializer;
15

16
use ApiPlatform\Metadata\Exception\ProblemExceptionInterface;
17
use Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface;
18
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
19

20
/**
21
 * Reserved attribute name converter.
22
 *
23
 * @author Baptiste Meyer <baptiste.meyer@gmail.com>
24
 */
25
final class ReservedAttributeNameConverter implements NameConverterInterface, AdvancedNameConverterInterface
26
{
27
    public const JSON_API_RESERVED_ATTRIBUTES = [
28
        'id' => '_id',
29
        'type' => '_type',
30
        'links' => '_links',
31
        'relationships' => '_relationships',
32
        'included' => '_included',
33
    ];
34

35
    public function __construct(private readonly ?NameConverterInterface $nameConverter = null)
36
    {
UNCOV
37
    }
950✔
38

39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function normalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string
43
    {
UNCOV
44
        if (null !== $this->nameConverter) {
68✔
UNCOV
45
            $propertyName = $this->nameConverter->normalize($propertyName, $class, $format, $context);
68✔
46
        }
47

UNCOV
48
        if ($class && is_a($class, ProblemExceptionInterface::class, true)) {
68✔
UNCOV
49
            return $propertyName;
3✔
50
        }
51

UNCOV
52
        if (isset(self::JSON_API_RESERVED_ATTRIBUTES[$propertyName])) {
65✔
UNCOV
53
            $propertyName = self::JSON_API_RESERVED_ATTRIBUTES[$propertyName];
49✔
54
        }
55

UNCOV
56
        return $propertyName;
65✔
57
    }
58

59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function denormalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string
63
    {
64
        if (\in_array($propertyName, self::JSON_API_RESERVED_ATTRIBUTES, true)) {
7✔
65
            $propertyName = substr($propertyName, 1);
×
66
        }
67

68
        if (null !== $this->nameConverter) {
7✔
69
            $propertyName = $this->nameConverter->denormalize($propertyName, $class, $format, $context);
7✔
70
        }
71

72
        return $propertyName;
7✔
73
    }
74
}
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