Skip to content

Commit

Permalink
Update FileParser.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuno Chaves authored Feb 13, 2018
1 parent 2ead4a1 commit 7927fa1
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/FileParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,13 @@ public function parse()
while (($line = fgets($file)) !== false) {
$lineNumber++;

// change encoding
if ($this->fromEncoding !== null && $this->toEncoding !== null) {
$line = iconv($this->fromEncoding, $this->toEncoding, $line);
}

if ($this->delimiter !== null) {
$line = str_getcsv($line, $this->delimiter, $this->enclosure, $this->escape);
// change encoding
if ($this->fromEncoding !== null && $this->toEncoding !== null) {
$line = array_map(function($val) {
return iconv($this->fromEncoding, $this->toEncoding, $val);
}, $line);
}
} else {
$line = iconv($this->fromEncoding, $this->toEncoding, $line);
}

// transform lines to object?
Expand All @@ -178,7 +175,7 @@ public function parse()
// execute callable for each line
if (is_callable($this->each)) {
$func = $this->each;
$line = $func($line);
$line = $func($line, $lineNumber);
}

// execute callable to filter line
Expand Down

0 comments on commit 7927fa1

Please sign in to comment.