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.

DirectoryTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 170
Duplicated Lines 8.24 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreation() 14 14 1
A testPermissions() 0 23 1
A testNesting() 0 22 1
A testFile() 0 65 1
A testAlreadyExists() 0 12 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\Generator;
3
4
use Naneau\FileGen\Structure;
5
use Naneau\FileGen\Directory;
6
use Naneau\FileGen\File;
7
use Naneau\FileGen\Generator;
8
9
/**
10
 * Test directory structure generation
11
 */
12
class DirectoryTest extends \Naneau\FileGen\Test\Generator\TestCase
13
{
14
    /**
15
     * Test simple creation
16
     *
17
     * @return void
18
     **/
19 View Code Duplication
    public function testCreation()
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...
20
    {
21
        $structure = new Structure;
22
        $structure
23
            ->directory('foo')
24
            ->directory('bar');
25
26
        $generator = $this->createGenerator();
27
        $generator->generate($structure);
28
29
        // See if structure was generated
30
        $this->assertTrue(is_dir($generator->getRoot() . '/foo'));
31
        $this->assertTrue(is_dir($generator->getRoot() . '/bar'));
32
    }
33
34
    /**
35
     * Test permissions
36
     *
37
     * @return void
38
     **/
39
    public function testPermissions()
40
    {
41
        $structure = new Structure;
42
        $structure
43
            ->directory('foo', 0755)
44
            ->directory('bar', 0700);
45
46
        $generator = $this->createGenerator();
47
        $generator->generate($structure);
48
49
        // See if structure was generated
50
        $this->assertTrue(is_dir($generator->getRoot() . '/foo'));
51
        $this->assertEquals(
52
            substr(sprintf('%o', fileperms($generator->getRoot() . '/foo')), -4),
53
            '0755'
54
        );
55
56
        $this->assertTrue(is_dir($generator->getRoot() . '/bar'));
57
        $this->assertEquals(
58
            substr(sprintf('%o', fileperms($generator->getRoot() . '/bar')), -4),
59
            '0700'
60
        );
61
    }
62
63
    /**
64
     * Test Nesting
65
     *
66
     * @return void
67
     **/
68
    public function testNesting()
69
    {
70
        $structure = new Structure;
71
        $structure
72
            // Incremental
73
            ->directory('foo')
74
            ->directory('foo/bar')
75
            ->directory('foo/bar/baz')
76
77
            // At once
78
            ->directory('bar/baz/qux')
79
            ;
80
81
        $generator = $this->createGenerator();
82
        $generator->generate($structure);
83
84
        $this->assertTrue(is_dir($generator->getRoot() . '/foo'));
85
        $this->assertTrue(is_dir($generator->getRoot() . '/foo/bar'));
86
        $this->assertTrue(is_dir($generator->getRoot() . '/foo/bar/baz'));
87
88
        $this->assertTrue(is_dir($generator->getRoot() . '/bar/baz/qux'));
89
    }
90
91
    /**
92
     * Test a complex structure of directories mixed with files
93
     *
94
     * @return void
95
     **/
96
    public function testFile()
97
    {
98
        // Note leading/trailing slashes
99
        $structure = new Structure;
100
        $structure
101
            // Incremental
102
            ->directory('foo/', 0755)
103
            ->directory('/foo/bar', 0700)
104
            ->directory('/foo/bar/baz/')
105
106
            // Files for each dir
107
            ->file('foo/fileOne', 'file one', 0775)
108
            ->file('foo/bar/fileTwo', 'file two', 0700)
109
            ->file('/foo/bar/baz/fileThree', 'file three')
110
111
            // At once
112
            ->directory('bar/baz/qux')
113
            ->file('bar/baz/qux/fileFour', 'file four')
114
            ;
115
116
        $generator = $this->createGenerator();
117
        $generator->generate($structure);
118
119
        $this->assertTrue(is_dir($generator->getRoot() . '/foo'));
120
        $this->assertEquals(
121
            substr(sprintf('%o', fileperms($generator->getRoot() . '/foo')), -4),
122
            '0755'
123
        );
124
125
        $this->assertEquals(
126
            file_get_contents($generator->getRoot() . '/foo/fileOne'),
127
            'file one'
128
        );
129
        $this->assertEquals(
130
            substr(sprintf('%o', fileperms($generator->getRoot() . '/foo/fileOne')), -4),
131
            '0775'
132
        );
133
134
        $this->assertTrue(is_dir($generator->getRoot() . '/foo/bar'));
135
        $this->assertEquals(
136
            substr(sprintf('%o', fileperms($generator->getRoot() . '/foo/bar')), -4),
137
            '0700'
138
        );
139
140
        $this->assertEquals(
141
            file_get_contents($generator->getRoot() . '/foo/bar/fileTwo'),
142
            'file two'
143
        );
144
        $this->assertEquals(
145
            substr(sprintf('%o', fileperms($generator->getRoot() . '/foo/bar/fileTwo')), -4),
146
            '0700'
147
        );
148
149
        $this->assertTrue(is_dir($generator->getRoot() . '/foo/bar/baz'));
150
        $this->assertEquals(
151
            file_get_contents($generator->getRoot() . '/foo/bar/baz/fileThree'),
152
            'file three'
153
        );
154
155
        $this->assertTrue(is_dir($generator->getRoot() . '/bar/baz/qux'));
156
        $this->assertEquals(
157
            file_get_contents($generator->getRoot() . '/bar/baz/qux/fileFour'),
158
            'file four'
159
        );
160
    }
161
162
    /**
163
     * Test already exists
164
     *
165
     * @expectedException Naneau\FileGen\Generator\Exception\NodeExists
166
     *
167
     * @return void
168
     **/
169
    public function testAlreadyExists()
170
    {
171
        $structure = new Structure;
172
        $structure->directory('foo');
173
174
        $generator = $this->createGenerator();
175
176
        // dir exists already... oh noes.
177
        mkdir($generator->getRoot() . '/foo');
178
179
        $generator->generate($structure);
180
    }
181
}
182