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

ExceptionNormalizer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 26
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A normalize() 0 12 3
A supportsNormalization() 0 4 1
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