Passed
Push — master ( bbba7b...22edb6 )
by Blizzz
09:41 queued 12s
created
lib/private/DB/PgSqlTools.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@
 block discarded – undo
49 49
 	 * @return null
50 50
 	 */
51 51
 	public function resynchronizeDatabaseSequences(Connection $conn) {
52
-		$filterExpression = '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/';
52
+		$filterExpression = '/^'.preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')).'/';
53 53
 		$databaseName = $conn->getDatabase();
54 54
 		$conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression);
55 55
 
Please login to merge, or discard this patch.
apps/files_versions/lib/Expiration.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	/** @var bool */
48 48
 	private $canPurgeToSaveSpace;
49 49
 
50
-	public function __construct(IConfig $config,ITimeFactory $timeFactory){
50
+	public function __construct(IConfig $config, ITimeFactory $timeFactory) {
51 51
 		$this->timeFactory = $timeFactory;
52 52
 		$this->retentionObligation = $config->getSystemValue('versions_retention_obligation', 'auto');
53 53
 
@@ -60,14 +60,14 @@  discard block
 block discarded – undo
60 60
 	 * Is versions expiration enabled
61 61
 	 * @return bool
62 62
 	 */
63
-	public function isEnabled(){
63
+	public function isEnabled() {
64 64
 		return $this->retentionObligation !== 'disabled';
65 65
 	}
66 66
 
67 67
 	/**
68 68
 	 * Is default expiration active
69 69
 	 */
70
-	public function shouldAutoExpire(){
70
+	public function shouldAutoExpire() {
71 71
 		return $this->minAge === self::NO_OBLIGATION
72 72
 				|| $this->maxAge === self::NO_OBLIGATION;
73 73
 	}
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 	 * @param bool $quotaExceeded
79 79
 	 * @return bool
80 80
 	 */
81
-	public function isExpired($timestamp, $quotaExceeded = false){
81
+	public function isExpired($timestamp, $quotaExceeded = false) {
82 82
 		// No expiration if disabled
83 83
 		if (!$this->isEnabled()) {
84 84
 			return false;
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 		$time = $this->timeFactory->getTime();
93 93
 		// Never expire dates in future e.g. misconfiguration or negative time
94 94
 		// adjustment
95
-		if ($time<$timestamp) {
95
+		if ($time < $timestamp) {
96 96
 			return false;
97 97
 		}
98 98
 
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	 * Get maximal retention obligation as a timestamp
120 120
 	 * @return int
121 121
 	 */
122
-	public function getMaxAgeAsTimestamp(){
122
+	public function getMaxAgeAsTimestamp() {
123 123
 		$maxAge = false;
124 124
 		if ($this->isEnabled() && $this->maxAge !== self::NO_OBLIGATION) {
125 125
 			$time = $this->timeFactory->getTime();
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 	 * Read versions_retention_obligation, validate it 
133 133
 	 * and set private members accordingly
134 134
 	 */
135
-	private function parseRetentionObligation(){
135
+	private function parseRetentionObligation() {
136 136
 		$splitValues = explode(',', $this->retentionObligation);
137 137
 		if (!isset($splitValues[0])) {
138 138
 			$minValue = 'auto';
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 		if (!ctype_digit($minValue) && $minValue !== 'auto') {
152 152
 			$isValid = false;
153 153
 			\OC::$server->getLogger()->warning(
154
-					$minValue . ' is not a valid value for minimal versions retention obligation. Check versions_retention_obligation in your config.php. Falling back to auto.',
154
+					$minValue.' is not a valid value for minimal versions retention obligation. Check versions_retention_obligation in your config.php. Falling back to auto.',
155 155
 					['app'=>'files_versions']
156 156
 			);
157 157
 		}
@@ -159,12 +159,12 @@  discard block
 block discarded – undo
159 159
 		if (!ctype_digit($maxValue) && $maxValue !== 'auto') {
160 160
 			$isValid = false;
161 161
 			\OC::$server->getLogger()->warning(
162
-					$maxValue . ' is not a valid value for maximal versions retention obligation. Check versions_retention_obligation in your config.php. Falling back to auto.',
162
+					$maxValue.' is not a valid value for maximal versions retention obligation. Check versions_retention_obligation in your config.php. Falling back to auto.',
163 163
 					['app'=>'files_versions']
164 164
 			);
165 165
 		}
166 166
 
167
-		if (!$isValid){
167
+		if (!$isValid) {
168 168
 			$minValue = 'auto';
169 169
 			$maxValue = 'auto';
170 170
 		}
@@ -177,13 +177,13 @@  discard block
 block discarded – undo
177 177
 			$this->canPurgeToSaveSpace = true;
178 178
 		} elseif ($minValue !== 'auto' && $maxValue === 'auto') {
179 179
 			// Keep for X days but delete anytime if space needed
180
-			$this->minAge = (int)$minValue;
180
+			$this->minAge = (int) $minValue;
181 181
 			$this->maxAge = self::NO_OBLIGATION;
182 182
 			$this->canPurgeToSaveSpace = true;
183 183
 		} elseif ($minValue === 'auto' && $maxValue !== 'auto') {
184 184
 			// Delete anytime if space needed, Delete all older than max automatically
185 185
 			$this->minAge = self::NO_OBLIGATION;
186
-			$this->maxAge = (int)$maxValue;
186
+			$this->maxAge = (int) $maxValue;
187 187
 			$this->canPurgeToSaveSpace = true;
188 188
 		} elseif ($minValue !== 'auto' && $maxValue !== 'auto') {
189 189
 			// Delete all older than max OR older than min if space needed
@@ -193,8 +193,8 @@  discard block
 block discarded – undo
193 193
 				$maxValue = $minValue;
194 194
 			}
195 195
 
196
-			$this->minAge = (int)$minValue;
197
-			$this->maxAge = (int)$maxValue;
196
+			$this->minAge = (int) $minValue;
197
+			$this->maxAge = (int) $maxValue;
198 198
 			$this->canPurgeToSaveSpace = false;
199 199
 		}
200 200
 	}
Please login to merge, or discard this patch.
apps/user_ldap/lib/Group_LDAP.php 1 patch
Spacing   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 		parent::__construct($access);
74 74
 		$filter = $this->access->connection->ldapGroupFilter;
75 75
 		$gassoc = $this->access->connection->ldapGroupMemberAssocAttr;
76
-		if(!empty($filter) && !empty($gassoc)) {
76
+		if (!empty($filter) && !empty($gassoc)) {
77 77
 			$this->enabled = true;
78 78
 		}
79 79
 
@@ -92,25 +92,25 @@  discard block
 block discarded – undo
92 92
 	 * Checks whether the user is member of a group or not.
93 93
 	 */
94 94
 	public function inGroup($uid, $gid) {
95
-		if(!$this->enabled) {
95
+		if (!$this->enabled) {
96 96
 			return false;
97 97
 		}
98 98
 		$cacheKey = 'inGroup'.$uid.':'.$gid;
99 99
 		$inGroup = $this->access->connection->getFromCache($cacheKey);
100
-		if(!is_null($inGroup)) {
101
-			return (bool)$inGroup;
100
+		if (!is_null($inGroup)) {
101
+			return (bool) $inGroup;
102 102
 		}
103 103
 
104 104
 		$userDN = $this->access->username2dn($uid);
105 105
 
106
-		if(isset($this->cachedGroupMembers[$gid])) {
106
+		if (isset($this->cachedGroupMembers[$gid])) {
107 107
 			$isInGroup = in_array($userDN, $this->cachedGroupMembers[$gid]);
108 108
 			return $isInGroup;
109 109
 		}
110 110
 
111 111
 		$cacheKeyMembers = 'inGroup-members:'.$gid;
112 112
 		$members = $this->access->connection->getFromCache($cacheKeyMembers);
113
-		if(!is_null($members)) {
113
+		if (!is_null($members)) {
114 114
 			$this->cachedGroupMembers[$gid] = $members;
115 115
 			$isInGroup = in_array($userDN, $members, true);
116 116
 			$this->access->connection->writeToCache($cacheKey, $isInGroup);
@@ -119,34 +119,34 @@  discard block
 block discarded – undo
119 119
 
120 120
 		$groupDN = $this->access->groupname2dn($gid);
121 121
 		// just in case
122
-		if(!$groupDN || !$userDN) {
122
+		if (!$groupDN || !$userDN) {
123 123
 			$this->access->connection->writeToCache($cacheKey, false);
124 124
 			return false;
125 125
 		}
126 126
 
127 127
 		//check primary group first
128
-		if($gid === $this->getUserPrimaryGroup($userDN)) {
128
+		if ($gid === $this->getUserPrimaryGroup($userDN)) {
129 129
 			$this->access->connection->writeToCache($cacheKey, true);
130 130
 			return true;
131 131
 		}
132 132
 
133 133
 		//usually, LDAP attributes are said to be case insensitive. But there are exceptions of course.
134 134
 		$members = $this->_groupMembers($groupDN);
135
-		if(!is_array($members) || count($members) === 0) {
135
+		if (!is_array($members) || count($members) === 0) {
136 136
 			$this->access->connection->writeToCache($cacheKey, false);
137 137
 			return false;
138 138
 		}
139 139
 
140 140
 		//extra work if we don't get back user DNs
141
-		if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
141
+		if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
142 142
 			$dns = [];
143 143
 			$filterParts = [];
144 144
 			$bytes = 0;
145
-			foreach($members as $mid) {
145
+			foreach ($members as $mid) {
146 146
 				$filter = str_replace('%uid', $mid, $this->access->connection->ldapLoginFilter);
147 147
 				$filterParts[] = $filter;
148 148
 				$bytes += strlen($filter);
149
-				if($bytes >= 9000000) {
149
+				if ($bytes >= 9000000) {
150 150
 					// AD has a default input buffer of 10 MB, we do not want
151 151
 					// to take even the chance to exceed it
152 152
 					$filter = $this->access->combineFilterWithOr($filterParts);
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 					$dns = array_merge($dns, $users);
157 157
 				}
158 158
 			}
159
-			if(count($filterParts) > 0) {
159
+			if (count($filterParts) > 0) {
160 160
 				$filter = $this->access->combineFilterWithOr($filterParts);
161 161
 				$users = $this->access->fetchListOfUsers($filter, 'dn', count($filterParts));
162 162
 				$dns = array_merge($dns, $users);
@@ -199,14 +199,14 @@  discard block
 block discarded – undo
199 199
 			$pos = strpos($memberURLs[0], '(');
200 200
 			if ($pos !== false) {
201 201
 				$memberUrlFilter = substr($memberURLs[0], $pos);
202
-				$foundMembers = $this->access->searchUsers($memberUrlFilter,'dn');
202
+				$foundMembers = $this->access->searchUsers($memberUrlFilter, 'dn');
203 203
 				$dynamicMembers = [];
204
-				foreach($foundMembers as $value) {
204
+				foreach ($foundMembers as $value) {
205 205
 					$dynamicMembers[$value['dn'][0]] = 1;
206 206
 				}
207 207
 			} else {
208 208
 				\OCP\Util::writeLog('user_ldap', 'No search filter found on member url '.
209
-					'of group ' . $dnGroup, ILogger::DEBUG);
209
+					'of group '.$dnGroup, ILogger::DEBUG);
210 210
 			}
211 211
 		}
212 212
 		return $dynamicMembers;
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 		// used extensively in cron job, caching makes sense for nested groups
231 231
 		$cacheKey = '_groupMembers'.$dnGroup;
232 232
 		$groupMembers = $this->access->connection->getFromCache($cacheKey);
233
-		if($groupMembers !== null) {
233
+		if ($groupMembers !== null) {
234 234
 			return $groupMembers;
235 235
 		}
236 236
 		$seen[$dnGroup] = 1;
@@ -290,10 +290,10 @@  discard block
 block discarded – undo
290 290
 		$recordMode = is_array($list) && isset($list[0]) && is_array($list[0]) && isset($list[0]['dn'][0]);
291 291
 
292 292
 		if ($nesting !== 1) {
293
-			if($recordMode) {
293
+			if ($recordMode) {
294 294
 				// the keys are numeric, but should hold the DN
295
-				return array_reduce($list, function ($transformed, $record) use ($dn) {
296
-					if($record['dn'][0] != $dn) {
295
+				return array_reduce($list, function($transformed, $record) use ($dn) {
296
+					if ($record['dn'][0] != $dn) {
297 297
 						$transformed[$record['dn'][0]] = $record;
298 298
 					}
299 299
 					return $transformed;
@@ -324,9 +324,9 @@  discard block
 block discarded – undo
324 324
 	 * @return string|bool
325 325
 	 */
326 326
 	public function gidNumber2Name($gid, $dn) {
327
-		$cacheKey = 'gidNumberToName' . $gid;
327
+		$cacheKey = 'gidNumberToName'.$gid;
328 328
 		$groupName = $this->access->connection->getFromCache($cacheKey);
329
-		if(!is_null($groupName) && isset($groupName)) {
329
+		if (!is_null($groupName) && isset($groupName)) {
330 330
 			return $groupName;
331 331
 		}
332 332
 
@@ -334,10 +334,10 @@  discard block
 block discarded – undo
334 334
 		$filter = $this->access->combineFilterWithAnd([
335 335
 			$this->access->connection->ldapGroupFilter,
336 336
 			'objectClass=posixGroup',
337
-			$this->access->connection->ldapGidNumber . '=' . $gid
337
+			$this->access->connection->ldapGidNumber.'='.$gid
338 338
 		]);
339 339
 		$result = $this->access->searchGroups($filter, ['dn'], 1);
340
-		if(empty($result)) {
340
+		if (empty($result)) {
341 341
 			return false;
342 342
 		}
343 343
 		$dn = $result[0]['dn'][0];
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
 	 */
361 361
 	private function getEntryGidNumber($dn, $attribute) {
362 362
 		$value = $this->access->readAttribute($dn, $attribute);
363
-		if(is_array($value) && !empty($value)) {
363
+		if (is_array($value) && !empty($value)) {
364 364
 			return $value[0];
365 365
 		}
366 366
 		return false;
@@ -382,9 +382,9 @@  discard block
 block discarded – undo
382 382
 	 */
383 383
 	public function getUserGidNumber($dn) {
384 384
 		$gidNumber = false;
385
-		if($this->access->connection->hasGidNumber) {
385
+		if ($this->access->connection->hasGidNumber) {
386 386
 			$gidNumber = $this->getEntryGidNumber($dn, $this->access->connection->ldapGidNumber);
387
-			if($gidNumber === false) {
387
+			if ($gidNumber === false) {
388 388
 				$this->access->connection->hasGidNumber = false;
389 389
 			}
390 390
 		}
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
 	 */
402 402
 	private function prepareFilterForUsersHasGidNumber($groupDN, $search = '') {
403 403
 		$groupID = $this->getGroupGidNumber($groupDN);
404
-		if($groupID === false) {
404
+		if ($groupID === false) {
405 405
 			throw new \Exception('Not a valid group');
406 406
 		}
407 407
 
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
 		if ($search !== '') {
411 411
 			$filterParts[] = $this->access->getFilterPartForUserSearch($search);
412 412
 		}
413
-		$filterParts[] = $this->access->connection->ldapGidNumber .'=' . $groupID;
413
+		$filterParts[] = $this->access->connection->ldapGidNumber.'='.$groupID;
414 414
 
415 415
 		return $this->access->combineFilterWithAnd($filterParts);
416 416
 	}
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
 		try {
453 453
 			$filter = $this->prepareFilterForUsersHasGidNumber($groupDN, $search);
454 454
 			$users = $this->access->countUsers($filter, ['dn'], $limit, $offset);
455
-			return (int)$users;
455
+			return (int) $users;
456 456
 		} catch (\Exception $e) {
457 457
 			return 0;
458 458
 		}
@@ -465,9 +465,9 @@  discard block
 block discarded – undo
465 465
 	 */
466 466
 	public function getUserGroupByGid($dn) {
467 467
 		$groupID = $this->getUserGidNumber($dn);
468
-		if($groupID !== false) {
468
+		if ($groupID !== false) {
469 469
 			$groupName = $this->gidNumber2Name($groupID, $dn);
470
-			if($groupName !== false) {
470
+			if ($groupName !== false) {
471 471
 				return $groupName;
472 472
 			}
473 473
 		}
@@ -484,22 +484,22 @@  discard block
 block discarded – undo
484 484
 	public function primaryGroupID2Name($gid, $dn) {
485 485
 		$cacheKey = 'primaryGroupIDtoName';
486 486
 		$groupNames = $this->access->connection->getFromCache($cacheKey);
487
-		if(!is_null($groupNames) && isset($groupNames[$gid])) {
487
+		if (!is_null($groupNames) && isset($groupNames[$gid])) {
488 488
 			return $groupNames[$gid];
489 489
 		}
490 490
 
491 491
 		$domainObjectSid = $this->access->getSID($dn);
492
-		if($domainObjectSid === false) {
492
+		if ($domainObjectSid === false) {
493 493
 			return false;
494 494
 		}
495 495
 
496 496
 		//we need to get the DN from LDAP
497 497
 		$filter = $this->access->combineFilterWithAnd([
498 498
 			$this->access->connection->ldapGroupFilter,
499
-			'objectsid=' . $domainObjectSid . '-' . $gid
499
+			'objectsid='.$domainObjectSid.'-'.$gid
500 500
 		]);
501 501
 		$result = $this->access->searchGroups($filter, ['dn'], 1);
502
-		if(empty($result)) {
502
+		if (empty($result)) {
503 503
 			return false;
504 504
 		}
505 505
 		$dn = $result[0]['dn'][0];
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
 	 */
523 523
 	private function getEntryGroupID($dn, $attribute) {
524 524
 		$value = $this->access->readAttribute($dn, $attribute);
525
-		if(is_array($value) && !empty($value)) {
525
+		if (is_array($value) && !empty($value)) {
526 526
 			return $value[0];
527 527
 		}
528 528
 		return false;
@@ -544,9 +544,9 @@  discard block
 block discarded – undo
544 544
 	 */
545 545
 	public function getUserPrimaryGroupIDs($dn) {
546 546
 		$primaryGroupID = false;
547
-		if($this->access->connection->hasPrimaryGroups) {
547
+		if ($this->access->connection->hasPrimaryGroups) {
548 548
 			$primaryGroupID = $this->getEntryGroupID($dn, 'primaryGroupID');
549
-			if($primaryGroupID === false) {
549
+			if ($primaryGroupID === false) {
550 550
 				$this->access->connection->hasPrimaryGroups = false;
551 551
 			}
552 552
 		}
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
 	 */
564 564
 	private function prepareFilterForUsersInPrimaryGroup($groupDN, $search = '') {
565 565
 		$groupID = $this->getGroupPrimaryGroupID($groupDN);
566
-		if($groupID === false) {
566
+		if ($groupID === false) {
567 567
 			throw new \Exception('Not a valid group');
568 568
 		}
569 569
 
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
 		if ($search !== '') {
573 573
 			$filterParts[] = $this->access->getFilterPartForUserSearch($search);
574 574
 		}
575
-		$filterParts[] = 'primaryGroupID=' . $groupID;
575
+		$filterParts[] = 'primaryGroupID='.$groupID;
576 576
 
577 577
 		return $this->access->combineFilterWithAnd($filterParts);
578 578
 	}
@@ -614,7 +614,7 @@  discard block
 block discarded – undo
614 614
 		try {
615 615
 			$filter = $this->prepareFilterForUsersInPrimaryGroup($groupDN, $search);
616 616
 			$users = $this->access->countUsers($filter, ['dn'], $limit, $offset);
617
-			return (int)$users;
617
+			return (int) $users;
618 618
 		} catch (\Exception $e) {
619 619
 			return 0;
620 620
 		}
@@ -627,9 +627,9 @@  discard block
 block discarded – undo
627 627
 	 */
628 628
 	public function getUserPrimaryGroup($dn) {
629 629
 		$groupID = $this->getUserPrimaryGroupIDs($dn);
630
-		if($groupID !== false) {
630
+		if ($groupID !== false) {
631 631
 			$groupName = $this->primaryGroupID2Name($groupID, $dn);
632
-			if($groupName !== false) {
632
+			if ($groupName !== false) {
633 633
 				return $groupName;
634 634
 			}
635 635
 		}
@@ -648,16 +648,16 @@  discard block
 block discarded – undo
648 648
 	 * This function includes groups based on dynamic group membership.
649 649
 	 */
650 650
 	public function getUserGroups($uid) {
651
-		if(!$this->enabled) {
651
+		if (!$this->enabled) {
652 652
 			return [];
653 653
 		}
654 654
 		$cacheKey = 'getUserGroups'.$uid;
655 655
 		$userGroups = $this->access->connection->getFromCache($cacheKey);
656
-		if(!is_null($userGroups)) {
656
+		if (!is_null($userGroups)) {
657 657
 			return $userGroups;
658 658
 		}
659 659
 		$userDN = $this->access->username2dn($uid);
660
-		if(!$userDN) {
660
+		if (!$userDN) {
661 661
 			$this->access->connection->writeToCache($cacheKey, []);
662 662
 			return [];
663 663
 		}
@@ -671,14 +671,14 @@  discard block
 block discarded – undo
671 671
 		if (!empty($dynamicGroupMemberURL)) {
672 672
 			// look through dynamic groups to add them to the result array if needed
673 673
 			$groupsToMatch = $this->access->fetchListOfGroups(
674
-				$this->access->connection->ldapGroupFilter,['dn',$dynamicGroupMemberURL]);
675
-			foreach($groupsToMatch as $dynamicGroup) {
674
+				$this->access->connection->ldapGroupFilter, ['dn', $dynamicGroupMemberURL]);
675
+			foreach ($groupsToMatch as $dynamicGroup) {
676 676
 				if (!array_key_exists($dynamicGroupMemberURL, $dynamicGroup)) {
677 677
 					continue;
678 678
 				}
679 679
 				$pos = strpos($dynamicGroup[$dynamicGroupMemberURL][0], '(');
680 680
 				if ($pos !== false) {
681
-					$memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0],$pos);
681
+					$memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0], $pos);
682 682
 					// apply filter via ldap search to see if this user is in this
683 683
 					// dynamic group
684 684
 					$userMatch = $this->access->readAttribute(
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
 					if ($userMatch !== false) {
690 690
 						// match found so this user is in this group
691 691
 						$groupName = $this->access->dn2groupname($dynamicGroup['dn'][0]);
692
-						if(is_string($groupName)) {
692
+						if (is_string($groupName)) {
693 693
 							// be sure to never return false if the dn could not be
694 694
 							// resolved to a name, for whatever reason.
695 695
 							$groups[] = $groupName;
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
 					}
698 698
 				} else {
699 699
 					\OCP\Util::writeLog('user_ldap', 'No search filter found on member url '.
700
-						'of group ' . print_r($dynamicGroup, true), ILogger::DEBUG);
700
+						'of group '.print_r($dynamicGroup, true), ILogger::DEBUG);
701 701
 				}
702 702
 			}
703 703
 		}
@@ -705,15 +705,15 @@  discard block
 block discarded – undo
705 705
 		// if possible, read out membership via memberOf. It's far faster than
706 706
 		// performing a search, which still is a fallback later.
707 707
 		// memberof doesn't support memberuid, so skip it here.
708
-		if((int)$this->access->connection->hasMemberOfFilterSupport === 1
709
-			&& (int)$this->access->connection->useMemberOfToDetectMembership === 1
708
+		if ((int) $this->access->connection->hasMemberOfFilterSupport === 1
709
+			&& (int) $this->access->connection->useMemberOfToDetectMembership === 1
710 710
 		    && strtolower($this->access->connection->ldapGroupMemberAssocAttr) !== 'memberuid'
711 711
 		    ) {
712 712
 			$groupDNs = $this->_getGroupDNsFromMemberOf($userDN);
713 713
 			if (is_array($groupDNs)) {
714 714
 				foreach ($groupDNs as $dn) {
715 715
 					$groupName = $this->access->dn2groupname($dn);
716
-					if(is_string($groupName)) {
716
+					if (is_string($groupName)) {
717 717
 						// be sure to never return false if the dn could not be
718 718
 						// resolved to a name, for whatever reason.
719 719
 						$groups[] = $groupName;
@@ -721,10 +721,10 @@  discard block
 block discarded – undo
721 721
 				}
722 722
 			}
723 723
 
724
-			if($primaryGroup !== false) {
724
+			if ($primaryGroup !== false) {
725 725
 				$groups[] = $primaryGroup;
726 726
 			}
727
-			if($gidGroupName !== false) {
727
+			if ($gidGroupName !== false) {
728 728
 				$groups[] = $gidGroupName;
729 729
 			}
730 730
 			$this->access->connection->writeToCache($cacheKey, $groups);
@@ -732,14 +732,14 @@  discard block
 block discarded – undo
732 732
 		}
733 733
 
734 734
 		//uniqueMember takes DN, memberuid the uid, so we need to distinguish
735
-		if((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember')
735
+		if ((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember')
736 736
 			|| (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'member')
737 737
 		) {
738 738
 			$uid = $userDN;
739
-		} else if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
739
+		} else if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
740 740
 			$result = $this->access->readAttribute($userDN, 'uid');
741 741
 			if ($result === false) {
742
-				\OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN ' . $userDN . ' on '.
742
+				\OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN '.$userDN.' on '.
743 743
 					$this->access->connection->ldapHost, ILogger::DEBUG);
744 744
 				$uid = false;
745 745
 			} else {
@@ -750,7 +750,7 @@  discard block
 block discarded – undo
750 750
 			$uid = $userDN;
751 751
 		}
752 752
 
753
-		if($uid !== false) {
753
+		if ($uid !== false) {
754 754
 			if (isset($this->cachedGroupsByMember[$uid])) {
755 755
 				$groups = array_merge($groups, $this->cachedGroupsByMember[$uid]);
756 756
 			} else {
@@ -761,10 +761,10 @@  discard block
 block discarded – undo
761 761
 			}
762 762
 		}
763 763
 
764
-		if($primaryGroup !== false) {
764
+		if ($primaryGroup !== false) {
765 765
 			$groups[] = $primaryGroup;
766 766
 		}
767
-		if($gidGroupName !== false) {
767
+		if ($gidGroupName !== false) {
768 768
 			$groups[] = $gidGroupName;
769 769
 		}
770 770
 
@@ -793,8 +793,8 @@  discard block
 block discarded – undo
793 793
 		$groups = $this->access->fetchListOfGroups($filter,
794 794
 			[$this->access->connection->ldapGroupDisplayName, 'dn']);
795 795
 		if (is_array($groups)) {
796
-			$fetcher = function ($dn, &$seen) {
797
-				if(is_array($dn) && isset($dn['dn'][0])) {
796
+			$fetcher = function($dn, &$seen) {
797
+				if (is_array($dn) && isset($dn['dn'][0])) {
798 798
 					$dn = $dn['dn'][0];
799 799
 				}
800 800
 				return $this->getGroupsByMember($dn, $seen);
@@ -816,33 +816,33 @@  discard block
 block discarded – undo
816 816
 	 * @throws \Exception
817 817
 	 */
818 818
 	public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
819
-		if(!$this->enabled) {
819
+		if (!$this->enabled) {
820 820
 			return [];
821 821
 		}
822
-		if(!$this->groupExists($gid)) {
822
+		if (!$this->groupExists($gid)) {
823 823
 			return [];
824 824
 		}
825 825
 		$search = $this->access->escapeFilterPart($search, true);
826 826
 		$cacheKey = 'usersInGroup-'.$gid.'-'.$search.'-'.$limit.'-'.$offset;
827 827
 		// check for cache of the exact query
828 828
 		$groupUsers = $this->access->connection->getFromCache($cacheKey);
829
-		if(!is_null($groupUsers)) {
829
+		if (!is_null($groupUsers)) {
830 830
 			return $groupUsers;
831 831
 		}
832 832
 
833 833
 		// check for cache of the query without limit and offset
834 834
 		$groupUsers = $this->access->connection->getFromCache('usersInGroup-'.$gid.'-'.$search);
835
-		if(!is_null($groupUsers)) {
835
+		if (!is_null($groupUsers)) {
836 836
 			$groupUsers = array_slice($groupUsers, $offset, $limit);
837 837
 			$this->access->connection->writeToCache($cacheKey, $groupUsers);
838 838
 			return $groupUsers;
839 839
 		}
840 840
 
841
-		if($limit === -1) {
841
+		if ($limit === -1) {
842 842
 			$limit = null;
843 843
 		}
844 844
 		$groupDN = $this->access->groupname2dn($gid);
845
-		if(!$groupDN) {
845
+		if (!$groupDN) {
846 846
 			// group couldn't be found, return empty resultset
847 847
 			$this->access->connection->writeToCache($cacheKey, []);
848 848
 			return [];
@@ -851,7 +851,7 @@  discard block
 block discarded – undo
851 851
 		$primaryUsers = $this->getUsersInPrimaryGroup($groupDN, $search, $limit, $offset);
852 852
 		$posixGroupUsers = $this->getUsersInGidNumber($groupDN, $search, $limit, $offset);
853 853
 		$members = $this->_groupMembers($groupDN);
854
-		if(!$members && empty($posixGroupUsers) && empty($primaryUsers)) {
854
+		if (!$members && empty($posixGroupUsers) && empty($primaryUsers)) {
855 855
 			//in case users could not be retrieved, return empty result set
856 856
 			$this->access->connection->writeToCache($cacheKey, []);
857 857
 			return [];
@@ -860,8 +860,8 @@  discard block
 block discarded – undo
860 860
 		$groupUsers = [];
861 861
 		$isMemberUid = (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid');
862 862
 		$attrs = $this->access->userManager->getAttributes(true);
863
-		foreach($members as $member) {
864
-			if($isMemberUid) {
863
+		foreach ($members as $member) {
864
+			if ($isMemberUid) {
865 865
 				//we got uids, need to get their DNs to 'translate' them to user names
866 866
 				$filter = $this->access->combineFilterWithAnd([
867 867
 					str_replace('%uid', trim($member), $this->access->connection->ldapLoginFilter),
@@ -871,23 +871,23 @@  discard block
 block discarded – undo
871 871
 					])
872 872
 				]);
873 873
 				$ldap_users = $this->access->fetchListOfUsers($filter, $attrs, 1);
874
-				if(count($ldap_users) < 1) {
874
+				if (count($ldap_users) < 1) {
875 875
 					continue;
876 876
 				}
877 877
 				$groupUsers[] = $this->access->dn2username($ldap_users[0]['dn'][0]);
878 878
 			} else {
879 879
 				//we got DNs, check if we need to filter by search or we can give back all of them
880 880
 				$uid = $this->access->dn2username($member);
881
-				if(!$uid) {
881
+				if (!$uid) {
882 882
 					continue;
883 883
 				}
884 884
 
885
-				$cacheKey = 'userExistsOnLDAP' . $uid;
885
+				$cacheKey = 'userExistsOnLDAP'.$uid;
886 886
 				$userExists = $this->access->connection->getFromCache($cacheKey);
887
-				if($userExists === false) {
887
+				if ($userExists === false) {
888 888
 					continue;
889 889
 				}
890
-				if($userExists === null || $search !== '') {
890
+				if ($userExists === null || $search !== '') {
891 891
 					if (!$this->access->readAttribute($member,
892 892
 						$this->access->connection->ldapUserDisplayName,
893 893
 						$this->access->combineFilterWithAnd([
@@ -895,7 +895,7 @@  discard block
 block discarded – undo
895 895
 							$this->access->connection->ldapUserFilter
896 896
 						])))
897 897
 					{
898
-						if($search === '') {
898
+						if ($search === '') {
899 899
 							$this->access->connection->writeToCache($cacheKey, false);
900 900
 						}
901 901
 						continue;
@@ -928,16 +928,16 @@  discard block
 block discarded – undo
928 928
 		}
929 929
 
930 930
 		$cacheKey = 'countUsersInGroup-'.$gid.'-'.$search;
931
-		if(!$this->enabled || !$this->groupExists($gid)) {
931
+		if (!$this->enabled || !$this->groupExists($gid)) {
932 932
 			return false;
933 933
 		}
934 934
 		$groupUsers = $this->access->connection->getFromCache($cacheKey);
935
-		if(!is_null($groupUsers)) {
935
+		if (!is_null($groupUsers)) {
936 936
 			return $groupUsers;
937 937
 		}
938 938
 
939 939
 		$groupDN = $this->access->groupname2dn($gid);
940
-		if(!$groupDN) {
940
+		if (!$groupDN) {
941 941
 			// group couldn't be found, return empty result set
942 942
 			$this->access->connection->writeToCache($cacheKey, false);
943 943
 			return false;
@@ -945,7 +945,7 @@  discard block
 block discarded – undo
945 945
 
946 946
 		$members = $this->_groupMembers($groupDN);
947 947
 		$primaryUserCount = $this->countUsersInPrimaryGroup($groupDN, '');
948
-		if(!$members && $primaryUserCount === 0) {
948
+		if (!$members && $primaryUserCount === 0) {
949 949
 			//in case users could not be retrieved, return empty result set
950 950
 			$this->access->connection->writeToCache($cacheKey, false);
951 951
 			return false;
@@ -970,27 +970,27 @@  discard block
 block discarded – undo
970 970
 		//For now this is not important, because the only use of this method
971 971
 		//does not supply a search string
972 972
 		$groupUsers = [];
973
-		foreach($members as $member) {
974
-			if($isMemberUid) {
973
+		foreach ($members as $member) {
974
+			if ($isMemberUid) {
975 975
 				//we got uids, need to get their DNs to 'translate' them to user names
976 976
 				$filter = $this->access->combineFilterWithAnd([
977 977
 					str_replace('%uid', $member, $this->access->connection->ldapLoginFilter),
978 978
 					$this->access->getFilterPartForUserSearch($search)
979 979
 				]);
980 980
 				$ldap_users = $this->access->fetchListOfUsers($filter, 'dn', 1);
981
-				if(count($ldap_users) < 1) {
981
+				if (count($ldap_users) < 1) {
982 982
 					continue;
983 983
 				}
984 984
 				$groupUsers[] = $this->access->dn2username($ldap_users[0]);
985 985
 			} else {
986 986
 				//we need to apply the search filter now
987
-				if(!$this->access->readAttribute($member,
987
+				if (!$this->access->readAttribute($member,
988 988
 					$this->access->connection->ldapUserDisplayName,
989 989
 					$this->access->getFilterPartForUserSearch($search))) {
990 990
 					continue;
991 991
 				}
992 992
 				// dn2username will also check if the users belong to the allowed base
993
-				if($ocname = $this->access->dn2username($member)) {
993
+				if ($ocname = $this->access->dn2username($member)) {
994 994
 					$groupUsers[] = $ocname;
995 995
 				}
996 996
 			}
@@ -1013,7 +1013,7 @@  discard block
 block discarded – undo
1013 1013
 	 * Returns a list with all groups (used by getGroups)
1014 1014
 	 */
1015 1015
 	protected function getGroupsChunk($search = '', $limit = -1, $offset = 0) {
1016
-		if(!$this->enabled) {
1016
+		if (!$this->enabled) {
1017 1017
 			return [];
1018 1018
 		}
1019 1019
 		$cacheKey = 'getGroups-'.$search.'-'.$limit.'-'.$offset;
@@ -1021,13 +1021,13 @@  discard block
 block discarded – undo
1021 1021
 		//Check cache before driving unnecessary searches
1022 1022
 		\OCP\Util::writeLog('user_ldap', 'getGroups '.$cacheKey, ILogger::DEBUG);
1023 1023
 		$ldap_groups = $this->access->connection->getFromCache($cacheKey);
1024
-		if(!is_null($ldap_groups)) {
1024
+		if (!is_null($ldap_groups)) {
1025 1025
 			return $ldap_groups;
1026 1026
 		}
1027 1027
 
1028 1028
 		// if we'd pass -1 to LDAP search, we'd end up in a Protocol
1029 1029
 		// error. With a limit of 0, we get 0 results. So we pass null.
1030
-		if($limit <= 0) {
1030
+		if ($limit <= 0) {
1031 1031
 			$limit = null;
1032 1032
 		}
1033 1033
 		$filter = $this->access->combineFilterWithAnd([
@@ -1059,11 +1059,11 @@  discard block
 block discarded – undo
1059 1059
 	 * (active directory has a limit of 1000 by default)
1060 1060
 	 */
1061 1061
 	public function getGroups($search = '', $limit = -1, $offset = 0) {
1062
-		if(!$this->enabled) {
1062
+		if (!$this->enabled) {
1063 1063
 			return [];
1064 1064
 		}
1065 1065
 		$search = $this->access->escapeFilterPart($search, true);
1066
-		$pagingSize = (int)$this->access->connection->ldapPagingSize;
1066
+		$pagingSize = (int) $this->access->connection->ldapPagingSize;
1067 1067
 		if ($pagingSize <= 0) {
1068 1068
 			return $this->getGroupsChunk($search, $limit, $offset);
1069 1069
 		}
@@ -1106,20 +1106,20 @@  discard block
 block discarded – undo
1106 1106
 	 */
1107 1107
 	public function groupExists($gid) {
1108 1108
 		$groupExists = $this->access->connection->getFromCache('groupExists'.$gid);
1109
-		if(!is_null($groupExists)) {
1110
-			return (bool)$groupExists;
1109
+		if (!is_null($groupExists)) {
1110
+			return (bool) $groupExists;
1111 1111
 		}
1112 1112
 
1113 1113
 		//getting dn, if false the group does not exist. If dn, it may be mapped
1114 1114
 		//only, requires more checking.
1115 1115
 		$dn = $this->access->groupname2dn($gid);
1116
-		if(!$dn) {
1116
+		if (!$dn) {
1117 1117
 			$this->access->connection->writeToCache('groupExists'.$gid, false);
1118 1118
 			return false;
1119 1119
 		}
1120 1120
 
1121 1121
 		//if group really still exists, we will be able to read its objectclass
1122
-		if(!is_array($this->access->readAttribute($dn, ''))) {
1122
+		if (!is_array($this->access->readAttribute($dn, ''))) {
1123 1123
 			$this->access->connection->writeToCache('groupExists'.$gid, false);
1124 1124
 			return false;
1125 1125
 		}
@@ -1137,7 +1137,7 @@  discard block
 block discarded – undo
1137 1137
 	 * compared with GroupInterface::CREATE_GROUP etc.
1138 1138
 	 */
1139 1139
 	public function implementsActions($actions) {
1140
-		return (bool)((GroupInterface::COUNT_USERS |
1140
+		return (bool) ((GroupInterface::COUNT_USERS |
1141 1141
 				$this->groupPluginManager->getImplementedActions()) & $actions);
1142 1142
 	}
1143 1143
 
@@ -1160,7 +1160,7 @@  discard block
 block discarded – undo
1160 1160
 			if ($dn = $this->groupPluginManager->createGroup($gid)) {
1161 1161
 				//updates group mapping
1162 1162
 				$uuid = $this->access->getUUID($dn, false);
1163
-				if(is_string($uuid)) {
1163
+				if (is_string($uuid)) {
1164 1164
 					$this->access->mapAndAnnounceIfApplicable(
1165 1165
 						$this->access->getGroupMapper(),
1166 1166
 						$dn,
@@ -1263,7 +1263,7 @@  discard block
 block discarded – undo
1263 1263
 			return $this->groupPluginManager->getDisplayName($gid);
1264 1264
 		}
1265 1265
 
1266
-		$cacheKey = 'group_getDisplayName' . $gid;
1266
+		$cacheKey = 'group_getDisplayName'.$gid;
1267 1267
 		if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
1268 1268
 			return $displayName;
1269 1269
 		}
Please login to merge, or discard this patch.
apps/user_ldap/lib/Access.php 1 patch
Spacing   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 	 * @return AbstractMapping
135 135
 	 */
136 136
 	public function getUserMapper() {
137
-		if(is_null($this->userMapper)) {
137
+		if (is_null($this->userMapper)) {
138 138
 			throw new \Exception('UserMapper was not assigned to this Access instance.');
139 139
 		}
140 140
 		return $this->userMapper;
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 * @return AbstractMapping
155 155
 	 */
156 156
 	public function getGroupMapper() {
157
-		if(is_null($this->groupMapper)) {
157
+		if (is_null($this->groupMapper)) {
158 158
 			throw new \Exception('GroupMapper was not assigned to this Access instance.');
159 159
 		}
160 160
 		return $this->groupMapper;
@@ -187,14 +187,14 @@  discard block
 block discarded – undo
187 187
 	 * @throws ServerNotAvailableException
188 188
 	 */
189 189
 	public function readAttribute($dn, $attr, $filter = 'objectClass=*') {
190
-		if(!$this->checkConnection()) {
190
+		if (!$this->checkConnection()) {
191 191
 			\OCP\Util::writeLog('user_ldap',
192 192
 				'No LDAP Connector assigned, access impossible for readAttribute.',
193 193
 				ILogger::WARN);
194 194
 			return false;
195 195
 		}
196 196
 		$cr = $this->connection->getConnectionResource();
197
-		if(!$this->ldap->isResource($cr)) {
197
+		if (!$this->ldap->isResource($cr)) {
198 198
 			//LDAP not available
199 199
 			\OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', ILogger::DEBUG);
200 200
 			return false;
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 		$this->abandonPagedSearch();
205 205
 		// openLDAP requires that we init a new Paged Search. Not needed by AD,
206 206
 		// but does not hurt either.
207
-		$pagingSize = (int)$this->connection->ldapPagingSize;
207
+		$pagingSize = (int) $this->connection->ldapPagingSize;
208 208
 		// 0 won't result in replies, small numbers may leave out groups
209 209
 		// (cf. #12306), 500 is default for paging and should work everywhere.
210 210
 		$maxResults = $pagingSize > 20 ? $pagingSize : 500;
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 		$isRangeRequest = false;
218 218
 		do {
219 219
 			$result = $this->executeRead($cr, $dn, $attrToRead, $filter, $maxResults);
220
-			if(is_bool($result)) {
220
+			if (is_bool($result)) {
221 221
 				// when an exists request was run and it was successful, an empty
222 222
 				// array must be returned
223 223
 				return $result ? [] : false;
@@ -234,22 +234,22 @@  discard block
 block discarded – undo
234 234
 			$result = $this->extractRangeData($result, $attr);
235 235
 			if (!empty($result)) {
236 236
 				$normalizedResult = $this->extractAttributeValuesFromResult(
237
-					[ $attr => $result['values'] ],
237
+					[$attr => $result['values']],
238 238
 					$attr
239 239
 				);
240 240
 				$values = array_merge($values, $normalizedResult);
241 241
 
242
-				if($result['rangeHigh'] === '*') {
242
+				if ($result['rangeHigh'] === '*') {
243 243
 					// when server replies with * as high range value, there are
244 244
 					// no more results left
245 245
 					return $values;
246 246
 				} else {
247
-					$low  = $result['rangeHigh'] + 1;
248
-					$attrToRead = $result['attributeName'] . ';range=' . $low . '-*';
247
+					$low = $result['rangeHigh'] + 1;
248
+					$attrToRead = $result['attributeName'].';range='.$low.'-*';
249 249
 					$isRangeRequest = true;
250 250
 				}
251 251
 			}
252
-		} while($isRangeRequest);
252
+		} while ($isRangeRequest);
253 253
 
254 254
 		\OCP\Util::writeLog('user_ldap', 'Requested attribute '.$attr.' not found for '.$dn, ILogger::DEBUG);
255 255
 		return false;
@@ -275,13 +275,13 @@  discard block
 block discarded – undo
275 275
 		if (!$this->ldap->isResource($rr)) {
276 276
 			if ($attribute !== '') {
277 277
 				//do not throw this message on userExists check, irritates
278
-				\OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN ' . $dn, ILogger::DEBUG);
278
+				\OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN '.$dn, ILogger::DEBUG);
279 279
 			}
280 280
 			//in case an error occurs , e.g. object does not exist
281 281
 			return false;
282 282
 		}
283 283
 		if ($attribute === '' && ($filter === 'objectclass=*' || $this->invokeLDAPMethod('countEntries', $cr, $rr) === 1)) {
284
-			\OCP\Util::writeLog('user_ldap', 'readAttribute: ' . $dn . ' found', ILogger::DEBUG);
284
+			\OCP\Util::writeLog('user_ldap', 'readAttribute: '.$dn.' found', ILogger::DEBUG);
285 285
 			return true;
286 286
 		}
287 287
 		$er = $this->invokeLDAPMethod('firstEntry', $cr, $rr);
@@ -306,12 +306,12 @@  discard block
 block discarded – undo
306 306
 	 */
307 307
 	public function extractAttributeValuesFromResult($result, $attribute) {
308 308
 		$values = [];
309
-		if(isset($result[$attribute]) && $result[$attribute]['count'] > 0) {
309
+		if (isset($result[$attribute]) && $result[$attribute]['count'] > 0) {
310 310
 			$lowercaseAttribute = strtolower($attribute);
311
-			for($i=0;$i<$result[$attribute]['count'];$i++) {
312
-				if($this->resemblesDN($attribute)) {
311
+			for ($i = 0; $i < $result[$attribute]['count']; $i++) {
312
+				if ($this->resemblesDN($attribute)) {
313 313
 					$values[] = $this->helper->sanitizeDN($result[$attribute][$i]);
314
-				} elseif($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') {
314
+				} elseif ($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') {
315 315
 					$values[] = $this->convertObjectGUID2Str($result[$attribute][$i]);
316 316
 				} else {
317 317
 					$values[] = $result[$attribute][$i];
@@ -333,10 +333,10 @@  discard block
 block discarded – undo
333 333
 	 */
334 334
 	public function extractRangeData($result, $attribute) {
335 335
 		$keys = array_keys($result);
336
-		foreach($keys as $key) {
337
-			if($key !== $attribute && strpos($key, $attribute) === 0) {
336
+		foreach ($keys as $key) {
337
+			if ($key !== $attribute && strpos($key, $attribute) === 0) {
338 338
 				$queryData = explode(';', $key);
339
-				if(strpos($queryData[1], 'range=') === 0) {
339
+				if (strpos($queryData[1], 'range=') === 0) {
340 340
 					$high = substr($queryData[1], 1 + strpos($queryData[1], '-'));
341 341
 					$data = [
342 342
 						'values' => $result[$key],
@@ -361,11 +361,11 @@  discard block
 block discarded – undo
361 361
 	 * @throws \Exception
362 362
 	 */
363 363
 	public function setPassword($userDN, $password) {
364
-		if((int)$this->connection->turnOnPasswordChange !== 1) {
364
+		if ((int) $this->connection->turnOnPasswordChange !== 1) {
365 365
 			throw new \Exception('LDAP password changes are disabled.');
366 366
 		}
367 367
 		$cr = $this->connection->getConnectionResource();
368
-		if(!$this->ldap->isResource($cr)) {
368
+		if (!$this->ldap->isResource($cr)) {
369 369
 			//LDAP not available
370 370
 			\OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', ILogger::DEBUG);
371 371
 			return false;
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
 			// try PASSWD extended operation first
375 375
 			return @$this->invokeLDAPMethod('exopPasswd', $cr, $userDN, '', $password) ||
376 376
 						@$this->invokeLDAPMethod('modReplace', $cr, $userDN, $password);
377
-		} catch(ConstraintViolationException $e) {
377
+		} catch (ConstraintViolationException $e) {
378 378
 			throw new HintException('Password change rejected.', \OC::$server->getL10N('user_ldap')->t('Password change rejected. Hint: ').$e->getMessage(), $e->getCode());
379 379
 		}
380 380
 	}
@@ -416,17 +416,17 @@  discard block
 block discarded – undo
416 416
 	 */
417 417
 	public function getDomainDNFromDN($dn) {
418 418
 		$allParts = $this->ldap->explodeDN($dn, 0);
419
-		if($allParts === false) {
419
+		if ($allParts === false) {
420 420
 			//not a valid DN
421 421
 			return '';
422 422
 		}
423 423
 		$domainParts = [];
424 424
 		$dcFound = false;
425
-		foreach($allParts as $part) {
426
-			if(!$dcFound && strpos($part, 'dc=') === 0) {
425
+		foreach ($allParts as $part) {
426
+			if (!$dcFound && strpos($part, 'dc=') === 0) {
427 427
 				$dcFound = true;
428 428
 			}
429
-			if($dcFound) {
429
+			if ($dcFound) {
430 430
 				$domainParts[] = $part;
431 431
 			}
432 432
 		}
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
 
453 453
 		//Check whether the DN belongs to the Base, to avoid issues on multi-
454 454
 		//server setups
455
-		if(is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
455
+		if (is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
456 456
 			return $fdn;
457 457
 		}
458 458
 
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
 		//To avoid bypassing the base DN settings under certain circumstances
472 472
 		//with the group support, check whether the provided DN matches one of
473 473
 		//the given Bases
474
-		if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) {
474
+		if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) {
475 475
 			return false;
476 476
 		}
477 477
 
@@ -489,11 +489,11 @@  discard block
 block discarded – undo
489 489
 	 */
490 490
 	public function groupsMatchFilter($groupDNs) {
491 491
 		$validGroupDNs = [];
492
-		foreach($groupDNs as $dn) {
492
+		foreach ($groupDNs as $dn) {
493 493
 			$cacheKey = 'groupsMatchFilter-'.$dn;
494 494
 			$groupMatchFilter = $this->connection->getFromCache($cacheKey);
495
-			if(!is_null($groupMatchFilter)) {
496
-				if($groupMatchFilter) {
495
+			if (!is_null($groupMatchFilter)) {
496
+				if ($groupMatchFilter) {
497 497
 					$validGroupDNs[] = $dn;
498 498
 				}
499 499
 				continue;
@@ -501,13 +501,13 @@  discard block
 block discarded – undo
501 501
 
502 502
 			// Check the base DN first. If this is not met already, we don't
503 503
 			// need to ask the server at all.
504
-			if(!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) {
504
+			if (!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) {
505 505
 				$this->connection->writeToCache($cacheKey, false);
506 506
 				continue;
507 507
 			}
508 508
 
509 509
 			$result = $this->readAttribute($dn, '', $this->connection->ldapGroupFilter);
510
-			if(is_array($result)) {
510
+			if (is_array($result)) {
511 511
 				$this->connection->writeToCache($cacheKey, true);
512 512
 				$validGroupDNs[] = $dn;
513 513
 			} else {
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
 		//To avoid bypassing the base DN settings under certain circumstances
531 531
 		//with the group support, check whether the provided DN matches one of
532 532
 		//the given Bases
533
-		if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
533
+		if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
534 534
 			return false;
535 535
 		}
536 536
 
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
 	 */
551 551
 	public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped = null, array $record = null) {
552 552
 		$newlyMapped = false;
553
-		if($isUser) {
553
+		if ($isUser) {
554 554
 			$mapper = $this->getUserMapper();
555 555
 			$nameAttribute = $this->connection->ldapUserDisplayName;
556 556
 			$filter = $this->connection->ldapUserFilter;
@@ -562,15 +562,15 @@  discard block
 block discarded – undo
562 562
 
563 563
 		//let's try to retrieve the Nextcloud name from the mappings table
564 564
 		$ncName = $mapper->getNameByDN($fdn);
565
-		if(is_string($ncName)) {
565
+		if (is_string($ncName)) {
566 566
 			return $ncName;
567 567
 		}
568 568
 
569 569
 		//second try: get the UUID and check if it is known. Then, update the DN and return the name.
570 570
 		$uuid = $this->getUUID($fdn, $isUser, $record);
571
-		if(is_string($uuid)) {
571
+		if (is_string($uuid)) {
572 572
 			$ncName = $mapper->getNameByUUID($uuid);
573
-			if(is_string($ncName)) {
573
+			if (is_string($ncName)) {
574 574
 				$mapper->setDNbyUUID($fdn, $uuid);
575 575
 				return $ncName;
576 576
 			}
@@ -580,17 +580,17 @@  discard block
 block discarded – undo
580 580
 			return false;
581 581
 		}
582 582
 
583
-		if(is_null($ldapName)) {
583
+		if (is_null($ldapName)) {
584 584
 			$ldapName = $this->readAttribute($fdn, $nameAttribute, $filter);
585
-			if(!isset($ldapName[0]) && empty($ldapName[0])) {
585
+			if (!isset($ldapName[0]) && empty($ldapName[0])) {
586 586
 				\OCP\Util::writeLog('user_ldap', 'No or empty name for '.$fdn.' with filter '.$filter.'.', ILogger::INFO);
587 587
 				return false;
588 588
 			}
589 589
 			$ldapName = $ldapName[0];
590 590
 		}
591 591
 
592
-		if($isUser) {
593
-			$usernameAttribute = (string)$this->connection->ldapExpertUsernameAttr;
592
+		if ($isUser) {
593
+			$usernameAttribute = (string) $this->connection->ldapExpertUsernameAttr;
594 594
 			if ($usernameAttribute !== '') {
595 595
 				$username = $this->readAttribute($fdn, $usernameAttribute);
596 596
 				$username = $username[0];
@@ -620,14 +620,14 @@  discard block
 block discarded – undo
620 620
 		// outside of core user management will still cache the user as non-existing.
621 621
 		$originalTTL = $this->connection->ldapCacheTTL;
622 622
 		$this->connection->setConfiguration(['ldapCacheTTL' => 0]);
623
-		if( $intName !== ''
623
+		if ($intName !== ''
624 624
 			&& (($isUser && !$this->ncUserManager->userExists($intName))
625 625
 				|| (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))
626 626
 			)
627 627
 		) {
628 628
 			$this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
629 629
 			$newlyMapped = $this->mapAndAnnounceIfApplicable($mapper, $fdn, $intName, $uuid, $isUser);
630
-			if($newlyMapped) {
630
+			if ($newlyMapped) {
631 631
 				return $intName;
632 632
 			}
633 633
 		}
@@ -635,7 +635,7 @@  discard block
 block discarded – undo
635 635
 		$this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
636 636
 		$altName = $this->createAltInternalOwnCloudName($intName, $isUser);
637 637
 		if (is_string($altName)) {
638
-			if($this->mapAndAnnounceIfApplicable($mapper, $fdn, $altName, $uuid, $isUser)) {
638
+			if ($this->mapAndAnnounceIfApplicable($mapper, $fdn, $altName, $uuid, $isUser)) {
639 639
 				$newlyMapped = true;
640 640
 				return $altName;
641 641
 			}
@@ -653,7 +653,7 @@  discard block
 block discarded – undo
653 653
 		string $uuid,
654 654
 		bool $isUser
655 655
 	) :bool {
656
-		if($mapper->map($fdn, $name, $uuid)) {
656
+		if ($mapper->map($fdn, $name, $uuid)) {
657 657
 			if ($this->ncUserManager instanceof PublicEmitter && $isUser) {
658 658
 				$this->cacheUserExists($name);
659 659
 				$this->ncUserManager->emit('\OC\User', 'assignedUserId', [$name]);
@@ -698,7 +698,7 @@  discard block
 block discarded – undo
698 698
 	 * @throws \Exception
699 699
 	 */
700 700
 	private function ldap2NextcloudNames($ldapObjects, $isUsers) {
701
-		if($isUsers) {
701
+		if ($isUsers) {
702 702
 			$nameAttribute = $this->connection->ldapUserDisplayName;
703 703
 			$sndAttribute  = $this->connection->ldapUserDisplayName2;
704 704
 		} else {
@@ -706,9 +706,9 @@  discard block
 block discarded – undo
706 706
 		}
707 707
 		$nextcloudNames = [];
708 708
 
709
-		foreach($ldapObjects as $ldapObject) {
709
+		foreach ($ldapObjects as $ldapObject) {
710 710
 			$nameByLDAP = null;
711
-			if(    isset($ldapObject[$nameAttribute])
711
+			if (isset($ldapObject[$nameAttribute])
712 712
 				&& is_array($ldapObject[$nameAttribute])
713 713
 				&& isset($ldapObject[$nameAttribute][0])
714 714
 			) {
@@ -717,19 +717,19 @@  discard block
 block discarded – undo
717 717
 			}
718 718
 
719 719
 			$ncName = $this->dn2ocname($ldapObject['dn'][0], $nameByLDAP, $isUsers);
720
-			if($ncName) {
720
+			if ($ncName) {
721 721
 				$nextcloudNames[] = $ncName;
722
-				if($isUsers) {
722
+				if ($isUsers) {
723 723
 					$this->updateUserState($ncName);
724 724
 					//cache the user names so it does not need to be retrieved
725 725
 					//again later (e.g. sharing dialogue).
726
-					if(is_null($nameByLDAP)) {
726
+					if (is_null($nameByLDAP)) {
727 727
 						continue;
728 728
 					}
729 729
 					$sndName = isset($ldapObject[$sndAttribute][0])
730 730
 						? $ldapObject[$sndAttribute][0] : '';
731 731
 					$this->cacheUserDisplayName($ncName, $nameByLDAP, $sndName);
732
-				} else if($nameByLDAP !== null) {
732
+				} else if ($nameByLDAP !== null) {
733 733
 					$this->cacheGroupDisplayName($ncName, $nameByLDAP);
734 734
 				}
735 735
 			}
@@ -745,7 +745,7 @@  discard block
 block discarded – undo
745 745
 	 */
746 746
 	public function updateUserState($ncname) {
747 747
 		$user = $this->userManager->get($ncname);
748
-		if($user instanceof OfflineUser) {
748
+		if ($user instanceof OfflineUser) {
749 749
 			$user->unmark();
750 750
 		}
751 751
 	}
@@ -785,7 +785,7 @@  discard block
 block discarded – undo
785 785
 	 */
786 786
 	public function cacheUserDisplayName($ocName, $displayName, $displayName2 = '') {
787 787
 		$user = $this->userManager->get($ocName);
788
-		if($user === null) {
788
+		if ($user === null) {
789 789
 			return;
790 790
 		}
791 791
 		$displayName = $user->composeAndStoreDisplayName($displayName, $displayName2);
@@ -794,7 +794,7 @@  discard block
 block discarded – undo
794 794
 	}
795 795
 
796 796
 	public function cacheGroupDisplayName(string $ncName, string $displayName): void {
797
-		$cacheKey = 'group_getDisplayName' . $ncName;
797
+		$cacheKey = 'group_getDisplayName'.$ncName;
798 798
 		$this->connection->writeToCache($cacheKey, $displayName);
799 799
 	}
800 800
 
@@ -810,9 +810,9 @@  discard block
 block discarded – undo
810 810
 		$attempts = 0;
811 811
 		//while loop is just a precaution. If a name is not generated within
812 812
 		//20 attempts, something else is very wrong. Avoids infinite loop.
813
-		while($attempts < 20){
814
-			$altName = $name . '_' . rand(1000,9999);
815
-			if(!$this->ncUserManager->userExists($altName)) {
813
+		while ($attempts < 20) {
814
+			$altName = $name.'_'.rand(1000, 9999);
815
+			if (!$this->ncUserManager->userExists($altName)) {
816 816
 				return $altName;
817 817
 			}
818 818
 			$attempts++;
@@ -834,25 +834,25 @@  discard block
 block discarded – undo
834 834
 	 */
835 835
 	private function _createAltInternalOwnCloudNameForGroups($name) {
836 836
 		$usedNames = $this->groupMapper->getNamesBySearch($name, "", '_%');
837
-		if(!$usedNames || count($usedNames) === 0) {
837
+		if (!$usedNames || count($usedNames) === 0) {
838 838
 			$lastNo = 1; //will become name_2
839 839
 		} else {
840 840
 			natsort($usedNames);
841 841
 			$lastName = array_pop($usedNames);
842
-			$lastNo = (int)substr($lastName, strrpos($lastName, '_') + 1);
842
+			$lastNo = (int) substr($lastName, strrpos($lastName, '_') + 1);
843 843
 		}
844
-		$altName = $name.'_'. (string)($lastNo+1);
844
+		$altName = $name.'_'.(string) ($lastNo + 1);
845 845
 		unset($usedNames);
846 846
 
847 847
 		$attempts = 1;
848
-		while($attempts < 21){
848
+		while ($attempts < 21) {
849 849
 			// Check to be really sure it is unique
850 850
 			// while loop is just a precaution. If a name is not generated within
851 851
 			// 20 attempts, something else is very wrong. Avoids infinite loop.
852
-			if(!\OC::$server->getGroupManager()->groupExists($altName)) {
852
+			if (!\OC::$server->getGroupManager()->groupExists($altName)) {
853 853
 				return $altName;
854 854
 			}
855
-			$altName = $name . '_' . ($lastNo + $attempts);
855
+			$altName = $name.'_'.($lastNo + $attempts);
856 856
 			$attempts++;
857 857
 		}
858 858
 		return false;
@@ -867,7 +867,7 @@  discard block
 block discarded – undo
867 867
 	private function createAltInternalOwnCloudName($name, $isUser) {
868 868
 		$originalTTL = $this->connection->ldapCacheTTL;
869 869
 		$this->connection->setConfiguration(['ldapCacheTTL' => 0]);
870
-		if($isUser) {
870
+		if ($isUser) {
871 871
 			$altName = $this->_createAltInternalOwnCloudNameForUsers($name);
872 872
 		} else {
873 873
 			$altName = $this->_createAltInternalOwnCloudNameForGroups($name);
@@ -916,13 +916,13 @@  discard block
 block discarded – undo
916 916
 	public function fetchListOfUsers($filter, $attr, $limit = null, $offset = null, $forceApplyAttributes = false) {
917 917
 		$ldapRecords = $this->searchUsers($filter, $attr, $limit, $offset);
918 918
 		$recordsToUpdate = $ldapRecords;
919
-		if(!$forceApplyAttributes) {
919
+		if (!$forceApplyAttributes) {
920 920
 			$isBackgroundJobModeAjax = $this->config
921 921
 					->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax';
922 922
 			$recordsToUpdate = array_filter($ldapRecords, function($record) use ($isBackgroundJobModeAjax) {
923 923
 				$newlyMapped = false;
924 924
 				$uid = $this->dn2ocname($record['dn'][0], null, true, $newlyMapped, $record);
925
-				if(is_string($uid)) {
925
+				if (is_string($uid)) {
926 926
 					$this->cacheUserExists($uid);
927 927
 				}
928 928
 				return ($uid !== false) && ($newlyMapped || $isBackgroundJobModeAjax);
@@ -940,15 +940,15 @@  discard block
 block discarded – undo
940 940
 	 * @param array $ldapRecords
941 941
 	 * @throws \Exception
942 942
 	 */
943
-	public function batchApplyUserAttributes(array $ldapRecords){
943
+	public function batchApplyUserAttributes(array $ldapRecords) {
944 944
 		$displayNameAttribute = strtolower($this->connection->ldapUserDisplayName);
945
-		foreach($ldapRecords as $userRecord) {
946
-			if(!isset($userRecord[$displayNameAttribute])) {
945
+		foreach ($ldapRecords as $userRecord) {
946
+			if (!isset($userRecord[$displayNameAttribute])) {
947 947
 				// displayName is obligatory
948 948
 				continue;
949 949
 			}
950
-			$ocName  = $this->dn2ocname($userRecord['dn'][0], null, true);
951
-			if($ocName === false) {
950
+			$ocName = $this->dn2ocname($userRecord['dn'][0], null, true);
951
+			if ($ocName === false) {
952 952
 				continue;
953 953
 			}
954 954
 			$this->updateUserState($ocName);
@@ -976,7 +976,7 @@  discard block
 block discarded – undo
976 976
 		array_walk($groupRecords, function($record) {
977 977
 			$newlyMapped = false;
978 978
 			$gid = $this->dn2ocname($record['dn'][0], null, false, $newlyMapped, $record);
979
-			if(!$newlyMapped && is_string($gid)) {
979
+			if (!$newlyMapped && is_string($gid)) {
980 980
 				$this->cacheGroupExists($gid);
981 981
 			}
982 982
 		});
@@ -989,8 +989,8 @@  discard block
 block discarded – undo
989 989
 	 * @return array
990 990
 	 */
991 991
 	private function fetchList($list, $manyAttributes) {
992
-		if(is_array($list)) {
993
-			if($manyAttributes) {
992
+		if (is_array($list)) {
993
+			if ($manyAttributes) {
994 994
 				return $list;
995 995
 			} else {
996 996
 				$list = array_reduce($list, function($carry, $item) {
@@ -1020,7 +1020,7 @@  discard block
 block discarded – undo
1020 1020
 	 */
1021 1021
 	public function searchUsers($filter, $attr = null, $limit = null, $offset = null) {
1022 1022
 		$result = [];
1023
-		foreach($this->connection->ldapBaseUsers as $base) {
1023
+		foreach ($this->connection->ldapBaseUsers as $base) {
1024 1024
 			$result = array_merge($result, $this->search($filter, [$base], $attr, $limit, $offset));
1025 1025
 		}
1026 1026
 		return $result;
@@ -1036,9 +1036,9 @@  discard block
 block discarded – undo
1036 1036
 	 */
1037 1037
 	public function countUsers($filter, $attr = ['dn'], $limit = null, $offset = null) {
1038 1038
 		$result = false;
1039
-		foreach($this->connection->ldapBaseUsers as $base) {
1039
+		foreach ($this->connection->ldapBaseUsers as $base) {
1040 1040
 			$count = $this->count($filter, [$base], $attr, $limit, $offset);
1041
-			$result = is_int($count) ? (int)$result + $count : $result;
1041
+			$result = is_int($count) ? (int) $result + $count : $result;
1042 1042
 		}
1043 1043
 		return $result;
1044 1044
 	}
@@ -1057,7 +1057,7 @@  discard block
 block discarded – undo
1057 1057
 	 */
1058 1058
 	public function searchGroups($filter, $attr = null, $limit = null, $offset = null) {
1059 1059
 		$result = [];
1060
-		foreach($this->connection->ldapBaseGroups as $base) {
1060
+		foreach ($this->connection->ldapBaseGroups as $base) {
1061 1061
 			$result = array_merge($result, $this->search($filter, [$base], $attr, $limit, $offset));
1062 1062
 		}
1063 1063
 		return $result;
@@ -1075,9 +1075,9 @@  discard block
 block discarded – undo
1075 1075
 	 */
1076 1076
 	public function countGroups($filter, $attr = ['dn'], $limit = null, $offset = null) {
1077 1077
 		$result = false;
1078
-		foreach($this->connection->ldapBaseGroups as $base) {
1078
+		foreach ($this->connection->ldapBaseGroups as $base) {
1079 1079
 			$count = $this->count($filter, [$base], $attr, $limit, $offset);
1080
-			$result = is_int($count) ? (int)$result + $count : $result;
1080
+			$result = is_int($count) ? (int) $result + $count : $result;
1081 1081
 		}
1082 1082
 		return $result;
1083 1083
 	}
@@ -1092,9 +1092,9 @@  discard block
 block discarded – undo
1092 1092
 	 */
1093 1093
 	public function countObjects($limit = null, $offset = null) {
1094 1094
 		$result = false;
1095
-		foreach($this->connection->ldapBase as $base) {
1095
+		foreach ($this->connection->ldapBase as $base) {
1096 1096
 			$count = $this->count('objectclass=*', [$base], ['dn'], $limit, $offset);
1097
-			$result = is_int($count) ? (int)$result + $count : $result;
1097
+			$result = is_int($count) ? (int) $result + $count : $result;
1098 1098
 		}
1099 1099
 		return $result;
1100 1100
 	}
@@ -1119,7 +1119,7 @@  discard block
 block discarded – undo
1119 1119
 		// php no longer supports call-time pass-by-reference
1120 1120
 		// thus cannot support controlPagedResultResponse as the third argument
1121 1121
 		// is a reference
1122
-		$doMethod = function () use ($command, &$arguments) {
1122
+		$doMethod = function() use ($command, &$arguments) {
1123 1123
 			if ($command == 'controlPagedResultResponse') {
1124 1124
 				throw new \InvalidArgumentException('Invoker does not support controlPagedResultResponse, call LDAP Wrapper directly instead.');
1125 1125
 			} else {
@@ -1137,7 +1137,7 @@  discard block
 block discarded – undo
1137 1137
 			$this->connection->resetConnectionResource();
1138 1138
 			$cr = $this->connection->getConnectionResource();
1139 1139
 
1140
-			if(!$this->ldap->isResource($cr)) {
1140
+			if (!$this->ldap->isResource($cr)) {
1141 1141
 				// Seems like we didn't find any resource.
1142 1142
 				\OCP\Util::writeLog('user_ldap', "Could not $command, because resource is missing.", ILogger::DEBUG);
1143 1143
 				throw $e;
@@ -1162,13 +1162,13 @@  discard block
 block discarded – undo
1162 1162
 	 * @throws ServerNotAvailableException
1163 1163
 	 */
1164 1164
 	private function executeSearch($filter, $base, &$attr = null, $limit = null, $offset = null) {
1165
-		if(!is_null($attr) && !is_array($attr)) {
1165
+		if (!is_null($attr) && !is_array($attr)) {
1166 1166
 			$attr = [mb_strtolower($attr, 'UTF-8')];
1167 1167
 		}
1168 1168
 
1169 1169
 		// See if we have a resource, in case not cancel with message
1170 1170
 		$cr = $this->connection->getConnectionResource();
1171
-		if(!$this->ldap->isResource($cr)) {
1171
+		if (!$this->ldap->isResource($cr)) {
1172 1172
 			// Seems like we didn't find any resource.
1173 1173
 			// Return an empty array just like before.
1174 1174
 			\OCP\Util::writeLog('user_ldap', 'Could not search, because resource is missing.', ILogger::DEBUG);
@@ -1176,13 +1176,13 @@  discard block
 block discarded – undo
1176 1176
 		}
1177 1177
 
1178 1178
 		//check whether paged search should be attempted
1179
-		$pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int)$limit, $offset);
1179
+		$pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int) $limit, $offset);
1180 1180
 
1181 1181
 		$linkResources = array_pad([], count($base), $cr);
1182 1182
 		$sr = $this->invokeLDAPMethod('search', $linkResources, $base, $filter, $attr);
1183 1183
 		// cannot use $cr anymore, might have changed in the previous call!
1184 1184
 		$error = $this->ldap->errno($this->connection->getConnectionResource());
1185
-		if(!is_array($sr) || $error !== 0) {
1185
+		if (!is_array($sr) || $error !== 0) {
1186 1186
 			\OCP\Util::writeLog('user_ldap', 'Attempt for Paging?  '.print_r($pagedSearchOK, true), ILogger::ERROR);
1187 1187
 			return false;
1188 1188
 		}
@@ -1207,29 +1207,29 @@  discard block
 block discarded – undo
1207 1207
 	 */
1208 1208
 	private function processPagedSearchStatus($sr, $filter, $base, $iFoundItems, $limit, $offset, $pagedSearchOK, $skipHandling) {
1209 1209
 		$cookie = null;
1210
-		if($pagedSearchOK) {
1210
+		if ($pagedSearchOK) {
1211 1211
 			$cr = $this->connection->getConnectionResource();
1212
-			foreach($sr as $key => $res) {
1213
-				if($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) {
1212
+			foreach ($sr as $key => $res) {
1213
+				if ($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) {
1214 1214
 					$this->setPagedResultCookie($base[$key], $filter, $limit, $offset, $cookie);
1215 1215
 				}
1216 1216
 			}
1217 1217
 
1218 1218
 			//browsing through prior pages to get the cookie for the new one
1219
-			if($skipHandling) {
1219
+			if ($skipHandling) {
1220 1220
 				return false;
1221 1221
 			}
1222 1222
 			// if count is bigger, then the server does not support
1223 1223
 			// paged search. Instead, he did a normal search. We set a
1224 1224
 			// flag here, so the callee knows how to deal with it.
1225
-			if($iFoundItems <= $limit) {
1225
+			if ($iFoundItems <= $limit) {
1226 1226
 				$this->pagedSearchedSuccessful = true;
1227 1227
 			}
1228 1228
 		} else {
1229
-			if(!is_null($limit) && (int)$this->connection->ldapPagingSize !== 0) {
1229
+			if (!is_null($limit) && (int) $this->connection->ldapPagingSize !== 0) {
1230 1230
 				\OC::$server->getLogger()->debug(
1231 1231
 					'Paged search was not available',
1232
-					[ 'app' => 'user_ldap' ]
1232
+					['app' => 'user_ldap']
1233 1233
 				);
1234 1234
 			}
1235 1235
 		}
@@ -1258,8 +1258,8 @@  discard block
 block discarded – undo
1258 1258
 	private function count($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) {
1259 1259
 		\OCP\Util::writeLog('user_ldap', 'Count filter:  '.print_r($filter, true), ILogger::DEBUG);
1260 1260
 
1261
-		$limitPerPage = (int)$this->connection->ldapPagingSize;
1262
-		if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1261
+		$limitPerPage = (int) $this->connection->ldapPagingSize;
1262
+		if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1263 1263
 			$limitPerPage = $limit;
1264 1264
 		}
1265 1265
 
@@ -1269,7 +1269,7 @@  discard block
 block discarded – undo
1269 1269
 
1270 1270
 		do {
1271 1271
 			$search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset);
1272
-			if($search === false) {
1272
+			if ($search === false) {
1273 1273
 				return $counter > 0 ? $counter : false;
1274 1274
 			}
1275 1275
 			list($sr, $pagedSearchOK) = $search;
@@ -1288,7 +1288,7 @@  discard block
 block discarded – undo
1288 1288
 			 * Continue now depends on $hasMorePages value
1289 1289
 			 */
1290 1290
 			$continue = $pagedSearchOK && $hasMorePages;
1291
-		} while($continue && (is_null($limit) || $limit <= 0 || $limit > $counter));
1291
+		} while ($continue && (is_null($limit) || $limit <= 0 || $limit > $counter));
1292 1292
 
1293 1293
 		return $counter;
1294 1294
 	}
@@ -1301,8 +1301,8 @@  discard block
 block discarded – undo
1301 1301
 	private function countEntriesInSearchResults($searchResults) {
1302 1302
 		$counter = 0;
1303 1303
 
1304
-		foreach($searchResults as $res) {
1305
-			$count = (int)$this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res);
1304
+		foreach ($searchResults as $res) {
1305
+			$count = (int) $this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res);
1306 1306
 			$counter += $count;
1307 1307
 		}
1308 1308
 
@@ -1322,8 +1322,8 @@  discard block
 block discarded – undo
1322 1322
 	 * @throws ServerNotAvailableException
1323 1323
 	 */
1324 1324
 	public function search($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) {
1325
-		$limitPerPage = (int)$this->connection->ldapPagingSize;
1326
-		if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1325
+		$limitPerPage = (int) $this->connection->ldapPagingSize;
1326
+		if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1327 1327
 			$limitPerPage = $limit;
1328 1328
 		}
1329 1329
 
@@ -1337,13 +1337,13 @@  discard block
 block discarded – undo
1337 1337
 		$savedoffset = $offset;
1338 1338
 		do {
1339 1339
 			$search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset);
1340
-			if($search === false) {
1340
+			if ($search === false) {
1341 1341
 				return [];
1342 1342
 			}
1343 1343
 			list($sr, $pagedSearchOK) = $search;
1344 1344
 			$cr = $this->connection->getConnectionResource();
1345 1345
 
1346
-			if($skipHandling) {
1346
+			if ($skipHandling) {
1347 1347
 				//i.e. result do not need to be fetched, we just need the cookie
1348 1348
 				//thus pass 1 or any other value as $iFoundItems because it is not
1349 1349
 				//used
@@ -1354,7 +1354,7 @@  discard block
 block discarded – undo
1354 1354
 			}
1355 1355
 
1356 1356
 			$iFoundItems = 0;
1357
-			foreach($sr as $res) {
1357
+			foreach ($sr as $res) {
1358 1358
 				$findings = array_merge($findings, $this->invokeLDAPMethod('getEntries', $cr, $res));
1359 1359
 				$iFoundItems = max($iFoundItems, $findings['count']);
1360 1360
 				unset($findings['count']);
@@ -1370,27 +1370,27 @@  discard block
 block discarded – undo
1370 1370
 
1371 1371
 		// if we're here, probably no connection resource is returned.
1372 1372
 		// to make Nextcloud behave nicely, we simply give back an empty array.
1373
-		if(is_null($findings)) {
1373
+		if (is_null($findings)) {
1374 1374
 			return [];
1375 1375
 		}
1376 1376
 
1377
-		if(!is_null($attr)) {
1377
+		if (!is_null($attr)) {
1378 1378
 			$selection = [];
1379 1379
 			$i = 0;
1380
-			foreach($findings as $item) {
1381
-				if(!is_array($item)) {
1380
+			foreach ($findings as $item) {
1381
+				if (!is_array($item)) {
1382 1382
 					continue;
1383 1383
 				}
1384 1384
 				$item = \OCP\Util::mb_array_change_key_case($item, MB_CASE_LOWER, 'UTF-8');
1385
-				foreach($attr as $key) {
1386
-					if(isset($item[$key])) {
1387
-						if(is_array($item[$key]) && isset($item[$key]['count'])) {
1385
+				foreach ($attr as $key) {
1386
+					if (isset($item[$key])) {
1387
+						if (is_array($item[$key]) && isset($item[$key]['count'])) {
1388 1388
 							unset($item[$key]['count']);
1389 1389
 						}
1390
-						if($key !== 'dn') {
1391
-							if($this->resemblesDN($key)) {
1390
+						if ($key !== 'dn') {
1391
+							if ($this->resemblesDN($key)) {
1392 1392
 								$selection[$i][$key] = $this->helper->sanitizeDN($item[$key]);
1393
-							} else if($key === 'objectguid' || $key === 'guid') {
1393
+							} else if ($key === 'objectguid' || $key === 'guid') {
1394 1394
 								$selection[$i][$key] = [$this->convertObjectGUID2Str($item[$key][0])];
1395 1395
 							} else {
1396 1396
 								$selection[$i][$key] = $item[$key];
@@ -1408,14 +1408,14 @@  discard block
 block discarded – undo
1408 1408
 		//we slice the findings, when
1409 1409
 		//a) paged search unsuccessful, though attempted
1410 1410
 		//b) no paged search, but limit set
1411
-		if((!$this->getPagedSearchResultState()
1411
+		if ((!$this->getPagedSearchResultState()
1412 1412
 			&& $pagedSearchOK)
1413 1413
 			|| (
1414 1414
 				!$pagedSearchOK
1415 1415
 				&& !is_null($limit)
1416 1416
 			)
1417 1417
 		) {
1418
-			$findings = array_slice($findings, (int)$offset, $limit);
1418
+			$findings = array_slice($findings, (int) $offset, $limit);
1419 1419
 		}
1420 1420
 		return $findings;
1421 1421
 	}
@@ -1428,13 +1428,13 @@  discard block
 block discarded – undo
1428 1428
 	public function sanitizeUsername($name) {
1429 1429
 		$name = trim($name);
1430 1430
 
1431
-		if($this->connection->ldapIgnoreNamingRules) {
1431
+		if ($this->connection->ldapIgnoreNamingRules) {
1432 1432
 			return $name;
1433 1433
 		}
1434 1434
 
1435 1435
 		// Transliteration to ASCII
1436 1436
 		$transliterated = @iconv('UTF-8', 'ASCII//TRANSLIT', $name);
1437
-		if($transliterated !== false) {
1437
+		if ($transliterated !== false) {
1438 1438
 			// depending on system config iconv can work or not
1439 1439
 			$name = $transliterated;
1440 1440
 		}
@@ -1445,7 +1445,7 @@  discard block
 block discarded – undo
1445 1445
 		// Every remaining disallowed characters will be removed
1446 1446
 		$name = preg_replace('/[^a-zA-Z0-9_.@-]/u', '', $name);
1447 1447
 
1448
-		if($name === '') {
1448
+		if ($name === '') {
1449 1449
 			throw new \InvalidArgumentException('provided name template for username does not contain any allowed characters');
1450 1450
 		}
1451 1451
 
@@ -1460,13 +1460,13 @@  discard block
 block discarded – undo
1460 1460
 	 */
1461 1461
 	public function escapeFilterPart($input, $allowAsterisk = false) {
1462 1462
 		$asterisk = '';
1463
-		if($allowAsterisk && strlen($input) > 0 && $input[0] === '*') {
1463
+		if ($allowAsterisk && strlen($input) > 0 && $input[0] === '*') {
1464 1464
 			$asterisk = '*';
1465 1465
 			$input = mb_substr($input, 1, null, 'UTF-8');
1466 1466
 		}
1467 1467
 		$search  = ['*', '\\', '(', ')'];
1468 1468
 		$replace = ['\\*', '\\\\', '\\(', '\\)'];
1469
-		return $asterisk . str_replace($search, $replace, $input);
1469
+		return $asterisk.str_replace($search, $replace, $input);
1470 1470
 	}
1471 1471
 
1472 1472
 	/**
@@ -1496,13 +1496,13 @@  discard block
 block discarded – undo
1496 1496
 	 */
1497 1497
 	private function combineFilter($filters, $operator) {
1498 1498
 		$combinedFilter = '('.$operator;
1499
-		foreach($filters as $filter) {
1499
+		foreach ($filters as $filter) {
1500 1500
 			if ($filter !== '' && $filter[0] !== '(') {
1501 1501
 				$filter = '('.$filter.')';
1502 1502
 			}
1503
-			$combinedFilter.=$filter;
1503
+			$combinedFilter .= $filter;
1504 1504
 		}
1505
-		$combinedFilter.=')';
1505
+		$combinedFilter .= ')';
1506 1506
 		return $combinedFilter;
1507 1507
 	}
1508 1508
 
@@ -1538,17 +1538,17 @@  discard block
 block discarded – undo
1538 1538
 	 * @throws \Exception
1539 1539
 	 */
1540 1540
 	private function getAdvancedFilterPartForSearch($search, $searchAttributes) {
1541
-		if(!is_array($searchAttributes) || count($searchAttributes) < 2) {
1541
+		if (!is_array($searchAttributes) || count($searchAttributes) < 2) {
1542 1542
 			throw new \Exception('searchAttributes must be an array with at least two string');
1543 1543
 		}
1544 1544
 		$searchWords = explode(' ', trim($search));
1545 1545
 		$wordFilters = [];
1546
-		foreach($searchWords as $word) {
1546
+		foreach ($searchWords as $word) {
1547 1547
 			$word = $this->prepareSearchTerm($word);
1548 1548
 			//every word needs to appear at least once
1549 1549
 			$wordMatchOneAttrFilters = [];
1550
-			foreach($searchAttributes as $attr) {
1551
-				$wordMatchOneAttrFilters[] = $attr . '=' . $word;
1550
+			foreach ($searchAttributes as $attr) {
1551
+				$wordMatchOneAttrFilters[] = $attr.'='.$word;
1552 1552
 			}
1553 1553
 			$wordFilters[] = $this->combineFilterWithOr($wordMatchOneAttrFilters);
1554 1554
 		}
@@ -1566,10 +1566,10 @@  discard block
 block discarded – undo
1566 1566
 	private function getFilterPartForSearch($search, $searchAttributes, $fallbackAttribute) {
1567 1567
 		$filter = [];
1568 1568
 		$haveMultiSearchAttributes = (is_array($searchAttributes) && count($searchAttributes) > 0);
1569
-		if($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) {
1569
+		if ($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) {
1570 1570
 			try {
1571 1571
 				return $this->getAdvancedFilterPartForSearch($search, $searchAttributes);
1572
-			} catch(\Exception $e) {
1572
+			} catch (\Exception $e) {
1573 1573
 				\OCP\Util::writeLog(
1574 1574
 					'user_ldap',
1575 1575
 					'Creating advanced filter for search failed, falling back to simple method.',
@@ -1579,17 +1579,17 @@  discard block
 block discarded – undo
1579 1579
 		}
1580 1580
 
1581 1581
 		$search = $this->prepareSearchTerm($search);
1582
-		if(!is_array($searchAttributes) || count($searchAttributes) === 0) {
1582
+		if (!is_array($searchAttributes) || count($searchAttributes) === 0) {
1583 1583
 			if ($fallbackAttribute === '') {
1584 1584
 				return '';
1585 1585
 			}
1586
-			$filter[] = $fallbackAttribute . '=' . $search;
1586
+			$filter[] = $fallbackAttribute.'='.$search;
1587 1587
 		} else {
1588
-			foreach($searchAttributes as $attribute) {
1589
-				$filter[] = $attribute . '=' . $search;
1588
+			foreach ($searchAttributes as $attribute) {
1589
+				$filter[] = $attribute.'='.$search;
1590 1590
 			}
1591 1591
 		}
1592
-		if(count($filter) === 1) {
1592
+		if (count($filter) === 1) {
1593 1593
 			return '('.$filter[0].')';
1594 1594
 		}
1595 1595
 		return $this->combineFilterWithOr($filter);
@@ -1610,7 +1610,7 @@  discard block
 block discarded – undo
1610 1610
 		if ($term === '') {
1611 1611
 			$result = '*';
1612 1612
 		} else if ($allowEnum !== 'no') {
1613
-			$result = $term . '*';
1613
+			$result = $term.'*';
1614 1614
 		}
1615 1615
 		return $result;
1616 1616
 	}
@@ -1622,7 +1622,7 @@  discard block
 block discarded – undo
1622 1622
 	public function getFilterForUserCount() {
1623 1623
 		$filter = $this->combineFilterWithAnd([
1624 1624
 			$this->connection->ldapUserFilter,
1625
-			$this->connection->ldapUserDisplayName . '=*'
1625
+			$this->connection->ldapUserDisplayName.'=*'
1626 1626
 		]);
1627 1627
 
1628 1628
 		return $filter;
@@ -1640,7 +1640,7 @@  discard block
 block discarded – undo
1640 1640
 			'ldapAgentName' => $name,
1641 1641
 			'ldapAgentPassword' => $password
1642 1642
 		];
1643
-		if(!$testConnection->setConfiguration($credentials)) {
1643
+		if (!$testConnection->setConfiguration($credentials)) {
1644 1644
 			return false;
1645 1645
 		}
1646 1646
 		return $testConnection->bind();
@@ -1662,30 +1662,30 @@  discard block
 block discarded – undo
1662 1662
 			// Sacrebleu! The UUID attribute is unknown :( We need first an
1663 1663
 			// existing DN to be able to reliably detect it.
1664 1664
 			$result = $this->search($filter, $base, ['dn'], 1);
1665
-			if(!isset($result[0]) || !isset($result[0]['dn'])) {
1665
+			if (!isset($result[0]) || !isset($result[0]['dn'])) {
1666 1666
 				throw new \Exception('Cannot determine UUID attribute');
1667 1667
 			}
1668 1668
 			$dn = $result[0]['dn'][0];
1669
-			if(!$this->detectUuidAttribute($dn, true)) {
1669
+			if (!$this->detectUuidAttribute($dn, true)) {
1670 1670
 				throw new \Exception('Cannot determine UUID attribute');
1671 1671
 			}
1672 1672
 		} else {
1673 1673
 			// The UUID attribute is either known or an override is given.
1674 1674
 			// By calling this method we ensure that $this->connection->$uuidAttr
1675 1675
 			// is definitely set
1676
-			if(!$this->detectUuidAttribute('', true)) {
1676
+			if (!$this->detectUuidAttribute('', true)) {
1677 1677
 				throw new \Exception('Cannot determine UUID attribute');
1678 1678
 			}
1679 1679
 		}
1680 1680
 
1681 1681
 		$uuidAttr = $this->connection->ldapUuidUserAttribute;
1682
-		if($uuidAttr === 'guid' || $uuidAttr === 'objectguid') {
1682
+		if ($uuidAttr === 'guid' || $uuidAttr === 'objectguid') {
1683 1683
 			$uuid = $this->formatGuid2ForFilterUser($uuid);
1684 1684
 		}
1685 1685
 
1686
-		$filter = $uuidAttr . '=' . $uuid;
1686
+		$filter = $uuidAttr.'='.$uuid;
1687 1687
 		$result = $this->searchUsers($filter, ['dn'], 2);
1688
-		if(is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) {
1688
+		if (is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) {
1689 1689
 			// we put the count into account to make sure that this is
1690 1690
 			// really unique
1691 1691
 			return $result[0]['dn'][0];
@@ -1705,7 +1705,7 @@  discard block
 block discarded – undo
1705 1705
 	 * @throws ServerNotAvailableException
1706 1706
 	 */
1707 1707
 	private function detectUuidAttribute($dn, $isUser = true, $force = false, array $ldapRecord = null) {
1708
-		if($isUser) {
1708
+		if ($isUser) {
1709 1709
 			$uuidAttr     = 'ldapUuidUserAttribute';
1710 1710
 			$uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
1711 1711
 		} else {
@@ -1713,8 +1713,8 @@  discard block
 block discarded – undo
1713 1713
 			$uuidOverride = $this->connection->ldapExpertUUIDGroupAttr;
1714 1714
 		}
1715 1715
 
1716
-		if(!$force) {
1717
-			if($this->connection->$uuidAttr !== 'auto') {
1716
+		if (!$force) {
1717
+			if ($this->connection->$uuidAttr !== 'auto') {
1718 1718
 				return true;
1719 1719
 			} else if (is_string($uuidOverride) && trim($uuidOverride) !== '') {
1720 1720
 				$this->connection->$uuidAttr = $uuidOverride;
@@ -1722,23 +1722,23 @@  discard block
 block discarded – undo
1722 1722
 			}
1723 1723
 
1724 1724
 			$attribute = $this->connection->getFromCache($uuidAttr);
1725
-			if(!$attribute === null) {
1725
+			if (!$attribute === null) {
1726 1726
 				$this->connection->$uuidAttr = $attribute;
1727 1727
 				return true;
1728 1728
 			}
1729 1729
 		}
1730 1730
 
1731
-		foreach(self::UUID_ATTRIBUTES as $attribute) {
1732
-			if($ldapRecord !== null) {
1731
+		foreach (self::UUID_ATTRIBUTES as $attribute) {
1732
+			if ($ldapRecord !== null) {
1733 1733
 				// we have the info from LDAP already, we don't need to talk to the server again
1734
-				if(isset($ldapRecord[$attribute])) {
1734
+				if (isset($ldapRecord[$attribute])) {
1735 1735
 					$this->connection->$uuidAttr = $attribute;
1736 1736
 					return true;
1737 1737
 				}
1738 1738
 			}
1739 1739
 
1740 1740
 			$value = $this->readAttribute($dn, $attribute);
1741
-			if(is_array($value) && isset($value[0]) && !empty($value[0])) {
1741
+			if (is_array($value) && isset($value[0]) && !empty($value[0])) {
1742 1742
 				\OC::$server->getLogger()->debug(
1743 1743
 					'Setting {attribute} as {subject}',
1744 1744
 					[
@@ -1765,7 +1765,7 @@  discard block
 block discarded – undo
1765 1765
 	 * @throws ServerNotAvailableException
1766 1766
 	 */
1767 1767
 	public function getUUID($dn, $isUser = true, $ldapRecord = null) {
1768
-		if($isUser) {
1768
+		if ($isUser) {
1769 1769
 			$uuidAttr     = 'ldapUuidUserAttribute';
1770 1770
 			$uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
1771 1771
 		} else {
@@ -1774,10 +1774,10 @@  discard block
 block discarded – undo
1774 1774
 		}
1775 1775
 
1776 1776
 		$uuid = false;
1777
-		if($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) {
1777
+		if ($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) {
1778 1778
 			$attr = $this->connection->$uuidAttr;
1779 1779
 			$uuid = isset($ldapRecord[$attr]) ? $ldapRecord[$attr] : $this->readAttribute($dn, $attr);
1780
-			if( !is_array($uuid)
1780
+			if (!is_array($uuid)
1781 1781
 				&& $uuidOverride !== ''
1782 1782
 				&& $this->detectUuidAttribute($dn, $isUser, true, $ldapRecord))
1783 1783
 			{
@@ -1785,7 +1785,7 @@  discard block
 block discarded – undo
1785 1785
 					? $ldapRecord[$this->connection->$uuidAttr]
1786 1786
 					: $this->readAttribute($dn, $this->connection->$uuidAttr);
1787 1787
 			}
1788
-			if(is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) {
1788
+			if (is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) {
1789 1789
 				$uuid = $uuid[0];
1790 1790
 			}
1791 1791
 		}
@@ -1802,19 +1802,19 @@  discard block
 block discarded – undo
1802 1802
 	private function convertObjectGUID2Str($oguid) {
1803 1803
 		$hex_guid = bin2hex($oguid);
1804 1804
 		$hex_guid_to_guid_str = '';
1805
-		for($k = 1; $k <= 4; ++$k) {
1805
+		for ($k = 1; $k <= 4; ++$k) {
1806 1806
 			$hex_guid_to_guid_str .= substr($hex_guid, 8 - 2 * $k, 2);
1807 1807
 		}
1808 1808
 		$hex_guid_to_guid_str .= '-';
1809
-		for($k = 1; $k <= 2; ++$k) {
1809
+		for ($k = 1; $k <= 2; ++$k) {
1810 1810
 			$hex_guid_to_guid_str .= substr($hex_guid, 12 - 2 * $k, 2);
1811 1811
 		}
1812 1812
 		$hex_guid_to_guid_str .= '-';
1813
-		for($k = 1; $k <= 2; ++$k) {
1813
+		for ($k = 1; $k <= 2; ++$k) {
1814 1814
 			$hex_guid_to_guid_str .= substr($hex_guid, 16 - 2 * $k, 2);
1815 1815
 		}
1816
-		$hex_guid_to_guid_str .= '-' . substr($hex_guid, 16, 4);
1817
-		$hex_guid_to_guid_str .= '-' . substr($hex_guid, 20);
1816
+		$hex_guid_to_guid_str .= '-'.substr($hex_guid, 16, 4);
1817
+		$hex_guid_to_guid_str .= '-'.substr($hex_guid, 20);
1818 1818
 
1819 1819
 		return strtoupper($hex_guid_to_guid_str);
1820 1820
 	}
@@ -1831,11 +1831,11 @@  discard block
 block discarded – undo
1831 1831
 	 * @return string
1832 1832
 	 */
1833 1833
 	public function formatGuid2ForFilterUser($guid) {
1834
-		if(!is_string($guid)) {
1834
+		if (!is_string($guid)) {
1835 1835
 			throw new \InvalidArgumentException('String expected');
1836 1836
 		}
1837 1837
 		$blocks = explode('-', $guid);
1838
-		if(count($blocks) !== 5) {
1838
+		if (count($blocks) !== 5) {
1839 1839
 			/*
1840 1840
 			 * Why not throw an Exception instead? This method is a utility
1841 1841
 			 * called only when trying to figure out whether a "missing" known
@@ -1848,20 +1848,20 @@  discard block
 block discarded – undo
1848 1848
 			 * user. Instead we write a log message.
1849 1849
 			 */
1850 1850
 			\OC::$server->getLogger()->info(
1851
-				'Passed string does not resemble a valid GUID. Known UUID ' .
1851
+				'Passed string does not resemble a valid GUID. Known UUID '.
1852 1852
 				'({uuid}) probably does not match UUID configuration.',
1853
-				[ 'app' => 'user_ldap', 'uuid' => $guid ]
1853
+				['app' => 'user_ldap', 'uuid' => $guid]
1854 1854
 			);
1855 1855
 			return $guid;
1856 1856
 		}
1857
-		for($i=0; $i < 3; $i++) {
1857
+		for ($i = 0; $i < 3; $i++) {
1858 1858
 			$pairs = str_split($blocks[$i], 2);
1859 1859
 			$pairs = array_reverse($pairs);
1860 1860
 			$blocks[$i] = implode('', $pairs);
1861 1861
 		}
1862
-		for($i=0; $i < 5; $i++) {
1862
+		for ($i = 0; $i < 5; $i++) {
1863 1863
 			$pairs = str_split($blocks[$i], 2);
1864
-			$blocks[$i] = '\\' . implode('\\', $pairs);
1864
+			$blocks[$i] = '\\'.implode('\\', $pairs);
1865 1865
 		}
1866 1866
 		return implode('', $blocks);
1867 1867
 	}
@@ -1877,12 +1877,12 @@  discard block
 block discarded – undo
1877 1877
 		$domainDN = $this->getDomainDNFromDN($dn);
1878 1878
 		$cacheKey = 'getSID-'.$domainDN;
1879 1879
 		$sid = $this->connection->getFromCache($cacheKey);
1880
-		if(!is_null($sid)) {
1880
+		if (!is_null($sid)) {
1881 1881
 			return $sid;
1882 1882
 		}
1883 1883
 
1884 1884
 		$objectSid = $this->readAttribute($domainDN, 'objectsid');
1885
-		if(!is_array($objectSid) || empty($objectSid)) {
1885
+		if (!is_array($objectSid) || empty($objectSid)) {
1886 1886
 			$this->connection->writeToCache($cacheKey, false);
1887 1887
 			return false;
1888 1888
 		}
@@ -1940,12 +1940,12 @@  discard block
 block discarded – undo
1940 1940
 		$belongsToBase = false;
1941 1941
 		$bases = $this->helper->sanitizeDN($bases);
1942 1942
 
1943
-		foreach($bases as $base) {
1943
+		foreach ($bases as $base) {
1944 1944
 			$belongsToBase = true;
1945
-			if(mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8')-mb_strlen($base, 'UTF-8'))) {
1945
+			if (mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8') - mb_strlen($base, 'UTF-8'))) {
1946 1946
 				$belongsToBase = false;
1947 1947
 			}
1948
-			if($belongsToBase) {
1948
+			if ($belongsToBase) {
1949 1949
 				break;
1950 1950
 			}
1951 1951
 		}
@@ -1974,16 +1974,16 @@  discard block
 block discarded – undo
1974 1974
 	 * @return string containing the key or empty if none is cached
1975 1975
 	 */
1976 1976
 	private function getPagedResultCookie($base, $filter, $limit, $offset) {
1977
-		if($offset === 0) {
1977
+		if ($offset === 0) {
1978 1978
 			return '';
1979 1979
 		}
1980 1980
 		$offset -= $limit;
1981 1981
 		//we work with cache here
1982
-		$cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . (int)$limit . '-' . (int)$offset;
1982
+		$cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.(int) $limit.'-'.(int) $offset;
1983 1983
 		$cookie = '';
1984
-		if(isset($this->cookies[$cacheKey])) {
1984
+		if (isset($this->cookies[$cacheKey])) {
1985 1985
 			$cookie = $this->cookies[$cacheKey];
1986
-			if(is_null($cookie)) {
1986
+			if (is_null($cookie)) {
1987 1987
 				$cookie = '';
1988 1988
 			}
1989 1989
 		}
@@ -2001,7 +2001,7 @@  discard block
 block discarded – undo
2001 2001
 	 * @return bool
2002 2002
 	 */
2003 2003
 	public function hasMoreResults() {
2004
-		if(empty($this->lastCookie) && $this->lastCookie !== '0') {
2004
+		if (empty($this->lastCookie) && $this->lastCookie !== '0') {
2005 2005
 			// as in RFC 2696, when all results are returned, the cookie will
2006 2006
 			// be empty.
2007 2007
 			return false;
@@ -2021,8 +2021,8 @@  discard block
 block discarded – undo
2021 2021
 	 */
2022 2022
 	private function setPagedResultCookie($base, $filter, $limit, $offset, $cookie) {
2023 2023
 		// allow '0' for 389ds
2024
-		if(!empty($cookie) || $cookie === '0') {
2025
-			$cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . (int)$limit . '-' . (int)$offset;
2024
+		if (!empty($cookie) || $cookie === '0') {
2025
+			$cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.(int) $limit.'-'.(int) $offset;
2026 2026
 			$this->cookies[$cacheKey] = $cookie;
2027 2027
 			$this->lastCookie = $cookie;
2028 2028
 		}
@@ -2052,16 +2052,16 @@  discard block
 block discarded – undo
2052 2052
 	private function initPagedSearch($filter, $bases, $attr, $limit, $offset) {
2053 2053
 		$pagedSearchOK = false;
2054 2054
 		if ($limit !== 0) {
2055
-			$offset = (int)$offset; //can be null
2055
+			$offset = (int) $offset; //can be null
2056 2056
 			\OCP\Util::writeLog('user_ldap',
2057 2057
 				'initializing paged search for  Filter '.$filter.' base '.print_r($bases, true)
2058
-				.' attr '.print_r($attr, true). ' limit ' .$limit.' offset '.$offset,
2058
+				.' attr '.print_r($attr, true).' limit '.$limit.' offset '.$offset,
2059 2059
 				ILogger::DEBUG);
2060 2060
 			//get the cookie from the search for the previous search, required by LDAP
2061
-			foreach($bases as $base) {
2061
+			foreach ($bases as $base) {
2062 2062
 
2063 2063
 				$cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset);
2064
-				if(empty($cookie) && $cookie !== "0" && ($offset > 0)) {
2064
+				if (empty($cookie) && $cookie !== "0" && ($offset > 0)) {
2065 2065
 					// no cookie known from a potential previous search. We need
2066 2066
 					// to start from 0 to come to the desired page. cookie value
2067 2067
 					// of '0' is valid, because 389ds
@@ -2071,17 +2071,17 @@  discard block
 block discarded – undo
2071 2071
 					//still no cookie? obviously, the server does not like us. Let's skip paging efforts.
2072 2072
 					// '0' is valid, because 389ds
2073 2073
 					//TODO: remember this, probably does not change in the next request...
2074
-					if(empty($cookie) && $cookie !== '0') {
2074
+					if (empty($cookie) && $cookie !== '0') {
2075 2075
 						$cookie = null;
2076 2076
 					}
2077 2077
 				}
2078
-				if(!is_null($cookie)) {
2078
+				if (!is_null($cookie)) {
2079 2079
 					//since offset = 0, this is a new search. We abandon other searches that might be ongoing.
2080 2080
 					$this->abandonPagedSearch();
2081 2081
 					$pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult',
2082 2082
 						$this->connection->getConnectionResource(), $limit,
2083 2083
 						false, $cookie);
2084
-					if(!$pagedSearchOK) {
2084
+					if (!$pagedSearchOK) {
2085 2085
 						return false;
2086 2086
 					}
2087 2087
 					\OCP\Util::writeLog('user_ldap', 'Ready for a paged search', ILogger::DEBUG);
@@ -2104,7 +2104,7 @@  discard block
 block discarded – undo
2104 2104
 			$this->abandonPagedSearch();
2105 2105
 			// in case someone set it to 0 … use 500, otherwise no results will
2106 2106
 			// be returned.
2107
-			$pageSize = (int)$this->connection->ldapPagingSize > 0 ? (int)$this->connection->ldapPagingSize : 500;
2107
+			$pageSize = (int) $this->connection->ldapPagingSize > 0 ? (int) $this->connection->ldapPagingSize : 500;
2108 2108
 			$pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult',
2109 2109
 				$this->connection->getConnectionResource(),
2110 2110
 				$pageSize, false, '');
Please login to merge, or discard this patch.
apps/user_ldap/lib/User_LDAP.php 1 patch
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -87,16 +87,16 @@  discard block
 block discarded – undo
87 87
 			return $this->userPluginManager->canChangeAvatar($uid);
88 88
 		}
89 89
 
90
-		if(!$this->implementsActions(Backend::PROVIDE_AVATAR)) {
90
+		if (!$this->implementsActions(Backend::PROVIDE_AVATAR)) {
91 91
 			return true;
92 92
 		}
93 93
 
94 94
 		$user = $this->access->userManager->get($uid);
95
-		if(!$user instanceof User) {
95
+		if (!$user instanceof User) {
96 96
 			return false;
97 97
 		}
98 98
 		$imageData = $user->getAvatarImage();
99
-		if($imageData === false) {
99
+		if ($imageData === false) {
100 100
 			return true;
101 101
 		}
102 102
 		return !$user->updateAvatar(true);
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	 * @throws \Exception
111 111
 	 */
112 112
 	public function loginName2UserName($loginName) {
113
-		$cacheKey = 'loginName2UserName-' . $loginName;
113
+		$cacheKey = 'loginName2UserName-'.$loginName;
114 114
 		$username = $this->access->connection->getFromCache($cacheKey);
115 115
 
116 116
 		if ($username !== null) {
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
 		//find out dn of the user name
157 157
 		$attrs = $this->access->userManager->getAttributes();
158 158
 		$users = $this->access->fetchUsersByLoginName($loginName, $attrs);
159
-		if(count($users) < 1) {
160
-			throw new NotOnLDAP('No user available for the given login name on ' .
161
-				$this->access->connection->ldapHost . ':' . $this->access->connection->ldapPort);
159
+		if (count($users) < 1) {
160
+			throw new NotOnLDAP('No user available for the given login name on '.
161
+				$this->access->connection->ldapHost.':'.$this->access->connection->ldapPort);
162 162
 		}
163 163
 		return $users[0];
164 164
 	}
@@ -173,23 +173,23 @@  discard block
 block discarded – undo
173 173
 	public function checkPassword($uid, $password) {
174 174
 		try {
175 175
 			$ldapRecord = $this->getLDAPUserByLoginName($uid);
176
-		} catch(NotOnLDAP $e) {
176
+		} catch (NotOnLDAP $e) {
177 177
 			\OC::$server->getLogger()->logException($e, ['app' => 'user_ldap', 'level' => ILogger::DEBUG]);
178 178
 			return false;
179 179
 		}
180 180
 		$dn = $ldapRecord['dn'][0];
181 181
 		$user = $this->access->userManager->get($dn);
182 182
 
183
-		if(!$user instanceof User) {
183
+		if (!$user instanceof User) {
184 184
 			Util::writeLog('user_ldap',
185
-				'LDAP Login: Could not get user object for DN ' . $dn .
185
+				'LDAP Login: Could not get user object for DN '.$dn.
186 186
 				'. Maybe the LDAP entry has no set display name attribute?',
187 187
 				ILogger::WARN);
188 188
 			return false;
189 189
 		}
190
-		if($user->getUsername() !== false) {
190
+		if ($user->getUsername() !== false) {
191 191
 			//are the credentials OK?
192
-			if(!$this->access->areCredentialsValid($dn, $password)) {
192
+			if (!$this->access->areCredentialsValid($dn, $password)) {
193 193
 				return false;
194 194
 			}
195 195
 
@@ -216,14 +216,14 @@  discard block
 block discarded – undo
216 216
 
217 217
 		$user = $this->access->userManager->get($uid);
218 218
 
219
-		if(!$user instanceof User) {
220
-			throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid .
219
+		if (!$user instanceof User) {
220
+			throw new \Exception('LDAP setPassword: Could not get user object for uid '.$uid.
221 221
 				'. Maybe the LDAP entry has no set display name attribute?');
222 222
 		}
223
-		if($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) {
223
+		if ($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) {
224 224
 			$ldapDefaultPPolicyDN = $this->access->connection->ldapDefaultPPolicyDN;
225 225
 			$turnOnPasswordChange = $this->access->connection->turnOnPasswordChange;
226
-			if (!empty($ldapDefaultPPolicyDN) && ((int)$turnOnPasswordChange === 1)) {
226
+			if (!empty($ldapDefaultPPolicyDN) && ((int) $turnOnPasswordChange === 1)) {
227 227
 				//remove last password expiry warning if any
228 228
 				$notification = $this->notificationManager->createNotification();
229 229
 				$notification->setApp('user_ldap')
@@ -252,18 +252,18 @@  discard block
 block discarded – undo
252 252
 
253 253
 		//check if users are cached, if so return
254 254
 		$ldap_users = $this->access->connection->getFromCache($cachekey);
255
-		if(!is_null($ldap_users)) {
255
+		if (!is_null($ldap_users)) {
256 256
 			return $ldap_users;
257 257
 		}
258 258
 
259 259
 		// if we'd pass -1 to LDAP search, we'd end up in a Protocol
260 260
 		// error. With a limit of 0, we get 0 results. So we pass null.
261
-		if($limit <= 0) {
261
+		if ($limit <= 0) {
262 262
 			$limit = null;
263 263
 		}
264 264
 		$filter = $this->access->combineFilterWithAnd([
265 265
 			$this->access->connection->ldapUserFilter,
266
-			$this->access->connection->ldapUserDisplayName . '=*',
266
+			$this->access->connection->ldapUserDisplayName.'=*',
267 267
 			$this->access->getFilterPartForUserSearch($search)
268 268
 		]);
269 269
 
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 			$this->access->userManager->getAttributes(true),
277 277
 			$limit, $offset);
278 278
 		$ldap_users = $this->access->nextcloudUserNames($ldap_users);
279
-		Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', ILogger::DEBUG);
279
+		Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users).' Users found', ILogger::DEBUG);
280 280
 
281 281
 		$this->access->connection->writeToCache($cachekey, $ldap_users);
282 282
 		return $ldap_users;
@@ -292,22 +292,22 @@  discard block
 block discarded – undo
292 292
 	 * @throws \OC\ServerNotAvailableException
293 293
 	 */
294 294
 	public function userExistsOnLDAP($user) {
295
-		if(is_string($user)) {
295
+		if (is_string($user)) {
296 296
 			$user = $this->access->userManager->get($user);
297 297
 		}
298
-		if(is_null($user)) {
298
+		if (is_null($user)) {
299 299
 			return false;
300 300
 		}
301 301
 		$uid = $user instanceof User ? $user->getUsername() : $user->getOCName();
302
-		$cacheKey = 'userExistsOnLDAP' . $uid;
302
+		$cacheKey = 'userExistsOnLDAP'.$uid;
303 303
 		$userExists = $this->access->connection->getFromCache($cacheKey);
304
-		if(!is_null($userExists)) {
305
-			return (bool)$userExists;
304
+		if (!is_null($userExists)) {
305
+			return (bool) $userExists;
306 306
 		}
307 307
 
308 308
 		$dn = $user->getDN();
309 309
 		//check if user really still exists by reading its entry
310
-		if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) {
310
+		if (!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) {
311 311
 			try {
312 312
 				$uuid = $this->access->getUserMapper()->getUUIDByDN($dn);
313 313
 				if (!$uuid) {
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 			}
332 332
 		}
333 333
 
334
-		if($user instanceof OfflineUser) {
334
+		if ($user instanceof OfflineUser) {
335 335
 			$user->unmark();
336 336
 		}
337 337
 
@@ -347,13 +347,13 @@  discard block
 block discarded – undo
347 347
 	 */
348 348
 	public function userExists($uid) {
349 349
 		$userExists = $this->access->connection->getFromCache('userExists'.$uid);
350
-		if(!is_null($userExists)) {
351
-			return (bool)$userExists;
350
+		if (!is_null($userExists)) {
351
+			return (bool) $userExists;
352 352
 		}
353 353
 		//getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking.
354 354
 		$user = $this->access->userManager->get($uid);
355 355
 
356
-		if(is_null($user)) {
356
+		if (is_null($user)) {
357 357
 			Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '.
358 358
 				$this->access->connection->ldapHost, ILogger::DEBUG);
359 359
 			$this->access->connection->writeToCache('userExists'.$uid, false);
@@ -373,19 +373,19 @@  discard block
 block discarded – undo
373 373
 	public function deleteUser($uid) {
374 374
 		if ($this->userPluginManager->canDeleteUser()) {
375 375
 			$status = $this->userPluginManager->deleteUser($uid);
376
-			if($status === false) {
376
+			if ($status === false) {
377 377
 				return false;
378 378
 			}
379 379
 		}
380 380
 
381 381
 		$marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0);
382
-		if((int)$marked === 0) {
382
+		if ((int) $marked === 0) {
383 383
 			\OC::$server->getLogger()->notice(
384
-				'User '.$uid . ' is not marked as deleted, not cleaning up.',
384
+				'User '.$uid.' is not marked as deleted, not cleaning up.',
385 385
 				['app' => 'user_ldap']);
386 386
 			return false;
387 387
 		}
388
-		\OC::$server->getLogger()->info('Cleaning up after user ' . $uid,
388
+		\OC::$server->getLogger()->info('Cleaning up after user '.$uid,
389 389
 			['app' => 'user_ldap']);
390 390
 
391 391
 		$this->access->getUserMapper()->unmap($uid); // we don't emit unassign signals here, since it is implicit to delete signals fired from core
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
 	 */
404 404
 	public function getHome($uid) {
405 405
 		// user Exists check required as it is not done in user proxy!
406
-		if(!$this->userExists($uid)) {
406
+		if (!$this->userExists($uid)) {
407 407
 			return false;
408 408
 		}
409 409
 
@@ -413,16 +413,16 @@  discard block
 block discarded – undo
413 413
 
414 414
 		$cacheKey = 'getHome'.$uid;
415 415
 		$path = $this->access->connection->getFromCache($cacheKey);
416
-		if(!is_null($path)) {
416
+		if (!is_null($path)) {
417 417
 			return $path;
418 418
 		}
419 419
 
420 420
 		// early return path if it is a deleted user
421 421
 		$user = $this->access->userManager->get($uid);
422
-		if($user instanceof User || $user instanceof OfflineUser) {
422
+		if ($user instanceof User || $user instanceof OfflineUser) {
423 423
 			$path = $user->getHomePath() ?: false;
424 424
 		} else {
425
-			throw new NoUserException($uid . ' is not a valid user anymore');
425
+			throw new NoUserException($uid.' is not a valid user anymore');
426 426
 		}
427 427
 
428 428
 		$this->access->cacheUserHome($uid, $path);
@@ -439,12 +439,12 @@  discard block
 block discarded – undo
439 439
 			return $this->userPluginManager->getDisplayName($uid);
440 440
 		}
441 441
 
442
-		if(!$this->userExists($uid)) {
442
+		if (!$this->userExists($uid)) {
443 443
 			return false;
444 444
 		}
445 445
 
446 446
 		$cacheKey = 'getDisplayName'.$uid;
447
-		if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
447
+		if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
448 448
 			return $displayName;
449 449
 		}
450 450
 
@@ -461,10 +461,10 @@  discard block
 block discarded – undo
461 461
 			$this->access->username2dn($uid),
462 462
 			$this->access->connection->ldapUserDisplayName);
463 463
 
464
-		if($displayName && (count($displayName) > 0)) {
464
+		if ($displayName && (count($displayName) > 0)) {
465 465
 			$displayName = $displayName[0];
466 466
 
467
-			if (is_array($displayName2)){
467
+			if (is_array($displayName2)) {
468 468
 				$displayName2 = count($displayName2) > 0 ? $displayName2[0] : '';
469 469
 			}
470 470
 
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
 	 */
509 509
 	public function getDisplayNames($search = '', $limit = null, $offset = null) {
510 510
 		$cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset;
511
-		if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) {
511
+		if (!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) {
512 512
 			return $displayNames;
513 513
 		}
514 514
 
@@ -530,12 +530,12 @@  discard block
 block discarded – undo
530 530
 	 * compared with \OC\User\Backend::CREATE_USER etc.
531 531
 	 */
532 532
 	public function implementsActions($actions) {
533
-		return (bool)((Backend::CHECK_PASSWORD
533
+		return (bool) ((Backend::CHECK_PASSWORD
534 534
 			| Backend::GET_HOME
535 535
 			| Backend::GET_DISPLAYNAME
536 536
 			| (($this->access->connection->ldapUserAvatarRule !== 'none') ? Backend::PROVIDE_AVATAR : 0)
537 537
 			| Backend::COUNT_USERS
538
-			| (((int)$this->access->connection->turnOnPasswordChange === 1)? Backend::SET_PASSWORD :0)
538
+			| (((int) $this->access->connection->turnOnPasswordChange === 1) ? Backend::SET_PASSWORD : 0)
539 539
 			| $this->userPluginManager->getImplementedActions())
540 540
 			& $actions);
541 541
 	}
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
 
560 560
 		$filter = $this->access->getFilterForUserCount();
561 561
 		$cacheKey = 'countUsers-'.$filter;
562
-		if(!is_null($entries = $this->access->connection->getFromCache($cacheKey))) {
562
+		if (!is_null($entries = $this->access->connection->getFromCache($cacheKey))) {
563 563
 			return $entries;
564 564
 		}
565 565
 		$entries = $this->access->countUsers($filter);
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
 	 * Backend name to be shown in user management
572 572
 	 * @return string the name of the backend to be shown
573 573
 	 */
574
-	public function getBackendName(){
574
+	public function getBackendName() {
575 575
 		return 'LDAP';
576 576
 	}
577 577
 	
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
 				if (is_string($dn)) {
610 610
 					// the NC user creation work flow requires a know user id up front
611 611
 					$uuid = $this->access->getUUID($dn, true);
612
-					if(is_string($uuid)) {
612
+					if (is_string($uuid)) {
613 613
 						$this->access->mapAndAnnounceIfApplicable(
614 614
 							$this->access->getUserMapper(),
615 615
 							$dn,
Please login to merge, or discard this patch.
apps/settings/lib/Controller/CheckSetupController.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 			'www.nextcloud.com', 'www.startpage.com', 'www.eff.org', 'www.edri.org'
138 138
 		]);
139 139
 
140
-		foreach($siteArray as $site) {
140
+		foreach ($siteArray as $site) {
141 141
 			if ($this->isSiteReachable($site)) {
142 142
 				return false;
143 143
 			}
@@ -150,8 +150,8 @@  discard block
 block discarded – undo
150 150
 	 * @return bool
151 151
 	 */
152 152
 	private function isSiteReachable($sitename) {
153
-		$httpSiteName = 'http://' . $sitename . '/';
154
-		$httpsSiteName = 'https://' . $sitename . '/';
153
+		$httpSiteName = 'http://'.$sitename.'/';
154
+		$httpsSiteName = 'https://'.$sitename.'/';
155 155
 
156 156
 		try {
157 157
 			$client = $this->clientService->newClient();
@@ -208,40 +208,40 @@  discard block
 block discarded – undo
208 208
 		// Don't run check when:
209 209
 		// 1. Server has `has_internet_connection` set to false
210 210
 		// 2. AppStore AND S2S is disabled
211
-		if(!$this->config->getSystemValue('has_internet_connection', true)) {
211
+		if (!$this->config->getSystemValue('has_internet_connection', true)) {
212 212
 			return '';
213 213
 		}
214
-		if(!$this->config->getSystemValue('appstoreenabled', true)
214
+		if (!$this->config->getSystemValue('appstoreenabled', true)
215 215
 			&& $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'no'
216 216
 			&& $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'no') {
217 217
 			return '';
218 218
 		}
219 219
 
220 220
 		$versionString = $this->getCurlVersion();
221
-		if(isset($versionString['ssl_version'])) {
221
+		if (isset($versionString['ssl_version'])) {
222 222
 			$versionString = $versionString['ssl_version'];
223 223
 		} else {
224 224
 			return '';
225 225
 		}
226 226
 
227
-		$features = (string)$this->l10n->t('installing and updating apps via the app store or Federated Cloud Sharing');
228
-		if(!$this->config->getSystemValue('appstoreenabled', true)) {
229
-			$features = (string)$this->l10n->t('Federated Cloud Sharing');
227
+		$features = (string) $this->l10n->t('installing and updating apps via the app store or Federated Cloud Sharing');
228
+		if (!$this->config->getSystemValue('appstoreenabled', true)) {
229
+			$features = (string) $this->l10n->t('Federated Cloud Sharing');
230 230
 		}
231 231
 
232 232
 		// Check if at least OpenSSL after 1.01d or 1.0.2b
233
-		if(strpos($versionString, 'OpenSSL/') === 0) {
233
+		if (strpos($versionString, 'OpenSSL/') === 0) {
234 234
 			$majorVersion = substr($versionString, 8, 5);
235 235
 			$patchRelease = substr($versionString, 13, 6);
236 236
 
237
-			if(($majorVersion === '1.0.1' && ord($patchRelease) < ord('d')) ||
237
+			if (($majorVersion === '1.0.1' && ord($patchRelease) < ord('d')) ||
238 238
 				($majorVersion === '1.0.2' && ord($patchRelease) < ord('b'))) {
239 239
 				return $this->l10n->t('cURL is using an outdated %1$s version (%2$s). Please update your operating system or features such as %3$s will not work reliably.', ['OpenSSL', $versionString, $features]);
240 240
 			}
241 241
 		}
242 242
 
243 243
 		// Check if NSS and perform heuristic check
244
-		if(strpos($versionString, 'NSS/') === 0) {
244
+		if (strpos($versionString, 'NSS/') === 0) {
245 245
 			try {
246 246
 				$firstClient = $this->clientService->newClient();
247 247
 				$firstClient->get('https://nextcloud.com/');
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 				$secondClient = $this->clientService->newClient();
250 250
 				$secondClient->get('https://nextcloud.com/');
251 251
 			} catch (ClientException $e) {
252
-				if($e->getResponse()->getStatusCode() === 400) {
252
+				if ($e->getResponse()->getStatusCode() === 400) {
253 253
 					return $this->l10n->t('cURL is using an outdated %1$s version (%2$s). Please update your operating system or features such as %3$s will not work reliably.', ['NSS', $versionString, $features]);
254 254
 				}
255 255
 			}
@@ -344,13 +344,13 @@  discard block
 block discarded – undo
344 344
 	 * @return DataResponse
345 345
 	 */
346 346
 	public function getFailedIntegrityCheckFiles() {
347
-		if(!$this->checker->isCodeCheckEnforced()) {
347
+		if (!$this->checker->isCodeCheckEnforced()) {
348 348
 			return new DataDisplayResponse('Integrity checker has been disabled. Integrity cannot be verified.');
349 349
 		}
350 350
 
351 351
 		$completeResults = $this->checker->getResults();
352 352
 
353
-		if(!empty($completeResults)) {
353
+		if (!empty($completeResults)) {
354 354
 			$formattedTextResponse = 'Technical information
355 355
 =====================
356 356
 The following list covers which files have failed the integrity check. Please read
@@ -360,12 +360,12 @@  discard block
 block discarded – undo
360 360
 Results
361 361
 =======
362 362
 ';
363
-			foreach($completeResults as $context => $contextResult) {
363
+			foreach ($completeResults as $context => $contextResult) {
364 364
 				$formattedTextResponse .= "- $context\n";
365 365
 
366
-				foreach($contextResult as $category => $result) {
366
+				foreach ($contextResult as $category => $result) {
367 367
 					$formattedTextResponse .= "\t- $category\n";
368
-					if($category !== 'EXCEPTION') {
368
+					if ($category !== 'EXCEPTION') {
369 369
 						foreach ($result as $key => $results) {
370 370
 							$formattedTextResponse .= "\t\t- $key\n";
371 371
 						}
@@ -406,23 +406,23 @@  discard block
 block discarded – undo
406 406
 	protected function isOpcacheProperlySetup() {
407 407
 		$iniWrapper = new IniGetWrapper();
408 408
 
409
-		if(!$iniWrapper->getBool('opcache.enable')) {
409
+		if (!$iniWrapper->getBool('opcache.enable')) {
410 410
 			return false;
411 411
 		}
412 412
 
413
-		if(!$iniWrapper->getBool('opcache.save_comments')) {
413
+		if (!$iniWrapper->getBool('opcache.save_comments')) {
414 414
 			return false;
415 415
 		}
416 416
 
417
-		if($iniWrapper->getNumeric('opcache.max_accelerated_files') < 10000) {
417
+		if ($iniWrapper->getNumeric('opcache.max_accelerated_files') < 10000) {
418 418
 			return false;
419 419
 		}
420 420
 
421
-		if($iniWrapper->getNumeric('opcache.memory_consumption') < 128) {
421
+		if ($iniWrapper->getNumeric('opcache.memory_consumption') < 128) {
422 422
 			return false;
423 423
 		}
424 424
 
425
-		if($iniWrapper->getNumeric('opcache.interned_strings_buffer') < 8) {
425
+		if ($iniWrapper->getNumeric('opcache.interned_strings_buffer') < 8) {
426 426
 			return false;
427 427
 		}
428 428
 
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
 	protected function getSuggestedOverwriteCliURL(): string {
489 489
 		$suggestedOverwriteCliUrl = '';
490 490
 		if ($this->config->getSystemValue('overwrite.cli.url', '') === '') {
491
-			$suggestedOverwriteCliUrl = $this->request->getServerProtocol() . '://' . $this->request->getInsecureServerHost() . \OC::$WEBROOT;
491
+			$suggestedOverwriteCliUrl = $this->request->getServerProtocol().'://'.$this->request->getInsecureServerHost().\OC::$WEBROOT;
492 492
 			if (!$this->config->getSystemValue('config_is_read_only', false)) {
493 493
 				// Set the overwrite URL when it was not set yet.
494 494
 				$this->config->setSystemValue('overwrite.cli.url', $suggestedOverwriteCliUrl);
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
 		return [
504 504
 			'diffInSeconds' => time() - $lastCronRun,
505 505
 			'relativeTime' => $this->dateTimeFormatter->formatTimeSpan($lastCronRun),
506
-			'backgroundJobsUrl' => $this->urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'server']) . '#backgroundjobs',
506
+			'backgroundJobsUrl' => $this->urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'server']).'#backgroundjobs',
507 507
 		];
508 508
 	}
509 509
 
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
 
562 562
 		foreach ($appsDir as $fileInfo) {
563 563
 			if ($fileInfo->isDir() && !$fileInfo->isDot()) {
564
-				$absAppPath = $appsPath . DIRECTORY_SEPARATOR . $fileInfo->getFilename();
564
+				$absAppPath = $appsPath.DIRECTORY_SEPARATOR.$fileInfo->getFilename();
565 565
 				$appDirUser = fileowner($absAppPath);
566 566
 				if ($appDirUser !== $currentUser) {
567 567
 					$appDirsWithDifferentOwner[] = $absAppPath;
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
 				$isAutoIncrement = $column->getAutoincrement();
628 628
 				$isAutoIncrementOnSqlite = $isSqlite && $isAutoIncrement;
629 629
 				if ($column->getType()->getName() !== Type::BIGINT && !$isAutoIncrementOnSqlite) {
630
-					$pendingColumns[] = $tableName . '.' . $columnName;
630
+					$pendingColumns[] = $tableName.'.'.$columnName;
631 631
 				}
632 632
 			}
633 633
 		}
@@ -653,12 +653,12 @@  discard block
 block discarded – undo
653 653
 
654 654
 		$tempPath = sys_get_temp_dir();
655 655
 		if (!is_dir($tempPath)) {
656
-			$this->logger->error('Error while checking the temporary PHP path - it was not properly set to a directory. value: ' . $tempPath);
656
+			$this->logger->error('Error while checking the temporary PHP path - it was not properly set to a directory. value: '.$tempPath);
657 657
 			return false;
658 658
 		}
659 659
 		$freeSpaceInTemp = disk_free_space($tempPath);
660 660
 		if ($freeSpaceInTemp === false) {
661
-			$this->logger->error('Error while checking the available disk space of temporary PHP path - no free disk space returned. temporary path: ' . $tempPath);
661
+			$this->logger->error('Error while checking the available disk space of temporary PHP path - no free disk space returned. temporary path: '.$tempPath);
662 662
 			return false;
663 663
 		}
664 664
 
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
 			return true;
668 668
 		}
669 669
 
670
-		$this->logger->warning('Checking the available space in the temporary path resulted in ' . round($freeSpaceInTempInGB, 1) . ' GB instead of the recommended 50GB. Path: ' . $tempPath);
670
+		$this->logger->warning('Checking the available space in the temporary path resulted in '.round($freeSpaceInTempInGB, 1).' GB instead of the recommended 50GB. Path: '.$tempPath);
671 671
 		return false;
672 672
 	}
673 673
 
Please login to merge, or discard this patch.
lib/public/App.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
 	 * @since 4.0.0
57 57
 	 * @deprecated 14.0.0 Use settings section in appinfo.xml to register personal admin sections
58 58
 	 */
59
-	public static function registerPersonal( $app, $page ) {
60
-		\OC_App::registerPersonal( $app, $page );
59
+	public static function registerPersonal($app, $page) {
60
+		\OC_App::registerPersonal($app, $page);
61 61
 	}
62 62
 
63 63
 	/**
@@ -68,8 +68,8 @@  discard block
 block discarded – undo
68 68
 	 * @since 4.0.0
69 69
 	 * @deprecated 14.0.0 Use settings section in appinfo.xml to register admin sections
70 70
 	 */
71
-	public static function registerAdmin( $app, $page ) {
72
-		\OC_App::registerAdmin( $app, $page );
71
+	public static function registerAdmin($app, $page) {
72
+		\OC_App::registerAdmin($app, $page);
73 73
 	}
74 74
 
75 75
 	/**
@@ -80,8 +80,8 @@  discard block
 block discarded – undo
80 80
 	 * @deprecated 14.0.0 ise \OC::$server->getAppManager()->getAppInfo($appId)
81 81
 	 * @since 4.0.0
82 82
 	 */
83
-	public static function getAppInfo( $app, $path=false ) {
84
-		return \OC_App::getAppInfo( $app, $path);
83
+	public static function getAppInfo($app, $path = false) {
84
+		return \OC_App::getAppInfo($app, $path);
85 85
 	}
86 86
 
87 87
 	/**
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
 	 * @since 4.0.0
94 94
 	 * @deprecated 13.0.0 use \OC::$server->getAppManager()->isEnabledForUser($appId)
95 95
 	 */
96
-	public static function isEnabled( $app ) {
97
-		return \OC::$server->getAppManager()->isEnabledForUser( $app );
96
+	public static function isEnabled($app) {
97
+		return \OC::$server->getAppManager()->isEnabledForUser($app);
98 98
 	}
99 99
 
100 100
 	/**
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 	 * @since 4.0.0
105 105
 	 * @deprecated 14.0.0 use \OC::$server->getAppManager()->getAppVersion($appId)
106 106
 	 */
107
-	public static function getAppVersion( $app ) {
107
+	public static function getAppVersion($app) {
108 108
 		return \OC::$server->getAppManager()->getAppVersion($app);
109 109
 	}
110 110
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/ApiController.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -59,9 +59,9 @@  discard block
 block discarded – undo
59 59
      */
60 60
     public function __construct($appName,
61 61
                                 IRequest $request,
62
-                                $corsMethods='PUT, POST, GET, DELETE, PATCH',
63
-                                $corsAllowedHeaders='Authorization, Content-Type, Accept',
64
-                                $corsMaxAge=1728000){
62
+                                $corsMethods = 'PUT, POST, GET, DELETE, PATCH',
63
+                                $corsAllowedHeaders = 'Authorization, Content-Type, Accept',
64
+                                $corsMaxAge = 1728000) {
65 65
         parent::__construct($appName, $request);
66 66
         $this->corsMethods = $corsMethods;
67 67
         $this->corsAllowedHeaders = $corsAllowedHeaders;
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
      * @since 7.0.0
80 80
      */
81 81
     public function preflightedCors() {
82
-        if(isset($this->request->server['HTTP_ORIGIN'])) {
82
+        if (isset($this->request->server['HTTP_ORIGIN'])) {
83 83
             $origin = $this->request->server['HTTP_ORIGIN'];
84 84
         } else {
85 85
             $origin = '*';
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
         $response = new Response();
89 89
         $response->addHeader('Access-Control-Allow-Origin', $origin);
90 90
         $response->addHeader('Access-Control-Allow-Methods', $this->corsMethods);
91
-        $response->addHeader('Access-Control-Max-Age', (string)$this->corsMaxAge);
91
+        $response->addHeader('Access-Control-Max-Age', (string) $this->corsMaxAge);
92 92
         $response->addHeader('Access-Control-Allow-Headers', $this->corsAllowedHeaders);
93 93
         $response->addHeader('Access-Control-Allow-Credentials', 'false');
94 94
         return $response;
Please login to merge, or discard this patch.
lib/private/User/Backend.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -39,14 +39,14 @@  discard block
 block discarded – undo
39 39
 	/**
40 40
 	 * actions that user backends can define
41 41
 	 */
42
-	const CREATE_USER		= 1;			// 1 << 0
43
-	const SET_PASSWORD		= 16;			// 1 << 4
44
-	const CHECK_PASSWORD	= 256;			// 1 << 8
45
-	const GET_HOME			= 4096;			// 1 << 12
46
-	const GET_DISPLAYNAME	= 65536;		// 1 << 16
47
-	const SET_DISPLAYNAME	= 1048576;		// 1 << 20
48
-	const PROVIDE_AVATAR	= 16777216;		// 1 << 24
49
-	const COUNT_USERS		= 268435456;	// 1 << 28
42
+	const CREATE_USER = 1; // 1 << 0
43
+	const SET_PASSWORD = 16; // 1 << 4
44
+	const CHECK_PASSWORD = 256; // 1 << 8
45
+	const GET_HOME = 4096; // 1 << 12
46
+	const GET_DISPLAYNAME	= 65536; // 1 << 16
47
+	const SET_DISPLAYNAME	= 1048576; // 1 << 20
48
+	const PROVIDE_AVATAR = 16777216; // 1 << 24
49
+	const COUNT_USERS = 268435456; // 1 << 28
50 50
 
51 51
 	protected $possibleActions = [
52 52
 		self::CREATE_USER => 'createUser',
@@ -68,8 +68,8 @@  discard block
 block discarded – undo
68 68
 	 */
69 69
 	public function getSupportedActions() {
70 70
 		$actions = 0;
71
-		foreach($this->possibleActions AS $action => $methodName) {
72
-			if(method_exists($this, $methodName)) {
71
+		foreach ($this->possibleActions AS $action => $methodName) {
72
+			if (method_exists($this, $methodName)) {
73 73
 				$actions |= $action;
74 74
 			}
75 75
 		}
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 	 * compared with self::CREATE_USER etc.
87 87
 	 */
88 88
 	public function implementsActions($actions) {
89
-		return (bool)($this->getSupportedActions() & $actions);
89
+		return (bool) ($this->getSupportedActions() & $actions);
90 90
 	}
91 91
 
92 92
 	/**
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	 *
97 97
 	 * Deletes a user
98 98
 	 */
99
-	public function deleteUser( $uid ) {
99
+	public function deleteUser($uid) {
100 100
 		return false;
101 101
 	}
102 102
 
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	public function getDisplayNames($search = '', $limit = null, $offset = null) {
151 151
 		$displayNames = [];
152 152
 		$users = $this->getUsers($search, $limit, $offset);
153
-		foreach ( $users as $user) {
153
+		foreach ($users as $user) {
154 154
 			$displayNames[$user] = $user;
155 155
 		}
156 156
 		return $displayNames;
Please login to merge, or discard this patch.