Completed
Push — develop ( 4b49c4...89d32a )
by Jaap
09:06 queued 05:30
created

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

Labels
Severity

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 4
    public function __construct($hash)
58
    {
59 4
        parent::__construct();
60
61 4
        $this->setHash($hash);
62 4
        $this->setNamespaceAliases(new Collection());
63 4
        $this->setIncludes(new Collection());
64
65 4
        $this->setConstants(new Collection());
66 4
        $this->setFunctions(new Collection());
67 4
        $this->setClasses(new Collection());
68 4
        $this->setInterfaces(new Collection());
69 4
        $this->setTraits(new Collection());
70
71 4
        $this->setMarkers(new Collection());
72 4
    }
73
74
    /**
75
     * Returns the hash of the contents for this file.
76
     *
77
     * @return string
78
     */
79 1
    public function getHash()
80
    {
81 1
        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 1
    public function getSource()
102
    {
103 1
        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 1
    public function setSource($source)
114
    {
115 1
        $this->source = $source;
116 1
    }
117
118
    /**
119
     * Returns the namespace aliases that have been defined in this file.
120
     *
121
     * @return Collection
122
     */
123 1
    public function getNamespaceAliases()
124
    {
125 1
        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 1
    public function setNamespaceAliases(Collection $namespaceAliases)
136
    {
137 1
        $this->namespaceAliases = $namespaceAliases;
138 1
    }
139
140
    /**
141
     * Returns a list of all includes that have been declared in this file.
142
     *
143
     * @return Collection
144
     */
145 1
    public function getIncludes()
146
    {
147 1
        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 1
    public function setIncludes(Collection $includes)
158
    {
159 1
        $this->includes = $includes;
160 1
    }
161
162
    /**
163
     * Returns a list of constant descriptors contained in this file.
164
     *
165
     * @return Collection
166
     */
167 1
    public function getConstants()
168
    {
169 1
        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 1
    public function setConstants(Collection $constants)
180
    {
181 1
        $this->constants = $constants;
182 1
    }
183
184
    /**
185
     * Returns a list of function descriptors contained in this file.
186
     *
187
     * @return Collection|FunctionInterface[]
188
     */
189 1
    public function getFunctions()
190
    {
191 1
        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 1
    public function setFunctions(Collection $functions)
202
    {
203 1
        $this->functions = $functions;
204 1
    }
205
206
    /**
207
     * Returns a list of class descriptors contained in this file.
208
     *
209
     * @return Collection|ClassInterface[]
210
     */
211 1
    public function getClasses()
212
    {
213 1
        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 1
    public function setClasses(Collection $classes)
224
    {
225 1
        $this->classes = $classes;
226 1
    }
227
228
    /**
229
     * Returns a list of interface descriptors contained in this file.
230
     *
231
     * @return Collection|InterfaceInterface[]
232
     */
233 1
    public function getInterfaces()
234
    {
235 1
        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 1
    public function setInterfaces(Collection $interfaces)
246
    {
247 1
        $this->interfaces = $interfaces;
248 1
    }
249
250
    /**
251
     * Returns a list of trait descriptors contained in this file.
252
     *
253
     * @return Collection|TraitInterface[]
254
     */
255 1
    public function getTraits()
256
    {
257 1
        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 1
    public function setTraits(Collection $traits)
268
    {
269 1
        $this->traits = $traits;
270 1
    }
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 1
    public function getMarkers()
285
    {
286 1
        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 1
    public function setMarkers(Collection $markers)
299
    {
300 1
        $this->markers = $markers;
301 1
    }
302
303
    /**
304
     * Returns a list of all errors in this file and all its child elements.
305
     *
306
     * @return Collection
307
     */
308 2
    public function getAllErrors()
309
    {
310 2
        $errors = $this->getErrors();
311
312 2
        $types = $this->getClasses()->merge($this->getInterfaces())->merge($this->getTraits());
0 ignored issues
show
It seems like $this->getInterfaces() targeting phpDocumentor\Descriptor...riptor::getInterfaces() can also be of type array<integer,object<php...or\InterfaceInterface>>; however, phpDocumentor\Descriptor\Collection::merge() does only seem to accept object<phpDocumentor\Descriptor\Collection>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
313
314 2
        $elements = $this->getFunctions()->merge($this->getConstants())->merge($types);
315
316 2
        foreach ($elements as $element) {
317 1
            if (!$element) {
318
                continue;
319
            }
320
321 1
            $errors = $errors->merge($element->getErrors());
322
        }
323
324 2
        foreach ($types as $element) {
325 1
            if (!$element) {
326
                continue;
327
            }
328
329 1
            foreach ($element->getMethods() as $item) {
330 1
                if (!$item) {
331
                    continue;
332
                }
333 1
                $errors = $errors->merge($item->getErrors());
334
            }
335
336 1
            if (method_exists($element, 'getConstants')) {
337 1
                foreach ($element->getConstants() as $item) {
338 1
                    if (!$item) {
339
                        continue;
340
                    }
341 1
                    $errors = $errors->merge($item->getErrors());
342
                }
343
            }
344
345 1
            if (method_exists($element, 'getProperties')) {
346 1
                foreach ($element->getProperties() as $item) {
347 1
                    if (!$item) {
348
                        continue;
349
                    }
350 1
                    $errors = $errors->merge($item->getErrors());
351
                }
352
            }
353
        }
354
355 2
        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 1
    public function setPath($path)
366
    {
367 1
        $this->path = $path;
368 1
    }
369
370
    /**
371
     * Returns the file path relative to the project's root.
372
     *
373
     * @return string
374
     */
375 1
    public function getPath()
376
    {
377 1
        return $this->path;
378
    }
379
}
380