From d24535073ed42f41bbd03d6ede911345bb408686 Mon Sep 17 00:00:00 2001 From: Pavel Levin Date: Tue, 16 May 2017 16:47:50 +0000 Subject: [PATCH] Simplify ConnectionManager::getConnection --- src/Connection/ConnectionManager.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/Connection/ConnectionManager.php b/src/Connection/ConnectionManager.php index 26517222..9c814d3c 100644 --- a/src/Connection/ConnectionManager.php +++ b/src/Connection/ConnectionManager.php @@ -65,21 +65,14 @@ public function registerConnection(Connection $connection) */ public function getConnection($alias = null) { - $message = null; - - if (null === $alias && empty($this->connections)) { - $message = sprintf('There is no connection configured'); - } elseif (null !== $alias && !array_key_exists($alias, $this->connections)) { - $message = sprintf('The connection with alias "%s" is not configured', $alias); - } - if ($message) { - throw new InvalidConnectionException($message); - } - if (null === $alias) { return $this->getDefaultConnection(); } + if (!array_key_exists($alias, $this->connections)) { + throw new InvalidConnectionException(sprintf('The connection with alias "%s" is not configured', $alias)); + } + return $this->connections[$alias]; }