1 | <?php |
||
16 | class RowIterator implements IteratorInterface |
||
17 | { |
||
18 | /** |
||
19 | * Value passed to fgetcsv. 0 means "unlimited" (slightly slower but accomodates for very long lines). |
||
20 | */ |
||
21 | const MAX_READ_BYTES_PER_LINE = 0; |
||
22 | |||
23 | /** @var resource Pointer to the CSV file to read */ |
||
24 | protected $filePointer; |
||
25 | |||
26 | /** @var int Number of read rows */ |
||
27 | protected $numReadRows = 0; |
||
28 | |||
29 | /** @var array|null Buffer used to store the row data, while checking if there are more rows to read */ |
||
30 | protected $rowDataBuffer; |
||
31 | |||
32 | /** @var bool Indicates whether all rows have been read */ |
||
33 | protected $hasReachedEndOfFile = false; |
||
34 | |||
35 | /** @var string Defines the character used to delimit fields (one character only) */ |
||
36 | protected $fieldDelimiter; |
||
37 | |||
38 | /** @var string Defines the character used to enclose fields (one character only) */ |
||
39 | protected $fieldEnclosure; |
||
40 | |||
41 | /** @var string Encoding of the CSV file to be read */ |
||
42 | protected $encoding; |
||
43 | |||
44 | /** @var bool Whether empty rows should be returned or skipped */ |
||
45 | protected $shouldPreserveEmptyRows; |
||
46 | |||
47 | /** @var \Box\Spout\Common\Helper\EncodingHelper Helper to work with different encodings */ |
||
48 | protected $encodingHelper; |
||
49 | |||
50 | /** @var \Box\Spout\Reader\CSV\Creator\InternalEntityFactory Factory to create entities */ |
||
51 | protected $entityFactory; |
||
52 | |||
53 | /** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper Helper to work with global functions */ |
||
54 | protected $globalFunctionsHelper; |
||
55 | |||
56 | /** |
||
57 | * @param resource $filePointer Pointer to the CSV file to read |
||
58 | * @param OptionsManagerInterface $optionsManager |
||
59 | * @param EncodingHelper $encodingHelper |
||
60 | * @param InternalEntityFactory $entityFactory |
||
61 | * @param GlobalFunctionsHelper $globalFunctionsHelper |
||
62 | */ |
||
63 | 27 | public function __construct( |
|
64 | $filePointer, |
||
65 | OptionsManagerInterface $optionsManager, |
||
66 | EncodingHelper $encodingHelper, |
||
67 | InternalEntityFactory $entityFactory, |
||
68 | GlobalFunctionsHelper $globalFunctionsHelper |
||
69 | ) { |
||
70 | 27 | $this->filePointer = $filePointer; |
|
71 | 27 | $this->fieldDelimiter = $optionsManager->getOption(Options::FIELD_DELIMITER); |
|
72 | 27 | $this->fieldEnclosure = $optionsManager->getOption(Options::FIELD_ENCLOSURE); |
|
73 | 27 | $this->encoding = $optionsManager->getOption(Options::ENCODING); |
|
74 | 27 | $this->shouldPreserveEmptyRows = $optionsManager->getOption(Options::SHOULD_PRESERVE_EMPTY_ROWS); |
|
75 | 27 | $this->encodingHelper = $encodingHelper; |
|
76 | 27 | $this->entityFactory = $entityFactory; |
|
77 | 27 | $this->globalFunctionsHelper = $globalFunctionsHelper; |
|
78 | 27 | } |
|
79 | |||
80 | /** |
||
81 | * Rewind the Iterator to the first element |
||
82 | * @see http://php.net/manual/en/iterator.rewind.php |
||
83 | * |
||
84 | * @return void |
||
85 | */ |
||
86 | 26 | public function rewind() |
|
95 | |||
96 | /** |
||
97 | * This rewinds and skips the BOM if inserted at the beginning of the file |
||
98 | * by moving the file pointer after it, so that it is not read. |
||
99 | * |
||
100 | * @return void |
||
101 | */ |
||
102 | 26 | protected function rewindAndSkipBom() |
|
109 | |||
110 | /** |
||
111 | * Checks if current position is valid |
||
112 | * @see http://php.net/manual/en/iterator.valid.php |
||
113 | * |
||
114 | * @return bool |
||
115 | */ |
||
116 | 26 | public function valid() |
|
120 | |||
121 | /** |
||
122 | * Move forward to next element. Reads data for the next unprocessed row. |
||
123 | * @see http://php.net/manual/en/iterator.next.php |
||
124 | * |
||
125 | * @throws \Box\Spout\Common\Exception\EncodingConversionException If unable to convert data to UTF-8 |
||
126 | * @return void |
||
127 | */ |
||
128 | 26 | public function next() |
|
136 | |||
137 | /** |
||
138 | * @throws \Box\Spout\Common\Exception\EncodingConversionException If unable to convert data to UTF-8 |
||
139 | * @return void |
||
140 | */ |
||
141 | 26 | protected function readDataForNextRow() |
|
158 | |||
159 | /** |
||
160 | * @param array|bool $currentRowData |
||
161 | * @return bool Whether the data for the current row can be returned or if we need to keep reading |
||
162 | */ |
||
163 | 26 | protected function shouldReadNextRow($currentRowData) |
|
174 | |||
175 | /** |
||
176 | * Returns the next row, converted if necessary to UTF-8. |
||
177 | * As fgetcsv() does not manage correctly encoding for non UTF-8 data, |
||
178 | * we remove manually whitespace with ltrim or rtrim (depending on the order of the bytes) |
||
179 | * |
||
180 | * @throws \Box\Spout\Common\Exception\EncodingConversionException If unable to convert data to UTF-8 |
||
181 | * @return array|false The row for the current file pointer, encoded in UTF-8 or FALSE if nothing to read |
||
182 | */ |
||
183 | 26 | protected function getNextUTF8EncodedRow() |
|
210 | |||
211 | /** |
||
212 | * @param array|bool $lineData Array containing the cells value for the line |
||
213 | * @return bool Whether the given line is empty |
||
214 | */ |
||
215 | 26 | protected function isEmptyLine($lineData) |
|
219 | |||
220 | /** |
||
221 | * Return the current element from the buffer |
||
222 | * @see http://php.net/manual/en/iterator.current.php |
||
223 | * |
||
224 | * @return array|null |
||
225 | */ |
||
226 | 24 | public function current() |
|
230 | |||
231 | /** |
||
232 | * Return the key of the current element |
||
233 | * @see http://php.net/manual/en/iterator.key.php |
||
234 | * |
||
235 | * @return int |
||
236 | */ |
||
237 | 18 | public function key() |
|
241 | |||
242 | /** |
||
243 | * Cleans up what was created to iterate over the object. |
||
244 | * |
||
245 | * @return void |
||
246 | */ |
||
247 | public function end() |
||
251 | } |
||
252 |
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..