Completed
Push — master ( 6744a4...ab6d26 )
by Guilh
7s
created

TwigExceptionController::getParameters()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 10
ccs 0
cts 8
cp 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 5
crap 6
1
<?php
2
3
/*
4
 * This file is part of the FOSRestBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\RestBundle\Controller;
13
14
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
15
use Symfony\Component\Debug\Exception\FlattenException;
16
use Symfony\Component\HttpFoundation\Request;
17
18
/**
19
 * Custom ExceptionController that uses the view layer and supports HTTP response status code mapping.
20
 * It additionally is able to prepare the template parameters for the core EngineInterface.
21
 */
22
class TwigExceptionController extends TemplatingExceptionController
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    protected function createView($format, FlattenException $exception, $code, $parameters, Request $request, $showException)
28
    {
29
        $view = parent::createView($format, $exception, $code, $parameters, $request, $showException);
0 ignored issues
show
Documentation introduced by
$exception is of type object<Symfony\Component...ption\FlattenException>, 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...
Documentation introduced by
$request is of type object<Symfony\Component\HttpFoundation\Request>, but the function expects a boolean.

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...
Unused Code introduced by
The call to TemplatingExceptionController::createView() has too many arguments starting with $showException.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
30
        $view->setTemplate($this->findTemplate($request, $format, $code, $showException));
31
32
        return $view;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     *
38
     * This code is inspired by TwigBundle and should be synchronized on a regular basis
39
     * see src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php
40
     */
41
    protected function findTemplate(Request $request, $format, $statusCode, $showException)
42
    {
43
        $name = $showException ? 'exception' : 'error';
44
        if ($showException && 'html' == $format) {
45
            $name = 'exception_full';
46
        }
47
48
        // when not in debug, try to find a template for the specific HTTP status code and format
49
        if (!$showException) {
50
            $template = new TemplateReference('TwigBundle', 'Exception', $name.$statusCode, $format, 'twig');
51
            if ($this->templating->exists($template)) {
52
                return $template;
53
            }
54
        }
55
56
        // try to find a template for the given format
57
        $template = new TemplateReference('TwigBundle', 'Exception', $name, $format, 'twig');
58
        if ($this->templating->exists($template)) {
59
            return $template;
60
        }
61
62
        // default to a generic HTML exception
63
        $request->setRequestFormat('html');
64
65
        return new TemplateReference('TwigBundle', 'Exception', $showException ? 'exception_full' : $name, 'html', 'twig');
66
    }
67
}
68