Completed
Push — master ( 7a0390...1e4134 )
by Christian
03:04
created

getMessageFromThrowable()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.9332
c 0
b 0
f 0
cc 4
nc 3
nop 2
crap 4
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 10
    public function __construct(ExceptionValueMap $messagesMap, bool $debug)
28
    {
29 10
        $this->messagesMap = $messagesMap;
30 10
        $this->debug = $debug;
31 10
    }
32
33 7
    protected function getMessageFromThrowable(\Throwable $throwable, ?int $statusCode = null): string
34
    {
35 7
        $showMessage = $this->messagesMap->resolveException($throwable);
36
37 7
        if ($showMessage || $this->debug) {
38 6
            return $throwable->getMessage();
39
        }
40
41 1
        return array_key_exists($statusCode, Response::$statusTexts) ? Response::$statusTexts[$statusCode] : 'error';
42
    }
43
}
44