GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

TwigTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 122
Duplicated Lines 66.39 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 6
dl 81
loc 122
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testRender() 17 17 1
A testRenderParameters() 22 22 1
A testStructureParameters() 21 21 1
A testMissingParameters() 21 21 1
A createTwig() 0 9 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
namespace Naneau\FileGen\Test\File;
3
4
use Naneau\FileGen\Structure;
5
use Naneau\FileGen\File\Contents\Twig as TwigContents;
6
7
use \Twig_Loader_Filesystem as TwigFileLoader;
8
use \Twig_Environment as TwigEnvironment;
9
10
/**
11
 * testing twig
12
 */
13
class TwigTest extends \Naneau\FileGen\Test\Generator\TestCase
14
{
15
    /**
16
     * Simple render
17
     *
18
     * @return void
19
     **/
20 View Code Duplication
    public function testRender()
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...
21
    {
22
        $generator = $this->createGenerator();
23
24
        $structure = new Structure;
25
        $structure->file('foo', new TwigContents(
0 ignored issues
show
Documentation introduced by
new \Naneau\FileGen\File...d('template_one.twig')) is of type object<Naneau\FileGen\File\Contents\Twig>, but the function expects a string|object<Naneau\FileGen\FileContents>.

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...
26
            $this->createTwig()->load('template_one.twig')
27
        ));
28
29
        $generator->generate($structure);
30
31
        // See if structure was generated
32
        $this->assertEquals(
33
            file_get_contents($generator->getRoot() . '/foo'),
34
            "foo bar baz\n" // Twig generates a newline at EOF...
35
        );
36
    }
37
38
    /**
39
     * Parameters
40
     *
41
     * @return void
42
     **/
43 View Code Duplication
    public function testRenderParameters()
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...
44
    {
45
        $generator = $this->createGenerator();
46
47
        $structure = new Structure;
48
        $structure->file('foo', new TwigContents(
0 ignored issues
show
Documentation introduced by
new \Naneau\FileGen\File...'bar', 'baz' => 'baz')) is of type object<Naneau\FileGen\File\Contents\Twig>, but the function expects a string|object<Naneau\FileGen\FileContents>.

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...
49
            $this->createTwig()->load('template_two.twig'),
50
            array(
51
                'foo' => 'foo',
52
                'bar' => 'bar',
53
                'baz' => 'baz'
54
            )
55
        ));
56
57
        $generator->generate($structure);
58
59
        // See if structure was generated
60
        $this->assertEquals(
61
            file_get_contents($generator->getRoot() . '/foo'),
62
            "foo bar baz\n" // Twig generates a newline at EOF...
63
        );
64
    }
65
66
    /**
67
     * Test parameters through structure
68
     *
69
     * @return void
70
     **/
71 View Code Duplication
    public function testStructureParameters()
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...
72
    {
73
        $structure = new Structure;
74
        $structure
75
            ->file('foo', new TwigContents(
0 ignored issues
show
Documentation introduced by
new \Naneau\FileGen\File...d('template_two.twig')) is of type object<Naneau\FileGen\File\Contents\Twig>, but the function expects a string|object<Naneau\FileGen\FileContents>.

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...
76
                $this->createTwig()->load('template_two.twig')
77
            ));
78
79
        $generator = $this->createGenerator(array(
80
            'foo' => 'foo',
81
            'bar' => 'bar',
82
            'baz' => 'baz'
83
        ));
84
        $generator->generate($structure);
85
86
        // See if structure was generated
87
        $this->assertEquals(
88
            file_get_contents($generator->getRoot() . '/foo'),
89
            "foo bar baz\n" // Twig generates a newline at EOF...
90
        );
91
    }
92
93
    /**
94
     * Parameters
95
     *
96
     * @return void
97
     **/
98 View Code Duplication
    public function testMissingParameters()
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...
99
    {
100
        $generator = $this->createGenerator();
101
102
        $structure = new Structure;
103
        $structure->file('foo', new TwigContents(
0 ignored issues
show
Documentation introduced by
new \Naneau\FileGen\File...'foo', 'baz' => 'baz')) is of type object<Naneau\FileGen\File\Contents\Twig>, but the function expects a string|object<Naneau\FileGen\FileContents>.

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...
104
            $this->createTwig()->load('template_two.twig'),
105
            array(
106
                'foo' => 'foo',
107
                'baz' => 'baz'
108
            )
109
        ));
110
111
        $generator->generate($structure);
112
113
        // See if structure was generated
114
        $this->assertEquals(
115
            file_get_contents($generator->getRoot() . '/foo'),
116
            "foo  baz\n" // Twig generates a newline at EOF...
117
        );
118
    }
119
120
    /**
121
     * Create a twig environment
122
     *
123
     * @return TwigEnvironment
124
     **/
125
    private function createTwig()
126
    {
127
        return new TwigEnvironment(
128
            new TwigFileLoader($this->getTestsRoot() .  '/templates/'),
129
            array(
130
                'cache' => sys_get_temp_dir() . '/filegen-tests-twig-compile'
131
            )
132
        );
133
    }
134
}
135