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.

CopyTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 77
Duplicated Lines 18.18 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 14
loc 77
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B testCopy() 0 24 1
A testNotExists() 14 14 1
A testNotReadable() 0 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
namespace Naneau\FileGen\Test;
3
4
use Naneau\FileGen\File\Contents\Copy as CopyContents;
5
use Naneau\FileGen\Structure;
6
use Naneau\FileGen\File;
7
use Naneau\FileGen\Generator;
8
9
/**
10
 * Copying of files
11
 */
12
class CopyTest extends \Naneau\FileGen\Test\Generator\TestCase
13
{
14
    /**
15
     * Test copying
16
     *
17
     * @return void
18
     **/
19
    public function testCopy()
20
    {
21
        $generator = $this->createGenerator();
22
23
        $structure = new Structure;
24
        $structure
25
            ->file('foo', 'foo contents')
26
            ->file(
27
                'bar',
28
                new CopyContents($generator->getRoot() . '/foo')
0 ignored issues
show
Documentation introduced by
new \Naneau\FileGen\File...or->getRoot() . '/foo') is of type object<Naneau\FileGen\File\Contents\Copy>, 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...
29
            );
30
31
        $generator->generate($structure);
32
33
        // See if structure was generated
34
        $this->assertEquals(
35
            file_get_contents($generator->getRoot() . '/foo'),
36
            'foo contents'
37
        );
38
        $this->assertEquals(
39
            file_get_contents($generator->getRoot() . '/bar'),
40
            'foo contents'
41
        );
42
    }
43
44
    /**
45
     * Test copy fail
46
     *
47
     * @expectedException Naneau\FileGen\File\Contents\Exception
48
     * @return void
49
     **/
50 View Code Duplication
    public function testNotExists()
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...
51
    {
52
        $generator = $this->createGenerator();
53
54
        $structure = new Structure;
55
        $structure
56
            ->file('foo', 'foo contents')
57
            ->file(
58
                'bar',
59
                new CopyContents($generator->getRoot() . '/I-do-not-exist')
0 ignored issues
show
Documentation introduced by
new \Naneau\FileGen\File...() . '/I-do-not-exist') is of type object<Naneau\FileGen\File\Contents\Copy>, 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...
60
            );
61
62
        $generator->generate($structure);
63
    }
64
65
    /**
66
     * Test copy fail
67
     *
68
     * @expectedException Naneau\FileGen\File\Contents\Exception
69
     * @return void
70
     **/
71
    public function testNotReadable()
72
    {
73
        $generator = $this->createGenerator();
74
75
        // Create unreadable file
76
        touch($generator->getRoot() . '/not-readable');
77
        chmod($generator->getRoot() . '/not-readable', 0000);
78
79
        $structure = new Structure;
80
        $structure
81
            ->file(
82
                'bar',
83
                new CopyContents($generator->getRoot() . '/not-readable')
0 ignored issues
show
Documentation introduced by
new \Naneau\FileGen\File...ot() . '/not-readable') is of type object<Naneau\FileGen\File\Contents\Copy>, 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...
84
            );
85
86
        $generator->generate($structure);
87
    }
88
}
89