Completed
Push — master ( fabcc6...b3ce24 )
by Benjamin
02:09
created

ExceptionController::findTemplate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
nop 4
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
        return new Response($this->twig->render(
25
            (string) $this->findTemplate($request, $request->getRequestFormat(), $code, $showException),
26
            array(
27
                'status_code' => $code,
28
                'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '',
29
                'exception' => $exception,
30
                'logger' => $logger,
31
                'currentContent' => $currentContent,
32
            )
33
        ), $code);
34
    }
35
36
    /**
37
     * @param Request $request
38
     * @param string  $format
39
     * @param int     $code          An HTTP response status code
40
     * @param bool    $showException
41
     *
42
     * @return string
43
     */
44
    protected function findTemplate(Request $request, $format, $code, $showException)
45
    {
46
        // try to find a template for the given format
47
        $template = sprintf('page/errors.html.twig');
48
        if ($this->templateExists($template)) {
49
            return $template;
50
        }
51
52
        return parent::findTemplate($request, $format, $code, $showException);
53
    }
54
}
55