Completed
Push — master ( fb3acb...928588 )
by Christian
02:51 queued 10s
created

getMessageFromThrowable()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 5
cp 0
rs 9.9332
c 0
b 0
f 0
cc 4
nc 3
nop 2
crap 20
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 FOS\RestBundle\Util\ExceptionValueMap;
15
use Symfony\Component\HttpFoundation\Response;
16
17
/**
18
 * @author Ener-Getick <[email protected]>
19
 *
20
 * @internal do not use this class in your code
21
 */
22
class AbstractExceptionNormalizer
23
{
24
    private $messagesMap;
25
    private $debug;
26
27 8
    public function __construct(ExceptionValueMap $messagesMap, bool $debug)
28
    {
29 8
        $this->messagesMap = $messagesMap;
30 8
        $this->debug = $debug;
31 8
    }
32
33
    protected function getMessageFromThrowable(\Throwable $throwable, ?int $statusCode = null): string
34
    {
35
        $showMessage = $this->messagesMap->resolveException($throwable);
36
37
        if ($showMessage || $this->debug) {
38
            return $throwable->getMessage();
39
        }
40
41
        return array_key_exists($statusCode, Response::$statusTexts) ? Response::$statusTexts[$statusCode] : 'error';
42
    }
43
}
44