Passed
Push — master ( 62403d...0c3e2f )
by Joas
14:50 queued 14s
created
apps/user_ldap/lib/Command/TestConfig.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -51,17 +51,17 @@  discard block
 block discarded – undo
51 51
 		$helper = new Helper(\OC::$server->getConfig());
52 52
 		$availableConfigs = $helper->getServerConfigurationPrefixes();
53 53
 		$configID = $input->getArgument('configID');
54
-		if(!in_array($configID, $availableConfigs)) {
54
+		if (!in_array($configID, $availableConfigs)) {
55 55
 			$output->writeln("Invalid configID");
56 56
 			return;
57 57
 		}
58 58
 
59 59
 		$result = $this->testConfig($configID);
60
-		if($result === 0) {
60
+		if ($result === 0) {
61 61
 			$output->writeln('The configuration is valid and the connection could be established!');
62
-		} else if($result === 1) {
62
+		} else if ($result === 1) {
63 63
 			$output->writeln('The configuration is invalid. Please have a look at the logs for further details.');
64
-		} else if($result === 2) {
64
+		} else if ($result === 2) {
65 65
 			$output->writeln('The configuration is valid, but the Bind failed. Please check the server settings and credentials.');
66 66
 		} else {
67 67
 			$output->writeln('Your LDAP server was kidnapped by aliens.');
@@ -80,12 +80,12 @@  discard block
 block discarded – undo
80 80
 		//ensure validation is run before we attempt the bind
81 81
 		$connection->getConfiguration();
82 82
 
83
-		if(!$connection->setConfiguration([
83
+		if (!$connection->setConfiguration([
84 84
 			'ldap_configuration_active' => 1,
85 85
 		])) {
86 86
 			return 1;
87 87
 		}
88
-		if($connection->bind()) {
88
+		if ($connection->bind()) {
89 89
 			return 0;
90 90
 		}
91 91
 		return 2;
Please login to merge, or discard this patch.
apps/user_ldap/lib/User/OfflineUser.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 	 * @return int
172 172
 	 */
173 173
 	public function getLastLogin() {
174
-		return (int)$this->lastLogin;
174
+		return (int) $this->lastLogin;
175 175
 	}
176 176
 
177 177
 	/**
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 	 * @return int
180 180
 	 */
181 181
 	public function getDetectedOn() {
182
-		return (int)$this->foundDeleted;
182
+		return (int) $this->foundDeleted;
183 183
 	}
184 184
 
185 185
 	/**
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 			'email'        => 'settings',
203 203
 			'lastLogin'    => 'login',
204 204
 		];
205
-		foreach($properties as $property => $app) {
205
+		foreach ($properties as $property => $app) {
206 206
 			$this->$property = $this->config->getUserValue($this->ocName, $app, $property, '');
207 207
 		}
208 208
 
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 		', 1);
226 226
 		$query->execute([$this->ocName]);
227 227
 		$sResult = $query->fetchColumn(0);
228
-		if((int)$sResult === 1) {
228
+		if ((int) $sResult === 1) {
229 229
 			$this->hasActiveShares = true;
230 230
 			return;
231 231
 		}
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 		', 1);
238 238
 		$query->execute([$this->ocName]);
239 239
 		$sResult = $query->fetchColumn(0);
240
-		if((int)$sResult === 1) {
240
+		if ((int) $sResult === 1) {
241 241
 			$this->hasActiveShares = true;
242 242
 			return;
243 243
 		}
Please login to merge, or discard this patch.
apps/user_ldap/lib/User/User.php 1 patch
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -154,17 +154,17 @@  discard block
 block discarded – undo
154 154
 	 * @return null
155 155
 	 */
156 156
 	public function update() {
157
-		if(is_null($this->dn)) {
157
+		if (is_null($this->dn)) {
158 158
 			return null;
159 159
 		}
160 160
 
161 161
 		$hasLoggedIn = $this->config->getUserValue($this->uid, 'user_ldap',
162 162
 				self::USER_PREFKEY_FIRSTLOGIN, 0);
163 163
 
164
-		if($this->needsRefresh()) {
164
+		if ($this->needsRefresh()) {
165 165
 			$this->updateEmail();
166 166
 			$this->updateQuota();
167
-			if($hasLoggedIn !== 0) {
167
+			if ($hasLoggedIn !== 0) {
168 168
 				//we do not need to try it, when the user has not been logged in
169 169
 				//before, because the file system will not be ready.
170 170
 				$this->updateAvatar();
@@ -182,12 +182,12 @@  discard block
 block discarded – undo
182 182
 	 */
183 183
 	public function markUser() {
184 184
 		$curValue = $this->config->getUserValue($this->getUsername(), 'user_ldap', 'isDeleted', '0');
185
-		if($curValue === '1') {
185
+		if ($curValue === '1') {
186 186
 			// the user is already marked, do not write to DB again
187 187
 			return;
188 188
 		}
189 189
 		$this->config->setUserValue($this->getUsername(), 'user_ldap', 'isDeleted', '1');
190
-		$this->config->setUserValue($this->getUsername(), 'user_ldap', 'foundDeleted', (string)time());
190
+		$this->config->setUserValue($this->getUsername(), 'user_ldap', 'foundDeleted', (string) time());
191 191
 	}
192 192
 
193 193
 	/**
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 		$this->markRefreshTime();
199 199
 		//Quota
200 200
 		$attr = strtolower($this->connection->ldapQuotaAttribute);
201
-		if(isset($ldapEntry[$attr])) {
201
+		if (isset($ldapEntry[$attr])) {
202 202
 			$this->updateQuota($ldapEntry[$attr][0]);
203 203
 		} else {
204 204
 			if ($this->connection->ldapQuotaDefault !== '') {
@@ -210,12 +210,12 @@  discard block
 block discarded – undo
210 210
 		//displayName
211 211
 		$displayName = $displayName2 = '';
212 212
 		$attr = strtolower($this->connection->ldapUserDisplayName);
213
-		if(isset($ldapEntry[$attr])) {
214
-			$displayName = (string)$ldapEntry[$attr][0];
213
+		if (isset($ldapEntry[$attr])) {
214
+			$displayName = (string) $ldapEntry[$attr][0];
215 215
 		}
216 216
 		$attr = strtolower($this->connection->ldapUserDisplayName2);
217
-		if(isset($ldapEntry[$attr])) {
218
-			$displayName2 = (string)$ldapEntry[$attr][0];
217
+		if (isset($ldapEntry[$attr])) {
218
+			$displayName2 = (string) $ldapEntry[$attr][0];
219 219
 		}
220 220
 		if ($displayName !== '') {
221 221
 			$this->composeAndStoreDisplayName($displayName, $displayName2);
@@ -231,22 +231,22 @@  discard block
 block discarded – undo
231 231
 		//email must be stored after displayname, because it would cause a user
232 232
 		//change event that will trigger fetching the display name again
233 233
 		$attr = strtolower($this->connection->ldapEmailAttribute);
234
-		if(isset($ldapEntry[$attr])) {
234
+		if (isset($ldapEntry[$attr])) {
235 235
 			$this->updateEmail($ldapEntry[$attr][0]);
236 236
 		}
237 237
 		unset($attr);
238 238
 
239 239
 		// LDAP Username, needed for s2s sharing
240
-		if(isset($ldapEntry['uid'])) {
240
+		if (isset($ldapEntry['uid'])) {
241 241
 			$this->storeLDAPUserName($ldapEntry['uid'][0]);
242
-		} else if(isset($ldapEntry['samaccountname'])) {
242
+		} else if (isset($ldapEntry['samaccountname'])) {
243 243
 			$this->storeLDAPUserName($ldapEntry['samaccountname'][0]);
244 244
 		}
245 245
 
246 246
 		//homePath
247
-		if(strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) {
247
+		if (strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) {
248 248
 			$attr = strtolower(substr($this->connection->homeFolderNamingRule, strlen('attr:')));
249
-			if(isset($ldapEntry[$attr])) {
249
+			if (isset($ldapEntry[$attr])) {
250 250
 				$this->access->cacheUserHome(
251 251
 					$this->getUsername(), $this->getHomePath($ldapEntry[$attr][0]));
252 252
 			}
@@ -255,14 +255,14 @@  discard block
 block discarded – undo
255 255
 		//memberOf groups
256 256
 		$cacheKey = 'getMemberOf'.$this->getUsername();
257 257
 		$groups = false;
258
-		if(isset($ldapEntry['memberof'])) {
258
+		if (isset($ldapEntry['memberof'])) {
259 259
 			$groups = $ldapEntry['memberof'];
260 260
 		}
261 261
 		$this->connection->writeToCache($cacheKey, $groups);
262 262
 
263 263
 		//external storage var
264 264
 		$attr = strtolower($this->connection->ldapExtStorageHomeAttribute);
265
-		if(isset($ldapEntry[$attr])) {
265
+		if (isset($ldapEntry[$attr])) {
266 266
 			$this->updateExtStorageHome($ldapEntry[$attr][0]);
267 267
 		}
268 268
 		unset($attr);
@@ -271,8 +271,8 @@  discard block
 block discarded – undo
271 271
 		/** @var Connection $connection */
272 272
 		$connection = $this->access->getConnection();
273 273
 		$attributes = $connection->resolveRule('avatar');
274
-		foreach ($attributes as $attribute)  {
275
-			if(isset($ldapEntry[$attribute])) {
274
+		foreach ($attributes as $attribute) {
275
+			if (isset($ldapEntry[$attribute])) {
276 276
 				$this->avatarImage = $ldapEntry[$attribute][0];
277 277
 				// the call to the method that saves the avatar in the file
278 278
 				// system must be postponed after the login. It is to ensure
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
 	 * @throws \Exception
308 308
 	 */
309 309
 	public function getHomePath($valueFromLDAP = null) {
310
-		$path = (string)$valueFromLDAP;
310
+		$path = (string) $valueFromLDAP;
311 311
 		$attr = null;
312 312
 
313 313
 		if (is_null($valueFromLDAP)
@@ -325,12 +325,12 @@  discard block
 block discarded – undo
325 325
 		if ($path !== '') {
326 326
 			//if attribute's value is an absolute path take this, otherwise append it to data dir
327 327
 			//check for / at the beginning or pattern c:\ resp. c:/
328
-			if(   '/' !== $path[0]
328
+			if ('/' !== $path[0]
329 329
 			   && !(3 < strlen($path) && ctype_alpha($path[0])
330 330
 			       && $path[1] === ':' && ('\\' === $path[2] || '/' === $path[2]))
331 331
 			) {
332 332
 				$path = $this->config->getSystemValue('datadirectory',
333
-						\OC::$SERVERROOT.'/data' ) . '/' . $path;
333
+						\OC::$SERVERROOT.'/data').'/'.$path;
334 334
 			}
335 335
 			//we need it to store it in the DB as well in case a user gets
336 336
 			//deleted so we can clean up afterwards
@@ -340,11 +340,11 @@  discard block
 block discarded – undo
340 340
 			return $path;
341 341
 		}
342 342
 
343
-		if(    !is_null($attr)
343
+		if (!is_null($attr)
344 344
 			&& $this->config->getAppValue('user_ldap', 'enforce_home_folder_naming_rule', true)
345 345
 		) {
346 346
 			// a naming rule attribute is defined, but it doesn't exist for that LDAP user
347
-			throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: ' . $this->getUsername());
347
+			throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: '.$this->getUsername());
348 348
 		}
349 349
 
350 350
 		//false will apply default behaviour as defined and done by OC_User
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
 	public function getMemberOfGroups() {
356 356
 		$cacheKey = 'getMemberOf'.$this->getUsername();
357 357
 		$memberOfGroups = $this->connection->getFromCache($cacheKey);
358
-		if(!is_null($memberOfGroups)) {
358
+		if (!is_null($memberOfGroups)) {
359 359
 			return $memberOfGroups;
360 360
 		}
361 361
 		$groupDNs = $this->access->readAttribute($this->getDN(), 'memberOf');
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 	 * @return string data (provided by LDAP) | false
369 369
 	 */
370 370
 	public function getAvatarImage() {
371
-		if(!is_null($this->avatarImage)) {
371
+		if (!is_null($this->avatarImage)) {
372 372
 			return $this->avatarImage;
373 373
 		}
374 374
 
@@ -376,9 +376,9 @@  discard block
 block discarded – undo
376 376
 		/** @var Connection $connection */
377 377
 		$connection = $this->access->getConnection();
378 378
 		$attributes = $connection->resolveRule('avatar');
379
-		foreach($attributes as $attribute) {
379
+		foreach ($attributes as $attribute) {
380 380
 			$result = $this->access->readAttribute($this->dn, $attribute);
381
-			if($result !== false && is_array($result) && isset($result[0])) {
381
+			if ($result !== false && is_array($result) && isset($result[0])) {
382 382
 				$this->avatarImage = $result[0];
383 383
 				break;
384 384
 			}
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
 		$lastChecked = $this->config->getUserValue($this->uid, 'user_ldap',
416 416
 			self::USER_PREFKEY_LASTREFRESH, 0);
417 417
 
418
-		if((time() - (int)$lastChecked) < (int)$this->config->getAppValue('user_ldap', 'updateAttributesInterval', 86400)) {
418
+		if ((time() - (int) $lastChecked) < (int) $this->config->getAppValue('user_ldap', 'updateAttributesInterval', 86400)) {
419 419
 			return false;
420 420
 		}
421 421
 		return  true;
@@ -440,12 +440,12 @@  discard block
 block discarded – undo
440 440
 	 * @return string the effective display name
441 441
 	 */
442 442
 	public function composeAndStoreDisplayName($displayName, $displayName2 = '') {
443
-		$displayName2 = (string)$displayName2;
444
-		if($displayName2 !== '') {
445
-			$displayName .= ' (' . $displayName2 . ')';
443
+		$displayName2 = (string) $displayName2;
444
+		if ($displayName2 !== '') {
445
+			$displayName .= ' ('.$displayName2.')';
446 446
 		}
447 447
 		$oldName = $this->config->getUserValue($this->uid, 'user_ldap', 'displayName', null);
448
-		if ($oldName !== $displayName)  {
448
+		if ($oldName !== $displayName) {
449 449
 			$this->store('displayName', $displayName);
450 450
 			$user = $this->userManager->get($this->getUsername());
451 451
 			if (!empty($oldName) && $user instanceof \OC\User\User) {
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
 	 * @return bool
474 474
 	 */
475 475
 	private function wasRefreshed($feature) {
476
-		if(isset($this->refreshedFeatures[$feature])) {
476
+		if (isset($this->refreshedFeatures[$feature])) {
477 477
 			return true;
478 478
 		}
479 479
 		$this->refreshedFeatures[$feature] = 1;
@@ -486,23 +486,23 @@  discard block
 block discarded – undo
486 486
 	 * @return null
487 487
 	 */
488 488
 	public function updateEmail($valueFromLDAP = null) {
489
-		if($this->wasRefreshed('email')) {
489
+		if ($this->wasRefreshed('email')) {
490 490
 			return;
491 491
 		}
492
-		$email = (string)$valueFromLDAP;
493
-		if(is_null($valueFromLDAP)) {
492
+		$email = (string) $valueFromLDAP;
493
+		if (is_null($valueFromLDAP)) {
494 494
 			$emailAttribute = $this->connection->ldapEmailAttribute;
495 495
 			if ($emailAttribute !== '') {
496 496
 				$aEmail = $this->access->readAttribute($this->dn, $emailAttribute);
497
-				if(is_array($aEmail) && (count($aEmail) > 0)) {
498
-					$email = (string)$aEmail[0];
497
+				if (is_array($aEmail) && (count($aEmail) > 0)) {
498
+					$email = (string) $aEmail[0];
499 499
 				}
500 500
 			}
501 501
 		}
502 502
 		if ($email !== '') {
503 503
 			$user = $this->userManager->get($this->uid);
504 504
 			if (!is_null($user)) {
505
-				$currentEmail = (string)$user->getEMailAddress();
505
+				$currentEmail = (string) $user->getEMailAddress();
506 506
 				if ($currentEmail !== $email) {
507 507
 					$user->setEMailAddress($email);
508 508
 				}
@@ -531,35 +531,35 @@  discard block
 block discarded – undo
531 531
 	 * @return null
532 532
 	 */
533 533
 	public function updateQuota($valueFromLDAP = null) {
534
-		if($this->wasRefreshed('quota')) {
534
+		if ($this->wasRefreshed('quota')) {
535 535
 			return;
536 536
 		}
537 537
 
538 538
 		$quotaAttribute = $this->connection->ldapQuotaAttribute;
539 539
 		$defaultQuota = $this->connection->ldapQuotaDefault;
540
-		if($quotaAttribute === '' && $defaultQuota === '') {
540
+		if ($quotaAttribute === '' && $defaultQuota === '') {
541 541
 			return;
542 542
 		}
543 543
 
544 544
 		$quota = false;
545
-		if(is_null($valueFromLDAP) && $quotaAttribute !== '') {
545
+		if (is_null($valueFromLDAP) && $quotaAttribute !== '') {
546 546
 			$aQuota = $this->access->readAttribute($this->dn, $quotaAttribute);
547
-			if($aQuota && (count($aQuota) > 0) && $this->verifyQuotaValue($aQuota[0])) {
547
+			if ($aQuota && (count($aQuota) > 0) && $this->verifyQuotaValue($aQuota[0])) {
548 548
 				$quota = $aQuota[0];
549
-			} else if(is_array($aQuota) && isset($aQuota[0])) {
550
-				$this->log->log('no suitable LDAP quota found for user ' . $this->uid . ': [' . $aQuota[0] . ']', ILogger::DEBUG);
549
+			} else if (is_array($aQuota) && isset($aQuota[0])) {
550
+				$this->log->log('no suitable LDAP quota found for user '.$this->uid.': ['.$aQuota[0].']', ILogger::DEBUG);
551 551
 			}
552 552
 		} else if ($this->verifyQuotaValue($valueFromLDAP)) {
553 553
 			$quota = $valueFromLDAP;
554 554
 		} else {
555
-			$this->log->log('no suitable LDAP quota found for user ' . $this->uid . ': [' . $valueFromLDAP . ']', ILogger::DEBUG);
555
+			$this->log->log('no suitable LDAP quota found for user '.$this->uid.': ['.$valueFromLDAP.']', ILogger::DEBUG);
556 556
 		}
557 557
 
558 558
 		if ($quota === false && $this->verifyQuotaValue($defaultQuota)) {
559 559
 			// quota not found using the LDAP attribute (or not parseable). Try the default quota
560 560
 			$quota = $defaultQuota;
561
-		} else if($quota === false) {
562
-			$this->log->log('no suitable default quota found for user ' . $this->uid . ': [' . $defaultQuota . ']', ILogger::DEBUG);
561
+		} else if ($quota === false) {
562
+			$this->log->log('no suitable default quota found for user '.$this->uid.': ['.$defaultQuota.']', ILogger::DEBUG);
563 563
 			return;
564 564
 		}
565 565
 
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
 		if ($targetUser instanceof IUser) {
568 568
 			$targetUser->setQuota($quota);
569 569
 		} else {
570
-			$this->log->log('trying to set a quota for user ' . $this->uid . ' but the user is missing', ILogger::INFO);
570
+			$this->log->log('trying to set a quota for user '.$this->uid.' but the user is missing', ILogger::INFO);
571 571
 		}
572 572
 	}
573 573
 
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
 	 * @param array $params
582 582
 	 */
583 583
 	public function updateAvatarPostLogin($params) {
584
-		if(isset($params['uid']) && $params['uid'] === $this->getUsername()) {
584
+		if (isset($params['uid']) && $params['uid'] === $this->getUsername()) {
585 585
 			$this->updateAvatar();
586 586
 		}
587 587
 	}
@@ -591,29 +591,29 @@  discard block
 block discarded – undo
591 591
 	 * @return bool
592 592
 	 */
593 593
 	public function updateAvatar($force = false) {
594
-		if(!$force && $this->wasRefreshed('avatar')) {
594
+		if (!$force && $this->wasRefreshed('avatar')) {
595 595
 			return false;
596 596
 		}
597 597
 		$avatarImage = $this->getAvatarImage();
598
-		if($avatarImage === false) {
598
+		if ($avatarImage === false) {
599 599
 			//not set, nothing left to do;
600 600
 			return false;
601 601
 		}
602 602
 
603
-		if(!$this->image->loadFromBase64(base64_encode($avatarImage))) {
603
+		if (!$this->image->loadFromBase64(base64_encode($avatarImage))) {
604 604
 			return false;
605 605
 		}
606 606
 
607 607
 		// use the checksum before modifications
608 608
 		$checksum = md5($this->image->data());
609 609
 
610
-		if($checksum === $this->config->getUserValue($this->uid, 'user_ldap', 'lastAvatarChecksum', '')) {
610
+		if ($checksum === $this->config->getUserValue($this->uid, 'user_ldap', 'lastAvatarChecksum', '')) {
611 611
 			return true;
612 612
 		}
613 613
 
614 614
 		$isSet = $this->setOwnCloudAvatar();
615 615
 
616
-		if($isSet) {
616
+		if ($isSet) {
617 617
 			// save checksum only after successful setting
618 618
 			$this->config->setUserValue($this->uid, 'user_ldap', 'lastAvatarChecksum', $checksum);
619 619
 		}
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
 	 * @return bool
627 627
 	 */
628 628
 	private function setOwnCloudAvatar() {
629
-		if(!$this->image->valid()) {
629
+		if (!$this->image->valid()) {
630 630
 			$this->log->log('avatar image data from LDAP invalid for '.$this->dn, ILogger::ERROR);
631 631
 			return false;
632 632
 		}
@@ -634,12 +634,12 @@  discard block
 block discarded – undo
634 634
 
635 635
 		//make sure it is a square and not bigger than 128x128
636 636
 		$size = min([$this->image->width(), $this->image->height(), 128]);
637
-		if(!$this->image->centerCrop($size)) {
637
+		if (!$this->image->centerCrop($size)) {
638 638
 			$this->log->log('croping image for avatar failed for '.$this->dn, ILogger::ERROR);
639 639
 			return false;
640 640
 		}
641 641
 
642
-		if(!$this->fs->isLoaded()) {
642
+		if (!$this->fs->isLoaded()) {
643 643
 			$this->fs->setup($this->uid);
644 644
 		}
645 645
 
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
 			return true;
650 650
 		} catch (\Exception $e) {
651 651
 			\OC::$server->getLogger()->logException($e, [
652
-				'message' => 'Could not set avatar for ' . $this->dn,
652
+				'message' => 'Could not set avatar for '.$this->dn,
653 653
 				'level' => ILogger::INFO,
654 654
 				'app' => 'user_ldap',
655 655
 			]);
@@ -705,8 +705,8 @@  discard block
 block discarded – undo
705 705
 	 */
706 706
 	public function handlePasswordExpiry($params) {
707 707
 		$ppolicyDN = $this->connection->ldapDefaultPPolicyDN;
708
-		if (empty($ppolicyDN) || ((int)$this->connection->turnOnPasswordChange !== 1)) {
709
-			return;//password expiry handling disabled
708
+		if (empty($ppolicyDN) || ((int) $this->connection->turnOnPasswordChange !== 1)) {
709
+			return; //password expiry handling disabled
710 710
 		}
711 711
 		$uid = $params['uid'];
712 712
 		if (isset($uid) && $uid === $this->getUsername()) {
@@ -715,8 +715,8 @@  discard block
 block discarded – undo
715 715
 
716 716
 			if (array_key_exists('pwdpolicysubentry', $result[0])) {
717 717
 				$pwdPolicySubentry = $result[0]['pwdpolicysubentry'];
718
-				if ($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)){
719
-					$ppolicyDN = $pwdPolicySubentry[0];//custom ppolicy DN
718
+				if ($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)) {
719
+					$ppolicyDN = $pwdPolicySubentry[0]; //custom ppolicy DN
720 720
 				}
721 721
 			}
722 722
 
@@ -725,9 +725,9 @@  discard block
 block discarded – undo
725 725
 			$pwdChangedTime = array_key_exists('pwdchangedtime', $result[0]) ? $result[0]['pwdchangedtime'] : [];
726 726
 
727 727
 			//retrieve relevant password policy attributes
728
-			$cacheKey = 'ppolicyAttributes' . $ppolicyDN;
728
+			$cacheKey = 'ppolicyAttributes'.$ppolicyDN;
729 729
 			$result = $this->connection->getFromCache($cacheKey);
730
-			if(is_null($result)) {
730
+			if (is_null($result)) {
731 731
 				$result = $this->access->search('objectclass=*', [$ppolicyDN], ['pwdgraceauthnlimit', 'pwdmaxage', 'pwdexpirewarning']);
732 732
 				$this->connection->writeToCache($cacheKey, $result);
733 733
 			}
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
 			//handle grace login
740 740
 			if (!empty($pwdGraceUseTime)) { //was this a grace login?
741 741
 				if (!empty($pwdGraceAuthNLimit)
742
-					&& count($pwdGraceUseTime) < (int)$pwdGraceAuthNLimit[0]) { //at least one more grace login available?
742
+					&& count($pwdGraceUseTime) < (int) $pwdGraceAuthNLimit[0]) { //at least one more grace login available?
743 743
 					$this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true');
744 744
 					header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute(
745 745
 					'user_ldap.renewPassword.showRenewPasswordForm', ['user' => $uid]));
@@ -760,9 +760,9 @@  discard block
 block discarded – undo
760 760
 			if (!empty($pwdChangedTime)) {
761 761
 				if (!empty($pwdMaxAge)
762 762
 					&& !empty($pwdExpireWarning)) {
763
-					$pwdMaxAgeInt = (int)$pwdMaxAge[0];
764
-					$pwdExpireWarningInt = (int)$pwdExpireWarning[0];
765
-					if ($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0){
763
+					$pwdMaxAgeInt = (int) $pwdMaxAge[0];
764
+					$pwdExpireWarningInt = (int) $pwdExpireWarning[0];
765
+					if ($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0) {
766 766
 						$pwdChangedTimeDt = \DateTime::createFromFormat('YmdHisZ', $pwdChangedTime[0]);
767 767
 						$pwdChangedTimeDt->add(new \DateInterval('PT'.$pwdMaxAgeInt.'S'));
768 768
 						$currentDateTime = new \DateTime();
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
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 		parent::__construct($access);
73 73
 		$filter = $this->access->connection->ldapGroupFilter;
74 74
 		$gassoc = $this->access->connection->ldapGroupMemberAssocAttr;
75
-		if(!empty($filter) && !empty($gassoc)) {
75
+		if (!empty($filter) && !empty($gassoc)) {
76 76
 			$this->enabled = true;
77 77
 		}
78 78
 
@@ -91,25 +91,25 @@  discard block
 block discarded – undo
91 91
 	 * Checks whether the user is member of a group or not.
92 92
 	 */
93 93
 	public function inGroup($uid, $gid) {
94
-		if(!$this->enabled) {
94
+		if (!$this->enabled) {
95 95
 			return false;
96 96
 		}
97 97
 		$cacheKey = 'inGroup'.$uid.':'.$gid;
98 98
 		$inGroup = $this->access->connection->getFromCache($cacheKey);
99
-		if(!is_null($inGroup)) {
100
-			return (bool)$inGroup;
99
+		if (!is_null($inGroup)) {
100
+			return (bool) $inGroup;
101 101
 		}
102 102
 
103 103
 		$userDN = $this->access->username2dn($uid);
104 104
 
105
-		if(isset($this->cachedGroupMembers[$gid])) {
105
+		if (isset($this->cachedGroupMembers[$gid])) {
106 106
 			$isInGroup = in_array($userDN, $this->cachedGroupMembers[$gid]);
107 107
 			return $isInGroup;
108 108
 		}
109 109
 
110 110
 		$cacheKeyMembers = 'inGroup-members:'.$gid;
111 111
 		$members = $this->access->connection->getFromCache($cacheKeyMembers);
112
-		if(!is_null($members)) {
112
+		if (!is_null($members)) {
113 113
 			$this->cachedGroupMembers[$gid] = $members;
114 114
 			$isInGroup = in_array($userDN, $members, true);
115 115
 			$this->access->connection->writeToCache($cacheKey, $isInGroup);
@@ -118,34 +118,34 @@  discard block
 block discarded – undo
118 118
 
119 119
 		$groupDN = $this->access->groupname2dn($gid);
120 120
 		// just in case
121
-		if(!$groupDN || !$userDN) {
121
+		if (!$groupDN || !$userDN) {
122 122
 			$this->access->connection->writeToCache($cacheKey, false);
123 123
 			return false;
124 124
 		}
125 125
 
126 126
 		//check primary group first
127
-		if($gid === $this->getUserPrimaryGroup($userDN)) {
127
+		if ($gid === $this->getUserPrimaryGroup($userDN)) {
128 128
 			$this->access->connection->writeToCache($cacheKey, true);
129 129
 			return true;
130 130
 		}
131 131
 
132 132
 		//usually, LDAP attributes are said to be case insensitive. But there are exceptions of course.
133 133
 		$members = $this->_groupMembers($groupDN);
134
-		if(!is_array($members) || count($members) === 0) {
134
+		if (!is_array($members) || count($members) === 0) {
135 135
 			$this->access->connection->writeToCache($cacheKey, false);
136 136
 			return false;
137 137
 		}
138 138
 
139 139
 		//extra work if we don't get back user DNs
140
-		if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
140
+		if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
141 141
 			$dns = [];
142 142
 			$filterParts = [];
143 143
 			$bytes = 0;
144
-			foreach($members as $mid) {
144
+			foreach ($members as $mid) {
145 145
 				$filter = str_replace('%uid', $mid, $this->access->connection->ldapLoginFilter);
146 146
 				$filterParts[] = $filter;
147 147
 				$bytes += strlen($filter);
148
-				if($bytes >= 9000000) {
148
+				if ($bytes >= 9000000) {
149 149
 					// AD has a default input buffer of 10 MB, we do not want
150 150
 					// to take even the chance to exceed it
151 151
 					$filter = $this->access->combineFilterWithOr($filterParts);
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 					$dns = array_merge($dns, $users);
156 156
 				}
157 157
 			}
158
-			if(count($filterParts) > 0) {
158
+			if (count($filterParts) > 0) {
159 159
 				$filter = $this->access->combineFilterWithOr($filterParts);
160 160
 				$users = $this->access->fetchListOfUsers($filter, 'dn', count($filterParts));
161 161
 				$dns = array_merge($dns, $users);
@@ -198,14 +198,14 @@  discard block
 block discarded – undo
198 198
 			$pos = strpos($memberURLs[0], '(');
199 199
 			if ($pos !== false) {
200 200
 				$memberUrlFilter = substr($memberURLs[0], $pos);
201
-				$foundMembers = $this->access->searchUsers($memberUrlFilter,'dn');
201
+				$foundMembers = $this->access->searchUsers($memberUrlFilter, 'dn');
202 202
 				$dynamicMembers = [];
203
-				foreach($foundMembers as $value) {
203
+				foreach ($foundMembers as $value) {
204 204
 					$dynamicMembers[$value['dn'][0]] = 1;
205 205
 				}
206 206
 			} else {
207 207
 				\OCP\Util::writeLog('user_ldap', 'No search filter found on member url '.
208
-					'of group ' . $dnGroup, ILogger::DEBUG);
208
+					'of group '.$dnGroup, ILogger::DEBUG);
209 209
 			}
210 210
 		}
211 211
 		return $dynamicMembers;
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 		// used extensively in cron job, caching makes sense for nested groups
230 230
 		$cacheKey = '_groupMembers'.$dnGroup;
231 231
 		$groupMembers = $this->access->connection->getFromCache($cacheKey);
232
-		if($groupMembers !== null) {
232
+		if ($groupMembers !== null) {
233 233
 			return $groupMembers;
234 234
 		}
235 235
 		$seen[$dnGroup] = 1;
@@ -289,10 +289,10 @@  discard block
 block discarded – undo
289 289
 		$recordMode = is_array($list) && isset($list[0]) && is_array($list[0]) && isset($list[0]['dn'][0]);
290 290
 
291 291
 		if ($nesting !== 1) {
292
-			if($recordMode) {
292
+			if ($recordMode) {
293 293
 				// the keys are numeric, but should hold the DN
294
-				return array_reduce($list, function ($transformed, $record) use ($dn) {
295
-					if($record['dn'][0] != $dn) {
294
+				return array_reduce($list, function($transformed, $record) use ($dn) {
295
+					if ($record['dn'][0] != $dn) {
296 296
 						$transformed[$record['dn'][0]] = $record;
297 297
 					}
298 298
 					return $transformed;
@@ -323,9 +323,9 @@  discard block
 block discarded – undo
323 323
 	 * @return string|bool
324 324
 	 */
325 325
 	public function gidNumber2Name($gid, $dn) {
326
-		$cacheKey = 'gidNumberToName' . $gid;
326
+		$cacheKey = 'gidNumberToName'.$gid;
327 327
 		$groupName = $this->access->connection->getFromCache($cacheKey);
328
-		if(!is_null($groupName) && isset($groupName)) {
328
+		if (!is_null($groupName) && isset($groupName)) {
329 329
 			return $groupName;
330 330
 		}
331 331
 
@@ -333,10 +333,10 @@  discard block
 block discarded – undo
333 333
 		$filter = $this->access->combineFilterWithAnd([
334 334
 			$this->access->connection->ldapGroupFilter,
335 335
 			'objectClass=posixGroup',
336
-			$this->access->connection->ldapGidNumber . '=' . $gid
336
+			$this->access->connection->ldapGidNumber.'='.$gid
337 337
 		]);
338 338
 		$result = $this->access->searchGroups($filter, ['dn'], 1);
339
-		if(empty($result)) {
339
+		if (empty($result)) {
340 340
 			return false;
341 341
 		}
342 342
 		$dn = $result[0]['dn'][0];
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
 	 */
360 360
 	private function getEntryGidNumber($dn, $attribute) {
361 361
 		$value = $this->access->readAttribute($dn, $attribute);
362
-		if(is_array($value) && !empty($value)) {
362
+		if (is_array($value) && !empty($value)) {
363 363
 			return $value[0];
364 364
 		}
365 365
 		return false;
@@ -381,9 +381,9 @@  discard block
 block discarded – undo
381 381
 	 */
382 382
 	public function getUserGidNumber($dn) {
383 383
 		$gidNumber = false;
384
-		if($this->access->connection->hasGidNumber) {
384
+		if ($this->access->connection->hasGidNumber) {
385 385
 			$gidNumber = $this->getEntryGidNumber($dn, $this->access->connection->ldapGidNumber);
386
-			if($gidNumber === false) {
386
+			if ($gidNumber === false) {
387 387
 				$this->access->connection->hasGidNumber = false;
388 388
 			}
389 389
 		}
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 	 */
401 401
 	private function prepareFilterForUsersHasGidNumber($groupDN, $search = '') {
402 402
 		$groupID = $this->getGroupGidNumber($groupDN);
403
-		if($groupID === false) {
403
+		if ($groupID === false) {
404 404
 			throw new \Exception('Not a valid group');
405 405
 		}
406 406
 
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
 		if ($search !== '') {
410 410
 			$filterParts[] = $this->access->getFilterPartForUserSearch($search);
411 411
 		}
412
-		$filterParts[] = $this->access->connection->ldapGidNumber .'=' . $groupID;
412
+		$filterParts[] = $this->access->connection->ldapGidNumber.'='.$groupID;
413 413
 
414 414
 		return $this->access->combineFilterWithAnd($filterParts);
415 415
 	}
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
 		try {
452 452
 			$filter = $this->prepareFilterForUsersHasGidNumber($groupDN, $search);
453 453
 			$users = $this->access->countUsers($filter, ['dn'], $limit, $offset);
454
-			return (int)$users;
454
+			return (int) $users;
455 455
 		} catch (\Exception $e) {
456 456
 			return 0;
457 457
 		}
@@ -464,9 +464,9 @@  discard block
 block discarded – undo
464 464
 	 */
465 465
 	public function getUserGroupByGid($dn) {
466 466
 		$groupID = $this->getUserGidNumber($dn);
467
-		if($groupID !== false) {
467
+		if ($groupID !== false) {
468 468
 			$groupName = $this->gidNumber2Name($groupID, $dn);
469
-			if($groupName !== false) {
469
+			if ($groupName !== false) {
470 470
 				return $groupName;
471 471
 			}
472 472
 		}
@@ -483,22 +483,22 @@  discard block
 block discarded – undo
483 483
 	public function primaryGroupID2Name($gid, $dn) {
484 484
 		$cacheKey = 'primaryGroupIDtoName';
485 485
 		$groupNames = $this->access->connection->getFromCache($cacheKey);
486
-		if(!is_null($groupNames) && isset($groupNames[$gid])) {
486
+		if (!is_null($groupNames) && isset($groupNames[$gid])) {
487 487
 			return $groupNames[$gid];
488 488
 		}
489 489
 
490 490
 		$domainObjectSid = $this->access->getSID($dn);
491
-		if($domainObjectSid === false) {
491
+		if ($domainObjectSid === false) {
492 492
 			return false;
493 493
 		}
494 494
 
495 495
 		//we need to get the DN from LDAP
496 496
 		$filter = $this->access->combineFilterWithAnd([
497 497
 			$this->access->connection->ldapGroupFilter,
498
-			'objectsid=' . $domainObjectSid . '-' . $gid
498
+			'objectsid='.$domainObjectSid.'-'.$gid
499 499
 		]);
500 500
 		$result = $this->access->searchGroups($filter, ['dn'], 1);
501
-		if(empty($result)) {
501
+		if (empty($result)) {
502 502
 			return false;
503 503
 		}
504 504
 		$dn = $result[0]['dn'][0];
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
 	 */
522 522
 	private function getEntryGroupID($dn, $attribute) {
523 523
 		$value = $this->access->readAttribute($dn, $attribute);
524
-		if(is_array($value) && !empty($value)) {
524
+		if (is_array($value) && !empty($value)) {
525 525
 			return $value[0];
526 526
 		}
527 527
 		return false;
@@ -543,9 +543,9 @@  discard block
 block discarded – undo
543 543
 	 */
544 544
 	public function getUserPrimaryGroupIDs($dn) {
545 545
 		$primaryGroupID = false;
546
-		if($this->access->connection->hasPrimaryGroups) {
546
+		if ($this->access->connection->hasPrimaryGroups) {
547 547
 			$primaryGroupID = $this->getEntryGroupID($dn, 'primaryGroupID');
548
-			if($primaryGroupID === false) {
548
+			if ($primaryGroupID === false) {
549 549
 				$this->access->connection->hasPrimaryGroups = false;
550 550
 			}
551 551
 		}
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
 	 */
563 563
 	private function prepareFilterForUsersInPrimaryGroup($groupDN, $search = '') {
564 564
 		$groupID = $this->getGroupPrimaryGroupID($groupDN);
565
-		if($groupID === false) {
565
+		if ($groupID === false) {
566 566
 			throw new \Exception('Not a valid group');
567 567
 		}
568 568
 
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
 		if ($search !== '') {
572 572
 			$filterParts[] = $this->access->getFilterPartForUserSearch($search);
573 573
 		}
574
-		$filterParts[] = 'primaryGroupID=' . $groupID;
574
+		$filterParts[] = 'primaryGroupID='.$groupID;
575 575
 
576 576
 		return $this->access->combineFilterWithAnd($filterParts);
577 577
 	}
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
 		try {
614 614
 			$filter = $this->prepareFilterForUsersInPrimaryGroup($groupDN, $search);
615 615
 			$users = $this->access->countUsers($filter, ['dn'], $limit, $offset);
616
-			return (int)$users;
616
+			return (int) $users;
617 617
 		} catch (\Exception $e) {
618 618
 			return 0;
619 619
 		}
@@ -626,9 +626,9 @@  discard block
 block discarded – undo
626 626
 	 */
627 627
 	public function getUserPrimaryGroup($dn) {
628 628
 		$groupID = $this->getUserPrimaryGroupIDs($dn);
629
-		if($groupID !== false) {
629
+		if ($groupID !== false) {
630 630
 			$groupName = $this->primaryGroupID2Name($groupID, $dn);
631
-			if($groupName !== false) {
631
+			if ($groupName !== false) {
632 632
 				return $groupName;
633 633
 			}
634 634
 		}
@@ -647,16 +647,16 @@  discard block
 block discarded – undo
647 647
 	 * This function includes groups based on dynamic group membership.
648 648
 	 */
649 649
 	public function getUserGroups($uid) {
650
-		if(!$this->enabled) {
650
+		if (!$this->enabled) {
651 651
 			return [];
652 652
 		}
653 653
 		$cacheKey = 'getUserGroups'.$uid;
654 654
 		$userGroups = $this->access->connection->getFromCache($cacheKey);
655
-		if(!is_null($userGroups)) {
655
+		if (!is_null($userGroups)) {
656 656
 			return $userGroups;
657 657
 		}
658 658
 		$userDN = $this->access->username2dn($uid);
659
-		if(!$userDN) {
659
+		if (!$userDN) {
660 660
 			$this->access->connection->writeToCache($cacheKey, []);
661 661
 			return [];
662 662
 		}
@@ -670,14 +670,14 @@  discard block
 block discarded – undo
670 670
 		if (!empty($dynamicGroupMemberURL)) {
671 671
 			// look through dynamic groups to add them to the result array if needed
672 672
 			$groupsToMatch = $this->access->fetchListOfGroups(
673
-				$this->access->connection->ldapGroupFilter,['dn',$dynamicGroupMemberURL]);
674
-			foreach($groupsToMatch as $dynamicGroup) {
673
+				$this->access->connection->ldapGroupFilter, ['dn', $dynamicGroupMemberURL]);
674
+			foreach ($groupsToMatch as $dynamicGroup) {
675 675
 				if (!array_key_exists($dynamicGroupMemberURL, $dynamicGroup)) {
676 676
 					continue;
677 677
 				}
678 678
 				$pos = strpos($dynamicGroup[$dynamicGroupMemberURL][0], '(');
679 679
 				if ($pos !== false) {
680
-					$memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0],$pos);
680
+					$memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0], $pos);
681 681
 					// apply filter via ldap search to see if this user is in this
682 682
 					// dynamic group
683 683
 					$userMatch = $this->access->readAttribute(
@@ -688,7 +688,7 @@  discard block
 block discarded – undo
688 688
 					if ($userMatch !== false) {
689 689
 						// match found so this user is in this group
690 690
 						$groupName = $this->access->dn2groupname($dynamicGroup['dn'][0]);
691
-						if(is_string($groupName)) {
691
+						if (is_string($groupName)) {
692 692
 							// be sure to never return false if the dn could not be
693 693
 							// resolved to a name, for whatever reason.
694 694
 							$groups[] = $groupName;
@@ -696,7 +696,7 @@  discard block
 block discarded – undo
696 696
 					}
697 697
 				} else {
698 698
 					\OCP\Util::writeLog('user_ldap', 'No search filter found on member url '.
699
-						'of group ' . print_r($dynamicGroup, true), ILogger::DEBUG);
699
+						'of group '.print_r($dynamicGroup, true), ILogger::DEBUG);
700 700
 				}
701 701
 			}
702 702
 		}
@@ -704,15 +704,15 @@  discard block
 block discarded – undo
704 704
 		// if possible, read out membership via memberOf. It's far faster than
705 705
 		// performing a search, which still is a fallback later.
706 706
 		// memberof doesn't support memberuid, so skip it here.
707
-		if((int)$this->access->connection->hasMemberOfFilterSupport === 1
708
-			&& (int)$this->access->connection->useMemberOfToDetectMembership === 1
707
+		if ((int) $this->access->connection->hasMemberOfFilterSupport === 1
708
+			&& (int) $this->access->connection->useMemberOfToDetectMembership === 1
709 709
 		    && strtolower($this->access->connection->ldapGroupMemberAssocAttr) !== 'memberuid'
710 710
 		    ) {
711 711
 			$groupDNs = $this->_getGroupDNsFromMemberOf($userDN);
712 712
 			if (is_array($groupDNs)) {
713 713
 				foreach ($groupDNs as $dn) {
714 714
 					$groupName = $this->access->dn2groupname($dn);
715
-					if(is_string($groupName)) {
715
+					if (is_string($groupName)) {
716 716
 						// be sure to never return false if the dn could not be
717 717
 						// resolved to a name, for whatever reason.
718 718
 						$groups[] = $groupName;
@@ -720,10 +720,10 @@  discard block
 block discarded – undo
720 720
 				}
721 721
 			}
722 722
 
723
-			if($primaryGroup !== false) {
723
+			if ($primaryGroup !== false) {
724 724
 				$groups[] = $primaryGroup;
725 725
 			}
726
-			if($gidGroupName !== false) {
726
+			if ($gidGroupName !== false) {
727 727
 				$groups[] = $gidGroupName;
728 728
 			}
729 729
 			$this->access->connection->writeToCache($cacheKey, $groups);
@@ -731,14 +731,14 @@  discard block
 block discarded – undo
731 731
 		}
732 732
 
733 733
 		//uniqueMember takes DN, memberuid the uid, so we need to distinguish
734
-		if((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember')
734
+		if ((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember')
735 735
 			|| (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'member')
736 736
 		) {
737 737
 			$uid = $userDN;
738
-		} else if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
738
+		} else if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
739 739
 			$result = $this->access->readAttribute($userDN, 'uid');
740 740
 			if ($result === false) {
741
-				\OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN ' . $userDN . ' on '.
741
+				\OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN '.$userDN.' on '.
742 742
 					$this->access->connection->ldapHost, ILogger::DEBUG);
743 743
 				$uid = false;
744 744
 			} else {
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
 			$uid = $userDN;
750 750
 		}
751 751
 
752
-		if($uid !== false) {
752
+		if ($uid !== false) {
753 753
 			if (isset($this->cachedGroupsByMember[$uid])) {
754 754
 				$groups = array_merge($groups, $this->cachedGroupsByMember[$uid]);
755 755
 			} else {
@@ -760,10 +760,10 @@  discard block
 block discarded – undo
760 760
 			}
761 761
 		}
762 762
 
763
-		if($primaryGroup !== false) {
763
+		if ($primaryGroup !== false) {
764 764
 			$groups[] = $primaryGroup;
765 765
 		}
766
-		if($gidGroupName !== false) {
766
+		if ($gidGroupName !== false) {
767 767
 			$groups[] = $gidGroupName;
768 768
 		}
769 769
 
@@ -792,8 +792,8 @@  discard block
 block discarded – undo
792 792
 		$groups = $this->access->fetchListOfGroups($filter,
793 793
 			[$this->access->connection->ldapGroupDisplayName, 'dn']);
794 794
 		if (is_array($groups)) {
795
-			$fetcher = function ($dn, &$seen) {
796
-				if(is_array($dn) && isset($dn['dn'][0])) {
795
+			$fetcher = function($dn, &$seen) {
796
+				if (is_array($dn) && isset($dn['dn'][0])) {
797 797
 					$dn = $dn['dn'][0];
798 798
 				}
799 799
 				return $this->getGroupsByMember($dn, $seen);
@@ -815,33 +815,33 @@  discard block
 block discarded – undo
815 815
 	 * @throws \Exception
816 816
 	 */
817 817
 	public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
818
-		if(!$this->enabled) {
818
+		if (!$this->enabled) {
819 819
 			return [];
820 820
 		}
821
-		if(!$this->groupExists($gid)) {
821
+		if (!$this->groupExists($gid)) {
822 822
 			return [];
823 823
 		}
824 824
 		$search = $this->access->escapeFilterPart($search, true);
825 825
 		$cacheKey = 'usersInGroup-'.$gid.'-'.$search.'-'.$limit.'-'.$offset;
826 826
 		// check for cache of the exact query
827 827
 		$groupUsers = $this->access->connection->getFromCache($cacheKey);
828
-		if(!is_null($groupUsers)) {
828
+		if (!is_null($groupUsers)) {
829 829
 			return $groupUsers;
830 830
 		}
831 831
 
832 832
 		// check for cache of the query without limit and offset
833 833
 		$groupUsers = $this->access->connection->getFromCache('usersInGroup-'.$gid.'-'.$search);
834
-		if(!is_null($groupUsers)) {
834
+		if (!is_null($groupUsers)) {
835 835
 			$groupUsers = array_slice($groupUsers, $offset, $limit);
836 836
 			$this->access->connection->writeToCache($cacheKey, $groupUsers);
837 837
 			return $groupUsers;
838 838
 		}
839 839
 
840
-		if($limit === -1) {
840
+		if ($limit === -1) {
841 841
 			$limit = null;
842 842
 		}
843 843
 		$groupDN = $this->access->groupname2dn($gid);
844
-		if(!$groupDN) {
844
+		if (!$groupDN) {
845 845
 			// group couldn't be found, return empty resultset
846 846
 			$this->access->connection->writeToCache($cacheKey, []);
847 847
 			return [];
@@ -850,7 +850,7 @@  discard block
 block discarded – undo
850 850
 		$primaryUsers = $this->getUsersInPrimaryGroup($groupDN, $search, $limit, $offset);
851 851
 		$posixGroupUsers = $this->getUsersInGidNumber($groupDN, $search, $limit, $offset);
852 852
 		$members = $this->_groupMembers($groupDN);
853
-		if(!$members && empty($posixGroupUsers) && empty($primaryUsers)) {
853
+		if (!$members && empty($posixGroupUsers) && empty($primaryUsers)) {
854 854
 			//in case users could not be retrieved, return empty result set
855 855
 			$this->access->connection->writeToCache($cacheKey, []);
856 856
 			return [];
@@ -859,8 +859,8 @@  discard block
 block discarded – undo
859 859
 		$groupUsers = [];
860 860
 		$isMemberUid = (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid');
861 861
 		$attrs = $this->access->userManager->getAttributes(true);
862
-		foreach($members as $member) {
863
-			if($isMemberUid) {
862
+		foreach ($members as $member) {
863
+			if ($isMemberUid) {
864 864
 				//we got uids, need to get their DNs to 'translate' them to user names
865 865
 				$filter = $this->access->combineFilterWithAnd([
866 866
 					str_replace('%uid', trim($member), $this->access->connection->ldapLoginFilter),
@@ -870,23 +870,23 @@  discard block
 block discarded – undo
870 870
 					])
871 871
 				]);
872 872
 				$ldap_users = $this->access->fetchListOfUsers($filter, $attrs, 1);
873
-				if(count($ldap_users) < 1) {
873
+				if (count($ldap_users) < 1) {
874 874
 					continue;
875 875
 				}
876 876
 				$groupUsers[] = $this->access->dn2username($ldap_users[0]['dn'][0]);
877 877
 			} else {
878 878
 				//we got DNs, check if we need to filter by search or we can give back all of them
879 879
 				$uid = $this->access->dn2username($member);
880
-				if(!$uid) {
880
+				if (!$uid) {
881 881
 					continue;
882 882
 				}
883 883
 
884
-				$cacheKey = 'userExistsOnLDAP' . $uid;
884
+				$cacheKey = 'userExistsOnLDAP'.$uid;
885 885
 				$userExists = $this->access->connection->getFromCache($cacheKey);
886
-				if($userExists === false) {
886
+				if ($userExists === false) {
887 887
 					continue;
888 888
 				}
889
-				if($userExists === null || $search !== '') {
889
+				if ($userExists === null || $search !== '') {
890 890
 					if (!$this->access->readAttribute($member,
891 891
 						$this->access->connection->ldapUserDisplayName,
892 892
 						$this->access->combineFilterWithAnd([
@@ -894,7 +894,7 @@  discard block
 block discarded – undo
894 894
 							$this->access->connection->ldapUserFilter
895 895
 						])))
896 896
 					{
897
-						if($search === '') {
897
+						if ($search === '') {
898 898
 							$this->access->connection->writeToCache($cacheKey, false);
899 899
 						}
900 900
 						continue;
@@ -927,16 +927,16 @@  discard block
 block discarded – undo
927 927
 		}
928 928
 
929 929
 		$cacheKey = 'countUsersInGroup-'.$gid.'-'.$search;
930
-		if(!$this->enabled || !$this->groupExists($gid)) {
930
+		if (!$this->enabled || !$this->groupExists($gid)) {
931 931
 			return false;
932 932
 		}
933 933
 		$groupUsers = $this->access->connection->getFromCache($cacheKey);
934
-		if(!is_null($groupUsers)) {
934
+		if (!is_null($groupUsers)) {
935 935
 			return $groupUsers;
936 936
 		}
937 937
 
938 938
 		$groupDN = $this->access->groupname2dn($gid);
939
-		if(!$groupDN) {
939
+		if (!$groupDN) {
940 940
 			// group couldn't be found, return empty result set
941 941
 			$this->access->connection->writeToCache($cacheKey, false);
942 942
 			return false;
@@ -944,7 +944,7 @@  discard block
 block discarded – undo
944 944
 
945 945
 		$members = $this->_groupMembers($groupDN);
946 946
 		$primaryUserCount = $this->countUsersInPrimaryGroup($groupDN, '');
947
-		if(!$members && $primaryUserCount === 0) {
947
+		if (!$members && $primaryUserCount === 0) {
948 948
 			//in case users could not be retrieved, return empty result set
949 949
 			$this->access->connection->writeToCache($cacheKey, false);
950 950
 			return false;
@@ -969,27 +969,27 @@  discard block
 block discarded – undo
969 969
 		//For now this is not important, because the only use of this method
970 970
 		//does not supply a search string
971 971
 		$groupUsers = [];
972
-		foreach($members as $member) {
973
-			if($isMemberUid) {
972
+		foreach ($members as $member) {
973
+			if ($isMemberUid) {
974 974
 				//we got uids, need to get their DNs to 'translate' them to user names
975 975
 				$filter = $this->access->combineFilterWithAnd([
976 976
 					str_replace('%uid', $member, $this->access->connection->ldapLoginFilter),
977 977
 					$this->access->getFilterPartForUserSearch($search)
978 978
 				]);
979 979
 				$ldap_users = $this->access->fetchListOfUsers($filter, 'dn', 1);
980
-				if(count($ldap_users) < 1) {
980
+				if (count($ldap_users) < 1) {
981 981
 					continue;
982 982
 				}
983 983
 				$groupUsers[] = $this->access->dn2username($ldap_users[0]);
984 984
 			} else {
985 985
 				//we need to apply the search filter now
986
-				if(!$this->access->readAttribute($member,
986
+				if (!$this->access->readAttribute($member,
987 987
 					$this->access->connection->ldapUserDisplayName,
988 988
 					$this->access->getFilterPartForUserSearch($search))) {
989 989
 					continue;
990 990
 				}
991 991
 				// dn2username will also check if the users belong to the allowed base
992
-				if($ocname = $this->access->dn2username($member)) {
992
+				if ($ocname = $this->access->dn2username($member)) {
993 993
 					$groupUsers[] = $ocname;
994 994
 				}
995 995
 			}
@@ -1012,7 +1012,7 @@  discard block
 block discarded – undo
1012 1012
 	 * Returns a list with all groups (used by getGroups)
1013 1013
 	 */
1014 1014
 	protected function getGroupsChunk($search = '', $limit = -1, $offset = 0) {
1015
-		if(!$this->enabled) {
1015
+		if (!$this->enabled) {
1016 1016
 			return [];
1017 1017
 		}
1018 1018
 		$cacheKey = 'getGroups-'.$search.'-'.$limit.'-'.$offset;
@@ -1020,13 +1020,13 @@  discard block
 block discarded – undo
1020 1020
 		//Check cache before driving unnecessary searches
1021 1021
 		\OCP\Util::writeLog('user_ldap', 'getGroups '.$cacheKey, ILogger::DEBUG);
1022 1022
 		$ldap_groups = $this->access->connection->getFromCache($cacheKey);
1023
-		if(!is_null($ldap_groups)) {
1023
+		if (!is_null($ldap_groups)) {
1024 1024
 			return $ldap_groups;
1025 1025
 		}
1026 1026
 
1027 1027
 		// if we'd pass -1 to LDAP search, we'd end up in a Protocol
1028 1028
 		// error. With a limit of 0, we get 0 results. So we pass null.
1029
-		if($limit <= 0) {
1029
+		if ($limit <= 0) {
1030 1030
 			$limit = null;
1031 1031
 		}
1032 1032
 		$filter = $this->access->combineFilterWithAnd([
@@ -1058,11 +1058,11 @@  discard block
 block discarded – undo
1058 1058
 	 * (active directory has a limit of 1000 by default)
1059 1059
 	 */
1060 1060
 	public function getGroups($search = '', $limit = -1, $offset = 0) {
1061
-		if(!$this->enabled) {
1061
+		if (!$this->enabled) {
1062 1062
 			return [];
1063 1063
 		}
1064 1064
 		$search = $this->access->escapeFilterPart($search, true);
1065
-		$pagingSize = (int)$this->access->connection->ldapPagingSize;
1065
+		$pagingSize = (int) $this->access->connection->ldapPagingSize;
1066 1066
 		if ($pagingSize <= 0) {
1067 1067
 			return $this->getGroupsChunk($search, $limit, $offset);
1068 1068
 		}
@@ -1105,20 +1105,20 @@  discard block
 block discarded – undo
1105 1105
 	 */
1106 1106
 	public function groupExists($gid) {
1107 1107
 		$groupExists = $this->access->connection->getFromCache('groupExists'.$gid);
1108
-		if(!is_null($groupExists)) {
1109
-			return (bool)$groupExists;
1108
+		if (!is_null($groupExists)) {
1109
+			return (bool) $groupExists;
1110 1110
 		}
1111 1111
 
1112 1112
 		//getting dn, if false the group does not exist. If dn, it may be mapped
1113 1113
 		//only, requires more checking.
1114 1114
 		$dn = $this->access->groupname2dn($gid);
1115
-		if(!$dn) {
1115
+		if (!$dn) {
1116 1116
 			$this->access->connection->writeToCache('groupExists'.$gid, false);
1117 1117
 			return false;
1118 1118
 		}
1119 1119
 
1120 1120
 		//if group really still exists, we will be able to read its objectclass
1121
-		if(!is_array($this->access->readAttribute($dn, ''))) {
1121
+		if (!is_array($this->access->readAttribute($dn, ''))) {
1122 1122
 			$this->access->connection->writeToCache('groupExists'.$gid, false);
1123 1123
 			return false;
1124 1124
 		}
@@ -1136,7 +1136,7 @@  discard block
 block discarded – undo
1136 1136
 	* compared with GroupInterface::CREATE_GROUP etc.
1137 1137
 	*/
1138 1138
 	public function implementsActions($actions) {
1139
-		return (bool)((GroupInterface::COUNT_USERS |
1139
+		return (bool) ((GroupInterface::COUNT_USERS |
1140 1140
 				$this->groupPluginManager->getImplementedActions()) & $actions);
1141 1141
 	}
1142 1142
 
@@ -1159,7 +1159,7 @@  discard block
 block discarded – undo
1159 1159
 			if ($dn = $this->groupPluginManager->createGroup($gid)) {
1160 1160
 				//updates group mapping
1161 1161
 				$uuid = $this->access->getUUID($dn, false);
1162
-				if(is_string($uuid)) {
1162
+				if (is_string($uuid)) {
1163 1163
 					$this->access->mapAndAnnounceIfApplicable(
1164 1164
 						$this->access->getGroupMapper(),
1165 1165
 						$dn,
@@ -1262,7 +1262,7 @@  discard block
 block discarded – undo
1262 1262
 			return $this->groupPluginManager->getDisplayName($gid);
1263 1263
 		}
1264 1264
 
1265
-		$cacheKey = 'group_getDisplayName' . $gid;
1265
+		$cacheKey = 'group_getDisplayName'.$gid;
1266 1266
 		if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
1267 1267
 			return $displayName;
1268 1268
 		}
Please login to merge, or discard this patch.
apps/user_ldap/lib/Helper.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 		$keys = $this->getServersConfig($referenceConfigkey);
101 101
 
102 102
 		$result = [];
103
-		foreach($keys as $key) {
103
+		foreach ($keys as $key) {
104 104
 			$len = strlen($key) - strlen($referenceConfigkey);
105 105
 			$prefix = substr($key, 0, $len);
106 106
 			$result[$prefix] = $this->config->getAppValue('user_ldap', $key);
@@ -117,18 +117,18 @@  discard block
 block discarded – undo
117 117
 	public function getNextServerConfigurationPrefix() {
118 118
 		$serverConnections = $this->getServerConfigurationPrefixes();
119 119
 
120
-		if(count($serverConnections) === 0) {
120
+		if (count($serverConnections) === 0) {
121 121
 			return 's01';
122 122
 		}
123 123
 
124 124
 		sort($serverConnections);
125 125
 		$lastKey = array_pop($serverConnections);
126
-		$lastNumber = (int)str_replace('s', '', $lastKey);
127
-		return 's' . str_pad($lastNumber + 1, 2, '0', STR_PAD_LEFT);
126
+		$lastNumber = (int) str_replace('s', '', $lastKey);
127
+		return 's'.str_pad($lastNumber + 1, 2, '0', STR_PAD_LEFT);
128 128
 	}
129 129
 
130 130
 	private function getServersConfig($value) {
131
-		$regex = '/' . $value . '$/S';
131
+		$regex = '/'.$value.'$/S';
132 132
 
133 133
 		$keys = $this->config->getAppKeys('user_ldap');
134 134
 		$result = [];
@@ -147,12 +147,12 @@  discard block
 block discarded – undo
147 147
 	 * @return bool true on success, false otherwise
148 148
 	 */
149 149
 	public function deleteServerConfiguration($prefix) {
150
-		if(!in_array($prefix, self::getServerConfigurationPrefixes())) {
150
+		if (!in_array($prefix, self::getServerConfigurationPrefixes())) {
151 151
 			return false;
152 152
 		}
153 153
 
154 154
 		$saveOtherConfigurations = '';
155
-		if(empty($prefix)) {
155
+		if (empty($prefix)) {
156 156
 			$saveOtherConfigurations = 'AND `configkey` NOT LIKE \'s%\'';
157 157
 		}
158 158
 
@@ -166,11 +166,11 @@  discard block
 block discarded – undo
166 166
 		');
167 167
 		$delRows = $query->execute([$prefix.'%']);
168 168
 
169
-		if($delRows === null) {
169
+		if ($delRows === null) {
170 170
 			return false;
171 171
 		}
172 172
 
173
-		if($delRows === 0) {
173
+		if ($delRows === 0) {
174 174
 			return false;
175 175
 		}
176 176
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 		$all = $this->getServerConfigurationPrefixes(false);
187 187
 		$active = $this->getServerConfigurationPrefixes(true);
188 188
 
189
-		if(!is_array($all) || !is_array($active)) {
189
+		if (!is_array($all) || !is_array($active)) {
190 190
 			throw new \Exception('Unexpected Return Value');
191 191
 		}
192 192
 
@@ -200,14 +200,14 @@  discard block
 block discarded – undo
200 200
 	 */
201 201
 	public function getDomainFromURL($url) {
202 202
 		$uinfo = parse_url($url);
203
-		if(!is_array($uinfo)) {
203
+		if (!is_array($uinfo)) {
204 204
 			return false;
205 205
 		}
206 206
 
207 207
 		$domain = false;
208
-		if(isset($uinfo['host'])) {
208
+		if (isset($uinfo['host'])) {
209 209
 			$domain = $uinfo['host'];
210
-		} else if(isset($uinfo['path'])) {
210
+		} else if (isset($uinfo['path'])) {
211 211
 			$domain = $uinfo['path'];
212 212
 		}
213 213
 
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 	 */
222 222
 	public function setLDAPProvider() {
223 223
 		$current = \OC::$server->getConfig()->getSystemValue('ldapProviderFactory', null);
224
-		if(is_null($current)) {
224
+		if (is_null($current)) {
225 225
 			\OC::$server->getConfig()->setSystemValue('ldapProviderFactory', LDAPProviderFactory::class);
226 226
 		}
227 227
 	}
@@ -233,9 +233,9 @@  discard block
 block discarded – undo
233 233
 	 */
234 234
 	public function sanitizeDN($dn) {
235 235
 		//treating multiple base DNs
236
-		if(is_array($dn)) {
236
+		if (is_array($dn)) {
237 237
 			$result = [];
238
-			foreach($dn as $singleDN) {
238
+			foreach ($dn as $singleDN) {
239 239
 				$result[] = $this->sanitizeDN($singleDN);
240 240
 			}
241 241
 			return $result;
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 	 * @throws \Exception
287 287
 	 */
288 288
 	public static function loginName2UserName($param) {
289
-		if(!isset($param['uid'])) {
289
+		if (!isset($param['uid'])) {
290 290
 			throw new \Exception('key uid is expected to be set in $param');
291 291
 		}
292 292
 
@@ -301,11 +301,11 @@  discard block
 block discarded – undo
301 301
 		$userSession = \OC::$server->getUserSession();
302 302
 		$userPluginManager = \OC::$server->query('LDAPUserPluginManager');
303 303
 
304
-		$userBackend  = new User_Proxy(
304
+		$userBackend = new User_Proxy(
305 305
 			$configPrefixes, $ldapWrapper, $ocConfig, $notificationManager, $userSession, $userPluginManager
306 306
 		);
307
-		$uid = $userBackend->loginName2UserName($param['uid'] );
308
-		if($uid !== false) {
307
+		$uid = $userBackend->loginName2UserName($param['uid']);
308
+		if ($uid !== false) {
309 309
 			$param['uid'] = $uid;
310 310
 		}
311 311
 	}
Please login to merge, or discard this patch.
apps/user_ldap/lib/Mapping/AbstractMapping.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	 * @return bool
55 55
 	 */
56 56
 	public function isColNameValid($col) {
57
-		switch($col) {
57
+		switch ($col) {
58 58
 			case 'ldap_dn':
59 59
 			case 'owncloud_name':
60 60
 			case 'directory_uuid':
@@ -73,19 +73,19 @@  discard block
 block discarded – undo
73 73
 	 * @return string|false
74 74
 	 */
75 75
 	protected function getXbyY($fetchCol, $compareCol, $search) {
76
-		if(!$this->isColNameValid($fetchCol)) {
76
+		if (!$this->isColNameValid($fetchCol)) {
77 77
 			//this is used internally only, but we don't want to risk
78 78
 			//having SQL injection at all.
79 79
 			throw new \Exception('Invalid Column Name');
80 80
 		}
81 81
 		$query = $this->dbc->prepare('
82
-			SELECT `' . $fetchCol . '`
83
-			FROM `'. $this->getTableName() .'`
84
-			WHERE `' . $compareCol . '` = ?
82
+			SELECT `' . $fetchCol.'`
83
+			FROM `'. $this->getTableName().'`
84
+			WHERE `' . $compareCol.'` = ?
85 85
 		');
86 86
 
87 87
 		$res = $query->execute([$search]);
88
-		if($res !== false) {
88
+		if ($res !== false) {
89 89
 			return $query->fetchColumn();
90 90
 		}
91 91
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 */
122 122
 	public function setDNbyUUID($fdn, $uuid) {
123 123
 		$query = $this->dbc->prepare('
124
-			UPDATE `' . $this->getTableName() . '`
124
+			UPDATE `' . $this->getTableName().'`
125 125
 			SET `ldap_dn` = ?
126 126
 			WHERE `directory_uuid` = ?
127 127
 		');
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 	 */
141 141
 	public function setUUIDbyDN($uuid, $fdn) {
142 142
 		$query = $this->dbc->prepare('
143
-			UPDATE `' . $this->getTableName() . '`
143
+			UPDATE `' . $this->getTableName().'`
144 144
 			SET `directory_uuid` = ?
145 145
 			WHERE `ldap_dn` = ?
146 146
 		');
@@ -167,14 +167,14 @@  discard block
 block discarded – undo
167 167
 	public function getNamesBySearch($search, $prefixMatch = "", $postfixMatch = "") {
168 168
 		$query = $this->dbc->prepare('
169 169
 			SELECT `owncloud_name`
170
-			FROM `'. $this->getTableName() .'`
170
+			FROM `'. $this->getTableName().'`
171 171
 			WHERE `owncloud_name` LIKE ?
172 172
 		');
173 173
 
174 174
 		$res = $query->execute([$prefixMatch.$this->dbc->escapeLikeParameter($search).$postfixMatch]);
175 175
 		$names = [];
176
-		if($res !== false) {
177
-			while($row = $query->fetch()) {
176
+		if ($res !== false) {
177
+			while ($row = $query->fetch()) {
178 178
 				$names[] = $row['owncloud_name'];
179 179
 			}
180 180
 		}
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 				`ldap_dn` AS `dn`,
213 213
 				`owncloud_name` AS `name`,
214 214
 				`directory_uuid` AS `uuid`
215
-			FROM `' . $this->getTableName() . '`',
215
+			FROM `' . $this->getTableName().'`',
216 216
 			$limit,
217 217
 			$offset
218 218
 		);
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 	 * @return bool
230 230
 	 */
231 231
 	public function map($fdn, $name, $uuid) {
232
-		if(mb_strlen($fdn) > 255) {
232
+		if (mb_strlen($fdn) > 255) {
233 233
 			\OC::$server->getLogger()->error(
234 234
 				'Cannot map, because the DN exceeds 255 characters: {dn}',
235 235
 				[
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 		try {
250 250
 			$result = $this->dbc->insertIfNotExist($this->getTableName(), $row);
251 251
 			// insertIfNotExist returns values as int
252
-			return (bool)$result;
252
+			return (bool) $result;
253 253
 		} catch (\Exception $e) {
254 254
 			return false;
255 255
 		}
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 	 */
263 263
 	public function unmap($name) {
264 264
 		$query = $this->dbc->prepare('
265
-			DELETE FROM `'. $this->getTableName() .'`
265
+			DELETE FROM `'. $this->getTableName().'`
266 266
 			WHERE `owncloud_name` = ?');
267 267
 
268 268
 		return $this->modify($query, [$name]);
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 	public function clear() {
276 276
 		$sql = $this->dbc
277 277
 			->getDatabasePlatform()
278
-			->getTruncateTableSQL('`' . $this->getTableName() . '`');
278
+			->getTruncateTableSQL('`'.$this->getTableName().'`');
279 279
 		return $this->dbc->prepare($sql)->execute();
280 280
 	}
281 281
 
@@ -294,9 +294,9 @@  discard block
 block discarded – undo
294 294
 			->from($this->getTableName());
295 295
 		$cursor = $picker->execute();
296 296
 		$result = true;
297
-		while($id = $cursor->fetchColumn(0)) {
297
+		while ($id = $cursor->fetchColumn(0)) {
298 298
 			$preCallback($id);
299
-			if($isUnmapped = $this->unmap($id)) {
299
+			if ($isUnmapped = $this->unmap($id)) {
300 300
 				$postCallback($id);
301 301
 			}
302 302
 			$result &= $isUnmapped;
@@ -317,6 +317,6 @@  discard block
 block discarded – undo
317 317
 		$res = $query->execute();
318 318
 		$count = $res->fetchColumn();
319 319
 		$res->closeCursor();
320
-		return (int)$count;
320
+		return (int) $count;
321 321
 	}
322 322
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Connection.php 1 patch
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 		$this->configuration = new Configuration($configPrefix,
111 111
 												 !is_null($configID));
112 112
 		$memcache = \OC::$server->getMemCacheFactory();
113
-		if($memcache->isAvailable()) {
113
+		if ($memcache->isAvailable()) {
114 114
 			$this->cache = $memcache->createDistributed();
115 115
 		}
116 116
 		$helper = new Helper(\OC::$server->getConfig());
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	}
120 120
 
121 121
 	public function __destruct() {
122
-		if(!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) {
122
+		if (!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) {
123 123
 			@$this->ldap->unbind($this->ldapConnectionRes);
124 124
 			$this->bindResult = [];
125 125
 		}
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 	public function __clone() {
132 132
 		$this->configuration = new Configuration($this->configPrefix,
133 133
 												 !is_null($this->configID));
134
-		if(count($this->bindResult) !== 0 && $this->bindResult['result'] === true) {
134
+		if (count($this->bindResult) !== 0 && $this->bindResult['result'] === true) {
135 135
 			$this->bindResult = [];
136 136
 		}
137 137
 		$this->ldapConnectionRes = null;
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 	 * @return bool|mixed
144 144
 	 */
145 145
 	public function __get($name) {
146
-		if(!$this->configured) {
146
+		if (!$this->configured) {
147 147
 			$this->readConfiguration();
148 148
 		}
149 149
 
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 		$before = $this->configuration->$name;
160 160
 		$this->configuration->$name = $value;
161 161
 		$after = $this->configuration->$name;
162
-		if($before !== $after) {
162
+		if ($before !== $after) {
163 163
 			if ($this->configID !== '' && $this->configID !== null) {
164 164
 				$this->configuration->saveConfiguration();
165 165
 			}
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 	 * @param bool $state
184 184
 	 */
185 185
 	public function setIgnoreValidation($state) {
186
-		$this->ignoreValidation = (bool)$state;
186
+		$this->ignoreValidation = (bool) $state;
187 187
 	}
188 188
 
189 189
 	/**
@@ -199,14 +199,14 @@  discard block
 block discarded – undo
199 199
 	 * Returns the LDAP handler
200 200
 	 */
201 201
 	public function getConnectionResource() {
202
-		if(!$this->ldapConnectionRes) {
202
+		if (!$this->ldapConnectionRes) {
203 203
 			$this->init();
204
-		} else if(!$this->ldap->isResource($this->ldapConnectionRes)) {
204
+		} else if (!$this->ldap->isResource($this->ldapConnectionRes)) {
205 205
 			$this->ldapConnectionRes = null;
206 206
 			$this->establishConnection();
207 207
 		}
208
-		if(is_null($this->ldapConnectionRes)) {
209
-			\OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, ILogger::ERROR);
208
+		if (is_null($this->ldapConnectionRes)) {
209
+			\OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server '.$this->configuration->ldapHost, ILogger::ERROR);
210 210
 			throw new ServerNotAvailableException('Connection to LDAP server could not be established');
211 211
 		}
212 212
 		return $this->ldapConnectionRes;
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 	 * resets the connection resource
217 217
 	 */
218 218
 	public function resetConnectionResource() {
219
-		if(!is_null($this->ldapConnectionRes)) {
219
+		if (!is_null($this->ldapConnectionRes)) {
220 220
 			@$this->ldap->unbind($this->ldapConnectionRes);
221 221
 			$this->ldapConnectionRes = null;
222 222
 			$this->bindResult = [];
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 	 */
230 230
 	private function getCacheKey($key) {
231 231
 		$prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-';
232
-		if(is_null($key)) {
232
+		if (is_null($key)) {
233 233
 			return $prefix;
234 234
 		}
235 235
 		return $prefix.hash('sha256', $key);
@@ -240,10 +240,10 @@  discard block
 block discarded – undo
240 240
 	 * @return mixed|null
241 241
 	 */
242 242
 	public function getFromCache($key) {
243
-		if(!$this->configured) {
243
+		if (!$this->configured) {
244 244
 			$this->readConfiguration();
245 245
 		}
246
-		if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) {
246
+		if (is_null($this->cache) || !$this->configuration->ldapCacheTTL) {
247 247
 			return null;
248 248
 		}
249 249
 		$key = $this->getCacheKey($key);
@@ -258,10 +258,10 @@  discard block
 block discarded – undo
258 258
 	 * @return string
259 259
 	 */
260 260
 	public function writeToCache($key, $value) {
261
-		if(!$this->configured) {
261
+		if (!$this->configured) {
262 262
 			$this->readConfiguration();
263 263
 		}
264
-		if(is_null($this->cache)
264
+		if (is_null($this->cache)
265 265
 			|| !$this->configuration->ldapCacheTTL
266 266
 			|| !$this->configuration->ldapConfigurationActive) {
267 267
 			return null;
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 	}
273 273
 
274 274
 	public function clearCache() {
275
-		if(!is_null($this->cache)) {
275
+		if (!is_null($this->cache)) {
276 276
 			$this->cache->clear($this->getCacheKey(null));
277 277
 		}
278 278
 	}
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 	 * @return null
285 285
 	 */
286 286
 	private function readConfiguration($force = false) {
287
-		if((!$this->configured || $force) && !is_null($this->configID)) {
287
+		if ((!$this->configured || $force) && !is_null($this->configID)) {
288 288
 			$this->configuration->readConfiguration();
289 289
 			$this->configured = $this->validateConfiguration();
290 290
 		}
@@ -297,12 +297,12 @@  discard block
 block discarded – undo
297 297
 	 * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters
298 298
 	 */
299 299
 	public function setConfiguration($config, &$setParameters = null) {
300
-		if(is_null($setParameters)) {
300
+		if (is_null($setParameters)) {
301 301
 			$setParameters = [];
302 302
 		}
303 303
 		$this->doNotValidate = false;
304 304
 		$this->configuration->setConfiguration($config, $setParameters);
305
-		if(count($setParameters) > 0) {
305
+		if (count($setParameters) > 0) {
306 306
 			$this->configured = $this->validateConfiguration();
307 307
 		}
308 308
 
@@ -329,10 +329,10 @@  discard block
 block discarded – undo
329 329
 		$config = $this->configuration->getConfiguration();
330 330
 		$cta = $this->configuration->getConfigTranslationArray();
331 331
 		$result = [];
332
-		foreach($cta as $dbkey => $configkey) {
333
-			switch($configkey) {
332
+		foreach ($cta as $dbkey => $configkey) {
333
+			switch ($configkey) {
334 334
 				case 'homeFolderNamingRule':
335
-					if(strpos($config[$configkey], 'attr:') === 0) {
335
+					if (strpos($config[$configkey], 'attr:') === 0) {
336 336
 						$result[$dbkey] = substr($config[$configkey], 5);
337 337
 					} else {
338 338
 						$result[$dbkey] = '';
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
 				case 'ldapBaseGroups':
344 344
 				case 'ldapAttributesForUserSearch':
345 345
 				case 'ldapAttributesForGroupSearch':
346
-					if(is_array($config[$configkey])) {
346
+					if (is_array($config[$configkey])) {
347 347
 						$result[$dbkey] = implode("\n", $config[$configkey]);
348 348
 						break;
349 349
 					} //else follows default
@@ -356,23 +356,23 @@  discard block
 block discarded – undo
356 356
 
357 357
 	private function doSoftValidation() {
358 358
 		//if User or Group Base are not set, take over Base DN setting
359
-		foreach(['ldapBaseUsers', 'ldapBaseGroups'] as $keyBase) {
359
+		foreach (['ldapBaseUsers', 'ldapBaseGroups'] as $keyBase) {
360 360
 			$val = $this->configuration->$keyBase;
361
-			if(empty($val)) {
361
+			if (empty($val)) {
362 362
 				$this->configuration->$keyBase = $this->configuration->ldapBase;
363 363
 			}
364 364
 		}
365 365
 
366
-		foreach(['ldapExpertUUIDUserAttr'  => 'ldapUuidUserAttribute',
366
+		foreach (['ldapExpertUUIDUserAttr'  => 'ldapUuidUserAttribute',
367 367
 					  'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute']
368 368
 				as $expertSetting => $effectiveSetting) {
369 369
 			$uuidOverride = $this->configuration->$expertSetting;
370
-			if(!empty($uuidOverride)) {
370
+			if (!empty($uuidOverride)) {
371 371
 				$this->configuration->$effectiveSetting = $uuidOverride;
372 372
 			} else {
373 373
 				$uuidAttributes = Access::UUID_ATTRIBUTES;
374 374
 				array_unshift($uuidAttributes, 'auto');
375
-				if(!in_array($this->configuration->$effectiveSetting,
375
+				if (!in_array($this->configuration->$effectiveSetting,
376 376
 							$uuidAttributes)
377 377
 					&& (!is_null($this->configID))) {
378 378
 					$this->configuration->$effectiveSetting = 'auto';
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
 			}
387 387
 		}
388 388
 
389
-		$backupPort = (int)$this->configuration->ldapBackupPort;
389
+		$backupPort = (int) $this->configuration->ldapBackupPort;
390 390
 		if ($backupPort <= 0) {
391 391
 			$this->configuration->backupPort = $this->configuration->ldapPort;
392 392
 		}
@@ -394,14 +394,14 @@  discard block
 block discarded – undo
394 394
 		//make sure empty search attributes are saved as simple, empty array
395 395
 		$saKeys = ['ldapAttributesForUserSearch',
396 396
 						'ldapAttributesForGroupSearch'];
397
-		foreach($saKeys as $key) {
397
+		foreach ($saKeys as $key) {
398 398
 			$val = $this->configuration->$key;
399
-			if(is_array($val) && count($val) === 1 && empty($val[0])) {
399
+			if (is_array($val) && count($val) === 1 && empty($val[0])) {
400 400
 				$this->configuration->$key = [];
401 401
 			}
402 402
 		}
403 403
 
404
-		if((stripos($this->configuration->ldapHost, 'ldaps://') === 0)
404
+		if ((stripos($this->configuration->ldapHost, 'ldaps://') === 0)
405 405
 			&& $this->configuration->ldapTLS) {
406 406
 			$this->configuration->ldapTLS = false;
407 407
 			\OCP\Util::writeLog(
@@ -418,15 +418,15 @@  discard block
 block discarded – undo
418 418
 	private function doCriticalValidation() {
419 419
 		$configurationOK = true;
420 420
 		$errorStr = 'Configuration Error (prefix '.
421
-			(string)$this->configPrefix .'): ';
421
+			(string) $this->configPrefix.'): ';
422 422
 
423 423
 		//options that shall not be empty
424 424
 		$options = ['ldapHost', 'ldapPort', 'ldapUserDisplayName',
425 425
 						 'ldapGroupDisplayName', 'ldapLoginFilter'];
426
-		foreach($options as $key) {
426
+		foreach ($options as $key) {
427 427
 			$val = $this->configuration->$key;
428
-			if(empty($val)) {
429
-				switch($key) {
428
+			if (empty($val)) {
429
+				switch ($key) {
430 430
 					case 'ldapHost':
431 431
 						$subj = 'LDAP Host';
432 432
 						break;
@@ -459,12 +459,12 @@  discard block
 block discarded – undo
459 459
 		$agent = $this->configuration->ldapAgentName;
460 460
 		$pwd = $this->configuration->ldapAgentPassword;
461 461
 		if (
462
-			($agent === ''  && $pwd !== '')
462
+			($agent === '' && $pwd !== '')
463 463
 			|| ($agent !== '' && $pwd === '')
464 464
 		) {
465 465
 			\OCP\Util::writeLog(
466 466
 				'user_ldap',
467
-				$errorStr.'either no password is given for the user ' .
467
+				$errorStr.'either no password is given for the user '.
468 468
 					'agent or a password is given, but not an LDAP agent.',
469 469
 				ILogger::WARN);
470 470
 			$configurationOK = false;
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
 		$baseUsers = $this->configuration->ldapBaseUsers;
475 475
 		$baseGroups = $this->configuration->ldapBaseGroups;
476 476
 
477
-		if(empty($base) && empty($baseUsers) && empty($baseGroups)) {
477
+		if (empty($base) && empty($baseUsers) && empty($baseGroups)) {
478 478
 			\OCP\Util::writeLog(
479 479
 				'user_ldap',
480 480
 				$errorStr.'Not a single Base DN given.',
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
 			$configurationOK = false;
484 484
 		}
485 485
 
486
-		if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8')
486
+		if (mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8')
487 487
 		   === false) {
488 488
 			\OCP\Util::writeLog(
489 489
 				'user_ldap',
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
 	 */
503 503
 	private function validateConfiguration() {
504 504
 
505
-		if($this->doNotValidate) {
505
+		if ($this->doNotValidate) {
506 506
 			//don't do a validation if it is a new configuration with pure
507 507
 			//default values. Will be allowed on changes via __set or
508 508
 			//setConfiguration
@@ -525,14 +525,14 @@  discard block
 block discarded – undo
525 525
 	 * @throws ServerNotAvailableException
526 526
 	 */
527 527
 	private function establishConnection() {
528
-		if(!$this->configuration->ldapConfigurationActive) {
528
+		if (!$this->configuration->ldapConfigurationActive) {
529 529
 			return null;
530 530
 		}
531 531
 		static $phpLDAPinstalled = true;
532
-		if(!$phpLDAPinstalled) {
532
+		if (!$phpLDAPinstalled) {
533 533
 			return false;
534 534
 		}
535
-		if(!$this->ignoreValidation && !$this->configured) {
535
+		if (!$this->ignoreValidation && !$this->configured) {
536 536
 			\OCP\Util::writeLog(
537 537
 				'user_ldap',
538 538
 				'Configuration is invalid, cannot connect',
@@ -540,8 +540,8 @@  discard block
 block discarded – undo
540 540
 			);
541 541
 			return false;
542 542
 		}
543
-		if(!$this->ldapConnectionRes) {
544
-			if(!$this->ldap->areLDAPFunctionsAvailable()) {
543
+		if (!$this->ldapConnectionRes) {
544
+			if (!$this->ldap->areLDAPFunctionsAvailable()) {
545 545
 				$phpLDAPinstalled = false;
546 546
 				\OCP\Util::writeLog(
547 547
 					'user_ldap',
@@ -551,8 +551,8 @@  discard block
 block discarded – undo
551 551
 
552 552
 				return false;
553 553
 			}
554
-			if($this->configuration->turnOffCertCheck) {
555
-				if(putenv('LDAPTLS_REQCERT=never')) {
554
+			if ($this->configuration->turnOffCertCheck) {
555
+				if (putenv('LDAPTLS_REQCERT=never')) {
556 556
 					\OCP\Util::writeLog('user_ldap',
557 557
 						'Turned off SSL certificate validation successfully.',
558 558
 						ILogger::DEBUG);
@@ -576,20 +576,20 @@  discard block
 block discarded – undo
576 576
 					return $this->bind();
577 577
 				}
578 578
 			} catch (ServerNotAvailableException $e) {
579
-				if(!$isBackupHost) {
579
+				if (!$isBackupHost) {
580 580
 					throw $e;
581 581
 				}
582 582
 			}
583 583
 
584 584
 			//if LDAP server is not reachable, try the Backup (Replica!) Server
585
-			if($isBackupHost || $isOverrideMainServer) {
585
+			if ($isBackupHost || $isOverrideMainServer) {
586 586
 				$this->doConnect($this->configuration->ldapBackupHost,
587 587
 								 $this->configuration->ldapBackupPort);
588 588
 				$this->bindResult = [];
589 589
 				$bindStatus = $this->bind();
590 590
 				$error = $this->ldap->isResource($this->ldapConnectionRes) ?
591 591
 					$this->ldap->errno($this->ldapConnectionRes) : -1;
592
-				if($bindStatus && $error === 0 && !$this->getFromCache('overrideMainServer')) {
592
+				if ($bindStatus && $error === 0 && !$this->getFromCache('overrideMainServer')) {
593 593
 					//when bind to backup server succeeded and failed to main server,
594 594
 					//skip contacting him until next cache refresh
595 595
 					$this->writeToCache('overrideMainServer', true);
@@ -614,17 +614,17 @@  discard block
 block discarded – undo
614 614
 
615 615
 		$this->ldapConnectionRes = $this->ldap->connect($host, $port);
616 616
 
617
-		if(!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) {
617
+		if (!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) {
618 618
 			throw new ServerNotAvailableException('Could not set required LDAP Protocol version.');
619 619
 		}
620 620
 
621
-		if(!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) {
621
+		if (!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) {
622 622
 			throw new ServerNotAvailableException('Could not disable LDAP referrals.');
623 623
 		}
624 624
 
625
-		if($this->configuration->ldapTLS) {
626
-			if(!$this->ldap->startTls($this->ldapConnectionRes)) {
627
-				throw new ServerNotAvailableException('Start TLS failed, when connecting to LDAP host ' . $host . '.');
625
+		if ($this->configuration->ldapTLS) {
626
+			if (!$this->ldap->startTls($this->ldapConnectionRes)) {
627
+				throw new ServerNotAvailableException('Start TLS failed, when connecting to LDAP host '.$host.'.');
628 628
 			}
629 629
 		}
630 630
 
@@ -635,19 +635,19 @@  discard block
 block discarded – undo
635 635
 	 * Binds to LDAP
636 636
 	 */
637 637
 	public function bind() {
638
-		if(!$this->configuration->ldapConfigurationActive) {
638
+		if (!$this->configuration->ldapConfigurationActive) {
639 639
 			return false;
640 640
 		}
641 641
 		$cr = $this->ldapConnectionRes;
642
-		if(!$this->ldap->isResource($cr)) {
642
+		if (!$this->ldap->isResource($cr)) {
643 643
 			$cr = $this->getConnectionResource();
644 644
 		}
645 645
 
646
-		if(
646
+		if (
647 647
 			count($this->bindResult) !== 0
648 648
 			&& $this->bindResult['dn'] === $this->configuration->ldapAgentName
649 649
 			&& \OC::$server->getHasher()->verify(
650
-				$this->configPrefix . $this->configuration->ldapAgentPassword,
650
+				$this->configPrefix.$this->configuration->ldapAgentPassword,
651 651
 				$this->bindResult['hash']
652 652
 			)
653 653
 		) {
@@ -663,20 +663,20 @@  discard block
 block discarded – undo
663 663
 
664 664
 		$this->bindResult = [
665 665
 			'dn' => $this->configuration->ldapAgentName,
666
-			'hash' => \OC::$server->getHasher()->hash($this->configPrefix . $this->configuration->ldapAgentPassword),
666
+			'hash' => \OC::$server->getHasher()->hash($this->configPrefix.$this->configuration->ldapAgentPassword),
667 667
 			'result' => $ldapLogin,
668 668
 		];
669 669
 
670
-		if(!$ldapLogin) {
670
+		if (!$ldapLogin) {
671 671
 			$errno = $this->ldap->errno($cr);
672 672
 
673 673
 			\OCP\Util::writeLog('user_ldap',
674
-				'Bind failed: ' . $errno . ': ' . $this->ldap->error($cr),
674
+				'Bind failed: '.$errno.': '.$this->ldap->error($cr),
675 675
 				ILogger::WARN);
676 676
 
677 677
 			// Set to failure mode, if LDAP error code is not LDAP_SUCCESS or LDAP_INVALID_CREDENTIALS
678 678
 			// or (needed for Apple Open Directory:) LDAP_INSUFFICIENT_ACCESS
679
-			if($errno !== 0 && $errno !== 49 && $errno !== 50) {
679
+			if ($errno !== 0 && $errno !== 49 && $errno !== 50) {
680 680
 				$this->ldapConnectionRes = null;
681 681
 			}
682 682
 
Please login to merge, or discard this patch.
apps/user_ldap/lib/Wizard.php 1 patch
Spacing   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	public function __construct(Configuration $configuration, ILDAPWrapper $ldap, Access $access) {
73 73
 		parent::__construct($ldap);
74 74
 		$this->configuration = $configuration;
75
-		if(is_null(Wizard::$l)) {
75
+		if (is_null(Wizard::$l)) {
76 76
 			Wizard::$l = \OC::$server->getL10N('user_ldap');
77 77
 		}
78 78
 		$this->access = $access;
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	}
81 81
 
82 82
 	public function  __destruct() {
83
-		if($this->result->hasChanges()) {
83
+		if ($this->result->hasChanges()) {
84 84
 			$this->configuration->saveConfiguration();
85 85
 		}
86 86
 	}
@@ -95,18 +95,18 @@  discard block
 block discarded – undo
95 95
 	 */
96 96
 	public function countEntries(string $filter, string $type): int {
97 97
 		$reqs = ['ldapHost', 'ldapPort', 'ldapBase'];
98
-		if($type === 'users') {
98
+		if ($type === 'users') {
99 99
 			$reqs[] = 'ldapUserFilter';
100 100
 		}
101
-		if(!$this->checkRequirements($reqs)) {
101
+		if (!$this->checkRequirements($reqs)) {
102 102
 			throw new \Exception('Requirements not met', 400);
103 103
 		}
104 104
 
105 105
 		$attr = ['dn']; // default
106 106
 		$limit = 1001;
107
-		if($type === 'groups') {
108
-			$result =  $this->access->countGroups($filter, $attr, $limit);
109
-		} else if($type === 'users') {
107
+		if ($type === 'groups') {
108
+			$result = $this->access->countGroups($filter, $attr, $limit);
109
+		} else if ($type === 'users') {
110 110
 			$result = $this->access->countUsers($filter, $attr, $limit);
111 111
 		} else if ($type === 'objects') {
112 112
 			$result = $this->access->countObjects($limit);
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 			throw new \Exception('Internal error: Invalid object type', 500);
115 115
 		}
116 116
 
117
-		return (int)$result;
117
+		return (int) $result;
118 118
 	}
119 119
 
120 120
 	/**
@@ -125,16 +125,16 @@  discard block
 block discarded – undo
125 125
 	 * @return string
126 126
 	 */
127 127
 	private function formatCountResult(int $count): string {
128
-		if($count > 1000) {
128
+		if ($count > 1000) {
129 129
 			return '> 1000';
130 130
 		}
131
-		return (string)$count;
131
+		return (string) $count;
132 132
 	}
133 133
 
134 134
 	public function countGroups() {
135 135
 		$filter = $this->configuration->ldapGroupFilter;
136 136
 
137
-		if(empty($filter)) {
137
+		if (empty($filter)) {
138 138
 			$output = self::$l->n('%s group found', '%s groups found', 0, [0]);
139 139
 			$this->result->addChange('ldap_group_count', $output);
140 140
 			return $this->result;
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 			$groupsTotal = $this->countEntries($filter, 'groups');
145 145
 		} catch (\Exception $e) {
146 146
 			//400 can be ignored, 500 is forwarded
147
-			if($e->getCode() === 500) {
147
+			if ($e->getCode() === 500) {
148 148
 				throw $e;
149 149
 			}
150 150
 			return false;
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 	public function countInBaseDN() {
187 187
 		// we don't need to provide a filter in this case
188 188
 		$total = $this->countEntries('', 'objects');
189
-		if($total === false) {
189
+		if ($total === false) {
190 190
 			throw new \Exception('invalid results received');
191 191
 		}
192 192
 		$this->result->addChange('ldap_test_base', $total);
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 	 * @return int|bool
201 201
 	 */
202 202
 	public function countUsersWithAttribute($attr, $existsCheck = false) {
203
-		if(!$this->checkRequirements(['ldapHost',
203
+		if (!$this->checkRequirements(['ldapHost',
204 204
 										   'ldapPort',
205 205
 										   'ldapBase',
206 206
 										   'ldapUserFilter',
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 
211 211
 		$filter = $this->access->combineFilterWithAnd([
212 212
 			$this->configuration->ldapUserFilter,
213
-			$attr . '=*'
213
+			$attr.'=*'
214 214
 		]);
215 215
 
216 216
 		$limit = ($existsCheck === false) ? null : 1;
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 	 * @throws \Exception
226 226
 	 */
227 227
 	public function detectUserDisplayNameAttribute() {
228
-		if(!$this->checkRequirements(['ldapHost',
228
+		if (!$this->checkRequirements(['ldapHost',
229 229
 										'ldapPort',
230 230
 										'ldapBase',
231 231
 										'ldapUserFilter',
@@ -237,8 +237,8 @@  discard block
 block discarded – undo
237 237
 		if ($attr !== '' && $attr !== 'displayName') {
238 238
 			// most likely not the default value with upper case N,
239 239
 			// verify it still produces a result
240
-			$count = (int)$this->countUsersWithAttribute($attr, true);
241
-			if($count > 0) {
240
+			$count = (int) $this->countUsersWithAttribute($attr, true);
241
+			if ($count > 0) {
242 242
 				//no change, but we sent it back to make sure the user interface
243 243
 				//is still correct, even if the ajax call was cancelled meanwhile
244 244
 				$this->result->addChange('ldap_display_name', $attr);
@@ -249,9 +249,9 @@  discard block
 block discarded – undo
249 249
 		// first attribute that has at least one result wins
250 250
 		$displayNameAttrs = ['displayname', 'cn'];
251 251
 		foreach ($displayNameAttrs as $attr) {
252
-			$count = (int)$this->countUsersWithAttribute($attr, true);
252
+			$count = (int) $this->countUsersWithAttribute($attr, true);
253 253
 
254
-			if($count > 0) {
254
+			if ($count > 0) {
255 255
 				$this->applyFind('ldap_display_name', $attr);
256 256
 				return $this->result;
257 257
 			}
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 	 * @return WizardResult|bool
268 268
 	 */
269 269
 	public function detectEmailAttribute() {
270
-		if(!$this->checkRequirements(['ldapHost',
270
+		if (!$this->checkRequirements(['ldapHost',
271 271
 										   'ldapPort',
272 272
 										   'ldapBase',
273 273
 										   'ldapUserFilter',
@@ -277,8 +277,8 @@  discard block
 block discarded – undo
277 277
 
278 278
 		$attr = $this->configuration->ldapEmailAttribute;
279 279
 		if ($attr !== '') {
280
-			$count = (int)$this->countUsersWithAttribute($attr, true);
281
-			if($count > 0) {
280
+			$count = (int) $this->countUsersWithAttribute($attr, true);
281
+			if ($count > 0) {
282 282
 				return false;
283 283
 			}
284 284
 			$writeLog = true;
@@ -289,19 +289,19 @@  discard block
 block discarded – undo
289 289
 		$emailAttributes = ['mail', 'mailPrimaryAddress'];
290 290
 		$winner = '';
291 291
 		$maxUsers = 0;
292
-		foreach($emailAttributes as $attr) {
292
+		foreach ($emailAttributes as $attr) {
293 293
 			$count = $this->countUsersWithAttribute($attr);
294
-			if($count > $maxUsers) {
294
+			if ($count > $maxUsers) {
295 295
 				$maxUsers = $count;
296 296
 				$winner = $attr;
297 297
 			}
298 298
 		}
299 299
 
300
-		if($winner !== '') {
300
+		if ($winner !== '') {
301 301
 			$this->applyFind('ldap_email_attr', $winner);
302
-			if($writeLog) {
303
-				\OCP\Util::writeLog('user_ldap', 'The mail attribute has ' .
304
-					'automatically been reset, because the original value ' .
302
+			if ($writeLog) {
303
+				\OCP\Util::writeLog('user_ldap', 'The mail attribute has '.
304
+					'automatically been reset, because the original value '.
305 305
 					'did not return any results.', ILogger::INFO);
306 306
 			}
307 307
 		}
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 	 * @throws \Exception
315 315
 	 */
316 316
 	public function determineAttributes() {
317
-		if(!$this->checkRequirements(['ldapHost',
317
+		if (!$this->checkRequirements(['ldapHost',
318 318
 										   'ldapPort',
319 319
 										   'ldapBase',
320 320
 										   'ldapUserFilter',
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 		$this->result->addOptions('ldap_loginfilter_attributes', $attributes);
331 331
 
332 332
 		$selected = $this->configuration->ldapLoginFilterAttributes;
333
-		if(is_array($selected) && !empty($selected)) {
333
+		if (is_array($selected) && !empty($selected)) {
334 334
 			$this->result->addChange('ldap_loginfilter_attributes', $selected);
335 335
 		}
336 336
 
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
 	 * @throws \Exception
344 344
 	 */
345 345
 	private function getUserAttributes() {
346
-		if(!$this->checkRequirements(['ldapHost',
346
+		if (!$this->checkRequirements(['ldapHost',
347 347
 										   'ldapPort',
348 348
 										   'ldapBase',
349 349
 										   'ldapUserFilter',
@@ -351,20 +351,20 @@  discard block
 block discarded – undo
351 351
 			return  false;
352 352
 		}
353 353
 		$cr = $this->getConnection();
354
-		if(!$cr) {
354
+		if (!$cr) {
355 355
 			throw new \Exception('Could not connect to LDAP');
356 356
 		}
357 357
 
358 358
 		$base = $this->configuration->ldapBase[0];
359 359
 		$filter = $this->configuration->ldapUserFilter;
360 360
 		$rr = $this->ldap->search($cr, $base, $filter, [], 1, 1);
361
-		if(!$this->ldap->isResource($rr)) {
361
+		if (!$this->ldap->isResource($rr)) {
362 362
 			return false;
363 363
 		}
364 364
 		$er = $this->ldap->firstEntry($cr, $rr);
365 365
 		$attributes = $this->ldap->getAttributes($cr, $er);
366 366
 		$pureAttributes = [];
367
-		for($i = 0; $i < $attributes['count']; $i++) {
367
+		for ($i = 0; $i < $attributes['count']; $i++) {
368 368
 			$pureAttributes[] = $attributes[$i];
369 369
 		}
370 370
 
@@ -399,23 +399,23 @@  discard block
 block discarded – undo
399 399
 	 * @throws \Exception
400 400
 	 */
401 401
 	private function determineGroups($dbKey, $confKey, $testMemberOf = true) {
402
-		if(!$this->checkRequirements(['ldapHost',
402
+		if (!$this->checkRequirements(['ldapHost',
403 403
 										   'ldapPort',
404 404
 										   'ldapBase',
405 405
 										   ])) {
406 406
 			return  false;
407 407
 		}
408 408
 		$cr = $this->getConnection();
409
-		if(!$cr) {
409
+		if (!$cr) {
410 410
 			throw new \Exception('Could not connect to LDAP');
411 411
 		}
412 412
 
413 413
 		$this->fetchGroups($dbKey, $confKey);
414 414
 
415
-		if($testMemberOf) {
415
+		if ($testMemberOf) {
416 416
 			$this->configuration->hasMemberOfFilterSupport = $this->testMemberOf();
417 417
 			$this->result->markChange();
418
-			if(!$this->configuration->hasMemberOfFilterSupport) {
418
+			if (!$this->configuration->hasMemberOfFilterSupport) {
419 419
 				throw new \Exception('memberOf is not supported by the server');
420 420
 			}
421 421
 		}
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
 		$obclasses = ['posixGroup', 'group', 'zimbraDistributionList', 'groupOfNames', 'groupOfUniqueNames'];
436 436
 
437 437
 		$filterParts = [];
438
-		foreach($obclasses as $obclass) {
438
+		foreach ($obclasses as $obclass) {
439 439
 			$filterParts[] = 'objectclass='.$obclass;
440 440
 		}
441 441
 		//we filter for everything
@@ -452,8 +452,8 @@  discard block
 block discarded – undo
452 452
 			// we need to request dn additionally here, otherwise memberOf
453 453
 			// detection will fail later
454 454
 			$result = $this->access->searchGroups($filter, ['cn', 'dn'], $limit, $offset);
455
-			foreach($result as $item) {
456
-				if(!isset($item['cn']) && !is_array($item['cn']) && !isset($item['cn'][0])) {
455
+			foreach ($result as $item) {
456
+				if (!isset($item['cn']) && !is_array($item['cn']) && !isset($item['cn'][0])) {
457 457
 					// just in case - no issue known
458 458
 					continue;
459 459
 				}
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
 			$offset += $limit;
464 464
 		} while ($this->access->hasMoreResults());
465 465
 
466
-		if(count($groupNames) > 0) {
466
+		if (count($groupNames) > 0) {
467 467
 			natsort($groupNames);
468 468
 			$this->result->addOptions($dbKey, array_values($groupNames));
469 469
 		} else {
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
 		}
472 472
 
473 473
 		$setFeatures = $this->configuration->$confKey;
474
-		if(is_array($setFeatures) && !empty($setFeatures)) {
474
+		if (is_array($setFeatures) && !empty($setFeatures)) {
475 475
 			//something is already configured? pre-select it.
476 476
 			$this->result->addChange($dbKey, $setFeatures);
477 477
 		}
@@ -479,14 +479,14 @@  discard block
 block discarded – undo
479 479
 	}
480 480
 
481 481
 	public function determineGroupMemberAssoc() {
482
-		if(!$this->checkRequirements(['ldapHost',
482
+		if (!$this->checkRequirements(['ldapHost',
483 483
 										   'ldapPort',
484 484
 										   'ldapGroupFilter',
485 485
 										   ])) {
486 486
 			return  false;
487 487
 		}
488 488
 		$attribute = $this->detectGroupMemberAssoc();
489
-		if($attribute === false) {
489
+		if ($attribute === false) {
490 490
 			return false;
491 491
 		}
492 492
 		$this->configuration->setConfiguration(['ldapGroupMemberAssocAttr' => $attribute]);
@@ -501,14 +501,14 @@  discard block
 block discarded – undo
501 501
 	 * @throws \Exception
502 502
 	 */
503 503
 	public function determineGroupObjectClasses() {
504
-		if(!$this->checkRequirements(['ldapHost',
504
+		if (!$this->checkRequirements(['ldapHost',
505 505
 										   'ldapPort',
506 506
 										   'ldapBase',
507 507
 										   ])) {
508 508
 			return  false;
509 509
 		}
510 510
 		$cr = $this->getConnection();
511
-		if(!$cr) {
511
+		if (!$cr) {
512 512
 			throw new \Exception('Could not connect to LDAP');
513 513
 		}
514 514
 
@@ -528,14 +528,14 @@  discard block
 block discarded – undo
528 528
 	 * @throws \Exception
529 529
 	 */
530 530
 	public function determineUserObjectClasses() {
531
-		if(!$this->checkRequirements(['ldapHost',
531
+		if (!$this->checkRequirements(['ldapHost',
532 532
 										   'ldapPort',
533 533
 										   'ldapBase',
534 534
 										   ])) {
535 535
 			return  false;
536 536
 		}
537 537
 		$cr = $this->getConnection();
538
-		if(!$cr) {
538
+		if (!$cr) {
539 539
 			throw new \Exception('Could not connect to LDAP');
540 540
 		}
541 541
 
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
 	 * @throws \Exception
559 559
 	 */
560 560
 	public function getGroupFilter() {
561
-		if(!$this->checkRequirements(['ldapHost',
561
+		if (!$this->checkRequirements(['ldapHost',
562 562
 										   'ldapPort',
563 563
 										   'ldapBase',
564 564
 										   ])) {
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
 	 * @throws \Exception
583 583
 	 */
584 584
 	public function getUserListFilter() {
585
-		if(!$this->checkRequirements(['ldapHost',
585
+		if (!$this->checkRequirements(['ldapHost',
586 586
 										   'ldapPort',
587 587
 										   'ldapBase',
588 588
 										   ])) {
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
 			$this->applyFind('ldap_display_name', $d['ldap_display_name']);
596 596
 		}
597 597
 		$filter = $this->composeLdapFilter(self::LFILTER_USER_LIST);
598
-		if(!$filter) {
598
+		if (!$filter) {
599 599
 			throw new \Exception('Cannot create filter');
600 600
 		}
601 601
 
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
 	 * @throws \Exception
609 609
 	 */
610 610
 	public function getUserLoginFilter() {
611
-		if(!$this->checkRequirements(['ldapHost',
611
+		if (!$this->checkRequirements(['ldapHost',
612 612
 										   'ldapPort',
613 613
 										   'ldapBase',
614 614
 										   'ldapUserFilter',
@@ -617,7 +617,7 @@  discard block
 block discarded – undo
617 617
 		}
618 618
 
619 619
 		$filter = $this->composeLdapFilter(self::LFILTER_LOGIN);
620
-		if(!$filter) {
620
+		if (!$filter) {
621 621
 			throw new \Exception('Cannot create filter');
622 622
 		}
623 623
 
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
 	 * @throws \Exception
632 632
 	 */
633 633
 	public function testLoginName($loginName) {
634
-		if(!$this->checkRequirements(['ldapHost',
634
+		if (!$this->checkRequirements(['ldapHost',
635 635
 			'ldapPort',
636 636
 			'ldapBase',
637 637
 			'ldapLoginFilter',
@@ -640,17 +640,17 @@  discard block
 block discarded – undo
640 640
 		}
641 641
 
642 642
 		$cr = $this->access->connection->getConnectionResource();
643
-		if(!$this->ldap->isResource($cr)) {
643
+		if (!$this->ldap->isResource($cr)) {
644 644
 			throw new \Exception('connection error');
645 645
 		}
646 646
 
647
-		if(mb_strpos($this->access->connection->ldapLoginFilter, '%uid', 0, 'UTF-8')
647
+		if (mb_strpos($this->access->connection->ldapLoginFilter, '%uid', 0, 'UTF-8')
648 648
 			=== false) {
649 649
 			throw new \Exception('missing placeholder');
650 650
 		}
651 651
 
652 652
 		$users = $this->access->countUsersByLoginName($loginName);
653
-		if($this->ldap->errno($cr) !== 0) {
653
+		if ($this->ldap->errno($cr) !== 0) {
654 654
 			throw new \Exception($this->ldap->error($cr));
655 655
 		}
656 656
 		$filter = str_replace('%uid', $loginName, $this->access->connection->ldapLoginFilter);
@@ -665,22 +665,22 @@  discard block
 block discarded – undo
665 665
 	 * @throws \Exception
666 666
 	 */
667 667
 	public function guessPortAndTLS() {
668
-		if(!$this->checkRequirements(['ldapHost',
668
+		if (!$this->checkRequirements(['ldapHost',
669 669
 										   ])) {
670 670
 			return false;
671 671
 		}
672 672
 		$this->checkHost();
673 673
 		$portSettings = $this->getPortSettingsToTry();
674 674
 
675
-		if(!is_array($portSettings)) {
675
+		if (!is_array($portSettings)) {
676 676
 			throw new \Exception(print_r($portSettings, true));
677 677
 		}
678 678
 
679 679
 		//proceed from the best configuration and return on first success
680
-		foreach($portSettings as $setting) {
680
+		foreach ($portSettings as $setting) {
681 681
 			$p = $setting['port'];
682 682
 			$t = $setting['tls'];
683
-			\OCP\Util::writeLog('user_ldap', 'Wiz: trying port '. $p . ', TLS '. $t, ILogger::DEBUG);
683
+			\OCP\Util::writeLog('user_ldap', 'Wiz: trying port '.$p.', TLS '.$t, ILogger::DEBUG);
684 684
 			//connectAndBind may throw Exception, it needs to be catched by the
685 685
 			//callee of this method
686 686
 
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
 				// any reply other than -1 (= cannot connect) is already okay,
691 691
 				// because then we found the server
692 692
 				// unavailable startTLS returns -11
693
-				if($e->getCode() > 0) {
693
+				if ($e->getCode() > 0) {
694 694
 					$settingsFound = true;
695 695
 				} else {
696 696
 					throw $e;
@@ -700,10 +700,10 @@  discard block
 block discarded – undo
700 700
 			if ($settingsFound === true) {
701 701
 				$config = [
702 702
 					'ldapPort' => $p,
703
-					'ldapTLS' => (int)$t
703
+					'ldapTLS' => (int) $t
704 704
 				];
705 705
 				$this->configuration->setConfiguration($config);
706
-				\OCP\Util::writeLog('user_ldap', 'Wiz: detected Port ' . $p, ILogger::DEBUG);
706
+				\OCP\Util::writeLog('user_ldap', 'Wiz: detected Port '.$p, ILogger::DEBUG);
707 707
 				$this->result->addChange('ldap_port', $p);
708 708
 				return $this->result;
709 709
 			}
@@ -718,7 +718,7 @@  discard block
 block discarded – undo
718 718
 	 * @return WizardResult|false WizardResult on success, false otherwise
719 719
 	 */
720 720
 	public function guessBaseDN() {
721
-		if(!$this->checkRequirements(['ldapHost',
721
+		if (!$this->checkRequirements(['ldapHost',
722 722
 										   'ldapPort',
723 723
 										   ])) {
724 724
 			return false;
@@ -727,9 +727,9 @@  discard block
 block discarded – undo
727 727
 		//check whether a DN is given in the agent name (99.9% of all cases)
728 728
 		$base = null;
729 729
 		$i = stripos($this->configuration->ldapAgentName, 'dc=');
730
-		if($i !== false) {
730
+		if ($i !== false) {
731 731
 			$base = substr($this->configuration->ldapAgentName, $i);
732
-			if($this->testBaseDN($base)) {
732
+			if ($this->testBaseDN($base)) {
733 733
 				$this->applyFind('ldap_base', $base);
734 734
 				return $this->result;
735 735
 			}
@@ -740,13 +740,13 @@  discard block
 block discarded – undo
740 740
 		//a base DN
741 741
 		$helper = new Helper(\OC::$server->getConfig());
742 742
 		$domain = $helper->getDomainFromURL($this->configuration->ldapHost);
743
-		if(!$domain) {
743
+		if (!$domain) {
744 744
 			return false;
745 745
 		}
746 746
 
747 747
 		$dparts = explode('.', $domain);
748
-		while(count($dparts) > 0) {
749
-			$base2 = 'dc=' . implode(',dc=', $dparts);
748
+		while (count($dparts) > 0) {
749
+			$base2 = 'dc='.implode(',dc=', $dparts);
750 750
 			if ($base !== $base2 && $this->testBaseDN($base2)) {
751 751
 				$this->applyFind('ldap_base', $base2);
752 752
 				return $this->result;
@@ -779,7 +779,7 @@  discard block
 block discarded – undo
779 779
 		$hostInfo = parse_url($host);
780 780
 
781 781
 		//removes Port from Host
782
-		if(is_array($hostInfo) && isset($hostInfo['port'])) {
782
+		if (is_array($hostInfo) && isset($hostInfo['port'])) {
783 783
 			$port = $hostInfo['port'];
784 784
 			$host = str_replace(':'.$port, '', $host);
785 785
 			$this->applyFind('ldap_host', $host);
@@ -796,30 +796,30 @@  discard block
 block discarded – undo
796 796
 	private function detectGroupMemberAssoc() {
797 797
 		$possibleAttrs = ['uniqueMember', 'memberUid', 'member', 'gidNumber'];
798 798
 		$filter = $this->configuration->ldapGroupFilter;
799
-		if(empty($filter)) {
799
+		if (empty($filter)) {
800 800
 			return false;
801 801
 		}
802 802
 		$cr = $this->getConnection();
803
-		if(!$cr) {
803
+		if (!$cr) {
804 804
 			throw new \Exception('Could not connect to LDAP');
805 805
 		}
806 806
 		$base = $this->configuration->ldapBaseGroups[0] ?: $this->configuration->ldapBase[0];
807 807
 		$rr = $this->ldap->search($cr, $base, $filter, $possibleAttrs, 0, 1000);
808
-		if(!$this->ldap->isResource($rr)) {
808
+		if (!$this->ldap->isResource($rr)) {
809 809
 			return false;
810 810
 		}
811 811
 		$er = $this->ldap->firstEntry($cr, $rr);
812
-		while(is_resource($er)) {
812
+		while (is_resource($er)) {
813 813
 			$this->ldap->getDN($cr, $er);
814 814
 			$attrs = $this->ldap->getAttributes($cr, $er);
815 815
 			$result = [];
816 816
 			$possibleAttrsCount = count($possibleAttrs);
817
-			for($i = 0; $i < $possibleAttrsCount; $i++) {
818
-				if(isset($attrs[$possibleAttrs[$i]])) {
817
+			for ($i = 0; $i < $possibleAttrsCount; $i++) {
818
+				if (isset($attrs[$possibleAttrs[$i]])) {
819 819
 					$result[$possibleAttrs[$i]] = $attrs[$possibleAttrs[$i]]['count'];
820 820
 				}
821 821
 			}
822
-			if(!empty($result)) {
822
+			if (!empty($result)) {
823 823
 				natsort($result);
824 824
 				return key($result);
825 825
 			}
@@ -838,14 +838,14 @@  discard block
 block discarded – undo
838 838
 	 */
839 839
 	private function testBaseDN($base) {
840 840
 		$cr = $this->getConnection();
841
-		if(!$cr) {
841
+		if (!$cr) {
842 842
 			throw new \Exception('Could not connect to LDAP');
843 843
 		}
844 844
 
845 845
 		//base is there, let's validate it. If we search for anything, we should
846 846
 		//get a result set > 0 on a proper base
847 847
 		$rr = $this->ldap->search($cr, $base, 'objectClass=*', ['dn'], 0, 1);
848
-		if(!$this->ldap->isResource($rr)) {
848
+		if (!$this->ldap->isResource($rr)) {
849 849
 			$errorNo  = $this->ldap->errno($cr);
850 850
 			$errorMsg = $this->ldap->error($cr);
851 851
 			\OCP\Util::writeLog('user_ldap', 'Wiz: Could not search base '.$base.
@@ -867,11 +867,11 @@  discard block
 block discarded – undo
867 867
 	 */
868 868
 	private function testMemberOf() {
869 869
 		$cr = $this->getConnection();
870
-		if(!$cr) {
870
+		if (!$cr) {
871 871
 			throw new \Exception('Could not connect to LDAP');
872 872
 		}
873 873
 		$result = $this->access->countUsers('memberOf=*', ['memberOf'], 1);
874
-		if(is_int($result) &&  $result > 0) {
874
+		if (is_int($result) && $result > 0) {
875 875
 			return true;
876 876
 		}
877 877
 		return false;
@@ -892,27 +892,27 @@  discard block
 block discarded – undo
892 892
 			case self::LFILTER_USER_LIST:
893 893
 				$objcs = $this->configuration->ldapUserFilterObjectclass;
894 894
 				//glue objectclasses
895
-				if(is_array($objcs) && count($objcs) > 0) {
895
+				if (is_array($objcs) && count($objcs) > 0) {
896 896
 					$filter .= '(|';
897
-					foreach($objcs as $objc) {
898
-						$filter .= '(objectclass=' . $objc . ')';
897
+					foreach ($objcs as $objc) {
898
+						$filter .= '(objectclass='.$objc.')';
899 899
 					}
900 900
 					$filter .= ')';
901 901
 					$parts++;
902 902
 				}
903 903
 				//glue group memberships
904
-				if($this->configuration->hasMemberOfFilterSupport) {
904
+				if ($this->configuration->hasMemberOfFilterSupport) {
905 905
 					$cns = $this->configuration->ldapUserFilterGroups;
906
-					if(is_array($cns) && count($cns) > 0) {
906
+					if (is_array($cns) && count($cns) > 0) {
907 907
 						$filter .= '(|';
908 908
 						$cr = $this->getConnection();
909
-						if(!$cr) {
909
+						if (!$cr) {
910 910
 							throw new \Exception('Could not connect to LDAP');
911 911
 						}
912 912
 						$base = $this->configuration->ldapBase[0];
913
-						foreach($cns as $cn) {
914
-							$rr = $this->ldap->search($cr, $base, 'cn=' . $cn, ['dn', 'primaryGroupToken']);
915
-							if(!$this->ldap->isResource($rr)) {
913
+						foreach ($cns as $cn) {
914
+							$rr = $this->ldap->search($cr, $base, 'cn='.$cn, ['dn', 'primaryGroupToken']);
915
+							if (!$this->ldap->isResource($rr)) {
916 916
 								continue;
917 917
 							}
918 918
 							$er = $this->ldap->firstEntry($cr, $rr);
@@ -921,11 +921,11 @@  discard block
 block discarded – undo
921 921
 							if ($dn === false || $dn === '') {
922 922
 								continue;
923 923
 							}
924
-							$filterPart = '(memberof=' . $dn . ')';
925
-							if(isset($attrs['primaryGroupToken'])) {
924
+							$filterPart = '(memberof='.$dn.')';
925
+							if (isset($attrs['primaryGroupToken'])) {
926 926
 								$pgt = $attrs['primaryGroupToken'][0];
927
-								$primaryFilterPart = '(primaryGroupID=' . $pgt .')';
928
-								$filterPart = '(|' . $filterPart . $primaryFilterPart . ')';
927
+								$primaryFilterPart = '(primaryGroupID='.$pgt.')';
928
+								$filterPart = '(|'.$filterPart.$primaryFilterPart.')';
929 929
 							}
930 930
 							$filter .= $filterPart;
931 931
 						}
@@ -934,8 +934,8 @@  discard block
 block discarded – undo
934 934
 					$parts++;
935 935
 				}
936 936
 				//wrap parts in AND condition
937
-				if($parts > 1) {
938
-					$filter = '(&' . $filter . ')';
937
+				if ($parts > 1) {
938
+					$filter = '(&'.$filter.')';
939 939
 				}
940 940
 				if ($filter === '') {
941 941
 					$filter = '(objectclass=*)';
@@ -945,27 +945,27 @@  discard block
 block discarded – undo
945 945
 			case self::LFILTER_GROUP_LIST:
946 946
 				$objcs = $this->configuration->ldapGroupFilterObjectclass;
947 947
 				//glue objectclasses
948
-				if(is_array($objcs) && count($objcs) > 0) {
948
+				if (is_array($objcs) && count($objcs) > 0) {
949 949
 					$filter .= '(|';
950
-					foreach($objcs as $objc) {
951
-						$filter .= '(objectclass=' . $objc . ')';
950
+					foreach ($objcs as $objc) {
951
+						$filter .= '(objectclass='.$objc.')';
952 952
 					}
953 953
 					$filter .= ')';
954 954
 					$parts++;
955 955
 				}
956 956
 				//glue group memberships
957 957
 				$cns = $this->configuration->ldapGroupFilterGroups;
958
-				if(is_array($cns) && count($cns) > 0) {
958
+				if (is_array($cns) && count($cns) > 0) {
959 959
 					$filter .= '(|';
960
-					foreach($cns as $cn) {
961
-						$filter .= '(cn=' . $cn . ')';
960
+					foreach ($cns as $cn) {
961
+						$filter .= '(cn='.$cn.')';
962 962
 					}
963 963
 					$filter .= ')';
964 964
 				}
965 965
 				$parts++;
966 966
 				//wrap parts in AND condition
967
-				if($parts > 1) {
968
-					$filter = '(&' . $filter . ')';
967
+				if ($parts > 1) {
968
+					$filter = '(&'.$filter.')';
969 969
 				}
970 970
 				break;
971 971
 
@@ -977,47 +977,47 @@  discard block
 block discarded – undo
977 977
 				$userAttributes = array_change_key_case(array_flip($userAttributes));
978 978
 				$parts = 0;
979 979
 
980
-				if($this->configuration->ldapLoginFilterUsername === '1') {
980
+				if ($this->configuration->ldapLoginFilterUsername === '1') {
981 981
 					$attr = '';
982
-					if(isset($userAttributes['uid'])) {
982
+					if (isset($userAttributes['uid'])) {
983 983
 						$attr = 'uid';
984
-					} else if(isset($userAttributes['samaccountname'])) {
984
+					} else if (isset($userAttributes['samaccountname'])) {
985 985
 						$attr = 'samaccountname';
986
-					} else if(isset($userAttributes['cn'])) {
986
+					} else if (isset($userAttributes['cn'])) {
987 987
 						//fallback
988 988
 						$attr = 'cn';
989 989
 					}
990 990
 					if ($attr !== '') {
991
-						$filterUsername = '(' . $attr . $loginpart . ')';
991
+						$filterUsername = '('.$attr.$loginpart.')';
992 992
 						$parts++;
993 993
 					}
994 994
 				}
995 995
 
996 996
 				$filterEmail = '';
997
-				if($this->configuration->ldapLoginFilterEmail === '1') {
997
+				if ($this->configuration->ldapLoginFilterEmail === '1') {
998 998
 					$filterEmail = '(|(mailPrimaryAddress=%uid)(mail=%uid))';
999 999
 					$parts++;
1000 1000
 				}
1001 1001
 
1002 1002
 				$filterAttributes = '';
1003 1003
 				$attrsToFilter = $this->configuration->ldapLoginFilterAttributes;
1004
-				if(is_array($attrsToFilter) && count($attrsToFilter) > 0) {
1004
+				if (is_array($attrsToFilter) && count($attrsToFilter) > 0) {
1005 1005
 					$filterAttributes = '(|';
1006
-					foreach($attrsToFilter as $attribute) {
1007
-						$filterAttributes .= '(' . $attribute . $loginpart . ')';
1006
+					foreach ($attrsToFilter as $attribute) {
1007
+						$filterAttributes .= '('.$attribute.$loginpart.')';
1008 1008
 					}
1009 1009
 					$filterAttributes .= ')';
1010 1010
 					$parts++;
1011 1011
 				}
1012 1012
 
1013 1013
 				$filterLogin = '';
1014
-				if($parts > 1) {
1014
+				if ($parts > 1) {
1015 1015
 					$filterLogin = '(|';
1016 1016
 				}
1017 1017
 				$filterLogin .= $filterUsername;
1018 1018
 				$filterLogin .= $filterEmail;
1019 1019
 				$filterLogin .= $filterAttributes;
1020
-				if($parts > 1) {
1020
+				if ($parts > 1) {
1021 1021
 					$filterLogin .= ')';
1022 1022
 				}
1023 1023
 
@@ -1042,12 +1042,12 @@  discard block
 block discarded – undo
1042 1042
 		//connect, does not really trigger any server communication
1043 1043
 		$host = $this->configuration->ldapHost;
1044 1044
 		$hostInfo = parse_url($host);
1045
-		if(!$hostInfo) {
1045
+		if (!$hostInfo) {
1046 1046
 			throw new \Exception(self::$l->t('Invalid Host'));
1047 1047
 		}
1048 1048
 		\OCP\Util::writeLog('user_ldap', 'Wiz: Attempting to connect ', ILogger::DEBUG);
1049 1049
 		$cr = $this->ldap->connect($host, $port);
1050
-		if(!is_resource($cr)) {
1050
+		if (!is_resource($cr)) {
1051 1051
 			throw new \Exception(self::$l->t('Invalid Host'));
1052 1052
 		}
1053 1053
 
@@ -1057,9 +1057,9 @@  discard block
 block discarded – undo
1057 1057
 		$this->ldap->setOption($cr, LDAP_OPT_NETWORK_TIMEOUT, self::LDAP_NW_TIMEOUT);
1058 1058
 
1059 1059
 		try {
1060
-			if($tls) {
1060
+			if ($tls) {
1061 1061
 				$isTlsWorking = @$this->ldap->startTls($cr);
1062
-				if(!$isTlsWorking) {
1062
+				if (!$isTlsWorking) {
1063 1063
 					return false;
1064 1064
 				}
1065 1065
 			}
@@ -1073,17 +1073,17 @@  discard block
 block discarded – undo
1073 1073
 			$errNo = $this->ldap->errno($cr);
1074 1074
 			$error = ldap_error($cr);
1075 1075
 			$this->ldap->unbind($cr);
1076
-		} catch(ServerNotAvailableException $e) {
1076
+		} catch (ServerNotAvailableException $e) {
1077 1077
 			return false;
1078 1078
 		}
1079 1079
 
1080
-		if($login === true) {
1080
+		if ($login === true) {
1081 1081
 			$this->ldap->unbind($cr);
1082
-			\OCP\Util::writeLog('user_ldap', 'Wiz: Bind successful to Port '. $port . ' TLS ' . (int)$tls, ILogger::DEBUG);
1082
+			\OCP\Util::writeLog('user_ldap', 'Wiz: Bind successful to Port '.$port.' TLS '.(int) $tls, ILogger::DEBUG);
1083 1083
 			return true;
1084 1084
 		}
1085 1085
 
1086
-		if($errNo === -1) {
1086
+		if ($errNo === -1) {
1087 1087
 			//host, port or TLS wrong
1088 1088
 			return false;
1089 1089
 		}
@@ -1111,9 +1111,9 @@  discard block
 block discarded – undo
1111 1111
 	 */
1112 1112
 	private function checkRequirements($reqs) {
1113 1113
 		$this->checkAgentRequirements();
1114
-		foreach($reqs as $option) {
1114
+		foreach ($reqs as $option) {
1115 1115
 			$value = $this->configuration->$option;
1116
-			if(empty($value)) {
1116
+			if (empty($value)) {
1117 1117
 				return false;
1118 1118
 			}
1119 1119
 		}
@@ -1135,33 +1135,33 @@  discard block
 block discarded – undo
1135 1135
 		$dnRead = [];
1136 1136
 		$foundItems = [];
1137 1137
 		$maxEntries = 0;
1138
-		if(!is_array($this->configuration->ldapBase)
1138
+		if (!is_array($this->configuration->ldapBase)
1139 1139
 		   || !isset($this->configuration->ldapBase[0])) {
1140 1140
 			return false;
1141 1141
 		}
1142 1142
 		$base = $this->configuration->ldapBase[0];
1143 1143
 		$cr = $this->getConnection();
1144
-		if(!$this->ldap->isResource($cr)) {
1144
+		if (!$this->ldap->isResource($cr)) {
1145 1145
 			return false;
1146 1146
 		}
1147 1147
 		$lastFilter = null;
1148
-		if(isset($filters[count($filters)-1])) {
1149
-			$lastFilter = $filters[count($filters)-1];
1148
+		if (isset($filters[count($filters) - 1])) {
1149
+			$lastFilter = $filters[count($filters) - 1];
1150 1150
 		}
1151
-		foreach($filters as $filter) {
1152
-			if($lastFilter === $filter && count($foundItems) > 0) {
1151
+		foreach ($filters as $filter) {
1152
+			if ($lastFilter === $filter && count($foundItems) > 0) {
1153 1153
 				//skip when the filter is a wildcard and results were found
1154 1154
 				continue;
1155 1155
 			}
1156 1156
 			// 20k limit for performance and reason
1157 1157
 			$rr = $this->ldap->search($cr, $base, $filter, [$attr], 0, 20000);
1158
-			if(!$this->ldap->isResource($rr)) {
1158
+			if (!$this->ldap->isResource($rr)) {
1159 1159
 				continue;
1160 1160
 			}
1161 1161
 			$entries = $this->ldap->countEntries($cr, $rr);
1162 1162
 			$getEntryFunc = 'firstEntry';
1163
-			if(($entries !== false) && ($entries > 0)) {
1164
-				if(!is_null($maxF) && $entries > $maxEntries) {
1163
+			if (($entries !== false) && ($entries > 0)) {
1164
+				if (!is_null($maxF) && $entries > $maxEntries) {
1165 1165
 					$maxEntries = $entries;
1166 1166
 					$maxF = $filter;
1167 1167
 				}
@@ -1169,13 +1169,13 @@  discard block
 block discarded – undo
1169 1169
 				do {
1170 1170
 					$entry = $this->ldap->$getEntryFunc($cr, $rr);
1171 1171
 					$getEntryFunc = 'nextEntry';
1172
-					if(!$this->ldap->isResource($entry)) {
1172
+					if (!$this->ldap->isResource($entry)) {
1173 1173
 						continue 2;
1174 1174
 					}
1175 1175
 					$rr = $entry; //will be expected by nextEntry next round
1176 1176
 					$attributes = $this->ldap->getAttributes($cr, $entry);
1177 1177
 					$dn = $this->ldap->getDN($cr, $entry);
1178
-					if($dn === false || in_array($dn, $dnRead)) {
1178
+					if ($dn === false || in_array($dn, $dnRead)) {
1179 1179
 						continue;
1180 1180
 					}
1181 1181
 					$newItems = [];
@@ -1186,7 +1186,7 @@  discard block
 block discarded – undo
1186 1186
 					$foundItems = array_merge($foundItems, $newItems);
1187 1187
 					$this->resultCache[$dn][$attr] = $newItems;
1188 1188
 					$dnRead[] = $dn;
1189
-				} while(($state === self::LRESULT_PROCESSED_SKIP
1189
+				} while (($state === self::LRESULT_PROCESSED_SKIP
1190 1190
 						|| $this->ldap->isResource($entry))
1191 1191
 						&& ($dnReadLimit === 0 || $dnReadCount < $dnReadLimit));
1192 1192
 			}
@@ -1209,11 +1209,11 @@  discard block
 block discarded – undo
1209 1209
 	 */
1210 1210
 	private function determineFeature($objectclasses, $attr, $dbkey, $confkey, $po = false) {
1211 1211
 		$cr = $this->getConnection();
1212
-		if(!$cr) {
1212
+		if (!$cr) {
1213 1213
 			throw new \Exception('Could not connect to LDAP');
1214 1214
 		}
1215 1215
 		$p = 'objectclass=';
1216
-		foreach($objectclasses as $key => $value) {
1216
+		foreach ($objectclasses as $key => $value) {
1217 1217
 			$objectclasses[$key] = $p.$value;
1218 1218
 		}
1219 1219
 		$maxEntryObjC = '';
@@ -1225,7 +1225,7 @@  discard block
 block discarded – undo
1225 1225
 		$availableFeatures =
1226 1226
 			$this->cumulativeSearchOnAttribute($objectclasses, $attr,
1227 1227
 											   $dig, $maxEntryObjC);
1228
-		if(is_array($availableFeatures)
1228
+		if (is_array($availableFeatures)
1229 1229
 		   && count($availableFeatures) > 0) {
1230 1230
 			natcasesort($availableFeatures);
1231 1231
 			//natcasesort keeps indices, but we must get rid of them for proper
@@ -1236,7 +1236,7 @@  discard block
 block discarded – undo
1236 1236
 		}
1237 1237
 
1238 1238
 		$setFeatures = $this->configuration->$confkey;
1239
-		if(is_array($setFeatures) && !empty($setFeatures)) {
1239
+		if (is_array($setFeatures) && !empty($setFeatures)) {
1240 1240
 			//something is already configured? pre-select it.
1241 1241
 			$this->result->addChange($dbkey, $setFeatures);
1242 1242
 		} else if ($po && $maxEntryObjC !== '') {
@@ -1258,7 +1258,7 @@  discard block
 block discarded – undo
1258 1258
 	 * LRESULT_PROCESSED_INVALID or LRESULT_PROCESSED_SKIP
1259 1259
 	 */
1260 1260
 	private function getAttributeValuesFromEntry($result, $attribute, &$known) {
1261
-		if(!is_array($result)
1261
+		if (!is_array($result)
1262 1262
 		   || !isset($result['count'])
1263 1263
 		   || !$result['count'] > 0) {
1264 1264
 			return self::LRESULT_PROCESSED_INVALID;
@@ -1267,12 +1267,12 @@  discard block
 block discarded – undo
1267 1267
 		// strtolower on all keys for proper comparison
1268 1268
 		$result = \OCP\Util::mb_array_change_key_case($result);
1269 1269
 		$attribute = strtolower($attribute);
1270
-		if(isset($result[$attribute])) {
1271
-			foreach($result[$attribute] as $key => $val) {
1272
-				if($key === 'count') {
1270
+		if (isset($result[$attribute])) {
1271
+			foreach ($result[$attribute] as $key => $val) {
1272
+				if ($key === 'count') {
1273 1273
 					continue;
1274 1274
 				}
1275
-				if(!in_array($val, $known)) {
1275
+				if (!in_array($val, $known)) {
1276 1276
 					$known[] = $val;
1277 1277
 				}
1278 1278
 			}
@@ -1286,7 +1286,7 @@  discard block
 block discarded – undo
1286 1286
 	 * @return bool|mixed
1287 1287
 	 */
1288 1288
 	private function getConnection() {
1289
-		if(!is_null($this->cr)) {
1289
+		if (!is_null($this->cr)) {
1290 1290
 			return $this->cr;
1291 1291
 		}
1292 1292
 
@@ -1298,14 +1298,14 @@  discard block
 block discarded – undo
1298 1298
 		$this->ldap->setOption($cr, LDAP_OPT_PROTOCOL_VERSION, 3);
1299 1299
 		$this->ldap->setOption($cr, LDAP_OPT_REFERRALS, 0);
1300 1300
 		$this->ldap->setOption($cr, LDAP_OPT_NETWORK_TIMEOUT, self::LDAP_NW_TIMEOUT);
1301
-		if($this->configuration->ldapTLS === 1) {
1301
+		if ($this->configuration->ldapTLS === 1) {
1302 1302
 			$this->ldap->startTls($cr);
1303 1303
 		}
1304 1304
 
1305 1305
 		$lo = @$this->ldap->bind($cr,
1306 1306
 								 $this->configuration->ldapAgentName,
1307 1307
 								 $this->configuration->ldapAgentPassword);
1308
-		if($lo === true) {
1308
+		if ($lo === true) {
1309 1309
 			$this->$cr = $cr;
1310 1310
 			return $cr;
1311 1311
 		}
@@ -1336,18 +1336,18 @@  discard block
 block discarded – undo
1336 1336
 		//636 ← LDAPS / SSL
1337 1337
 		//7xxx ← UCS. need to be checked first, because both ports may be open
1338 1338
 		$host = $this->configuration->ldapHost;
1339
-		$port = (int)$this->configuration->ldapPort;
1339
+		$port = (int) $this->configuration->ldapPort;
1340 1340
 		$portSettings = [];
1341 1341
 
1342 1342
 		//In case the port is already provided, we will check this first
1343
-		if($port > 0) {
1343
+		if ($port > 0) {
1344 1344
 			$hostInfo = parse_url($host);
1345
-			if(!(is_array($hostInfo)
1345
+			if (!(is_array($hostInfo)
1346 1346
 				&& isset($hostInfo['scheme'])
1347 1347
 				&& stripos($hostInfo['scheme'], 'ldaps') !== false)) {
1348 1348
 				$portSettings[] = ['port' => $port, 'tls' => true];
1349 1349
 			}
1350
-			$portSettings[] =['port' => $port, 'tls' => false];
1350
+			$portSettings[] = ['port' => $port, 'tls' => false];
1351 1351
 		}
1352 1352
 
1353 1353
 		//default ports
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
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 	 * @return AbstractMapping
134 134
 	 */
135 135
 	public function getUserMapper() {
136
-		if(is_null($this->userMapper)) {
136
+		if (is_null($this->userMapper)) {
137 137
 			throw new \Exception('UserMapper was not assigned to this Access instance.');
138 138
 		}
139 139
 		return $this->userMapper;
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 	 * @return AbstractMapping
154 154
 	 */
155 155
 	public function getGroupMapper() {
156
-		if(is_null($this->groupMapper)) {
156
+		if (is_null($this->groupMapper)) {
157 157
 			throw new \Exception('GroupMapper was not assigned to this Access instance.');
158 158
 		}
159 159
 		return $this->groupMapper;
@@ -186,14 +186,14 @@  discard block
 block discarded – undo
186 186
 	 * @throws ServerNotAvailableException
187 187
 	 */
188 188
 	public function readAttribute($dn, $attr, $filter = 'objectClass=*') {
189
-		if(!$this->checkConnection()) {
189
+		if (!$this->checkConnection()) {
190 190
 			\OCP\Util::writeLog('user_ldap',
191 191
 				'No LDAP Connector assigned, access impossible for readAttribute.',
192 192
 				ILogger::WARN);
193 193
 			return false;
194 194
 		}
195 195
 		$cr = $this->connection->getConnectionResource();
196
-		if(!$this->ldap->isResource($cr)) {
196
+		if (!$this->ldap->isResource($cr)) {
197 197
 			//LDAP not available
198 198
 			\OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', ILogger::DEBUG);
199 199
 			return false;
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 		$this->abandonPagedSearch();
204 204
 		// openLDAP requires that we init a new Paged Search. Not needed by AD,
205 205
 		// but does not hurt either.
206
-		$pagingSize = (int)$this->connection->ldapPagingSize;
206
+		$pagingSize = (int) $this->connection->ldapPagingSize;
207 207
 		// 0 won't result in replies, small numbers may leave out groups
208 208
 		// (cf. #12306), 500 is default for paging and should work everywhere.
209 209
 		$maxResults = $pagingSize > 20 ? $pagingSize : 500;
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 		$isRangeRequest = false;
217 217
 		do {
218 218
 			$result = $this->executeRead($cr, $dn, $attrToRead, $filter, $maxResults);
219
-			if(is_bool($result)) {
219
+			if (is_bool($result)) {
220 220
 				// when an exists request was run and it was successful, an empty
221 221
 				// array must be returned
222 222
 				return $result ? [] : false;
@@ -233,22 +233,22 @@  discard block
 block discarded – undo
233 233
 			$result = $this->extractRangeData($result, $attr);
234 234
 			if (!empty($result)) {
235 235
 				$normalizedResult = $this->extractAttributeValuesFromResult(
236
-					[ $attr => $result['values'] ],
236
+					[$attr => $result['values']],
237 237
 					$attr
238 238
 				);
239 239
 				$values = array_merge($values, $normalizedResult);
240 240
 
241
-				if($result['rangeHigh'] === '*') {
241
+				if ($result['rangeHigh'] === '*') {
242 242
 					// when server replies with * as high range value, there are
243 243
 					// no more results left
244 244
 					return $values;
245 245
 				} else {
246
-					$low  = $result['rangeHigh'] + 1;
247
-					$attrToRead = $result['attributeName'] . ';range=' . $low . '-*';
246
+					$low = $result['rangeHigh'] + 1;
247
+					$attrToRead = $result['attributeName'].';range='.$low.'-*';
248 248
 					$isRangeRequest = true;
249 249
 				}
250 250
 			}
251
-		} while($isRangeRequest);
251
+		} while ($isRangeRequest);
252 252
 
253 253
 		\OCP\Util::writeLog('user_ldap', 'Requested attribute '.$attr.' not found for '.$dn, ILogger::DEBUG);
254 254
 		return false;
@@ -274,13 +274,13 @@  discard block
 block discarded – undo
274 274
 		if (!$this->ldap->isResource($rr)) {
275 275
 			if ($attribute !== '') {
276 276
 				//do not throw this message on userExists check, irritates
277
-				\OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN ' . $dn, ILogger::DEBUG);
277
+				\OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN '.$dn, ILogger::DEBUG);
278 278
 			}
279 279
 			//in case an error occurs , e.g. object does not exist
280 280
 			return false;
281 281
 		}
282 282
 		if ($attribute === '' && ($filter === 'objectclass=*' || $this->invokeLDAPMethod('countEntries', $cr, $rr) === 1)) {
283
-			\OCP\Util::writeLog('user_ldap', 'readAttribute: ' . $dn . ' found', ILogger::DEBUG);
283
+			\OCP\Util::writeLog('user_ldap', 'readAttribute: '.$dn.' found', ILogger::DEBUG);
284 284
 			return true;
285 285
 		}
286 286
 		$er = $this->invokeLDAPMethod('firstEntry', $cr, $rr);
@@ -305,12 +305,12 @@  discard block
 block discarded – undo
305 305
 	 */
306 306
 	public function extractAttributeValuesFromResult($result, $attribute) {
307 307
 		$values = [];
308
-		if(isset($result[$attribute]) && $result[$attribute]['count'] > 0) {
308
+		if (isset($result[$attribute]) && $result[$attribute]['count'] > 0) {
309 309
 			$lowercaseAttribute = strtolower($attribute);
310
-			for($i=0;$i<$result[$attribute]['count'];$i++) {
311
-				if($this->resemblesDN($attribute)) {
310
+			for ($i = 0; $i < $result[$attribute]['count']; $i++) {
311
+				if ($this->resemblesDN($attribute)) {
312 312
 					$values[] = $this->helper->sanitizeDN($result[$attribute][$i]);
313
-				} elseif($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') {
313
+				} elseif ($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') {
314 314
 					$values[] = $this->convertObjectGUID2Str($result[$attribute][$i]);
315 315
 				} else {
316 316
 					$values[] = $result[$attribute][$i];
@@ -332,10 +332,10 @@  discard block
 block discarded – undo
332 332
 	 */
333 333
 	public function extractRangeData($result, $attribute) {
334 334
 		$keys = array_keys($result);
335
-		foreach($keys as $key) {
336
-			if($key !== $attribute && strpos($key, $attribute) === 0) {
335
+		foreach ($keys as $key) {
336
+			if ($key !== $attribute && strpos($key, $attribute) === 0) {
337 337
 				$queryData = explode(';', $key);
338
-				if(strpos($queryData[1], 'range=') === 0) {
338
+				if (strpos($queryData[1], 'range=') === 0) {
339 339
 					$high = substr($queryData[1], 1 + strpos($queryData[1], '-'));
340 340
 					$data = [
341 341
 						'values' => $result[$key],
@@ -360,11 +360,11 @@  discard block
 block discarded – undo
360 360
 	 * @throws \Exception
361 361
 	 */
362 362
 	public function setPassword($userDN, $password) {
363
-		if((int)$this->connection->turnOnPasswordChange !== 1) {
363
+		if ((int) $this->connection->turnOnPasswordChange !== 1) {
364 364
 			throw new \Exception('LDAP password changes are disabled.');
365 365
 		}
366 366
 		$cr = $this->connection->getConnectionResource();
367
-		if(!$this->ldap->isResource($cr)) {
367
+		if (!$this->ldap->isResource($cr)) {
368 368
 			//LDAP not available
369 369
 			\OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', ILogger::DEBUG);
370 370
 			return false;
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
 			// try PASSWD extended operation first
374 374
 			return @$this->invokeLDAPMethod('exopPasswd', $cr, $userDN, '', $password) ||
375 375
 						@$this->invokeLDAPMethod('modReplace', $cr, $userDN, $password);
376
-		} catch(ConstraintViolationException $e) {
376
+		} catch (ConstraintViolationException $e) {
377 377
 			throw new HintException('Password change rejected.', \OC::$server->getL10N('user_ldap')->t('Password change rejected. Hint: ').$e->getMessage(), $e->getCode());
378 378
 		}
379 379
 	}
@@ -415,17 +415,17 @@  discard block
 block discarded – undo
415 415
 	 */
416 416
 	public function getDomainDNFromDN($dn) {
417 417
 		$allParts = $this->ldap->explodeDN($dn, 0);
418
-		if($allParts === false) {
418
+		if ($allParts === false) {
419 419
 			//not a valid DN
420 420
 			return '';
421 421
 		}
422 422
 		$domainParts = [];
423 423
 		$dcFound = false;
424
-		foreach($allParts as $part) {
425
-			if(!$dcFound && strpos($part, 'dc=') === 0) {
424
+		foreach ($allParts as $part) {
425
+			if (!$dcFound && strpos($part, 'dc=') === 0) {
426 426
 				$dcFound = true;
427 427
 			}
428
-			if($dcFound) {
428
+			if ($dcFound) {
429 429
 				$domainParts[] = $part;
430 430
 			}
431 431
 		}
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
 
452 452
 		//Check whether the DN belongs to the Base, to avoid issues on multi-
453 453
 		//server setups
454
-		if(is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
454
+		if (is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
455 455
 			return $fdn;
456 456
 		}
457 457
 
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
 		//To avoid bypassing the base DN settings under certain circumstances
471 471
 		//with the group support, check whether the provided DN matches one of
472 472
 		//the given Bases
473
-		if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) {
473
+		if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) {
474 474
 			return false;
475 475
 		}
476 476
 
@@ -488,11 +488,11 @@  discard block
 block discarded – undo
488 488
 	 */
489 489
 	public function groupsMatchFilter($groupDNs) {
490 490
 		$validGroupDNs = [];
491
-		foreach($groupDNs as $dn) {
491
+		foreach ($groupDNs as $dn) {
492 492
 			$cacheKey = 'groupsMatchFilter-'.$dn;
493 493
 			$groupMatchFilter = $this->connection->getFromCache($cacheKey);
494
-			if(!is_null($groupMatchFilter)) {
495
-				if($groupMatchFilter) {
494
+			if (!is_null($groupMatchFilter)) {
495
+				if ($groupMatchFilter) {
496 496
 					$validGroupDNs[] = $dn;
497 497
 				}
498 498
 				continue;
@@ -500,13 +500,13 @@  discard block
 block discarded – undo
500 500
 
501 501
 			// Check the base DN first. If this is not met already, we don't
502 502
 			// need to ask the server at all.
503
-			if(!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) {
503
+			if (!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) {
504 504
 				$this->connection->writeToCache($cacheKey, false);
505 505
 				continue;
506 506
 			}
507 507
 
508 508
 			$result = $this->readAttribute($dn, '', $this->connection->ldapGroupFilter);
509
-			if(is_array($result)) {
509
+			if (is_array($result)) {
510 510
 				$this->connection->writeToCache($cacheKey, true);
511 511
 				$validGroupDNs[] = $dn;
512 512
 			} else {
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
 		//To avoid bypassing the base DN settings under certain circumstances
530 530
 		//with the group support, check whether the provided DN matches one of
531 531
 		//the given Bases
532
-		if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
532
+		if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
533 533
 			return false;
534 534
 		}
535 535
 
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
 	 */
550 550
 	public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped = null, array $record = null) {
551 551
 		$newlyMapped = false;
552
-		if($isUser) {
552
+		if ($isUser) {
553 553
 			$mapper = $this->getUserMapper();
554 554
 			$nameAttribute = $this->connection->ldapUserDisplayName;
555 555
 			$filter = $this->connection->ldapUserFilter;
@@ -561,15 +561,15 @@  discard block
 block discarded – undo
561 561
 
562 562
 		//let's try to retrieve the Nextcloud name from the mappings table
563 563
 		$ncName = $mapper->getNameByDN($fdn);
564
-		if(is_string($ncName)) {
564
+		if (is_string($ncName)) {
565 565
 			return $ncName;
566 566
 		}
567 567
 
568 568
 		//second try: get the UUID and check if it is known. Then, update the DN and return the name.
569 569
 		$uuid = $this->getUUID($fdn, $isUser, $record);
570
-		if(is_string($uuid)) {
570
+		if (is_string($uuid)) {
571 571
 			$ncName = $mapper->getNameByUUID($uuid);
572
-			if(is_string($ncName)) {
572
+			if (is_string($ncName)) {
573 573
 				$mapper->setDNbyUUID($fdn, $uuid);
574 574
 				return $ncName;
575 575
 			}
@@ -579,17 +579,17 @@  discard block
 block discarded – undo
579 579
 			return false;
580 580
 		}
581 581
 
582
-		if(is_null($ldapName)) {
582
+		if (is_null($ldapName)) {
583 583
 			$ldapName = $this->readAttribute($fdn, $nameAttribute, $filter);
584
-			if(!isset($ldapName[0]) && empty($ldapName[0])) {
584
+			if (!isset($ldapName[0]) && empty($ldapName[0])) {
585 585
 				\OCP\Util::writeLog('user_ldap', 'No or empty name for '.$fdn.' with filter '.$filter.'.', ILogger::INFO);
586 586
 				return false;
587 587
 			}
588 588
 			$ldapName = $ldapName[0];
589 589
 		}
590 590
 
591
-		if($isUser) {
592
-			$usernameAttribute = (string)$this->connection->ldapExpertUsernameAttr;
591
+		if ($isUser) {
592
+			$usernameAttribute = (string) $this->connection->ldapExpertUsernameAttr;
593 593
 			if ($usernameAttribute !== '') {
594 594
 				$username = $this->readAttribute($fdn, $usernameAttribute);
595 595
 				$username = $username[0];
@@ -619,14 +619,14 @@  discard block
 block discarded – undo
619 619
 		// outside of core user management will still cache the user as non-existing.
620 620
 		$originalTTL = $this->connection->ldapCacheTTL;
621 621
 		$this->connection->setConfiguration(['ldapCacheTTL' => 0]);
622
-		if( $intName !== ''
622
+		if ($intName !== ''
623 623
 			&& (($isUser && !$this->ncUserManager->userExists($intName))
624 624
 				|| (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))
625 625
 			)
626 626
 		) {
627 627
 			$this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
628 628
 			$newlyMapped = $this->mapAndAnnounceIfApplicable($mapper, $fdn, $intName, $uuid, $isUser);
629
-			if($newlyMapped) {
629
+			if ($newlyMapped) {
630 630
 				return $intName;
631 631
 			}
632 632
 		}
@@ -634,7 +634,7 @@  discard block
 block discarded – undo
634 634
 		$this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
635 635
 		$altName = $this->createAltInternalOwnCloudName($intName, $isUser);
636 636
 		if (is_string($altName)) {
637
-			if($this->mapAndAnnounceIfApplicable($mapper, $fdn, $altName, $uuid, $isUser)) {
637
+			if ($this->mapAndAnnounceIfApplicable($mapper, $fdn, $altName, $uuid, $isUser)) {
638 638
 				$newlyMapped = true;
639 639
 				return $altName;
640 640
 			}
@@ -652,7 +652,7 @@  discard block
 block discarded – undo
652 652
 		string $uuid,
653 653
 		bool $isUser
654 654
 	) :bool {
655
-		if($mapper->map($fdn, $name, $uuid)) {
655
+		if ($mapper->map($fdn, $name, $uuid)) {
656 656
 			if ($this->ncUserManager instanceof PublicEmitter && $isUser) {
657 657
 				$this->cacheUserExists($name);
658 658
 				$this->ncUserManager->emit('\OC\User', 'assignedUserId', [$name]);
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
 	 * @throws \Exception
698 698
 	 */
699 699
 	private function ldap2NextcloudNames($ldapObjects, $isUsers) {
700
-		if($isUsers) {
700
+		if ($isUsers) {
701 701
 			$nameAttribute = $this->connection->ldapUserDisplayName;
702 702
 			$sndAttribute  = $this->connection->ldapUserDisplayName2;
703 703
 		} else {
@@ -705,9 +705,9 @@  discard block
 block discarded – undo
705 705
 		}
706 706
 		$nextcloudNames = [];
707 707
 
708
-		foreach($ldapObjects as $ldapObject) {
708
+		foreach ($ldapObjects as $ldapObject) {
709 709
 			$nameByLDAP = null;
710
-			if(    isset($ldapObject[$nameAttribute])
710
+			if (isset($ldapObject[$nameAttribute])
711 711
 				&& is_array($ldapObject[$nameAttribute])
712 712
 				&& isset($ldapObject[$nameAttribute][0])
713 713
 			) {
@@ -716,19 +716,19 @@  discard block
 block discarded – undo
716 716
 			}
717 717
 
718 718
 			$ncName = $this->dn2ocname($ldapObject['dn'][0], $nameByLDAP, $isUsers);
719
-			if($ncName) {
719
+			if ($ncName) {
720 720
 				$nextcloudNames[] = $ncName;
721
-				if($isUsers) {
721
+				if ($isUsers) {
722 722
 					$this->updateUserState($ncName);
723 723
 					//cache the user names so it does not need to be retrieved
724 724
 					//again later (e.g. sharing dialogue).
725
-					if(is_null($nameByLDAP)) {
725
+					if (is_null($nameByLDAP)) {
726 726
 						continue;
727 727
 					}
728 728
 					$sndName = isset($ldapObject[$sndAttribute][0])
729 729
 						? $ldapObject[$sndAttribute][0] : '';
730 730
 					$this->cacheUserDisplayName($ncName, $nameByLDAP, $sndName);
731
-				} else if($nameByLDAP !== null) {
731
+				} else if ($nameByLDAP !== null) {
732 732
 					$this->cacheGroupDisplayName($ncName, $nameByLDAP);
733 733
 				}
734 734
 			}
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
 	 */
745 745
 	public function updateUserState($ncname) {
746 746
 		$user = $this->userManager->get($ncname);
747
-		if($user instanceof OfflineUser) {
747
+		if ($user instanceof OfflineUser) {
748 748
 			$user->unmark();
749 749
 		}
750 750
 	}
@@ -784,7 +784,7 @@  discard block
 block discarded – undo
784 784
 	 */
785 785
 	public function cacheUserDisplayName($ocName, $displayName, $displayName2 = '') {
786 786
 		$user = $this->userManager->get($ocName);
787
-		if($user === null) {
787
+		if ($user === null) {
788 788
 			return;
789 789
 		}
790 790
 		$displayName = $user->composeAndStoreDisplayName($displayName, $displayName2);
@@ -793,7 +793,7 @@  discard block
 block discarded – undo
793 793
 	}
794 794
 
795 795
 	public function cacheGroupDisplayName(string $ncName, string $displayName): void {
796
-		$cacheKey = 'group_getDisplayName' . $ncName;
796
+		$cacheKey = 'group_getDisplayName'.$ncName;
797 797
 		$this->connection->writeToCache($cacheKey, $displayName);
798 798
 	}
799 799
 
@@ -809,9 +809,9 @@  discard block
 block discarded – undo
809 809
 		$attempts = 0;
810 810
 		//while loop is just a precaution. If a name is not generated within
811 811
 		//20 attempts, something else is very wrong. Avoids infinite loop.
812
-		while($attempts < 20){
813
-			$altName = $name . '_' . rand(1000,9999);
814
-			if(!$this->ncUserManager->userExists($altName)) {
812
+		while ($attempts < 20) {
813
+			$altName = $name.'_'.rand(1000, 9999);
814
+			if (!$this->ncUserManager->userExists($altName)) {
815 815
 				return $altName;
816 816
 			}
817 817
 			$attempts++;
@@ -833,25 +833,25 @@  discard block
 block discarded – undo
833 833
 	 */
834 834
 	private function _createAltInternalOwnCloudNameForGroups($name) {
835 835
 		$usedNames = $this->groupMapper->getNamesBySearch($name, "", '_%');
836
-		if(!$usedNames || count($usedNames) === 0) {
836
+		if (!$usedNames || count($usedNames) === 0) {
837 837
 			$lastNo = 1; //will become name_2
838 838
 		} else {
839 839
 			natsort($usedNames);
840 840
 			$lastName = array_pop($usedNames);
841
-			$lastNo = (int)substr($lastName, strrpos($lastName, '_') + 1);
841
+			$lastNo = (int) substr($lastName, strrpos($lastName, '_') + 1);
842 842
 		}
843
-		$altName = $name.'_'. (string)($lastNo+1);
843
+		$altName = $name.'_'.(string) ($lastNo + 1);
844 844
 		unset($usedNames);
845 845
 
846 846
 		$attempts = 1;
847
-		while($attempts < 21){
847
+		while ($attempts < 21) {
848 848
 			// Check to be really sure it is unique
849 849
 			// while loop is just a precaution. If a name is not generated within
850 850
 			// 20 attempts, something else is very wrong. Avoids infinite loop.
851
-			if(!\OC::$server->getGroupManager()->groupExists($altName)) {
851
+			if (!\OC::$server->getGroupManager()->groupExists($altName)) {
852 852
 				return $altName;
853 853
 			}
854
-			$altName = $name . '_' . ($lastNo + $attempts);
854
+			$altName = $name.'_'.($lastNo + $attempts);
855 855
 			$attempts++;
856 856
 		}
857 857
 		return false;
@@ -866,7 +866,7 @@  discard block
 block discarded – undo
866 866
 	private function createAltInternalOwnCloudName($name, $isUser) {
867 867
 		$originalTTL = $this->connection->ldapCacheTTL;
868 868
 		$this->connection->setConfiguration(['ldapCacheTTL' => 0]);
869
-		if($isUser) {
869
+		if ($isUser) {
870 870
 			$altName = $this->_createAltInternalOwnCloudNameForUsers($name);
871 871
 		} else {
872 872
 			$altName = $this->_createAltInternalOwnCloudNameForGroups($name);
@@ -915,13 +915,13 @@  discard block
 block discarded – undo
915 915
 	public function fetchListOfUsers($filter, $attr, $limit = null, $offset = null, $forceApplyAttributes = false) {
916 916
 		$ldapRecords = $this->searchUsers($filter, $attr, $limit, $offset);
917 917
 		$recordsToUpdate = $ldapRecords;
918
-		if(!$forceApplyAttributes) {
918
+		if (!$forceApplyAttributes) {
919 919
 			$isBackgroundJobModeAjax = $this->config
920 920
 					->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax';
921 921
 			$recordsToUpdate = array_filter($ldapRecords, function($record) use ($isBackgroundJobModeAjax) {
922 922
 				$newlyMapped = false;
923 923
 				$uid = $this->dn2ocname($record['dn'][0], null, true, $newlyMapped, $record);
924
-				if(is_string($uid)) {
924
+				if (is_string($uid)) {
925 925
 					$this->cacheUserExists($uid);
926 926
 				}
927 927
 				return ($uid !== false) && ($newlyMapped || $isBackgroundJobModeAjax);
@@ -939,15 +939,15 @@  discard block
 block discarded – undo
939 939
 	 * @param array $ldapRecords
940 940
 	 * @throws \Exception
941 941
 	 */
942
-	public function batchApplyUserAttributes(array $ldapRecords){
942
+	public function batchApplyUserAttributes(array $ldapRecords) {
943 943
 		$displayNameAttribute = strtolower($this->connection->ldapUserDisplayName);
944
-		foreach($ldapRecords as $userRecord) {
945
-			if(!isset($userRecord[$displayNameAttribute])) {
944
+		foreach ($ldapRecords as $userRecord) {
945
+			if (!isset($userRecord[$displayNameAttribute])) {
946 946
 				// displayName is obligatory
947 947
 				continue;
948 948
 			}
949
-			$ocName  = $this->dn2ocname($userRecord['dn'][0], null, true);
950
-			if($ocName === false) {
949
+			$ocName = $this->dn2ocname($userRecord['dn'][0], null, true);
950
+			if ($ocName === false) {
951 951
 				continue;
952 952
 			}
953 953
 			$this->updateUserState($ocName);
@@ -975,7 +975,7 @@  discard block
 block discarded – undo
975 975
 		array_walk($groupRecords, function($record) {
976 976
 			$newlyMapped = false;
977 977
 			$gid = $this->dn2ocname($record['dn'][0], null, false, $newlyMapped, $record);
978
-			if(!$newlyMapped && is_string($gid)) {
978
+			if (!$newlyMapped && is_string($gid)) {
979 979
 				$this->cacheGroupExists($gid);
980 980
 			}
981 981
 		});
@@ -988,8 +988,8 @@  discard block
 block discarded – undo
988 988
 	 * @return array
989 989
 	 */
990 990
 	private function fetchList($list, $manyAttributes) {
991
-		if(is_array($list)) {
992
-			if($manyAttributes) {
991
+		if (is_array($list)) {
992
+			if ($manyAttributes) {
993 993
 				return $list;
994 994
 			} else {
995 995
 				$list = array_reduce($list, function($carry, $item) {
@@ -1019,7 +1019,7 @@  discard block
 block discarded – undo
1019 1019
 	 */
1020 1020
 	public function searchUsers($filter, $attr = null, $limit = null, $offset = null) {
1021 1021
 		$result = [];
1022
-		foreach($this->connection->ldapBaseUsers as $base) {
1022
+		foreach ($this->connection->ldapBaseUsers as $base) {
1023 1023
 			$result = array_merge($result, $this->search($filter, [$base], $attr, $limit, $offset));
1024 1024
 		}
1025 1025
 		return $result;
@@ -1035,9 +1035,9 @@  discard block
 block discarded – undo
1035 1035
 	 */
1036 1036
 	public function countUsers($filter, $attr = ['dn'], $limit = null, $offset = null) {
1037 1037
 		$result = false;
1038
-		foreach($this->connection->ldapBaseUsers as $base) {
1038
+		foreach ($this->connection->ldapBaseUsers as $base) {
1039 1039
 			$count = $this->count($filter, [$base], $attr, $limit, $offset);
1040
-			$result = is_int($count) ? (int)$result + $count : $result;
1040
+			$result = is_int($count) ? (int) $result + $count : $result;
1041 1041
 		}
1042 1042
 		return $result;
1043 1043
 	}
@@ -1056,7 +1056,7 @@  discard block
 block discarded – undo
1056 1056
 	 */
1057 1057
 	public function searchGroups($filter, $attr = null, $limit = null, $offset = null) {
1058 1058
 		$result = [];
1059
-		foreach($this->connection->ldapBaseGroups as $base) {
1059
+		foreach ($this->connection->ldapBaseGroups as $base) {
1060 1060
 			$result = array_merge($result, $this->search($filter, [$base], $attr, $limit, $offset));
1061 1061
 		}
1062 1062
 		return $result;
@@ -1074,9 +1074,9 @@  discard block
 block discarded – undo
1074 1074
 	 */
1075 1075
 	public function countGroups($filter, $attr = ['dn'], $limit = null, $offset = null) {
1076 1076
 		$result = false;
1077
-		foreach($this->connection->ldapBaseGroups as $base) {
1077
+		foreach ($this->connection->ldapBaseGroups as $base) {
1078 1078
 			$count = $this->count($filter, [$base], $attr, $limit, $offset);
1079
-			$result = is_int($count) ? (int)$result + $count : $result;
1079
+			$result = is_int($count) ? (int) $result + $count : $result;
1080 1080
 		}
1081 1081
 		return $result;
1082 1082
 	}
@@ -1091,9 +1091,9 @@  discard block
 block discarded – undo
1091 1091
 	 */
1092 1092
 	public function countObjects($limit = null, $offset = null) {
1093 1093
 		$result = false;
1094
-		foreach($this->connection->ldapBase as $base) {
1094
+		foreach ($this->connection->ldapBase as $base) {
1095 1095
 			$count = $this->count('objectclass=*', [$base], ['dn'], $limit, $offset);
1096
-			$result = is_int($count) ? (int)$result + $count : $result;
1096
+			$result = is_int($count) ? (int) $result + $count : $result;
1097 1097
 		}
1098 1098
 		return $result;
1099 1099
 	}
@@ -1118,7 +1118,7 @@  discard block
 block discarded – undo
1118 1118
 		// php no longer supports call-time pass-by-reference
1119 1119
 		// thus cannot support controlPagedResultResponse as the third argument
1120 1120
 		// is a reference
1121
-		$doMethod = function () use ($command, &$arguments) {
1121
+		$doMethod = function() use ($command, &$arguments) {
1122 1122
 			if ($command == 'controlPagedResultResponse') {
1123 1123
 				throw new \InvalidArgumentException('Invoker does not support controlPagedResultResponse, call LDAP Wrapper directly instead.');
1124 1124
 			} else {
@@ -1136,7 +1136,7 @@  discard block
 block discarded – undo
1136 1136
 			$this->connection->resetConnectionResource();
1137 1137
 			$cr = $this->connection->getConnectionResource();
1138 1138
 
1139
-			if(!$this->ldap->isResource($cr)) {
1139
+			if (!$this->ldap->isResource($cr)) {
1140 1140
 				// Seems like we didn't find any resource.
1141 1141
 				\OCP\Util::writeLog('user_ldap', "Could not $command, because resource is missing.", ILogger::DEBUG);
1142 1142
 				throw $e;
@@ -1161,13 +1161,13 @@  discard block
 block discarded – undo
1161 1161
 	 * @throws ServerNotAvailableException
1162 1162
 	 */
1163 1163
 	private function executeSearch($filter, $base, &$attr = null, $limit = null, $offset = null) {
1164
-		if(!is_null($attr) && !is_array($attr)) {
1164
+		if (!is_null($attr) && !is_array($attr)) {
1165 1165
 			$attr = [mb_strtolower($attr, 'UTF-8')];
1166 1166
 		}
1167 1167
 
1168 1168
 		// See if we have a resource, in case not cancel with message
1169 1169
 		$cr = $this->connection->getConnectionResource();
1170
-		if(!$this->ldap->isResource($cr)) {
1170
+		if (!$this->ldap->isResource($cr)) {
1171 1171
 			// Seems like we didn't find any resource.
1172 1172
 			// Return an empty array just like before.
1173 1173
 			\OCP\Util::writeLog('user_ldap', 'Could not search, because resource is missing.', ILogger::DEBUG);
@@ -1175,13 +1175,13 @@  discard block
 block discarded – undo
1175 1175
 		}
1176 1176
 
1177 1177
 		//check whether paged search should be attempted
1178
-		$pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int)$limit, $offset);
1178
+		$pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int) $limit, $offset);
1179 1179
 
1180 1180
 		$linkResources = array_pad([], count($base), $cr);
1181 1181
 		$sr = $this->invokeLDAPMethod('search', $linkResources, $base, $filter, $attr);
1182 1182
 		// cannot use $cr anymore, might have changed in the previous call!
1183 1183
 		$error = $this->ldap->errno($this->connection->getConnectionResource());
1184
-		if(!is_array($sr) || $error !== 0) {
1184
+		if (!is_array($sr) || $error !== 0) {
1185 1185
 			\OCP\Util::writeLog('user_ldap', 'Attempt for Paging?  '.print_r($pagedSearchOK, true), ILogger::ERROR);
1186 1186
 			return false;
1187 1187
 		}
@@ -1206,29 +1206,29 @@  discard block
 block discarded – undo
1206 1206
 	 */
1207 1207
 	private function processPagedSearchStatus($sr, $filter, $base, $iFoundItems, $limit, $offset, $pagedSearchOK, $skipHandling) {
1208 1208
 		$cookie = null;
1209
-		if($pagedSearchOK) {
1209
+		if ($pagedSearchOK) {
1210 1210
 			$cr = $this->connection->getConnectionResource();
1211
-			foreach($sr as $key => $res) {
1212
-				if($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) {
1211
+			foreach ($sr as $key => $res) {
1212
+				if ($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) {
1213 1213
 					$this->setPagedResultCookie($base[$key], $filter, $limit, $offset, $cookie);
1214 1214
 				}
1215 1215
 			}
1216 1216
 
1217 1217
 			//browsing through prior pages to get the cookie for the new one
1218
-			if($skipHandling) {
1218
+			if ($skipHandling) {
1219 1219
 				return false;
1220 1220
 			}
1221 1221
 			// if count is bigger, then the server does not support
1222 1222
 			// paged search. Instead, he did a normal search. We set a
1223 1223
 			// flag here, so the callee knows how to deal with it.
1224
-			if($iFoundItems <= $limit) {
1224
+			if ($iFoundItems <= $limit) {
1225 1225
 				$this->pagedSearchedSuccessful = true;
1226 1226
 			}
1227 1227
 		} else {
1228
-			if(!is_null($limit) && (int)$this->connection->ldapPagingSize !== 0) {
1228
+			if (!is_null($limit) && (int) $this->connection->ldapPagingSize !== 0) {
1229 1229
 				\OC::$server->getLogger()->debug(
1230 1230
 					'Paged search was not available',
1231
-					[ 'app' => 'user_ldap' ]
1231
+					['app' => 'user_ldap']
1232 1232
 				);
1233 1233
 			}
1234 1234
 		}
@@ -1257,8 +1257,8 @@  discard block
 block discarded – undo
1257 1257
 	private function count($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) {
1258 1258
 		\OCP\Util::writeLog('user_ldap', 'Count filter:  '.print_r($filter, true), ILogger::DEBUG);
1259 1259
 
1260
-		$limitPerPage = (int)$this->connection->ldapPagingSize;
1261
-		if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1260
+		$limitPerPage = (int) $this->connection->ldapPagingSize;
1261
+		if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1262 1262
 			$limitPerPage = $limit;
1263 1263
 		}
1264 1264
 
@@ -1268,7 +1268,7 @@  discard block
 block discarded – undo
1268 1268
 
1269 1269
 		do {
1270 1270
 			$search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset);
1271
-			if($search === false) {
1271
+			if ($search === false) {
1272 1272
 				return $counter > 0 ? $counter : false;
1273 1273
 			}
1274 1274
 			list($sr, $pagedSearchOK) = $search;
@@ -1287,7 +1287,7 @@  discard block
 block discarded – undo
1287 1287
 			 * Continue now depends on $hasMorePages value
1288 1288
 			 */
1289 1289
 			$continue = $pagedSearchOK && $hasMorePages;
1290
-		} while($continue && (is_null($limit) || $limit <= 0 || $limit > $counter));
1290
+		} while ($continue && (is_null($limit) || $limit <= 0 || $limit > $counter));
1291 1291
 
1292 1292
 		return $counter;
1293 1293
 	}
@@ -1300,8 +1300,8 @@  discard block
 block discarded – undo
1300 1300
 	private function countEntriesInSearchResults($searchResults) {
1301 1301
 		$counter = 0;
1302 1302
 
1303
-		foreach($searchResults as $res) {
1304
-			$count = (int)$this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res);
1303
+		foreach ($searchResults as $res) {
1304
+			$count = (int) $this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res);
1305 1305
 			$counter += $count;
1306 1306
 		}
1307 1307
 
@@ -1321,8 +1321,8 @@  discard block
 block discarded – undo
1321 1321
 	 * @throws ServerNotAvailableException
1322 1322
 	 */
1323 1323
 	public function search($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) {
1324
-		$limitPerPage = (int)$this->connection->ldapPagingSize;
1325
-		if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1324
+		$limitPerPage = (int) $this->connection->ldapPagingSize;
1325
+		if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1326 1326
 			$limitPerPage = $limit;
1327 1327
 		}
1328 1328
 
@@ -1336,13 +1336,13 @@  discard block
 block discarded – undo
1336 1336
 		$savedoffset = $offset;
1337 1337
 		do {
1338 1338
 			$search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset);
1339
-			if($search === false) {
1339
+			if ($search === false) {
1340 1340
 				return [];
1341 1341
 			}
1342 1342
 			list($sr, $pagedSearchOK) = $search;
1343 1343
 			$cr = $this->connection->getConnectionResource();
1344 1344
 
1345
-			if($skipHandling) {
1345
+			if ($skipHandling) {
1346 1346
 				//i.e. result do not need to be fetched, we just need the cookie
1347 1347
 				//thus pass 1 or any other value as $iFoundItems because it is not
1348 1348
 				//used
@@ -1353,7 +1353,7 @@  discard block
 block discarded – undo
1353 1353
 			}
1354 1354
 
1355 1355
 			$iFoundItems = 0;
1356
-			foreach($sr as $res) {
1356
+			foreach ($sr as $res) {
1357 1357
 				$findings = array_merge($findings, $this->invokeLDAPMethod('getEntries', $cr, $res));
1358 1358
 				$iFoundItems = max($iFoundItems, $findings['count']);
1359 1359
 				unset($findings['count']);
@@ -1369,27 +1369,27 @@  discard block
 block discarded – undo
1369 1369
 
1370 1370
 		// if we're here, probably no connection resource is returned.
1371 1371
 		// to make Nextcloud behave nicely, we simply give back an empty array.
1372
-		if(is_null($findings)) {
1372
+		if (is_null($findings)) {
1373 1373
 			return [];
1374 1374
 		}
1375 1375
 
1376
-		if(!is_null($attr)) {
1376
+		if (!is_null($attr)) {
1377 1377
 			$selection = [];
1378 1378
 			$i = 0;
1379
-			foreach($findings as $item) {
1380
-				if(!is_array($item)) {
1379
+			foreach ($findings as $item) {
1380
+				if (!is_array($item)) {
1381 1381
 					continue;
1382 1382
 				}
1383 1383
 				$item = \OCP\Util::mb_array_change_key_case($item, MB_CASE_LOWER, 'UTF-8');
1384
-				foreach($attr as $key) {
1385
-					if(isset($item[$key])) {
1386
-						if(is_array($item[$key]) && isset($item[$key]['count'])) {
1384
+				foreach ($attr as $key) {
1385
+					if (isset($item[$key])) {
1386
+						if (is_array($item[$key]) && isset($item[$key]['count'])) {
1387 1387
 							unset($item[$key]['count']);
1388 1388
 						}
1389
-						if($key !== 'dn') {
1390
-							if($this->resemblesDN($key)) {
1389
+						if ($key !== 'dn') {
1390
+							if ($this->resemblesDN($key)) {
1391 1391
 								$selection[$i][$key] = $this->helper->sanitizeDN($item[$key]);
1392
-							} else if($key === 'objectguid' || $key === 'guid') {
1392
+							} else if ($key === 'objectguid' || $key === 'guid') {
1393 1393
 								$selection[$i][$key] = [$this->convertObjectGUID2Str($item[$key][0])];
1394 1394
 							} else {
1395 1395
 								$selection[$i][$key] = $item[$key];
@@ -1407,14 +1407,14 @@  discard block
 block discarded – undo
1407 1407
 		//we slice the findings, when
1408 1408
 		//a) paged search unsuccessful, though attempted
1409 1409
 		//b) no paged search, but limit set
1410
-		if((!$this->getPagedSearchResultState()
1410
+		if ((!$this->getPagedSearchResultState()
1411 1411
 			&& $pagedSearchOK)
1412 1412
 			|| (
1413 1413
 				!$pagedSearchOK
1414 1414
 				&& !is_null($limit)
1415 1415
 			)
1416 1416
 		) {
1417
-			$findings = array_slice($findings, (int)$offset, $limit);
1417
+			$findings = array_slice($findings, (int) $offset, $limit);
1418 1418
 		}
1419 1419
 		return $findings;
1420 1420
 	}
@@ -1427,13 +1427,13 @@  discard block
 block discarded – undo
1427 1427
 	public function sanitizeUsername($name) {
1428 1428
 		$name = trim($name);
1429 1429
 
1430
-		if($this->connection->ldapIgnoreNamingRules) {
1430
+		if ($this->connection->ldapIgnoreNamingRules) {
1431 1431
 			return $name;
1432 1432
 		}
1433 1433
 
1434 1434
 		// Transliteration to ASCII
1435 1435
 		$transliterated = @iconv('UTF-8', 'ASCII//TRANSLIT', $name);
1436
-		if($transliterated !== false) {
1436
+		if ($transliterated !== false) {
1437 1437
 			// depending on system config iconv can work or not
1438 1438
 			$name = $transliterated;
1439 1439
 		}
@@ -1444,7 +1444,7 @@  discard block
 block discarded – undo
1444 1444
 		// Every remaining disallowed characters will be removed
1445 1445
 		$name = preg_replace('/[^a-zA-Z0-9_.@-]/u', '', $name);
1446 1446
 
1447
-		if($name === '') {
1447
+		if ($name === '') {
1448 1448
 			throw new \InvalidArgumentException('provided name template for username does not contain any allowed characters');
1449 1449
 		}
1450 1450
 
@@ -1459,13 +1459,13 @@  discard block
 block discarded – undo
1459 1459
 	*/
1460 1460
 	public function escapeFilterPart($input, $allowAsterisk = false) {
1461 1461
 		$asterisk = '';
1462
-		if($allowAsterisk && strlen($input) > 0 && $input[0] === '*') {
1462
+		if ($allowAsterisk && strlen($input) > 0 && $input[0] === '*') {
1463 1463
 			$asterisk = '*';
1464 1464
 			$input = mb_substr($input, 1, null, 'UTF-8');
1465 1465
 		}
1466 1466
 		$search  = ['*', '\\', '(', ')'];
1467 1467
 		$replace = ['\\*', '\\\\', '\\(', '\\)'];
1468
-		return $asterisk . str_replace($search, $replace, $input);
1468
+		return $asterisk.str_replace($search, $replace, $input);
1469 1469
 	}
1470 1470
 
1471 1471
 	/**
@@ -1495,13 +1495,13 @@  discard block
 block discarded – undo
1495 1495
 	 */
1496 1496
 	private function combineFilter($filters, $operator) {
1497 1497
 		$combinedFilter = '('.$operator;
1498
-		foreach($filters as $filter) {
1498
+		foreach ($filters as $filter) {
1499 1499
 			if ($filter !== '' && $filter[0] !== '(') {
1500 1500
 				$filter = '('.$filter.')';
1501 1501
 			}
1502
-			$combinedFilter.=$filter;
1502
+			$combinedFilter .= $filter;
1503 1503
 		}
1504
-		$combinedFilter.=')';
1504
+		$combinedFilter .= ')';
1505 1505
 		return $combinedFilter;
1506 1506
 	}
1507 1507
 
@@ -1537,17 +1537,17 @@  discard block
 block discarded – undo
1537 1537
 	 * @throws \Exception
1538 1538
 	 */
1539 1539
 	private function getAdvancedFilterPartForSearch($search, $searchAttributes) {
1540
-		if(!is_array($searchAttributes) || count($searchAttributes) < 2) {
1540
+		if (!is_array($searchAttributes) || count($searchAttributes) < 2) {
1541 1541
 			throw new \Exception('searchAttributes must be an array with at least two string');
1542 1542
 		}
1543 1543
 		$searchWords = explode(' ', trim($search));
1544 1544
 		$wordFilters = [];
1545
-		foreach($searchWords as $word) {
1545
+		foreach ($searchWords as $word) {
1546 1546
 			$word = $this->prepareSearchTerm($word);
1547 1547
 			//every word needs to appear at least once
1548 1548
 			$wordMatchOneAttrFilters = [];
1549
-			foreach($searchAttributes as $attr) {
1550
-				$wordMatchOneAttrFilters[] = $attr . '=' . $word;
1549
+			foreach ($searchAttributes as $attr) {
1550
+				$wordMatchOneAttrFilters[] = $attr.'='.$word;
1551 1551
 			}
1552 1552
 			$wordFilters[] = $this->combineFilterWithOr($wordMatchOneAttrFilters);
1553 1553
 		}
@@ -1565,10 +1565,10 @@  discard block
 block discarded – undo
1565 1565
 	private function getFilterPartForSearch($search, $searchAttributes, $fallbackAttribute) {
1566 1566
 		$filter = [];
1567 1567
 		$haveMultiSearchAttributes = (is_array($searchAttributes) && count($searchAttributes) > 0);
1568
-		if($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) {
1568
+		if ($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) {
1569 1569
 			try {
1570 1570
 				return $this->getAdvancedFilterPartForSearch($search, $searchAttributes);
1571
-			} catch(\Exception $e) {
1571
+			} catch (\Exception $e) {
1572 1572
 				\OCP\Util::writeLog(
1573 1573
 					'user_ldap',
1574 1574
 					'Creating advanced filter for search failed, falling back to simple method.',
@@ -1578,17 +1578,17 @@  discard block
 block discarded – undo
1578 1578
 		}
1579 1579
 
1580 1580
 		$search = $this->prepareSearchTerm($search);
1581
-		if(!is_array($searchAttributes) || count($searchAttributes) === 0) {
1581
+		if (!is_array($searchAttributes) || count($searchAttributes) === 0) {
1582 1582
 			if ($fallbackAttribute === '') {
1583 1583
 				return '';
1584 1584
 			}
1585
-			$filter[] = $fallbackAttribute . '=' . $search;
1585
+			$filter[] = $fallbackAttribute.'='.$search;
1586 1586
 		} else {
1587
-			foreach($searchAttributes as $attribute) {
1588
-				$filter[] = $attribute . '=' . $search;
1587
+			foreach ($searchAttributes as $attribute) {
1588
+				$filter[] = $attribute.'='.$search;
1589 1589
 			}
1590 1590
 		}
1591
-		if(count($filter) === 1) {
1591
+		if (count($filter) === 1) {
1592 1592
 			return '('.$filter[0].')';
1593 1593
 		}
1594 1594
 		return $this->combineFilterWithOr($filter);
@@ -1609,7 +1609,7 @@  discard block
 block discarded – undo
1609 1609
 		if ($term === '') {
1610 1610
 			$result = '*';
1611 1611
 		} else if ($allowEnum !== 'no') {
1612
-			$result = $term . '*';
1612
+			$result = $term.'*';
1613 1613
 		}
1614 1614
 		return $result;
1615 1615
 	}
@@ -1621,7 +1621,7 @@  discard block
 block discarded – undo
1621 1621
 	public function getFilterForUserCount() {
1622 1622
 		$filter = $this->combineFilterWithAnd([
1623 1623
 			$this->connection->ldapUserFilter,
1624
-			$this->connection->ldapUserDisplayName . '=*'
1624
+			$this->connection->ldapUserDisplayName.'=*'
1625 1625
 		]);
1626 1626
 
1627 1627
 		return $filter;
@@ -1639,7 +1639,7 @@  discard block
 block discarded – undo
1639 1639
 			'ldapAgentName' => $name,
1640 1640
 			'ldapAgentPassword' => $password
1641 1641
 		];
1642
-		if(!$testConnection->setConfiguration($credentials)) {
1642
+		if (!$testConnection->setConfiguration($credentials)) {
1643 1643
 			return false;
1644 1644
 		}
1645 1645
 		return $testConnection->bind();
@@ -1661,30 +1661,30 @@  discard block
 block discarded – undo
1661 1661
 			// Sacrebleu! The UUID attribute is unknown :( We need first an
1662 1662
 			// existing DN to be able to reliably detect it.
1663 1663
 			$result = $this->search($filter, $base, ['dn'], 1);
1664
-			if(!isset($result[0]) || !isset($result[0]['dn'])) {
1664
+			if (!isset($result[0]) || !isset($result[0]['dn'])) {
1665 1665
 				throw new \Exception('Cannot determine UUID attribute');
1666 1666
 			}
1667 1667
 			$dn = $result[0]['dn'][0];
1668
-			if(!$this->detectUuidAttribute($dn, true)) {
1668
+			if (!$this->detectUuidAttribute($dn, true)) {
1669 1669
 				throw new \Exception('Cannot determine UUID attribute');
1670 1670
 			}
1671 1671
 		} else {
1672 1672
 			// The UUID attribute is either known or an override is given.
1673 1673
 			// By calling this method we ensure that $this->connection->$uuidAttr
1674 1674
 			// is definitely set
1675
-			if(!$this->detectUuidAttribute('', true)) {
1675
+			if (!$this->detectUuidAttribute('', true)) {
1676 1676
 				throw new \Exception('Cannot determine UUID attribute');
1677 1677
 			}
1678 1678
 		}
1679 1679
 
1680 1680
 		$uuidAttr = $this->connection->ldapUuidUserAttribute;
1681
-		if($uuidAttr === 'guid' || $uuidAttr === 'objectguid') {
1681
+		if ($uuidAttr === 'guid' || $uuidAttr === 'objectguid') {
1682 1682
 			$uuid = $this->formatGuid2ForFilterUser($uuid);
1683 1683
 		}
1684 1684
 
1685
-		$filter = $uuidAttr . '=' . $uuid;
1685
+		$filter = $uuidAttr.'='.$uuid;
1686 1686
 		$result = $this->searchUsers($filter, ['dn'], 2);
1687
-		if(is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) {
1687
+		if (is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) {
1688 1688
 			// we put the count into account to make sure that this is
1689 1689
 			// really unique
1690 1690
 			return $result[0]['dn'][0];
@@ -1704,7 +1704,7 @@  discard block
 block discarded – undo
1704 1704
 	 * @throws ServerNotAvailableException
1705 1705
 	 */
1706 1706
 	private function detectUuidAttribute($dn, $isUser = true, $force = false, array $ldapRecord = null) {
1707
-		if($isUser) {
1707
+		if ($isUser) {
1708 1708
 			$uuidAttr     = 'ldapUuidUserAttribute';
1709 1709
 			$uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
1710 1710
 		} else {
@@ -1712,8 +1712,8 @@  discard block
 block discarded – undo
1712 1712
 			$uuidOverride = $this->connection->ldapExpertUUIDGroupAttr;
1713 1713
 		}
1714 1714
 
1715
-		if(!$force) {
1716
-			if($this->connection->$uuidAttr !== 'auto') {
1715
+		if (!$force) {
1716
+			if ($this->connection->$uuidAttr !== 'auto') {
1717 1717
 				return true;
1718 1718
 			} else if (is_string($uuidOverride) && trim($uuidOverride) !== '') {
1719 1719
 				$this->connection->$uuidAttr = $uuidOverride;
@@ -1721,23 +1721,23 @@  discard block
 block discarded – undo
1721 1721
 			}
1722 1722
 
1723 1723
 			$attribute = $this->connection->getFromCache($uuidAttr);
1724
-			if(!$attribute === null) {
1724
+			if (!$attribute === null) {
1725 1725
 				$this->connection->$uuidAttr = $attribute;
1726 1726
 				return true;
1727 1727
 			}
1728 1728
 		}
1729 1729
 
1730
-		foreach(self::UUID_ATTRIBUTES as $attribute) {
1731
-			if($ldapRecord !== null) {
1730
+		foreach (self::UUID_ATTRIBUTES as $attribute) {
1731
+			if ($ldapRecord !== null) {
1732 1732
 				// we have the info from LDAP already, we don't need to talk to the server again
1733
-				if(isset($ldapRecord[$attribute])) {
1733
+				if (isset($ldapRecord[$attribute])) {
1734 1734
 					$this->connection->$uuidAttr = $attribute;
1735 1735
 					return true;
1736 1736
 				}
1737 1737
 			}
1738 1738
 
1739 1739
 			$value = $this->readAttribute($dn, $attribute);
1740
-			if(is_array($value) && isset($value[0]) && !empty($value[0])) {
1740
+			if (is_array($value) && isset($value[0]) && !empty($value[0])) {
1741 1741
 				\OC::$server->getLogger()->debug(
1742 1742
 					'Setting {attribute} as {subject}',
1743 1743
 					[
@@ -1764,7 +1764,7 @@  discard block
 block discarded – undo
1764 1764
 	 * @throws ServerNotAvailableException
1765 1765
 	 */
1766 1766
 	public function getUUID($dn, $isUser = true, $ldapRecord = null) {
1767
-		if($isUser) {
1767
+		if ($isUser) {
1768 1768
 			$uuidAttr     = 'ldapUuidUserAttribute';
1769 1769
 			$uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
1770 1770
 		} else {
@@ -1773,10 +1773,10 @@  discard block
 block discarded – undo
1773 1773
 		}
1774 1774
 
1775 1775
 		$uuid = false;
1776
-		if($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) {
1776
+		if ($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) {
1777 1777
 			$attr = $this->connection->$uuidAttr;
1778 1778
 			$uuid = isset($ldapRecord[$attr]) ? $ldapRecord[$attr] : $this->readAttribute($dn, $attr);
1779
-			if( !is_array($uuid)
1779
+			if (!is_array($uuid)
1780 1780
 				&& $uuidOverride !== ''
1781 1781
 				&& $this->detectUuidAttribute($dn, $isUser, true, $ldapRecord))
1782 1782
 			{
@@ -1784,7 +1784,7 @@  discard block
 block discarded – undo
1784 1784
 					? $ldapRecord[$this->connection->$uuidAttr]
1785 1785
 					: $this->readAttribute($dn, $this->connection->$uuidAttr);
1786 1786
 			}
1787
-			if(is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) {
1787
+			if (is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) {
1788 1788
 				$uuid = $uuid[0];
1789 1789
 			}
1790 1790
 		}
@@ -1801,19 +1801,19 @@  discard block
 block discarded – undo
1801 1801
 	private function convertObjectGUID2Str($oguid) {
1802 1802
 		$hex_guid = bin2hex($oguid);
1803 1803
 		$hex_guid_to_guid_str = '';
1804
-		for($k = 1; $k <= 4; ++$k) {
1804
+		for ($k = 1; $k <= 4; ++$k) {
1805 1805
 			$hex_guid_to_guid_str .= substr($hex_guid, 8 - 2 * $k, 2);
1806 1806
 		}
1807 1807
 		$hex_guid_to_guid_str .= '-';
1808
-		for($k = 1; $k <= 2; ++$k) {
1808
+		for ($k = 1; $k <= 2; ++$k) {
1809 1809
 			$hex_guid_to_guid_str .= substr($hex_guid, 12 - 2 * $k, 2);
1810 1810
 		}
1811 1811
 		$hex_guid_to_guid_str .= '-';
1812
-		for($k = 1; $k <= 2; ++$k) {
1812
+		for ($k = 1; $k <= 2; ++$k) {
1813 1813
 			$hex_guid_to_guid_str .= substr($hex_guid, 16 - 2 * $k, 2);
1814 1814
 		}
1815
-		$hex_guid_to_guid_str .= '-' . substr($hex_guid, 16, 4);
1816
-		$hex_guid_to_guid_str .= '-' . substr($hex_guid, 20);
1815
+		$hex_guid_to_guid_str .= '-'.substr($hex_guid, 16, 4);
1816
+		$hex_guid_to_guid_str .= '-'.substr($hex_guid, 20);
1817 1817
 
1818 1818
 		return strtoupper($hex_guid_to_guid_str);
1819 1819
 	}
@@ -1830,11 +1830,11 @@  discard block
 block discarded – undo
1830 1830
 	 * @return string
1831 1831
 	 */
1832 1832
 	public function formatGuid2ForFilterUser($guid) {
1833
-		if(!is_string($guid)) {
1833
+		if (!is_string($guid)) {
1834 1834
 			throw new \InvalidArgumentException('String expected');
1835 1835
 		}
1836 1836
 		$blocks = explode('-', $guid);
1837
-		if(count($blocks) !== 5) {
1837
+		if (count($blocks) !== 5) {
1838 1838
 			/*
1839 1839
 			 * Why not throw an Exception instead? This method is a utility
1840 1840
 			 * called only when trying to figure out whether a "missing" known
@@ -1847,20 +1847,20 @@  discard block
 block discarded – undo
1847 1847
 			 * user. Instead we write a log message.
1848 1848
 			 */
1849 1849
 			\OC::$server->getLogger()->info(
1850
-				'Passed string does not resemble a valid GUID. Known UUID ' .
1850
+				'Passed string does not resemble a valid GUID. Known UUID '.
1851 1851
 				'({uuid}) probably does not match UUID configuration.',
1852
-				[ 'app' => 'user_ldap', 'uuid' => $guid ]
1852
+				['app' => 'user_ldap', 'uuid' => $guid]
1853 1853
 			);
1854 1854
 			return $guid;
1855 1855
 		}
1856
-		for($i=0; $i < 3; $i++) {
1856
+		for ($i = 0; $i < 3; $i++) {
1857 1857
 			$pairs = str_split($blocks[$i], 2);
1858 1858
 			$pairs = array_reverse($pairs);
1859 1859
 			$blocks[$i] = implode('', $pairs);
1860 1860
 		}
1861
-		for($i=0; $i < 5; $i++) {
1861
+		for ($i = 0; $i < 5; $i++) {
1862 1862
 			$pairs = str_split($blocks[$i], 2);
1863
-			$blocks[$i] = '\\' . implode('\\', $pairs);
1863
+			$blocks[$i] = '\\'.implode('\\', $pairs);
1864 1864
 		}
1865 1865
 		return implode('', $blocks);
1866 1866
 	}
@@ -1876,12 +1876,12 @@  discard block
 block discarded – undo
1876 1876
 		$domainDN = $this->getDomainDNFromDN($dn);
1877 1877
 		$cacheKey = 'getSID-'.$domainDN;
1878 1878
 		$sid = $this->connection->getFromCache($cacheKey);
1879
-		if(!is_null($sid)) {
1879
+		if (!is_null($sid)) {
1880 1880
 			return $sid;
1881 1881
 		}
1882 1882
 
1883 1883
 		$objectSid = $this->readAttribute($domainDN, 'objectsid');
1884
-		if(!is_array($objectSid) || empty($objectSid)) {
1884
+		if (!is_array($objectSid) || empty($objectSid)) {
1885 1885
 			$this->connection->writeToCache($cacheKey, false);
1886 1886
 			return false;
1887 1887
 		}
@@ -1939,12 +1939,12 @@  discard block
 block discarded – undo
1939 1939
 		$belongsToBase = false;
1940 1940
 		$bases = $this->helper->sanitizeDN($bases);
1941 1941
 
1942
-		foreach($bases as $base) {
1942
+		foreach ($bases as $base) {
1943 1943
 			$belongsToBase = true;
1944
-			if(mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8')-mb_strlen($base, 'UTF-8'))) {
1944
+			if (mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8') - mb_strlen($base, 'UTF-8'))) {
1945 1945
 				$belongsToBase = false;
1946 1946
 			}
1947
-			if($belongsToBase) {
1947
+			if ($belongsToBase) {
1948 1948
 				break;
1949 1949
 			}
1950 1950
 		}
@@ -1973,16 +1973,16 @@  discard block
 block discarded – undo
1973 1973
 	 * @return string containing the key or empty if none is cached
1974 1974
 	 */
1975 1975
 	private function getPagedResultCookie($base, $filter, $limit, $offset) {
1976
-		if($offset === 0) {
1976
+		if ($offset === 0) {
1977 1977
 			return '';
1978 1978
 		}
1979 1979
 		$offset -= $limit;
1980 1980
 		//we work with cache here
1981
-		$cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . (int)$limit . '-' . (int)$offset;
1981
+		$cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.(int) $limit.'-'.(int) $offset;
1982 1982
 		$cookie = '';
1983
-		if(isset($this->cookies[$cacheKey])) {
1983
+		if (isset($this->cookies[$cacheKey])) {
1984 1984
 			$cookie = $this->cookies[$cacheKey];
1985
-			if(is_null($cookie)) {
1985
+			if (is_null($cookie)) {
1986 1986
 				$cookie = '';
1987 1987
 			}
1988 1988
 		}
@@ -2000,7 +2000,7 @@  discard block
 block discarded – undo
2000 2000
 	 * @return bool
2001 2001
 	 */
2002 2002
 	public function hasMoreResults() {
2003
-		if(empty($this->lastCookie) && $this->lastCookie !== '0') {
2003
+		if (empty($this->lastCookie) && $this->lastCookie !== '0') {
2004 2004
 			// as in RFC 2696, when all results are returned, the cookie will
2005 2005
 			// be empty.
2006 2006
 			return false;
@@ -2020,8 +2020,8 @@  discard block
 block discarded – undo
2020 2020
 	 */
2021 2021
 	private function setPagedResultCookie($base, $filter, $limit, $offset, $cookie) {
2022 2022
 		// allow '0' for 389ds
2023
-		if(!empty($cookie) || $cookie === '0') {
2024
-			$cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . (int)$limit . '-' . (int)$offset;
2023
+		if (!empty($cookie) || $cookie === '0') {
2024
+			$cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.(int) $limit.'-'.(int) $offset;
2025 2025
 			$this->cookies[$cacheKey] = $cookie;
2026 2026
 			$this->lastCookie = $cookie;
2027 2027
 		}
@@ -2051,16 +2051,16 @@  discard block
 block discarded – undo
2051 2051
 	private function initPagedSearch($filter, $bases, $attr, $limit, $offset) {
2052 2052
 		$pagedSearchOK = false;
2053 2053
 		if ($limit !== 0) {
2054
-			$offset = (int)$offset; //can be null
2054
+			$offset = (int) $offset; //can be null
2055 2055
 			\OCP\Util::writeLog('user_ldap',
2056 2056
 				'initializing paged search for  Filter '.$filter.' base '.print_r($bases, true)
2057
-				.' attr '.print_r($attr, true). ' limit ' .$limit.' offset '.$offset,
2057
+				.' attr '.print_r($attr, true).' limit '.$limit.' offset '.$offset,
2058 2058
 				ILogger::DEBUG);
2059 2059
 			//get the cookie from the search for the previous search, required by LDAP
2060
-			foreach($bases as $base) {
2060
+			foreach ($bases as $base) {
2061 2061
 
2062 2062
 				$cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset);
2063
-				if(empty($cookie) && $cookie !== "0" && ($offset > 0)) {
2063
+				if (empty($cookie) && $cookie !== "0" && ($offset > 0)) {
2064 2064
 					// no cookie known from a potential previous search. We need
2065 2065
 					// to start from 0 to come to the desired page. cookie value
2066 2066
 					// of '0' is valid, because 389ds
@@ -2070,17 +2070,17 @@  discard block
 block discarded – undo
2070 2070
 					//still no cookie? obviously, the server does not like us. Let's skip paging efforts.
2071 2071
 					// '0' is valid, because 389ds
2072 2072
 					//TODO: remember this, probably does not change in the next request...
2073
-					if(empty($cookie) && $cookie !== '0') {
2073
+					if (empty($cookie) && $cookie !== '0') {
2074 2074
 						$cookie = null;
2075 2075
 					}
2076 2076
 				}
2077
-				if(!is_null($cookie)) {
2077
+				if (!is_null($cookie)) {
2078 2078
 					//since offset = 0, this is a new search. We abandon other searches that might be ongoing.
2079 2079
 					$this->abandonPagedSearch();
2080 2080
 					$pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult',
2081 2081
 						$this->connection->getConnectionResource(), $limit,
2082 2082
 						false, $cookie);
2083
-					if(!$pagedSearchOK) {
2083
+					if (!$pagedSearchOK) {
2084 2084
 						return false;
2085 2085
 					}
2086 2086
 					\OCP\Util::writeLog('user_ldap', 'Ready for a paged search', ILogger::DEBUG);
@@ -2103,7 +2103,7 @@  discard block
 block discarded – undo
2103 2103
 			$this->abandonPagedSearch();
2104 2104
 			// in case someone set it to 0 … use 500, otherwise no results will
2105 2105
 			// be returned.
2106
-			$pageSize = (int)$this->connection->ldapPagingSize > 0 ? (int)$this->connection->ldapPagingSize : 500;
2106
+			$pageSize = (int) $this->connection->ldapPagingSize > 0 ? (int) $this->connection->ldapPagingSize : 500;
2107 2107
 			$pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult',
2108 2108
 				$this->connection->getConnectionResource(),
2109 2109
 				$pageSize, false, '');
Please login to merge, or discard this patch.