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

api-platform / core / 12086660505

29 Nov 2024 02:41PM UTC coverage: 61.216% (-0.008%) from 61.224%
12086660505

push

github

web-flow
fix(jsonld): check if supportedTypes exists (#6825)

2 of 7 new or added lines in 2 files covered. (28.57%)

1 existing line in 1 file now uncovered.

11317 of 18487 relevant lines covered (61.22%)

16.99 hits per line

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

94.44
/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\Symfony\Validator\Exception\ValidationException as SymfonyValidationException;
18
use ApiPlatform\Validator\Exception\ValidationException;
19
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
20

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

25
    public function __construct(private readonly NormalizerInterface $inner, private readonly array $defaultContext = [])
26
    {
27
    }
124✔
28

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

38
        if ('Error' === $normalized['@type']) {
16✔
39
            $normalized['@type'] = 'hydra:Error';
5✔
40
        }
41

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

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

50
        return $normalized;
16✔
51
    }
52

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

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

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