Skip to content

Commit

Permalink
refactor(MigrateDumpCommand): Replace nested if blocks with early ret…
Browse files Browse the repository at this point in the history
…urn instead.
  • Loading branch information
Paul Rogers committed Apr 4, 2019
1 parent 6f2a237 commit c0fbbcd
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions src/Commands/MigrateDumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ private static function mysqlDump(array $db_config, string $schema_sql_path) : i
. ' --no-data',
$exit_code
);
if (0 !== $exit_code) {
return $exit_code;
}

$schema_sql = file_get_contents($schema_sql_path);
if (false === $schema_sql) {
return 1;
Expand All @@ -94,15 +98,13 @@ private static function mysqlDump(array $db_config, string $schema_sql_path) : i
}

// Include migration rows to avoid unnecessary reruns conflicting.
if (0 === $exit_code) {
// CONSIDER: How this could be done as consistent snapshot with
// dump of structure, and avoid duplicate "SET" comments.
passthru(
$command_prefix . ' migrations --no-create-info --skip-extended-insert >> '
. escapeshellarg($schema_sql_path),
$exit_code
);
}
// CONSIDER: How this could be done as consistent snapshot with
// dump of structure, and avoid duplicate "SET" comments.
passthru(
$command_prefix . ' migrations --no-create-info --skip-extended-insert >> '
. escapeshellarg($schema_sql_path),
$exit_code
);

return $exit_code;
}
Expand Down Expand Up @@ -131,17 +133,18 @@ private static function pgsqlDump(array $db_config, string $schema_sql_path) : i
. ' --schema-only',
$exit_code
);
if (0 !== $exit_code) {
return $exit_code;
}

// Include migration rows to avoid unnecessary reruns conflicting.
if (0 === $exit_code) {
// CONSIDER: How this could be done as consistent snapshot with
// dump of structure, and avoid duplicate "SET" comments.
passthru(
$command_prefix . ' --table=migrations --data-only --inserts >> '
. escapeshellarg($schema_sql_path),
$exit_code
);
}
// CONSIDER: How this could be done as consistent snapshot with
// dump of structure, and avoid duplicate "SET" comments.
passthru(
$command_prefix . ' --table=migrations --data-only --inserts >> '
. escapeshellarg($schema_sql_path),
$exit_code
);

return $exit_code;
}
Expand Down

0 comments on commit c0fbbcd

Please sign in to comment.