File   A
last analyzed

Complexity

Total Complexity 20

Size/Duplication

Total Lines 239
Duplicated Lines 0 %

Coupling/Cohesion

Components 7
Dependencies 5

Test Coverage

Coverage 96.15%

Importance

Changes 0
Metric Value
dl 0
loc 239
rs 10
c 0
b 0
f 0
ccs 50
cts 52
cp 0.9615
wmc 20
lcom 7
cbo 5

20 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getHash() 0 4 1
A getSource() 0 4 1
A getNamespaces() 0 4 1
A addNamespace() 0 4 1
A getIncludes() 0 4 1
A addInclude() 0 4 1
A getConstants() 0 4 1
A addConstant() 0 4 1
A getFunctions() 0 4 1
A addFunction() 0 4 1
A getClasses() 0 4 1
A addClass() 0 4 1
A getInterfaces() 0 4 1
A addInterface() 0 4 1
A getTraits() 0 4 1
A addTrait() 0 4 1
A getPath() 0 4 1
A getDocBlock() 0 4 1
A getName() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * This file is part of phpDocumentor.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @copyright 2010-2018 Mike van Riel<[email protected]>
11
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
12
 * @link      http://phpdoc.org
13
 */
14
15
namespace phpDocumentor\Reflection\Php;
16
17
use phpDocumentor\Reflection\DocBlock;
18
use phpDocumentor\Reflection\Fqsen;
19
20
/**
21
 * Represents a file in the project.
22
 */
23
final class File
24
{
25
    /**
26
     * @var DocBlock|null
27
     */
28
    private $docBlock = null;
29
30
    /**
31
     * @var string
32
     */
33
    private $hash;
34
35
    /**
36
     * @var string
37
     */
38
    private $name = null;
39
40
    /**
41
     * @var string
42
     */
43
    private $path = null;
44
45
    /**
46
     * @var string
47
     */
48
    private $source = null;
49
50
    /**
51
     * @var Fqsen[]
52
     */
53
    private $namespaces = [];
54
55
    /**
56
     * @var string[]
57
     */
58
    private $includes = [];
59
60
    /**
61
     * @var Function_[]
62
     */
63
    private $functions = [];
64
65
    /**
66
     * @var Constant[]
67
     */
68
    private $constants = [];
69
70
    /**
71
     * @var Class_[]
72
     */
73
    private $classes = [];
74
75
    /**
76
     * @var Interface_[]
77
     */
78
    private $interfaces = [];
79
80
    /**
81
     * @var Trait_[]
82
     */
83
    private $traits = [];
84
85
    /**
86
     * Initializes a new file descriptor with the given hash of its contents.
87
     *
88
     * @param string $hash An MD5 hash of the contents if this file.
89
     */
90 7
    public function __construct(string $hash, string $path, string $source = '', ?DocBlock $docBlock = null)
91
    {
92 7
        $this->hash = $hash;
93 7
        $this->path = $path;
94 7
        $this->name = basename($path);
95 7
        $this->source = $source;
96 7
        $this->docBlock = $docBlock;
97 7
    }
98
99
    /**
100
     * Returns the hash of the contents for this file.
101
     */
102 1
    public function getHash(): string
103
    {
104 1
        return $this->hash;
105
    }
106
107
    /**
108
     * Retrieves the contents of this file.
109
     */
110 1
    public function getSource(): string
111
    {
112 1
        return $this->source;
113
    }
114
115
    /**
116
     * Returns the namespace fqsens that have been defined in this file.
117
     *
118
     * @return Fqsen[]
119
     */
120 1
    public function getNamespaces(): array
121
    {
122 1
        return $this->namespaces;
123
    }
124
125
    /**
126
     * Add namespace to file
127
     */
128 1
    public function addNamespace(Fqsen $fqsen): void
129
    {
130 1
        $this->namespaces[(string) $fqsen] = $fqsen;
131 1
    }
132
133
    /**
134
     * Returns a list of all includes that have been declared in this file.
135
     *
136
     * @return string[]
137
     */
138 1
    public function getIncludes(): array
139
    {
140 1
        return $this->includes;
141
    }
142
143 1
    public function addInclude(string $include): void
144
    {
145 1
        $this->includes[$include] = $include;
146 1
    }
147
148
    /**
149
     * Returns a list of constant descriptors contained in this file.
150
     *
151
     * @return Constant[]
152
     */
153 1
    public function getConstants(): array
154
    {
155 1
        return $this->constants;
156
    }
157
158
    /**
159
     * Add constant to this file.
160
     */
161 1
    public function addConstant(Constant $constant): void
162
    {
163 1
        $this->constants[(string) $constant->getFqsen()] = $constant;
164 1
    }
165
166
    /**
167
     * Returns a list of function descriptors contained in this file.
168
     *
169
     * @return Function_[]
170
     */
171 1
    public function getFunctions(): array
172
    {
173 1
        return $this->functions;
174
    }
175
176
    /**
177
     * Add function to this file.
178
     */
179 1
    public function addFunction(Function_ $function): void
180
    {
181 1
        $this->functions[(string) $function->getFqsen()] = $function;
182 1
    }
183
184
    /**
185
     * Returns a list of class descriptors contained in this file.
186
     *
187
     * @return Class_[]
188
     */
189 1
    public function getClasses(): array
190
    {
191 1
        return $this->classes;
192
    }
193
194
    /**
195
     * Add Class to this file.
196
     */
197 1
    public function addClass(Class_ $class): void
198
    {
199 1
        $this->classes[(string) $class->getFqsen()] = $class;
200 1
    }
201
202
    /**
203
     * Returns a list of interface descriptors contained in this file.
204
     *
205
     * @return Interface_[]
206
     */
207 1
    public function getInterfaces(): array
208
    {
209 1
        return $this->interfaces;
210
    }
211
212
    /**
213
     * Add interface to this file.
214
     */
215 1
    public function addInterface(Interface_ $interface): void
216
    {
217 1
        $this->interfaces[(string) $interface->getFqsen()] = $interface;
218 1
    }
219
220
    /**
221
     * Returns a list of trait descriptors contained in this file.
222
     *
223
     * @return Trait_[]
224
     */
225 1
    public function getTraits(): array
226
    {
227 1
        return $this->traits;
228
    }
229
230
    /**
231
     * Add trait to this file.
232
     */
233 1
    public function addTrait(Trait_ $trait): void
234
    {
235 1
        $this->traits[(string) $trait->getFqsen()] = $trait;
236 1
    }
237
238
    /**
239
     * Returns the file path relative to the project's root.
240
     */
241 1
    public function getPath(): string
242
    {
243 1
        return $this->path;
244
    }
245
246
    /**
247
     * Returns the DocBlock of the element if available
248
     */
249 1
    public function getDocBlock(): ?DocBlock
250
    {
251 1
        return $this->docBlock;
252
    }
253
254
    /**
255
     * Returns the full name of this file
256
     */
257
    public function getName(): string
258
    {
259
        return $this->name;
260
    }
261
}
262