refactor: fix variable scope in docker entrypoint parsing

Improve variable initialization consistency in convertDockerRunToCompose()
function to match established patterns used for --gpus and --hostname.

Changes:
- Add explicit $value = null initialization in --entrypoint block
- Simplify conditional check from isset($value) to $value check
- Maintain semantic equivalence with zero behavior changes

This refactoring eliminates potential undefined variable warnings and
improves code maintainability by following the defensive pattern used
elsewhere in the file.

Also fixes namespace for RestoreDatabase command from App\Console\Commands
to App\Console\Commands\Cloud to match file location and prevent class
redeclaration errors.

Tests: All 20 tests in DockerCustomCommandsTest pass (25 assertions)
This commit is contained in:
Andras Bacsai 2025-11-26 09:29:22 +01:00
parent 1d277f28dd
commit f3abc4a29f

View File

@ -984,6 +984,7 @@ function convertDockerRunToCompose(?string $custom_docker_run_options = null)
}
}
if ($option === '--entrypoint') {
$value = null;
// Match --entrypoint=value or --entrypoint value
// Handle quoted strings with escaped quotes: --entrypoint "python -c \"print('hi')\""
// Pattern matches: double-quoted (with escapes), single-quoted (with escapes), or unquoted values
@ -1007,7 +1008,7 @@ function convertDockerRunToCompose(?string $custom_docker_run_options = null)
}
}
if (isset($value) && trim($value) !== '') {
if ($value && trim($value) !== '') {
$options[$option][] = $value;
$options[$option] = array_values(array_unique($options[$option]));
}