-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
GlobalConstantIterator.php
135 lines (116 loc) · 2.77 KB
/
GlobalConstantIterator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\Php\Factory;
use Iterator;
use phpDocumentor\Reflection\Fqsen;
use PhpParser\Comment\Doc;
use PhpParser\Node\Expr;
use PhpParser\Node\Stmt\Const_;
/**
* @implements Iterator<int, GlobalConstantIterator>
*/
final class GlobalConstantIterator implements Iterator
{
private Const_ $constant;
/** @var int index of the current constant to use */
private int $index = 0;
/**
* Initializes the class with source data.
*/
public function __construct(Const_ $constant)
{
$this->constant = $constant;
}
/**
* Gets line the node started in.
*
* @return int Line
*/
public function getLine(): int
{
return $this->constant->getLine();
}
/**
* Gets line the node ended in.
*
* @return int Line
*/
public function getEndLine(): int
{
return $this->constant->getEndLine();
}
/**
* Returns the name of the current constant.
*/
public function getName(): string
{
return (string) $this->constant->consts[$this->index]->name;
}
/**
* Returns the fqsen of the current constant.
*/
public function getFqsen(): Fqsen
{
return $this->constant->consts[$this->index]->getAttribute('fqsen');
}
/**
* Gets the doc comment of the node.
*
* The doc comment has to be the last comment associated with the node.
*/
public function getDocComment(): ?Doc
{
$docComment = $this->constant->consts[$this->index]->getDocComment();
if ($docComment === null) {
$docComment = $this->constant->getDocComment();
}
return $docComment;
}
public function getValue(): Expr
{
return $this->constant->consts[$this->index]->value;
}
/**
* @link http://php.net/manual/en/iterator.current.php
*/
public function current(): self
{
return $this;
}
/**
* @link http://php.net/manual/en/iterator.next.php
*/
public function next(): void
{
++$this->index;
}
/**
* @link http://php.net/manual/en/iterator.key.php
*/
public function key(): ?int
{
return $this->index;
}
/**
* @link http://php.net/manual/en/iterator.valid.php
*/
public function valid(): bool
{
return isset($this->constant->consts[$this->index]);
}
/**
* @link http://php.net/manual/en/iterator.rewind.php
*/
public function rewind(): void
{
$this->index = 0;
}
}