Completed
Pull Request — master (#8634)
by Blizzz
36:51 queued 20:51
created
apps/user_ldap/lib/Access.php 1 patch
Spacing   +182 added lines, -182 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
 	}
@@ -1306,7 +1306,7 @@  discard block
 block discarded – undo
1306 1306
 	 * @return string
1307 1307
 	 */
1308 1308
 	public function sanitizeUsername($name) {
1309
-		if($this->connection->ldapIgnoreNamingRules) {
1309
+		if ($this->connection->ldapIgnoreNamingRules) {
1310 1310
 			return trim($name);
1311 1311
 		}
1312 1312
 
@@ -1320,7 +1320,7 @@  discard block
 block discarded – undo
1320 1320
 		// Every remaining disallowed characters will be removed
1321 1321
 		$name = preg_replace('/[^a-zA-Z0-9_.@-]/u', '', $name);
1322 1322
 
1323
-		if($name === '') {
1323
+		if ($name === '') {
1324 1324
 			throw new \InvalidArgumentException('provided name template for username does not contain any allowed characters');
1325 1325
 		}
1326 1326
 
@@ -1335,13 +1335,13 @@  discard block
 block discarded – undo
1335 1335
 	*/
1336 1336
 	public function escapeFilterPart($input, $allowAsterisk = false) {
1337 1337
 		$asterisk = '';
1338
-		if($allowAsterisk && strlen($input) > 0 && $input[0] === '*') {
1338
+		if ($allowAsterisk && strlen($input) > 0 && $input[0] === '*') {
1339 1339
 			$asterisk = '*';
1340 1340
 			$input = mb_substr($input, 1, null, 'UTF-8');
1341 1341
 		}
1342 1342
 		$search  = array('*', '\\', '(', ')');
1343 1343
 		$replace = array('\\*', '\\\\', '\\(', '\\)');
1344
-		return $asterisk . str_replace($search, $replace, $input);
1344
+		return $asterisk.str_replace($search, $replace, $input);
1345 1345
 	}
1346 1346
 
1347 1347
 	/**
@@ -1371,13 +1371,13 @@  discard block
 block discarded – undo
1371 1371
 	 */
1372 1372
 	private function combineFilter($filters, $operator) {
1373 1373
 		$combinedFilter = '('.$operator;
1374
-		foreach($filters as $filter) {
1374
+		foreach ($filters as $filter) {
1375 1375
 			if ($filter !== '' && $filter[0] !== '(') {
1376 1376
 				$filter = '('.$filter.')';
1377 1377
 			}
1378
-			$combinedFilter.=$filter;
1378
+			$combinedFilter .= $filter;
1379 1379
 		}
1380
-		$combinedFilter.=')';
1380
+		$combinedFilter .= ')';
1381 1381
 		return $combinedFilter;
1382 1382
 	}
1383 1383
 
@@ -1413,17 +1413,17 @@  discard block
 block discarded – undo
1413 1413
 	 * @throws \Exception
1414 1414
 	 */
1415 1415
 	private function getAdvancedFilterPartForSearch($search, $searchAttributes) {
1416
-		if(!is_array($searchAttributes) || count($searchAttributes) < 2) {
1416
+		if (!is_array($searchAttributes) || count($searchAttributes) < 2) {
1417 1417
 			throw new \Exception('searchAttributes must be an array with at least two string');
1418 1418
 		}
1419 1419
 		$searchWords = explode(' ', trim($search));
1420 1420
 		$wordFilters = array();
1421
-		foreach($searchWords as $word) {
1421
+		foreach ($searchWords as $word) {
1422 1422
 			$word = $this->prepareSearchTerm($word);
1423 1423
 			//every word needs to appear at least once
1424 1424
 			$wordMatchOneAttrFilters = array();
1425
-			foreach($searchAttributes as $attr) {
1426
-				$wordMatchOneAttrFilters[] = $attr . '=' . $word;
1425
+			foreach ($searchAttributes as $attr) {
1426
+				$wordMatchOneAttrFilters[] = $attr.'='.$word;
1427 1427
 			}
1428 1428
 			$wordFilters[] = $this->combineFilterWithOr($wordMatchOneAttrFilters);
1429 1429
 		}
@@ -1441,10 +1441,10 @@  discard block
 block discarded – undo
1441 1441
 	private function getFilterPartForSearch($search, $searchAttributes, $fallbackAttribute) {
1442 1442
 		$filter = array();
1443 1443
 		$haveMultiSearchAttributes = (is_array($searchAttributes) && count($searchAttributes) > 0);
1444
-		if($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) {
1444
+		if ($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) {
1445 1445
 			try {
1446 1446
 				return $this->getAdvancedFilterPartForSearch($search, $searchAttributes);
1447
-			} catch(\Exception $e) {
1447
+			} catch (\Exception $e) {
1448 1448
 				\OCP\Util::writeLog(
1449 1449
 					'user_ldap',
1450 1450
 					'Creating advanced filter for search failed, falling back to simple method.',
@@ -1454,17 +1454,17 @@  discard block
 block discarded – undo
1454 1454
 		}
1455 1455
 
1456 1456
 		$search = $this->prepareSearchTerm($search);
1457
-		if(!is_array($searchAttributes) || count($searchAttributes) === 0) {
1457
+		if (!is_array($searchAttributes) || count($searchAttributes) === 0) {
1458 1458
 			if ($fallbackAttribute === '') {
1459 1459
 				return '';
1460 1460
 			}
1461
-			$filter[] = $fallbackAttribute . '=' . $search;
1461
+			$filter[] = $fallbackAttribute.'='.$search;
1462 1462
 		} else {
1463
-			foreach($searchAttributes as $attribute) {
1464
-				$filter[] = $attribute . '=' . $search;
1463
+			foreach ($searchAttributes as $attribute) {
1464
+				$filter[] = $attribute.'='.$search;
1465 1465
 			}
1466 1466
 		}
1467
-		if(count($filter) === 1) {
1467
+		if (count($filter) === 1) {
1468 1468
 			return '('.$filter[0].')';
1469 1469
 		}
1470 1470
 		return $this->combineFilterWithOr($filter);
@@ -1485,7 +1485,7 @@  discard block
 block discarded – undo
1485 1485
 		if ($term === '') {
1486 1486
 			$result = '*';
1487 1487
 		} else if ($allowEnum !== 'no') {
1488
-			$result = $term . '*';
1488
+			$result = $term.'*';
1489 1489
 		}
1490 1490
 		return $result;
1491 1491
 	}
@@ -1497,7 +1497,7 @@  discard block
 block discarded – undo
1497 1497
 	public function getFilterForUserCount() {
1498 1498
 		$filter = $this->combineFilterWithAnd(array(
1499 1499
 			$this->connection->ldapUserFilter,
1500
-			$this->connection->ldapUserDisplayName . '=*'
1500
+			$this->connection->ldapUserDisplayName.'=*'
1501 1501
 		));
1502 1502
 
1503 1503
 		return $filter;
@@ -1515,7 +1515,7 @@  discard block
 block discarded – undo
1515 1515
 			'ldapAgentName' => $name,
1516 1516
 			'ldapAgentPassword' => $password
1517 1517
 		);
1518
-		if(!$testConnection->setConfiguration($credentials)) {
1518
+		if (!$testConnection->setConfiguration($credentials)) {
1519 1519
 			return false;
1520 1520
 		}
1521 1521
 		return $testConnection->bind();
@@ -1537,30 +1537,30 @@  discard block
 block discarded – undo
1537 1537
 			// Sacrebleu! The UUID attribute is unknown :( We need first an
1538 1538
 			// existing DN to be able to reliably detect it.
1539 1539
 			$result = $this->search($filter, $base, ['dn'], 1);
1540
-			if(!isset($result[0]) || !isset($result[0]['dn'])) {
1540
+			if (!isset($result[0]) || !isset($result[0]['dn'])) {
1541 1541
 				throw new \Exception('Cannot determine UUID attribute');
1542 1542
 			}
1543 1543
 			$dn = $result[0]['dn'][0];
1544
-			if(!$this->detectUuidAttribute($dn, true)) {
1544
+			if (!$this->detectUuidAttribute($dn, true)) {
1545 1545
 				throw new \Exception('Cannot determine UUID attribute');
1546 1546
 			}
1547 1547
 		} else {
1548 1548
 			// The UUID attribute is either known or an override is given.
1549 1549
 			// By calling this method we ensure that $this->connection->$uuidAttr
1550 1550
 			// is definitely set
1551
-			if(!$this->detectUuidAttribute('', true)) {
1551
+			if (!$this->detectUuidAttribute('', true)) {
1552 1552
 				throw new \Exception('Cannot determine UUID attribute');
1553 1553
 			}
1554 1554
 		}
1555 1555
 
1556 1556
 		$uuidAttr = $this->connection->ldapUuidUserAttribute;
1557
-		if($uuidAttr === 'guid' || $uuidAttr === 'objectguid') {
1557
+		if ($uuidAttr === 'guid' || $uuidAttr === 'objectguid') {
1558 1558
 			$uuid = $this->formatGuid2ForFilterUser($uuid);
1559 1559
 		}
1560 1560
 
1561
-		$filter = $uuidAttr . '=' . $uuid;
1561
+		$filter = $uuidAttr.'='.$uuid;
1562 1562
 		$result = $this->searchUsers($filter, ['dn'], 2);
1563
-		if(is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) {
1563
+		if (is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) {
1564 1564
 			// we put the count into account to make sure that this is
1565 1565
 			// really unique
1566 1566
 			return $result[0]['dn'][0];
@@ -1579,7 +1579,7 @@  discard block
 block discarded – undo
1579 1579
 	 * @return bool true on success, false otherwise
1580 1580
 	 */
1581 1581
 	private function detectUuidAttribute($dn, $isUser = true, $force = false, array $ldapRecord = null) {
1582
-		if($isUser) {
1582
+		if ($isUser) {
1583 1583
 			$uuidAttr     = 'ldapUuidUserAttribute';
1584 1584
 			$uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
1585 1585
 		} else {
@@ -1587,7 +1587,7 @@  discard block
 block discarded – undo
1587 1587
 			$uuidOverride = $this->connection->ldapExpertUUIDGroupAttr;
1588 1588
 		}
1589 1589
 
1590
-		if(($this->connection->$uuidAttr !== 'auto') && !$force) {
1590
+		if (($this->connection->$uuidAttr !== 'auto') && !$force) {
1591 1591
 			return true;
1592 1592
 		}
1593 1593
 
@@ -1596,10 +1596,10 @@  discard block
 block discarded – undo
1596 1596
 			return true;
1597 1597
 		}
1598 1598
 
1599
-		foreach(self::UUID_ATTRIBUTES as $attribute) {
1600
-			if($ldapRecord !== null) {
1599
+		foreach (self::UUID_ATTRIBUTES as $attribute) {
1600
+			if ($ldapRecord !== null) {
1601 1601
 				// we have the info from LDAP already, we don't need to talk to the server again
1602
-				if(isset($ldapRecord[$attribute])) {
1602
+				if (isset($ldapRecord[$attribute])) {
1603 1603
 					$this->connection->$uuidAttr = $attribute;
1604 1604
 					return true;
1605 1605
 				} else {
@@ -1608,7 +1608,7 @@  discard block
 block discarded – undo
1608 1608
 			}
1609 1609
 
1610 1610
 			$value = $this->readAttribute($dn, $attribute);
1611
-			if(is_array($value) && isset($value[0]) && !empty($value[0])) {
1611
+			if (is_array($value) && isset($value[0]) && !empty($value[0])) {
1612 1612
 				\OCP\Util::writeLog('user_ldap',
1613 1613
 									'Setting '.$attribute.' as '.$uuidAttr,
1614 1614
 									\OCP\Util::DEBUG);
@@ -1630,7 +1630,7 @@  discard block
 block discarded – undo
1630 1630
 	 * @return bool|string
1631 1631
 	 */
1632 1632
 	public function getUUID($dn, $isUser = true, $ldapRecord = null) {
1633
-		if($isUser) {
1633
+		if ($isUser) {
1634 1634
 			$uuidAttr     = 'ldapUuidUserAttribute';
1635 1635
 			$uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
1636 1636
 		} else {
@@ -1639,10 +1639,10 @@  discard block
 block discarded – undo
1639 1639
 		}
1640 1640
 
1641 1641
 		$uuid = false;
1642
-		if($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) {
1642
+		if ($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) {
1643 1643
 			$attr = $this->connection->$uuidAttr;
1644 1644
 			$uuid = isset($ldapRecord[$attr]) ? $ldapRecord[$attr] : $this->readAttribute($dn, $attr);
1645
-			if( !is_array($uuid)
1645
+			if (!is_array($uuid)
1646 1646
 				&& $uuidOverride !== ''
1647 1647
 				&& $this->detectUuidAttribute($dn, $isUser, true, $ldapRecord))
1648 1648
 			{
@@ -1650,7 +1650,7 @@  discard block
 block discarded – undo
1650 1650
 					? $ldapRecord[$this->connection->$uuidAttr]
1651 1651
 					: $this->readAttribute($dn, $this->connection->$uuidAttr);
1652 1652
 			}
1653
-			if(is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) {
1653
+			if (is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) {
1654 1654
 				$uuid = $uuid[0];
1655 1655
 			}
1656 1656
 		}
@@ -1667,19 +1667,19 @@  discard block
 block discarded – undo
1667 1667
 	private function convertObjectGUID2Str($oguid) {
1668 1668
 		$hex_guid = bin2hex($oguid);
1669 1669
 		$hex_guid_to_guid_str = '';
1670
-		for($k = 1; $k <= 4; ++$k) {
1670
+		for ($k = 1; $k <= 4; ++$k) {
1671 1671
 			$hex_guid_to_guid_str .= substr($hex_guid, 8 - 2 * $k, 2);
1672 1672
 		}
1673 1673
 		$hex_guid_to_guid_str .= '-';
1674
-		for($k = 1; $k <= 2; ++$k) {
1674
+		for ($k = 1; $k <= 2; ++$k) {
1675 1675
 			$hex_guid_to_guid_str .= substr($hex_guid, 12 - 2 * $k, 2);
1676 1676
 		}
1677 1677
 		$hex_guid_to_guid_str .= '-';
1678
-		for($k = 1; $k <= 2; ++$k) {
1678
+		for ($k = 1; $k <= 2; ++$k) {
1679 1679
 			$hex_guid_to_guid_str .= substr($hex_guid, 16 - 2 * $k, 2);
1680 1680
 		}
1681
-		$hex_guid_to_guid_str .= '-' . substr($hex_guid, 16, 4);
1682
-		$hex_guid_to_guid_str .= '-' . substr($hex_guid, 20);
1681
+		$hex_guid_to_guid_str .= '-'.substr($hex_guid, 16, 4);
1682
+		$hex_guid_to_guid_str .= '-'.substr($hex_guid, 20);
1683 1683
 
1684 1684
 		return strtoupper($hex_guid_to_guid_str);
1685 1685
 	}
@@ -1696,11 +1696,11 @@  discard block
 block discarded – undo
1696 1696
 	 * @return string
1697 1697
 	 */
1698 1698
 	public function formatGuid2ForFilterUser($guid) {
1699
-		if(!is_string($guid)) {
1699
+		if (!is_string($guid)) {
1700 1700
 			throw new \InvalidArgumentException('String expected');
1701 1701
 		}
1702 1702
 		$blocks = explode('-', $guid);
1703
-		if(count($blocks) !== 5) {
1703
+		if (count($blocks) !== 5) {
1704 1704
 			/*
1705 1705
 			 * Why not throw an Exception instead? This method is a utility
1706 1706
 			 * called only when trying to figure out whether a "missing" known
@@ -1713,20 +1713,20 @@  discard block
 block discarded – undo
1713 1713
 			 * user. Instead we write a log message.
1714 1714
 			 */
1715 1715
 			\OC::$server->getLogger()->info(
1716
-				'Passed string does not resemble a valid GUID. Known UUID ' .
1716
+				'Passed string does not resemble a valid GUID. Known UUID '.
1717 1717
 				'({uuid}) probably does not match UUID configuration.',
1718
-				[ 'app' => 'user_ldap', 'uuid' => $guid ]
1718
+				['app' => 'user_ldap', 'uuid' => $guid]
1719 1719
 			);
1720 1720
 			return $guid;
1721 1721
 		}
1722
-		for($i=0; $i < 3; $i++) {
1722
+		for ($i = 0; $i < 3; $i++) {
1723 1723
 			$pairs = str_split($blocks[$i], 2);
1724 1724
 			$pairs = array_reverse($pairs);
1725 1725
 			$blocks[$i] = implode('', $pairs);
1726 1726
 		}
1727
-		for($i=0; $i < 5; $i++) {
1727
+		for ($i = 0; $i < 5; $i++) {
1728 1728
 			$pairs = str_split($blocks[$i], 2);
1729
-			$blocks[$i] = '\\' . implode('\\', $pairs);
1729
+			$blocks[$i] = '\\'.implode('\\', $pairs);
1730 1730
 		}
1731 1731
 		return implode('', $blocks);
1732 1732
 	}
@@ -1740,12 +1740,12 @@  discard block
 block discarded – undo
1740 1740
 		$domainDN = $this->getDomainDNFromDN($dn);
1741 1741
 		$cacheKey = 'getSID-'.$domainDN;
1742 1742
 		$sid = $this->connection->getFromCache($cacheKey);
1743
-		if(!is_null($sid)) {
1743
+		if (!is_null($sid)) {
1744 1744
 			return $sid;
1745 1745
 		}
1746 1746
 
1747 1747
 		$objectSid = $this->readAttribute($domainDN, 'objectsid');
1748
-		if(!is_array($objectSid) || empty($objectSid)) {
1748
+		if (!is_array($objectSid) || empty($objectSid)) {
1749 1749
 			$this->connection->writeToCache($cacheKey, false);
1750 1750
 			return false;
1751 1751
 		}
@@ -1803,12 +1803,12 @@  discard block
 block discarded – undo
1803 1803
 		$belongsToBase = false;
1804 1804
 		$bases = $this->helper->sanitizeDN($bases);
1805 1805
 
1806
-		foreach($bases as $base) {
1806
+		foreach ($bases as $base) {
1807 1807
 			$belongsToBase = true;
1808
-			if(mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8')-mb_strlen($base, 'UTF-8'))) {
1808
+			if (mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8') - mb_strlen($base, 'UTF-8'))) {
1809 1809
 				$belongsToBase = false;
1810 1810
 			}
1811
-			if($belongsToBase) {
1811
+			if ($belongsToBase) {
1812 1812
 				break;
1813 1813
 			}
1814 1814
 		}
@@ -1819,7 +1819,7 @@  discard block
 block discarded – undo
1819 1819
 	 * resets a running Paged Search operation
1820 1820
 	 */
1821 1821
 	private function abandonPagedSearch() {
1822
-		if($this->connection->hasPagedResultSupport) {
1822
+		if ($this->connection->hasPagedResultSupport) {
1823 1823
 			$cr = $this->connection->getConnectionResource();
1824 1824
 			$this->invokeLDAPMethod('controlPagedResult', $cr, 0, false, $this->lastCookie);
1825 1825
 			$this->getPagedSearchResultState();
@@ -1837,16 +1837,16 @@  discard block
 block discarded – undo
1837 1837
 	 * @return string containing the key or empty if none is cached
1838 1838
 	 */
1839 1839
 	private function getPagedResultCookie($base, $filter, $limit, $offset) {
1840
-		if($offset === 0) {
1840
+		if ($offset === 0) {
1841 1841
 			return '';
1842 1842
 		}
1843 1843
 		$offset -= $limit;
1844 1844
 		//we work with cache here
1845
-		$cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . (int)$limit . '-' . (int)$offset;
1845
+		$cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.(int) $limit.'-'.(int) $offset;
1846 1846
 		$cookie = '';
1847
-		if(isset($this->cookies[$cacheKey])) {
1847
+		if (isset($this->cookies[$cacheKey])) {
1848 1848
 			$cookie = $this->cookies[$cacheKey];
1849
-			if(is_null($cookie)) {
1849
+			if (is_null($cookie)) {
1850 1850
 				$cookie = '';
1851 1851
 			}
1852 1852
 		}
@@ -1864,11 +1864,11 @@  discard block
 block discarded – undo
1864 1864
 	 * @return bool
1865 1865
 	 */
1866 1866
 	public function hasMoreResults() {
1867
-		if(!$this->connection->hasPagedResultSupport) {
1867
+		if (!$this->connection->hasPagedResultSupport) {
1868 1868
 			return false;
1869 1869
 		}
1870 1870
 
1871
-		if(empty($this->lastCookie) && $this->lastCookie !== '0') {
1871
+		if (empty($this->lastCookie) && $this->lastCookie !== '0') {
1872 1872
 			// as in RFC 2696, when all results are returned, the cookie will
1873 1873
 			// be empty.
1874 1874
 			return false;
@@ -1888,8 +1888,8 @@  discard block
 block discarded – undo
1888 1888
 	 */
1889 1889
 	private function setPagedResultCookie($base, $filter, $limit, $offset, $cookie) {
1890 1890
 		// allow '0' for 389ds
1891
-		if(!empty($cookie) || $cookie === '0') {
1892
-			$cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . (int)$limit . '-' . (int)$offset;
1891
+		if (!empty($cookie) || $cookie === '0') {
1892
+			$cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.(int) $limit.'-'.(int) $offset;
1893 1893
 			$this->cookies[$cacheKey] = $cookie;
1894 1894
 			$this->lastCookie = $cookie;
1895 1895
 		}
@@ -1916,17 +1916,17 @@  discard block
 block discarded – undo
1916 1916
 	 */
1917 1917
 	private function initPagedSearch($filter, $bases, $attr, $limit, $offset) {
1918 1918
 		$pagedSearchOK = false;
1919
-		if($this->connection->hasPagedResultSupport && ($limit !== 0)) {
1920
-			$offset = (int)$offset; //can be null
1919
+		if ($this->connection->hasPagedResultSupport && ($limit !== 0)) {
1920
+			$offset = (int) $offset; //can be null
1921 1921
 			\OCP\Util::writeLog('user_ldap',
1922 1922
 				'initializing paged search for  Filter '.$filter.' base '.print_r($bases, true)
1923
-				.' attr '.print_r($attr, true). ' limit ' .$limit.' offset '.$offset,
1923
+				.' attr '.print_r($attr, true).' limit '.$limit.' offset '.$offset,
1924 1924
 				\OCP\Util::DEBUG);
1925 1925
 			//get the cookie from the search for the previous search, required by LDAP
1926
-			foreach($bases as $base) {
1926
+			foreach ($bases as $base) {
1927 1927
 
1928 1928
 				$cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset);
1929
-				if(empty($cookie) && $cookie !== "0" && ($offset > 0)) {
1929
+				if (empty($cookie) && $cookie !== "0" && ($offset > 0)) {
1930 1930
 					// no cookie known from a potential previous search. We need
1931 1931
 					// to start from 0 to come to the desired page. cookie value
1932 1932
 					// of '0' is valid, because 389ds
@@ -1936,17 +1936,17 @@  discard block
 block discarded – undo
1936 1936
 					//still no cookie? obviously, the server does not like us. Let's skip paging efforts.
1937 1937
 					// '0' is valid, because 389ds
1938 1938
 					//TODO: remember this, probably does not change in the next request...
1939
-					if(empty($cookie) && $cookie !== '0') {
1939
+					if (empty($cookie) && $cookie !== '0') {
1940 1940
 						$cookie = null;
1941 1941
 					}
1942 1942
 				}
1943
-				if(!is_null($cookie)) {
1943
+				if (!is_null($cookie)) {
1944 1944
 					//since offset = 0, this is a new search. We abandon other searches that might be ongoing.
1945 1945
 					$this->abandonPagedSearch();
1946 1946
 					$pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult',
1947 1947
 						$this->connection->getConnectionResource(), $limit,
1948 1948
 						false, $cookie);
1949
-					if(!$pagedSearchOK) {
1949
+					if (!$pagedSearchOK) {
1950 1950
 						return false;
1951 1951
 					}
1952 1952
 					\OCP\Util::writeLog('user_ldap', 'Ready for a paged search', \OCP\Util::DEBUG);
@@ -1962,14 +1962,14 @@  discard block
 block discarded – undo
1962 1962
 		 * So we added "&& !empty($this->lastCookie)" to this test to ignore pagination
1963 1963
 		 * if we don't have a previous paged search.
1964 1964
 		 */
1965
-		} else if($this->connection->hasPagedResultSupport && $limit === 0 && !empty($this->lastCookie)) {
1965
+		} else if ($this->connection->hasPagedResultSupport && $limit === 0 && !empty($this->lastCookie)) {
1966 1966
 			// a search without limit was requested. However, if we do use
1967 1967
 			// Paged Search once, we always must do it. This requires us to
1968 1968
 			// initialize it with the configured page size.
1969 1969
 			$this->abandonPagedSearch();
1970 1970
 			// in case someone set it to 0 … use 500, otherwise no results will
1971 1971
 			// be returned.
1972
-			$pageSize = (int)$this->connection->ldapPagingSize > 0 ? (int)$this->connection->ldapPagingSize : 500;
1972
+			$pageSize = (int) $this->connection->ldapPagingSize > 0 ? (int) $this->connection->ldapPagingSize : 500;
1973 1973
 			$pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult',
1974 1974
 				$this->connection->getConnectionResource(),
1975 1975
 				$pageSize, false, '');
Please login to merge, or discard this patch.