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\Stmt\Const_; |
21
|
|
|
|
22
|
|
|
final class GlobalConstantIterator implements Iterator |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var Const_ |
26
|
|
|
*/ |
27
|
|
|
private $constant; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var int index of the current constant to use |
31
|
|
|
*/ |
32
|
|
|
private $index = 0; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Initializes the class with source data. |
36
|
|
|
*/ |
37
|
5 |
|
public function __construct(Const_ $constant) |
38
|
|
|
{ |
39
|
5 |
|
$this->constant = $constant; |
40
|
5 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Gets line the node started in. |
44
|
|
|
* |
45
|
|
|
* @return int Line |
46
|
|
|
*/ |
47
|
1 |
|
public function getLine() : int |
48
|
|
|
{ |
49
|
1 |
|
return $this->constant->getLine(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Returns the name of the current constant. |
54
|
|
|
*/ |
55
|
1 |
|
public function getName() : string |
56
|
|
|
{ |
57
|
1 |
|
return (string) $this->constant->consts[$this->index]->name; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Returns the fqsen of the current constant. |
62
|
|
|
*/ |
63
|
1 |
|
public function getFqsen() : Fqsen |
64
|
|
|
{ |
65
|
1 |
|
return $this->constant->consts[$this->index]->fqsen; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Gets the doc comment of the node. |
70
|
|
|
* |
71
|
|
|
* The doc comment has to be the last comment associated with the node. |
72
|
|
|
*/ |
73
|
2 |
|
public function getDocComment() : ?Doc |
74
|
|
|
{ |
75
|
2 |
|
$docComment = $this->constant->consts[$this->index]->getDocComment(); |
76
|
2 |
|
if ($docComment === null) { |
77
|
1 |
|
$docComment = $this->constant->getDocComment(); |
78
|
|
|
} |
79
|
|
|
|
80
|
2 |
|
return $docComment; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function getValue() |
84
|
|
|
{ |
85
|
|
|
return $this->constant->consts[$this->index]->value; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @link http://php.net/manual/en/iterator.current.php |
90
|
|
|
*/ |
91
|
1 |
|
public function current() : self |
92
|
|
|
{ |
93
|
1 |
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @link http://php.net/manual/en/iterator.next.php |
98
|
|
|
*/ |
99
|
2 |
|
public function next() : void |
100
|
|
|
{ |
101
|
2 |
|
++$this->index; |
102
|
2 |
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @link http://php.net/manual/en/iterator.key.php |
106
|
|
|
*/ |
107
|
1 |
|
public function key() : ?int |
108
|
|
|
{ |
109
|
1 |
|
return $this->index; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @link http://php.net/manual/en/iterator.valid.php |
114
|
|
|
*/ |
115
|
1 |
|
public function valid() : bool |
116
|
|
|
{ |
117
|
1 |
|
return isset($this->constant->consts[$this->index]); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @link http://php.net/manual/en/iterator.rewind.php |
122
|
|
|
*/ |
123
|
1 |
|
public function rewind() : void |
124
|
|
|
{ |
125
|
1 |
|
$this->index = 0; |
126
|
1 |
|
} |
127
|
|
|
} |
128
|
|
|
|