From ab9deb2215cb48262c74b83e2102f4b130d44148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20J=C3=A2nio?= Date: Sat, 16 Oct 2021 23:46:59 -0300 Subject: [PATCH 1/2] simplifies value assignment --- src/Configuration.php | 82 ++++--------------------------------------- 1 file changed, 6 insertions(+), 76 deletions(-) diff --git a/src/Configuration.php b/src/Configuration.php index 6a39c8e3..f755e431 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -183,82 +183,12 @@ class Configuration public function __construct(array $data = null) { $this->tempFolderPath = sys_get_temp_dir(); - if(isset($data["apiKeys"])) - { - $this->apiKeys = $data["apiKeys"]; - } - if(isset($data["apiKeyPrefixes"])) - { - $this->apiKeyPrefixes = $data["apiKeyPrefixes"]; - } - if(isset($data["accessToken"])) - { - $this->accessToken = $data["accessToken"]; - } - if(isset($data["username"])) - { - $this->username = $data["username"]; - } - if(isset($data["password"])) - { - $this->password = $data["password"]; - } - if(isset($data["defaultHeaders"])) - { - $this->defaultHeaders = $data["defaultHeaders"]; - } - if(isset($data["host"])) - { - $this->host = $data["host"]; - } - if(isset($data["curlTimeout"])) - { - $this->curlTimeout = $data["curlTimeout"]; - } - if(isset($data["curlConnectTimeout"])) - { - $this->curlConnectTimeout = $data["curlConnectTimeout"]; - } - if(isset($data["userAgent"])) - { - $this->userAgent = $data["userAgent"]; - } - if(isset($data["debug"])) - { - $this->debug = $data["debug"]; - } - if(isset($data["debugFile"])) - { - $this->debugFile = $data["debugFile"]; - } - if(isset($data["tempFolderPath"])) - { - $this->tempFolderPath = $data["tempFolderPath"]; - } - if(isset($data["sslVerification"])) - { - $this->sslVerification = $data["sslVerification"]; - } - if(isset($data["proxyHost"])) - { - $this->proxyHost = $data["proxyHost"]; - } - if(isset($data["proxyPort"])) - { - $this->proxyPort = $data["proxyPort"]; - } - if(isset($data["proxyType"])) - { - $this->proxyType = $data["proxyType"]; - } - if(isset($data["proxyUser"])) - { - $this->proxyUser = $data["proxyUser"]; - } - if(isset($data["proxyPassword"])) - { - $this->proxyPassword = $data["proxyPassword"]; - } + + foreach ($data as $key => $value) { + if (property_exists($this, $key)) { + $this->$key = $value; + } + } } /** From 436b41672e33208c5500e712ff8fe844f0cfbbca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20J=C3=A2nio?= Date: Wed, 2 Nov 2022 20:52:00 -0300 Subject: [PATCH 2/2] Checks received data and dynamically assigned to object properties --- src/Configuration.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Configuration.php b/src/Configuration.php index f755e431..24b6e310 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -184,8 +184,30 @@ public function __construct(array $data = null) { $this->tempFolderPath = sys_get_temp_dir(); + $allowedInputs = [ + 'apiKeys', + 'apiKeyPrefixes', + 'accessToken', + 'username', + 'password', + 'defaultHeaders', + 'host', + 'curlTimeout', + 'curlConnectTimeout', + 'userAgent', + 'debug', + 'debugFile', + 'tempFolderPath', + 'sslVerification', + 'proxyHost', + 'proxyPort', + 'proxyType', + 'proxyUser', + 'proxyPassword', + ]; + foreach ($data as $key => $value) { - if (property_exists($this, $key)) { + if (property_exists($this, $key) && in_array($key, $allowedInputs)) { $this->$key = $value; } }