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

api-platform / core / 10629574833

30 Aug 2024 08:38AM UTC coverage: 7.676% (-0.01%) from 7.687%
10629574833

push

github

web-flow
feat(doctrine): add new filter for filtering an entity using PHP backed enum, resolves #6506 (#6547)

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

7082 existing lines in 239 files now uncovered.

12488 of 162690 relevant lines covered (7.68%)

22.89 hits per line

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

100.0
/src/JsonApi/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\JsonApi\Serializer;
15

16
use Symfony\Component\ErrorHandler\Exception\FlattenException;
17
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
18

19
/**
20
 * Converts {@see \Exception} or {@see FlattenException} or to a JSON API error representation.
21
 *
22
 * @author Héctor Hurtarte <hectorh30@gmail.com>
23
 */
24
final class ErrorNormalizer implements NormalizerInterface
25
{
26
    public const FORMAT = 'jsonapi';
27

28
    public function __construct(private ?NormalizerInterface $itemNormalizer = null)
29
    {
UNCOV
30
    }
2,255✔
31

32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function normalize(mixed $object, ?string $format = null, array $context = []): array
36
    {
UNCOV
37
        $jsonApiObject = $this->itemNormalizer->normalize($object, $format, $context);
8✔
UNCOV
38
        $error = $jsonApiObject['data']['attributes'];
8✔
UNCOV
39
        $error['id'] = $jsonApiObject['data']['id'];
8✔
UNCOV
40
        $error['type'] = $jsonApiObject['data']['id'];
8✔
41

UNCOV
42
        return ['errors' => [$error]];
8✔
43
    }
44

45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
49
    {
UNCOV
50
        return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException);
8✔
51
    }
52

53
    public function getSupportedTypes($format): array
54
    {
UNCOV
55
        if (self::FORMAT === $format) {
2,124✔
UNCOV
56
            return [
181✔
UNCOV
57
                \Exception::class => true,
181✔
UNCOV
58
                FlattenException::class => true,
181✔
UNCOV
59
            ];
181✔
60
        }
61

UNCOV
62
        return [];
1,943✔
63
    }
64
}
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