Skip to content

Commit c0fbbcd

Browse files
author
Paul Rogers
committed
refactor(MigrateDumpCommand): Replace nested if blocks with early return instead.
1 parent 6f2a237 commit c0fbbcd

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/Commands/MigrateDumpCommand.php

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ private static function mysqlDump(array $db_config, string $schema_sql_path) : i
8484
. ' --no-data',
8585
$exit_code
8686
);
87+
if (0 !== $exit_code) {
88+
return $exit_code;
89+
}
90+
8791
$schema_sql = file_get_contents($schema_sql_path);
8892
if (false === $schema_sql) {
8993
return 1;
@@ -94,15 +98,13 @@ private static function mysqlDump(array $db_config, string $schema_sql_path) : i
9498
}
9599

96100
// Include migration rows to avoid unnecessary reruns conflicting.
97-
if (0 === $exit_code) {
98-
// CONSIDER: How this could be done as consistent snapshot with
99-
// dump of structure, and avoid duplicate "SET" comments.
100-
passthru(
101-
$command_prefix . ' migrations --no-create-info --skip-extended-insert >> '
102-
. escapeshellarg($schema_sql_path),
103-
$exit_code
104-
);
105-
}
101+
// CONSIDER: How this could be done as consistent snapshot with
102+
// dump of structure, and avoid duplicate "SET" comments.
103+
passthru(
104+
$command_prefix . ' migrations --no-create-info --skip-extended-insert >> '
105+
. escapeshellarg($schema_sql_path),
106+
$exit_code
107+
);
106108

107109
return $exit_code;
108110
}
@@ -131,17 +133,18 @@ private static function pgsqlDump(array $db_config, string $schema_sql_path) : i
131133
. ' --schema-only',
132134
$exit_code
133135
);
136+
if (0 !== $exit_code) {
137+
return $exit_code;
138+
}
134139

135140
// Include migration rows to avoid unnecessary reruns conflicting.
136-
if (0 === $exit_code) {
137-
// CONSIDER: How this could be done as consistent snapshot with
138-
// dump of structure, and avoid duplicate "SET" comments.
139-
passthru(
140-
$command_prefix . ' --table=migrations --data-only --inserts >> '
141-
. escapeshellarg($schema_sql_path),
142-
$exit_code
143-
);
144-
}
141+
// CONSIDER: How this could be done as consistent snapshot with
142+
// dump of structure, and avoid duplicate "SET" comments.
143+
passthru(
144+
$command_prefix . ' --table=migrations --data-only --inserts >> '
145+
. escapeshellarg($schema_sql_path),
146+
$exit_code
147+
);
145148

146149
return $exit_code;
147150
}

0 commit comments

Comments
 (0)