Completed
Pull Request — develop (#89)
by Jaap
02:41
created

PropertyIterator::isStatic()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
c 1
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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
14
namespace phpDocumentor\Reflection\Php\Factory;
15
16
17
use phpDocumentor\Reflection\Fqsen;
18
use PhpParser\Comment;
19
use PhpParser\Node;
20
use PhpParser\Node\Stmt\Property as PropertyNode;
21
22
/**
23
 * This class acts like a combination of a PropertyNode and PropertyProperty to be able to create property descriptors using a normal strategy.
24
 */
25
final class PropertyIterator implements \Iterator
26
{
27
    /**
28
     * @var PropertyNode
29
     */
30
    private $property;
31
32
    /** @var int index of the current propertyProperty to use */
33
    private $index = 0;
34
35
    /**
36
     * Instantiates this iterator with the propertyNode to iterate.
37
     *
38
     * @param PropertyNode $property
39
     */
40 2
    public function __construct(PropertyNode $property)
41
    {
42 2
        $this->property = $property;
43 2
    }
44
45
    /**
46
     * returns true when the current property is public.
47
     *
48
     * @return bool
49
     */
50 1
    public function isPublic()
51
    {
52 1
        return $this->property->isPublic();
53
    }
54
55
    /**
56
     * returns true when the current property is protected.
57
     *
58
     * @return bool
59
     */
60 1
    public function isProtected()
61
    {
62 1
        return $this->property->isProtected();
63
    }
64
65
    /**
66
     * returns true when the current property is private.
67
     *
68
     * @return bool
69
     */
70 1
    public function isPrivate()
71
    {
72 1
        return $this->property->isPrivate();
73
    }
74
75
    /**
76
     * returns true when the current property is static.
77
     *
78
     * @return bool
79
     */
80 1
    public function isStatic()
81
    {
82 1
        return $this->property->isStatic();
83
    }
84
85
    /**
86
     * Gets line the node started in.
87
     *
88
     * @return int Line
89
     */
90 1
    public function getLine()
91
    {
92 1
        return $this->property->getLine();
93
    }
94
95
    /**
96
     * Gets the doc comment of the node.
97
     *
98
     * The doc comment has to be the last comment associated with the node.
99
     *
100
     * @return null|Comment\Doc Doc comment object or null
101
     */
102 2
    public function getDocComment()
103
    {
104 2
        $docComment = $this->property->props[$this->index]->getDocComment();
105 2
        if ($docComment === null) {
106 1
            $docComment = $this->property->getDocComment();
107
        }
108
109 2
        return $docComment;
110
    }
111
112
    /**
113
     * returns the name of the current property.
114
     *
115
     * @return string
116
     */
117 1
    public function getName()
118
    {
119 1
        return $this->property->props[$this->index]->name;
120
    }
121
122
    /**
123
     * returns the default value of the current property.
124
     *
125
     * @return null|Node\Expr
126
     */
127 1
    public function getDefault()
128
    {
129 1
        return $this->property->props[$this->index]->default;
130
    }
131
132
133
    /**
134
     * Returns the fqsen of the current property.
135
     *
136
     * @return Fqsen
137
     */
138
    public function getFqsen()
139
    {
140
        return $this->property->props[$this->index]->fqsen;
0 ignored issues
show
Bug introduced by
The property fqsen does not seem to exist in PhpParser\Node\Stmt\PropertyProperty.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
141
    }
142
143
    /**
144
     * (PHP 5 &gt;= 5.0.0)<br/>
145
     * Return the current element
146
     * @link http://php.net/manual/en/iterator.current.php
147
     * @return PropertyIterator Can return any type.
148
     */
149 1
    public function current()
150
    {
151 1
        return $this;
152
    }
153
154
    /**
155
     * (PHP 5 &gt;= 5.0.0)<br/>
156
     * Move forward to next element
157
     * @link http://php.net/manual/en/iterator.next.php
158
     * @return void Any returned value is ignored.
159
     */
160 2
    public function next()
161
    {
162 2
        $this->index++;
163 2
    }
164
165
    /**
166
     * (PHP 5 &gt;= 5.0.0)<br/>
167
     * Return the key of the current element
168
     * @link http://php.net/manual/en/iterator.key.php
169
     * @return integer scalar on success, or null on failure.
170
     */
171 1
    public function key()
172
    {
173 1
        return $this->index;
174
    }
175
176
    /**
177
     * (PHP 5 &gt;= 5.0.0)<br/>
178
     * Checks if current position is valid
179
     * @link http://php.net/manual/en/iterator.valid.php
180
     * @return boolean The return value will be casted to boolean and then evaluated.
181
     * Returns true on success or false on failure.
182
     */
183 1
    public function valid()
184
    {
185 1
        return isset($this->property->props[$this->index]);
186
    }
187
    /**
188
     * (PHP 5 &gt;= 5.0.0)<br/>
189
     * Rewind the Iterator to the first element
190
     * @link http://php.net/manual/en/iterator.rewind.php
191
     * @return void Any returned value is ignored.
192
     */
193 1
    public function rewind()
194
    {
195 1
        $this->index = 0;
196 1
    }
197
}
198