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

api-platform / core / 11271860720

10 Oct 2024 10:04AM UTC coverage: 7.84% (+0.007%) from 7.833%
11271860720

push

github

soyuka
Merge 3.4

0 of 34 new or added lines in 5 files covered. (0.0%)

11160 existing lines in 381 files now uncovered.

12955 of 165237 relevant lines covered (7.84%)

27.06 hits per line

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

100.0
/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
    {
NEW
27
    }
2,622✔
28

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

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

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

NEW
45
        return $normalized;
203✔
46
    }
47

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

54
    public function getSupportedTypes(?string $format): array
55
    {
NEW
56
        return $this->inner->getSupportedTypes($format);
2,367✔
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