Completed
Push — master ( 957717...7a0390 )
by Christian
02:31 queued 11s
created

ExceptionNormalizer::normalize()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 9
cp 0
rs 9.8666
c 0
b 0
f 0
cc 3
nc 2
nop 3
crap 12
1
<?php
2
3
/*
4
 * This file is part of the FOSRestBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.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
namespace FOS\RestBundle\Serializer\Normalizer;
13
14
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
15
16
/**
17
 * Normalizes Exception instances.
18
 *
19
 * @author Ener-Getick <[email protected]>
20
 *
21
 * @internal
22
 */
23
class ExceptionNormalizer extends AbstractExceptionNormalizer implements NormalizerInterface
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function normalize($object, $format = null, array $context = []): array
29
    {
30
        $data = [];
31
32
        if (isset($context['status_code'])) {
33
            $data['code'] = $statusCode = $context['status_code'];
34
        }
35
36
        $data['message'] = $this->getMessageFromThrowable($object, isset($statusCode) ? $statusCode : null);
37
38
        return $data;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function supportsNormalization($data, $format = null): bool
45
    {
46
        return $data instanceof \Throwable;
47
    }
48
}
49