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

api-platform / core / 11251666902

09 Oct 2024 09:00AM UTC coverage: 61.844% (+0.02%) from 61.822%
11251666902

push

github

web-flow
fix(hydra): hydra_prefix on errors (#6704)

* fix(hydra): hydra_prefix on errors

* doc: remove warning from changelog

* review

13 of 14 new or added lines in 2 files covered. (92.86%)

167 existing lines in 27 files now uncovered.

11391 of 18419 relevant lines covered (61.84%)

66.73 hits per line

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

92.31
/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
    }
475✔
28

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

37
        if (isset($normalized['description'])) {
60✔
38
            $normalized['hydra:description'] = $normalized['description'];
60✔
39
        }
40

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

45
        return $normalized;
60✔
46
    }
47

48
    public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
49
    {
50
        return $this->inner->supportsNormalization($data, $format, $context)
200✔
51
            && (is_a($data, Error::class) || is_a($data, ValidationException::class) || is_a($data, SymfonyValidationException::class));
200✔
52
    }
53

54
    public function getSupportedTypes(?string $format): array
55
    {
56
        return $this->inner->getSupportedTypes($format);
407✔
57
    }
58
}
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