1 | <?php |
||
19 | class LineStreamIterator implements Iterator |
||
20 | { |
||
21 | use GetOptionTrait; |
||
22 | |||
23 | const OPTION_ENDING = 'ending'; |
||
24 | const OPTION_IGNORE_BLANK = 'ignoreBlank'; |
||
25 | const OPTION_INCLUDE_ENDING = 'includeEnding'; |
||
26 | |||
27 | const DEFAULT_ENDING = PHP_EOL; |
||
28 | const DEFAULT_IGNORE_BLANK = true; |
||
29 | const DEFAULT_INCLUDE_ENDING = false; |
||
30 | |||
31 | /** @var string */ |
||
32 | private $ending; |
||
33 | /** @var int */ |
||
34 | private $position = 0; |
||
35 | /** @var string */ |
||
36 | private $current; |
||
37 | /** @var bool */ |
||
38 | private $ignoreBlank = true; |
||
39 | /** @var StreamInterface */ |
||
40 | private $stream; |
||
41 | /** @var bool */ |
||
42 | private $includeEnding; |
||
43 | |||
44 | /** |
||
45 | * LineStreamIterator constructor. |
||
46 | * |
||
47 | * @param StreamInterface $stream |
||
48 | * @param array $options |
||
49 | */ |
||
50 | 9 | public function __construct(StreamInterface $stream, array $options = []) |
|
58 | |||
59 | /** |
||
60 | * @param bool $ignore |
||
61 | * |
||
62 | * @return $this |
||
63 | */ |
||
64 | 4 | public function setIgnoreBlank($ignore) |
|
69 | |||
70 | /** |
||
71 | * Return the current element |
||
72 | * |
||
73 | * @link http://php.net/manual/en/iterator.current.php |
||
74 | * @return mixed Can return any type. |
||
75 | * @since 5.0.0 |
||
76 | */ |
||
77 | 6 | public function current() |
|
81 | |||
82 | /** |
||
83 | * Move forward to next element |
||
84 | * |
||
85 | * @link http://php.net/manual/en/iterator.next.php |
||
86 | * @since 5.0.0 |
||
87 | */ |
||
88 | 6 | public function next() |
|
94 | |||
95 | /** |
||
96 | * @param string $ending |
||
97 | * |
||
98 | * @return bool |
||
99 | */ |
||
100 | 6 | private function readStreamTill($ending) |
|
124 | |||
125 | /** |
||
126 | * Return the key of the current element |
||
127 | * |
||
128 | * @link http://php.net/manual/en/iterator.key.php |
||
129 | * @return mixed scalar on success, or null on failure. |
||
130 | * @since 5.0.0 |
||
131 | */ |
||
132 | 6 | public function key() |
|
136 | |||
137 | /** |
||
138 | * Checks if current position is valid |
||
139 | * |
||
140 | * @link http://php.net/manual/en/iterator.valid.php |
||
141 | * @return bool The return value will be casted to boolean and then evaluated. |
||
142 | * Returns true on success or false on failure. |
||
143 | * @since 5.0.0 |
||
144 | */ |
||
145 | 5 | public function valid() |
|
149 | |||
150 | /** |
||
151 | * {@inheritdoc} |
||
152 | */ |
||
153 | 6 | public function rewind() |
|
159 | |||
160 | /** |
||
161 | * @return bool |
||
162 | */ |
||
163 | 3 | public function isIgnoreBlank() |
|
167 | |||
168 | /** |
||
169 | * @return bool |
||
170 | */ |
||
171 | 3 | public function isIncludeEnding() |
|
175 | |||
176 | /** |
||
177 | * @param bool $includeEnding |
||
178 | * |
||
179 | * @return $this |
||
180 | */ |
||
181 | 1 | public function setIncludeEnding($includeEnding) |
|
186 | |||
187 | /** |
||
188 | * @param string $ending |
||
189 | * |
||
190 | * @return $this |
||
191 | */ |
||
192 | 1 | public function setEnding($ending) |
|
197 | |||
198 | /** |
||
199 | * @return string |
||
200 | */ |
||
201 | 3 | public function getEnding() |
|
205 | } |
||
206 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.