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

api-platform / core / 9710673650

25 Jun 2024 02:01PM UTC coverage: 61.693% (-0.9%) from 62.637%
9710673650

push

github

web-flow
feat(laravel): laravel component (#5882)

* feat(laravel): laravel component

* try to skip laravel

* feat(jsonapi): component

* feat(laravel): json api support (needs review)

* work on relations

* relations (needs toMany) + skolem + IRI to resource

* links handler

* ulid

* validation

* slug post

* remove deprecations

* move classes

* fix tests

* fix tests metadata

* phpstan

* missing class

* fix laravel tests

* fix stan

33 of 77 new or added lines in 20 files covered. (42.86%)

140 existing lines in 15 files now uncovered.

10787 of 17485 relevant lines covered (61.69%)

59.64 hits per line

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

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

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

20
/**
21
 * @internal
22
 */
23
trait ErrorNormalizerTrait
24
{
25
    private function getErrorMessage($object, array $context, bool $debug = false): string
26
    {
NEW
27
        $message = $object->getMessage();
×
28

NEW
29
        if ($debug) {
×
NEW
30
            return $message;
×
31
        }
32

NEW
33
        if ($object instanceof FlattenException) {
×
NEW
34
            $statusCode = $context['statusCode'] ?? $object->getStatusCode();
×
NEW
35
            if ($statusCode >= 500 && $statusCode < 600) {
×
NEW
36
                $message = Response::$statusTexts[$statusCode] ?? Response::$statusTexts[Response::HTTP_INTERNAL_SERVER_ERROR];
×
37
            }
38
        }
39

NEW
40
        return $message;
×
41
    }
42

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

NEW
51
        if (is_a($exceptionClass, ErrorCodeSerializableInterface::class, true)) {
×
NEW
52
            return $exceptionClass::getErrorCode();
×
53
        }
54

NEW
55
        return null;
×
56
    }
57
}
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