Completed
Push — develop ( 49ed8e...8c2a0b )
by Jaap
09:55
created

src/phpDocumentor/Descriptor/FileDescriptor.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * phpDocumentor
4
 *
5
 * PHP Version 5.3
6
 *
7
 * @copyright 2010-2014 Mike van Riel / Naenius (http://www.naenius.com)
8
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
9
 * @link      http://phpdoc.org
10
 */
11
12
namespace phpDocumentor\Descriptor;
13
14
/**
15
 * Represents a file in the project.
16
 */
17
class FileDescriptor extends DescriptorAbstract implements Interfaces\FileInterface
18
{
19
    /** @var string $hash */
20
    protected $hash;
21
22
    /** @var string $path */
23
    protected $path = '';
24
25
    /** @var string|null $source */
26
    protected $source = null;
27
28
    /** @var Collection $namespaceAliases */
29
    protected $namespaceAliases;
30
31
    /** @var Collection $includes */
32
    protected $includes;
33
34
    /** @var Collection $constants */
35
    protected $constants;
36
37
    /** @var Collection $functions */
38
    protected $functions;
39
40
    /** @var Collection $classes */
41
    protected $classes;
42
43
    /** @var Collection $interfaces */
44
    protected $interfaces;
45
46
    /** @var Collection $traits */
47
    protected $traits;
48
49
    /** @var Collection $markers */
50
    protected $markers;
51
52
    /**
53
     * Initializes a new file descriptor with the given hash of its contents.
54
     *
55
     * @param string $hash An MD5 hash of the contents if this file.
56
     */
57
    public function __construct($hash)
58
    {
59
        parent::__construct();
60
61
        $this->setHash($hash);
62
        $this->setNamespaceAliases(new Collection());
63
        $this->setIncludes(new Collection());
64
65
        $this->setConstants(new Collection());
66
        $this->setFunctions(new Collection());
67
        $this->setClasses(new Collection());
68
        $this->setInterfaces(new Collection());
69
        $this->setTraits(new Collection());
70
71
        $this->setMarkers(new Collection());
72
    }
73
74
    /**
75
     * Returns the hash of the contents for this file.
76
     *
77
     * @return string
78
     */
79
    public function getHash()
80
    {
81
        return $this->hash;
82
    }
83
84
    /**
85
     * Sets the hash of the contents for this file.
86
     *
87
     * @param string $hash
88
     *
89
     * @return void
90
     */
91
    protected function setHash($hash)
92
    {
93
        $this->hash = $hash;
94
    }
95
96
    /**
97
     * Retrieves the contents of this file.
98
     *
99
     * @return string|null
100
     */
101
    public function getSource()
102
    {
103
        return $this->source;
104
    }
105
106
    /**
107
     * Sets the source contents for this file.
108
     *
109
     * @param string|null $source
110
     *
111
     * @return void
112
     */
113
    public function setSource($source)
114
    {
115
        $this->source = $source;
116
    }
117
118
    /**
119
     * Returns the namespace aliases that have been defined in this file.
120
     *
121
     * @return Collection
122
     */
123
    public function getNamespaceAliases()
124
    {
125
        return $this->namespaceAliases;
126
    }
127
128
    /**
129
     * Sets the collection of namespace aliases for this file.
130
     *
131
     * @param Collection $namespaceAliases
132
     *
133
     * @return void
134
     */
135
    public function setNamespaceAliases(Collection $namespaceAliases)
136
    {
137
        $this->namespaceAliases = $namespaceAliases;
138
    }
139
140
    /**
141
     * Returns a list of all includes that have been declared in this file.
142
     *
143
     * @return Collection
144
     */
145
    public function getIncludes()
146
    {
147
        return $this->includes;
148
    }
149
150
    /**
151
     * Sets a list of all includes that have been declared in this file.
152
     *
153
     * @param Collection $includes
154
     *
155
     * @return void
156
     */
157
    public function setIncludes(Collection $includes)
158
    {
159
        $this->includes = $includes;
160
    }
161
162
    /**
163
     * Returns a list of constant descriptors contained in this file.
164
     *
165
     * @return Collection
166
     */
167
    public function getConstants()
168
    {
169
        return $this->constants;
170
    }
171
172
    /**
173
     * Sets a list of constant descriptors contained in this file.
174
     *
175
     * @param Collection $constants
176
     *
177
     * @return void
178
     */
179
    public function setConstants(Collection $constants)
180
    {
181
        $this->constants = $constants;
182
    }
183
184
    /**
185
     * Returns a list of function descriptors contained in this file.
186
     *
187
     * @return Collection|FunctionInterface[]
188
     */
189
    public function getFunctions()
190
    {
191
        return $this->functions;
192
    }
193
194
    /**
195
     * Sets a list of function descriptors contained in this file.
196
     *
197
     * @param Collection $functions
198
     *
199
     * @return void
200
     */
201
    public function setFunctions(Collection $functions)
202
    {
203
        $this->functions = $functions;
204
    }
205
206
    /**
207
     * Returns a list of class descriptors contained in this file.
208
     *
209
     * @return Collection|ClassInterface[]
210
     */
211
    public function getClasses()
212
    {
213
        return $this->classes;
214
    }
215
216
    /**
217
     * Sets a list of class descriptors contained in this file.
218
     *
219
     * @param Collection $classes
220
     *
221
     * @return void
222
     */
223
    public function setClasses(Collection $classes)
224
    {
225
        $this->classes = $classes;
226
    }
227
228
    /**
229
     * Returns a list of interface descriptors contained in this file.
230
     *
231
     * @return Collection|InterfaceInterface[]
232
     */
233
    public function getInterfaces()
234
    {
235
        return $this->interfaces;
236
    }
237
238
    /**
239
     * Sets a list of interface descriptors contained in this file.
240
     *
241
     * @param Collection $interfaces
242
     *
243
     * @return void
244
     */
245
    public function setInterfaces(Collection $interfaces)
246
    {
247
        $this->interfaces = $interfaces;
248
    }
249
250
    /**
251
     * Returns a list of trait descriptors contained in this file.
252
     *
253
     * @return Collection|TraitInterface[]
254
     */
255
    public function getTraits()
256
    {
257
        return $this->traits;
258
    }
259
260
    /**
261
     * Sets a list of trait descriptors contained in this file.
262
     *
263
     * @param Collection $traits
264
     *
265
     * @return void
266
     */
267
    public function setTraits(Collection $traits)
268
    {
269
        $this->traits = $traits;
270
    }
271
272
    /**
273
     * Returns a series of markers contained in this file.
274
     *
275
     * A marker is a special inline comment that starts with a keyword and is followed by a single line description.
276
     *
277
     * Example:
278
     * ```
279
     * // TODO: This is an item that needs to be done.
280
     * ```
281
     *
282
     * @return Collection
283
     */
284
    public function getMarkers()
285
    {
286
        return $this->markers;
287
    }
288
289
    /**
290
     * Sets a series of markers contained in this file.
291
     *
292
     * @param Collection $markers
293
     *
294
     * @see getMarkers() for more information on markers.
295
     *
296
     * @return void
297
     */
298
    public function setMarkers(Collection $markers)
299
    {
300
        $this->markers = $markers;
301
    }
302
303
    /**
304
     * Returns a list of all errors in this file and all its child elements.
305
     *
306
     * @return Collection
307
     */
308
    public function getAllErrors()
0 ignored issues
show
This operation has 291 execution paths which exceeds the configured maximum of 200.

A high number of execution paths generally suggests many nested conditional statements and make the code less readible. This can usually be fixed by splitting the method into several smaller methods.

You can also find more information in the “Code” section of your repository.

Loading history...
309
    {
310
        $errors = $this->getErrors();
311
312
        $types = $this->getClasses()->merge($this->getInterfaces())->merge($this->getTraits());
313
314
        $elements = $this->getFunctions()->merge($this->getConstants())->merge($types);
315
316
        foreach ($elements as $element) {
317
            if (!$element) {
318
                continue;
319
            }
320
321
            $errors = $errors->merge($element->getErrors());
322
        }
323
324
        foreach ($types as $element) {
325
            if (!$element) {
326
                continue;
327
            }
328
329
            foreach ($element->getMethods() as $item) {
330
                if (!$item) {
331
                    continue;
332
                }
333
                $errors = $errors->merge($item->getErrors());
334
            }
335
336
            if (method_exists($element, 'getConstants')) {
337
                foreach ($element->getConstants() as $item) {
338
                    if (!$item) {
339
                        continue;
340
                    }
341
                    $errors = $errors->merge($item->getErrors());
342
                }
343
            }
344
345
            if (method_exists($element, 'getProperties')) {
346
                foreach ($element->getProperties() as $item) {
347
                    if (!$item) {
348
                        continue;
349
                    }
350
                    $errors = $errors->merge($item->getErrors());
351
                }
352
            }
353
        }
354
355
        return $errors;
356
    }
357
358
    /**
359
     * Sets the file path for this file relative to the project's root.
360
     *
361
     * @param string $path
362
     *
363
     * @return void
364
     */
365
    public function setPath($path)
366
    {
367
        $this->path = $path;
368
    }
369
370
    /**
371
     * Returns the file path relative to the project's root.
372
     *
373
     * @return string
374
     */
375
    public function getPath()
376
    {
377
        return $this->path;
378
    }
379
}
380