Skip to content

Commit 7357615

Browse files
committed
address comment: use SPLFileObject.
1 parent 9088ef1 commit 7357615

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

src/Migration/Sources/CSV.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,30 @@ public function report(array $resources = []): array
5858
{
5959
$report = [];
6060

61-
$this->withCsvStream(function ($stream) use (&$report) {
62-
$headers = fgetcsv($stream);
63-
if (! is_array($headers) || count($headers) === 0) {
64-
return;
65-
}
61+
if (! $this->device->exists($this->filePath)) {
62+
return $report;
63+
}
64+
65+
$file = new \SplFileObject($this->filePath, 'r');
66+
$file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY);
6667

67-
$rowCount = 0;
68-
while (fgetcsv($stream) !== false) {
69-
$rowCount++;
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;
7079
}
7180

72-
$report[Resource::TYPE_DOCUMENT] = $rowCount;
73-
});
81+
$rowCount++;
82+
}
83+
84+
$report[Resource::TYPE_DOCUMENT] = $rowCount;
7485

7586
return $report;
7687
}

0 commit comments

Comments
 (0)