Completed
Push — develop ( 66de6a...7afc9d )
by Jaap
04:46 queued 03:01
created

Method::__construct()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 32
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 23
nc 8
nop 8
dl 0
loc 32
ccs 16
cts 16
cp 1
crap 4
rs 8.5806
c 1
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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\Fqsen;
17
use phpDocumentor\Reflection\Element;
18
use phpDocumentor\Reflection\Location;
19
use phpDocumentor\Reflection\Php\Visibility;
20
use phpDocumentor\Reflection\Type;
21
use phpDocumentor\Reflection\Types\Mixed_;
22
23
/**
24
 * Descriptor representing a Method in a Class, Interface or Trait.
25
 */
26
final class Method implements Element
0 ignored issues
show
Complexity introduced by
The class Method has a coupling between objects value of 13. Consider to reduce the number of dependencies under 13.
Loading history...
27
{
28
    /**
29
     * @var DocBlock|null documentation of this method.
30
     */
31
    private $docBlock = null;
32
33
    /**
34
     * @var Fqsen Full Qualified Structural Element Name
35
     */
36
    private $fqsen;
37
38
    /** @var bool $abstract */
39
    private $abstract = false;
40
41
    /** @var bool $final */
42
    private $final = false;
43
44
    /** @var bool $static */
45
    private $static = false;
46
47
    /** @var Visibility visibility of this method */
48
    private $visibility = null;
49
50
    /** @var Argument[] */
51
    private $arguments = array();
52
53
    /**
54
     * @var Location
55
     */
56
    private $location;
57
    /**
58
     * @var Type
59
     */
60
    private $returnType;
61
62
    /**
63
     * Initializes the all properties.
64
     *
65
     * @param Fqsen $fqsen
66
     * @param Visibility|null $visibility when null is provided a default 'public' is set.
67
     * @param DocBlock|null $docBlock
68
     * @param bool $abstract
69
     * @param bool $static
70
     * @param bool $final
71
     * @param Location|null $location
72
     * @param Type $returnType
73
     */
74 9
    public function __construct(
75
        Fqsen $fqsen,
76
        Visibility $visibility = null,
77
        DocBlock $docBlock = null,
78
        $abstract = false,
79
        $static = false,
80
        $final = false,
81
        Location $location = null,
82
        Type $returnType = null
83
    ) {
84 9
        $this->fqsen = $fqsen;
85 9
        $this->visibility = $visibility;
86 9
        $this->docBlock = $docBlock;
87
88 9
        if ($this->visibility === null) {
89 3
            $this->visibility = new Visibility('public');
90
        }
91
92 9
        if ($location === null) {
93 9
            $location = new Location(-1);
94
        }
95
96 9
        if ($returnType ===  null) {
97 8
            $returnType = new Mixed_();
98
        }
99
100 9
        $this->abstract = $abstract;
101 9
        $this->static = $static;
102 9
        $this->final = $final;
103 9
        $this->location = $location;
104 9
        $this->returnType = $returnType;
105 9
    }
106
107
    /**
108
     * Returns true when this method is abstract. Otherwise returns false.
109
     *
110
     * @return bool
111
     */
112 1
    public function isAbstract()
113
    {
114 1
        return $this->abstract;
115
    }
116
117
    /**
118
     * Returns true when this method is final. Otherwise returns false.
119
     *
120
     * @return bool
121
     */
122 1
    public function isFinal()
123
    {
124 1
        return $this->final;
125
    }
126
127
    /**
128
     * Returns true when this method is static. Otherwise returns false.
129
     *
130
     * @return bool
131
     */
132 1
    public function isStatic()
133
    {
134 1
        return $this->static;
135
    }
136
137
    /**
138
     * Returns the Visibility of this method.
139
     *
140
     * @return Visibility
141
     */
142 2
    public function getVisibility()
143
    {
144 2
        return $this->visibility;
145
    }
146
147
    /**
148
     * Returns the arguments of this method.
149
     *
150
     * @return Argument[]
151
     */
152 1
    public function getArguments()
153
    {
154 1
        return $this->arguments;
155
    }
156
157
158
    /**
159
     * Add new argument to this method.
160
     *
161
     * @param Argument $argument
162
     * @return void
163
     */
164 1
    public function addArgument(Argument $argument)
165
    {
166 1
        $this->arguments[] = $argument;
167 1
    }
168
169
    /**
170
     * Returns the Fqsen of the element.
171
     *
172
     * @return Fqsen
173
     */
174 1
    public function getFqsen()
175
    {
176 1
        return $this->fqsen;
177
    }
178
179
    /**
180
     * Returns the name of the element.
181
     *
182
     * @return string
183
     */
184 1
    public function getName()
185
    {
186 1
        return $this->fqsen->getName();
187
    }
188
189
    /**
190
     * Returns the DocBlock of this method if available.
191
     *
192
     * @returns null|DocBlock
193
     */
194 1
    public function getDocBlock()
195
    {
196 1
        return $this->docBlock;
197
    }
198
199
    /**
200
     * @return Location
201
     */
202
    public function getLocation()
203
    {
204
        return $this->location;
205
    }
206
207
    /**
208
     * Returns the in code defined return type.
209
     *
210
     * Return types are introduced in php 7.0 when your could doesn't have a
211
     * return type defined this method will return Mixed_ by default. The return value of this
212
     * method is not affected by the return tag in your docblock.
213
     *
214
     * @return Type
215
     */
216 2
    public function getReturnType()
217
    {
218 2
        return $this->returnType;
219
    }
220
}
221