Completed
Push — master ( 5aa97c...8e030c )
by Christian
10:05 queued 11s
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
    /**
25
     * @var ExceptionValueMap
26
     */
27
    private $messagesMap;
28
29
    /**
30
     * @var bool
31
     */
32
    private $debug;
33
34
    /**
35
     * @param array $messagesMap
36
     * @param bool  $debug
37
     */
38 12
    public function __construct(ExceptionValueMap $messagesMap, $debug)
39
    {
40 12
        $this->messagesMap = $messagesMap;
41 12
        $this->debug = $debug;
42 12
    }
43
44
    /**
45
     * Extracts the exception message.
46
     *
47
     * @param \Throwable $throwable
48
     * @param int|null   $statusCode
49
     *
50
     * @return string
51
     */
52 7
    protected function getMessageFromThrowable(\Throwable $throwable, $statusCode = null)
53
    {
54 7
        $showMessage = $this->messagesMap->resolveThrowable($throwable);
0 ignored issues
show
Bug introduced by
The method resolveThrowable() does not seem to exist on object<FOS\RestBundle\Util\ExceptionValueMap>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
56 7
        if ($showMessage || $this->debug) {
57 6
            return $throwable->getMessage();
58
        }
59
60 1
        return array_key_exists($statusCode, Response::$statusTexts) ? Response::$statusTexts[$statusCode] : 'error';
61
    }
62
}
63