Completed
Push — develop ( 4fc097...cb6ec7 )
by Jaap
01:50
created

Class_::getLocation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * This file is part of phpDocumentor.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @copyright 2010-2015 Mike van Riel<[email protected]>
9
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
10
 * @link      http://phpdoc.org
11
 */
12
13
namespace phpDocumentor\Reflection\Php;
14
15
use phpDocumentor\Reflection\DocBlock;
16
use phpDocumentor\Reflection\Element;
17
use phpDocumentor\Reflection\Fqsen;
18
use phpDocumentor\Reflection\Location;
19
20
/**
21
 * Descriptor representing a Class.
22
 */
23
// @codingStandardsIgnoreStart
24
final class Class_ implements Element
25
// @codingStandardsIgnoreEnd
26
{
27
    /**
28
     * @var Fqsen Full Qualified Structural Element Name
29
     */
30
    private $fqsen;
31
32
    /**
33
     * @var DocBlock|null
34
     */
35
    private $docBlock = null;
36
37
    /** @var boolean $abstract Whether this is an abstract class. */
38
    private $abstract = false;
39
40
    /** @var boolean $final Whether this class is marked as final and can't be subclassed. */
41
    private $final = false;
42
43
    /**
44
     * @var Class_ $parent The class this class is extending.
45
     */
46
    private $parent = null;
47
48
    /** @var Fqsen[] $implements References to interfaces that are implemented by this class. */
49
    private $implements = array();
50
51
    /** @var Constant[] $constants References to constants defined in this class. */
52
    private $constants = array();
53
54
    /** @var Property[] $properties References to properties defined in this class. */
55
    private $properties = array();
56
57
    /** @var Method[] $methods References to methods defined in this class. */
58
    private $methods = array();
59
60
    /** @var Fqsen[] $usedTraits References to traits consumed by this class */
61
    private $usedTraits = array();
62
63
    /**
64
     * @var null|Location
65
     */
66
    private $location;
67
68
    /**
69
     * Initializes a number of properties with the given values. Others are initialized by definition.
70
     *
71 3
     * @param Fqsen $fqsen
72
     * @param DocBlock $docBlock
73
     * @param Fqsen $parent
74
     * @param bool $abstract
75
     * @param bool $final
76
     * @param Location|null $location
77
     */
78 3
    public function __construct(
79 3
        Fqsen $fqsen,
80 3
        DocBlock $docBlock = null,
81 3
        Fqsen $parent = null,
82 3
        $abstract = false,
83 3
        $final = false,
84
        Location $location = null
85
    ) {
86
        if ($location === null) {
87
            $location = new Location(-1);
88
        }
89
90 1
        $this->fqsen = $fqsen;
91
        $this->parent = $parent;
0 ignored issues
show
Documentation Bug introduced by
It seems like $parent can also be of type object<phpDocumentor\Reflection\Fqsen>. However, the property $parent is declared as type object<phpDocumentor\Reflection\Php\Class_>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
92 1
        $this->docBlock = $docBlock;
93
        $this->abstract = $abstract;
94
        $this->final = $final;
95
        $this->location = $location;
96
    }
97
98
    /**
99
     * Returns true when this class is final. Otherwise returns false.
100 1
     *
101
     * @return bool
102 1
     */
103
    public function isFinal()
104
    {
105
        return $this->final;
106
    }
107
108
    /**
109
     * Returns true when this class is abstract. Otherwise returns false.
110 1
     *
111
     * @return bool
112 1
     */
113
    public function isAbstract()
114
    {
115
        return $this->abstract;
116
    }
117
118
    /**
119
     * Returns the superclass this class is extending if available.
120 1
     *
121
     * @return NUll|Fqsen
122 1
     */
123
    public function getParent()
124
    {
125
        return $this->parent;
126
    }
127
128
    /**
129
     * Returns the interfaces this class is implementing.
130
     *
131 1
     * @return Fqsen[]
132
     */
133 1
    public function getInterfaces()
134 1
    {
135
        return $this->implements;
136
    }
137
138
    /**
139
     * Add a interface Fqsen this class is implementing.
140
     *
141 1
     * @param Fqsen $interface
142
     * @return void
143 1
     */
144
    public function addInterface(Fqsen $interface)
145
    {
146
        $this->implements[(string)$interface] = $interface;
147
    }
148
149
    /**
150
     * Returns the constants of this class.
151
     *
152 1
     * @return Constant[]
153
     */
154 1
    public function getConstants()
155 1
    {
156
        return $this->constants;
157
    }
158
159
    /**
160
     * Add Constant to this class.
161
     *
162 1
     * @param Constant $constant
163
     * @return void
164 1
     */
165
    public function addConstant(Constant $constant)
166
    {
167
        $this->constants[(string)$constant->getFqsen()] = $constant;
168
    }
169
170
    /**
171
     * Returns the methods of this class.
172
     *
173 1
     * @return Method[]
174
     */
175 1
    public function getMethods()
176 1
    {
177
        return $this->methods;
178
    }
179
180
    /**
181
     * Add a method to this class.
182
     *
183 1
     * @param Method $method
184
     * @return void
185 1
     */
186
    public function addMethod(Method $method)
187
    {
188
        $this->methods[(string)$method->getFqsen()] = $method;
189
    }
190
191
    /**
192
     * Returns the properties of this class.
193
     *
194 1
     * @return Property[]
195
     */
196 1
    public function getProperties()
197 1
    {
198
        return $this->properties;
199
    }
200
201
    /**
202
     * Add a property to this class.
203
     *
204 1
     * @param Property $property
205
     * @return void
206 1
     */
207
    public function addProperty(Property $property)
208
    {
209
        $this->properties[(string)$property->getFqsen()] = $property;
210
    }
211
212
    /**
213
     * Returns the traits used by this class.
214 1
     *
215
     * @return Fqsen[]
216 1
     */
217 1
    public function getUsedTraits()
218
    {
219
        return $this->usedTraits;
220
    }
221
222
    /**
223
     * Add trait fqsen used by this class.
224
     *
225
     * @param Fqsen $fqsen
226
     */
227
    public function addUsedTrait(Fqsen $fqsen)
228
    {
229
        $this->usedTraits[(string)$fqsen] = $fqsen;
230
    }
231
232
    /**
233
     * Returns the Fqsen of the element.
234
     *
235
     * @return Fqsen
236
     */
237
    public function getFqsen()
238
    {
239
        return $this->fqsen;
240
    }
241
242
    /**
243
     * Returns the name of the element.
244
     *
245
     * @return string
246
     */
247
    public function getName()
248
    {
249
        return $this->fqsen->getName();
250
    }
251
252
    /**
253
     * @returns null|DocBlock
254
     */
255
    public function getDocBlock()
256
    {
257
        return $this->docBlock;
258
    }
259
260
    /**
261
     * @return null|Location
262
     */
263
    public function getLocation()
264
    {
265
        return $this->location;
266
    }
267
}
268