From 2297e50223df9df0e3d05e18dcb3a63800b8d134 Mon Sep 17 00:00:00 2001 From: Paul Rock Date: Thu, 30 Aug 2018 01:48:59 +0300 Subject: [PATCH] naming of throw methods changed --- src/Client.php | 6 +++--- src/Config.php | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Client.php b/src/Client.php index 0be0aed..2e5bd63 100644 --- a/src/Client.php +++ b/src/Client.php @@ -49,7 +49,7 @@ class Client implements Interfaces\ClientInterface public function __construct(ConfigInterface $config) { // Check for important keys - $this->keysCheck(['host', 'user', 'pass'], $config); + $this->exceptionIfKeyNotExist(['host', 'user', 'pass'], $config); // Save config if everything is okay $this->_config = $config; @@ -67,11 +67,11 @@ class Client implements Interfaces\ClientInterface * @param ConfigInterface $config * @throws ConfigException */ - private function keysCheck(array $keys, ConfigInterface $config) + private function exceptionIfKeyNotExist(array $keys, ConfigInterface $config) { $parameters = $config->getParameters(); foreach ($keys as $key) { - if (false === (array_key_exists($key, $parameters) && isset($parameters[$key]))) { + if (!array_key_exists($key, $parameters) && isset($parameters[$key])) { throw new ConfigException("Parameter '$key' of Config is not set or empty"); } } diff --git a/src/Config.php b/src/Config.php index 8313b03..7bbdfd2 100644 --- a/src/Config.php +++ b/src/Config.php @@ -25,16 +25,16 @@ class Config implements ConfigInterface ]; /** - * Check if key in list of allowed parameters + * Check if key in list of parameters * * @param string $key * @param array $array * @throws ConfigException */ - private function keyAllowed(string $key, array $array) + private function exceptionIfKeyNotExist(string $key, array $array) { if (!array_key_exists($key, $array)) { - throw new ConfigException("Requested parameter '$key' not found in allowed list [" . implode(',', + throw new ConfigException("Requested parameter '$key' not found in list [" . implode(',', array_keys($array)) . ']'); } } @@ -47,10 +47,10 @@ class Config implements ConfigInterface * @param mixed $isType What type should be * @throws ConfigException */ - private function keyType(string $name, $whatType, $isType) + private function exceptionIfTypeMismatch(string $name, $whatType, $isType) { if ($whatType !== $isType) { - throw new ConfigException("Parameter '$name' has wrong type '$whatType'' but should be '$isType''"); + throw new ConfigException("Parameter '$name' has wrong type '$whatType' but should be '$isType'"); } } @@ -65,10 +65,10 @@ class Config implements ConfigInterface public function set(string $name, $value): ConfigInterface { // Check of key in array - $this->keyAllowed($name, self::ALLOWED); + $this->exceptionIfKeyNotExist($name, self::ALLOWED); // Check what type has this value - $this->keyType($name, \gettype($value), self::ALLOWED[$name]); + $this->exceptionIfTypeMismatch($name, \gettype($value), self::ALLOWED[$name]); // Save value to array $this->_parameters[$name] = $value; @@ -104,7 +104,7 @@ class Config implements ConfigInterface public function delete(string $parameter): ConfigInterface { // Check of key in array - $this->keyAllowed($parameter, self::ALLOWED); + $this->exceptionIfKeyNotExist($parameter, self::ALLOWED); // Save value to array unset($this->_parameters[$parameter]); @@ -122,7 +122,7 @@ class Config implements ConfigInterface public function get(string $parameter) { // Check of key in array - $this->keyAllowed($parameter, self::ALLOWED); + $this->exceptionIfKeyNotExist($parameter, self::ALLOWED); return $this->getPort($parameter) ?? $this->_parameters[$parameter]; }