Completed
Push — master ( fb3acb...928588 )
by Christian
02:51 queued 10s
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 6
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 1
@trigger_error(sprintf('The %s\ExceptionNormalizer class is deprecated since FOSRestBundle 2.8.', __NAMESPACE__), E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
15
16
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
17
18
/**
19
 * Normalizes Exception instances.
20
 *
21
 * @author Ener-Getick <[email protected]>
22
 *
23
 * @deprecated since 2.8
24
 */
25
class ExceptionNormalizer extends AbstractExceptionNormalizer implements NormalizerInterface
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function normalize($object, $format = null, array $context = []): array
31
    {
32
        $data = [];
33
34
        if (isset($context['status_code'])) {
35
            $data['code'] = $statusCode = $context['status_code'];
36
        }
37
38
        $data['message'] = $this->getMessageFromThrowable($object, isset($statusCode) ? $statusCode : null);
39
40
        return $data;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 7
    public function supportsNormalization($data, $format = null): bool
47
    {
48 7
        return $data instanceof \Throwable;
49
    }
50
}
51