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

api-platform / core / 15955912273

29 Jun 2025 01:51PM UTC coverage: 22.057% (-0.03%) from 22.082%
15955912273

Pull #7249

github

web-flow
Merge d9904d788 into a42034dc3
Pull Request #7249: chore: solve some phpstan issues

0 of 9 new or added lines in 8 files covered. (0.0%)

11540 existing lines in 372 files now uncovered.

11522 of 52237 relevant lines covered (22.06%)

11.08 hits per line

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

90.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\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
    }
258✔
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;
34✔
UNCOV
31
        $normalized = $this->inner->normalize($object, $format, $context);
34✔
UNCOV
32
        $hydraPrefix = $this->getHydraPrefix($context);
34✔
UNCOV
33
        if (!$hydraPrefix) {
34✔
34
            return $normalized;
×
35
        }
36

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

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

UNCOV
46
        if (isset($normalized['title'])) {
34✔
UNCOV
47
            $normalized['hydra:title'] = $normalized['title'];
34✔
48
            // this is confusing as the field is also available in the Problem Detail Json representation
49
            // but we don't want to repeat the title in the response, tldr: use hydra without prefix
UNCOV
50
            unset($normalized['title']);
34✔
51
        }
52

UNCOV
53
        return $normalized;
34✔
54
    }
55

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

62
    public function getSupportedTypes(?string $format): array
63
    {
UNCOV
64
        if (method_exists($this->inner, 'getSupportedTypes')) {
230✔
UNCOV
65
            return $this->inner->getSupportedTypes($format);
230✔
66
        }
67

68
        return [];
×
69
    }
70
}
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