ExceptionController::showExceptionAction()   B
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 30
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 13
cts 13
cp 1
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 17
nc 4
nop 3
crap 3
1
<?php
2
3
namespace SumoCoders\FrameworkErrorBundle\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6
use Symfony\Bundle\FrameworkBundle\Translation\Translator;
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\Debug\Exception\FlattenException;
9
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
10
11
class ExceptionController extends Controller
12
{
13
    /**
14
     * @param Request              $request
15
     * @param FlattenException     $exception
16
     * @param DebugLoggerInterface $logger
0 ignored issues
show
Documentation introduced by
Should the type for parameter $logger not be null|DebugLoggerInterface?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
17
     * @return \Symfony\Component\HttpFoundation\Response
18
     */
19 2
    public function showExceptionAction(
20
        Request $request,
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
21
        FlattenException $exception,
22
        DebugLoggerInterface $logger = null
0 ignored issues
show
Unused Code introduced by
The parameter $logger is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
23
    ) {
24
        /** @var Translator $translator */
25 2
        $translator = $this->get('translator');
26 2
        $message = $translator->trans('error.messages.generic');
27
28
        // check if the error is whitelisted to overrule the message
29 2
        if (in_array(
30 2
            $exception->getClass(),
31 2
            $this->container->getParameter('sumo_coders_framework_error.show_messages_for')
32
        )) {
33 1
            $message = $exception->getMessage();
34
        }
35
36
        // translate page not found messages
37 2
        if ('Symfony\Component\HttpKernel\Exception\NotFoundHttpException' == $exception->getClass()) {
38 1
            $message = $translator->trans('error.messages.noRouteFound');
39
        }
40
41 2
        return $this->render(
42 2
            '::error.html.twig',
43
            array(
44 2
                'status_code' => $exception->getStatusCode(),
45 2
                'status_text' => $message,
46
            )
47
        );
48
    }
49
}
50