From c5f9e8e878cbff94232bce4a339fd9faaa21c882 Mon Sep 17 00:00:00 2001 From: 4Giedrius <4giedrius@gmail.com> Date: Mon, 30 Mar 2015 16:48:17 +0300 Subject: [PATCH] Using `array_get` and `checkRequiredParamsForArray` where possible in SolusVM constructor --- src/bb-modules/Servicesolusvm/SolusVM.php | 31 +++++++---------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/src/bb-modules/Servicesolusvm/SolusVM.php b/src/bb-modules/Servicesolusvm/SolusVM.php index 15498ca65..434770194 100644 --- a/src/bb-modules/Servicesolusvm/SolusVM.php +++ b/src/bb-modules/Servicesolusvm/SolusVM.php @@ -24,29 +24,16 @@ class SolusVM implements \Box\InjectionAwareInterface{ public function __construct(array $c) { - if(!isset($c['id'])) { - throw new \Exception('API ID is missing'); - } + $required = array( + 'id' => 'API ID is missing', + 'key' => 'API key is missing', + 'ipaddress' => 'API ip address is missing', + ); + $this->di['validator']->checkRequiredParamsForArray($required, $c); - if(!isset($c['key'])) { - throw new \Exception('API key is missing'); - } - - if(!isset($c['ipaddress'])) { - throw new \Exception('API ip address is missing'); - } - - if(!isset($c['usertype'])) { - $c['usertype'] = 'admin'; - } - - if(!isset($c['secure'])) { - $c['secure'] = false; - } - - if(!isset($c['port'])) { - $c['port'] = null; - } + $c['usertype'] = $this->di['array_get']($c, 'usertype', 'admin'); + $c['secure'] = $this->di['array_get']($c, 'secure', false); + $c['port'] = $this->di['array_get']($c, 'port', null); if ($c['secure']) { if ($c["port"]) {