@@ -105,16 +105,9 @@ private function _removeBom()
105
105
}
106
106
107
107
108
- /**
109
- * Constructor
110
- *
111
- * @param string $file CSV Datei
112
- * @param string $delimiter
113
- */
108
+
114
109
public function __construct ($ file , $ delimiter = 'auto ' )
115
110
{
116
- ini_set ("auto_detect_line_endings " , true );
117
-
118
111
$ this ->_filePath = $ file ;
119
112
120
113
$ finfo = new \finfo (FILEINFO_MIME_TYPE );
@@ -203,10 +196,8 @@ public function detectDelimiter()
203
196
/**
204
197
* @return int
205
198
*/
206
- public function count ()
199
+ public function count (): int
207
200
{
208
- // return max(0, count(file($this->_filePath)) - 1);
209
-
210
201
$ handle = $ this ->fopen ();
211
202
$ count = 0 ;
212
203
@@ -219,14 +210,12 @@ public function count()
219
210
$ this ->fclose ($ handle );
220
211
221
212
return max (0 , $ count - 1 );
222
-
223
213
}
224
214
225
215
/**
226
- * Iterator Funktion zum zurücksetzen des Arrays
227
- *
216
+ * @return void
228
217
*/
229
- public function rewind ()
218
+ public function rewind (): void
230
219
{
231
220
$ this ->_index = 1 ;
232
221
@@ -239,30 +228,32 @@ public function rewind()
239
228
}
240
229
241
230
/**
242
- * Iterator Funktion, gibt das aktuelle Element zurück
243
- *
244
- * @return array
231
+ * @return array|null
232
+ * @throws Exception
245
233
*/
246
- public function current ()
234
+ public function current (): ? array
247
235
{
248
236
if (is_resource ($ this ->_file )) {
249
- $ values = $ this ->mapLabelsToValues (fgetcsv ($ this ->_file , self ::MAX_LINE_LENGTH , $ this ->_delimiter ));
237
+ $ values = $ this ->mapLabelsToValues (fgetcsv ($ this ->_file , self ::MAX_LINE_LENGTH , $ this ->_delimiter , ' " ' , '' ));
250
238
return $ values ;
251
239
}
252
240
253
241
return null ;
254
242
}
255
243
256
244
/**
257
- * Mapt die Labels auf die Datensätze
245
+ * Map labels to values
258
246
*
259
247
* @param mixed $data
260
248
* @return mixed
249
+ * @throws Exception
261
250
*/
262
251
private function mapLabelsToValues ($ data )
263
252
{
253
+ $ result = array ();
254
+
264
255
if (!is_array ($ data )) {
265
- return $ data ;
256
+ return $ result ;
266
257
}
267
258
268
259
$ mapped = array ();
@@ -295,7 +286,6 @@ private function mapLabelsToValues($data)
295
286
throw new \Exception ($ msg );
296
287
}
297
288
298
- $ result = array ();
299
289
foreach ($ this ->_labels as $ id => $ label ) {
300
290
if (isset ($ mapped [$ id ])) {
301
291
$ result [$ label ] = $ mapped [$ id ];
@@ -306,45 +296,37 @@ private function mapLabelsToValues($data)
306
296
}
307
297
308
298
/**
309
- * Iterator Funktion, gibt den aktuellen Index zurück
310
- *
311
299
* @return int
312
300
*/
313
- public function key ()
301
+ public function key (): string | int | null
314
302
{
315
303
return $ this ->_index ;
316
304
}
317
305
318
306
/**
319
- * Zum nächsten Element springen
320
- *
321
- * @return boolean true wenn noch ein element vorhanden ist
307
+ * Jump to the next element
322
308
*/
323
- public function next ($ index = true )
309
+ public function next (): void
324
310
{
325
311
if (is_resource ($ this ->_file )) {
326
- if ($ index ) {
327
- ++$ this ->_index ;
328
- }
329
- return !feof ($ this ->_file );
312
+ ++$ this ->_index ;
330
313
}
331
- return false ;
332
314
}
333
315
334
316
/**
335
- * Iterator Funktion, prüft ob Element gültig
336
- *
337
317
* @return boolean
338
318
*/
339
- public function valid ()
319
+ public function valid (): bool
340
320
{
341
- if (!$ this ->next (false )) {
342
- if (is_resource ($ this ->_file )) {
321
+ if (is_resource ($ this ->_file )) {
322
+ if (!feof ($ this ->_file )) {
323
+ return true ;
324
+ } else {
343
325
$ this ->fclose ($ this ->_file );
344
326
}
345
- return false ;
346
327
}
347
- return true ;
328
+
329
+ return false ;
348
330
}
349
331
350
332
/**
0 commit comments