Completed
Push — master ( 422e48...fabcc6 )
by Benjamin
02:32 queued 14s
created

ExceptionController::showAction()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 18
rs 9.4285
cc 2
eloc 12
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
    /**
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
        ));
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
        $name = $showException ? 'exception' : 'error';
47
        if ($showException && 'html' == $format) {
48
            $name = 'exception_full';
49
        }
50
51
        // For error pages, try to find a template for the specific HTTP status code and format
52
        if (!$showException) {
53
            $template = sprintf('@Twig/Exception/%s%s.%s.twig', $name, $code, $format);
54
            if ($this->templateExists($template)) {
55
                return $template;
56
            }
57
        }
58
59
        // try to find a template for the given format
60
        $template = sprintf('@Twig/Exception/%s.%s.twig', $name, $format);
61
        if ($this->templateExists($template)) {
62
            return $template;
63
        }
64
65
        // default to a generic HTML exception
66
        $request->setRequestFormat('html');
67
68
        return sprintf('@Twig/Exception/%s.html.twig', $showException ? 'exception_full' : $name);
69
    }
70
}
71