Skip to content

CsvReader::current() does not check for end of line. #130

Description

@GDXbsv

CsvReader::current() does not check for end of line.
So if we have the end of the file $line = $this->file->current(); returns us false.
Then php die when try to count for false if (count($this->columnHeaders) === count($line)) {

It as well can happen here:

        if (empty($this->columnHeaders)) {
            return $this->file->current();
        }

So that means
public function current(): ?array has a wrong return type (according to code, it has to be false|null|array)

I am currently use composer patch which is adding a simple check.

         do {
             $line = $this->file->current();
 
+			if ($line === false) {
+				return false;
+			}
+
             // In non-strict mode pad/slice the line to match the column headers
             if (!$this->isStrict()) {
                 if ($this->headersCount > count($line)) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions