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

api-platform / core / 12314371934

13 Dec 2024 10:57AM UTC coverage: 62.118% (-0.003%) from 62.121%
12314371934

push

github

soyuka
ci: use problem error normalizer trait

11493 of 18502 relevant lines covered (62.12%)

68.69 hits per line

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

57.14
/src/Problem/Serializer/ErrorNormalizerTrait.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\Problem\Serializer;
15

16
use ApiPlatform\Exception\ErrorCodeSerializableInterface;
17
use Symfony\Component\ErrorHandler\Exception\FlattenException;
18
use Symfony\Component\HttpFoundation\Response;
19

20
trait ErrorNormalizerTrait
21
{
22
    private function getErrorMessage($object, array $context, bool $debug = false): string
23
    {
24
        $message = $object->getMessage();
36✔
25

26
        if ($debug) {
36✔
27
            return $message;
16✔
28
        }
29

30
        if ($object instanceof FlattenException) {
20✔
31
            $statusCode = $context['statusCode'] ?? $object->getStatusCode();
16✔
32
            if ($statusCode >= 500 && $statusCode < 600) {
16✔
33
                $message = Response::$statusTexts[$statusCode] ?? Response::$statusTexts[Response::HTTP_INTERNAL_SERVER_ERROR];
12✔
34
            }
35
        }
36

37
        return $message;
20✔
38
    }
39

40
    private function getErrorCode(object $object): ?string
41
    {
42
        if ($object instanceof FlattenException) {
×
43
            $exceptionClass = $object->getClass();
×
44
        } else {
45
            $exceptionClass = $object::class;
×
46
        }
47

48
        if (is_a($exceptionClass, ErrorCodeSerializableInterface::class, true)) {
×
49
            return $exceptionClass::getErrorCode();
×
50
        }
51

52
        return null;
×
53
    }
54
}
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