Completed
Pull Request — develop (#91)
by Jaap
04:27
created

Class_::getDocBlock()   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
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
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
19
/**
20
 * Descriptor representing a Class.
21
 */
22
// @codingStandardsIgnoreStart
23
final class Class_ implements Element
24
// @codingStandardsIgnoreEnd
25
{
26
    /**
27
     * @var Fqsen Full Qualified Structural Element Name
28
     */
29
    private $fqsen;
30
31
    /**
32
     * @var DocBlock|null
33
     */
34
    private $docBlock = null;
35
36
    /** @var boolean $abstract Whether this is an abstract class. */
37
    private $abstract = false;
38
39
    /** @var boolean $final Whether this class is marked as final and can't be subclassed. */
40
    private $final = false;
41
42
    /**
43
     * @var Class_ $parent The class this class is extending.
44
     */
45
    private $parent = null;
46
47
    /** @var Fqsen[] $implements References to interfaces that are implemented by this class. */
48
    private $implements = array();
49
50
    /** @var Constant[] $constants References to constants defined in this class. */
51
    private $constants = array();
52
53
    /** @var Property[] $properties References to properties defined in this class. */
54
    private $properties = array();
55
56
    /** @var Method[] $methods References to methods defined in this class. */
57
    private $methods = array();
58
59
    /** @var Fqsen[] $usedTraits References to traits consumed by this class */
60
    private $usedTraits = array();
61
62
    /**
63
     * Initializes a number of properties with the given values. Others are initialized by definition.
64
     *
65
     * @param Fqsen $fqsen
66
     * @param DocBlock $docBlock
67
     * @param Fqsen $parent
68
     * @param bool $abstract
69
     * @param bool $final
70
     */
71 3
    public function __construct(
72
        Fqsen $fqsen,
73
        DocBlock $docBlock = null,
74
        Fqsen $parent = null,
75
        $abstract = false,
76
        $final = false
77
    ) {
78 3
        $this->fqsen = $fqsen;
79 3
        $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...
80 3
        $this->docBlock = $docBlock;
81 3
        $this->abstract = $abstract;
82 3
        $this->final = $final;
83 3
    }
84
85
    /**
86
     * Returns true when this class is final. Otherwise returns false.
87
     *
88
     * @return bool
89
     */
90 1
    public function isFinal()
91
    {
92 1
        return $this->final;
93
    }
94
95
    /**
96
     * Returns true when this class is abstract. Otherwise returns false.
97
     *
98
     * @return bool
99
     */
100 1
    public function isAbstract()
101
    {
102 1
        return $this->abstract;
103
    }
104
105
    /**
106
     * Returns the superclass this class is extending if available.
107
     *
108
     * @return NUll|Fqsen
109
     */
110 1
    public function getParent()
111
    {
112 1
        return $this->parent;
113
    }
114
115
    /**
116
     * Returns the interfaces this class is implementing.
117
     *
118
     * @return Fqsen[]
119
     */
120 1
    public function getInterfaces()
121
    {
122 1
        return $this->implements;
123
    }
124
125
    /**
126
     * Add a interface Fqsen this class is implementing.
127
     *
128
     * @param Fqsen $interface
129
     * @return void
130
     */
131 1
    public function addInterface(Fqsen $interface)
132
    {
133 1
        $this->implements[(string)$interface] = $interface;
134 1
    }
135
136
    /**
137
     * Returns the constants of this class.
138
     *
139
     * @return Constant[]
140
     */
141 1
    public function getConstants()
142
    {
143 1
        return $this->constants;
144
    }
145
146
    /**
147
     * Add Constant to this class.
148
     *
149
     * @param Constant $constant
150
     * @return void
151
     */
152 1
    public function addConstant(Constant $constant)
153
    {
154 1
        $this->constants[(string)$constant->getFqsen()] = $constant;
155 1
    }
156
157
    /**
158
     * Returns the methods of this class.
159
     *
160
     * @return Method[]
161
     */
162 1
    public function getMethods()
163
    {
164 1
        return $this->methods;
165
    }
166
167
    /**
168
     * Add a method to this class.
169
     *
170
     * @param Method $method
171
     * @return void
172
     */
173 1
    public function addMethod(Method $method)
174
    {
175 1
        $this->methods[(string)$method->getFqsen()] = $method;
176 1
    }
177
178
    /**
179
     * Returns the properties of this class.
180
     *
181
     * @return Property[]
182
     */
183 1
    public function getProperties()
184
    {
185 1
        return $this->properties;
186
    }
187
188
    /**
189
     * Add a property to this class.
190
     *
191
     * @param Property $property
192
     * @return void
193
     */
194 1
    public function addProperty(Property $property)
195
    {
196 1
        $this->properties[(string)$property->getFqsen()] = $property;
197 1
    }
198
199
    /**
200
     * Returns the traits used by this class.
201
     *
202
     * @return Fqsen[]
203
     */
204 1
    public function getUsedTraits()
205
    {
206 1
        return $this->usedTraits;
207
    }
208
209
    /**
210
     * Add trait fqsen used by this class.
211
     *
212
     * @param Fqsen $fqsen
213
     */
214 1
    public function addUsedTrait(Fqsen $fqsen)
215
    {
216 1
        $this->usedTraits[(string)$fqsen] = $fqsen;
217 1
    }
218
219
    /**
220
     * Returns the Fqsen of the element.
221
     *
222
     * @return Fqsen
223
     */
224
    public function getFqsen()
225
    {
226
        return $this->fqsen;
227
    }
228
229
    /**
230
     * Returns the name of the element.
231
     *
232
     * @return string
233
     */
234
    public function getName()
235
    {
236
        return $this->fqsen->getName();
237
    }
238
239
    /**
240
     * @returns null|DocBlock
241
     */
242
    public function getDocBlock()
243
    {
244
        return $this->docBlock;
245
    }
246
}
247