ExceptionController::findTemplate()   B
last analyzed

Complexity

Conditions 9
Paths 20

Size

Total Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 8.0555
c 0
b 0
f 0
cc 9
nc 20
nop 4
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Explicit Architecture POC,
7
 * which is created on top of the Symfony Demo application.
8
 *
9
 * (c) Herberto Graça <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Acme\App\Presentation\Web\Core\Exception;
16
17
use Symfony\Bundle\TwigBundle\Controller\ExceptionController as TwigExceptionController;
18
use Symfony\Component\Debug\Exception\FlattenException;
19
use Symfony\Component\HttpFoundation\Request;
20
use Symfony\Component\HttpFoundation\Response;
21
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
22
23
final class ExceptionController extends TwigExceptionController
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\TwigBundl...ler\ExceptionController has been deprecated with message: since Symfony 4.4, use Symfony\Component\HttpKernel\Controller\ErrorController instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
24
{
25
    private const TEMPLATE_NAMESPACE_TWIG = 'Twig';
26
    private const TEMPLATE_NAMESPACE_WEB = 'Web';
27
28
    public function show(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null): Response
29
    {
30
        return parent::showAction($request, $exception, $logger);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (showAction() instead of show()). Are you sure this is correct? If so, you might want to change this to $this->showAction().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
31
    }
32
33
    /**
34
     * @param string  $format
35
     * @param int     $code          An HTTP response status code
36
     * @param bool    $showException
37
     */
38
    protected function findTemplate(Request $request, $format, $code, $showException): string
39
    {
40
        $name = $showException ? 'exception' : 'error';
41
        $namespace = self::TEMPLATE_NAMESPACE_WEB;
42
        if ($showException && $format === 'html') {
43
            $name = 'exception_full';
44
            $namespace = self::TEMPLATE_NAMESPACE_TWIG;
45
        }
46
47
        // For error pages, try to find a template for the specific HTTP status code and format
48
        if (!$showException) {
49
            $template = sprintf('@%s/Exception/%s%s.%s.twig', $namespace, $name, $code, $format);
50
            if ($this->templateExists($template)) {
51
                return $template;
52
            }
53
        }
54
55
        // try to find a template for the given format
56
        $template = sprintf('@%s/Exception/%s.%s.twig', $namespace, $name, $format);
57
        if ($this->templateExists($template)) {
58
            return $template;
59
        }
60
61
        // default to a generic HTML exception
62
        $request->setRequestFormat('html');
63
64
        return sprintf(
65
            '@%s/Exception/%s.html.twig',
66
            $showException ? self::TEMPLATE_NAMESPACE_TWIG : self::TEMPLATE_NAMESPACE_WEB,
67
            $showException ? 'exception_full' : $name
68
        );
69
    }
70
}
71