diff --git a/src/Command/Shared/ConnectTrait.php b/src/Command/Shared/ConnectTrait.php index c95dc58e7..517d93c93 100644 --- a/src/Command/Shared/ConnectTrait.php +++ b/src/Command/Shared/ConnectTrait.php @@ -16,31 +16,21 @@ trait ConnectTrait public function resolveConnection($key = 'default', $target = 'default') { $connectionInfo = Database::getConnectionInfo($key); - if (!$connectionInfo || !isset($connectionInfo[$target])) { - $this->getIo()->error( - sprintf( - $this->trans('commands.database.connect.messages.database-not-found'), - $key, - $target - ) - ); - - return null; + if (empty($connectionInfo[$target])) { + throw new \Exception(sprintf( + $this->trans('commands.database.connect.messages.database-not-found'), + $key, + $target + )); } - - $databaseConnection = $connectionInfo[$target]; - if (!in_array($databaseConnection['driver'], $this->supportedDrivers)) { - $this->getIo()->error( - sprintf( - $this->trans('commands.database.connect.messages.database-not-supported'), - $databaseConnection['driver'] - ) - ); - - return null; + else if (!in_array($connectionInfo[$target]['driver'], $this->supportedDrivers)) { + throw new \Exception(sprintf( + $this->trans('commands.database.connect.messages.database-not-supported'), + $connectionInfo[$target]['driver'] + )); } - return $databaseConnection; + return $connectionInfo[$target]; } public function getRedBeanConnection($database = 'default')