From 5f683ca0af21b5b4bd27bb4a2782a60d6e1f7726 Mon Sep 17 00:00:00 2001 From: Paul Rock Date: Tue, 21 Aug 2018 23:25:06 +0300 Subject: [PATCH] get method simplification in config class --- src/Config.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/Config.php b/src/Config.php index 4e08b98..9e4cc74 100644 --- a/src/Config.php +++ b/src/Config.php @@ -73,6 +73,24 @@ class Config implements ConfigInterface } /** + * Return port number (get from defaults if port is not set by user) + * + * @param string $parameter + * @return bool|int + */ + private function getPort(string $parameter) + { + // If client need port number and port is not set + if ($parameter === 'port' && !isset($this->_parameters['port'])) { + // then use default with or without ssl encryption + return (isset($this->_parameters['ssl']) && $this->_parameters['ssl']) + ? Client::PORT_SSL + : Client::PORT; + } + return null; + } + + /** * Return parameter of current config by name * * @param string $parameter @@ -88,15 +106,7 @@ class Config implements ConfigInterface // __construct } - // If client need port number and port is not set - if ($parameter === 'port' && !isset($this->_parameters['port'])) { - // then use default with or without ssl encryption - return (isset($this->_parameters['ssl']) && $this->_parameters['ssl']) - ? Client::PORT_SSL - : Client::PORT; - } - - return $this->_parameters[$parameter]; + return $this->getPort($parameter) ?? $this->_parameters[$parameter]; } /**