Skip to content

Commit ff392fe

Browse files
committed
address comment: use SPLFileObject with seek.
1 parent 7357615 commit ff392fe

1 file changed

Lines changed: 5 additions & 13 deletions

File tree

src/Migration/Sources/CSV.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,12 @@ public function report(array $resources = []): array
6565
$file = new \SplFileObject($this->filePath, 'r');
6666
$file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY);
6767

68-
if (! $file->eof()) {
69-
$file->fgetcsv();
70-
}
71-
72-
$rowCount = 0;
73-
while (! $file->eof()) {
74-
$row = $file->fgetcsv();
75-
76-
// check for blank lines
77-
if ($row === [null] || $row === false) {
78-
continue;
79-
}
68+
$file->seek(PHP_INT_MAX);
69+
$rowCount = $file->key();
8070

81-
$rowCount++;
71+
// Subtract to exclude header
72+
if ($rowCount > 0) {
73+
$rowCount--;
8274
}
8375

8476
$report[Resource::TYPE_DOCUMENT] = $rowCount;

0 commit comments

Comments
 (0)