Skip to content

Commit

Permalink
CSVReader::current() avoid recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
boekkooi committed Jul 24, 2014
1 parent d58d326 commit a8401b3
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/Ddeboer/DataImport/Reader/CsvReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,15 @@ public function __construct(\SplFileObject $file, $delimiter = ',', $enclosure =
*/
public function current()
{
$line = $this->file->current();
// If the CSV has no column headers just return the line
if (empty($this->columnHeaders)) {
return $this->file->current();
}

// Since the CSV has column headers use them to construct an associative array for the columns in this line
do {
$line = $this->file->current();

// If the CSV has column headers, use them to construct an associative
// array for the columns in this line
if (!empty($this->columnHeaders)) {
// In non-strict mode pad/slice the line to match the column headers
if (!$this->isStrict()) {
if ($this->headersCount > count($line)) {
Expand All @@ -135,13 +139,10 @@ public function current()
if ($this->valid()) {
$this->errors[$this->key()] = $line;
$this->next();

return $this->current();
}
}
} while($this->valid());

// Else just return the column values
return $line;
return null;
}

/**
Expand Down

0 comments on commit a8401b3

Please sign in to comment.