Skip to content

Commit

Permalink
comment
Browse files Browse the repository at this point in the history
  • Loading branch information
justinkekeocha committed Apr 15, 2024
1 parent d4709cd commit 7b3d05c
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/DatabaseDump.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function getDirectoryListing($directoryPath): array
foreach ($files as $file) {
//Remove current directory and parent directory from listing
//Choose only files except folders
if ($file != '.' && $file != '..' && is_file($directoryPath.'/'.$file)) {
if ($file != '.' && $file != '..' && is_file($directoryPath . '/' . $file)) {
$result[] = $file;
}
}
Expand All @@ -53,7 +53,7 @@ public function getDump(int|string $needle): self

//check if the pointer is an integer
$this->filePath = is_int($needle)
? $dumpFolder.array_reverse($dumpListings)[$needle]
? $dumpFolder . array_reverse($dumpListings)[$needle]
: "$dumpFolder$needle";

return $this;
Expand Down Expand Up @@ -101,7 +101,7 @@ protected function readFile(int $offset = 0)
fseek($file, $offset);

// Ensure the file is opened
if (! $file) {
if (!$file) {
throw new Exception("Unable to open the file: {$this->filePath}");
}

Expand All @@ -110,7 +110,7 @@ protected function readFile(int $offset = 0)

try {

while (! feof($file)) {
while (!feof($file)) {
$line = fgets($file);

$this->fileOffset = ftell($file);
Expand Down Expand Up @@ -168,13 +168,17 @@ public function seed(string|array $modelOrTableName, ?int $chunkLength = null, ?
foreach ($modelOrTableName as $row) {
$tables[] = $this->resolveModelOrTableName($row);
}
//Ignore $formatRow
//Ignore $formatRowCallback when array is passed.
$formatRowCallback = null;
} else {
$tables[] = $this->resolveModelOrTableName($modelOrTableName);
}

//GenerateSchema
if (! $this->schema) {
/* Generate a schema of the dump and note the file offset of each table.
This ensures that subsequent seed calls on the same dump file don't start afresh,
But starts gets the already saved offset for the particular table and starts reading from there
*/
if (!$this->schema) {
$this->generateSchema();
}

Expand All @@ -201,7 +205,7 @@ public function seed(string|array $modelOrTableName, ?int $chunkLength = null, ?
);

//Check header tag
if (! $isHeader && ! $isFooter) {
if (!$isHeader && !$isFooter) {
$rowToArray = (array) $row;
if (is_callable($formatRowCallback)) {
$rowToArray = call_user_func($formatRowCallback, $rowToArray);
Expand Down

0 comments on commit 7b3d05c

Please sign in to comment.