VariadicControllerTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 88.64 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 39
loc 44
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanBeCreated() 11 11 1
A testEmptyReturnsResponse() 11 11 1
A testArrayReturnsResponse() 17 17 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\VariadicController;
17
18
/**
19
 * @covers \SymfonyUtil\Controller\VariadicController
20
 * @requires PHP 5.6.0
21
 */
22
final class VariadicControllerTest extends TestCase
23
{
24 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...
25
    {
26
        $this->assertInstanceOf(
27
            // VariadicController::class, // 5.4 < php (code is checked even if not executed!)
28
            'SymfonyUtil\Controller\VariadicController',
29
            new VariadicController(new TwigEngine(
30
                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...
31
                new TemplateNameParser()
32
            ))
33
        );
34
    }
35
36 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...
37
    {
38
        $this->assertInstanceOf(
39
            // Response::class, // 5.4 < php (code is checked even if not executed!)
40
            'Symfony\Component\HttpFoundation\Response',
41
            (new VariadicController(new TwigEngine(
42
                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...
43
                new TemplateNameParser()
44
            )))->__invoke()
45
        );
46
    }
47
48 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...
49
    {
50
        $this->assertInstanceOf(
51
            // Response::class, // 5.4 < php (code is checked even if not executed!)
52
            'Symfony\Component\HttpFoundation\Response',
53
            (new VariadicController(new TwigEngine(
54
                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...
55
                    'index.html.twig' => '<ul>{% for item in 0 %}<li>{{ item }}</li>{% endfor %}</ul>',
56
                ])),
57
                new TemplateNameParser()
58
            )))->__invoke([
59
                'One',
60
                'Two',
61
                'Three',
62
            ])
63
        );
64
    }
65
}
66
67
// http://api.symfony.com/3.3/Symfony/Bridge/Twig/TwigEngine.html
68
// http://api.symfony.com/3.3/Symfony/Bundle/TwigBundle/TwigEngine.html
69