Trait_::getUsedTraits()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 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\Element;
19
use phpDocumentor\Reflection\Fqsen;
20
use phpDocumentor\Reflection\Location;
21
22
/**
23
 * Descriptor representing a Trait.
24
 */
25
// @codingStandardsIgnoreStart
26
final class Trait_ implements Element
27
// @codingStandardsIgnoreEnd
28
{
29
    /**
30
     * @var Fqsen Full Qualified Structural Element Name
31
     */
32
    private $fqsen;
33
34
    /**
35
     * @var DocBlock|null
36
     */
37
    private $docBlock;
38
39
    /** @var Property[] $properties */
40
    private $properties = [];
41
42
    /** @var Method[] $methods */
43
    private $methods = [];
44
45
    /** @var Fqsen[] $usedTraits References to traits consumed by this trait */
46
    private $usedTraits = [];
47
48
    /**
49
     * @var Location
50
     */
51
    private $location;
52
53
    /**
54
     * Initializes the all properties
55
     */
56 2
    public function __construct(Fqsen $fqsen, ?DocBlock $docBlock = null, ?Location $location = null)
57
    {
58 2
        if ($location === null) {
59 2
            $location = new Location(-1);
60
        }
61
62 2
        $this->fqsen = $fqsen;
63 2
        $this->docBlock = $docBlock;
64 2
        $this->location = $location;
65 2
    }
66
67
    /**
68
     * Returns the methods of this Trait.
69
     *
70
     * @return Method[]
71
     */
72 1
    public function getMethods(): array
73
    {
74 1
        return $this->methods;
75
    }
76
77
    /**
78
     * Add a method to this Trait
79
     */
80 1
    public function addMethod(Method $method): void
81
    {
82 1
        $this->methods[(string) $method->getFqsen()] = $method;
83 1
    }
84
85
    /**
86
     * Returns the properties of this trait.
87
     *
88
     * @return Property[]
89
     */
90 1
    public function getProperties(): array
91
    {
92 1
        return $this->properties;
93
    }
94
95
    /**
96
     * Add a property to this Trait.
97
     */
98 1
    public function addProperty(Property $property): void
99
    {
100 1
        $this->properties[(string) $property->getFqsen()] = $property;
101 1
    }
102
103
    /**
104
     * Returns the Fqsen of the element.
105
     */
106 1
    public function getFqsen(): Fqsen
107
    {
108 1
        return $this->fqsen;
109
    }
110
111
    /**
112
     * Returns the name of the element.
113
     */
114 1
    public function getName(): string
115
    {
116 1
        return $this->fqsen->getName();
117
    }
118
119 1
    public function getDocBlock(): ?DocBlock
120
    {
121 1
        return $this->docBlock;
122
    }
123
124
    /**
125
     * Returns fqsen of all traits used by this trait.
126
     *
127
     * @return Fqsen[]
128
     */
129 1
    public function getUsedTraits(): array
130
    {
131 1
        return $this->usedTraits;
132
    }
133
134
    /**
135
     * Add reference to trait used by this trait.
136
     */
137 1
    public function addUsedTrait(Fqsen $fqsen): void
138
    {
139 1
        $this->usedTraits[(string) $fqsen] = $fqsen;
140 1
    }
141
142
    public function getLocation(): Location
143
    {
144
        return $this->location;
145
    }
146
}
147