1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of SebastianFeldmann\Cli. |
5
|
|
|
* |
6
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace SebastianFeldmann\Cli\Reader; |
13
|
|
|
|
14
|
|
|
use Iterator; |
15
|
|
|
use SebastianFeldmann\Cli\Reader; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Abstract Reader class |
19
|
|
|
* |
20
|
|
|
* @package SebastianFeldmann\Cli |
21
|
|
|
* @author Sebastian Feldmann <[email protected]> |
22
|
|
|
* @link https://github.com/sebastianfeldmann/cli |
23
|
|
|
* @since Class available since Release 3.3.0 |
24
|
|
|
*/ |
25
|
|
|
abstract class Abstraction implements Reader |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Internal iterator to handle foreach |
29
|
|
|
* |
30
|
|
|
* @var \Iterator |
31
|
|
|
*/ |
32
|
|
|
private $iterator; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Return the internal iterator |
36
|
|
|
* |
37
|
|
|
* @return \Iterator |
38
|
|
|
*/ |
39
|
|
|
private function getIterator(): Iterator |
40
|
|
|
{ |
41
|
|
|
return $this->iterator; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Set the pointer to the next line |
46
|
|
|
* |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
|
|
public function next(): void |
50
|
|
|
{ |
51
|
|
|
$this->getIterator()->next(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get the line number of the current line |
56
|
|
|
* |
57
|
|
|
* @return int |
58
|
|
|
*/ |
59
|
|
|
public function key(): int |
60
|
|
|
{ |
61
|
|
|
return $this->getIterator()->key(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Check whether the current line is valid |
66
|
|
|
* |
67
|
|
|
* @return bool |
68
|
|
|
*/ |
69
|
|
|
public function valid(): bool |
70
|
|
|
{ |
71
|
|
|
return $this->getIterator()->valid(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Recreate/rewind the iterator |
76
|
|
|
* |
77
|
|
|
* @return void |
78
|
|
|
*/ |
79
|
|
|
public function rewind(): void |
80
|
|
|
{ |
81
|
|
|
$this->iterator = $this->createIterator(); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get the current line |
86
|
|
|
* |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
public function current(): string |
90
|
|
|
{ |
91
|
|
|
return $this->getIterator()->current(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Create the internal iterator |
96
|
|
|
* |
97
|
|
|
* @return iterable |
98
|
|
|
*/ |
99
|
|
|
protected abstract function createIterator(): iterable; |
100
|
|
|
} |
101
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..