ExceptionController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 7
dl 0
loc 54
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A showAction() 0 24 3
A findTemplate() 0 10 3
1
<?php
2
3
namespace Alpixel\Bundle\CMSBundle\Controller;
4
5
use Symfony\Bundle\TwigBundle\Controller\ExceptionController as BaseController;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
use Symfony\Component\Debug\Exception\FlattenException;
9
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
10
11
class ExceptionController extends BaseController
12
{
13
    protected $exceptionTemplate;
14
15
    public function __construct(\Twig_Environment $twig, $debug, $exceptionTemplate)
16
    {
17
        $this->exceptionTemplate = $exceptionTemplate;
18
        parent::__construct($twig, $debug);
0 ignored issues
show
Compatibility introduced by
$twig of type object<Twig_Environment> is not a sub-type of object<Twig\Environment>. It seems like you assume a child class of the class Twig_Environment to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
19
    }
20
21
    public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
22
    {
23
        $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
0 ignored issues
show
Documentation introduced by
$request->headers->get('X-Php-Ob-Level', -1) is of type string|array<integer,string>|null, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
24
        $showException = $request->attributes->get('showException', $this->debug); // As opposed to an additional parameter, this maintains BC
25
26
        $code = $exception->getStatusCode();
27
28
        if ($showException) {
29
            $statusCode = Response::HTTP_ACCEPTED;
30
        } else {
31
            $statusCode = $code;
32
        }
33
34
        return new Response($this->twig->render(
35
            (string) $this->findTemplate($request, $request->getRequestFormat(), $code, $showException),
36
            [
37
                'status_code'    => $code,
38
                'status_text'    => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '',
39
                'exception'      => $exception,
40
                'logger'         => $logger,
41
                'currentContent' => $currentContent,
42
            ]
43
        ), $statusCode);
44
    }
45
46
    /**
47
     * @param Request $request
48
     * @param string  $format
49
     * @param int     $code          An HTTP response status code
50
     * @param bool    $showException
51
     *
52
     * @return string
53
     */
54
    protected function findTemplate(Request $request, $format, $code, $showException)
55
    {
56
        if (!$showException) {
57
            if ($this->templateExists($this->exceptionTemplate)) {
58
                return $this->exceptionTemplate;
59
            }
60
        }
61
62
        return parent::findTemplate($request, $format, $code, $showException);
63
    }
64
}
65