Completed
Push — master ( 946f14...8e5056 )
by Benjamin
02:19
created

ExceptionController::showAction()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 24
rs 8.9713
cc 3
eloc 16
nc 2
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
    /**
15
     * @Route("/erreur", name="error")
16
     */
17
    public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
18
    {
19
        $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...
20
        $showException = $request->attributes->get('showException', $this->debug); // As opposed to an additional parameter, this maintains BC
21
22
        $code = $exception->getStatusCode();
23
24
        if($showException) {
25
            $statusCode = Response::HTTP_ACCEPTED;
26
        } else {
27
            $statusCode = $code;
28
        }
29
30
        return new Response($this->twig->render(
31
            (string) $this->findTemplate($request, $request->getRequestFormat(), $code, $showException),
32
            [
33
                'status_code'    => $code,
34
                'status_text'    => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '',
35
                'exception'      => $exception,
36
                'logger'         => $logger,
37
                'currentContent' => $currentContent,
38
            ]
39
        ), $statusCode);
40
    }
41
42
    /**
43
     * @param Request $request
44
     * @param string  $format
45
     * @param int     $code          An HTTP response status code
46
     * @param bool    $showException
47
     *
48
     * @return string
49
     */
50
    protected function findTemplate(Request $request, $format, $code, $showException)
51
    {
52
        if(!$showException) {
53
            // try to find a template for the given format
54
            $template = sprintf('page/errors.html.twig');
55
            if ($this->templateExists($template)) {
56
                return $template;
57
            }
58
        }
59
60
        return parent::findTemplate($request, $format, $code, $showException);
61
    }
62
}
63