From e607f5c5d3fe0b41f2e00bd14ef96dc2ce31816c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20=C5=81ojewski?= Date: Mon, 13 Apr 2020 11:55:00 +0200 Subject: [PATCH] firstNonemptyProperty --- lib/Query/QueryProvider.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/Query/QueryProvider.php b/lib/Query/QueryProvider.php index 1b5c735..28c25c6 100644 --- a/lib/Query/QueryProvider.php +++ b/lib/Query/QueryProvider.php @@ -53,6 +53,25 @@ class QueryProvider implements \ArrayAccess $this->loadQueries(); } + /** + * Get first nonempty property value. + * + * @param mixed ...$keys Property keys. + * + * @return mixed + */ + private function firstNonemptyProperty(...$keys) + { + foreach ($keys as $key) { + $value = $this->properties[$key]; + if (!empty($value)) { + return $value; + } + } + + return null; + } + /** * Load queries to the array. */ @@ -64,19 +83,19 @@ class QueryProvider implements \ArrayAccess $gAdmin = $this->properties[DB::GROUP_ADMIN_COLUMN]; $gGID = $this->properties[DB::GROUP_GID_COLUMN]; - $gName = $this->properties[DB::GROUP_NAME_COLUMN] || $this->properties[DB::GROUP_GID_COLUMN]; + $gName = $this->firstNonemptyProperty(DB::GROUP_NAME_COLUMN, DB::GROUP_GID_COLUMN); $uActive = $this->properties[DB::USER_ACTIVE_COLUMN]; $uAvatar = $this->properties[DB::USER_AVATAR_COLUMN]; $uDisabled = $this->properties[DB::USER_DISABLED_COLUMN]; $uEmail = $this->properties[DB::USER_EMAIL_COLUMN]; $uHome = $this->properties[DB::USER_HOME_COLUMN]; - $uName = $this->properties[DB::USER_NAME_COLUMN] || $this->properties[DB::USER_USERNAME_COLUMN] || $this->properties[DB::USER_UID_COLUMN]; + $uName = $this->firstNonemptyProperty(DB::USER_NAME_COLUMN, DB::USER_USERNAME_COLUMN, DB::USER_UID_COLUMN); $uPassword = $this->properties[DB::USER_PASSWORD_COLUMN]; $uQuota = $this->properties[DB::USER_QUOTA_COLUMN]; $uSalt = $this->properties[DB::USER_SALT_COLUMN]; $uUID = $this->properties[DB::USER_UID_COLUMN]; - $uUsername = $this->properties[DB::USER_USERNAME_COLUMN] || $this->properties[DB::USER_UID_COLUMN]; + $uUsername = $this->firstNonemptyProperty(DB::USER_USERNAME_COLUMN, DB::USER_UID_COLUMN); $ugGID = $this->properties[DB::USER_GROUP_GID_COLUMN]; $ugUID = $this->properties[DB::USER_GROUP_UID_COLUMN];