protected function getConnection(string $type, Server $server) : IConnection
    {
        switch ($type) {
            case 'master':
                if ($this->servers['master']['server'] == null) {
                    throw new RuntimeException('No master specified');
                }

                if ($this->servers['master']['connection'] == null) {
                    $this->servers['master']['connection'] = $this->connectToServer($server);
                }

                return $this->servers['master']['connection'];
            default:
                $serverHashId = spl_object_hash($server);

                if (!isset($this->servers[$type][$serverHashId])
                    || $this->servers[$type][$serverHashId]['server'] == null
                ) {
                    throw new RuntimeException("Server of type '" . $type . "' not added to connection pool");
                }

                if ($this->servers[$type][$serverHashId]['connection'] == null) {
                    $this->servers[$type][$serverHashId]['connection'] = $this->connectToServer($server);
                }

                return $this->servers[$type][$serverHashId]['connection'];
        }
    }