Completed
Push — master ( 6744a4...ab6d26 )
by Guilh
7s
created

ExceptionNormalizer::supportsNormalization()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 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
class ExceptionNormalizer extends AbstractExceptionNormalizer implements NormalizerInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26 2
    public function normalize($object, $format = null, array $context = [])
27
    {
28 2
        $data = [];
29
30 2
        if (isset($context['template_data']['status_code'])) {
31 2
            $data['code'] = $statusCode = $context['template_data']['status_code'];
32 2
        }
33
34 2
        $data['message'] = $this->getExceptionMessage($object, isset($statusCode) ? $statusCode : null);
35
36 2
        return $data;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 2
    public function supportsNormalization($data, $format = null)
43
    {
44 2
        return $data instanceof \Exception;
45
    }
46
}
47