TemplatingControllerTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 88.68 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 6
dl 47
loc 53
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanBeCreated() 11 11 1
A testHomeCanBeCreated() 10 10 1
A testEmptyReturnsResponse() 10 10 1
A testArrayReturnsResponse() 16 16 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of the Symfony-Util package.
5
 *
6
 * (c) Jean-Bernard Addor
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
use PHPUnit\Framework\TestCase;
13
use Symfony\Bridge\Twig\TwigEngine;
14
use Symfony\Component\HttpFoundation\Response;
15
use Symfony\Component\Templating\TemplateNameParser;
16
use SymfonyUtil\Controller\TemplatingController;
17
18
class HomeTemplatingController extends TemplatingController // To test more in details
19
{
20
    const TEMPLATE = 'home.html.twig';
21
}
22
23
/**
24
 * @covers \SymfonyUtil\Controller\TemplatingController
25
 */
26
final class TemplatingControllerTest extends TestCase
27
{
28 View Code Duplication
    public function testCanBeCreated()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30
        $this->assertInstanceOf(
31
            // TemplatingController::class, // 5.4 < php
32
            'SymfonyUtil\Controller\TemplatingController',
33
            new TemplatingController(new TwigEngine(
34
                new Twig_Environment(new Twig_Loader_Array(['index.html.twig' => 'Hello World!'])),
0 ignored issues
show
Documentation introduced by
new \Twig_Environment(ne...g' => 'Hello World!'))) is of type object<Twig_Environment>, but the function expects a object<Twig\Environment>.

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...
35
                new TemplateNameParser()
36
            ))
37
        );
38
    }
39
40 View Code Duplication
    public function testHomeCanBeCreated()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        $this->assertInstanceOf(
43
            TemplatingController::class, // 5.4 < php
44
            new HomeTemplatingController(new TwigEngine(
45
                new Twig_Environment(new Twig_Loader_Array(['home.html.twig' => 'Hello World!'])),
0 ignored issues
show
Documentation introduced by
new \Twig_Environment(ne...g' => 'Hello World!'))) is of type object<Twig_Environment>, but the function expects a object<Twig\Environment>.

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...
46
                new TemplateNameParser()
47
            ))
48
        );
49
    }
50
51 View Code Duplication
    public function testEmptyReturnsResponse()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
52
    {
53
        $this->assertInstanceOf(
54
            Response::class, // 5.4 < php
55
            (new TemplatingController(new TwigEngine(
56
                new Twig_Environment(new Twig_Loader_Array(['index.html.twig' => 'Hello World!'])),
0 ignored issues
show
Documentation introduced by
new \Twig_Environment(ne...g' => 'Hello World!'))) is of type object<Twig_Environment>, but the function expects a object<Twig\Environment>.

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...
57
                new TemplateNameParser()
58
            )))->__invoke()
59
        );
60
    }
61
62 View Code Duplication
    public function testArrayReturnsResponse()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
    {
64
        $this->assertInstanceOf(
65
            Response::class, // 5.4 < php
66
            (new TemplatingController(new TwigEngine(
67
                new Twig_Environment(new Twig_Loader_Array([
0 ignored issues
show
Documentation introduced by
new \Twig_Environment(ne...i>{% endfor %}</ul>'))) is of type object<Twig_Environment>, but the function expects a object<Twig\Environment>.

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...
68
                    'index.html.twig' => '<ul>{% for item in 0 %}<li>{{ item }}</li>{% endfor %}</ul>',
69
                ])),
70
                new TemplateNameParser()
71
            )))->__invoke([ // This is strange.
0 ignored issues
show
Unused Code introduced by
The call to TemplatingController::__invoke() has too many arguments starting with array('One', 'Two', 'Three').

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...
72
                'One',
73
                'Two',
74
                'Three',
75
            ])
76
        );
77
    }
78
}
79
80
// http://api.symfony.com/3.3/Symfony/Bridge/Twig/TwigEngine.html
81
// http://api.symfony.com/3.3/Symfony/Bundle/TwigBundle/TwigEngine.html
82