Completed
Push — develop ( 9dbd4b...3bc77a )
by Jaap
16s
created

ArgumentDescriptor::getType()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 0
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 3
rs 10
c 0
b 0
f 0
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
 * @author    Mike van Riel <[email protected]>
11
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
12
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
13
 * @link      http://phpdoc.org
14
 */
15
16
namespace phpDocumentor\Descriptor;
17
18
use phpDocumentor\Reflection\Type;
19
20
/**
21
 * Descriptor representing a single Argument of a method or function.
22
 */
23
class ArgumentDescriptor extends DescriptorAbstract implements Interfaces\ArgumentInterface
24
{
25
    /** @var MethodDescriptor $method */
26
    protected $method;
27
28
    /** @var Type|null $type normalized type of this argument */
29
    protected $type = null;
30
31
    /** @var string|null $default the default value for an argument or null if none is provided */
32
    protected $default;
33
34
    /** @var bool $byReference whether the argument passes the parameter by reference instead of by value */
35
    protected $byReference = false;
36
37
    /** @var boolean Determines if this Argument represents a variadic argument */
38
    protected $isVariadic = false;
39
40
    /**
41 1
     * To which method does this argument belong to
42
     */
43 1
    public function setMethod(MethodDescriptor $method)
44 1
    {
45
        $this->method = $method;
46
    }
47
48
    /**
49 1
     * {@inheritDoc}
50
     */
51 1
    public function setType(?Type $type)
52 1
    {
53
        $this->type = $type;
54
    }
55
56
    /**
57 2
     * {@inheritDoc}
58
     */
59 2
    public function getType(): ?Type
60 2
    {
61 1
        if ($this->type === null && $this->getInheritedElement() !== null) {
62
            $this->setType($this->getInheritedElement()->getType());
63
        }
64 2
65
        return $this->type;
66
    }
67
68
    public function getTypes(): array
69
    {
70 1
        trigger_error('Please use getType', E_USER_DEPRECATED);
71
        return [$this->getType()];
72 1
    }
73 1
74 1
    /**
75 1
     * @return null|ArgumentDescriptor
76 1
     */
77 1
    public function getInheritedElement()
78
    {
79
        if ($this->method instanceof MethodDescriptor &&
80
            $this->method->getInheritedElement() instanceof MethodDescriptor) {
81
            $parents = $this->method->getInheritedElement()->getArguments();
82 1
            foreach ($parents as $parentArgument) {
83
                if ($parentArgument->getName() === $this->getName()) {
84
                    return $parentArgument;
85
                }
86
            }
87
        }
88 1
89
        return null;
90 1
    }
91 1
92
    /**
93
     * {@inheritDoc}
94
     */
95
    public function setDefault($value)
96 1
    {
97
        $this->default = $value;
98 1
    }
99
100
    /**
101
     * {@inheritDoc}
102
     */
103
    public function getDefault()
104 1
    {
105
        return $this->default;
106 1
    }
107 1
108
    /**
109
     * {@inheritDoc}
110
     */
111
    public function setByReference($byReference)
112 1
    {
113
        $this->byReference = $byReference;
114 1
    }
115
116
    /**
117
     * {@inheritDoc}
118
     */
119
    public function isByReference()
120
    {
121
        return $this->byReference;
122
    }
123
124 1
    /**
125
     * Sets whether this argument represents a variadic argument.
126 1
     *
127 1
     * @param boolean $isVariadic
128
     *
129
     * @return false
130
     */
131
    public function setVariadic($isVariadic)
132
    {
133
        $this->isVariadic = $isVariadic;
134 1
    }
135
136 1
    /**
137
     * Returns whether this argument represents a variadic argument.
138
     *
139
     * @return boolean
140
     */
141
    public function isVariadic()
142
    {
143
        return $this->isVariadic;
144
    }
145
}
146