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

AbstractExceptionNormalizer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 44.44%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 22
ccs 4
cts 9
cp 0.4444
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getMessageFromThrowable() 0 10 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 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