Completed
Pull Request — master (#7418)
by Blizzz
13:24
created
apps/user_ldap/lib/Access.php 1 patch
Spacing   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 	 * @return AbstractMapping
125 125
 	 */
126 126
 	public function getUserMapper() {
127
-		if(is_null($this->userMapper)) {
127
+		if (is_null($this->userMapper)) {
128 128
 			throw new \Exception('UserMapper was not assigned to this Access instance.');
129 129
 		}
130 130
 		return $this->userMapper;
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 	 * @return AbstractMapping
145 145
 	 */
146 146
 	public function getGroupMapper() {
147
-		if(is_null($this->groupMapper)) {
147
+		if (is_null($this->groupMapper)) {
148 148
 			throw new \Exception('GroupMapper was not assigned to this Access instance.');
149 149
 		}
150 150
 		return $this->groupMapper;
@@ -175,14 +175,14 @@  discard block
 block discarded – undo
175 175
 	 *          array if $attr is empty, false otherwise
176 176
 	 */
177 177
 	public function readAttribute($dn, $attr, $filter = 'objectClass=*') {
178
-		if(!$this->checkConnection()) {
178
+		if (!$this->checkConnection()) {
179 179
 			\OCP\Util::writeLog('user_ldap',
180 180
 				'No LDAP Connector assigned, access impossible for readAttribute.',
181 181
 				\OCP\Util::WARN);
182 182
 			return false;
183 183
 		}
184 184
 		$cr = $this->connection->getConnectionResource();
185
-		if(!$this->ldap->isResource($cr)) {
185
+		if (!$this->ldap->isResource($cr)) {
186 186
 			//LDAP not available
187 187
 			\OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG);
188 188
 			return false;
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 		$isRangeRequest = false;
206 206
 		do {
207 207
 			$result = $this->executeRead($cr, $dn, $attrToRead, $filter, $maxResults);
208
-			if(is_bool($result)) {
208
+			if (is_bool($result)) {
209 209
 				// when an exists request was run and it was successful, an empty
210 210
 				// array must be returned
211 211
 				return $result ? [] : false;
@@ -222,22 +222,22 @@  discard block
 block discarded – undo
222 222
 			$result = $this->extractRangeData($result, $attr);
223 223
 			if (!empty($result)) {
224 224
 				$normalizedResult = $this->extractAttributeValuesFromResult(
225
-					[ $attr => $result['values'] ],
225
+					[$attr => $result['values']],
226 226
 					$attr
227 227
 				);
228 228
 				$values = array_merge($values, $normalizedResult);
229 229
 
230
-				if($result['rangeHigh'] === '*') {
230
+				if ($result['rangeHigh'] === '*') {
231 231
 					// when server replies with * as high range value, there are
232 232
 					// no more results left
233 233
 					return $values;
234 234
 				} else {
235
-					$low  = $result['rangeHigh'] + 1;
236
-					$attrToRead = $result['attributeName'] . ';range=' . $low . '-*';
235
+					$low = $result['rangeHigh'] + 1;
236
+					$attrToRead = $result['attributeName'].';range='.$low.'-*';
237 237
 					$isRangeRequest = true;
238 238
 				}
239 239
 			}
240
-		} while($isRangeRequest);
240
+		} while ($isRangeRequest);
241 241
 
242 242
 		\OCP\Util::writeLog('user_ldap', 'Requested attribute '.$attr.' not found for '.$dn, \OCP\Util::DEBUG);
243 243
 		return false;
@@ -262,13 +262,13 @@  discard block
 block discarded – undo
262 262
 		if (!$this->ldap->isResource($rr)) {
263 263
 			if ($attribute !== '') {
264 264
 				//do not throw this message on userExists check, irritates
265
-				\OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN ' . $dn, \OCP\Util::DEBUG);
265
+				\OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN '.$dn, \OCP\Util::DEBUG);
266 266
 			}
267 267
 			//in case an error occurs , e.g. object does not exist
268 268
 			return false;
269 269
 		}
270 270
 		if ($attribute === '' && ($filter === 'objectclass=*' || $this->invokeLDAPMethod('countEntries', $cr, $rr) === 1)) {
271
-			\OCP\Util::writeLog('user_ldap', 'readAttribute: ' . $dn . ' found', \OCP\Util::DEBUG);
271
+			\OCP\Util::writeLog('user_ldap', 'readAttribute: '.$dn.' found', \OCP\Util::DEBUG);
272 272
 			return true;
273 273
 		}
274 274
 		$er = $this->invokeLDAPMethod('firstEntry', $cr, $rr);
@@ -293,12 +293,12 @@  discard block
 block discarded – undo
293 293
 	 */
294 294
 	public function extractAttributeValuesFromResult($result, $attribute) {
295 295
 		$values = [];
296
-		if(isset($result[$attribute]) && $result[$attribute]['count'] > 0) {
296
+		if (isset($result[$attribute]) && $result[$attribute]['count'] > 0) {
297 297
 			$lowercaseAttribute = strtolower($attribute);
298
-			for($i=0;$i<$result[$attribute]['count'];$i++) {
299
-				if($this->resemblesDN($attribute)) {
298
+			for ($i = 0; $i < $result[$attribute]['count']; $i++) {
299
+				if ($this->resemblesDN($attribute)) {
300 300
 					$values[] = $this->helper->sanitizeDN($result[$attribute][$i]);
301
-				} elseif($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') {
301
+				} elseif ($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') {
302 302
 					$values[] = $this->convertObjectGUID2Str($result[$attribute][$i]);
303 303
 				} else {
304 304
 					$values[] = $result[$attribute][$i];
@@ -320,10 +320,10 @@  discard block
 block discarded – undo
320 320
 	 */
321 321
 	public function extractRangeData($result, $attribute) {
322 322
 		$keys = array_keys($result);
323
-		foreach($keys as $key) {
324
-			if($key !== $attribute && strpos($key, $attribute) === 0) {
323
+		foreach ($keys as $key) {
324
+			if ($key !== $attribute && strpos($key, $attribute) === 0) {
325 325
 				$queryData = explode(';', $key);
326
-				if(strpos($queryData[1], 'range=') === 0) {
326
+				if (strpos($queryData[1], 'range=') === 0) {
327 327
 					$high = substr($queryData[1], 1 + strpos($queryData[1], '-'));
328 328
 					$data = [
329 329
 						'values' => $result[$key],
@@ -348,18 +348,18 @@  discard block
 block discarded – undo
348 348
 	 * @throws \Exception
349 349
 	 */
350 350
 	public function setPassword($userDN, $password) {
351
-		if(intval($this->connection->turnOnPasswordChange) !== 1) {
351
+		if (intval($this->connection->turnOnPasswordChange) !== 1) {
352 352
 			throw new \Exception('LDAP password changes are disabled.');
353 353
 		}
354 354
 		$cr = $this->connection->getConnectionResource();
355
-		if(!$this->ldap->isResource($cr)) {
355
+		if (!$this->ldap->isResource($cr)) {
356 356
 			//LDAP not available
357 357
 			\OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG);
358 358
 			return false;
359 359
 		}
360 360
 		try {
361 361
 			return @$this->invokeLDAPMethod('modReplace', $cr, $userDN, $password);
362
-		} catch(ConstraintViolationException $e) {
362
+		} catch (ConstraintViolationException $e) {
363 363
 			throw new HintException('Password change rejected.', \OC::$server->getL10N('user_ldap')->t('Password change rejected. Hint: ').$e->getMessage(), $e->getCode());
364 364
 		}
365 365
 	}
@@ -401,17 +401,17 @@  discard block
 block discarded – undo
401 401
 	 */
402 402
 	public function getDomainDNFromDN($dn) {
403 403
 		$allParts = $this->ldap->explodeDN($dn, 0);
404
-		if($allParts === false) {
404
+		if ($allParts === false) {
405 405
 			//not a valid DN
406 406
 			return '';
407 407
 		}
408 408
 		$domainParts = array();
409 409
 		$dcFound = false;
410
-		foreach($allParts as $part) {
411
-			if(!$dcFound && strpos($part, 'dc=') === 0) {
410
+		foreach ($allParts as $part) {
411
+			if (!$dcFound && strpos($part, 'dc=') === 0) {
412 412
 				$dcFound = true;
413 413
 			}
414
-			if($dcFound) {
414
+			if ($dcFound) {
415 415
 				$domainParts[] = $part;
416 416
 			}
417 417
 		}
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
 
439 439
 		//Check whether the DN belongs to the Base, to avoid issues on multi-
440 440
 		//server setups
441
-		if(is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
441
+		if (is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
442 442
 			return $fdn;
443 443
 		}
444 444
 
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
 		//To avoid bypassing the base DN settings under certain circumstances
456 456
 		//with the group support, check whether the provided DN matches one of
457 457
 		//the given Bases
458
-		if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) {
458
+		if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) {
459 459
 			return false;
460 460
 		}
461 461
 
@@ -472,11 +472,11 @@  discard block
 block discarded – undo
472 472
 	 */
473 473
 	public function groupsMatchFilter($groupDNs) {
474 474
 		$validGroupDNs = [];
475
-		foreach($groupDNs as $dn) {
475
+		foreach ($groupDNs as $dn) {
476 476
 			$cacheKey = 'groupsMatchFilter-'.$dn;
477 477
 			$groupMatchFilter = $this->connection->getFromCache($cacheKey);
478
-			if(!is_null($groupMatchFilter)) {
479
-				if($groupMatchFilter) {
478
+			if (!is_null($groupMatchFilter)) {
479
+				if ($groupMatchFilter) {
480 480
 					$validGroupDNs[] = $dn;
481 481
 				}
482 482
 				continue;
@@ -484,13 +484,13 @@  discard block
 block discarded – undo
484 484
 
485 485
 			// Check the base DN first. If this is not met already, we don't
486 486
 			// need to ask the server at all.
487
-			if(!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) {
487
+			if (!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) {
488 488
 				$this->connection->writeToCache($cacheKey, false);
489 489
 				continue;
490 490
 			}
491 491
 
492 492
 			$result = $this->readAttribute($dn, 'cn', $this->connection->ldapGroupFilter);
493
-			if(is_array($result)) {
493
+			if (is_array($result)) {
494 494
 				$this->connection->writeToCache($cacheKey, true);
495 495
 				$validGroupDNs[] = $dn;
496 496
 			} else {
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
 		//To avoid bypassing the base DN settings under certain circumstances
512 512
 		//with the group support, check whether the provided DN matches one of
513 513
 		//the given Bases
514
-		if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
514
+		if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
515 515
 			return false;
516 516
 		}
517 517
 
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
 	 */
532 532
 	public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped = null, array $record = null) {
533 533
 		$newlyMapped = false;
534
-		if($isUser) {
534
+		if ($isUser) {
535 535
 			$mapper = $this->getUserMapper();
536 536
 			$nameAttribute = $this->connection->ldapUserDisplayName;
537 537
 		} else {
@@ -541,15 +541,15 @@  discard block
 block discarded – undo
541 541
 
542 542
 		//let's try to retrieve the Nextcloud name from the mappings table
543 543
 		$ncName = $mapper->getNameByDN($fdn);
544
-		if(is_string($ncName)) {
544
+		if (is_string($ncName)) {
545 545
 			return $ncName;
546 546
 		}
547 547
 
548 548
 		//second try: get the UUID and check if it is known. Then, update the DN and return the name.
549 549
 		$uuid = $this->getUUID($fdn, $isUser, $record);
550
-		if(is_string($uuid)) {
550
+		if (is_string($uuid)) {
551 551
 			$ncName = $mapper->getNameByUUID($uuid);
552
-			if(is_string($ncName)) {
552
+			if (is_string($ncName)) {
553 553
 				$mapper->setDNbyUUID($fdn, $uuid);
554 554
 				return $ncName;
555 555
 			}
@@ -559,16 +559,16 @@  discard block
 block discarded – undo
559 559
 			return false;
560 560
 		}
561 561
 
562
-		if(is_null($ldapName)) {
562
+		if (is_null($ldapName)) {
563 563
 			$ldapName = $this->readAttribute($fdn, $nameAttribute);
564
-			if(!isset($ldapName[0]) && empty($ldapName[0])) {
564
+			if (!isset($ldapName[0]) && empty($ldapName[0])) {
565 565
 				\OCP\Util::writeLog('user_ldap', 'No or empty name for '.$fdn.'.', \OCP\Util::INFO);
566 566
 				return false;
567 567
 			}
568 568
 			$ldapName = $ldapName[0];
569 569
 		}
570 570
 
571
-		if($isUser) {
571
+		if ($isUser) {
572 572
 			$usernameAttribute = strval($this->connection->ldapExpertUsernameAttr);
573 573
 			if ($usernameAttribute !== '') {
574 574
 				$username = $this->readAttribute($fdn, $usernameAttribute);
@@ -587,9 +587,9 @@  discard block
 block discarded – undo
587 587
 		// outside of core user management will still cache the user as non-existing.
588 588
 		$originalTTL = $this->connection->ldapCacheTTL;
589 589
 		$this->connection->setConfiguration(array('ldapCacheTTL' => 0));
590
-		if(($isUser && $intName !== '' && !\OCP\User::userExists($intName))
590
+		if (($isUser && $intName !== '' && !\OCP\User::userExists($intName))
591 591
 			|| (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))) {
592
-			if($mapper->map($fdn, $intName, $uuid)) {
592
+			if ($mapper->map($fdn, $intName, $uuid)) {
593 593
 				$this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL));
594 594
 				$newlyMapped = true;
595 595
 				return $intName;
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
 		$this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL));
599 599
 
600 600
 		$altName = $this->createAltInternalOwnCloudName($intName, $isUser);
601
-		if(is_string($altName) && $mapper->map($fdn, $altName, $uuid)) {
601
+		if (is_string($altName) && $mapper->map($fdn, $altName, $uuid)) {
602 602
 			$newlyMapped = true;
603 603
 			return $altName;
604 604
 		}
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
 	 * @return array
637 637
 	 */
638 638
 	private function ldap2NextcloudNames($ldapObjects, $isUsers) {
639
-		if($isUsers) {
639
+		if ($isUsers) {
640 640
 			$nameAttribute = $this->connection->ldapUserDisplayName;
641 641
 			$sndAttribute  = $this->connection->ldapUserDisplayName2;
642 642
 		} else {
@@ -644,9 +644,9 @@  discard block
 block discarded – undo
644 644
 		}
645 645
 		$nextcloudNames = array();
646 646
 
647
-		foreach($ldapObjects as $ldapObject) {
647
+		foreach ($ldapObjects as $ldapObject) {
648 648
 			$nameByLDAP = null;
649
-			if(    isset($ldapObject[$nameAttribute])
649
+			if (isset($ldapObject[$nameAttribute])
650 650
 				&& is_array($ldapObject[$nameAttribute])
651 651
 				&& isset($ldapObject[$nameAttribute][0])
652 652
 			) {
@@ -655,12 +655,12 @@  discard block
 block discarded – undo
655 655
 			}
656 656
 
657 657
 			$ncName = $this->dn2ocname($ldapObject['dn'][0], $nameByLDAP, $isUsers);
658
-			if($ncName) {
658
+			if ($ncName) {
659 659
 				$nextcloudNames[] = $ncName;
660
-				if($isUsers) {
660
+				if ($isUsers) {
661 661
 					//cache the user names so it does not need to be retrieved
662 662
 					//again later (e.g. sharing dialogue).
663
-					if(is_null($nameByLDAP)) {
663
+					if (is_null($nameByLDAP)) {
664 664
 						continue;
665 665
 					}
666 666
 					$sndName = isset($ldapObject[$sndAttribute][0])
@@ -698,7 +698,7 @@  discard block
 block discarded – undo
698 698
 	 */
699 699
 	public function cacheUserDisplayName($ocName, $displayName, $displayName2 = '') {
700 700
 		$user = $this->userManager->get($ocName);
701
-		if($user === null) {
701
+		if ($user === null) {
702 702
 			return;
703 703
 		}
704 704
 		$displayName = $user->composeAndStoreDisplayName($displayName, $displayName2);
@@ -718,9 +718,9 @@  discard block
 block discarded – undo
718 718
 		$attempts = 0;
719 719
 		//while loop is just a precaution. If a name is not generated within
720 720
 		//20 attempts, something else is very wrong. Avoids infinite loop.
721
-		while($attempts < 20){
722
-			$altName = $name . '_' . rand(1000,9999);
723
-			if(!\OCP\User::userExists($altName)) {
721
+		while ($attempts < 20) {
722
+			$altName = $name.'_'.rand(1000, 9999);
723
+			if (!\OCP\User::userExists($altName)) {
724 724
 				return $altName;
725 725
 			}
726 726
 			$attempts++;
@@ -742,25 +742,25 @@  discard block
 block discarded – undo
742 742
 	 */
743 743
 	private function _createAltInternalOwnCloudNameForGroups($name) {
744 744
 		$usedNames = $this->groupMapper->getNamesBySearch($name, "", '_%');
745
-		if(!($usedNames) || count($usedNames) === 0) {
745
+		if (!($usedNames) || count($usedNames) === 0) {
746 746
 			$lastNo = 1; //will become name_2
747 747
 		} else {
748 748
 			natsort($usedNames);
749 749
 			$lastName = array_pop($usedNames);
750 750
 			$lastNo = intval(substr($lastName, strrpos($lastName, '_') + 1));
751 751
 		}
752
-		$altName = $name.'_'.strval($lastNo+1);
752
+		$altName = $name.'_'.strval($lastNo + 1);
753 753
 		unset($usedNames);
754 754
 
755 755
 		$attempts = 1;
756
-		while($attempts < 21){
756
+		while ($attempts < 21) {
757 757
 			// Check to be really sure it is unique
758 758
 			// while loop is just a precaution. If a name is not generated within
759 759
 			// 20 attempts, something else is very wrong. Avoids infinite loop.
760
-			if(!\OC::$server->getGroupManager()->groupExists($altName)) {
760
+			if (!\OC::$server->getGroupManager()->groupExists($altName)) {
761 761
 				return $altName;
762 762
 			}
763
-			$altName = $name . '_' . ($lastNo + $attempts);
763
+			$altName = $name.'_'.($lastNo + $attempts);
764 764
 			$attempts++;
765 765
 		}
766 766
 		return false;
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
 	private function createAltInternalOwnCloudName($name, $isUser) {
776 776
 		$originalTTL = $this->connection->ldapCacheTTL;
777 777
 		$this->connection->setConfiguration(array('ldapCacheTTL' => 0));
778
-		if($isUser) {
778
+		if ($isUser) {
779 779
 			$altName = $this->_createAltInternalOwnCloudNameForUsers($name);
780 780
 		} else {
781 781
 			$altName = $this->_createAltInternalOwnCloudNameForGroups($name);
@@ -825,13 +825,13 @@  discard block
 block discarded – undo
825 825
 	public function fetchListOfUsers($filter, $attr, $limit = null, $offset = null, $forceApplyAttributes = false) {
826 826
 		$ldapRecords = $this->searchUsers($filter, $attr, $limit, $offset);
827 827
 		$recordsToUpdate = $ldapRecords;
828
-		if(!$forceApplyAttributes) {
828
+		if (!$forceApplyAttributes) {
829 829
 			$isBackgroundJobModeAjax = $this->config
830 830
 					->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax';
831 831
 			$recordsToUpdate = array_filter($ldapRecords, function($record) use ($isBackgroundJobModeAjax) {
832 832
 				$newlyMapped = false;
833 833
 				$uid = $this->dn2ocname($record['dn'][0], null, true, $newlyMapped, $record);
834
-				if(is_string($uid)) {
834
+				if (is_string($uid)) {
835 835
 					$this->cacheUserExists($uid);
836 836
 				}
837 837
 				return ($uid !== false) && ($newlyMapped || $isBackgroundJobModeAjax);
@@ -847,19 +847,19 @@  discard block
 block discarded – undo
847 847
 	 * and their values
848 848
 	 * @param array $ldapRecords
849 849
 	 */
850
-	public function batchApplyUserAttributes(array $ldapRecords){
850
+	public function batchApplyUserAttributes(array $ldapRecords) {
851 851
 		$displayNameAttribute = strtolower($this->connection->ldapUserDisplayName);
852
-		foreach($ldapRecords as $userRecord) {
853
-			if(!isset($userRecord[$displayNameAttribute])) {
852
+		foreach ($ldapRecords as $userRecord) {
853
+			if (!isset($userRecord[$displayNameAttribute])) {
854 854
 				// displayName is obligatory
855 855
 				continue;
856 856
 			}
857
-			$ocName  = $this->dn2ocname($userRecord['dn'][0], null, true);
858
-			if($ocName === false) {
857
+			$ocName = $this->dn2ocname($userRecord['dn'][0], null, true);
858
+			if ($ocName === false) {
859 859
 				continue;
860 860
 			}
861 861
 			$user = $this->userManager->get($ocName);
862
-			if($user instanceof OfflineUser) {
862
+			if ($user instanceof OfflineUser) {
863 863
 				$user->unmark();
864 864
 				$user = $this->userManager->get($ocName);
865 865
 			}
@@ -891,8 +891,8 @@  discard block
 block discarded – undo
891 891
 	 * @return array
892 892
 	 */
893 893
 	private function fetchList($list, $manyAttributes) {
894
-		if(is_array($list)) {
895
-			if($manyAttributes) {
894
+		if (is_array($list)) {
895
+			if ($manyAttributes) {
896 896
 				return $list;
897 897
 			} else {
898 898
 				$list = array_reduce($list, function($carry, $item) {
@@ -990,7 +990,7 @@  discard block
 block discarded – undo
990 990
 		// php no longer supports call-time pass-by-reference
991 991
 		// thus cannot support controlPagedResultResponse as the third argument
992 992
 		// is a reference
993
-		$doMethod = function () use ($command, &$arguments) {
993
+		$doMethod = function() use ($command, &$arguments) {
994 994
 			if ($command == 'controlPagedResultResponse') {
995 995
 				throw new \InvalidArgumentException('Invoker does not support controlPagedResultResponse, call LDAP Wrapper directly instead.');
996 996
 			} else {
@@ -1008,7 +1008,7 @@  discard block
 block discarded – undo
1008 1008
 			$this->connection->resetConnectionResource();
1009 1009
 			$cr = $this->connection->getConnectionResource();
1010 1010
 
1011
-			if(!$this->ldap->isResource($cr)) {
1011
+			if (!$this->ldap->isResource($cr)) {
1012 1012
 				// Seems like we didn't find any resource.
1013 1013
 				\OCP\Util::writeLog('user_ldap', "Could not $command, because resource is missing.", \OCP\Util::DEBUG);
1014 1014
 				throw $e;
@@ -1033,13 +1033,13 @@  discard block
 block discarded – undo
1033 1033
 	 * @throws ServerNotAvailableException
1034 1034
 	 */
1035 1035
 	private function executeSearch($filter, $base, &$attr = null, $limit = null, $offset = null) {
1036
-		if(!is_null($attr) && !is_array($attr)) {
1036
+		if (!is_null($attr) && !is_array($attr)) {
1037 1037
 			$attr = array(mb_strtolower($attr, 'UTF-8'));
1038 1038
 		}
1039 1039
 
1040 1040
 		// See if we have a resource, in case not cancel with message
1041 1041
 		$cr = $this->connection->getConnectionResource();
1042
-		if(!$this->ldap->isResource($cr)) {
1042
+		if (!$this->ldap->isResource($cr)) {
1043 1043
 			// Seems like we didn't find any resource.
1044 1044
 			// Return an empty array just like before.
1045 1045
 			\OCP\Util::writeLog('user_ldap', 'Could not search, because resource is missing.', \OCP\Util::DEBUG);
@@ -1053,7 +1053,7 @@  discard block
 block discarded – undo
1053 1053
 		$sr = $this->invokeLDAPMethod('search', $linkResources, $base, $filter, $attr);
1054 1054
 		// cannot use $cr anymore, might have changed in the previous call!
1055 1055
 		$error = $this->ldap->errno($this->connection->getConnectionResource());
1056
-		if(!is_array($sr) || $error !== 0) {
1056
+		if (!is_array($sr) || $error !== 0) {
1057 1057
 			\OCP\Util::writeLog('user_ldap', 'Attempt for Paging?  '.print_r($pagedSearchOK, true), \OCP\Util::ERROR);
1058 1058
 			return false;
1059 1059
 		}
@@ -1076,26 +1076,26 @@  discard block
 block discarded – undo
1076 1076
 	 */
1077 1077
 	private function processPagedSearchStatus($sr, $filter, $base, $iFoundItems, $limit, $offset, $pagedSearchOK, $skipHandling) {
1078 1078
 		$cookie = null;
1079
-		if($pagedSearchOK) {
1079
+		if ($pagedSearchOK) {
1080 1080
 			$cr = $this->connection->getConnectionResource();
1081
-			foreach($sr as $key => $res) {
1082
-				if($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) {
1081
+			foreach ($sr as $key => $res) {
1082
+				if ($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) {
1083 1083
 					$this->setPagedResultCookie($base[$key], $filter, $limit, $offset, $cookie);
1084 1084
 				}
1085 1085
 			}
1086 1086
 
1087 1087
 			//browsing through prior pages to get the cookie for the new one
1088
-			if($skipHandling) {
1088
+			if ($skipHandling) {
1089 1089
 				return false;
1090 1090
 			}
1091 1091
 			// if count is bigger, then the server does not support
1092 1092
 			// paged search. Instead, he did a normal search. We set a
1093 1093
 			// flag here, so the callee knows how to deal with it.
1094
-			if($iFoundItems <= $limit) {
1094
+			if ($iFoundItems <= $limit) {
1095 1095
 				$this->pagedSearchedSuccessful = true;
1096 1096
 			}
1097 1097
 		} else {
1098
-			if(!is_null($limit)) {
1098
+			if (!is_null($limit)) {
1099 1099
 				\OCP\Util::writeLog('user_ldap', 'Paged search was not available', \OCP\Util::INFO);
1100 1100
 			}
1101 1101
 		}
@@ -1125,7 +1125,7 @@  discard block
 block discarded – undo
1125 1125
 		\OCP\Util::writeLog('user_ldap', 'Count filter:  '.print_r($filter, true), \OCP\Util::DEBUG);
1126 1126
 
1127 1127
 		$limitPerPage = intval($this->connection->ldapPagingSize);
1128
-		if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1128
+		if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1129 1129
 			$limitPerPage = $limit;
1130 1130
 		}
1131 1131
 
@@ -1135,7 +1135,7 @@  discard block
 block discarded – undo
1135 1135
 
1136 1136
 		do {
1137 1137
 			$search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset);
1138
-			if($search === false) {
1138
+			if ($search === false) {
1139 1139
 				return $counter > 0 ? $counter : false;
1140 1140
 			}
1141 1141
 			list($sr, $pagedSearchOK) = $search;
@@ -1154,7 +1154,7 @@  discard block
 block discarded – undo
1154 1154
 			 * Continue now depends on $hasMorePages value
1155 1155
 			 */
1156 1156
 			$continue = $pagedSearchOK && $hasMorePages;
1157
-		} while($continue && (is_null($limit) || $limit <= 0 || $limit > $counter));
1157
+		} while ($continue && (is_null($limit) || $limit <= 0 || $limit > $counter));
1158 1158
 
1159 1159
 		return $counter;
1160 1160
 	}
@@ -1166,7 +1166,7 @@  discard block
 block discarded – undo
1166 1166
 	private function countEntriesInSearchResults($searchResults) {
1167 1167
 		$counter = 0;
1168 1168
 
1169
-		foreach($searchResults as $res) {
1169
+		foreach ($searchResults as $res) {
1170 1170
 			$count = intval($this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res));
1171 1171
 			$counter += $count;
1172 1172
 		}
@@ -1188,7 +1188,7 @@  discard block
 block discarded – undo
1188 1188
 	 */
1189 1189
 	public function search($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) {
1190 1190
 		$limitPerPage = intval($this->connection->ldapPagingSize);
1191
-		if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1191
+		if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1192 1192
 			$limitPerPage = $limit;
1193 1193
 		}
1194 1194
 
@@ -1202,13 +1202,13 @@  discard block
 block discarded – undo
1202 1202
 		$savedoffset = $offset;
1203 1203
 		do {
1204 1204
 			$search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset);
1205
-			if($search === false) {
1205
+			if ($search === false) {
1206 1206
 				return [];
1207 1207
 			}
1208 1208
 			list($sr, $pagedSearchOK) = $search;
1209 1209
 			$cr = $this->connection->getConnectionResource();
1210 1210
 
1211
-			if($skipHandling) {
1211
+			if ($skipHandling) {
1212 1212
 				//i.e. result do not need to be fetched, we just need the cookie
1213 1213
 				//thus pass 1 or any other value as $iFoundItems because it is not
1214 1214
 				//used
@@ -1219,7 +1219,7 @@  discard block
 block discarded – undo
1219 1219
 			}
1220 1220
 
1221 1221
 			$iFoundItems = 0;
1222
-			foreach($sr as $res) {
1222
+			foreach ($sr as $res) {
1223 1223
 				$findings = array_merge($findings, $this->invokeLDAPMethod('getEntries', $cr, $res));
1224 1224
 				$iFoundItems = max($iFoundItems, $findings['count']);
1225 1225
 				unset($findings['count']);
@@ -1235,24 +1235,24 @@  discard block
 block discarded – undo
1235 1235
 
1236 1236
 		// if we're here, probably no connection resource is returned.
1237 1237
 		// to make Nextcloud behave nicely, we simply give back an empty array.
1238
-		if(is_null($findings)) {
1238
+		if (is_null($findings)) {
1239 1239
 			return array();
1240 1240
 		}
1241 1241
 
1242
-		if(!is_null($attr)) {
1242
+		if (!is_null($attr)) {
1243 1243
 			$selection = [];
1244 1244
 			$i = 0;
1245
-			foreach($findings as $item) {
1246
-				if(!is_array($item)) {
1245
+			foreach ($findings as $item) {
1246
+				if (!is_array($item)) {
1247 1247
 					continue;
1248 1248
 				}
1249 1249
 				$item = \OCP\Util::mb_array_change_key_case($item, MB_CASE_LOWER, 'UTF-8');
1250
-				foreach($attr as $key) {
1251
-					if(isset($item[$key])) {
1252
-						if(is_array($item[$key]) && isset($item[$key]['count'])) {
1250
+				foreach ($attr as $key) {
1251
+					if (isset($item[$key])) {
1252
+						if (is_array($item[$key]) && isset($item[$key]['count'])) {
1253 1253
 							unset($item[$key]['count']);
1254 1254
 						}
1255
-						if($key !== 'dn') {
1255
+						if ($key !== 'dn') {
1256 1256
 							$selection[$i][$key] = $this->resemblesDN($key) ?
1257 1257
 								$this->helper->sanitizeDN($item[$key])
1258 1258
 								: $key === 'objectguid' || $key === 'guid' ?
@@ -1271,7 +1271,7 @@  discard block
 block discarded – undo
1271 1271
 		//we slice the findings, when
1272 1272
 		//a) paged search unsuccessful, though attempted
1273 1273
 		//b) no paged search, but limit set
1274
-		if((!$this->getPagedSearchResultState()
1274
+		if ((!$this->getPagedSearchResultState()
1275 1275
 			&& $pagedSearchOK)
1276 1276
 			|| (
1277 1277
 				!$pagedSearchOK
@@ -1288,7 +1288,7 @@  discard block
 block discarded – undo
1288 1288
 	 * @return bool|mixed|string
1289 1289
 	 */
1290 1290
 	public function sanitizeUsername($name) {
1291
-		if($this->connection->ldapIgnoreNamingRules) {
1291
+		if ($this->connection->ldapIgnoreNamingRules) {
1292 1292
 			return trim($name);
1293 1293
 		}
1294 1294
 
@@ -1313,13 +1313,13 @@  discard block
 block discarded – undo
1313 1313
 	*/
1314 1314
 	public function escapeFilterPart($input, $allowAsterisk = false) {
1315 1315
 		$asterisk = '';
1316
-		if($allowAsterisk && strlen($input) > 0 && $input[0] === '*') {
1316
+		if ($allowAsterisk && strlen($input) > 0 && $input[0] === '*') {
1317 1317
 			$asterisk = '*';
1318 1318
 			$input = mb_substr($input, 1, null, 'UTF-8');
1319 1319
 		}
1320 1320
 		$search  = array('*', '\\', '(', ')');
1321 1321
 		$replace = array('\\*', '\\\\', '\\(', '\\)');
1322
-		return $asterisk . str_replace($search, $replace, $input);
1322
+		return $asterisk.str_replace($search, $replace, $input);
1323 1323
 	}
1324 1324
 
1325 1325
 	/**
@@ -1349,13 +1349,13 @@  discard block
 block discarded – undo
1349 1349
 	 */
1350 1350
 	private function combineFilter($filters, $operator) {
1351 1351
 		$combinedFilter = '('.$operator;
1352
-		foreach($filters as $filter) {
1352
+		foreach ($filters as $filter) {
1353 1353
 			if ($filter !== '' && $filter[0] !== '(') {
1354 1354
 				$filter = '('.$filter.')';
1355 1355
 			}
1356
-			$combinedFilter.=$filter;
1356
+			$combinedFilter .= $filter;
1357 1357
 		}
1358
-		$combinedFilter.=')';
1358
+		$combinedFilter .= ')';
1359 1359
 		return $combinedFilter;
1360 1360
 	}
1361 1361
 
@@ -1391,17 +1391,17 @@  discard block
 block discarded – undo
1391 1391
 	 * @throws \Exception
1392 1392
 	 */
1393 1393
 	private function getAdvancedFilterPartForSearch($search, $searchAttributes) {
1394
-		if(!is_array($searchAttributes) || count($searchAttributes) < 2) {
1394
+		if (!is_array($searchAttributes) || count($searchAttributes) < 2) {
1395 1395
 			throw new \Exception('searchAttributes must be an array with at least two string');
1396 1396
 		}
1397 1397
 		$searchWords = explode(' ', trim($search));
1398 1398
 		$wordFilters = array();
1399
-		foreach($searchWords as $word) {
1399
+		foreach ($searchWords as $word) {
1400 1400
 			$word = $this->prepareSearchTerm($word);
1401 1401
 			//every word needs to appear at least once
1402 1402
 			$wordMatchOneAttrFilters = array();
1403
-			foreach($searchAttributes as $attr) {
1404
-				$wordMatchOneAttrFilters[] = $attr . '=' . $word;
1403
+			foreach ($searchAttributes as $attr) {
1404
+				$wordMatchOneAttrFilters[] = $attr.'='.$word;
1405 1405
 			}
1406 1406
 			$wordFilters[] = $this->combineFilterWithOr($wordMatchOneAttrFilters);
1407 1407
 		}
@@ -1419,10 +1419,10 @@  discard block
 block discarded – undo
1419 1419
 	private function getFilterPartForSearch($search, $searchAttributes, $fallbackAttribute) {
1420 1420
 		$filter = array();
1421 1421
 		$haveMultiSearchAttributes = (is_array($searchAttributes) && count($searchAttributes) > 0);
1422
-		if($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) {
1422
+		if ($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) {
1423 1423
 			try {
1424 1424
 				return $this->getAdvancedFilterPartForSearch($search, $searchAttributes);
1425
-			} catch(\Exception $e) {
1425
+			} catch (\Exception $e) {
1426 1426
 				\OCP\Util::writeLog(
1427 1427
 					'user_ldap',
1428 1428
 					'Creating advanced filter for search failed, falling back to simple method.',
@@ -1432,17 +1432,17 @@  discard block
 block discarded – undo
1432 1432
 		}
1433 1433
 
1434 1434
 		$search = $this->prepareSearchTerm($search);
1435
-		if(!is_array($searchAttributes) || count($searchAttributes) === 0) {
1435
+		if (!is_array($searchAttributes) || count($searchAttributes) === 0) {
1436 1436
 			if ($fallbackAttribute === '') {
1437 1437
 				return '';
1438 1438
 			}
1439
-			$filter[] = $fallbackAttribute . '=' . $search;
1439
+			$filter[] = $fallbackAttribute.'='.$search;
1440 1440
 		} else {
1441
-			foreach($searchAttributes as $attribute) {
1442
-				$filter[] = $attribute . '=' . $search;
1441
+			foreach ($searchAttributes as $attribute) {
1442
+				$filter[] = $attribute.'='.$search;
1443 1443
 			}
1444 1444
 		}
1445
-		if(count($filter) === 1) {
1445
+		if (count($filter) === 1) {
1446 1446
 			return '('.$filter[0].')';
1447 1447
 		}
1448 1448
 		return $this->combineFilterWithOr($filter);
@@ -1463,7 +1463,7 @@  discard block
 block discarded – undo
1463 1463
 		if ($term === '') {
1464 1464
 			$result = '*';
1465 1465
 		} else if ($allowEnum !== 'no') {
1466
-			$result = $term . '*';
1466
+			$result = $term.'*';
1467 1467
 		}
1468 1468
 		return $result;
1469 1469
 	}
@@ -1475,7 +1475,7 @@  discard block
 block discarded – undo
1475 1475
 	public function getFilterForUserCount() {
1476 1476
 		$filter = $this->combineFilterWithAnd(array(
1477 1477
 			$this->connection->ldapUserFilter,
1478
-			$this->connection->ldapUserDisplayName . '=*'
1478
+			$this->connection->ldapUserDisplayName.'=*'
1479 1479
 		));
1480 1480
 
1481 1481
 		return $filter;
@@ -1493,7 +1493,7 @@  discard block
 block discarded – undo
1493 1493
 			'ldapAgentName' => $name,
1494 1494
 			'ldapAgentPassword' => $password
1495 1495
 		);
1496
-		if(!$testConnection->setConfiguration($credentials)) {
1496
+		if (!$testConnection->setConfiguration($credentials)) {
1497 1497
 			return false;
1498 1498
 		}
1499 1499
 		return $testConnection->bind();
@@ -1515,30 +1515,30 @@  discard block
 block discarded – undo
1515 1515
 			// Sacrebleu! The UUID attribute is unknown :( We need first an
1516 1516
 			// existing DN to be able to reliably detect it.
1517 1517
 			$result = $this->search($filter, $base, ['dn'], 1);
1518
-			if(!isset($result[0]) || !isset($result[0]['dn'])) {
1518
+			if (!isset($result[0]) || !isset($result[0]['dn'])) {
1519 1519
 				throw new \Exception('Cannot determine UUID attribute');
1520 1520
 			}
1521 1521
 			$dn = $result[0]['dn'][0];
1522
-			if(!$this->detectUuidAttribute($dn, true)) {
1522
+			if (!$this->detectUuidAttribute($dn, true)) {
1523 1523
 				throw new \Exception('Cannot determine UUID attribute');
1524 1524
 			}
1525 1525
 		} else {
1526 1526
 			// The UUID attribute is either known or an override is given.
1527 1527
 			// By calling this method we ensure that $this->connection->$uuidAttr
1528 1528
 			// is definitely set
1529
-			if(!$this->detectUuidAttribute('', true)) {
1529
+			if (!$this->detectUuidAttribute('', true)) {
1530 1530
 				throw new \Exception('Cannot determine UUID attribute');
1531 1531
 			}
1532 1532
 		}
1533 1533
 
1534 1534
 		$uuidAttr = $this->connection->ldapUuidUserAttribute;
1535
-		if($uuidAttr === 'guid' || $uuidAttr === 'objectguid') {
1535
+		if ($uuidAttr === 'guid' || $uuidAttr === 'objectguid') {
1536 1536
 			$uuid = $this->formatGuid2ForFilterUser($uuid);
1537 1537
 		}
1538 1538
 
1539
-		$filter = $uuidAttr . '=' . $uuid;
1539
+		$filter = $uuidAttr.'='.$uuid;
1540 1540
 		$result = $this->searchUsers($filter, ['dn'], 2);
1541
-		if(is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) {
1541
+		if (is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) {
1542 1542
 			// we put the count into account to make sure that this is
1543 1543
 			// really unique
1544 1544
 			return $result[0]['dn'][0];
@@ -1557,7 +1557,7 @@  discard block
 block discarded – undo
1557 1557
 	 * @return bool true on success, false otherwise
1558 1558
 	 */
1559 1559
 	private function detectUuidAttribute($dn, $isUser = true, $force = false, array $ldapRecord = null) {
1560
-		if($isUser) {
1560
+		if ($isUser) {
1561 1561
 			$uuidAttr     = 'ldapUuidUserAttribute';
1562 1562
 			$uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
1563 1563
 		} else {
@@ -1565,7 +1565,7 @@  discard block
 block discarded – undo
1565 1565
 			$uuidOverride = $this->connection->ldapExpertUUIDGroupAttr;
1566 1566
 		}
1567 1567
 
1568
-		if(($this->connection->$uuidAttr !== 'auto') && !$force) {
1568
+		if (($this->connection->$uuidAttr !== 'auto') && !$force) {
1569 1569
 			return true;
1570 1570
 		}
1571 1571
 
@@ -1574,10 +1574,10 @@  discard block
 block discarded – undo
1574 1574
 			return true;
1575 1575
 		}
1576 1576
 
1577
-		foreach(self::UUID_ATTRIBUTES as $attribute) {
1578
-			if($ldapRecord !== null) {
1577
+		foreach (self::UUID_ATTRIBUTES as $attribute) {
1578
+			if ($ldapRecord !== null) {
1579 1579
 				// we have the info from LDAP already, we don't need to talk to the server again
1580
-				if(isset($ldapRecord[$attribute])) {
1580
+				if (isset($ldapRecord[$attribute])) {
1581 1581
 					$this->connection->$uuidAttr = $attribute;
1582 1582
 					return true;
1583 1583
 				} else {
@@ -1586,7 +1586,7 @@  discard block
 block discarded – undo
1586 1586
 			}
1587 1587
 
1588 1588
 			$value = $this->readAttribute($dn, $attribute);
1589
-			if(is_array($value) && isset($value[0]) && !empty($value[0])) {
1589
+			if (is_array($value) && isset($value[0]) && !empty($value[0])) {
1590 1590
 				\OCP\Util::writeLog('user_ldap',
1591 1591
 									'Setting '.$attribute.' as '.$uuidAttr,
1592 1592
 									\OCP\Util::DEBUG);
@@ -1608,7 +1608,7 @@  discard block
 block discarded – undo
1608 1608
 	 * @return bool|string
1609 1609
 	 */
1610 1610
 	public function getUUID($dn, $isUser = true, $ldapRecord = null) {
1611
-		if($isUser) {
1611
+		if ($isUser) {
1612 1612
 			$uuidAttr     = 'ldapUuidUserAttribute';
1613 1613
 			$uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
1614 1614
 		} else {
@@ -1617,10 +1617,10 @@  discard block
 block discarded – undo
1617 1617
 		}
1618 1618
 
1619 1619
 		$uuid = false;
1620
-		if($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) {
1620
+		if ($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) {
1621 1621
 			$attr = $this->connection->$uuidAttr;
1622 1622
 			$uuid = isset($ldapRecord[$attr]) ? $ldapRecord[$attr] : $this->readAttribute($dn, $attr);
1623
-			if( !is_array($uuid)
1623
+			if (!is_array($uuid)
1624 1624
 				&& $uuidOverride !== ''
1625 1625
 				&& $this->detectUuidAttribute($dn, $isUser, true, $ldapRecord))
1626 1626
 			{
@@ -1628,7 +1628,7 @@  discard block
 block discarded – undo
1628 1628
 					? $ldapRecord[$this->connection->$uuidAttr]
1629 1629
 					: $this->readAttribute($dn, $this->connection->$uuidAttr);
1630 1630
 			}
1631
-			if(is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) {
1631
+			if (is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) {
1632 1632
 				$uuid = $uuid[0];
1633 1633
 			}
1634 1634
 		}
@@ -1645,19 +1645,19 @@  discard block
 block discarded – undo
1645 1645
 	private function convertObjectGUID2Str($oguid) {
1646 1646
 		$hex_guid = bin2hex($oguid);
1647 1647
 		$hex_guid_to_guid_str = '';
1648
-		for($k = 1; $k <= 4; ++$k) {
1648
+		for ($k = 1; $k <= 4; ++$k) {
1649 1649
 			$hex_guid_to_guid_str .= substr($hex_guid, 8 - 2 * $k, 2);
1650 1650
 		}
1651 1651
 		$hex_guid_to_guid_str .= '-';
1652
-		for($k = 1; $k <= 2; ++$k) {
1652
+		for ($k = 1; $k <= 2; ++$k) {
1653 1653
 			$hex_guid_to_guid_str .= substr($hex_guid, 12 - 2 * $k, 2);
1654 1654
 		}
1655 1655
 		$hex_guid_to_guid_str .= '-';
1656
-		for($k = 1; $k <= 2; ++$k) {
1656
+		for ($k = 1; $k <= 2; ++$k) {
1657 1657
 			$hex_guid_to_guid_str .= substr($hex_guid, 16 - 2 * $k, 2);
1658 1658
 		}
1659
-		$hex_guid_to_guid_str .= '-' . substr($hex_guid, 16, 4);
1660
-		$hex_guid_to_guid_str .= '-' . substr($hex_guid, 20);
1659
+		$hex_guid_to_guid_str .= '-'.substr($hex_guid, 16, 4);
1660
+		$hex_guid_to_guid_str .= '-'.substr($hex_guid, 20);
1661 1661
 
1662 1662
 		return strtoupper($hex_guid_to_guid_str);
1663 1663
 	}
@@ -1674,11 +1674,11 @@  discard block
 block discarded – undo
1674 1674
 	 * @return string
1675 1675
 	 */
1676 1676
 	public function formatGuid2ForFilterUser($guid) {
1677
-		if(!is_string($guid)) {
1677
+		if (!is_string($guid)) {
1678 1678
 			throw new \InvalidArgumentException('String expected');
1679 1679
 		}
1680 1680
 		$blocks = explode('-', $guid);
1681
-		if(count($blocks) !== 5) {
1681
+		if (count($blocks) !== 5) {
1682 1682
 			/*
1683 1683
 			 * Why not throw an Exception instead? This method is a utility
1684 1684
 			 * called only when trying to figure out whether a "missing" known
@@ -1691,20 +1691,20 @@  discard block
 block discarded – undo
1691 1691
 			 * user. Instead we write a log message.
1692 1692
 			 */
1693 1693
 			\OC::$server->getLogger()->info(
1694
-				'Passed string does not resemble a valid GUID. Known UUID ' .
1694
+				'Passed string does not resemble a valid GUID. Known UUID '.
1695 1695
 				'({uuid}) probably does not match UUID configuration.',
1696
-				[ 'app' => 'user_ldap', 'uuid' => $guid ]
1696
+				['app' => 'user_ldap', 'uuid' => $guid]
1697 1697
 			);
1698 1698
 			return $guid;
1699 1699
 		}
1700
-		for($i=0; $i < 3; $i++) {
1700
+		for ($i = 0; $i < 3; $i++) {
1701 1701
 			$pairs = str_split($blocks[$i], 2);
1702 1702
 			$pairs = array_reverse($pairs);
1703 1703
 			$blocks[$i] = implode('', $pairs);
1704 1704
 		}
1705
-		for($i=0; $i < 5; $i++) {
1705
+		for ($i = 0; $i < 5; $i++) {
1706 1706
 			$pairs = str_split($blocks[$i], 2);
1707
-			$blocks[$i] = '\\' . implode('\\', $pairs);
1707
+			$blocks[$i] = '\\'.implode('\\', $pairs);
1708 1708
 		}
1709 1709
 		return implode('', $blocks);
1710 1710
 	}
@@ -1718,12 +1718,12 @@  discard block
 block discarded – undo
1718 1718
 		$domainDN = $this->getDomainDNFromDN($dn);
1719 1719
 		$cacheKey = 'getSID-'.$domainDN;
1720 1720
 		$sid = $this->connection->getFromCache($cacheKey);
1721
-		if(!is_null($sid)) {
1721
+		if (!is_null($sid)) {
1722 1722
 			return $sid;
1723 1723
 		}
1724 1724
 
1725 1725
 		$objectSid = $this->readAttribute($domainDN, 'objectsid');
1726
-		if(!is_array($objectSid) || empty($objectSid)) {
1726
+		if (!is_array($objectSid) || empty($objectSid)) {
1727 1727
 			$this->connection->writeToCache($cacheKey, false);
1728 1728
 			return false;
1729 1729
 		}
@@ -1781,12 +1781,12 @@  discard block
 block discarded – undo
1781 1781
 		$belongsToBase = false;
1782 1782
 		$bases = $this->helper->sanitizeDN($bases);
1783 1783
 
1784
-		foreach($bases as $base) {
1784
+		foreach ($bases as $base) {
1785 1785
 			$belongsToBase = true;
1786
-			if(mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8')-mb_strlen($base, 'UTF-8'))) {
1786
+			if (mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8') - mb_strlen($base, 'UTF-8'))) {
1787 1787
 				$belongsToBase = false;
1788 1788
 			}
1789
-			if($belongsToBase) {
1789
+			if ($belongsToBase) {
1790 1790
 				break;
1791 1791
 			}
1792 1792
 		}
@@ -1797,7 +1797,7 @@  discard block
 block discarded – undo
1797 1797
 	 * resets a running Paged Search operation
1798 1798
 	 */
1799 1799
 	private function abandonPagedSearch() {
1800
-		if($this->connection->hasPagedResultSupport) {
1800
+		if ($this->connection->hasPagedResultSupport) {
1801 1801
 			$cr = $this->connection->getConnectionResource();
1802 1802
 			$this->invokeLDAPMethod('controlPagedResult', $cr, 0, false, $this->lastCookie);
1803 1803
 			$this->getPagedSearchResultState();
@@ -1815,16 +1815,16 @@  discard block
 block discarded – undo
1815 1815
 	 * @return string containing the key or empty if none is cached
1816 1816
 	 */
1817 1817
 	private function getPagedResultCookie($base, $filter, $limit, $offset) {
1818
-		if($offset === 0) {
1818
+		if ($offset === 0) {
1819 1819
 			return '';
1820 1820
 		}
1821 1821
 		$offset -= $limit;
1822 1822
 		//we work with cache here
1823
-		$cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . intval($limit) . '-' . intval($offset);
1823
+		$cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.intval($limit).'-'.intval($offset);
1824 1824
 		$cookie = '';
1825
-		if(isset($this->cookies[$cacheKey])) {
1825
+		if (isset($this->cookies[$cacheKey])) {
1826 1826
 			$cookie = $this->cookies[$cacheKey];
1827
-			if(is_null($cookie)) {
1827
+			if (is_null($cookie)) {
1828 1828
 				$cookie = '';
1829 1829
 			}
1830 1830
 		}
@@ -1842,11 +1842,11 @@  discard block
 block discarded – undo
1842 1842
 	 * @return bool
1843 1843
 	 */
1844 1844
 	public function hasMoreResults() {
1845
-		if(!$this->connection->hasPagedResultSupport) {
1845
+		if (!$this->connection->hasPagedResultSupport) {
1846 1846
 			return false;
1847 1847
 		}
1848 1848
 
1849
-		if(empty($this->lastCookie) && $this->lastCookie !== '0') {
1849
+		if (empty($this->lastCookie) && $this->lastCookie !== '0') {
1850 1850
 			// as in RFC 2696, when all results are returned, the cookie will
1851 1851
 			// be empty.
1852 1852
 			return false;
@@ -1866,8 +1866,8 @@  discard block
 block discarded – undo
1866 1866
 	 */
1867 1867
 	private function setPagedResultCookie($base, $filter, $limit, $offset, $cookie) {
1868 1868
 		// allow '0' for 389ds
1869
-		if(!empty($cookie) || $cookie === '0') {
1870
-			$cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' .intval($limit) . '-' . intval($offset);
1869
+		if (!empty($cookie) || $cookie === '0') {
1870
+			$cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.intval($limit).'-'.intval($offset);
1871 1871
 			$this->cookies[$cacheKey] = $cookie;
1872 1872
 			$this->lastCookie = $cookie;
1873 1873
 		}
@@ -1894,22 +1894,22 @@  discard block
 block discarded – undo
1894 1894
 	 */
1895 1895
 	private function initPagedSearch($filter, $bases, $attr, $limit, $offset) {
1896 1896
 		$pagedSearchOK = false;
1897
-		if($this->connection->hasPagedResultSupport && ($limit !== 0)) {
1897
+		if ($this->connection->hasPagedResultSupport && ($limit !== 0)) {
1898 1898
 			$offset = intval($offset); //can be null
1899 1899
 			\OCP\Util::writeLog('user_ldap',
1900 1900
 				'initializing paged search for  Filter '.$filter.' base '.print_r($bases, true)
1901
-				.' attr '.print_r($attr, true). ' limit ' .$limit.' offset '.$offset,
1901
+				.' attr '.print_r($attr, true).' limit '.$limit.' offset '.$offset,
1902 1902
 				\OCP\Util::DEBUG);
1903 1903
 			//get the cookie from the search for the previous search, required by LDAP
1904
-			foreach($bases as $base) {
1904
+			foreach ($bases as $base) {
1905 1905
 
1906 1906
 				$cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset);
1907
-				if(empty($cookie) && $cookie !== "0" && ($offset > 0)) {
1907
+				if (empty($cookie) && $cookie !== "0" && ($offset > 0)) {
1908 1908
 					// no cookie known from a potential previous search. We need
1909 1909
 					// to start from 0 to come to the desired page. cookie value
1910 1910
 					// of '0' is valid, because 389ds
1911 1911
 					$reOffset = 0;
1912
-					while($reOffset < $offset) {
1912
+					while ($reOffset < $offset) {
1913 1913
 						$this->search($filter, array($base), $attr, $limit, $reOffset, true);
1914 1914
 						$reOffset += $limit;
1915 1915
 					}
@@ -1917,17 +1917,17 @@  discard block
 block discarded – undo
1917 1917
 					//still no cookie? obviously, the server does not like us. Let's skip paging efforts.
1918 1918
 					// '0' is valid, because 389ds
1919 1919
 					//TODO: remember this, probably does not change in the next request...
1920
-					if(empty($cookie) && $cookie !== '0') {
1920
+					if (empty($cookie) && $cookie !== '0') {
1921 1921
 						$cookie = null;
1922 1922
 					}
1923 1923
 				}
1924
-				if(!is_null($cookie)) {
1924
+				if (!is_null($cookie)) {
1925 1925
 					//since offset = 0, this is a new search. We abandon other searches that might be ongoing.
1926 1926
 					$this->abandonPagedSearch();
1927 1927
 					$pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult',
1928 1928
 						$this->connection->getConnectionResource(), $limit,
1929 1929
 						false, $cookie);
1930
-					if(!$pagedSearchOK) {
1930
+					if (!$pagedSearchOK) {
1931 1931
 						return false;
1932 1932
 					}
1933 1933
 					\OCP\Util::writeLog('user_ldap', 'Ready for a paged search', \OCP\Util::DEBUG);
@@ -1944,7 +1944,7 @@  discard block
 block discarded – undo
1944 1944
 		 * So we added "&& !empty($this->lastCookie)" to this test to ignore pagination
1945 1945
 		 * if we don't have a previous paged search.
1946 1946
 		 */
1947
-		} else if($this->connection->hasPagedResultSupport && $limit === 0 && !empty($this->lastCookie)) {
1947
+		} else if ($this->connection->hasPagedResultSupport && $limit === 0 && !empty($this->lastCookie)) {
1948 1948
 			// a search without limit was requested. However, if we do use
1949 1949
 			// Paged Search once, we always must do it. This requires us to
1950 1950
 			// initialize it with the configured page size.
Please login to merge, or discard this patch.