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

api-platform / core / 15250451308

26 May 2025 09:29AM UTC coverage: 26.388% (+0.008%) from 26.38%
15250451308

push

github

soyuka
fix(openapi): `example` and `default` with nullable value not being shown

0 of 3 new or added lines in 2 files covered. (0.0%)

11122 existing lines in 371 files now uncovered.

13009 of 49299 relevant lines covered (26.39%)

44.73 hits per line

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

88.89
/src/JsonLd/Serializer/ErrorNormalizer.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\JsonLd\Serializer;
15

16
use ApiPlatform\State\ApiResource\Error;
17
use ApiPlatform\Validator\Exception\ValidationException;
18
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
19

20
final class ErrorNormalizer implements NormalizerInterface
21
{
22
    use HydraPrefixTrait;
23

24
    public function __construct(private readonly NormalizerInterface $inner, private readonly array $defaultContext = [])
25
    {
UNCOV
26
    }
1,196✔
27

28
    public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
29
    {
UNCOV
30
        $context += $this->defaultContext;
105✔
UNCOV
31
        $normalized = $this->inner->normalize($object, $format, $context);
105✔
UNCOV
32
        $hydraPrefix = $this->getHydraPrefix($context);
105✔
UNCOV
33
        if (!$hydraPrefix) {
105✔
34
            return $normalized;
×
35
        }
36

UNCOV
37
        if ('Error' === $normalized['@type']) {
105✔
UNCOV
38
            $normalized['@type'] = 'hydra:Error';
65✔
39
        }
40

UNCOV
41
        if (isset($normalized['description'])) {
105✔
UNCOV
42
            $normalized['hydra:description'] = $normalized['description'];
105✔
43
        }
44

UNCOV
45
        if (isset($normalized['title'])) {
105✔
UNCOV
46
            $normalized['hydra:title'] = $normalized['title'];
105✔
47
        }
48

UNCOV
49
        return $normalized;
105✔
50
    }
51

52
    public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
53
    {
UNCOV
54
        return $this->inner->supportsNormalization($data, $format, $context)
725✔
UNCOV
55
            && (is_a($data, Error::class) || is_a($data, ValidationException::class));
725✔
56
    }
57

58
    public function getSupportedTypes(?string $format): array
59
    {
UNCOV
60
        if (method_exists($this->inner, 'getSupportedTypes')) {
1,074✔
UNCOV
61
            return $this->inner->getSupportedTypes($format);
1,074✔
62
        }
63

64
        return [];
×
65
    }
66
}
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