Completed
Pull Request — master (#8634)
by Blizzz
33:44 queued 15:43
created
apps/user_ldap/lib/Access.php 1 patch
Spacing   +183 added lines, -183 removed lines patch added patch discarded remove patch
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 	 * @return AbstractMapping
126 126
 	 */
127 127
 	public function getUserMapper() {
128
-		if(is_null($this->userMapper)) {
128
+		if (is_null($this->userMapper)) {
129 129
 			throw new \Exception('UserMapper was not assigned to this Access instance.');
130 130
 		}
131 131
 		return $this->userMapper;
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 	 * @return AbstractMapping
146 146
 	 */
147 147
 	public function getGroupMapper() {
148
-		if(is_null($this->groupMapper)) {
148
+		if (is_null($this->groupMapper)) {
149 149
 			throw new \Exception('GroupMapper was not assigned to this Access instance.');
150 150
 		}
151 151
 		return $this->groupMapper;
@@ -178,14 +178,14 @@  discard block
 block discarded – undo
178 178
 	 * @throws ServerNotAvailableException
179 179
 	 */
180 180
 	public function readAttribute($dn, $attr, $filter = 'objectClass=*') {
181
-		if(!$this->checkConnection()) {
181
+		if (!$this->checkConnection()) {
182 182
 			\OCP\Util::writeLog('user_ldap',
183 183
 				'No LDAP Connector assigned, access impossible for readAttribute.',
184 184
 				\OCP\Util::WARN);
185 185
 			return false;
186 186
 		}
187 187
 		$cr = $this->connection->getConnectionResource();
188
-		if(!$this->ldap->isResource($cr)) {
188
+		if (!$this->ldap->isResource($cr)) {
189 189
 			//LDAP not available
190 190
 			\OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG);
191 191
 			return false;
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 		$this->abandonPagedSearch();
196 196
 		// openLDAP requires that we init a new Paged Search. Not needed by AD,
197 197
 		// but does not hurt either.
198
-		$pagingSize = (int)$this->connection->ldapPagingSize;
198
+		$pagingSize = (int) $this->connection->ldapPagingSize;
199 199
 		// 0 won't result in replies, small numbers may leave out groups
200 200
 		// (cf. #12306), 500 is default for paging and should work everywhere.
201 201
 		$maxResults = $pagingSize > 20 ? $pagingSize : 500;
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 		$isRangeRequest = false;
209 209
 		do {
210 210
 			$result = $this->executeRead($cr, $dn, $attrToRead, $filter, $maxResults);
211
-			if(is_bool($result)) {
211
+			if (is_bool($result)) {
212 212
 				// when an exists request was run and it was successful, an empty
213 213
 				// array must be returned
214 214
 				return $result ? [] : false;
@@ -225,22 +225,22 @@  discard block
 block discarded – undo
225 225
 			$result = $this->extractRangeData($result, $attr);
226 226
 			if (!empty($result)) {
227 227
 				$normalizedResult = $this->extractAttributeValuesFromResult(
228
-					[ $attr => $result['values'] ],
228
+					[$attr => $result['values']],
229 229
 					$attr
230 230
 				);
231 231
 				$values = array_merge($values, $normalizedResult);
232 232
 
233
-				if($result['rangeHigh'] === '*') {
233
+				if ($result['rangeHigh'] === '*') {
234 234
 					// when server replies with * as high range value, there are
235 235
 					// no more results left
236 236
 					return $values;
237 237
 				} else {
238
-					$low  = $result['rangeHigh'] + 1;
239
-					$attrToRead = $result['attributeName'] . ';range=' . $low . '-*';
238
+					$low = $result['rangeHigh'] + 1;
239
+					$attrToRead = $result['attributeName'].';range='.$low.'-*';
240 240
 					$isRangeRequest = true;
241 241
 				}
242 242
 			}
243
-		} while($isRangeRequest);
243
+		} while ($isRangeRequest);
244 244
 
245 245
 		\OCP\Util::writeLog('user_ldap', 'Requested attribute '.$attr.' not found for '.$dn, \OCP\Util::DEBUG);
246 246
 		return false;
@@ -266,13 +266,13 @@  discard block
 block discarded – undo
266 266
 		if (!$this->ldap->isResource($rr)) {
267 267
 			if ($attribute !== '') {
268 268
 				//do not throw this message on userExists check, irritates
269
-				\OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN ' . $dn, \OCP\Util::DEBUG);
269
+				\OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN '.$dn, \OCP\Util::DEBUG);
270 270
 			}
271 271
 			//in case an error occurs , e.g. object does not exist
272 272
 			return false;
273 273
 		}
274 274
 		if ($attribute === '' && ($filter === 'objectclass=*' || $this->invokeLDAPMethod('countEntries', $cr, $rr) === 1)) {
275
-			\OCP\Util::writeLog('user_ldap', 'readAttribute: ' . $dn . ' found', \OCP\Util::DEBUG);
275
+			\OCP\Util::writeLog('user_ldap', 'readAttribute: '.$dn.' found', \OCP\Util::DEBUG);
276 276
 			return true;
277 277
 		}
278 278
 		$er = $this->invokeLDAPMethod('firstEntry', $cr, $rr);
@@ -297,12 +297,12 @@  discard block
 block discarded – undo
297 297
 	 */
298 298
 	public function extractAttributeValuesFromResult($result, $attribute) {
299 299
 		$values = [];
300
-		if(isset($result[$attribute]) && $result[$attribute]['count'] > 0) {
300
+		if (isset($result[$attribute]) && $result[$attribute]['count'] > 0) {
301 301
 			$lowercaseAttribute = strtolower($attribute);
302
-			for($i=0;$i<$result[$attribute]['count'];$i++) {
303
-				if($this->resemblesDN($attribute)) {
302
+			for ($i = 0; $i < $result[$attribute]['count']; $i++) {
303
+				if ($this->resemblesDN($attribute)) {
304 304
 					$values[] = $this->helper->sanitizeDN($result[$attribute][$i]);
305
-				} elseif($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') {
305
+				} elseif ($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') {
306 306
 					$values[] = $this->convertObjectGUID2Str($result[$attribute][$i]);
307 307
 				} else {
308 308
 					$values[] = $result[$attribute][$i];
@@ -324,10 +324,10 @@  discard block
 block discarded – undo
324 324
 	 */
325 325
 	public function extractRangeData($result, $attribute) {
326 326
 		$keys = array_keys($result);
327
-		foreach($keys as $key) {
328
-			if($key !== $attribute && strpos($key, $attribute) === 0) {
327
+		foreach ($keys as $key) {
328
+			if ($key !== $attribute && strpos($key, $attribute) === 0) {
329 329
 				$queryData = explode(';', $key);
330
-				if(strpos($queryData[1], 'range=') === 0) {
330
+				if (strpos($queryData[1], 'range=') === 0) {
331 331
 					$high = substr($queryData[1], 1 + strpos($queryData[1], '-'));
332 332
 					$data = [
333 333
 						'values' => $result[$key],
@@ -352,18 +352,18 @@  discard block
 block discarded – undo
352 352
 	 * @throws \Exception
353 353
 	 */
354 354
 	public function setPassword($userDN, $password) {
355
-		if((int)$this->connection->turnOnPasswordChange !== 1) {
355
+		if ((int) $this->connection->turnOnPasswordChange !== 1) {
356 356
 			throw new \Exception('LDAP password changes are disabled.');
357 357
 		}
358 358
 		$cr = $this->connection->getConnectionResource();
359
-		if(!$this->ldap->isResource($cr)) {
359
+		if (!$this->ldap->isResource($cr)) {
360 360
 			//LDAP not available
361 361
 			\OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG);
362 362
 			return false;
363 363
 		}
364 364
 		try {
365 365
 			return @$this->invokeLDAPMethod('modReplace', $cr, $userDN, $password);
366
-		} catch(ConstraintViolationException $e) {
366
+		} catch (ConstraintViolationException $e) {
367 367
 			throw new HintException('Password change rejected.', \OC::$server->getL10N('user_ldap')->t('Password change rejected. Hint: ').$e->getMessage(), $e->getCode());
368 368
 		}
369 369
 	}
@@ -405,17 +405,17 @@  discard block
 block discarded – undo
405 405
 	 */
406 406
 	public function getDomainDNFromDN($dn) {
407 407
 		$allParts = $this->ldap->explodeDN($dn, 0);
408
-		if($allParts === false) {
408
+		if ($allParts === false) {
409 409
 			//not a valid DN
410 410
 			return '';
411 411
 		}
412 412
 		$domainParts = array();
413 413
 		$dcFound = false;
414
-		foreach($allParts as $part) {
415
-			if(!$dcFound && strpos($part, 'dc=') === 0) {
414
+		foreach ($allParts as $part) {
415
+			if (!$dcFound && strpos($part, 'dc=') === 0) {
416 416
 				$dcFound = true;
417 417
 			}
418
-			if($dcFound) {
418
+			if ($dcFound) {
419 419
 				$domainParts[] = $part;
420 420
 			}
421 421
 		}
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
 
442 442
 		//Check whether the DN belongs to the Base, to avoid issues on multi-
443 443
 		//server setups
444
-		if(is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
444
+		if (is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
445 445
 			return $fdn;
446 446
 		}
447 447
 
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
 		//To avoid bypassing the base DN settings under certain circumstances
459 459
 		//with the group support, check whether the provided DN matches one of
460 460
 		//the given Bases
461
-		if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) {
461
+		if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) {
462 462
 			return false;
463 463
 		}
464 464
 
@@ -475,11 +475,11 @@  discard block
 block discarded – undo
475 475
 	 */
476 476
 	public function groupsMatchFilter($groupDNs) {
477 477
 		$validGroupDNs = [];
478
-		foreach($groupDNs as $dn) {
478
+		foreach ($groupDNs as $dn) {
479 479
 			$cacheKey = 'groupsMatchFilter-'.$dn;
480 480
 			$groupMatchFilter = $this->connection->getFromCache($cacheKey);
481
-			if(!is_null($groupMatchFilter)) {
482
-				if($groupMatchFilter) {
481
+			if (!is_null($groupMatchFilter)) {
482
+				if ($groupMatchFilter) {
483 483
 					$validGroupDNs[] = $dn;
484 484
 				}
485 485
 				continue;
@@ -487,13 +487,13 @@  discard block
 block discarded – undo
487 487
 
488 488
 			// Check the base DN first. If this is not met already, we don't
489 489
 			// need to ask the server at all.
490
-			if(!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) {
490
+			if (!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) {
491 491
 				$this->connection->writeToCache($cacheKey, false);
492 492
 				continue;
493 493
 			}
494 494
 
495 495
 			$result = $this->readAttribute($dn, 'cn', $this->connection->ldapGroupFilter);
496
-			if(is_array($result)) {
496
+			if (is_array($result)) {
497 497
 				$this->connection->writeToCache($cacheKey, true);
498 498
 				$validGroupDNs[] = $dn;
499 499
 			} else {
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
 		//To avoid bypassing the base DN settings under certain circumstances
515 515
 		//with the group support, check whether the provided DN matches one of
516 516
 		//the given Bases
517
-		if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
517
+		if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
518 518
 			return false;
519 519
 		}
520 520
 
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
 	 */
535 535
 	public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped = null, array $record = null) {
536 536
 		$newlyMapped = false;
537
-		if($isUser) {
537
+		if ($isUser) {
538 538
 			$mapper = $this->getUserMapper();
539 539
 			$nameAttribute = $this->connection->ldapUserDisplayName;
540 540
 		} else {
@@ -544,15 +544,15 @@  discard block
 block discarded – undo
544 544
 
545 545
 		//let's try to retrieve the Nextcloud name from the mappings table
546 546
 		$ncName = $mapper->getNameByDN($fdn);
547
-		if(is_string($ncName)) {
547
+		if (is_string($ncName)) {
548 548
 			return $ncName;
549 549
 		}
550 550
 
551 551
 		//second try: get the UUID and check if it is known. Then, update the DN and return the name.
552 552
 		$uuid = $this->getUUID($fdn, $isUser, $record);
553
-		if(is_string($uuid)) {
553
+		if (is_string($uuid)) {
554 554
 			$ncName = $mapper->getNameByUUID($uuid);
555
-			if(is_string($ncName)) {
555
+			if (is_string($ncName)) {
556 556
 				$mapper->setDNbyUUID($fdn, $uuid);
557 557
 				return $ncName;
558 558
 			}
@@ -562,17 +562,17 @@  discard block
 block discarded – undo
562 562
 			return false;
563 563
 		}
564 564
 
565
-		if(is_null($ldapName)) {
565
+		if (is_null($ldapName)) {
566 566
 			$ldapName = $this->readAttribute($fdn, $nameAttribute);
567
-			if(!isset($ldapName[0]) && empty($ldapName[0])) {
567
+			if (!isset($ldapName[0]) && empty($ldapName[0])) {
568 568
 				\OCP\Util::writeLog('user_ldap', 'No or empty name for '.$fdn.'.', \OCP\Util::INFO);
569 569
 				return false;
570 570
 			}
571 571
 			$ldapName = $ldapName[0];
572 572
 		}
573 573
 
574
-		if($isUser) {
575
-			$usernameAttribute = (string)$this->connection->ldapExpertUsernameAttr;
574
+		if ($isUser) {
575
+			$usernameAttribute = (string) $this->connection->ldapExpertUsernameAttr;
576 576
 			if ($usernameAttribute !== '') {
577 577
 				$username = $this->readAttribute($fdn, $usernameAttribute);
578 578
 				$username = $username[0];
@@ -602,9 +602,9 @@  discard block
 block discarded – undo
602 602
 		// outside of core user management will still cache the user as non-existing.
603 603
 		$originalTTL = $this->connection->ldapCacheTTL;
604 604
 		$this->connection->setConfiguration(array('ldapCacheTTL' => 0));
605
-		if(($isUser && $intName !== '' && !\OC::$server->getUserManager()->userExists($intName))
605
+		if (($isUser && $intName !== '' && !\OC::$server->getUserManager()->userExists($intName))
606 606
 			|| (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))) {
607
-			if($mapper->map($fdn, $intName, $uuid)) {
607
+			if ($mapper->map($fdn, $intName, $uuid)) {
608 608
 				$this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL));
609 609
 				$newlyMapped = true;
610 610
 				return $intName;
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
 		$this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL));
614 614
 
615 615
 		$altName = $this->createAltInternalOwnCloudName($intName, $isUser);
616
-		if(is_string($altName) && $mapper->map($fdn, $altName, $uuid)) {
616
+		if (is_string($altName) && $mapper->map($fdn, $altName, $uuid)) {
617 617
 			$newlyMapped = true;
618 618
 			return $altName;
619 619
 		}
@@ -651,7 +651,7 @@  discard block
 block discarded – undo
651 651
 	 * @return array
652 652
 	 */
653 653
 	private function ldap2NextcloudNames($ldapObjects, $isUsers) {
654
-		if($isUsers) {
654
+		if ($isUsers) {
655 655
 			$nameAttribute = $this->connection->ldapUserDisplayName;
656 656
 			$sndAttribute  = $this->connection->ldapUserDisplayName2;
657 657
 		} else {
@@ -659,9 +659,9 @@  discard block
 block discarded – undo
659 659
 		}
660 660
 		$nextcloudNames = array();
661 661
 
662
-		foreach($ldapObjects as $ldapObject) {
662
+		foreach ($ldapObjects as $ldapObject) {
663 663
 			$nameByLDAP = null;
664
-			if(    isset($ldapObject[$nameAttribute])
664
+			if (isset($ldapObject[$nameAttribute])
665 665
 				&& is_array($ldapObject[$nameAttribute])
666 666
 				&& isset($ldapObject[$nameAttribute][0])
667 667
 			) {
@@ -670,12 +670,12 @@  discard block
 block discarded – undo
670 670
 			}
671 671
 
672 672
 			$ncName = $this->dn2ocname($ldapObject['dn'][0], $nameByLDAP, $isUsers);
673
-			if($ncName) {
673
+			if ($ncName) {
674 674
 				$nextcloudNames[] = $ncName;
675
-				if($isUsers) {
675
+				if ($isUsers) {
676 676
 					//cache the user names so it does not need to be retrieved
677 677
 					//again later (e.g. sharing dialogue).
678
-					if(is_null($nameByLDAP)) {
678
+					if (is_null($nameByLDAP)) {
679 679
 						continue;
680 680
 					}
681 681
 					$sndName = isset($ldapObject[$sndAttribute][0])
@@ -713,7 +713,7 @@  discard block
 block discarded – undo
713 713
 	 */
714 714
 	public function cacheUserDisplayName($ocName, $displayName, $displayName2 = '') {
715 715
 		$user = $this->userManager->get($ocName);
716
-		if($user === null) {
716
+		if ($user === null) {
717 717
 			return;
718 718
 		}
719 719
 		$displayName = $user->composeAndStoreDisplayName($displayName, $displayName2);
@@ -733,9 +733,9 @@  discard block
 block discarded – undo
733 733
 		$attempts = 0;
734 734
 		//while loop is just a precaution. If a name is not generated within
735 735
 		//20 attempts, something else is very wrong. Avoids infinite loop.
736
-		while($attempts < 20){
737
-			$altName = $name . '_' . rand(1000,9999);
738
-			if(!\OC::$server->getUserManager()->userExists($altName)) {
736
+		while ($attempts < 20) {
737
+			$altName = $name.'_'.rand(1000, 9999);
738
+			if (!\OC::$server->getUserManager()->userExists($altName)) {
739 739
 				return $altName;
740 740
 			}
741 741
 			$attempts++;
@@ -757,25 +757,25 @@  discard block
 block discarded – undo
757 757
 	 */
758 758
 	private function _createAltInternalOwnCloudNameForGroups($name) {
759 759
 		$usedNames = $this->groupMapper->getNamesBySearch($name, "", '_%');
760
-		if(!$usedNames || count($usedNames) === 0) {
760
+		if (!$usedNames || count($usedNames) === 0) {
761 761
 			$lastNo = 1; //will become name_2
762 762
 		} else {
763 763
 			natsort($usedNames);
764 764
 			$lastName = array_pop($usedNames);
765
-			$lastNo = (int)substr($lastName, strrpos($lastName, '_') + 1);
765
+			$lastNo = (int) substr($lastName, strrpos($lastName, '_') + 1);
766 766
 		}
767
-		$altName = $name.'_'. (string)($lastNo+1);
767
+		$altName = $name.'_'.(string) ($lastNo + 1);
768 768
 		unset($usedNames);
769 769
 
770 770
 		$attempts = 1;
771
-		while($attempts < 21){
771
+		while ($attempts < 21) {
772 772
 			// Check to be really sure it is unique
773 773
 			// while loop is just a precaution. If a name is not generated within
774 774
 			// 20 attempts, something else is very wrong. Avoids infinite loop.
775
-			if(!\OC::$server->getGroupManager()->groupExists($altName)) {
775
+			if (!\OC::$server->getGroupManager()->groupExists($altName)) {
776 776
 				return $altName;
777 777
 			}
778
-			$altName = $name . '_' . ($lastNo + $attempts);
778
+			$altName = $name.'_'.($lastNo + $attempts);
779 779
 			$attempts++;
780 780
 		}
781 781
 		return false;
@@ -790,7 +790,7 @@  discard block
 block discarded – undo
790 790
 	private function createAltInternalOwnCloudName($name, $isUser) {
791 791
 		$originalTTL = $this->connection->ldapCacheTTL;
792 792
 		$this->connection->setConfiguration(array('ldapCacheTTL' => 0));
793
-		if($isUser) {
793
+		if ($isUser) {
794 794
 			$altName = $this->_createAltInternalOwnCloudNameForUsers($name);
795 795
 		} else {
796 796
 			$altName = $this->_createAltInternalOwnCloudNameForGroups($name);
@@ -838,13 +838,13 @@  discard block
 block discarded – undo
838 838
 	public function fetchListOfUsers($filter, $attr, $limit = null, $offset = null, $forceApplyAttributes = false) {
839 839
 		$ldapRecords = $this->searchUsers($filter, $attr, $limit, $offset);
840 840
 		$recordsToUpdate = $ldapRecords;
841
-		if(!$forceApplyAttributes) {
841
+		if (!$forceApplyAttributes) {
842 842
 			$isBackgroundJobModeAjax = $this->config
843 843
 					->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax';
844 844
 			$recordsToUpdate = array_filter($ldapRecords, function($record) use ($isBackgroundJobModeAjax) {
845 845
 				$newlyMapped = false;
846 846
 				$uid = $this->dn2ocname($record['dn'][0], null, true, $newlyMapped, $record);
847
-				if(is_string($uid)) {
847
+				if (is_string($uid)) {
848 848
 					$this->cacheUserExists($uid);
849 849
 				}
850 850
 				return ($uid !== false) && ($newlyMapped || $isBackgroundJobModeAjax);
@@ -860,19 +860,19 @@  discard block
 block discarded – undo
860 860
 	 * and their values
861 861
 	 * @param array $ldapRecords
862 862
 	 */
863
-	public function batchApplyUserAttributes(array $ldapRecords){
863
+	public function batchApplyUserAttributes(array $ldapRecords) {
864 864
 		$displayNameAttribute = strtolower($this->connection->ldapUserDisplayName);
865
-		foreach($ldapRecords as $userRecord) {
866
-			if(!isset($userRecord[$displayNameAttribute])) {
865
+		foreach ($ldapRecords as $userRecord) {
866
+			if (!isset($userRecord[$displayNameAttribute])) {
867 867
 				// displayName is obligatory
868 868
 				continue;
869 869
 			}
870
-			$ocName  = $this->dn2ocname($userRecord['dn'][0], null, true);
871
-			if($ocName === false) {
870
+			$ocName = $this->dn2ocname($userRecord['dn'][0], null, true);
871
+			if ($ocName === false) {
872 872
 				continue;
873 873
 			}
874 874
 			$user = $this->userManager->get($ocName);
875
-			if($user instanceof OfflineUser) {
875
+			if ($user instanceof OfflineUser) {
876 876
 				$user->unmark();
877 877
 				$user = $this->userManager->get($ocName);
878 878
 			}
@@ -904,8 +904,8 @@  discard block
 block discarded – undo
904 904
 	 * @return array
905 905
 	 */
906 906
 	private function fetchList($list, $manyAttributes) {
907
-		if(is_array($list)) {
908
-			if($manyAttributes) {
907
+		if (is_array($list)) {
908
+			if ($manyAttributes) {
909 909
 				return $list;
910 910
 			} else {
911 911
 				$list = array_reduce($list, function($carry, $item) {
@@ -1003,7 +1003,7 @@  discard block
 block discarded – undo
1003 1003
 		// php no longer supports call-time pass-by-reference
1004 1004
 		// thus cannot support controlPagedResultResponse as the third argument
1005 1005
 		// is a reference
1006
-		$doMethod = function () use ($command, &$arguments) {
1006
+		$doMethod = function() use ($command, &$arguments) {
1007 1007
 			if ($command == 'controlPagedResultResponse') {
1008 1008
 				throw new \InvalidArgumentException('Invoker does not support controlPagedResultResponse, call LDAP Wrapper directly instead.');
1009 1009
 			} else {
@@ -1021,7 +1021,7 @@  discard block
 block discarded – undo
1021 1021
 			$this->connection->resetConnectionResource();
1022 1022
 			$cr = $this->connection->getConnectionResource();
1023 1023
 
1024
-			if(!$this->ldap->isResource($cr)) {
1024
+			if (!$this->ldap->isResource($cr)) {
1025 1025
 				// Seems like we didn't find any resource.
1026 1026
 				\OCP\Util::writeLog('user_ldap', "Could not $command, because resource is missing.", \OCP\Util::DEBUG);
1027 1027
 				throw $e;
@@ -1046,13 +1046,13 @@  discard block
 block discarded – undo
1046 1046
 	 * @throws ServerNotAvailableException
1047 1047
 	 */
1048 1048
 	private function executeSearch($filter, $base, &$attr = null, $limit = null, $offset = null) {
1049
-		if(!is_null($attr) && !is_array($attr)) {
1049
+		if (!is_null($attr) && !is_array($attr)) {
1050 1050
 			$attr = array(mb_strtolower($attr, 'UTF-8'));
1051 1051
 		}
1052 1052
 
1053 1053
 		// See if we have a resource, in case not cancel with message
1054 1054
 		$cr = $this->connection->getConnectionResource();
1055
-		if(!$this->ldap->isResource($cr)) {
1055
+		if (!$this->ldap->isResource($cr)) {
1056 1056
 			// Seems like we didn't find any resource.
1057 1057
 			// Return an empty array just like before.
1058 1058
 			\OCP\Util::writeLog('user_ldap', 'Could not search, because resource is missing.', \OCP\Util::DEBUG);
@@ -1060,13 +1060,13 @@  discard block
 block discarded – undo
1060 1060
 		}
1061 1061
 
1062 1062
 		//check whether paged search should be attempted
1063
-		$pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int)$limit, $offset);
1063
+		$pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int) $limit, $offset);
1064 1064
 
1065 1065
 		$linkResources = array_pad(array(), count($base), $cr);
1066 1066
 		$sr = $this->invokeLDAPMethod('search', $linkResources, $base, $filter, $attr);
1067 1067
 		// cannot use $cr anymore, might have changed in the previous call!
1068 1068
 		$error = $this->ldap->errno($this->connection->getConnectionResource());
1069
-		if(!is_array($sr) || $error !== 0) {
1069
+		if (!is_array($sr) || $error !== 0) {
1070 1070
 			\OCP\Util::writeLog('user_ldap', 'Attempt for Paging?  '.print_r($pagedSearchOK, true), \OCP\Util::ERROR);
1071 1071
 			return false;
1072 1072
 		}
@@ -1089,29 +1089,29 @@  discard block
 block discarded – undo
1089 1089
 	 */
1090 1090
 	private function processPagedSearchStatus($sr, $filter, $base, $iFoundItems, $limit, $offset, $pagedSearchOK, $skipHandling) {
1091 1091
 		$cookie = null;
1092
-		if($pagedSearchOK) {
1092
+		if ($pagedSearchOK) {
1093 1093
 			$cr = $this->connection->getConnectionResource();
1094
-			foreach($sr as $key => $res) {
1095
-				if($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) {
1094
+			foreach ($sr as $key => $res) {
1095
+				if ($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) {
1096 1096
 					$this->setPagedResultCookie($base[$key], $filter, $limit, $offset, $cookie);
1097 1097
 				}
1098 1098
 			}
1099 1099
 
1100 1100
 			//browsing through prior pages to get the cookie for the new one
1101
-			if($skipHandling) {
1101
+			if ($skipHandling) {
1102 1102
 				return false;
1103 1103
 			}
1104 1104
 			// if count is bigger, then the server does not support
1105 1105
 			// paged search. Instead, he did a normal search. We set a
1106 1106
 			// flag here, so the callee knows how to deal with it.
1107
-			if($iFoundItems <= $limit) {
1107
+			if ($iFoundItems <= $limit) {
1108 1108
 				$this->pagedSearchedSuccessful = true;
1109 1109
 			}
1110 1110
 		} else {
1111
-			if(!is_null($limit) && (int)$this->connection->ldapPagingSize !== 0) {
1111
+			if (!is_null($limit) && (int) $this->connection->ldapPagingSize !== 0) {
1112 1112
 				\OC::$server->getLogger()->debug(
1113 1113
 					'Paged search was not available',
1114
-					[ 'app' => 'user_ldap' ]
1114
+					['app' => 'user_ldap']
1115 1115
 				);
1116 1116
 			}
1117 1117
 		}
@@ -1140,8 +1140,8 @@  discard block
 block discarded – undo
1140 1140
 	private function count($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) {
1141 1141
 		\OCP\Util::writeLog('user_ldap', 'Count filter:  '.print_r($filter, true), \OCP\Util::DEBUG);
1142 1142
 
1143
-		$limitPerPage = (int)$this->connection->ldapPagingSize;
1144
-		if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1143
+		$limitPerPage = (int) $this->connection->ldapPagingSize;
1144
+		if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1145 1145
 			$limitPerPage = $limit;
1146 1146
 		}
1147 1147
 
@@ -1151,7 +1151,7 @@  discard block
 block discarded – undo
1151 1151
 
1152 1152
 		do {
1153 1153
 			$search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset);
1154
-			if($search === false) {
1154
+			if ($search === false) {
1155 1155
 				return $counter > 0 ? $counter : false;
1156 1156
 			}
1157 1157
 			list($sr, $pagedSearchOK) = $search;
@@ -1170,7 +1170,7 @@  discard block
 block discarded – undo
1170 1170
 			 * Continue now depends on $hasMorePages value
1171 1171
 			 */
1172 1172
 			$continue = $pagedSearchOK && $hasMorePages;
1173
-		} while($continue && (is_null($limit) || $limit <= 0 || $limit > $counter));
1173
+		} while ($continue && (is_null($limit) || $limit <= 0 || $limit > $counter));
1174 1174
 
1175 1175
 		return $counter;
1176 1176
 	}
@@ -1182,8 +1182,8 @@  discard block
 block discarded – undo
1182 1182
 	private function countEntriesInSearchResults($searchResults) {
1183 1183
 		$counter = 0;
1184 1184
 
1185
-		foreach($searchResults as $res) {
1186
-			$count = (int)$this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res);
1185
+		foreach ($searchResults as $res) {
1186
+			$count = (int) $this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res);
1187 1187
 			$counter += $count;
1188 1188
 		}
1189 1189
 
@@ -1203,8 +1203,8 @@  discard block
 block discarded – undo
1203 1203
 	 * @throws ServerNotAvailableException
1204 1204
 	 */
1205 1205
 	public function search($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) {
1206
-		$limitPerPage = (int)$this->connection->ldapPagingSize;
1207
-		if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1206
+		$limitPerPage = (int) $this->connection->ldapPagingSize;
1207
+		if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1208 1208
 			$limitPerPage = $limit;
1209 1209
 		}
1210 1210
 
@@ -1218,13 +1218,13 @@  discard block
 block discarded – undo
1218 1218
 		$savedoffset = $offset;
1219 1219
 		do {
1220 1220
 			$search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset);
1221
-			if($search === false) {
1221
+			if ($search === false) {
1222 1222
 				return [];
1223 1223
 			}
1224 1224
 			list($sr, $pagedSearchOK) = $search;
1225 1225
 			$cr = $this->connection->getConnectionResource();
1226 1226
 
1227
-			if($skipHandling) {
1227
+			if ($skipHandling) {
1228 1228
 				//i.e. result do not need to be fetched, we just need the cookie
1229 1229
 				//thus pass 1 or any other value as $iFoundItems because it is not
1230 1230
 				//used
@@ -1235,7 +1235,7 @@  discard block
 block discarded – undo
1235 1235
 			}
1236 1236
 
1237 1237
 			$iFoundItems = 0;
1238
-			foreach($sr as $res) {
1238
+			foreach ($sr as $res) {
1239 1239
 				$findings = array_merge($findings, $this->invokeLDAPMethod('getEntries', $cr, $res));
1240 1240
 				$iFoundItems = max($iFoundItems, $findings['count']);
1241 1241
 				unset($findings['count']);
@@ -1251,27 +1251,27 @@  discard block
 block discarded – undo
1251 1251
 
1252 1252
 		// if we're here, probably no connection resource is returned.
1253 1253
 		// to make Nextcloud behave nicely, we simply give back an empty array.
1254
-		if(is_null($findings)) {
1254
+		if (is_null($findings)) {
1255 1255
 			return array();
1256 1256
 		}
1257 1257
 
1258
-		if(!is_null($attr)) {
1258
+		if (!is_null($attr)) {
1259 1259
 			$selection = [];
1260 1260
 			$i = 0;
1261
-			foreach($findings as $item) {
1262
-				if(!is_array($item)) {
1261
+			foreach ($findings as $item) {
1262
+				if (!is_array($item)) {
1263 1263
 					continue;
1264 1264
 				}
1265 1265
 				$item = \OCP\Util::mb_array_change_key_case($item, MB_CASE_LOWER, 'UTF-8');
1266
-				foreach($attr as $key) {
1267
-					if(isset($item[$key])) {
1268
-						if(is_array($item[$key]) && isset($item[$key]['count'])) {
1266
+				foreach ($attr as $key) {
1267
+					if (isset($item[$key])) {
1268
+						if (is_array($item[$key]) && isset($item[$key]['count'])) {
1269 1269
 							unset($item[$key]['count']);
1270 1270
 						}
1271
-						if($key !== 'dn') {
1272
-							if($this->resemblesDN($key)) {
1271
+						if ($key !== 'dn') {
1272
+							if ($this->resemblesDN($key)) {
1273 1273
 								$selection[$i][$key] = $this->helper->sanitizeDN($item[$key]);
1274
-							} else if($key === 'objectguid' || $key === 'guid') {
1274
+							} else if ($key === 'objectguid' || $key === 'guid') {
1275 1275
 								$selection[$i][$key] = [$this->convertObjectGUID2Str($item[$key][0])];
1276 1276
 							} else {
1277 1277
 								$selection[$i][$key] = $item[$key];
@@ -1289,14 +1289,14 @@  discard block
 block discarded – undo
1289 1289
 		//we slice the findings, when
1290 1290
 		//a) paged search unsuccessful, though attempted
1291 1291
 		//b) no paged search, but limit set
1292
-		if((!$this->getPagedSearchResultState()
1292
+		if ((!$this->getPagedSearchResultState()
1293 1293
 			&& $pagedSearchOK)
1294 1294
 			|| (
1295 1295
 				!$pagedSearchOK
1296 1296
 				&& !is_null($limit)
1297 1297
 			)
1298 1298
 		) {
1299
-			$findings = array_slice($findings, (int)$offset, $limit);
1299
+			$findings = array_slice($findings, (int) $offset, $limit);
1300 1300
 		}
1301 1301
 		return $findings;
1302 1302
 	}
@@ -1309,13 +1309,13 @@  discard block
 block discarded – undo
1309 1309
 	public function sanitizeUsername($name) {
1310 1310
 		$name = trim($name);
1311 1311
 
1312
-		if($this->connection->ldapIgnoreNamingRules) {
1312
+		if ($this->connection->ldapIgnoreNamingRules) {
1313 1313
 			return $name;
1314 1314
 		}
1315 1315
 
1316 1316
 		// Transliteration to ASCII
1317 1317
 		$transliterated = @iconv('UTF-8', 'ASCII//TRANSLIT', $name);
1318
-		if($transliterated !== false) {
1318
+		if ($transliterated !== false) {
1319 1319
 			// depending on system config iconv can work or not
1320 1320
 			$name = $transliterated;
1321 1321
 		}
@@ -1326,7 +1326,7 @@  discard block
 block discarded – undo
1326 1326
 		// Every remaining disallowed characters will be removed
1327 1327
 		$name = preg_replace('/[^a-zA-Z0-9_.@-]/u', '', $name);
1328 1328
 
1329
-		if($name === '') {
1329
+		if ($name === '') {
1330 1330
 			throw new \InvalidArgumentException('provided name template for username does not contain any allowed characters');
1331 1331
 		}
1332 1332
 
@@ -1341,13 +1341,13 @@  discard block
 block discarded – undo
1341 1341
 	*/
1342 1342
 	public function escapeFilterPart($input, $allowAsterisk = false) {
1343 1343
 		$asterisk = '';
1344
-		if($allowAsterisk && strlen($input) > 0 && $input[0] === '*') {
1344
+		if ($allowAsterisk && strlen($input) > 0 && $input[0] === '*') {
1345 1345
 			$asterisk = '*';
1346 1346
 			$input = mb_substr($input, 1, null, 'UTF-8');
1347 1347
 		}
1348 1348
 		$search  = array('*', '\\', '(', ')');
1349 1349
 		$replace = array('\\*', '\\\\', '\\(', '\\)');
1350
-		return $asterisk . str_replace($search, $replace, $input);
1350
+		return $asterisk.str_replace($search, $replace, $input);
1351 1351
 	}
1352 1352
 
1353 1353
 	/**
@@ -1377,13 +1377,13 @@  discard block
 block discarded – undo
1377 1377
 	 */
1378 1378
 	private function combineFilter($filters, $operator) {
1379 1379
 		$combinedFilter = '('.$operator;
1380
-		foreach($filters as $filter) {
1380
+		foreach ($filters as $filter) {
1381 1381
 			if ($filter !== '' && $filter[0] !== '(') {
1382 1382
 				$filter = '('.$filter.')';
1383 1383
 			}
1384
-			$combinedFilter.=$filter;
1384
+			$combinedFilter .= $filter;
1385 1385
 		}
1386
-		$combinedFilter.=')';
1386
+		$combinedFilter .= ')';
1387 1387
 		return $combinedFilter;
1388 1388
 	}
1389 1389
 
@@ -1419,17 +1419,17 @@  discard block
 block discarded – undo
1419 1419
 	 * @throws \Exception
1420 1420
 	 */
1421 1421
 	private function getAdvancedFilterPartForSearch($search, $searchAttributes) {
1422
-		if(!is_array($searchAttributes) || count($searchAttributes) < 2) {
1422
+		if (!is_array($searchAttributes) || count($searchAttributes) < 2) {
1423 1423
 			throw new \Exception('searchAttributes must be an array with at least two string');
1424 1424
 		}
1425 1425
 		$searchWords = explode(' ', trim($search));
1426 1426
 		$wordFilters = array();
1427
-		foreach($searchWords as $word) {
1427
+		foreach ($searchWords as $word) {
1428 1428
 			$word = $this->prepareSearchTerm($word);
1429 1429
 			//every word needs to appear at least once
1430 1430
 			$wordMatchOneAttrFilters = array();
1431
-			foreach($searchAttributes as $attr) {
1432
-				$wordMatchOneAttrFilters[] = $attr . '=' . $word;
1431
+			foreach ($searchAttributes as $attr) {
1432
+				$wordMatchOneAttrFilters[] = $attr.'='.$word;
1433 1433
 			}
1434 1434
 			$wordFilters[] = $this->combineFilterWithOr($wordMatchOneAttrFilters);
1435 1435
 		}
@@ -1447,10 +1447,10 @@  discard block
 block discarded – undo
1447 1447
 	private function getFilterPartForSearch($search, $searchAttributes, $fallbackAttribute) {
1448 1448
 		$filter = array();
1449 1449
 		$haveMultiSearchAttributes = (is_array($searchAttributes) && count($searchAttributes) > 0);
1450
-		if($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) {
1450
+		if ($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) {
1451 1451
 			try {
1452 1452
 				return $this->getAdvancedFilterPartForSearch($search, $searchAttributes);
1453
-			} catch(\Exception $e) {
1453
+			} catch (\Exception $e) {
1454 1454
 				\OCP\Util::writeLog(
1455 1455
 					'user_ldap',
1456 1456
 					'Creating advanced filter for search failed, falling back to simple method.',
@@ -1460,17 +1460,17 @@  discard block
 block discarded – undo
1460 1460
 		}
1461 1461
 
1462 1462
 		$search = $this->prepareSearchTerm($search);
1463
-		if(!is_array($searchAttributes) || count($searchAttributes) === 0) {
1463
+		if (!is_array($searchAttributes) || count($searchAttributes) === 0) {
1464 1464
 			if ($fallbackAttribute === '') {
1465 1465
 				return '';
1466 1466
 			}
1467
-			$filter[] = $fallbackAttribute . '=' . $search;
1467
+			$filter[] = $fallbackAttribute.'='.$search;
1468 1468
 		} else {
1469
-			foreach($searchAttributes as $attribute) {
1470
-				$filter[] = $attribute . '=' . $search;
1469
+			foreach ($searchAttributes as $attribute) {
1470
+				$filter[] = $attribute.'='.$search;
1471 1471
 			}
1472 1472
 		}
1473
-		if(count($filter) === 1) {
1473
+		if (count($filter) === 1) {
1474 1474
 			return '('.$filter[0].')';
1475 1475
 		}
1476 1476
 		return $this->combineFilterWithOr($filter);
@@ -1491,7 +1491,7 @@  discard block
 block discarded – undo
1491 1491
 		if ($term === '') {
1492 1492
 			$result = '*';
1493 1493
 		} else if ($allowEnum !== 'no') {
1494
-			$result = $term . '*';
1494
+			$result = $term.'*';
1495 1495
 		}
1496 1496
 		return $result;
1497 1497
 	}
@@ -1503,7 +1503,7 @@  discard block
 block discarded – undo
1503 1503
 	public function getFilterForUserCount() {
1504 1504
 		$filter = $this->combineFilterWithAnd(array(
1505 1505
 			$this->connection->ldapUserFilter,
1506
-			$this->connection->ldapUserDisplayName . '=*'
1506
+			$this->connection->ldapUserDisplayName.'=*'
1507 1507
 		));
1508 1508
 
1509 1509
 		return $filter;
@@ -1521,7 +1521,7 @@  discard block
 block discarded – undo
1521 1521
 			'ldapAgentName' => $name,
1522 1522
 			'ldapAgentPassword' => $password
1523 1523
 		);
1524
-		if(!$testConnection->setConfiguration($credentials)) {
1524
+		if (!$testConnection->setConfiguration($credentials)) {
1525 1525
 			return false;
1526 1526
 		}
1527 1527
 		return $testConnection->bind();
@@ -1543,30 +1543,30 @@  discard block
 block discarded – undo
1543 1543
 			// Sacrebleu! The UUID attribute is unknown :( We need first an
1544 1544
 			// existing DN to be able to reliably detect it.
1545 1545
 			$result = $this->search($filter, $base, ['dn'], 1);
1546
-			if(!isset($result[0]) || !isset($result[0]['dn'])) {
1546
+			if (!isset($result[0]) || !isset($result[0]['dn'])) {
1547 1547
 				throw new \Exception('Cannot determine UUID attribute');
1548 1548
 			}
1549 1549
 			$dn = $result[0]['dn'][0];
1550
-			if(!$this->detectUuidAttribute($dn, true)) {
1550
+			if (!$this->detectUuidAttribute($dn, true)) {
1551 1551
 				throw new \Exception('Cannot determine UUID attribute');
1552 1552
 			}
1553 1553
 		} else {
1554 1554
 			// The UUID attribute is either known or an override is given.
1555 1555
 			// By calling this method we ensure that $this->connection->$uuidAttr
1556 1556
 			// is definitely set
1557
-			if(!$this->detectUuidAttribute('', true)) {
1557
+			if (!$this->detectUuidAttribute('', true)) {
1558 1558
 				throw new \Exception('Cannot determine UUID attribute');
1559 1559
 			}
1560 1560
 		}
1561 1561
 
1562 1562
 		$uuidAttr = $this->connection->ldapUuidUserAttribute;
1563
-		if($uuidAttr === 'guid' || $uuidAttr === 'objectguid') {
1563
+		if ($uuidAttr === 'guid' || $uuidAttr === 'objectguid') {
1564 1564
 			$uuid = $this->formatGuid2ForFilterUser($uuid);
1565 1565
 		}
1566 1566
 
1567
-		$filter = $uuidAttr . '=' . $uuid;
1567
+		$filter = $uuidAttr.'='.$uuid;
1568 1568
 		$result = $this->searchUsers($filter, ['dn'], 2);
1569
-		if(is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) {
1569
+		if (is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) {
1570 1570
 			// we put the count into account to make sure that this is
1571 1571
 			// really unique
1572 1572
 			return $result[0]['dn'][0];
@@ -1585,7 +1585,7 @@  discard block
 block discarded – undo
1585 1585
 	 * @return bool true on success, false otherwise
1586 1586
 	 */
1587 1587
 	private function detectUuidAttribute($dn, $isUser = true, $force = false, array $ldapRecord = null) {
1588
-		if($isUser) {
1588
+		if ($isUser) {
1589 1589
 			$uuidAttr     = 'ldapUuidUserAttribute';
1590 1590
 			$uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
1591 1591
 		} else {
@@ -1593,7 +1593,7 @@  discard block
 block discarded – undo
1593 1593
 			$uuidOverride = $this->connection->ldapExpertUUIDGroupAttr;
1594 1594
 		}
1595 1595
 
1596
-		if(($this->connection->$uuidAttr !== 'auto') && !$force) {
1596
+		if (($this->connection->$uuidAttr !== 'auto') && !$force) {
1597 1597
 			return true;
1598 1598
 		}
1599 1599
 
@@ -1602,10 +1602,10 @@  discard block
 block discarded – undo
1602 1602
 			return true;
1603 1603
 		}
1604 1604
 
1605
-		foreach(self::UUID_ATTRIBUTES as $attribute) {
1606
-			if($ldapRecord !== null) {
1605
+		foreach (self::UUID_ATTRIBUTES as $attribute) {
1606
+			if ($ldapRecord !== null) {
1607 1607
 				// we have the info from LDAP already, we don't need to talk to the server again
1608
-				if(isset($ldapRecord[$attribute])) {
1608
+				if (isset($ldapRecord[$attribute])) {
1609 1609
 					$this->connection->$uuidAttr = $attribute;
1610 1610
 					return true;
1611 1611
 				} else {
@@ -1614,7 +1614,7 @@  discard block
 block discarded – undo
1614 1614
 			}
1615 1615
 
1616 1616
 			$value = $this->readAttribute($dn, $attribute);
1617
-			if(is_array($value) && isset($value[0]) && !empty($value[0])) {
1617
+			if (is_array($value) && isset($value[0]) && !empty($value[0])) {
1618 1618
 				\OCP\Util::writeLog('user_ldap',
1619 1619
 									'Setting '.$attribute.' as '.$uuidAttr,
1620 1620
 									\OCP\Util::DEBUG);
@@ -1636,7 +1636,7 @@  discard block
 block discarded – undo
1636 1636
 	 * @return bool|string
1637 1637
 	 */
1638 1638
 	public function getUUID($dn, $isUser = true, $ldapRecord = null) {
1639
-		if($isUser) {
1639
+		if ($isUser) {
1640 1640
 			$uuidAttr     = 'ldapUuidUserAttribute';
1641 1641
 			$uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
1642 1642
 		} else {
@@ -1645,10 +1645,10 @@  discard block
 block discarded – undo
1645 1645
 		}
1646 1646
 
1647 1647
 		$uuid = false;
1648
-		if($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) {
1648
+		if ($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) {
1649 1649
 			$attr = $this->connection->$uuidAttr;
1650 1650
 			$uuid = isset($ldapRecord[$attr]) ? $ldapRecord[$attr] : $this->readAttribute($dn, $attr);
1651
-			if( !is_array($uuid)
1651
+			if (!is_array($uuid)
1652 1652
 				&& $uuidOverride !== ''
1653 1653
 				&& $this->detectUuidAttribute($dn, $isUser, true, $ldapRecord))
1654 1654
 			{
@@ -1656,7 +1656,7 @@  discard block
 block discarded – undo
1656 1656
 					? $ldapRecord[$this->connection->$uuidAttr]
1657 1657
 					: $this->readAttribute($dn, $this->connection->$uuidAttr);
1658 1658
 			}
1659
-			if(is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) {
1659
+			if (is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) {
1660 1660
 				$uuid = $uuid[0];
1661 1661
 			}
1662 1662
 		}
@@ -1673,19 +1673,19 @@  discard block
 block discarded – undo
1673 1673
 	private function convertObjectGUID2Str($oguid) {
1674 1674
 		$hex_guid = bin2hex($oguid);
1675 1675
 		$hex_guid_to_guid_str = '';
1676
-		for($k = 1; $k <= 4; ++$k) {
1676
+		for ($k = 1; $k <= 4; ++$k) {
1677 1677
 			$hex_guid_to_guid_str .= substr($hex_guid, 8 - 2 * $k, 2);
1678 1678
 		}
1679 1679
 		$hex_guid_to_guid_str .= '-';
1680
-		for($k = 1; $k <= 2; ++$k) {
1680
+		for ($k = 1; $k <= 2; ++$k) {
1681 1681
 			$hex_guid_to_guid_str .= substr($hex_guid, 12 - 2 * $k, 2);
1682 1682
 		}
1683 1683
 		$hex_guid_to_guid_str .= '-';
1684
-		for($k = 1; $k <= 2; ++$k) {
1684
+		for ($k = 1; $k <= 2; ++$k) {
1685 1685
 			$hex_guid_to_guid_str .= substr($hex_guid, 16 - 2 * $k, 2);
1686 1686
 		}
1687
-		$hex_guid_to_guid_str .= '-' . substr($hex_guid, 16, 4);
1688
-		$hex_guid_to_guid_str .= '-' . substr($hex_guid, 20);
1687
+		$hex_guid_to_guid_str .= '-'.substr($hex_guid, 16, 4);
1688
+		$hex_guid_to_guid_str .= '-'.substr($hex_guid, 20);
1689 1689
 
1690 1690
 		return strtoupper($hex_guid_to_guid_str);
1691 1691
 	}
@@ -1702,11 +1702,11 @@  discard block
 block discarded – undo
1702 1702
 	 * @return string
1703 1703
 	 */
1704 1704
 	public function formatGuid2ForFilterUser($guid) {
1705
-		if(!is_string($guid)) {
1705
+		if (!is_string($guid)) {
1706 1706
 			throw new \InvalidArgumentException('String expected');
1707 1707
 		}
1708 1708
 		$blocks = explode('-', $guid);
1709
-		if(count($blocks) !== 5) {
1709
+		if (count($blocks) !== 5) {
1710 1710
 			/*
1711 1711
 			 * Why not throw an Exception instead? This method is a utility
1712 1712
 			 * called only when trying to figure out whether a "missing" known
@@ -1719,20 +1719,20 @@  discard block
 block discarded – undo
1719 1719
 			 * user. Instead we write a log message.
1720 1720
 			 */
1721 1721
 			\OC::$server->getLogger()->info(
1722
-				'Passed string does not resemble a valid GUID. Known UUID ' .
1722
+				'Passed string does not resemble a valid GUID. Known UUID '.
1723 1723
 				'({uuid}) probably does not match UUID configuration.',
1724
-				[ 'app' => 'user_ldap', 'uuid' => $guid ]
1724
+				['app' => 'user_ldap', 'uuid' => $guid]
1725 1725
 			);
1726 1726
 			return $guid;
1727 1727
 		}
1728
-		for($i=0; $i < 3; $i++) {
1728
+		for ($i = 0; $i < 3; $i++) {
1729 1729
 			$pairs = str_split($blocks[$i], 2);
1730 1730
 			$pairs = array_reverse($pairs);
1731 1731
 			$blocks[$i] = implode('', $pairs);
1732 1732
 		}
1733
-		for($i=0; $i < 5; $i++) {
1733
+		for ($i = 0; $i < 5; $i++) {
1734 1734
 			$pairs = str_split($blocks[$i], 2);
1735
-			$blocks[$i] = '\\' . implode('\\', $pairs);
1735
+			$blocks[$i] = '\\'.implode('\\', $pairs);
1736 1736
 		}
1737 1737
 		return implode('', $blocks);
1738 1738
 	}
@@ -1746,12 +1746,12 @@  discard block
 block discarded – undo
1746 1746
 		$domainDN = $this->getDomainDNFromDN($dn);
1747 1747
 		$cacheKey = 'getSID-'.$domainDN;
1748 1748
 		$sid = $this->connection->getFromCache($cacheKey);
1749
-		if(!is_null($sid)) {
1749
+		if (!is_null($sid)) {
1750 1750
 			return $sid;
1751 1751
 		}
1752 1752
 
1753 1753
 		$objectSid = $this->readAttribute($domainDN, 'objectsid');
1754
-		if(!is_array($objectSid) || empty($objectSid)) {
1754
+		if (!is_array($objectSid) || empty($objectSid)) {
1755 1755
 			$this->connection->writeToCache($cacheKey, false);
1756 1756
 			return false;
1757 1757
 		}
@@ -1809,12 +1809,12 @@  discard block
 block discarded – undo
1809 1809
 		$belongsToBase = false;
1810 1810
 		$bases = $this->helper->sanitizeDN($bases);
1811 1811
 
1812
-		foreach($bases as $base) {
1812
+		foreach ($bases as $base) {
1813 1813
 			$belongsToBase = true;
1814
-			if(mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8')-mb_strlen($base, 'UTF-8'))) {
1814
+			if (mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8') - mb_strlen($base, 'UTF-8'))) {
1815 1815
 				$belongsToBase = false;
1816 1816
 			}
1817
-			if($belongsToBase) {
1817
+			if ($belongsToBase) {
1818 1818
 				break;
1819 1819
 			}
1820 1820
 		}
@@ -1825,7 +1825,7 @@  discard block
 block discarded – undo
1825 1825
 	 * resets a running Paged Search operation
1826 1826
 	 */
1827 1827
 	private function abandonPagedSearch() {
1828
-		if($this->connection->hasPagedResultSupport) {
1828
+		if ($this->connection->hasPagedResultSupport) {
1829 1829
 			$cr = $this->connection->getConnectionResource();
1830 1830
 			$this->invokeLDAPMethod('controlPagedResult', $cr, 0, false, $this->lastCookie);
1831 1831
 			$this->getPagedSearchResultState();
@@ -1843,16 +1843,16 @@  discard block
 block discarded – undo
1843 1843
 	 * @return string containing the key or empty if none is cached
1844 1844
 	 */
1845 1845
 	private function getPagedResultCookie($base, $filter, $limit, $offset) {
1846
-		if($offset === 0) {
1846
+		if ($offset === 0) {
1847 1847
 			return '';
1848 1848
 		}
1849 1849
 		$offset -= $limit;
1850 1850
 		//we work with cache here
1851
-		$cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . (int)$limit . '-' . (int)$offset;
1851
+		$cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.(int) $limit.'-'.(int) $offset;
1852 1852
 		$cookie = '';
1853
-		if(isset($this->cookies[$cacheKey])) {
1853
+		if (isset($this->cookies[$cacheKey])) {
1854 1854
 			$cookie = $this->cookies[$cacheKey];
1855
-			if(is_null($cookie)) {
1855
+			if (is_null($cookie)) {
1856 1856
 				$cookie = '';
1857 1857
 			}
1858 1858
 		}
@@ -1870,11 +1870,11 @@  discard block
 block discarded – undo
1870 1870
 	 * @return bool
1871 1871
 	 */
1872 1872
 	public function hasMoreResults() {
1873
-		if(!$this->connection->hasPagedResultSupport) {
1873
+		if (!$this->connection->hasPagedResultSupport) {
1874 1874
 			return false;
1875 1875
 		}
1876 1876
 
1877
-		if(empty($this->lastCookie) && $this->lastCookie !== '0') {
1877
+		if (empty($this->lastCookie) && $this->lastCookie !== '0') {
1878 1878
 			// as in RFC 2696, when all results are returned, the cookie will
1879 1879
 			// be empty.
1880 1880
 			return false;
@@ -1894,8 +1894,8 @@  discard block
 block discarded – undo
1894 1894
 	 */
1895 1895
 	private function setPagedResultCookie($base, $filter, $limit, $offset, $cookie) {
1896 1896
 		// allow '0' for 389ds
1897
-		if(!empty($cookie) || $cookie === '0') {
1898
-			$cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . (int)$limit . '-' . (int)$offset;
1897
+		if (!empty($cookie) || $cookie === '0') {
1898
+			$cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.(int) $limit.'-'.(int) $offset;
1899 1899
 			$this->cookies[$cacheKey] = $cookie;
1900 1900
 			$this->lastCookie = $cookie;
1901 1901
 		}
@@ -1922,17 +1922,17 @@  discard block
 block discarded – undo
1922 1922
 	 */
1923 1923
 	private function initPagedSearch($filter, $bases, $attr, $limit, $offset) {
1924 1924
 		$pagedSearchOK = false;
1925
-		if($this->connection->hasPagedResultSupport && ($limit !== 0)) {
1926
-			$offset = (int)$offset; //can be null
1925
+		if ($this->connection->hasPagedResultSupport && ($limit !== 0)) {
1926
+			$offset = (int) $offset; //can be null
1927 1927
 			\OCP\Util::writeLog('user_ldap',
1928 1928
 				'initializing paged search for  Filter '.$filter.' base '.print_r($bases, true)
1929
-				.' attr '.print_r($attr, true). ' limit ' .$limit.' offset '.$offset,
1929
+				.' attr '.print_r($attr, true).' limit '.$limit.' offset '.$offset,
1930 1930
 				\OCP\Util::DEBUG);
1931 1931
 			//get the cookie from the search for the previous search, required by LDAP
1932
-			foreach($bases as $base) {
1932
+			foreach ($bases as $base) {
1933 1933
 
1934 1934
 				$cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset);
1935
-				if(empty($cookie) && $cookie !== "0" && ($offset > 0)) {
1935
+				if (empty($cookie) && $cookie !== "0" && ($offset > 0)) {
1936 1936
 					// no cookie known from a potential previous search. We need
1937 1937
 					// to start from 0 to come to the desired page. cookie value
1938 1938
 					// of '0' is valid, because 389ds
@@ -1942,17 +1942,17 @@  discard block
 block discarded – undo
1942 1942
 					//still no cookie? obviously, the server does not like us. Let's skip paging efforts.
1943 1943
 					// '0' is valid, because 389ds
1944 1944
 					//TODO: remember this, probably does not change in the next request...
1945
-					if(empty($cookie) && $cookie !== '0') {
1945
+					if (empty($cookie) && $cookie !== '0') {
1946 1946
 						$cookie = null;
1947 1947
 					}
1948 1948
 				}
1949
-				if(!is_null($cookie)) {
1949
+				if (!is_null($cookie)) {
1950 1950
 					//since offset = 0, this is a new search. We abandon other searches that might be ongoing.
1951 1951
 					$this->abandonPagedSearch();
1952 1952
 					$pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult',
1953 1953
 						$this->connection->getConnectionResource(), $limit,
1954 1954
 						false, $cookie);
1955
-					if(!$pagedSearchOK) {
1955
+					if (!$pagedSearchOK) {
1956 1956
 						return false;
1957 1957
 					}
1958 1958
 					\OCP\Util::writeLog('user_ldap', 'Ready for a paged search', \OCP\Util::DEBUG);
@@ -1968,14 +1968,14 @@  discard block
 block discarded – undo
1968 1968
 		 * So we added "&& !empty($this->lastCookie)" to this test to ignore pagination
1969 1969
 		 * if we don't have a previous paged search.
1970 1970
 		 */
1971
-		} else if($this->connection->hasPagedResultSupport && $limit === 0 && !empty($this->lastCookie)) {
1971
+		} else if ($this->connection->hasPagedResultSupport && $limit === 0 && !empty($this->lastCookie)) {
1972 1972
 			// a search without limit was requested. However, if we do use
1973 1973
 			// Paged Search once, we always must do it. This requires us to
1974 1974
 			// initialize it with the configured page size.
1975 1975
 			$this->abandonPagedSearch();
1976 1976
 			// in case someone set it to 0 … use 500, otherwise no results will
1977 1977
 			// be returned.
1978
-			$pageSize = (int)$this->connection->ldapPagingSize > 0 ? (int)$this->connection->ldapPagingSize : 500;
1978
+			$pageSize = (int) $this->connection->ldapPagingSize > 0 ? (int) $this->connection->ldapPagingSize : 500;
1979 1979
 			$pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult',
1980 1980
 				$this->connection->getConnectionResource(),
1981 1981
 				$pageSize, false, '');
Please login to merge, or discard this patch.