Skip to content

Commit

Permalink
Merge pull request #1 from cfv1000/feature/countable-file
Browse files Browse the repository at this point in the history
feature/countable-file
  • Loading branch information
Flaviu Chelaru committed Nov 21, 2021
2 parents 2813ca6 + a9d7754 commit c266b80
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace cfv1000\CsvReader;

use Countable;
use Iterator;
use SplFileObject;
use SplFileInfo;

class Reader implements Iterator
class Reader implements Iterator, Countable
{
/**
* @var SplFileObject
Expand Down Expand Up @@ -118,4 +119,15 @@ public function tell(): int
{
return $this->file->ftell();
}

/**
* Will return number of lines in the file
* File cursor will be set to the end of file for it (rewind is required if you want to loop through it)
* @return int
*/
public function count()
{
$this->file->fseek(PHP_INT_MAX);
return $this->file->key();
}
}

0 comments on commit c266b80

Please sign in to comment.