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

api-platform / core / 10797021570

10 Sep 2024 04:49PM UTC coverage: 7.679% (+0.02%) from 7.659%
10797021570

push

github

soyuka
fix(laravel): parameter fixes and tests

32 of 49 new or added lines in 6 files covered. (65.31%)

2574 existing lines in 81 files now uncovered.

12619 of 164324 relevant lines covered (7.68%)

23.18 hits per line

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

90.91
/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 Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface;
17
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
18

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

34
    public function __construct(private readonly ?NameConverterInterface $nameConverter = null)
35
    {
UNCOV
36
    }
2,259✔
37

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

UNCOV
47
        if (isset(self::JSON_API_RESERVED_ATTRIBUTES[$propertyName])) {
170✔
UNCOV
48
            $propertyName = self::JSON_API_RESERVED_ATTRIBUTES[$propertyName];
145✔
49
        }
50

UNCOV
51
        return $propertyName;
170✔
52
    }
53

54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function denormalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string
58
    {
UNCOV
59
        if (\in_array($propertyName, self::JSON_API_RESERVED_ATTRIBUTES, true)) {
23✔
60
            $propertyName = substr($propertyName, 1);
×
61
        }
62

UNCOV
63
        if (null !== $this->nameConverter) {
23✔
UNCOV
64
            $propertyName = $this->nameConverter->denormalize($propertyName, $class, $format, $context);
23✔
65
        }
66

UNCOV
67
        return $propertyName;
23✔
68
    }
69
}
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

© 2026 Coveralls, Inc