Completed
Push — develop ( 4b49c4...89d32a )
by Jaap
09:06 queued 05:30
created

phpDocumentor/Descriptor/ArgumentDescriptor.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * phpDocumentor
4
 *
5
 * PHP Version 5.3
6
 *
7
 * @copyright 2010-2014 Mike van Riel / Naenius (http://www.naenius.com)
8
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
9
 * @link      http://phpdoc.org
10
 */
11
namespace phpDocumentor\Descriptor;
12
13
/**
14
 * Descriptor representing a single Argument of a method or function.
15
 */
16
class ArgumentDescriptor extends DescriptorAbstract implements Interfaces\ArgumentInterface
17
{
18
    /** @var MethodDescriptor $method */
19
    protected $method;
20
21
    /** @var string[] $type an array of normalized types that should be in this Argument */
22
    protected $types = array();
23
24
    /** @var string|null $default the default value for an argument or null if none is provided */
25
    protected $default;
26
27
    /** @var bool $byReference whether the argument passes the parameter by reference instead of by value */
28
    protected $byReference = false;
29
30
    /** @var boolean Determines if this Argument represents a variadic argument */
31
    protected $isVariadic = false;
32
33
    /**
34
     * To which method does this argument belong to
35
     *
36
     * @param MethodDescriptor $method
37
     */
38
    public function setMethod(MethodDescriptor $method)
39
    {
40
        $this->method = $method;
41
    }
42
43
    /**
44
     * {@inheritDoc}
45
     */
46 1
    public function setTypes($types)
47
    {
48 1
        $this->types = $types;
49 1
    }
50
51
    /**
52
     * {@inheritDoc}
53
     */
54 2
    public function getTypes()
55
    {
56 2
        $countable = $this->types instanceof \Countable || is_array($this->types);
57 2
        if ((!$countable || count($this->types) == 0) && $this->getInheritedElement() !== null) {
58 1
            $this->setTypes($this->getInheritedElement()->getTypes());
59
        }
60
61 2
        return $this->types;
62
    }
63
64
    /**
65
     * @return null|ArgumentDescriptor
66
     */
67
    public function getInheritedElement()
68
    {
69
        if ($this->method instanceof MethodDescriptor &&
70
            $this->method->getInheritedElement() instanceof MethodDescriptor) {
71
            $parents = $this->method->getInheritedElement()->getArguments();
72
            foreach($parents as $parentArgument)
0 ignored issues
show
Expected 1 space after FOREACH keyword; 0 found
Loading history...
73
            {
74
                if ($parentArgument->getName() === $this->getName()) {
75
                    return $parentArgument;
76
                }
77
            }
78
        }
79
        return null;
80
    }
81
82
    /**
83
     * {@inheritDoc}
84
     */
85 1
    public function setDefault($value)
86
    {
87 1
        $this->default = $value;
88 1
    }
89
90
    /**
91
     * {@inheritDoc}
92
     */
93 1
    public function getDefault()
94
    {
95 1
        return $this->default;
96
    }
97
98
    /**
99
     * {@inheritDoc}
100
     */
101 1
    public function setByReference($byReference)
102
    {
103 1
        $this->byReference = $byReference;
104 1
    }
105
106
    /**
107
     * {@inheritDoc}
108
     */
109 1
    public function isByReference()
110
    {
111 1
        return $this->byReference;
112
    }
113
114
    /**
115
     * Sets whether this argument represents a variadic argument.
116
     *
117
     * @param boolean $isVariadic
118
     *
119
     * @return false
120
     */
121
    public function setVariadic($isVariadic)
122
    {
123
        $this->isVariadic = $isVariadic;
124
    }
125
126
    /**
127
     * Returns whether this argument represents a variadic argument.
128
     *
129
     * @return boolean
130
     */
131
    public function isVariadic()
132
    {
133
        return $this->isVariadic;
134
    }
135
}
136