Completed
Pull Request — develop (#87)
by Jaap
03:38
created

ClassConstantIterator   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 92.86%

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 12
c 3
b 1
f 1
lcom 1
cbo 2
dl 0
loc 128
ccs 26
cts 28
cp 0.9286
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getLine() 0 4 1
A getName() 0 4 1
A getFqsen() 0 4 1
A getValue() 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
A getDocComment() 0 9 2
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
use phpDocumentor\Reflection\Fqsen;
17
use PhpParser\Comment\Doc;
18
use PhpParser\Node\Stmt\ClassConst;
19
20
/**
21
 * This class acts like a combination of a ClassConst and Const_ to be able to create constant descriptors using a normal strategy.
22
 */
23
final class ClassConstantIterator implements \Iterator
24
{
25
    /**
26
     * @var ClassConst
27
     */
28
    private $classConstants;
29
30
    /** @var int index of the current ClassConst to use */
31
    private $index = 0;
32
33
    /**
34
     * Initializes the class with source data.
35
     *
36
     * @param ClassConst $classConst
37
     */
38 1
    public function __construct(ClassConst $classConst)
39
    {
40 1
        $this->classConstants = $classConst;
41 1
    }
42
43
    /**
44
     * Gets line the node started in.
45
     *
46
     * @return int Line
47
     */
48 1
    public function getLine()
49
    {
50 1
        return $this->classConstants->getLine();
51
    }
52
53
    /**
54
     * Returns the name of the current constant.
55
     *
56
     * @return string
57
     */
58 1
    public function getName()
59
    {
60 1
       return $this->classConstants->consts[$this->index]->name;
0 ignored issues
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 8 spaces, but found 7).
Loading history...
61
    }
62
63
    /**
64
     * Returns the fqsen of the current constant.
65
     *
66
     * @return Fqsen
67
     */
68 1
    public function getFqsen()
69
    {
70 1
        return $this->classConstants->consts[$this->index]->fqsen;
0 ignored issues
show
Bug introduced by
The property fqsen does not seem to exist in PhpParser\Node\Const_.

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...
71
    }
72
73
    /**
74
     * Gets the doc comment of the node.
75
     *
76
     * The doc comment has to be the last comment associated with the node.
77
     *
78
     * @return null|Doc Doc comment object or null
79
     */
80 2
    public function getDocComment()
81
    {
82 2
        $docComment = $this->classConstants->consts[$this->index]->getDocComment();
83 2
        if ($docComment === null) {
84 1
            $docComment = $this->classConstants->getDocComment();
85
        }
86
87 2
        return $docComment;
88
    }
89
90
    public function getValue()
91
    {
92
        return $this->classConstants->consts[$this->index]->value;
93
    }
94
95
    /**
96
     * (PHP 5 &gt;= 5.0.0)<br/>
97
     * Return the current element
98
     * @link http://php.net/manual/en/iterator.current.php
99
     * @return mixed Can return any type.
100
     */
101 1
    public function current()
102
    {
103 1
        return $this;
104
    }
105
106
    /**
107
     * (PHP 5 &gt;= 5.0.0)<br/>
108
     * Move forward to next element
109
     * @link http://php.net/manual/en/iterator.next.php
110
     * @return void Any returned value is ignored.
111
     */
112 2
    public function next()
113
    {
114 2
        $this->index++;
115 2
    }
116
117
    /**
118
     * (PHP 5 &gt;= 5.0.0)<br/>
119
     * Return the key of the current element
120
     * @link http://php.net/manual/en/iterator.key.php
121
     * @return mixed scalar on success, or null on failure.
122
     */
123 1
    public function key()
124
    {
125 1
        return $this->index;
126
    }
127
128
    /**
129
     * (PHP 5 &gt;= 5.0.0)<br/>
130
     * Checks if current position is valid
131
     * @link http://php.net/manual/en/iterator.valid.php
132
     * @return boolean The return value will be casted to boolean and then evaluated.
133
     * Returns true on success or false on failure.
134
     */
135 1
    public function valid()
136
    {
137 1
        return isset($this->classConstants->consts[$this->index]);
138
    }
139
140
    /**
141
     * (PHP 5 &gt;= 5.0.0)<br/>
142
     * Rewind the Iterator to the first element
143
     * @link http://php.net/manual/en/iterator.rewind.php
144
     * @return void Any returned value is ignored.
145
     */
146 1
    public function rewind()
147
    {
148 1
        $this->index = 0;
149 1
    }
150
}
151