Completed
Pull Request — master (#5104)
by Blizzz
14:18
created
apps/user_ldap/lib/Access.php 1 patch
Spacing   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 	 * @return AbstractMapping
113 113
 	 */
114 114
 	public function getUserMapper() {
115
-		if(is_null($this->userMapper)) {
115
+		if (is_null($this->userMapper)) {
116 116
 			throw new \Exception('UserMapper was not assigned to this Access instance.');
117 117
 		}
118 118
 		return $this->userMapper;
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 	 * @return AbstractMapping
133 133
 	 */
134 134
 	public function getGroupMapper() {
135
-		if(is_null($this->groupMapper)) {
135
+		if (is_null($this->groupMapper)) {
136 136
 			throw new \Exception('GroupMapper was not assigned to this Access instance.');
137 137
 		}
138 138
 		return $this->groupMapper;
@@ -163,14 +163,14 @@  discard block
 block discarded – undo
163 163
 	 *          array if $attr is empty, false otherwise
164 164
 	 */
165 165
 	public function readAttribute($dn, $attr, $filter = 'objectClass=*') {
166
-		if(!$this->checkConnection()) {
166
+		if (!$this->checkConnection()) {
167 167
 			\OCP\Util::writeLog('user_ldap',
168 168
 				'No LDAP Connector assigned, access impossible for readAttribute.',
169 169
 				\OCP\Util::WARN);
170 170
 			return false;
171 171
 		}
172 172
 		$cr = $this->connection->getConnectionResource();
173
-		if(!$this->ldap->isResource($cr)) {
173
+		if (!$this->ldap->isResource($cr)) {
174 174
 			//LDAP not available
175 175
 			\OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG);
176 176
 			return false;
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 		$isRangeRequest = false;
194 194
 		do {
195 195
 			$result = $this->executeRead($cr, $dn, $attrToRead, $filter, $maxResults);
196
-			if(is_bool($result)) {
196
+			if (is_bool($result)) {
197 197
 				// when an exists request was run and it was successful, an empty
198 198
 				// array must be returned
199 199
 				return $result ? [] : false;
@@ -210,22 +210,22 @@  discard block
 block discarded – undo
210 210
 			$result = $this->extractRangeData($result, $attr);
211 211
 			if (!empty($result)) {
212 212
 				$normalizedResult = $this->extractAttributeValuesFromResult(
213
-					[ $attr => $result['values'] ],
213
+					[$attr => $result['values']],
214 214
 					$attr
215 215
 				);
216 216
 				$values = array_merge($values, $normalizedResult);
217 217
 
218
-				if($result['rangeHigh'] === '*') {
218
+				if ($result['rangeHigh'] === '*') {
219 219
 					// when server replies with * as high range value, there are
220 220
 					// no more results left
221 221
 					return $values;
222 222
 				} else {
223
-					$low  = $result['rangeHigh'] + 1;
224
-					$attrToRead = $result['attributeName'] . ';range=' . $low . '-*';
223
+					$low = $result['rangeHigh'] + 1;
224
+					$attrToRead = $result['attributeName'].';range='.$low.'-*';
225 225
 					$isRangeRequest = true;
226 226
 				}
227 227
 			}
228
-		} while($isRangeRequest);
228
+		} while ($isRangeRequest);
229 229
 
230 230
 		\OCP\Util::writeLog('user_ldap', 'Requested attribute '.$attr.' not found for '.$dn, \OCP\Util::DEBUG);
231 231
 		return false;
@@ -250,13 +250,13 @@  discard block
 block discarded – undo
250 250
 		if (!$this->ldap->isResource($rr)) {
251 251
 			if ($attribute !== '') {
252 252
 				//do not throw this message on userExists check, irritates
253
-				\OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN ' . $dn, \OCP\Util::DEBUG);
253
+				\OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN '.$dn, \OCP\Util::DEBUG);
254 254
 			}
255 255
 			//in case an error occurs , e.g. object does not exist
256 256
 			return false;
257 257
 		}
258 258
 		if ($attribute === '' && ($filter === 'objectclass=*' || $this->invokeLDAPMethod('countEntries', $cr, $rr) === 1)) {
259
-			\OCP\Util::writeLog('user_ldap', 'readAttribute: ' . $dn . ' found', \OCP\Util::DEBUG);
259
+			\OCP\Util::writeLog('user_ldap', 'readAttribute: '.$dn.' found', \OCP\Util::DEBUG);
260 260
 			return true;
261 261
 		}
262 262
 		$er = $this->invokeLDAPMethod('firstEntry', $cr, $rr);
@@ -281,12 +281,12 @@  discard block
 block discarded – undo
281 281
 	 */
282 282
 	public function extractAttributeValuesFromResult($result, $attribute) {
283 283
 		$values = [];
284
-		if(isset($result[$attribute]) && $result[$attribute]['count'] > 0) {
284
+		if (isset($result[$attribute]) && $result[$attribute]['count'] > 0) {
285 285
 			$lowercaseAttribute = strtolower($attribute);
286
-			for($i=0;$i<$result[$attribute]['count'];$i++) {
287
-				if($this->resemblesDN($attribute)) {
286
+			for ($i = 0; $i < $result[$attribute]['count']; $i++) {
287
+				if ($this->resemblesDN($attribute)) {
288 288
 					$values[] = $this->helper->sanitizeDN($result[$attribute][$i]);
289
-				} elseif($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') {
289
+				} elseif ($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') {
290 290
 					$values[] = $this->convertObjectGUID2Str($result[$attribute][$i]);
291 291
 				} else {
292 292
 					$values[] = $result[$attribute][$i];
@@ -308,10 +308,10 @@  discard block
 block discarded – undo
308 308
 	 */
309 309
 	public function extractRangeData($result, $attribute) {
310 310
 		$keys = array_keys($result);
311
-		foreach($keys as $key) {
312
-			if($key !== $attribute && strpos($key, $attribute) === 0) {
311
+		foreach ($keys as $key) {
312
+			if ($key !== $attribute && strpos($key, $attribute) === 0) {
313 313
 				$queryData = explode(';', $key);
314
-				if(strpos($queryData[1], 'range=') === 0) {
314
+				if (strpos($queryData[1], 'range=') === 0) {
315 315
 					$high = substr($queryData[1], 1 + strpos($queryData[1], '-'));
316 316
 					$data = [
317 317
 						'values' => $result[$key],
@@ -336,18 +336,18 @@  discard block
 block discarded – undo
336 336
 	 * @throws \Exception
337 337
 	 */
338 338
 	public function setPassword($userDN, $password) {
339
-		if(intval($this->connection->turnOnPasswordChange) !== 1) {
339
+		if (intval($this->connection->turnOnPasswordChange) !== 1) {
340 340
 			throw new \Exception('LDAP password changes are disabled.');
341 341
 		}
342 342
 		$cr = $this->connection->getConnectionResource();
343
-		if(!$this->ldap->isResource($cr)) {
343
+		if (!$this->ldap->isResource($cr)) {
344 344
 			//LDAP not available
345 345
 			\OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG);
346 346
 			return false;
347 347
 		}
348 348
 		try {
349 349
 			return $this->invokeLDAPMethod('modReplace', $cr, $userDN, $password);
350
-		} catch(ConstraintViolationException $e) {
350
+		} catch (ConstraintViolationException $e) {
351 351
 			throw new HintException('Password change rejected.', \OC::$server->getL10N('user_ldap')->t('Password change rejected. Hint: ').$e->getMessage(), $e->getCode());
352 352
 		}
353 353
 	}
@@ -389,17 +389,17 @@  discard block
 block discarded – undo
389 389
 	 */
390 390
 	public function getDomainDNFromDN($dn) {
391 391
 		$allParts = $this->ldap->explodeDN($dn, 0);
392
-		if($allParts === false) {
392
+		if ($allParts === false) {
393 393
 			//not a valid DN
394 394
 			return '';
395 395
 		}
396 396
 		$domainParts = array();
397 397
 		$dcFound = false;
398
-		foreach($allParts as $part) {
399
-			if(!$dcFound && strpos($part, 'dc=') === 0) {
398
+		foreach ($allParts as $part) {
399
+			if (!$dcFound && strpos($part, 'dc=') === 0) {
400 400
 				$dcFound = true;
401 401
 			}
402
-			if($dcFound) {
402
+			if ($dcFound) {
403 403
 				$domainParts[] = $part;
404 404
 			}
405 405
 		}
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
 
427 427
 		//Check whether the DN belongs to the Base, to avoid issues on multi-
428 428
 		//server setups
429
-		if(is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
429
+		if (is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
430 430
 			return $fdn;
431 431
 		}
432 432
 
@@ -443,7 +443,7 @@  discard block
 block discarded – undo
443 443
 		//To avoid bypassing the base DN settings under certain circumstances
444 444
 		//with the group support, check whether the provided DN matches one of
445 445
 		//the given Bases
446
-		if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) {
446
+		if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) {
447 447
 			return false;
448 448
 		}
449 449
 
@@ -460,11 +460,11 @@  discard block
 block discarded – undo
460 460
 	 */
461 461
 	public function groupsMatchFilter($groupDNs) {
462 462
 		$validGroupDNs = [];
463
-		foreach($groupDNs as $dn) {
463
+		foreach ($groupDNs as $dn) {
464 464
 			$cacheKey = 'groupsMatchFilter-'.$dn;
465 465
 			$groupMatchFilter = $this->connection->getFromCache($cacheKey);
466
-			if(!is_null($groupMatchFilter)) {
467
-				if($groupMatchFilter) {
466
+			if (!is_null($groupMatchFilter)) {
467
+				if ($groupMatchFilter) {
468 468
 					$validGroupDNs[] = $dn;
469 469
 				}
470 470
 				continue;
@@ -472,13 +472,13 @@  discard block
 block discarded – undo
472 472
 
473 473
 			// Check the base DN first. If this is not met already, we don't
474 474
 			// need to ask the server at all.
475
-			if(!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) {
475
+			if (!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) {
476 476
 				$this->connection->writeToCache($cacheKey, false);
477 477
 				continue;
478 478
 			}
479 479
 
480 480
 			$result = $this->readAttribute($dn, 'cn', $this->connection->ldapGroupFilter);
481
-			if(is_array($result)) {
481
+			if (is_array($result)) {
482 482
 				$this->connection->writeToCache($cacheKey, true);
483 483
 				$validGroupDNs[] = $dn;
484 484
 			} else {
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
 		//To avoid bypassing the base DN settings under certain circumstances
500 500
 		//with the group support, check whether the provided DN matches one of
501 501
 		//the given Bases
502
-		if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
502
+		if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
503 503
 			return false;
504 504
 		}
505 505
 
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
 	 * @return string|false with with the name to use in Nextcloud
515 515
 	 */
516 516
 	public function dn2ocname($fdn, $ldapName = null, $isUser = true) {
517
-		if($isUser) {
517
+		if ($isUser) {
518 518
 			$mapper = $this->getUserMapper();
519 519
 			$nameAttribute = $this->connection->ldapUserDisplayName;
520 520
 		} else {
@@ -524,15 +524,15 @@  discard block
 block discarded – undo
524 524
 
525 525
 		//let's try to retrieve the Nextcloud name from the mappings table
526 526
 		$ocName = $mapper->getNameByDN($fdn);
527
-		if(is_string($ocName)) {
527
+		if (is_string($ocName)) {
528 528
 			return $ocName;
529 529
 		}
530 530
 
531 531
 		//second try: get the UUID and check if it is known. Then, update the DN and return the name.
532 532
 		$uuid = $this->getUUID($fdn, $isUser);
533
-		if(is_string($uuid)) {
533
+		if (is_string($uuid)) {
534 534
 			$ocName = $mapper->getNameByUUID($uuid);
535
-			if(is_string($ocName)) {
535
+			if (is_string($ocName)) {
536 536
 				$mapper->setDNbyUUID($fdn, $uuid);
537 537
 				return $ocName;
538 538
 			}
@@ -542,16 +542,16 @@  discard block
 block discarded – undo
542 542
 			return false;
543 543
 		}
544 544
 
545
-		if(is_null($ldapName)) {
545
+		if (is_null($ldapName)) {
546 546
 			$ldapName = $this->readAttribute($fdn, $nameAttribute);
547
-			if(!isset($ldapName[0]) && empty($ldapName[0])) {
547
+			if (!isset($ldapName[0]) && empty($ldapName[0])) {
548 548
 				\OCP\Util::writeLog('user_ldap', 'No or empty name for '.$fdn.'.', \OCP\Util::INFO);
549 549
 				return false;
550 550
 			}
551 551
 			$ldapName = $ldapName[0];
552 552
 		}
553 553
 
554
-		if($isUser) {
554
+		if ($isUser) {
555 555
 			$usernameAttribute = strval($this->connection->ldapExpertUsernameAttr);
556 556
 			if ($usernameAttribute !== '') {
557 557
 				$username = $this->readAttribute($fdn, $usernameAttribute);
@@ -570,9 +570,9 @@  discard block
 block discarded – undo
570 570
 		// outside of core user management will still cache the user as non-existing.
571 571
 		$originalTTL = $this->connection->ldapCacheTTL;
572 572
 		$this->connection->setConfiguration(array('ldapCacheTTL' => 0));
573
-		if(($isUser && !\OCP\User::userExists($intName))
573
+		if (($isUser && !\OCP\User::userExists($intName))
574 574
 			|| (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))) {
575
-			if($mapper->map($fdn, $intName, $uuid)) {
575
+			if ($mapper->map($fdn, $intName, $uuid)) {
576 576
 				$this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL));
577 577
 				return $intName;
578 578
 			}
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
 		$this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL));
581 581
 
582 582
 		$altName = $this->createAltInternalOwnCloudName($intName, $isUser);
583
-		if(is_string($altName) && $mapper->map($fdn, $altName, $uuid)) {
583
+		if (is_string($altName) && $mapper->map($fdn, $altName, $uuid)) {
584 584
 			return $altName;
585 585
 		}
586 586
 
@@ -617,7 +617,7 @@  discard block
 block discarded – undo
617 617
 	 * @return array
618 618
 	 */
619 619
 	private function ldap2NextcloudNames($ldapObjects, $isUsers) {
620
-		if($isUsers) {
620
+		if ($isUsers) {
621 621
 			$nameAttribute = $this->connection->ldapUserDisplayName;
622 622
 			$sndAttribute  = $this->connection->ldapUserDisplayName2;
623 623
 		} else {
@@ -625,9 +625,9 @@  discard block
 block discarded – undo
625 625
 		}
626 626
 		$nextcloudNames = array();
627 627
 
628
-		foreach($ldapObjects as $ldapObject) {
628
+		foreach ($ldapObjects as $ldapObject) {
629 629
 			$nameByLDAP = null;
630
-			if(    isset($ldapObject[$nameAttribute])
630
+			if (isset($ldapObject[$nameAttribute])
631 631
 				&& is_array($ldapObject[$nameAttribute])
632 632
 				&& isset($ldapObject[$nameAttribute][0])
633 633
 			) {
@@ -636,12 +636,12 @@  discard block
 block discarded – undo
636 636
 			}
637 637
 
638 638
 			$ncName = $this->dn2ocname($ldapObject['dn'][0], $nameByLDAP, $isUsers);
639
-			if($ncName) {
639
+			if ($ncName) {
640 640
 				$nextcloudNames[] = $ncName;
641
-				if($isUsers) {
641
+				if ($isUsers) {
642 642
 					//cache the user names so it does not need to be retrieved
643 643
 					//again later (e.g. sharing dialogue).
644
-					if(is_null($nameByLDAP)) {
644
+					if (is_null($nameByLDAP)) {
645 645
 						continue;
646 646
 					}
647 647
 					$sndName = isset($ldapObject[$sndAttribute][0])
@@ -679,7 +679,7 @@  discard block
 block discarded – undo
679 679
 	 */
680 680
 	public function cacheUserDisplayName($ocName, $displayName, $displayName2 = '') {
681 681
 		$user = $this->userManager->get($ocName);
682
-		if($user === null) {
682
+		if ($user === null) {
683 683
 			return;
684 684
 		}
685 685
 		$displayName = $user->composeAndStoreDisplayName($displayName, $displayName2);
@@ -699,9 +699,9 @@  discard block
 block discarded – undo
699 699
 		$attempts = 0;
700 700
 		//while loop is just a precaution. If a name is not generated within
701 701
 		//20 attempts, something else is very wrong. Avoids infinite loop.
702
-		while($attempts < 20){
703
-			$altName = $name . '_' . rand(1000,9999);
704
-			if(!\OCP\User::userExists($altName)) {
702
+		while ($attempts < 20) {
703
+			$altName = $name.'_'.rand(1000, 9999);
704
+			if (!\OCP\User::userExists($altName)) {
705 705
 				return $altName;
706 706
 			}
707 707
 			$attempts++;
@@ -723,25 +723,25 @@  discard block
 block discarded – undo
723 723
 	 */
724 724
 	private function _createAltInternalOwnCloudNameForGroups($name) {
725 725
 		$usedNames = $this->groupMapper->getNamesBySearch($name, "", '_%');
726
-		if(!($usedNames) || count($usedNames) === 0) {
726
+		if (!($usedNames) || count($usedNames) === 0) {
727 727
 			$lastNo = 1; //will become name_2
728 728
 		} else {
729 729
 			natsort($usedNames);
730 730
 			$lastName = array_pop($usedNames);
731 731
 			$lastNo = intval(substr($lastName, strrpos($lastName, '_') + 1));
732 732
 		}
733
-		$altName = $name.'_'.strval($lastNo+1);
733
+		$altName = $name.'_'.strval($lastNo + 1);
734 734
 		unset($usedNames);
735 735
 
736 736
 		$attempts = 1;
737
-		while($attempts < 21){
737
+		while ($attempts < 21) {
738 738
 			// Check to be really sure it is unique
739 739
 			// while loop is just a precaution. If a name is not generated within
740 740
 			// 20 attempts, something else is very wrong. Avoids infinite loop.
741
-			if(!\OC::$server->getGroupManager()->groupExists($altName)) {
741
+			if (!\OC::$server->getGroupManager()->groupExists($altName)) {
742 742
 				return $altName;
743 743
 			}
744
-			$altName = $name . '_' . ($lastNo + $attempts);
744
+			$altName = $name.'_'.($lastNo + $attempts);
745 745
 			$attempts++;
746 746
 		}
747 747
 		return false;
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
 	private function createAltInternalOwnCloudName($name, $isUser) {
757 757
 		$originalTTL = $this->connection->ldapCacheTTL;
758 758
 		$this->connection->setConfiguration(array('ldapCacheTTL' => 0));
759
-		if($isUser) {
759
+		if ($isUser) {
760 760
 			$altName = $this->_createAltInternalOwnCloudNameForUsers($name);
761 761
 		} else {
762 762
 			$altName = $this->_createAltInternalOwnCloudNameForGroups($name);
@@ -814,20 +814,20 @@  discard block
 block discarded – undo
814 814
 	 * and their values
815 815
 	 * @param array $ldapRecords
816 816
 	 */
817
-	public function batchApplyUserAttributes(array $ldapRecords){
817
+	public function batchApplyUserAttributes(array $ldapRecords) {
818 818
 		$displayNameAttribute = strtolower($this->connection->ldapUserDisplayName);
819
-		foreach($ldapRecords as $userRecord) {
820
-			if(!isset($userRecord[$displayNameAttribute])) {
819
+		foreach ($ldapRecords as $userRecord) {
820
+			if (!isset($userRecord[$displayNameAttribute])) {
821 821
 				// displayName is obligatory
822 822
 				continue;
823 823
 			}
824
-			$ocName  = $this->dn2ocname($userRecord['dn'][0]);
825
-			if($ocName === false) {
824
+			$ocName = $this->dn2ocname($userRecord['dn'][0]);
825
+			if ($ocName === false) {
826 826
 				continue;
827 827
 			}
828 828
 			$this->cacheUserExists($ocName);
829 829
 			$user = $this->userManager->get($ocName);
830
-			if($user instanceof OfflineUser) {
830
+			if ($user instanceof OfflineUser) {
831 831
 				$user->unmark();
832 832
 				$user = $this->userManager->get($ocName);
833 833
 			}
@@ -859,8 +859,8 @@  discard block
 block discarded – undo
859 859
 	 * @return array
860 860
 	 */
861 861
 	private function fetchList($list, $manyAttributes) {
862
-		if(is_array($list)) {
863
-			if($manyAttributes) {
862
+		if (is_array($list)) {
863
+			if ($manyAttributes) {
864 864
 				return $list;
865 865
 			} else {
866 866
 				$list = array_reduce($list, function($carry, $item) {
@@ -958,7 +958,7 @@  discard block
 block discarded – undo
958 958
 		// php no longer supports call-time pass-by-reference
959 959
 		// thus cannot support controlPagedResultResponse as the third argument
960 960
 		// is a reference
961
-		$doMethod = function () use ($command, &$arguments) {
961
+		$doMethod = function() use ($command, &$arguments) {
962 962
 			if ($command == 'controlPagedResultResponse') {
963 963
 				throw new \InvalidArgumentException('Invoker does not support controlPagedResultResponse, call LDAP Wrapper directly instead.');
964 964
 			} else {
@@ -976,7 +976,7 @@  discard block
 block discarded – undo
976 976
 			$this->connection->resetConnectionResource();
977 977
 			$cr = $this->connection->getConnectionResource();
978 978
 
979
-			if(!$this->ldap->isResource($cr)) {
979
+			if (!$this->ldap->isResource($cr)) {
980 980
 				// Seems like we didn't find any resource.
981 981
 				\OCP\Util::writeLog('user_ldap', "Could not $command, because resource is missing.", \OCP\Util::DEBUG);
982 982
 				throw $e;
@@ -997,13 +997,13 @@  discard block
 block discarded – undo
997 997
 	 * @throws \OC\ServerNotAvailableException
998 998
 	 */
999 999
 	private function executeSearch($filter, $base, &$attr = null, $limit = null, $offset = null) {
1000
-		if(!is_null($attr) && !is_array($attr)) {
1000
+		if (!is_null($attr) && !is_array($attr)) {
1001 1001
 			$attr = array(mb_strtolower($attr, 'UTF-8'));
1002 1002
 		}
1003 1003
 
1004 1004
 		// See if we have a resource, in case not cancel with message
1005 1005
 		$cr = $this->connection->getConnectionResource();
1006
-		if(!$this->ldap->isResource($cr)) {
1006
+		if (!$this->ldap->isResource($cr)) {
1007 1007
 			// Seems like we didn't find any resource.
1008 1008
 			// Return an empty array just like before.
1009 1009
 			\OCP\Util::writeLog('user_ldap', 'Could not search, because resource is missing.', \OCP\Util::DEBUG);
@@ -1017,7 +1017,7 @@  discard block
 block discarded – undo
1017 1017
 		$sr = $this->invokeLDAPMethod('search', $linkResources, $base, $filter, $attr);
1018 1018
 		// cannot use $cr anymore, might have changed in the previous call!
1019 1019
 		$error = $this->ldap->errno($this->connection->getConnectionResource());
1020
-		if(!is_array($sr) || $error !== 0) {
1020
+		if (!is_array($sr) || $error !== 0) {
1021 1021
 			\OCP\Util::writeLog('user_ldap', 'Attempt for Paging?  '.print_r($pagedSearchOK, true), \OCP\Util::ERROR);
1022 1022
 			return false;
1023 1023
 		}
@@ -1040,26 +1040,26 @@  discard block
 block discarded – undo
1040 1040
 	 */
1041 1041
 	private function processPagedSearchStatus($sr, $filter, $base, $iFoundItems, $limit, $offset, $pagedSearchOK, $skipHandling) {
1042 1042
 		$cookie = null;
1043
-		if($pagedSearchOK) {
1043
+		if ($pagedSearchOK) {
1044 1044
 			$cr = $this->connection->getConnectionResource();
1045
-			foreach($sr as $key => $res) {
1046
-				if($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) {
1045
+			foreach ($sr as $key => $res) {
1046
+				if ($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) {
1047 1047
 					$this->setPagedResultCookie($base[$key], $filter, $limit, $offset, $cookie);
1048 1048
 				}
1049 1049
 			}
1050 1050
 
1051 1051
 			//browsing through prior pages to get the cookie for the new one
1052
-			if($skipHandling) {
1052
+			if ($skipHandling) {
1053 1053
 				return false;
1054 1054
 			}
1055 1055
 			// if count is bigger, then the server does not support
1056 1056
 			// paged search. Instead, he did a normal search. We set a
1057 1057
 			// flag here, so the callee knows how to deal with it.
1058
-			if($iFoundItems <= $limit) {
1058
+			if ($iFoundItems <= $limit) {
1059 1059
 				$this->pagedSearchedSuccessful = true;
1060 1060
 			}
1061 1061
 		} else {
1062
-			if(!is_null($limit)) {
1062
+			if (!is_null($limit)) {
1063 1063
 				\OCP\Util::writeLog('user_ldap', 'Paged search was not available', \OCP\Util::INFO);
1064 1064
 			}
1065 1065
 		}
@@ -1088,7 +1088,7 @@  discard block
 block discarded – undo
1088 1088
 		\OCP\Util::writeLog('user_ldap', 'Count filter:  '.print_r($filter, true), \OCP\Util::DEBUG);
1089 1089
 
1090 1090
 		$limitPerPage = intval($this->connection->ldapPagingSize);
1091
-		if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1091
+		if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1092 1092
 			$limitPerPage = $limit;
1093 1093
 		}
1094 1094
 
@@ -1099,7 +1099,7 @@  discard block
 block discarded – undo
1099 1099
 		do {
1100 1100
 			$search = $this->executeSearch($filter, $base, $attr,
1101 1101
 										   $limitPerPage, $offset);
1102
-			if($search === false) {
1102
+			if ($search === false) {
1103 1103
 				return $counter > 0 ? $counter : false;
1104 1104
 			}
1105 1105
 			list($sr, $pagedSearchOK) = $search;
@@ -1118,7 +1118,7 @@  discard block
 block discarded – undo
1118 1118
 			 * Continue now depends on $hasMorePages value
1119 1119
 			 */
1120 1120
 			$continue = $pagedSearchOK && $hasMorePages;
1121
-		} while($continue && (is_null($limit) || $limit <= 0 || $limit > $counter));
1121
+		} while ($continue && (is_null($limit) || $limit <= 0 || $limit > $counter));
1122 1122
 
1123 1123
 		return $counter;
1124 1124
 	}
@@ -1130,7 +1130,7 @@  discard block
 block discarded – undo
1130 1130
 	private function countEntriesInSearchResults($searchResults) {
1131 1131
 		$counter = 0;
1132 1132
 
1133
-		foreach($searchResults as $res) {
1133
+		foreach ($searchResults as $res) {
1134 1134
 			$count = intval($this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res));
1135 1135
 			$counter += $count;
1136 1136
 		}
@@ -1149,7 +1149,7 @@  discard block
 block discarded – undo
1149 1149
 	 * @return array with the search result
1150 1150
 	 */
1151 1151
 	public function search($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) {
1152
-		if($limit <= 0) {
1152
+		if ($limit <= 0) {
1153 1153
 			//otherwise search will fail
1154 1154
 			$limit = null;
1155 1155
 		}
@@ -1164,13 +1164,13 @@  discard block
 block discarded – undo
1164 1164
 		$savedoffset = $offset;
1165 1165
 		do {
1166 1166
 			$search = $this->executeSearch($filter, $base, $attr, $limit, $offset);
1167
-			if($search === false) {
1167
+			if ($search === false) {
1168 1168
 				return array();
1169 1169
 			}
1170 1170
 			list($sr, $pagedSearchOK) = $search;
1171 1171
 			$cr = $this->connection->getConnectionResource();
1172 1172
 
1173
-			if($skipHandling) {
1173
+			if ($skipHandling) {
1174 1174
 				//i.e. result do not need to be fetched, we just need the cookie
1175 1175
 				//thus pass 1 or any other value as $iFoundItems because it is not
1176 1176
 				//used
@@ -1180,7 +1180,7 @@  discard block
 block discarded – undo
1180 1180
 				return array();
1181 1181
 			}
1182 1182
 
1183
-			foreach($sr as $res) {
1183
+			foreach ($sr as $res) {
1184 1184
 				$findings = array_merge($findings, $this->invokeLDAPMethod('getEntries', $cr, $res));
1185 1185
 			}
1186 1186
 
@@ -1194,25 +1194,25 @@  discard block
 block discarded – undo
1194 1194
 
1195 1195
 		// if we're here, probably no connection resource is returned.
1196 1196
 		// to make Nextcloud behave nicely, we simply give back an empty array.
1197
-		if(is_null($findings)) {
1197
+		if (is_null($findings)) {
1198 1198
 			return array();
1199 1199
 		}
1200 1200
 
1201
-		if(!is_null($attr)) {
1201
+		if (!is_null($attr)) {
1202 1202
 			$selection = array();
1203 1203
 			$i = 0;
1204
-			foreach($findings as $item) {
1205
-				if(!is_array($item)) {
1204
+			foreach ($findings as $item) {
1205
+				if (!is_array($item)) {
1206 1206
 					continue;
1207 1207
 				}
1208 1208
 				$item = \OCP\Util::mb_array_change_key_case($item, MB_CASE_LOWER, 'UTF-8');
1209
-				foreach($attr as $key) {
1209
+				foreach ($attr as $key) {
1210 1210
 					$key = mb_strtolower($key, 'UTF-8');
1211
-					if(isset($item[$key])) {
1212
-						if(is_array($item[$key]) && isset($item[$key]['count'])) {
1211
+					if (isset($item[$key])) {
1212
+						if (is_array($item[$key]) && isset($item[$key]['count'])) {
1213 1213
 							unset($item[$key]['count']);
1214 1214
 						}
1215
-						if($key !== 'dn') {
1215
+						if ($key !== 'dn') {
1216 1216
 							$selection[$i][$key] = $this->resemblesDN($key) ?
1217 1217
 								$this->helper->sanitizeDN($item[$key])
1218 1218
 								: $item[$key];
@@ -1229,7 +1229,7 @@  discard block
 block discarded – undo
1229 1229
 		//we slice the findings, when
1230 1230
 		//a) paged search unsuccessful, though attempted
1231 1231
 		//b) no paged search, but limit set
1232
-		if((!$this->getPagedSearchResultState()
1232
+		if ((!$this->getPagedSearchResultState()
1233 1233
 			&& $pagedSearchOK)
1234 1234
 			|| (
1235 1235
 				!$pagedSearchOK
@@ -1246,7 +1246,7 @@  discard block
 block discarded – undo
1246 1246
 	 * @return bool|mixed|string
1247 1247
 	 */
1248 1248
 	public function sanitizeUsername($name) {
1249
-		if($this->connection->ldapIgnoreNamingRules) {
1249
+		if ($this->connection->ldapIgnoreNamingRules) {
1250 1250
 			return $name;
1251 1251
 		}
1252 1252
 
@@ -1271,13 +1271,13 @@  discard block
 block discarded – undo
1271 1271
 	*/
1272 1272
 	public function escapeFilterPart($input, $allowAsterisk = false) {
1273 1273
 		$asterisk = '';
1274
-		if($allowAsterisk && strlen($input) > 0 && $input[0] === '*') {
1274
+		if ($allowAsterisk && strlen($input) > 0 && $input[0] === '*') {
1275 1275
 			$asterisk = '*';
1276 1276
 			$input = mb_substr($input, 1, null, 'UTF-8');
1277 1277
 		}
1278 1278
 		$search  = array('*', '\\', '(', ')');
1279 1279
 		$replace = array('\\*', '\\\\', '\\(', '\\)');
1280
-		return $asterisk . str_replace($search, $replace, $input);
1280
+		return $asterisk.str_replace($search, $replace, $input);
1281 1281
 	}
1282 1282
 
1283 1283
 	/**
@@ -1307,13 +1307,13 @@  discard block
 block discarded – undo
1307 1307
 	 */
1308 1308
 	private function combineFilter($filters, $operator) {
1309 1309
 		$combinedFilter = '('.$operator;
1310
-		foreach($filters as $filter) {
1310
+		foreach ($filters as $filter) {
1311 1311
 			if ($filter !== '' && $filter[0] !== '(') {
1312 1312
 				$filter = '('.$filter.')';
1313 1313
 			}
1314
-			$combinedFilter.=$filter;
1314
+			$combinedFilter .= $filter;
1315 1315
 		}
1316
-		$combinedFilter.=')';
1316
+		$combinedFilter .= ')';
1317 1317
 		return $combinedFilter;
1318 1318
 	}
1319 1319
 
@@ -1349,17 +1349,17 @@  discard block
 block discarded – undo
1349 1349
 	 * @throws \Exception
1350 1350
 	 */
1351 1351
 	private function getAdvancedFilterPartForSearch($search, $searchAttributes) {
1352
-		if(!is_array($searchAttributes) || count($searchAttributes) < 2) {
1352
+		if (!is_array($searchAttributes) || count($searchAttributes) < 2) {
1353 1353
 			throw new \Exception('searchAttributes must be an array with at least two string');
1354 1354
 		}
1355 1355
 		$searchWords = explode(' ', trim($search));
1356 1356
 		$wordFilters = array();
1357
-		foreach($searchWords as $word) {
1357
+		foreach ($searchWords as $word) {
1358 1358
 			$word = $this->prepareSearchTerm($word);
1359 1359
 			//every word needs to appear at least once
1360 1360
 			$wordMatchOneAttrFilters = array();
1361
-			foreach($searchAttributes as $attr) {
1362
-				$wordMatchOneAttrFilters[] = $attr . '=' . $word;
1361
+			foreach ($searchAttributes as $attr) {
1362
+				$wordMatchOneAttrFilters[] = $attr.'='.$word;
1363 1363
 			}
1364 1364
 			$wordFilters[] = $this->combineFilterWithOr($wordMatchOneAttrFilters);
1365 1365
 		}
@@ -1377,10 +1377,10 @@  discard block
 block discarded – undo
1377 1377
 	private function getFilterPartForSearch($search, $searchAttributes, $fallbackAttribute) {
1378 1378
 		$filter = array();
1379 1379
 		$haveMultiSearchAttributes = (is_array($searchAttributes) && count($searchAttributes) > 0);
1380
-		if($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) {
1380
+		if ($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) {
1381 1381
 			try {
1382 1382
 				return $this->getAdvancedFilterPartForSearch($search, $searchAttributes);
1383
-			} catch(\Exception $e) {
1383
+			} catch (\Exception $e) {
1384 1384
 				\OCP\Util::writeLog(
1385 1385
 					'user_ldap',
1386 1386
 					'Creating advanced filter for search failed, falling back to simple method.',
@@ -1390,17 +1390,17 @@  discard block
 block discarded – undo
1390 1390
 		}
1391 1391
 
1392 1392
 		$search = $this->prepareSearchTerm($search);
1393
-		if(!is_array($searchAttributes) || count($searchAttributes) === 0) {
1393
+		if (!is_array($searchAttributes) || count($searchAttributes) === 0) {
1394 1394
 			if ($fallbackAttribute === '') {
1395 1395
 				return '';
1396 1396
 			}
1397
-			$filter[] = $fallbackAttribute . '=' . $search;
1397
+			$filter[] = $fallbackAttribute.'='.$search;
1398 1398
 		} else {
1399
-			foreach($searchAttributes as $attribute) {
1400
-				$filter[] = $attribute . '=' . $search;
1399
+			foreach ($searchAttributes as $attribute) {
1400
+				$filter[] = $attribute.'='.$search;
1401 1401
 			}
1402 1402
 		}
1403
-		if(count($filter) === 1) {
1403
+		if (count($filter) === 1) {
1404 1404
 			return '('.$filter[0].')';
1405 1405
 		}
1406 1406
 		return $this->combineFilterWithOr($filter);
@@ -1421,7 +1421,7 @@  discard block
 block discarded – undo
1421 1421
 		if ($term === '') {
1422 1422
 			$result = '*';
1423 1423
 		} else if ($allowEnum !== 'no') {
1424
-			$result = $term . '*';
1424
+			$result = $term.'*';
1425 1425
 		}
1426 1426
 		return $result;
1427 1427
 	}
@@ -1433,7 +1433,7 @@  discard block
 block discarded – undo
1433 1433
 	public function getFilterForUserCount() {
1434 1434
 		$filter = $this->combineFilterWithAnd(array(
1435 1435
 			$this->connection->ldapUserFilter,
1436
-			$this->connection->ldapUserDisplayName . '=*'
1436
+			$this->connection->ldapUserDisplayName.'=*'
1437 1437
 		));
1438 1438
 
1439 1439
 		return $filter;
@@ -1451,7 +1451,7 @@  discard block
 block discarded – undo
1451 1451
 			'ldapAgentName' => $name,
1452 1452
 			'ldapAgentPassword' => $password
1453 1453
 		);
1454
-		if(!$testConnection->setConfiguration($credentials)) {
1454
+		if (!$testConnection->setConfiguration($credentials)) {
1455 1455
 			return false;
1456 1456
 		}
1457 1457
 		return $testConnection->bind();
@@ -1473,30 +1473,30 @@  discard block
 block discarded – undo
1473 1473
 			// Sacrebleu! The UUID attribute is unknown :( We need first an
1474 1474
 			// existing DN to be able to reliably detect it.
1475 1475
 			$result = $this->search($filter, $base, ['dn'], 1);
1476
-			if(!isset($result[0]) || !isset($result[0]['dn'])) {
1476
+			if (!isset($result[0]) || !isset($result[0]['dn'])) {
1477 1477
 				throw new \Exception('Cannot determine UUID attribute');
1478 1478
 			}
1479 1479
 			$dn = $result[0]['dn'][0];
1480
-			if(!$this->detectUuidAttribute($dn, true)) {
1480
+			if (!$this->detectUuidAttribute($dn, true)) {
1481 1481
 				throw new \Exception('Cannot determine UUID attribute');
1482 1482
 			}
1483 1483
 		} else {
1484 1484
 			// The UUID attribute is either known or an override is given.
1485 1485
 			// By calling this method we ensure that $this->connection->$uuidAttr
1486 1486
 			// is definitely set
1487
-			if(!$this->detectUuidAttribute('', true)) {
1487
+			if (!$this->detectUuidAttribute('', true)) {
1488 1488
 				throw new \Exception('Cannot determine UUID attribute');
1489 1489
 			}
1490 1490
 		}
1491 1491
 
1492 1492
 		$uuidAttr = $this->connection->ldapUuidUserAttribute;
1493
-		if($uuidAttr === 'guid' || $uuidAttr === 'objectguid') {
1493
+		if ($uuidAttr === 'guid' || $uuidAttr === 'objectguid') {
1494 1494
 			$uuid = $this->formatGuid2ForFilterUser($uuid);
1495 1495
 		}
1496 1496
 
1497
-		$filter = $uuidAttr . '=' . $uuid;
1497
+		$filter = $uuidAttr.'='.$uuid;
1498 1498
 		$result = $this->searchUsers($filter, ['dn'], 2);
1499
-		if(is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) {
1499
+		if (is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) {
1500 1500
 			// we put the count into account to make sure that this is
1501 1501
 			// really unique
1502 1502
 			return $result[0]['dn'][0];
@@ -1513,7 +1513,7 @@  discard block
 block discarded – undo
1513 1513
 	 * @return bool true on success, false otherwise
1514 1514
 	 */
1515 1515
 	private function detectUuidAttribute($dn, $isUser = true, $force = false) {
1516
-		if($isUser) {
1516
+		if ($isUser) {
1517 1517
 			$uuidAttr     = 'ldapUuidUserAttribute';
1518 1518
 			$uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
1519 1519
 		} else {
@@ -1521,7 +1521,7 @@  discard block
 block discarded – undo
1521 1521
 			$uuidOverride = $this->connection->ldapExpertUUIDGroupAttr;
1522 1522
 		}
1523 1523
 
1524
-		if(($this->connection->$uuidAttr !== 'auto') && !$force) {
1524
+		if (($this->connection->$uuidAttr !== 'auto') && !$force) {
1525 1525
 			return true;
1526 1526
 		}
1527 1527
 
@@ -1533,9 +1533,9 @@  discard block
 block discarded – undo
1533 1533
 		// for now, supported attributes are entryUUID, nsuniqueid, objectGUID, ipaUniqueID
1534 1534
 		$testAttributes = array('entryuuid', 'nsuniqueid', 'objectguid', 'guid', 'ipauniqueid');
1535 1535
 
1536
-		foreach($testAttributes as $attribute) {
1536
+		foreach ($testAttributes as $attribute) {
1537 1537
 			$value = $this->readAttribute($dn, $attribute);
1538
-			if(is_array($value) && isset($value[0]) && !empty($value[0])) {
1538
+			if (is_array($value) && isset($value[0]) && !empty($value[0])) {
1539 1539
 				\OCP\Util::writeLog('user_ldap',
1540 1540
 									'Setting '.$attribute.' as '.$uuidAttr,
1541 1541
 									\OCP\Util::DEBUG);
@@ -1556,7 +1556,7 @@  discard block
 block discarded – undo
1556 1556
 	 * @return string|bool
1557 1557
 	 */
1558 1558
 	public function getUUID($dn, $isUser = true) {
1559
-		if($isUser) {
1559
+		if ($isUser) {
1560 1560
 			$uuidAttr     = 'ldapUuidUserAttribute';
1561 1561
 			$uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
1562 1562
 		} else {
@@ -1565,15 +1565,15 @@  discard block
 block discarded – undo
1565 1565
 		}
1566 1566
 
1567 1567
 		$uuid = false;
1568
-		if($this->detectUuidAttribute($dn, $isUser)) {
1568
+		if ($this->detectUuidAttribute($dn, $isUser)) {
1569 1569
 			$uuid = $this->readAttribute($dn, $this->connection->$uuidAttr);
1570
-			if( !is_array($uuid)
1570
+			if (!is_array($uuid)
1571 1571
 				&& $uuidOverride !== ''
1572 1572
 				&& $this->detectUuidAttribute($dn, $isUser, true)) {
1573 1573
 					$uuid = $this->readAttribute($dn,
1574 1574
 												 $this->connection->$uuidAttr);
1575 1575
 			}
1576
-			if(is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) {
1576
+			if (is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) {
1577 1577
 				$uuid = $uuid[0];
1578 1578
 			}
1579 1579
 		}
@@ -1590,19 +1590,19 @@  discard block
 block discarded – undo
1590 1590
 	private function convertObjectGUID2Str($oguid) {
1591 1591
 		$hex_guid = bin2hex($oguid);
1592 1592
 		$hex_guid_to_guid_str = '';
1593
-		for($k = 1; $k <= 4; ++$k) {
1593
+		for ($k = 1; $k <= 4; ++$k) {
1594 1594
 			$hex_guid_to_guid_str .= substr($hex_guid, 8 - 2 * $k, 2);
1595 1595
 		}
1596 1596
 		$hex_guid_to_guid_str .= '-';
1597
-		for($k = 1; $k <= 2; ++$k) {
1597
+		for ($k = 1; $k <= 2; ++$k) {
1598 1598
 			$hex_guid_to_guid_str .= substr($hex_guid, 12 - 2 * $k, 2);
1599 1599
 		}
1600 1600
 		$hex_guid_to_guid_str .= '-';
1601
-		for($k = 1; $k <= 2; ++$k) {
1601
+		for ($k = 1; $k <= 2; ++$k) {
1602 1602
 			$hex_guid_to_guid_str .= substr($hex_guid, 16 - 2 * $k, 2);
1603 1603
 		}
1604
-		$hex_guid_to_guid_str .= '-' . substr($hex_guid, 16, 4);
1605
-		$hex_guid_to_guid_str .= '-' . substr($hex_guid, 20);
1604
+		$hex_guid_to_guid_str .= '-'.substr($hex_guid, 16, 4);
1605
+		$hex_guid_to_guid_str .= '-'.substr($hex_guid, 20);
1606 1606
 
1607 1607
 		return strtoupper($hex_guid_to_guid_str);
1608 1608
 	}
@@ -1619,11 +1619,11 @@  discard block
 block discarded – undo
1619 1619
 	 * @return string
1620 1620
 	 */
1621 1621
 	public function formatGuid2ForFilterUser($guid) {
1622
-		if(!is_string($guid)) {
1622
+		if (!is_string($guid)) {
1623 1623
 			throw new \InvalidArgumentException('String expected');
1624 1624
 		}
1625 1625
 		$blocks = explode('-', $guid);
1626
-		if(count($blocks) !== 5) {
1626
+		if (count($blocks) !== 5) {
1627 1627
 			/*
1628 1628
 			 * Why not throw an Exception instead? This method is a utility
1629 1629
 			 * called only when trying to figure out whether a "missing" known
@@ -1636,20 +1636,20 @@  discard block
 block discarded – undo
1636 1636
 			 * user. Instead we write a log message.
1637 1637
 			 */
1638 1638
 			\OC::$server->getLogger()->info(
1639
-				'Passed string does not resemble a valid GUID. Known UUID ' .
1639
+				'Passed string does not resemble a valid GUID. Known UUID '.
1640 1640
 				'({uuid}) probably does not match UUID configuration.',
1641
-				[ 'app' => 'user_ldap', 'uuid' => $guid ]
1641
+				['app' => 'user_ldap', 'uuid' => $guid]
1642 1642
 			);
1643 1643
 			return $guid;
1644 1644
 		}
1645
-		for($i=0; $i < 3; $i++) {
1645
+		for ($i = 0; $i < 3; $i++) {
1646 1646
 			$pairs = str_split($blocks[$i], 2);
1647 1647
 			$pairs = array_reverse($pairs);
1648 1648
 			$blocks[$i] = implode('', $pairs);
1649 1649
 		}
1650
-		for($i=0; $i < 5; $i++) {
1650
+		for ($i = 0; $i < 5; $i++) {
1651 1651
 			$pairs = str_split($blocks[$i], 2);
1652
-			$blocks[$i] = '\\' . implode('\\', $pairs);
1652
+			$blocks[$i] = '\\'.implode('\\', $pairs);
1653 1653
 		}
1654 1654
 		return implode('', $blocks);
1655 1655
 	}
@@ -1663,12 +1663,12 @@  discard block
 block discarded – undo
1663 1663
 		$domainDN = $this->getDomainDNFromDN($dn);
1664 1664
 		$cacheKey = 'getSID-'.$domainDN;
1665 1665
 		$sid = $this->connection->getFromCache($cacheKey);
1666
-		if(!is_null($sid)) {
1666
+		if (!is_null($sid)) {
1667 1667
 			return $sid;
1668 1668
 		}
1669 1669
 
1670 1670
 		$objectSid = $this->readAttribute($domainDN, 'objectsid');
1671
-		if(!is_array($objectSid) || empty($objectSid)) {
1671
+		if (!is_array($objectSid) || empty($objectSid)) {
1672 1672
 			$this->connection->writeToCache($cacheKey, false);
1673 1673
 			return false;
1674 1674
 		}
@@ -1726,12 +1726,12 @@  discard block
 block discarded – undo
1726 1726
 		$belongsToBase = false;
1727 1727
 		$bases = $this->helper->sanitizeDN($bases);
1728 1728
 
1729
-		foreach($bases as $base) {
1729
+		foreach ($bases as $base) {
1730 1730
 			$belongsToBase = true;
1731
-			if(mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8')-mb_strlen($base, 'UTF-8'))) {
1731
+			if (mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8') - mb_strlen($base, 'UTF-8'))) {
1732 1732
 				$belongsToBase = false;
1733 1733
 			}
1734
-			if($belongsToBase) {
1734
+			if ($belongsToBase) {
1735 1735
 				break;
1736 1736
 			}
1737 1737
 		}
@@ -1742,7 +1742,7 @@  discard block
 block discarded – undo
1742 1742
 	 * resets a running Paged Search operation
1743 1743
 	 */
1744 1744
 	private function abandonPagedSearch() {
1745
-		if($this->connection->hasPagedResultSupport) {
1745
+		if ($this->connection->hasPagedResultSupport) {
1746 1746
 			$cr = $this->connection->getConnectionResource();
1747 1747
 			$this->invokeLDAPMethod('controlPagedResult', $cr, 0, false, $this->lastCookie);
1748 1748
 			$this->getPagedSearchResultState();
@@ -1760,16 +1760,16 @@  discard block
 block discarded – undo
1760 1760
 	 * @return string containing the key or empty if none is cached
1761 1761
 	 */
1762 1762
 	private function getPagedResultCookie($base, $filter, $limit, $offset) {
1763
-		if($offset === 0) {
1763
+		if ($offset === 0) {
1764 1764
 			return '';
1765 1765
 		}
1766 1766
 		$offset -= $limit;
1767 1767
 		//we work with cache here
1768
-		$cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . intval($limit) . '-' . intval($offset);
1768
+		$cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.intval($limit).'-'.intval($offset);
1769 1769
 		$cookie = '';
1770
-		if(isset($this->cookies[$cacheKey])) {
1770
+		if (isset($this->cookies[$cacheKey])) {
1771 1771
 			$cookie = $this->cookies[$cacheKey];
1772
-			if(is_null($cookie)) {
1772
+			if (is_null($cookie)) {
1773 1773
 				$cookie = '';
1774 1774
 			}
1775 1775
 		}
@@ -1787,11 +1787,11 @@  discard block
 block discarded – undo
1787 1787
 	 * @return bool
1788 1788
 	 */
1789 1789
 	public function hasMoreResults() {
1790
-		if(!$this->connection->hasPagedResultSupport) {
1790
+		if (!$this->connection->hasPagedResultSupport) {
1791 1791
 			return false;
1792 1792
 		}
1793 1793
 
1794
-		if(empty($this->lastCookie) && $this->lastCookie !== '0') {
1794
+		if (empty($this->lastCookie) && $this->lastCookie !== '0') {
1795 1795
 			// as in RFC 2696, when all results are returned, the cookie will
1796 1796
 			// be empty.
1797 1797
 			return false;
@@ -1811,8 +1811,8 @@  discard block
 block discarded – undo
1811 1811
 	 */
1812 1812
 	private function setPagedResultCookie($base, $filter, $limit, $offset, $cookie) {
1813 1813
 		// allow '0' for 389ds
1814
-		if(!empty($cookie) || $cookie === '0') {
1815
-			$cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' .intval($limit) . '-' . intval($offset);
1814
+		if (!empty($cookie) || $cookie === '0') {
1815
+			$cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.intval($limit).'-'.intval($offset);
1816 1816
 			$this->cookies[$cacheKey] = $cookie;
1817 1817
 			$this->lastCookie = $cookie;
1818 1818
 		}
@@ -1839,17 +1839,17 @@  discard block
 block discarded – undo
1839 1839
 	 */
1840 1840
 	private function initPagedSearch($filter, $bases, $attr, $limit, $offset) {
1841 1841
 		$pagedSearchOK = false;
1842
-		if($this->connection->hasPagedResultSupport && ($limit !== 0)) {
1842
+		if ($this->connection->hasPagedResultSupport && ($limit !== 0)) {
1843 1843
 			$offset = intval($offset); //can be null
1844 1844
 			\OCP\Util::writeLog('user_ldap',
1845 1845
 				'initializing paged search for  Filter '.$filter.' base '.print_r($bases, true)
1846
-				.' attr '.print_r($attr, true). ' limit ' .$limit.' offset '.$offset,
1846
+				.' attr '.print_r($attr, true).' limit '.$limit.' offset '.$offset,
1847 1847
 				\OCP\Util::DEBUG);
1848 1848
 			//get the cookie from the search for the previous search, required by LDAP
1849
-			foreach($bases as $base) {
1849
+			foreach ($bases as $base) {
1850 1850
 
1851 1851
 				$cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset);
1852
-				if(empty($cookie) && $cookie !== "0" && ($offset > 0)) {
1852
+				if (empty($cookie) && $cookie !== "0" && ($offset > 0)) {
1853 1853
 					// no cookie known, although the offset is not 0. Maybe cache run out. We need
1854 1854
 					// to start all over *sigh* (btw, Dear Reader, did you know LDAP paged
1855 1855
 					// searching was designed by MSFT?)
@@ -1862,18 +1862,18 @@  discard block
 block discarded – undo
1862 1862
 					$cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset);
1863 1863
 					//still no cookie? obviously, the server does not like us. Let's skip paging efforts.
1864 1864
 					//TODO: remember this, probably does not change in the next request...
1865
-					if(empty($cookie) && $cookie !== '0') {
1865
+					if (empty($cookie) && $cookie !== '0') {
1866 1866
 						// '0' is valid, because 389ds
1867 1867
 						$cookie = null;
1868 1868
 					}
1869 1869
 				}
1870
-				if(!is_null($cookie)) {
1870
+				if (!is_null($cookie)) {
1871 1871
 					//since offset = 0, this is a new search. We abandon other searches that might be ongoing.
1872 1872
 					$this->abandonPagedSearch();
1873 1873
 					$pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult',
1874 1874
 						$this->connection->getConnectionResource(), $limit,
1875 1875
 						false, $cookie);
1876
-					if(!$pagedSearchOK) {
1876
+					if (!$pagedSearchOK) {
1877 1877
 						return false;
1878 1878
 					}
1879 1879
 					\OCP\Util::writeLog('user_ldap', 'Ready for a paged search', \OCP\Util::DEBUG);
@@ -1890,7 +1890,7 @@  discard block
 block discarded – undo
1890 1890
 		 * So we added "&& !empty($this->lastCookie)" to this test to ignore pagination
1891 1891
 		 * if we don't have a previous paged search.
1892 1892
 		 */
1893
-		} else if($this->connection->hasPagedResultSupport && $limit === 0 && !empty($this->lastCookie)) {
1893
+		} else if ($this->connection->hasPagedResultSupport && $limit === 0 && !empty($this->lastCookie)) {
1894 1894
 			// a search without limit was requested. However, if we do use
1895 1895
 			// Paged Search once, we always must do it. This requires us to
1896 1896
 			// initialize it with the configured page size.
Please login to merge, or discard this patch.