Completed
Push — master ( 66c8a4...185444 )
by Benjamin
02:33
created

ExceptionController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 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\HttpKernel\Exception\FlattenException;
9
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
10
use Symfony\Component\Routing\Annotation\Route;
11
12
class ExceptionController extends BaseController
13
{
14
    protected $exceptionTemplate;
15
16
    public function __construct(\Twig_Environment $twig, $debug, $exceptionTemplate)
17
    {
18
        $this->exceptionTemplate = $exceptionTemplate;
19
        parent::__construct($twig, $debug);
20
    }
21
22
23
    public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
24
    {
25
        $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, 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...
26
        $showException = $request->attributes->get('showException', $this->debug); // As opposed to an additional parameter, this maintains BC
27
28
        $code = $exception->getStatusCode();
29
30
        if ($showException) {
31
            $statusCode = Response::HTTP_ACCEPTED;
32
        } else {
33
            $statusCode = $code;
34
        }
35
36
        return new Response($this->twig->render(
37
            (string) $this->findTemplate($request, $request->getRequestFormat(), $code, $showException),
38
            [
39
                'status_code'    => $code,
40
                'status_text'    => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '',
41
                'exception'      => $exception,
42
                'logger'         => $logger,
43
                'currentContent' => $currentContent,
44
            ]
45
        ), $statusCode);
46
    }
47
48
    /**
49
     * @param Request $request
50
     * @param string  $format
51
     * @param int     $code          An HTTP response status code
52
     * @param bool    $showException
53
     *
54
     * @return string
55
     */
56
    protected function findTemplate(Request $request, $format, $code, $showException)
57
    {
58
        if (!$showException) {
59
            if ($this->templateExists($this->exceptionTemplate)) {
60
                return $this->exceptionTemplate;
61
            }
62
        }
63
64
        return parent::findTemplate($request, $format, $code, $showException);
65
    }
66
}
67