PropertyIterator   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 141
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 94.44%

Importance

Changes 0
Metric Value
dl 0
loc 141
rs 10
c 0
b 0
f 0
ccs 34
cts 36
cp 0.9444
wmc 16
lcom 1
cbo 2

15 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isPublic() 0 4 1
A isProtected() 0 4 1
A isPrivate() 0 4 1
A isStatic() 0 4 1
A getLine() 0 4 1
A getDocComment() 0 9 2
A getName() 0 4 1
A getDefault() 0 4 1
A getFqsen() 0 4 1
A current() 0 4 1
A next() 0 4 1
A key() 0 4 1
A valid() 0 4 1
A rewind() 0 4 1
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
 * @copyright 2010-2018 Mike van Riel<[email protected]>
11
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
12
 * @link      http://phpdoc.org
13
 */
14
15
namespace phpDocumentor\Reflection\Php\Factory;
16
17
use Iterator;
18
use phpDocumentor\Reflection\Fqsen;
19
use PhpParser\Comment\Doc;
20
use PhpParser\Node\Expr;
21
use PhpParser\Node\Stmt\Property as PropertyNode;
22
23
/**
24
 * This class acts like a combination of a PropertyNode and PropertyProperty to
25
 * be able to create property descriptors using a normal strategy.
26
 */
27
final class PropertyIterator implements Iterator
28
{
29
    /**
30
     * @var PropertyNode
31
     */
32
    private $property;
33
34
    /**
35
     * @var int index of the current propertyProperty to use
36
     */
37
    private $index = 0;
38
39
    /**
40
     * Instantiates this iterator with the propertyNode to iterate.
41
     */
42 2
    public function __construct(PropertyNode $property)
43
    {
44 2
        $this->property = $property;
45 2
    }
46
47
    /**
48
     * returns true when the current property is public.
49
     */
50 1
    public function isPublic(): bool
51
    {
52 1
        return $this->property->isPublic();
53
    }
54
55
    /**
56
     * returns true when the current property is protected.
57
     */
58 1
    public function isProtected(): bool
59
    {
60 1
        return $this->property->isProtected();
61
    }
62
63
    /**
64
     * returns true when the current property is private.
65
     */
66 1
    public function isPrivate(): bool
67
    {
68 1
        return $this->property->isPrivate();
69
    }
70
71
    /**
72
     * returns true when the current property is static.
73
     */
74 1
    public function isStatic(): bool
75
    {
76 1
        return $this->property->isStatic();
77
    }
78
79
    /**
80
     * Gets line the node started in.
81
     */
82 1
    public function getLine(): int
83
    {
84 1
        return $this->property->getLine();
85
    }
86
87
    /**
88
     * Gets the doc comment of the node.
89
     *
90
     * The doc comment has to be the last comment associated with the node.
91
     */
92 2
    public function getDocComment(): ?Doc
93
    {
94 2
        $docComment = $this->property->props[$this->index]->getDocComment();
95 2
        if ($docComment === null) {
96 1
            $docComment = $this->property->getDocComment();
97
        }
98
99 2
        return $docComment;
100
    }
101
102
    /**
103
     * returns the name of the current property.
104
     */
105 1
    public function getName(): string
106
    {
107 1
        return (string) $this->property->props[$this->index]->name;
108
    }
109
110
    /**
111
     * returns the default value of the current property.
112
     *
113
     * @return null|string|Expr
114
     */
115 1
    public function getDefault()
116
    {
117 1
        return $this->property->props[$this->index]->default;
118
    }
119
120
    /**
121
     * Returns the fqsen of the current property.
122
     */
123
    public function getFqsen(): Fqsen
124
    {
125
        return $this->property->props[$this->index]->fqsen;
126
    }
127
128
    /**
129
     * @link http://php.net/manual/en/iterator.current.php
130
     */
131 1
    public function current(): self
132
    {
133 1
        return $this;
134
    }
135
136
    /**
137
     * @link http://php.net/manual/en/iterator.next.php
138
     */
139 2
    public function next(): void
140
    {
141 2
        ++$this->index;
142 2
    }
143
144
    /**
145
     * @link http://php.net/manual/en/iterator.key.php
146
     */
147 1
    public function key(): ?int
148
    {
149 1
        return $this->index;
150
    }
151
152
    /**
153
     * @link http://php.net/manual/en/iterator.valid.php
154
     */
155 1
    public function valid(): bool
156
    {
157 1
        return isset($this->property->props[$this->index]);
158
    }
159
160
    /**
161
     * @link http://php.net/manual/en/iterator.rewind.php
162
     */
163 1
    public function rewind(): void
164
    {
165 1
        $this->index = 0;
166 1
    }
167
}
168