diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-04-10 14:19:56 +0200 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-04-10 14:19:56 +0200 |
commit | caff1023ea72bb2ea94130e18a2a6e2ccf819e5f (patch) | |
tree | 186d494c2aea5dea7255d3584ef5d595fc6e6194 /apps/user_ldap/lib/User | |
parent | edf8ce32cffdb920e8171207b342abbd7f1fbe73 (diff) | |
download | nextcloud-server-caff1023ea72bb2ea94130e18a2a6e2ccf819e5f.tar.gz nextcloud-server-caff1023ea72bb2ea94130e18a2a6e2ccf819e5f.zip |
Format control structures, classes, methods and function
To continue this formatting madness, here's a tiny patch that adds
unified formatting for control structures like if and loops as well as
classes, their methods and anonymous functions. This basically forces
the constructs to start on the same line. This is not exactly what PSR2
wants, but I think we can have a few exceptions with "our" style. The
starting of braces on the same line is pracrically standard for our
code.
This also removes and empty lines from method/function bodies at the
beginning and end.
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/user_ldap/lib/User')
-rw-r--r-- | apps/user_ldap/lib/User/DeletedUsersIndex.php | 8 | ||||
-rw-r--r-- | apps/user_ldap/lib/User/Manager.php | 24 | ||||
-rw-r--r-- | apps/user_ldap/lib/User/OfflineUser.php | 6 | ||||
-rw-r--r-- | apps/user_ldap/lib/User/User.php | 98 |
4 files changed, 66 insertions, 70 deletions
diff --git a/apps/user_ldap/lib/User/DeletedUsersIndex.php b/apps/user_ldap/lib/User/DeletedUsersIndex.php index 98de28b6925..fee2b02d2c3 100644 --- a/apps/user_ldap/lib/User/DeletedUsersIndex.php +++ b/apps/user_ldap/lib/User/DeletedUsersIndex.php @@ -71,7 +71,7 @@ class DeletedUsersIndex { 'user_ldap', 'isDeleted', '1'); $userObjects = []; - foreach($deletedUsers as $user) { + foreach ($deletedUsers as $user) { $userObjects[] = new OfflineUser($user, $this->config, $this->db, $this->mapping); } $this->deletedUsers = $userObjects; @@ -84,7 +84,7 @@ class DeletedUsersIndex { * @return \OCA\User_LDAP\User\OfflineUser[] */ public function getUsers() { - if(is_array($this->deletedUsers)) { + if (is_array($this->deletedUsers)) { return $this->deletedUsers; } return $this->fetchDeletedUsers(); @@ -95,7 +95,7 @@ class DeletedUsersIndex { * @return bool */ public function hasUsers() { - if(!is_array($this->deletedUsers)) { + if (!is_array($this->deletedUsers)) { $this->fetchDeletedUsers(); } return is_array($this->deletedUsers) && (count($this->deletedUsers) > 0); @@ -109,7 +109,7 @@ class DeletedUsersIndex { */ public function markUser($ocName) { $curValue = $this->config->getUserValue($ocName, 'user_ldap', 'isDeleted', '0'); - if($curValue === '1') { + if ($curValue === '1') { // the user is already marked, do not write to DB again return; } diff --git a/apps/user_ldap/lib/User/Manager.php b/apps/user_ldap/lib/User/Manager.php index f3729f2458e..a62aa3b39ac 100644 --- a/apps/user_ldap/lib/User/Manager.php +++ b/apps/user_ldap/lib/User/Manager.php @@ -97,7 +97,6 @@ class Manager { IAvatarManager $avatarManager, Image $image, IDBConnection $db, IUserManager $userManager, INotificationManager $notificationManager) { - $this->ocConfig = $ocConfig; $this->ocFilesystem = $ocFilesystem; $this->ocLog = $ocLog; @@ -142,7 +141,7 @@ class Manager { * @param $uid */ public function invalidate($uid) { - if(!isset($this->usersByUid[$uid])) { + if (!isset($this->usersByUid[$uid])) { return; } $dn = $this->usersByUid[$uid]->getDN(); @@ -156,7 +155,7 @@ class Manager { * @return null */ private function checkAccess() { - if(is_null($this->access)) { + if (is_null($this->access)) { throw new \Exception('LDAP Access instance must be set first'); } } @@ -181,11 +180,11 @@ class Manager { ]; $homeRule = $this->access->getConnection()->homeFolderNamingRule; - if(strpos($homeRule, 'attr:') === 0) { + if (strpos($homeRule, 'attr:') === 0) { $attributes[] = substr($homeRule, strlen('attr:')); } - if(!$minimal) { + if (!$minimal) { // attributes that are not really important but may come with big // payload. $attributes = array_merge( @@ -197,7 +196,7 @@ class Manager { $attributes = array_reduce($attributes, function ($list, $attribute) { $attribute = strtolower(trim((string)$attribute)); - if(!empty($attribute) && !in_array($attribute, $list)) { + if (!empty($attribute) && !in_array($attribute, $list)) { $list[] = $attribute; } @@ -240,11 +239,11 @@ class Manager { */ protected function createInstancyByUserName($id) { //most likely a uid. Check whether it is a deleted user - if($this->isDeletedUser($id)) { + if ($this->isDeletedUser($id)) { return $this->getDeletedUser($id); } $dn = $this->access->username2dn($id); - if($dn !== false) { + if ($dn !== false) { return $this->createAndCache($dn, $id); } return null; @@ -258,20 +257,19 @@ class Manager { */ public function get($id) { $this->checkAccess(); - if(isset($this->usersByDN[$id])) { + if (isset($this->usersByDN[$id])) { return $this->usersByDN[$id]; - } elseif(isset($this->usersByUid[$id])) { + } elseif (isset($this->usersByUid[$id])) { return $this->usersByUid[$id]; } - if($this->access->stringResemblesDN($id)) { + if ($this->access->stringResemblesDN($id)) { $uid = $this->access->dn2username($id); - if($uid !== false) { + if ($uid !== false) { return $this->createAndCache($id, $uid); } } return $this->createInstancyByUserName($id); } - } diff --git a/apps/user_ldap/lib/User/OfflineUser.php b/apps/user_ldap/lib/User/OfflineUser.php index 60a39e95022..72d29dd5441 100644 --- a/apps/user_ldap/lib/User/OfflineUser.php +++ b/apps/user_ldap/lib/User/OfflineUser.php @@ -203,7 +203,7 @@ class OfflineUser { 'email' => 'settings', 'lastLogin' => 'login', ]; - foreach($properties as $property => $app) { + foreach ($properties as $property => $app) { $this->$property = $this->config->getUserValue($this->ocName, $app, $property, ''); } @@ -226,7 +226,7 @@ class OfflineUser { ', 1); $query->execute([$this->ocName]); $sResult = $query->fetchColumn(0); - if((int)$sResult === 1) { + if ((int)$sResult === 1) { $this->hasActiveShares = true; return; } @@ -238,7 +238,7 @@ class OfflineUser { ', 1); $query->execute([$this->ocName]); $sResult = $query->fetchColumn(0); - if((int)$sResult === 1) { + if ((int)$sResult === 1) { $this->hasActiveShares = true; return; } diff --git a/apps/user_ldap/lib/User/User.php b/apps/user_ldap/lib/User/User.php index 28eeddccef0..724db063659 100644 --- a/apps/user_ldap/lib/User/User.php +++ b/apps/user_ldap/lib/User/User.php @@ -127,7 +127,6 @@ class User { IConfig $config, FilesystemHelper $fs, Image $image, LogWrapper $log, IAvatarManager $avatarManager, IUserManager $userManager, INotificationManager $notificationManager) { - if ($username === null) { $log->log("uid for '$dn' must not be null!", ILogger::ERROR); throw new \InvalidArgumentException('uid must not be null!'); @@ -156,17 +155,17 @@ class User { * @return null */ public function update() { - if(is_null($this->dn)) { + if (is_null($this->dn)) { return null; } $hasLoggedIn = $this->config->getUserValue($this->uid, 'user_ldap', self::USER_PREFKEY_FIRSTLOGIN, 0); - if($this->needsRefresh()) { + if ($this->needsRefresh()) { $this->updateEmail(); $this->updateQuota(); - if($hasLoggedIn !== 0) { + if ($hasLoggedIn !== 0) { //we do not need to try it, when the user has not been logged in //before, because the file system will not be ready. $this->updateAvatar(); @@ -184,7 +183,7 @@ class User { */ public function markUser() { $curValue = $this->config->getUserValue($this->getUsername(), 'user_ldap', 'isDeleted', '0'); - if($curValue === '1') { + if ($curValue === '1') { // the user is already marked, do not write to DB again return; } @@ -200,7 +199,7 @@ class User { $this->markRefreshTime(); //Quota $attr = strtolower($this->connection->ldapQuotaAttribute); - if(isset($ldapEntry[$attr])) { + if (isset($ldapEntry[$attr])) { $this->updateQuota($ldapEntry[$attr][0]); } else { if ($this->connection->ldapQuotaDefault !== '') { @@ -212,11 +211,11 @@ class User { //displayName $displayName = $displayName2 = ''; $attr = strtolower($this->connection->ldapUserDisplayName); - if(isset($ldapEntry[$attr])) { + if (isset($ldapEntry[$attr])) { $displayName = (string)$ldapEntry[$attr][0]; } $attr = strtolower($this->connection->ldapUserDisplayName2); - if(isset($ldapEntry[$attr])) { + if (isset($ldapEntry[$attr])) { $displayName2 = (string)$ldapEntry[$attr][0]; } if ($displayName !== '') { @@ -233,22 +232,22 @@ class User { //email must be stored after displayname, because it would cause a user //change event that will trigger fetching the display name again $attr = strtolower($this->connection->ldapEmailAttribute); - if(isset($ldapEntry[$attr])) { + if (isset($ldapEntry[$attr])) { $this->updateEmail($ldapEntry[$attr][0]); } unset($attr); // LDAP Username, needed for s2s sharing - if(isset($ldapEntry['uid'])) { + if (isset($ldapEntry['uid'])) { $this->storeLDAPUserName($ldapEntry['uid'][0]); - } elseif(isset($ldapEntry['samaccountname'])) { + } elseif (isset($ldapEntry['samaccountname'])) { $this->storeLDAPUserName($ldapEntry['samaccountname'][0]); } //homePath - if(strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) { + if (strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) { $attr = strtolower(substr($this->connection->homeFolderNamingRule, strlen('attr:'))); - if(isset($ldapEntry[$attr])) { + if (isset($ldapEntry[$attr])) { $this->access->cacheUserHome( $this->getUsername(), $this->getHomePath($ldapEntry[$attr][0])); } @@ -257,14 +256,14 @@ class User { //memberOf groups $cacheKey = 'getMemberOf'.$this->getUsername(); $groups = false; - if(isset($ldapEntry['memberof'])) { + if (isset($ldapEntry['memberof'])) { $groups = $ldapEntry['memberof']; } $this->connection->writeToCache($cacheKey, $groups); //external storage var $attr = strtolower($this->connection->ldapExtStorageHomeAttribute); - if(isset($ldapEntry[$attr])) { + if (isset($ldapEntry[$attr])) { $this->updateExtStorageHome($ldapEntry[$attr][0]); } unset($attr); @@ -273,8 +272,8 @@ class User { /** @var Connection $connection */ $connection = $this->access->getConnection(); $attributes = $connection->resolveRule('avatar'); - foreach ($attributes as $attribute) { - if(isset($ldapEntry[$attribute])) { + foreach ($attributes as $attribute) { + if (isset($ldapEntry[$attribute])) { $this->avatarImage = $ldapEntry[$attribute][0]; // the call to the method that saves the avatar in the file // system must be postponed after the login. It is to ensure @@ -314,8 +313,7 @@ class User { if (is_null($valueFromLDAP) && strpos($this->access->connection->homeFolderNamingRule, 'attr:') === 0 - && $this->access->connection->homeFolderNamingRule !== 'attr:') - { + && $this->access->connection->homeFolderNamingRule !== 'attr:') { $attr = substr($this->access->connection->homeFolderNamingRule, strlen('attr:')); $homedir = $this->access->readAttribute( $this->access->username2dn($this->getUsername()), $attr); @@ -327,7 +325,7 @@ class User { if ($path !== '') { //if attribute's value is an absolute path take this, otherwise append it to data dir //check for / at the beginning or pattern c:\ resp. c:/ - if('/' !== $path[0] + if ('/' !== $path[0] && !(3 < strlen($path) && ctype_alpha($path[0]) && $path[1] === ':' && ('\\' === $path[2] || '/' === $path[2])) ) { @@ -342,7 +340,7 @@ class User { return $path; } - if(!is_null($attr) + if (!is_null($attr) && $this->config->getAppValue('user_ldap', 'enforce_home_folder_naming_rule', true) ) { // a naming rule attribute is defined, but it doesn't exist for that LDAP user @@ -357,7 +355,7 @@ class User { public function getMemberOfGroups() { $cacheKey = 'getMemberOf'.$this->getUsername(); $memberOfGroups = $this->connection->getFromCache($cacheKey); - if(!is_null($memberOfGroups)) { + if (!is_null($memberOfGroups)) { return $memberOfGroups; } $groupDNs = $this->access->readAttribute($this->getDN(), 'memberOf'); @@ -370,7 +368,7 @@ class User { * @return string data (provided by LDAP) | false */ public function getAvatarImage() { - if(!is_null($this->avatarImage)) { + if (!is_null($this->avatarImage)) { return $this->avatarImage; } @@ -378,9 +376,9 @@ class User { /** @var Connection $connection */ $connection = $this->access->getConnection(); $attributes = $connection->resolveRule('avatar'); - foreach($attributes as $attribute) { + foreach ($attributes as $attribute) { $result = $this->access->readAttribute($this->dn, $attribute); - if($result !== false && is_array($result) && isset($result[0])) { + if ($result !== false && is_array($result) && isset($result[0])) { $this->avatarImage = $result[0]; break; } @@ -417,7 +415,7 @@ class User { $lastChecked = $this->config->getUserValue($this->uid, 'user_ldap', self::USER_PREFKEY_LASTREFRESH, 0); - if((time() - (int)$lastChecked) < (int)$this->config->getAppValue('user_ldap', 'updateAttributesInterval', 86400)) { + if ((time() - (int)$lastChecked) < (int)$this->config->getAppValue('user_ldap', 'updateAttributesInterval', 86400)) { return false; } return true; @@ -443,11 +441,11 @@ class User { */ public function composeAndStoreDisplayName($displayName, $displayName2 = '') { $displayName2 = (string)$displayName2; - if($displayName2 !== '') { + if ($displayName2 !== '') { $displayName .= ' (' . $displayName2 . ')'; } $oldName = $this->config->getUserValue($this->uid, 'user_ldap', 'displayName', null); - if ($oldName !== $displayName) { + if ($oldName !== $displayName) { $this->store('displayName', $displayName); $user = $this->userManager->get($this->getUsername()); if (!empty($oldName) && $user instanceof \OC\User\User) { @@ -475,7 +473,7 @@ class User { * @return bool */ private function wasRefreshed($feature) { - if(isset($this->refreshedFeatures[$feature])) { + if (isset($this->refreshedFeatures[$feature])) { return true; } $this->refreshedFeatures[$feature] = 1; @@ -488,15 +486,15 @@ class User { * @return null */ public function updateEmail($valueFromLDAP = null) { - if($this->wasRefreshed('email')) { + if ($this->wasRefreshed('email')) { return; } $email = (string)$valueFromLDAP; - if(is_null($valueFromLDAP)) { + if (is_null($valueFromLDAP)) { $emailAttribute = $this->connection->ldapEmailAttribute; if ($emailAttribute !== '') { $aEmail = $this->access->readAttribute($this->dn, $emailAttribute); - if(is_array($aEmail) && (count($aEmail) > 0)) { + if (is_array($aEmail) && (count($aEmail) > 0)) { $email = (string)$aEmail[0]; } } @@ -533,22 +531,22 @@ class User { * @return null */ public function updateQuota($valueFromLDAP = null) { - if($this->wasRefreshed('quota')) { + if ($this->wasRefreshed('quota')) { return; } $quotaAttribute = $this->connection->ldapQuotaAttribute; $defaultQuota = $this->connection->ldapQuotaDefault; - if($quotaAttribute === '' && $defaultQuota === '') { + if ($quotaAttribute === '' && $defaultQuota === '') { return; } $quota = false; - if(is_null($valueFromLDAP) && $quotaAttribute !== '') { + if (is_null($valueFromLDAP) && $quotaAttribute !== '') { $aQuota = $this->access->readAttribute($this->dn, $quotaAttribute); - if($aQuota && (count($aQuota) > 0) && $this->verifyQuotaValue($aQuota[0])) { + if ($aQuota && (count($aQuota) > 0) && $this->verifyQuotaValue($aQuota[0])) { $quota = $aQuota[0]; - } elseif(is_array($aQuota) && isset($aQuota[0])) { + } elseif (is_array($aQuota) && isset($aQuota[0])) { $this->log->log('no suitable LDAP quota found for user ' . $this->uid . ': [' . $aQuota[0] . ']', ILogger::DEBUG); } } elseif ($this->verifyQuotaValue($valueFromLDAP)) { @@ -560,7 +558,7 @@ class User { if ($quota === false && $this->verifyQuotaValue($defaultQuota)) { // quota not found using the LDAP attribute (or not parseable). Try the default quota $quota = $defaultQuota; - } elseif($quota === false) { + } elseif ($quota === false) { $this->log->log('no suitable default quota found for user ' . $this->uid . ': [' . $defaultQuota . ']', ILogger::DEBUG); return; } @@ -583,7 +581,7 @@ class User { * @param array $params */ public function updateAvatarPostLogin($params) { - if(isset($params['uid']) && $params['uid'] === $this->getUsername()) { + if (isset($params['uid']) && $params['uid'] === $this->getUsername()) { $this->updateAvatar(); } } @@ -593,29 +591,29 @@ class User { * @return bool */ public function updateAvatar($force = false) { - if(!$force && $this->wasRefreshed('avatar')) { + if (!$force && $this->wasRefreshed('avatar')) { return false; } $avatarImage = $this->getAvatarImage(); - if($avatarImage === false) { + if ($avatarImage === false) { //not set, nothing left to do; return false; } - if(!$this->image->loadFromBase64(base64_encode($avatarImage))) { + if (!$this->image->loadFromBase64(base64_encode($avatarImage))) { return false; } // use the checksum before modifications $checksum = md5($this->image->data()); - if($checksum === $this->config->getUserValue($this->uid, 'user_ldap', 'lastAvatarChecksum', '')) { + if ($checksum === $this->config->getUserValue($this->uid, 'user_ldap', 'lastAvatarChecksum', '')) { return true; } $isSet = $this->setOwnCloudAvatar(); - if($isSet) { + if ($isSet) { // save checksum only after successful setting $this->config->setUserValue($this->uid, 'user_ldap', 'lastAvatarChecksum', $checksum); } @@ -628,7 +626,7 @@ class User { * @return bool */ private function setOwnCloudAvatar() { - if(!$this->image->valid()) { + if (!$this->image->valid()) { $this->log->log('avatar image data from LDAP invalid for '.$this->dn, ILogger::ERROR); return false; } @@ -636,12 +634,12 @@ class User { //make sure it is a square and not bigger than 128x128 $size = min([$this->image->width(), $this->image->height(), 128]); - if(!$this->image->centerCrop($size)) { + if (!$this->image->centerCrop($size)) { $this->log->log('croping image for avatar failed for '.$this->dn, ILogger::ERROR); return false; } - if(!$this->fs->isLoaded()) { + if (!$this->fs->isLoaded()) { $this->fs->setup($this->uid); } @@ -717,7 +715,7 @@ class User { if (array_key_exists('pwdpolicysubentry', $result[0])) { $pwdPolicySubentry = $result[0]['pwdpolicysubentry']; - if ($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)){ + if ($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)) { $ppolicyDN = $pwdPolicySubentry[0];//custom ppolicy DN } } @@ -729,7 +727,7 @@ class User { //retrieve relevant password policy attributes $cacheKey = 'ppolicyAttributes' . $ppolicyDN; $result = $this->connection->getFromCache($cacheKey); - if(is_null($result)) { + if (is_null($result)) { $result = $this->access->search('objectclass=*', [$ppolicyDN], ['pwdgraceauthnlimit', 'pwdmaxage', 'pwdexpirewarning']); $this->connection->writeToCache($cacheKey, $result); } @@ -764,7 +762,7 @@ class User { && !empty($pwdExpireWarning)) { $pwdMaxAgeInt = (int)$pwdMaxAge[0]; $pwdExpireWarningInt = (int)$pwdExpireWarning[0]; - if ($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0){ + if ($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0) { $pwdChangedTimeDt = \DateTime::createFromFormat('YmdHisZ', $pwdChangedTime[0]); $pwdChangedTimeDt->add(new \DateInterval('PT'.$pwdMaxAgeInt.'S')); $currentDateTime = new \DateTime(); |