Skip to content

Commit 7927fa1

Browse files
author
Nuno Chaves
authored
Update FileParser.php
1 parent 2ead4a1 commit 7927fa1

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/FileParser.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,13 @@ public function parse()
158158
while (($line = fgets($file)) !== false) {
159159
$lineNumber++;
160160

161+
// change encoding
162+
if ($this->fromEncoding !== null && $this->toEncoding !== null) {
163+
$line = iconv($this->fromEncoding, $this->toEncoding, $line);
164+
}
165+
161166
if ($this->delimiter !== null) {
162167
$line = str_getcsv($line, $this->delimiter, $this->enclosure, $this->escape);
163-
// change encoding
164-
if ($this->fromEncoding !== null && $this->toEncoding !== null) {
165-
$line = array_map(function($val) {
166-
return iconv($this->fromEncoding, $this->toEncoding, $val);
167-
}, $line);
168-
}
169-
} else {
170-
$line = iconv($this->fromEncoding, $this->toEncoding, $line);
171168
}
172169

173170
// transform lines to object?
@@ -178,7 +175,7 @@ public function parse()
178175
// execute callable for each line
179176
if (is_callable($this->each)) {
180177
$func = $this->each;
181-
$line = $func($line);
178+
$line = $func($line, $lineNumber);
182179
}
183180

184181
// execute callable to filter line

0 commit comments

Comments
 (0)