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.

Directory   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 178
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 18
lcom 1
cbo 3
dl 0
loc 178
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
B scan() 0 24 4
A getChildren() 0 4 1
A setChildren() 0 6 1
A addChild() 0 8 1
A hasChild() 0 10 3
A getChild() 0 13 3
A rewind() 0 4 1
A current() 0 4 1
A key() 0 4 1
A next() 0 4 1
A valid() 0 4 1
1
<?php
2
namespace Naneau\FileGen;
3
4
use Naneau\FileGen\Exception as FileGenException;
5
6
use Naneau\FileGen\AccessRights;
7
8
use \Iterator;
9
10
/**
11
 * A directory, that can contain children (other directories, files, symlinks)
12
 */
13
class Directory extends AccessRights implements Iterator
14
{
15
    /**
16
     * Position of the iteration
17
     *
18
     * @var int
19
     **/
20
    private $position = 0;
21
22
    /**
23
     * Child nodes
24
     *
25
     * @var Node[]
26
     **/
27
    private $children = array();
28
29
    /**
30
     * Scan the child nodes for a path
31
     *
32
     * When given a path like `foo/bar/baz`, it will see if directory `foo`
33
     * exists, it has a child directory node `bar`, which should have a child
34
     * node `baz`
35
     *
36
     * Will return either the found child node, or boolean false
37
     *
38
     * @param  string    $path
39
     * @return Node|bool
40
     **/
41
    public function scan($path)
42
    {
43
        // Start scanning at the root (this dir)
44
        $node = $this;
45
46
        foreach (explode(DIRECTORY_SEPARATOR, $path) as $item) {
47
            // For every child dir (starting at lowest level)
48
49
            // Can't find children if $node is not a directory
50
            if (!($node instanceof Directory)) {
51
                return false;
52
            }
53
54
            // If the current node doesn't have the item, $path doesn't exist (fully)
55
            if (!$node->hasChild($item)) {
56
                return false;
57
            }
58
59
            // New parent node
60
            $node = $node->getChild($item);
61
        }
62
63
        return $node;
64
    }
65
66
    /**
67
     * Get the child nodes
68
     *
69
     * @return Node[]
70
     */
71
    public function getChildren()
72
    {
73
        return $this->children;
74
    }
75
76
    /**
77
     * Set the child nodes
78
     *
79
     * @param  Node[]    $children
80
     * @return Directory
81
     */
82
    public function setChildren(array $children)
83
    {
84
        $this->children = $children;
85
86
        return $this;
87
    }
88
89
    /**
90
     * Add a child
91
     *
92
     * @param  Node      $child
93
     * @return Directory
94
     **/
95
    public function addChild(Node $child)
96
    {
97
        $child->setParent($this);
98
99
        $this->children[] = $child;
100
101
        return $this;
102
    }
103
104
    /**
105
     * Does a child with name $name exist?
106
     *
107
     * @param  string $name
108
     * @return bool
109
     **/
110
    public function hasChild($name)
111
    {
112
        foreach ($this as $node) {
113
            if ($node->getName() === $name) {
114
                return true;
115
            }
116
        }
117
118
        return false;
119
    }
120
121
    /**
122
     * Get a child with name $name
123
     *
124
     * @param  string $name
125
     * @return Node
126
     **/
127
    public function getChild($name)
128
    {
129
        foreach ($this as $node) {
130
            if ($node->getName() === $name) {
131
                return $node;
132
            }
133
        }
134
135
        throw new FileGenException(sprintf(
136
            'Node "%s" not found',
137
            $name
138
        ));
139
    }
140
141
    /**
142
     * Rewind iterator
143
     *
144
     * @return void
145
     **/
146
    public function rewind()
147
    {
148
        $this->position = 0;
149
    }
150
151
    /**
152
     * Get current node
153
     *
154
     * @return Node
155
     **/
156
    public function current()
157
    {
158
        return $this->children[$this->position];
159
    }
160
161
    /**
162
     * Get current key
163
     *
164
     * @return int
165
     **/
166
    public function key()
167
    {
168
        return $this->position;
169
    }
170
171
    /**
172
     * Go to next position
173
     *
174
     * @return void
175
     **/
176
    public function next()
177
    {
178
        ++$this->position;
179
    }
180
181
    /**
182
     * Is the iterator in a valid position?
183
     *
184
     * @return bool
185
     **/
186
    public function valid()
187
    {
188
        return isset($this->children[$this->position]);
189
    }
190
}
191