From 11207a9a2ee21821fd19528bf92bf5c649cb2e94 Mon Sep 17 00:00:00 2001 From: polarathene Date: Tue, 5 Nov 2019 20:26:06 +1300 Subject: [PATCH] Fix: Check for null install directory earlier Allows for failing fast when no install directory was provided to the command(uses package name instead). --- src/Composer/Command/CreateProjectCommand.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index e84234467..7a43eb990 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -279,6 +279,12 @@ EOT $packageVersion = $requirements[0]['version']; } + // if no directory was specified, use the 2nd part of the package name + if (null === $directory) { + $parts = explode("/", $name, 2); + $directory = getcwd() . DIRECTORY_SEPARATOR . array_pop($parts); + } + $fs = new Filesystem(); if (is_dir($directory) && !$fs->isDirEmpty($directory)) { throw new \InvalidArgumentException("Project directory $directory is not empty."); @@ -325,11 +331,6 @@ EOT throw new \InvalidArgumentException($errorMessage .'.'); } - if (null === $directory) { - $parts = explode("/", $name, 2); - $directory = getcwd() . DIRECTORY_SEPARATOR . array_pop($parts); - } - // handler Ctrl+C for unix-like systems if (function_exists('pcntl_async_signals')) { @mkdir($directory, 0777, true);