Passed
Push — master ( 63c64b...0d0850 )
by Morris
10:58
created
apps/files/lib/Controller/ApiController.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -170,13 +170,13 @@  discard block
 block discarded – undo
170 170
 	 * @return array
171 171
 	 */
172 172
 	private function formatNodes(array $nodes) {
173
-		return array_values(array_map(function (Node $node) {
173
+		return array_values(array_map(function(Node $node) {
174 174
 			/** @var \OC\Files\Node\Node $shareTypes */
175 175
 			$shareTypes = $this->getShareTypes($node);
176 176
 			$file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo());
177 177
 			$parts = explode('/', dirname($node->getPath()), 4);
178 178
 			if (isset($parts[3])) {
179
-				$file['path'] = '/' . $parts[3];
179
+				$file['path'] = '/'.$parts[3];
180 180
 			} else {
181 181
 				$file['path'] = '/';
182 182
 			}
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 	 * @throws \OCP\PreConditionNotMetException
268 268
 	 */
269 269
 	public function showHiddenFiles($show) {
270
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int)$show);
270
+		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int) $show);
271 271
 		return new Response();
272 272
 	}
273 273
 
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 	 * @throws \OCP\PreConditionNotMetException
282 282
 	 */
283 283
 	public function showGridView($show) {
284
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', (int)$show);
284
+		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', (int) $show);
285 285
 		return new Response();
286 286
 	}
287 287
 
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
 		foreach ($navItems as $item) {
313 313
 			// check if data is valid
314 314
 			if (($show === 0 || $show === 1) && isset($item['expandedState']) && $key === $item['expandedState']) {
315
-				$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, (int)$show);
315
+				$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, (int) $show);
316 316
 				return new Response();
317 317
 			}
318 318
 		}
Please login to merge, or discard this patch.
apps/user_ldap/lib/Access.php 1 patch
Spacing   +190 added lines, -190 removed lines patch added patch discarded remove patch
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 	 * @return AbstractMapping
130 130
 	 */
131 131
 	public function getUserMapper() {
132
-		if(is_null($this->userMapper)) {
132
+		if (is_null($this->userMapper)) {
133 133
 			throw new \Exception('UserMapper was not assigned to this Access instance.');
134 134
 		}
135 135
 		return $this->userMapper;
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	 * @return AbstractMapping
150 150
 	 */
151 151
 	public function getGroupMapper() {
152
-		if(is_null($this->groupMapper)) {
152
+		if (is_null($this->groupMapper)) {
153 153
 			throw new \Exception('GroupMapper was not assigned to this Access instance.');
154 154
 		}
155 155
 		return $this->groupMapper;
@@ -182,14 +182,14 @@  discard block
 block discarded – undo
182 182
 	 * @throws ServerNotAvailableException
183 183
 	 */
184 184
 	public function readAttribute($dn, $attr, $filter = 'objectClass=*') {
185
-		if(!$this->checkConnection()) {
185
+		if (!$this->checkConnection()) {
186 186
 			\OCP\Util::writeLog('user_ldap',
187 187
 				'No LDAP Connector assigned, access impossible for readAttribute.',
188 188
 				ILogger::WARN);
189 189
 			return false;
190 190
 		}
191 191
 		$cr = $this->connection->getConnectionResource();
192
-		if(!$this->ldap->isResource($cr)) {
192
+		if (!$this->ldap->isResource($cr)) {
193 193
 			//LDAP not available
194 194
 			\OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', ILogger::DEBUG);
195 195
 			return false;
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 		$this->abandonPagedSearch();
200 200
 		// openLDAP requires that we init a new Paged Search. Not needed by AD,
201 201
 		// but does not hurt either.
202
-		$pagingSize = (int)$this->connection->ldapPagingSize;
202
+		$pagingSize = (int) $this->connection->ldapPagingSize;
203 203
 		// 0 won't result in replies, small numbers may leave out groups
204 204
 		// (cf. #12306), 500 is default for paging and should work everywhere.
205 205
 		$maxResults = $pagingSize > 20 ? $pagingSize : 500;
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 		$isRangeRequest = false;
213 213
 		do {
214 214
 			$result = $this->executeRead($cr, $dn, $attrToRead, $filter, $maxResults);
215
-			if(is_bool($result)) {
215
+			if (is_bool($result)) {
216 216
 				// when an exists request was run and it was successful, an empty
217 217
 				// array must be returned
218 218
 				return $result ? [] : false;
@@ -229,22 +229,22 @@  discard block
 block discarded – undo
229 229
 			$result = $this->extractRangeData($result, $attr);
230 230
 			if (!empty($result)) {
231 231
 				$normalizedResult = $this->extractAttributeValuesFromResult(
232
-					[ $attr => $result['values'] ],
232
+					[$attr => $result['values']],
233 233
 					$attr
234 234
 				);
235 235
 				$values = array_merge($values, $normalizedResult);
236 236
 
237
-				if($result['rangeHigh'] === '*') {
237
+				if ($result['rangeHigh'] === '*') {
238 238
 					// when server replies with * as high range value, there are
239 239
 					// no more results left
240 240
 					return $values;
241 241
 				} else {
242
-					$low  = $result['rangeHigh'] + 1;
243
-					$attrToRead = $result['attributeName'] . ';range=' . $low . '-*';
242
+					$low = $result['rangeHigh'] + 1;
243
+					$attrToRead = $result['attributeName'].';range='.$low.'-*';
244 244
 					$isRangeRequest = true;
245 245
 				}
246 246
 			}
247
-		} while($isRangeRequest);
247
+		} while ($isRangeRequest);
248 248
 
249 249
 		\OCP\Util::writeLog('user_ldap', 'Requested attribute '.$attr.' not found for '.$dn, ILogger::DEBUG);
250 250
 		return false;
@@ -270,13 +270,13 @@  discard block
 block discarded – undo
270 270
 		if (!$this->ldap->isResource($rr)) {
271 271
 			if ($attribute !== '') {
272 272
 				//do not throw this message on userExists check, irritates
273
-				\OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN ' . $dn, ILogger::DEBUG);
273
+				\OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN '.$dn, ILogger::DEBUG);
274 274
 			}
275 275
 			//in case an error occurs , e.g. object does not exist
276 276
 			return false;
277 277
 		}
278 278
 		if ($attribute === '' && ($filter === 'objectclass=*' || $this->invokeLDAPMethod('countEntries', $cr, $rr) === 1)) {
279
-			\OCP\Util::writeLog('user_ldap', 'readAttribute: ' . $dn . ' found', ILogger::DEBUG);
279
+			\OCP\Util::writeLog('user_ldap', 'readAttribute: '.$dn.' found', ILogger::DEBUG);
280 280
 			return true;
281 281
 		}
282 282
 		$er = $this->invokeLDAPMethod('firstEntry', $cr, $rr);
@@ -301,12 +301,12 @@  discard block
 block discarded – undo
301 301
 	 */
302 302
 	public function extractAttributeValuesFromResult($result, $attribute) {
303 303
 		$values = [];
304
-		if(isset($result[$attribute]) && $result[$attribute]['count'] > 0) {
304
+		if (isset($result[$attribute]) && $result[$attribute]['count'] > 0) {
305 305
 			$lowercaseAttribute = strtolower($attribute);
306
-			for($i=0;$i<$result[$attribute]['count'];$i++) {
307
-				if($this->resemblesDN($attribute)) {
306
+			for ($i = 0; $i < $result[$attribute]['count']; $i++) {
307
+				if ($this->resemblesDN($attribute)) {
308 308
 					$values[] = $this->helper->sanitizeDN($result[$attribute][$i]);
309
-				} elseif($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') {
309
+				} elseif ($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') {
310 310
 					$values[] = $this->convertObjectGUID2Str($result[$attribute][$i]);
311 311
 				} else {
312 312
 					$values[] = $result[$attribute][$i];
@@ -328,10 +328,10 @@  discard block
 block discarded – undo
328 328
 	 */
329 329
 	public function extractRangeData($result, $attribute) {
330 330
 		$keys = array_keys($result);
331
-		foreach($keys as $key) {
332
-			if($key !== $attribute && strpos($key, $attribute) === 0) {
331
+		foreach ($keys as $key) {
332
+			if ($key !== $attribute && strpos($key, $attribute) === 0) {
333 333
 				$queryData = explode(';', $key);
334
-				if(strpos($queryData[1], 'range=') === 0) {
334
+				if (strpos($queryData[1], 'range=') === 0) {
335 335
 					$high = substr($queryData[1], 1 + strpos($queryData[1], '-'));
336 336
 					$data = [
337 337
 						'values' => $result[$key],
@@ -356,18 +356,18 @@  discard block
 block discarded – undo
356 356
 	 * @throws \Exception
357 357
 	 */
358 358
 	public function setPassword($userDN, $password) {
359
-		if((int)$this->connection->turnOnPasswordChange !== 1) {
359
+		if ((int) $this->connection->turnOnPasswordChange !== 1) {
360 360
 			throw new \Exception('LDAP password changes are disabled.');
361 361
 		}
362 362
 		$cr = $this->connection->getConnectionResource();
363
-		if(!$this->ldap->isResource($cr)) {
363
+		if (!$this->ldap->isResource($cr)) {
364 364
 			//LDAP not available
365 365
 			\OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', ILogger::DEBUG);
366 366
 			return false;
367 367
 		}
368 368
 		try {
369 369
 			return @$this->invokeLDAPMethod('modReplace', $cr, $userDN, $password);
370
-		} catch(ConstraintViolationException $e) {
370
+		} catch (ConstraintViolationException $e) {
371 371
 			throw new HintException('Password change rejected.', \OC::$server->getL10N('user_ldap')->t('Password change rejected. Hint: ').$e->getMessage(), $e->getCode());
372 372
 		}
373 373
 	}
@@ -409,17 +409,17 @@  discard block
 block discarded – undo
409 409
 	 */
410 410
 	public function getDomainDNFromDN($dn) {
411 411
 		$allParts = $this->ldap->explodeDN($dn, 0);
412
-		if($allParts === false) {
412
+		if ($allParts === false) {
413 413
 			//not a valid DN
414 414
 			return '';
415 415
 		}
416 416
 		$domainParts = array();
417 417
 		$dcFound = false;
418
-		foreach($allParts as $part) {
419
-			if(!$dcFound && strpos($part, 'dc=') === 0) {
418
+		foreach ($allParts as $part) {
419
+			if (!$dcFound && strpos($part, 'dc=') === 0) {
420 420
 				$dcFound = true;
421 421
 			}
422
-			if($dcFound) {
422
+			if ($dcFound) {
423 423
 				$domainParts[] = $part;
424 424
 			}
425 425
 		}
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
 
446 446
 		//Check whether the DN belongs to the Base, to avoid issues on multi-
447 447
 		//server setups
448
-		if(is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
448
+		if (is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
449 449
 			return $fdn;
450 450
 		}
451 451
 
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
 		//To avoid bypassing the base DN settings under certain circumstances
465 465
 		//with the group support, check whether the provided DN matches one of
466 466
 		//the given Bases
467
-		if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) {
467
+		if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) {
468 468
 			return false;
469 469
 		}
470 470
 
@@ -482,11 +482,11 @@  discard block
 block discarded – undo
482 482
 	 */
483 483
 	public function groupsMatchFilter($groupDNs) {
484 484
 		$validGroupDNs = [];
485
-		foreach($groupDNs as $dn) {
485
+		foreach ($groupDNs as $dn) {
486 486
 			$cacheKey = 'groupsMatchFilter-'.$dn;
487 487
 			$groupMatchFilter = $this->connection->getFromCache($cacheKey);
488
-			if(!is_null($groupMatchFilter)) {
489
-				if($groupMatchFilter) {
488
+			if (!is_null($groupMatchFilter)) {
489
+				if ($groupMatchFilter) {
490 490
 					$validGroupDNs[] = $dn;
491 491
 				}
492 492
 				continue;
@@ -494,13 +494,13 @@  discard block
 block discarded – undo
494 494
 
495 495
 			// Check the base DN first. If this is not met already, we don't
496 496
 			// need to ask the server at all.
497
-			if(!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) {
497
+			if (!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) {
498 498
 				$this->connection->writeToCache($cacheKey, false);
499 499
 				continue;
500 500
 			}
501 501
 
502 502
 			$result = $this->readAttribute($dn, '', $this->connection->ldapGroupFilter);
503
-			if(is_array($result)) {
503
+			if (is_array($result)) {
504 504
 				$this->connection->writeToCache($cacheKey, true);
505 505
 				$validGroupDNs[] = $dn;
506 506
 			} else {
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
 		//To avoid bypassing the base DN settings under certain circumstances
524 524
 		//with the group support, check whether the provided DN matches one of
525 525
 		//the given Bases
526
-		if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
526
+		if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
527 527
 			return false;
528 528
 		}
529 529
 
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
 	 */
544 544
 	public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped = null, array $record = null) {
545 545
 		$newlyMapped = false;
546
-		if($isUser) {
546
+		if ($isUser) {
547 547
 			$mapper = $this->getUserMapper();
548 548
 			$nameAttribute = $this->connection->ldapUserDisplayName;
549 549
 			$filter = $this->connection->ldapUserFilter;
@@ -555,15 +555,15 @@  discard block
 block discarded – undo
555 555
 
556 556
 		//let's try to retrieve the Nextcloud name from the mappings table
557 557
 		$ncName = $mapper->getNameByDN($fdn);
558
-		if(is_string($ncName)) {
558
+		if (is_string($ncName)) {
559 559
 			return $ncName;
560 560
 		}
561 561
 
562 562
 		//second try: get the UUID and check if it is known. Then, update the DN and return the name.
563 563
 		$uuid = $this->getUUID($fdn, $isUser, $record);
564
-		if(is_string($uuid)) {
564
+		if (is_string($uuid)) {
565 565
 			$ncName = $mapper->getNameByUUID($uuid);
566
-			if(is_string($ncName)) {
566
+			if (is_string($ncName)) {
567 567
 				$mapper->setDNbyUUID($fdn, $uuid);
568 568
 				return $ncName;
569 569
 			}
@@ -573,17 +573,17 @@  discard block
 block discarded – undo
573 573
 			return false;
574 574
 		}
575 575
 
576
-		if(is_null($ldapName)) {
576
+		if (is_null($ldapName)) {
577 577
 			$ldapName = $this->readAttribute($fdn, $nameAttribute, $filter);
578
-			if(!isset($ldapName[0]) && empty($ldapName[0])) {
578
+			if (!isset($ldapName[0]) && empty($ldapName[0])) {
579 579
 				\OCP\Util::writeLog('user_ldap', 'No or empty name for '.$fdn.' with filter '.$filter.'.', ILogger::INFO);
580 580
 				return false;
581 581
 			}
582 582
 			$ldapName = $ldapName[0];
583 583
 		}
584 584
 
585
-		if($isUser) {
586
-			$usernameAttribute = (string)$this->connection->ldapExpertUsernameAttr;
585
+		if ($isUser) {
586
+			$usernameAttribute = (string) $this->connection->ldapExpertUsernameAttr;
587 587
 			if ($usernameAttribute !== '') {
588 588
 				$username = $this->readAttribute($fdn, $usernameAttribute);
589 589
 				$username = $username[0];
@@ -613,14 +613,14 @@  discard block
 block discarded – undo
613 613
 		// outside of core user management will still cache the user as non-existing.
614 614
 		$originalTTL = $this->connection->ldapCacheTTL;
615 615
 		$this->connection->setConfiguration(['ldapCacheTTL' => 0]);
616
-		if( $intName !== ''
616
+		if ($intName !== ''
617 617
 			&& (($isUser && !$this->ncUserManager->userExists($intName))
618 618
 				|| (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))
619 619
 			)
620 620
 		) {
621 621
 			$this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
622 622
 			$newlyMapped = $this->mapAndAnnounceIfApplicable($mapper, $fdn, $intName, $uuid, $isUser);
623
-			if($newlyMapped) {
623
+			if ($newlyMapped) {
624 624
 				return $intName;
625 625
 			}
626 626
 		}
@@ -628,7 +628,7 @@  discard block
 block discarded – undo
628 628
 		$this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
629 629
 		$altName = $this->createAltInternalOwnCloudName($intName, $isUser);
630 630
 		if (is_string($altName)) {
631
-			if($this->mapAndAnnounceIfApplicable($mapper, $fdn, $altName, $uuid, $isUser)) {
631
+			if ($this->mapAndAnnounceIfApplicable($mapper, $fdn, $altName, $uuid, $isUser)) {
632 632
 				$newlyMapped = true;
633 633
 				return $altName;
634 634
 			}
@@ -646,7 +646,7 @@  discard block
 block discarded – undo
646 646
 		string $uuid,
647 647
 		bool $isUser
648 648
 	) :bool {
649
-		if($mapper->map($fdn, $name, $uuid)) {
649
+		if ($mapper->map($fdn, $name, $uuid)) {
650 650
 			if ($this->ncUserManager instanceof PublicEmitter && $isUser) {
651 651
 				$this->cacheUserExists($name);
652 652
 				$this->ncUserManager->emit('\OC\User', 'assignedUserId', [$name]);
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
 	 * @throws \Exception
690 690
 	 */
691 691
 	private function ldap2NextcloudNames($ldapObjects, $isUsers) {
692
-		if($isUsers) {
692
+		if ($isUsers) {
693 693
 			$nameAttribute = $this->connection->ldapUserDisplayName;
694 694
 			$sndAttribute  = $this->connection->ldapUserDisplayName2;
695 695
 		} else {
@@ -697,9 +697,9 @@  discard block
 block discarded – undo
697 697
 		}
698 698
 		$nextcloudNames = [];
699 699
 
700
-		foreach($ldapObjects as $ldapObject) {
700
+		foreach ($ldapObjects as $ldapObject) {
701 701
 			$nameByLDAP = null;
702
-			if(    isset($ldapObject[$nameAttribute])
702
+			if (isset($ldapObject[$nameAttribute])
703 703
 				&& is_array($ldapObject[$nameAttribute])
704 704
 				&& isset($ldapObject[$nameAttribute][0])
705 705
 			) {
@@ -708,19 +708,19 @@  discard block
 block discarded – undo
708 708
 			}
709 709
 
710 710
 			$ncName = $this->dn2ocname($ldapObject['dn'][0], $nameByLDAP, $isUsers);
711
-			if($ncName) {
711
+			if ($ncName) {
712 712
 				$nextcloudNames[] = $ncName;
713
-				if($isUsers) {
713
+				if ($isUsers) {
714 714
 					$this->updateUserState($ncName);
715 715
 					//cache the user names so it does not need to be retrieved
716 716
 					//again later (e.g. sharing dialogue).
717
-					if(is_null($nameByLDAP)) {
717
+					if (is_null($nameByLDAP)) {
718 718
 						continue;
719 719
 					}
720 720
 					$sndName = isset($ldapObject[$sndAttribute][0])
721 721
 						? $ldapObject[$sndAttribute][0] : '';
722 722
 					$this->cacheUserDisplayName($ncName, $nameByLDAP, $sndName);
723
-				} else if($nameByLDAP !== null) {
723
+				} else if ($nameByLDAP !== null) {
724 724
 					$this->cacheGroupDisplayName($ncName, $nameByLDAP);
725 725
 				}
726 726
 			}
@@ -736,7 +736,7 @@  discard block
 block discarded – undo
736 736
 	 */
737 737
 	public function updateUserState($ncname) {
738 738
 		$user = $this->userManager->get($ncname);
739
-		if($user instanceof OfflineUser) {
739
+		if ($user instanceof OfflineUser) {
740 740
 			$user->unmark();
741 741
 		}
742 742
 	}
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
 	 */
770 770
 	public function cacheUserDisplayName($ocName, $displayName, $displayName2 = '') {
771 771
 		$user = $this->userManager->get($ocName);
772
-		if($user === null) {
772
+		if ($user === null) {
773 773
 			return;
774 774
 		}
775 775
 		$displayName = $user->composeAndStoreDisplayName($displayName, $displayName2);
@@ -778,7 +778,7 @@  discard block
 block discarded – undo
778 778
 	}
779 779
 
780 780
 	public function cacheGroupDisplayName(string $ncName, string $displayName): void {
781
-		$cacheKey = 'group_getDisplayName' . $ncName;
781
+		$cacheKey = 'group_getDisplayName'.$ncName;
782 782
 		$this->connection->writeToCache($cacheKey, $displayName);
783 783
 	}
784 784
 
@@ -794,9 +794,9 @@  discard block
 block discarded – undo
794 794
 		$attempts = 0;
795 795
 		//while loop is just a precaution. If a name is not generated within
796 796
 		//20 attempts, something else is very wrong. Avoids infinite loop.
797
-		while($attempts < 20){
798
-			$altName = $name . '_' . rand(1000,9999);
799
-			if(!$this->ncUserManager->userExists($altName)) {
797
+		while ($attempts < 20) {
798
+			$altName = $name.'_'.rand(1000, 9999);
799
+			if (!$this->ncUserManager->userExists($altName)) {
800 800
 				return $altName;
801 801
 			}
802 802
 			$attempts++;
@@ -818,25 +818,25 @@  discard block
 block discarded – undo
818 818
 	 */
819 819
 	private function _createAltInternalOwnCloudNameForGroups($name) {
820 820
 		$usedNames = $this->groupMapper->getNamesBySearch($name, "", '_%');
821
-		if(!$usedNames || count($usedNames) === 0) {
821
+		if (!$usedNames || count($usedNames) === 0) {
822 822
 			$lastNo = 1; //will become name_2
823 823
 		} else {
824 824
 			natsort($usedNames);
825 825
 			$lastName = array_pop($usedNames);
826
-			$lastNo = (int)substr($lastName, strrpos($lastName, '_') + 1);
826
+			$lastNo = (int) substr($lastName, strrpos($lastName, '_') + 1);
827 827
 		}
828
-		$altName = $name.'_'. (string)($lastNo+1);
828
+		$altName = $name.'_'.(string) ($lastNo + 1);
829 829
 		unset($usedNames);
830 830
 
831 831
 		$attempts = 1;
832
-		while($attempts < 21){
832
+		while ($attempts < 21) {
833 833
 			// Check to be really sure it is unique
834 834
 			// while loop is just a precaution. If a name is not generated within
835 835
 			// 20 attempts, something else is very wrong. Avoids infinite loop.
836
-			if(!\OC::$server->getGroupManager()->groupExists($altName)) {
836
+			if (!\OC::$server->getGroupManager()->groupExists($altName)) {
837 837
 				return $altName;
838 838
 			}
839
-			$altName = $name . '_' . ($lastNo + $attempts);
839
+			$altName = $name.'_'.($lastNo + $attempts);
840 840
 			$attempts++;
841 841
 		}
842 842
 		return false;
@@ -851,7 +851,7 @@  discard block
 block discarded – undo
851 851
 	private function createAltInternalOwnCloudName($name, $isUser) {
852 852
 		$originalTTL = $this->connection->ldapCacheTTL;
853 853
 		$this->connection->setConfiguration(array('ldapCacheTTL' => 0));
854
-		if($isUser) {
854
+		if ($isUser) {
855 855
 			$altName = $this->_createAltInternalOwnCloudNameForUsers($name);
856 856
 		} else {
857 857
 			$altName = $this->_createAltInternalOwnCloudNameForGroups($name);
@@ -900,13 +900,13 @@  discard block
 block discarded – undo
900 900
 	public function fetchListOfUsers($filter, $attr, $limit = null, $offset = null, $forceApplyAttributes = false) {
901 901
 		$ldapRecords = $this->searchUsers($filter, $attr, $limit, $offset);
902 902
 		$recordsToUpdate = $ldapRecords;
903
-		if(!$forceApplyAttributes) {
903
+		if (!$forceApplyAttributes) {
904 904
 			$isBackgroundJobModeAjax = $this->config
905 905
 					->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax';
906 906
 			$recordsToUpdate = array_filter($ldapRecords, function($record) use ($isBackgroundJobModeAjax) {
907 907
 				$newlyMapped = false;
908 908
 				$uid = $this->dn2ocname($record['dn'][0], null, true, $newlyMapped, $record);
909
-				if(is_string($uid)) {
909
+				if (is_string($uid)) {
910 910
 					$this->cacheUserExists($uid);
911 911
 				}
912 912
 				return ($uid !== false) && ($newlyMapped || $isBackgroundJobModeAjax);
@@ -924,15 +924,15 @@  discard block
 block discarded – undo
924 924
 	 * @param array $ldapRecords
925 925
 	 * @throws \Exception
926 926
 	 */
927
-	public function batchApplyUserAttributes(array $ldapRecords){
927
+	public function batchApplyUserAttributes(array $ldapRecords) {
928 928
 		$displayNameAttribute = strtolower($this->connection->ldapUserDisplayName);
929
-		foreach($ldapRecords as $userRecord) {
930
-			if(!isset($userRecord[$displayNameAttribute])) {
929
+		foreach ($ldapRecords as $userRecord) {
930
+			if (!isset($userRecord[$displayNameAttribute])) {
931 931
 				// displayName is obligatory
932 932
 				continue;
933 933
 			}
934
-			$ocName  = $this->dn2ocname($userRecord['dn'][0], null, true);
935
-			if($ocName === false) {
934
+			$ocName = $this->dn2ocname($userRecord['dn'][0], null, true);
935
+			if ($ocName === false) {
936 936
 				continue;
937 937
 			}
938 938
 			$this->updateUserState($ocName);
@@ -965,8 +965,8 @@  discard block
 block discarded – undo
965 965
 	 * @return array
966 966
 	 */
967 967
 	private function fetchList($list, $manyAttributes) {
968
-		if(is_array($list)) {
969
-			if($manyAttributes) {
968
+		if (is_array($list)) {
969
+			if ($manyAttributes) {
970 970
 				return $list;
971 971
 			} else {
972 972
 				$list = array_reduce($list, function($carry, $item) {
@@ -996,7 +996,7 @@  discard block
 block discarded – undo
996 996
 	 */
997 997
 	public function searchUsers($filter, $attr = null, $limit = null, $offset = null) {
998 998
 		$result = [];
999
-		foreach($this->connection->ldapBaseUsers as $base) {
999
+		foreach ($this->connection->ldapBaseUsers as $base) {
1000 1000
 			$result = array_merge($result, $this->search($filter, [$base], $attr, $limit, $offset));
1001 1001
 		}
1002 1002
 		return $result;
@@ -1012,9 +1012,9 @@  discard block
 block discarded – undo
1012 1012
 	 */
1013 1013
 	public function countUsers($filter, $attr = array('dn'), $limit = null, $offset = null) {
1014 1014
 		$result = false;
1015
-		foreach($this->connection->ldapBaseUsers as $base) {
1015
+		foreach ($this->connection->ldapBaseUsers as $base) {
1016 1016
 			$count = $this->count($filter, [$base], $attr, $limit, $offset);
1017
-			$result = is_int($count) ? (int)$result + $count : $result;
1017
+			$result = is_int($count) ? (int) $result + $count : $result;
1018 1018
 		}
1019 1019
 		return $result;
1020 1020
 	}
@@ -1033,7 +1033,7 @@  discard block
 block discarded – undo
1033 1033
 	 */
1034 1034
 	public function searchGroups($filter, $attr = null, $limit = null, $offset = null) {
1035 1035
 		$result = [];
1036
-		foreach($this->connection->ldapBaseGroups as $base) {
1036
+		foreach ($this->connection->ldapBaseGroups as $base) {
1037 1037
 			$result = array_merge($result, $this->search($filter, [$base], $attr, $limit, $offset));
1038 1038
 		}
1039 1039
 		return $result;
@@ -1051,9 +1051,9 @@  discard block
 block discarded – undo
1051 1051
 	 */
1052 1052
 	public function countGroups($filter, $attr = array('dn'), $limit = null, $offset = null) {
1053 1053
 		$result = false;
1054
-		foreach($this->connection->ldapBaseGroups as $base) {
1054
+		foreach ($this->connection->ldapBaseGroups as $base) {
1055 1055
 			$count = $this->count($filter, [$base], $attr, $limit, $offset);
1056
-			$result = is_int($count) ? (int)$result + $count : $result;
1056
+			$result = is_int($count) ? (int) $result + $count : $result;
1057 1057
 		}
1058 1058
 		return $result;
1059 1059
 	}
@@ -1068,9 +1068,9 @@  discard block
 block discarded – undo
1068 1068
 	 */
1069 1069
 	public function countObjects($limit = null, $offset = null) {
1070 1070
 		$result = false;
1071
-		foreach($this->connection->ldapBase as $base) {
1071
+		foreach ($this->connection->ldapBase as $base) {
1072 1072
 			$count = $this->count('objectclass=*', [$base], ['dn'], $limit, $offset);
1073
-			$result = is_int($count) ? (int)$result + $count : $result;
1073
+			$result = is_int($count) ? (int) $result + $count : $result;
1074 1074
 		}
1075 1075
 		return $result;
1076 1076
 	}
@@ -1095,7 +1095,7 @@  discard block
 block discarded – undo
1095 1095
 		// php no longer supports call-time pass-by-reference
1096 1096
 		// thus cannot support controlPagedResultResponse as the third argument
1097 1097
 		// is a reference
1098
-		$doMethod = function () use ($command, &$arguments) {
1098
+		$doMethod = function() use ($command, &$arguments) {
1099 1099
 			if ($command == 'controlPagedResultResponse') {
1100 1100
 				throw new \InvalidArgumentException('Invoker does not support controlPagedResultResponse, call LDAP Wrapper directly instead.');
1101 1101
 			} else {
@@ -1113,7 +1113,7 @@  discard block
 block discarded – undo
1113 1113
 			$this->connection->resetConnectionResource();
1114 1114
 			$cr = $this->connection->getConnectionResource();
1115 1115
 
1116
-			if(!$this->ldap->isResource($cr)) {
1116
+			if (!$this->ldap->isResource($cr)) {
1117 1117
 				// Seems like we didn't find any resource.
1118 1118
 				\OCP\Util::writeLog('user_ldap', "Could not $command, because resource is missing.", ILogger::DEBUG);
1119 1119
 				throw $e;
@@ -1138,13 +1138,13 @@  discard block
 block discarded – undo
1138 1138
 	 * @throws ServerNotAvailableException
1139 1139
 	 */
1140 1140
 	private function executeSearch($filter, $base, &$attr = null, $limit = null, $offset = null) {
1141
-		if(!is_null($attr) && !is_array($attr)) {
1141
+		if (!is_null($attr) && !is_array($attr)) {
1142 1142
 			$attr = array(mb_strtolower($attr, 'UTF-8'));
1143 1143
 		}
1144 1144
 
1145 1145
 		// See if we have a resource, in case not cancel with message
1146 1146
 		$cr = $this->connection->getConnectionResource();
1147
-		if(!$this->ldap->isResource($cr)) {
1147
+		if (!$this->ldap->isResource($cr)) {
1148 1148
 			// Seems like we didn't find any resource.
1149 1149
 			// Return an empty array just like before.
1150 1150
 			\OCP\Util::writeLog('user_ldap', 'Could not search, because resource is missing.', ILogger::DEBUG);
@@ -1152,13 +1152,13 @@  discard block
 block discarded – undo
1152 1152
 		}
1153 1153
 
1154 1154
 		//check whether paged search should be attempted
1155
-		$pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int)$limit, $offset);
1155
+		$pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int) $limit, $offset);
1156 1156
 
1157 1157
 		$linkResources = array_pad(array(), count($base), $cr);
1158 1158
 		$sr = $this->invokeLDAPMethod('search', $linkResources, $base, $filter, $attr);
1159 1159
 		// cannot use $cr anymore, might have changed in the previous call!
1160 1160
 		$error = $this->ldap->errno($this->connection->getConnectionResource());
1161
-		if(!is_array($sr) || $error !== 0) {
1161
+		if (!is_array($sr) || $error !== 0) {
1162 1162
 			\OCP\Util::writeLog('user_ldap', 'Attempt for Paging?  '.print_r($pagedSearchOK, true), ILogger::ERROR);
1163 1163
 			return false;
1164 1164
 		}
@@ -1183,29 +1183,29 @@  discard block
 block discarded – undo
1183 1183
 	 */
1184 1184
 	private function processPagedSearchStatus($sr, $filter, $base, $iFoundItems, $limit, $offset, $pagedSearchOK, $skipHandling) {
1185 1185
 		$cookie = null;
1186
-		if($pagedSearchOK) {
1186
+		if ($pagedSearchOK) {
1187 1187
 			$cr = $this->connection->getConnectionResource();
1188
-			foreach($sr as $key => $res) {
1189
-				if($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) {
1188
+			foreach ($sr as $key => $res) {
1189
+				if ($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) {
1190 1190
 					$this->setPagedResultCookie($base[$key], $filter, $limit, $offset, $cookie);
1191 1191
 				}
1192 1192
 			}
1193 1193
 
1194 1194
 			//browsing through prior pages to get the cookie for the new one
1195
-			if($skipHandling) {
1195
+			if ($skipHandling) {
1196 1196
 				return false;
1197 1197
 			}
1198 1198
 			// if count is bigger, then the server does not support
1199 1199
 			// paged search. Instead, he did a normal search. We set a
1200 1200
 			// flag here, so the callee knows how to deal with it.
1201
-			if($iFoundItems <= $limit) {
1201
+			if ($iFoundItems <= $limit) {
1202 1202
 				$this->pagedSearchedSuccessful = true;
1203 1203
 			}
1204 1204
 		} else {
1205
-			if(!is_null($limit) && (int)$this->connection->ldapPagingSize !== 0) {
1205
+			if (!is_null($limit) && (int) $this->connection->ldapPagingSize !== 0) {
1206 1206
 				\OC::$server->getLogger()->debug(
1207 1207
 					'Paged search was not available',
1208
-					[ 'app' => 'user_ldap' ]
1208
+					['app' => 'user_ldap']
1209 1209
 				);
1210 1210
 			}
1211 1211
 		}
@@ -1234,8 +1234,8 @@  discard block
 block discarded – undo
1234 1234
 	private function count($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) {
1235 1235
 		\OCP\Util::writeLog('user_ldap', 'Count filter:  '.print_r($filter, true), ILogger::DEBUG);
1236 1236
 
1237
-		$limitPerPage = (int)$this->connection->ldapPagingSize;
1238
-		if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1237
+		$limitPerPage = (int) $this->connection->ldapPagingSize;
1238
+		if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1239 1239
 			$limitPerPage = $limit;
1240 1240
 		}
1241 1241
 
@@ -1245,7 +1245,7 @@  discard block
 block discarded – undo
1245 1245
 
1246 1246
 		do {
1247 1247
 			$search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset);
1248
-			if($search === false) {
1248
+			if ($search === false) {
1249 1249
 				return $counter > 0 ? $counter : false;
1250 1250
 			}
1251 1251
 			list($sr, $pagedSearchOK) = $search;
@@ -1264,7 +1264,7 @@  discard block
 block discarded – undo
1264 1264
 			 * Continue now depends on $hasMorePages value
1265 1265
 			 */
1266 1266
 			$continue = $pagedSearchOK && $hasMorePages;
1267
-		} while($continue && (is_null($limit) || $limit <= 0 || $limit > $counter));
1267
+		} while ($continue && (is_null($limit) || $limit <= 0 || $limit > $counter));
1268 1268
 
1269 1269
 		return $counter;
1270 1270
 	}
@@ -1277,8 +1277,8 @@  discard block
 block discarded – undo
1277 1277
 	private function countEntriesInSearchResults($searchResults) {
1278 1278
 		$counter = 0;
1279 1279
 
1280
-		foreach($searchResults as $res) {
1281
-			$count = (int)$this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res);
1280
+		foreach ($searchResults as $res) {
1281
+			$count = (int) $this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res);
1282 1282
 			$counter += $count;
1283 1283
 		}
1284 1284
 
@@ -1298,8 +1298,8 @@  discard block
 block discarded – undo
1298 1298
 	 * @throws ServerNotAvailableException
1299 1299
 	 */
1300 1300
 	public function search($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) {
1301
-		$limitPerPage = (int)$this->connection->ldapPagingSize;
1302
-		if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1301
+		$limitPerPage = (int) $this->connection->ldapPagingSize;
1302
+		if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1303 1303
 			$limitPerPage = $limit;
1304 1304
 		}
1305 1305
 
@@ -1313,13 +1313,13 @@  discard block
 block discarded – undo
1313 1313
 		$savedoffset = $offset;
1314 1314
 		do {
1315 1315
 			$search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset);
1316
-			if($search === false) {
1316
+			if ($search === false) {
1317 1317
 				return [];
1318 1318
 			}
1319 1319
 			list($sr, $pagedSearchOK) = $search;
1320 1320
 			$cr = $this->connection->getConnectionResource();
1321 1321
 
1322
-			if($skipHandling) {
1322
+			if ($skipHandling) {
1323 1323
 				//i.e. result do not need to be fetched, we just need the cookie
1324 1324
 				//thus pass 1 or any other value as $iFoundItems because it is not
1325 1325
 				//used
@@ -1330,7 +1330,7 @@  discard block
 block discarded – undo
1330 1330
 			}
1331 1331
 
1332 1332
 			$iFoundItems = 0;
1333
-			foreach($sr as $res) {
1333
+			foreach ($sr as $res) {
1334 1334
 				$findings = array_merge($findings, $this->invokeLDAPMethod('getEntries', $cr, $res));
1335 1335
 				$iFoundItems = max($iFoundItems, $findings['count']);
1336 1336
 				unset($findings['count']);
@@ -1346,27 +1346,27 @@  discard block
 block discarded – undo
1346 1346
 
1347 1347
 		// if we're here, probably no connection resource is returned.
1348 1348
 		// to make Nextcloud behave nicely, we simply give back an empty array.
1349
-		if(is_null($findings)) {
1349
+		if (is_null($findings)) {
1350 1350
 			return array();
1351 1351
 		}
1352 1352
 
1353
-		if(!is_null($attr)) {
1353
+		if (!is_null($attr)) {
1354 1354
 			$selection = [];
1355 1355
 			$i = 0;
1356
-			foreach($findings as $item) {
1357
-				if(!is_array($item)) {
1356
+			foreach ($findings as $item) {
1357
+				if (!is_array($item)) {
1358 1358
 					continue;
1359 1359
 				}
1360 1360
 				$item = \OCP\Util::mb_array_change_key_case($item, MB_CASE_LOWER, 'UTF-8');
1361
-				foreach($attr as $key) {
1362
-					if(isset($item[$key])) {
1363
-						if(is_array($item[$key]) && isset($item[$key]['count'])) {
1361
+				foreach ($attr as $key) {
1362
+					if (isset($item[$key])) {
1363
+						if (is_array($item[$key]) && isset($item[$key]['count'])) {
1364 1364
 							unset($item[$key]['count']);
1365 1365
 						}
1366
-						if($key !== 'dn') {
1367
-							if($this->resemblesDN($key)) {
1366
+						if ($key !== 'dn') {
1367
+							if ($this->resemblesDN($key)) {
1368 1368
 								$selection[$i][$key] = $this->helper->sanitizeDN($item[$key]);
1369
-							} else if($key === 'objectguid' || $key === 'guid') {
1369
+							} else if ($key === 'objectguid' || $key === 'guid') {
1370 1370
 								$selection[$i][$key] = [$this->convertObjectGUID2Str($item[$key][0])];
1371 1371
 							} else {
1372 1372
 								$selection[$i][$key] = $item[$key];
@@ -1384,14 +1384,14 @@  discard block
 block discarded – undo
1384 1384
 		//we slice the findings, when
1385 1385
 		//a) paged search unsuccessful, though attempted
1386 1386
 		//b) no paged search, but limit set
1387
-		if((!$this->getPagedSearchResultState()
1387
+		if ((!$this->getPagedSearchResultState()
1388 1388
 			&& $pagedSearchOK)
1389 1389
 			|| (
1390 1390
 				!$pagedSearchOK
1391 1391
 				&& !is_null($limit)
1392 1392
 			)
1393 1393
 		) {
1394
-			$findings = array_slice($findings, (int)$offset, $limit);
1394
+			$findings = array_slice($findings, (int) $offset, $limit);
1395 1395
 		}
1396 1396
 		return $findings;
1397 1397
 	}
@@ -1404,13 +1404,13 @@  discard block
 block discarded – undo
1404 1404
 	public function sanitizeUsername($name) {
1405 1405
 		$name = trim($name);
1406 1406
 
1407
-		if($this->connection->ldapIgnoreNamingRules) {
1407
+		if ($this->connection->ldapIgnoreNamingRules) {
1408 1408
 			return $name;
1409 1409
 		}
1410 1410
 
1411 1411
 		// Transliteration to ASCII
1412 1412
 		$transliterated = @iconv('UTF-8', 'ASCII//TRANSLIT', $name);
1413
-		if($transliterated !== false) {
1413
+		if ($transliterated !== false) {
1414 1414
 			// depending on system config iconv can work or not
1415 1415
 			$name = $transliterated;
1416 1416
 		}
@@ -1421,7 +1421,7 @@  discard block
 block discarded – undo
1421 1421
 		// Every remaining disallowed characters will be removed
1422 1422
 		$name = preg_replace('/[^a-zA-Z0-9_.@-]/u', '', $name);
1423 1423
 
1424
-		if($name === '') {
1424
+		if ($name === '') {
1425 1425
 			throw new \InvalidArgumentException('provided name template for username does not contain any allowed characters');
1426 1426
 		}
1427 1427
 
@@ -1436,13 +1436,13 @@  discard block
 block discarded – undo
1436 1436
 	*/
1437 1437
 	public function escapeFilterPart($input, $allowAsterisk = false) {
1438 1438
 		$asterisk = '';
1439
-		if($allowAsterisk && strlen($input) > 0 && $input[0] === '*') {
1439
+		if ($allowAsterisk && strlen($input) > 0 && $input[0] === '*') {
1440 1440
 			$asterisk = '*';
1441 1441
 			$input = mb_substr($input, 1, null, 'UTF-8');
1442 1442
 		}
1443 1443
 		$search  = array('*', '\\', '(', ')');
1444 1444
 		$replace = array('\\*', '\\\\', '\\(', '\\)');
1445
-		return $asterisk . str_replace($search, $replace, $input);
1445
+		return $asterisk.str_replace($search, $replace, $input);
1446 1446
 	}
1447 1447
 
1448 1448
 	/**
@@ -1472,13 +1472,13 @@  discard block
 block discarded – undo
1472 1472
 	 */
1473 1473
 	private function combineFilter($filters, $operator) {
1474 1474
 		$combinedFilter = '('.$operator;
1475
-		foreach($filters as $filter) {
1475
+		foreach ($filters as $filter) {
1476 1476
 			if ($filter !== '' && $filter[0] !== '(') {
1477 1477
 				$filter = '('.$filter.')';
1478 1478
 			}
1479
-			$combinedFilter.=$filter;
1479
+			$combinedFilter .= $filter;
1480 1480
 		}
1481
-		$combinedFilter.=')';
1481
+		$combinedFilter .= ')';
1482 1482
 		return $combinedFilter;
1483 1483
 	}
1484 1484
 
@@ -1514,17 +1514,17 @@  discard block
 block discarded – undo
1514 1514
 	 * @throws \Exception
1515 1515
 	 */
1516 1516
 	private function getAdvancedFilterPartForSearch($search, $searchAttributes) {
1517
-		if(!is_array($searchAttributes) || count($searchAttributes) < 2) {
1517
+		if (!is_array($searchAttributes) || count($searchAttributes) < 2) {
1518 1518
 			throw new \Exception('searchAttributes must be an array with at least two string');
1519 1519
 		}
1520 1520
 		$searchWords = explode(' ', trim($search));
1521 1521
 		$wordFilters = array();
1522
-		foreach($searchWords as $word) {
1522
+		foreach ($searchWords as $word) {
1523 1523
 			$word = $this->prepareSearchTerm($word);
1524 1524
 			//every word needs to appear at least once
1525 1525
 			$wordMatchOneAttrFilters = array();
1526
-			foreach($searchAttributes as $attr) {
1527
-				$wordMatchOneAttrFilters[] = $attr . '=' . $word;
1526
+			foreach ($searchAttributes as $attr) {
1527
+				$wordMatchOneAttrFilters[] = $attr.'='.$word;
1528 1528
 			}
1529 1529
 			$wordFilters[] = $this->combineFilterWithOr($wordMatchOneAttrFilters);
1530 1530
 		}
@@ -1542,10 +1542,10 @@  discard block
 block discarded – undo
1542 1542
 	private function getFilterPartForSearch($search, $searchAttributes, $fallbackAttribute) {
1543 1543
 		$filter = array();
1544 1544
 		$haveMultiSearchAttributes = (is_array($searchAttributes) && count($searchAttributes) > 0);
1545
-		if($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) {
1545
+		if ($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) {
1546 1546
 			try {
1547 1547
 				return $this->getAdvancedFilterPartForSearch($search, $searchAttributes);
1548
-			} catch(\Exception $e) {
1548
+			} catch (\Exception $e) {
1549 1549
 				\OCP\Util::writeLog(
1550 1550
 					'user_ldap',
1551 1551
 					'Creating advanced filter for search failed, falling back to simple method.',
@@ -1555,17 +1555,17 @@  discard block
 block discarded – undo
1555 1555
 		}
1556 1556
 
1557 1557
 		$search = $this->prepareSearchTerm($search);
1558
-		if(!is_array($searchAttributes) || count($searchAttributes) === 0) {
1558
+		if (!is_array($searchAttributes) || count($searchAttributes) === 0) {
1559 1559
 			if ($fallbackAttribute === '') {
1560 1560
 				return '';
1561 1561
 			}
1562
-			$filter[] = $fallbackAttribute . '=' . $search;
1562
+			$filter[] = $fallbackAttribute.'='.$search;
1563 1563
 		} else {
1564
-			foreach($searchAttributes as $attribute) {
1565
-				$filter[] = $attribute . '=' . $search;
1564
+			foreach ($searchAttributes as $attribute) {
1565
+				$filter[] = $attribute.'='.$search;
1566 1566
 			}
1567 1567
 		}
1568
-		if(count($filter) === 1) {
1568
+		if (count($filter) === 1) {
1569 1569
 			return '('.$filter[0].')';
1570 1570
 		}
1571 1571
 		return $this->combineFilterWithOr($filter);
@@ -1586,7 +1586,7 @@  discard block
 block discarded – undo
1586 1586
 		if ($term === '') {
1587 1587
 			$result = '*';
1588 1588
 		} else if ($allowEnum !== 'no') {
1589
-			$result = $term . '*';
1589
+			$result = $term.'*';
1590 1590
 		}
1591 1591
 		return $result;
1592 1592
 	}
@@ -1598,7 +1598,7 @@  discard block
 block discarded – undo
1598 1598
 	public function getFilterForUserCount() {
1599 1599
 		$filter = $this->combineFilterWithAnd(array(
1600 1600
 			$this->connection->ldapUserFilter,
1601
-			$this->connection->ldapUserDisplayName . '=*'
1601
+			$this->connection->ldapUserDisplayName.'=*'
1602 1602
 		));
1603 1603
 
1604 1604
 		return $filter;
@@ -1616,7 +1616,7 @@  discard block
 block discarded – undo
1616 1616
 			'ldapAgentName' => $name,
1617 1617
 			'ldapAgentPassword' => $password
1618 1618
 		);
1619
-		if(!$testConnection->setConfiguration($credentials)) {
1619
+		if (!$testConnection->setConfiguration($credentials)) {
1620 1620
 			return false;
1621 1621
 		}
1622 1622
 		return $testConnection->bind();
@@ -1638,30 +1638,30 @@  discard block
 block discarded – undo
1638 1638
 			// Sacrebleu! The UUID attribute is unknown :( We need first an
1639 1639
 			// existing DN to be able to reliably detect it.
1640 1640
 			$result = $this->search($filter, $base, ['dn'], 1);
1641
-			if(!isset($result[0]) || !isset($result[0]['dn'])) {
1641
+			if (!isset($result[0]) || !isset($result[0]['dn'])) {
1642 1642
 				throw new \Exception('Cannot determine UUID attribute');
1643 1643
 			}
1644 1644
 			$dn = $result[0]['dn'][0];
1645
-			if(!$this->detectUuidAttribute($dn, true)) {
1645
+			if (!$this->detectUuidAttribute($dn, true)) {
1646 1646
 				throw new \Exception('Cannot determine UUID attribute');
1647 1647
 			}
1648 1648
 		} else {
1649 1649
 			// The UUID attribute is either known or an override is given.
1650 1650
 			// By calling this method we ensure that $this->connection->$uuidAttr
1651 1651
 			// is definitely set
1652
-			if(!$this->detectUuidAttribute('', true)) {
1652
+			if (!$this->detectUuidAttribute('', true)) {
1653 1653
 				throw new \Exception('Cannot determine UUID attribute');
1654 1654
 			}
1655 1655
 		}
1656 1656
 
1657 1657
 		$uuidAttr = $this->connection->ldapUuidUserAttribute;
1658
-		if($uuidAttr === 'guid' || $uuidAttr === 'objectguid') {
1658
+		if ($uuidAttr === 'guid' || $uuidAttr === 'objectguid') {
1659 1659
 			$uuid = $this->formatGuid2ForFilterUser($uuid);
1660 1660
 		}
1661 1661
 
1662
-		$filter = $uuidAttr . '=' . $uuid;
1662
+		$filter = $uuidAttr.'='.$uuid;
1663 1663
 		$result = $this->searchUsers($filter, ['dn'], 2);
1664
-		if(is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) {
1664
+		if (is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) {
1665 1665
 			// we put the count into account to make sure that this is
1666 1666
 			// really unique
1667 1667
 			return $result[0]['dn'][0];
@@ -1681,7 +1681,7 @@  discard block
 block discarded – undo
1681 1681
 	 * @throws ServerNotAvailableException
1682 1682
 	 */
1683 1683
 	private function detectUuidAttribute($dn, $isUser = true, $force = false, array $ldapRecord = null) {
1684
-		if($isUser) {
1684
+		if ($isUser) {
1685 1685
 			$uuidAttr     = 'ldapUuidUserAttribute';
1686 1686
 			$uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
1687 1687
 		} else {
@@ -1689,7 +1689,7 @@  discard block
 block discarded – undo
1689 1689
 			$uuidOverride = $this->connection->ldapExpertUUIDGroupAttr;
1690 1690
 		}
1691 1691
 
1692
-		if(($this->connection->$uuidAttr !== 'auto') && !$force) {
1692
+		if (($this->connection->$uuidAttr !== 'auto') && !$force) {
1693 1693
 			return true;
1694 1694
 		}
1695 1695
 
@@ -1698,10 +1698,10 @@  discard block
 block discarded – undo
1698 1698
 			return true;
1699 1699
 		}
1700 1700
 
1701
-		foreach(self::UUID_ATTRIBUTES as $attribute) {
1702
-			if($ldapRecord !== null) {
1701
+		foreach (self::UUID_ATTRIBUTES as $attribute) {
1702
+			if ($ldapRecord !== null) {
1703 1703
 				// we have the info from LDAP already, we don't need to talk to the server again
1704
-				if(isset($ldapRecord[$attribute])) {
1704
+				if (isset($ldapRecord[$attribute])) {
1705 1705
 					$this->connection->$uuidAttr = $attribute;
1706 1706
 					return true;
1707 1707
 				} else {
@@ -1710,7 +1710,7 @@  discard block
 block discarded – undo
1710 1710
 			}
1711 1711
 
1712 1712
 			$value = $this->readAttribute($dn, $attribute);
1713
-			if(is_array($value) && isset($value[0]) && !empty($value[0])) {
1713
+			if (is_array($value) && isset($value[0]) && !empty($value[0])) {
1714 1714
 				\OCP\Util::writeLog(
1715 1715
 					'user_ldap',
1716 1716
 					'Setting '.$attribute.' as '.$uuidAttr,
@@ -1737,7 +1737,7 @@  discard block
 block discarded – undo
1737 1737
 	 * @throws ServerNotAvailableException
1738 1738
 	 */
1739 1739
 	public function getUUID($dn, $isUser = true, $ldapRecord = null) {
1740
-		if($isUser) {
1740
+		if ($isUser) {
1741 1741
 			$uuidAttr     = 'ldapUuidUserAttribute';
1742 1742
 			$uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
1743 1743
 		} else {
@@ -1746,10 +1746,10 @@  discard block
 block discarded – undo
1746 1746
 		}
1747 1747
 
1748 1748
 		$uuid = false;
1749
-		if($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) {
1749
+		if ($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) {
1750 1750
 			$attr = $this->connection->$uuidAttr;
1751 1751
 			$uuid = isset($ldapRecord[$attr]) ? $ldapRecord[$attr] : $this->readAttribute($dn, $attr);
1752
-			if( !is_array($uuid)
1752
+			if (!is_array($uuid)
1753 1753
 				&& $uuidOverride !== ''
1754 1754
 				&& $this->detectUuidAttribute($dn, $isUser, true, $ldapRecord))
1755 1755
 			{
@@ -1757,7 +1757,7 @@  discard block
 block discarded – undo
1757 1757
 					? $ldapRecord[$this->connection->$uuidAttr]
1758 1758
 					: $this->readAttribute($dn, $this->connection->$uuidAttr);
1759 1759
 			}
1760
-			if(is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) {
1760
+			if (is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) {
1761 1761
 				$uuid = $uuid[0];
1762 1762
 			}
1763 1763
 		}
@@ -1774,19 +1774,19 @@  discard block
 block discarded – undo
1774 1774
 	private function convertObjectGUID2Str($oguid) {
1775 1775
 		$hex_guid = bin2hex($oguid);
1776 1776
 		$hex_guid_to_guid_str = '';
1777
-		for($k = 1; $k <= 4; ++$k) {
1777
+		for ($k = 1; $k <= 4; ++$k) {
1778 1778
 			$hex_guid_to_guid_str .= substr($hex_guid, 8 - 2 * $k, 2);
1779 1779
 		}
1780 1780
 		$hex_guid_to_guid_str .= '-';
1781
-		for($k = 1; $k <= 2; ++$k) {
1781
+		for ($k = 1; $k <= 2; ++$k) {
1782 1782
 			$hex_guid_to_guid_str .= substr($hex_guid, 12 - 2 * $k, 2);
1783 1783
 		}
1784 1784
 		$hex_guid_to_guid_str .= '-';
1785
-		for($k = 1; $k <= 2; ++$k) {
1785
+		for ($k = 1; $k <= 2; ++$k) {
1786 1786
 			$hex_guid_to_guid_str .= substr($hex_guid, 16 - 2 * $k, 2);
1787 1787
 		}
1788
-		$hex_guid_to_guid_str .= '-' . substr($hex_guid, 16, 4);
1789
-		$hex_guid_to_guid_str .= '-' . substr($hex_guid, 20);
1788
+		$hex_guid_to_guid_str .= '-'.substr($hex_guid, 16, 4);
1789
+		$hex_guid_to_guid_str .= '-'.substr($hex_guid, 20);
1790 1790
 
1791 1791
 		return strtoupper($hex_guid_to_guid_str);
1792 1792
 	}
@@ -1803,11 +1803,11 @@  discard block
 block discarded – undo
1803 1803
 	 * @return string
1804 1804
 	 */
1805 1805
 	public function formatGuid2ForFilterUser($guid) {
1806
-		if(!is_string($guid)) {
1806
+		if (!is_string($guid)) {
1807 1807
 			throw new \InvalidArgumentException('String expected');
1808 1808
 		}
1809 1809
 		$blocks = explode('-', $guid);
1810
-		if(count($blocks) !== 5) {
1810
+		if (count($blocks) !== 5) {
1811 1811
 			/*
1812 1812
 			 * Why not throw an Exception instead? This method is a utility
1813 1813
 			 * called only when trying to figure out whether a "missing" known
@@ -1820,20 +1820,20 @@  discard block
 block discarded – undo
1820 1820
 			 * user. Instead we write a log message.
1821 1821
 			 */
1822 1822
 			\OC::$server->getLogger()->info(
1823
-				'Passed string does not resemble a valid GUID. Known UUID ' .
1823
+				'Passed string does not resemble a valid GUID. Known UUID '.
1824 1824
 				'({uuid}) probably does not match UUID configuration.',
1825
-				[ 'app' => 'user_ldap', 'uuid' => $guid ]
1825
+				['app' => 'user_ldap', 'uuid' => $guid]
1826 1826
 			);
1827 1827
 			return $guid;
1828 1828
 		}
1829
-		for($i=0; $i < 3; $i++) {
1829
+		for ($i = 0; $i < 3; $i++) {
1830 1830
 			$pairs = str_split($blocks[$i], 2);
1831 1831
 			$pairs = array_reverse($pairs);
1832 1832
 			$blocks[$i] = implode('', $pairs);
1833 1833
 		}
1834
-		for($i=0; $i < 5; $i++) {
1834
+		for ($i = 0; $i < 5; $i++) {
1835 1835
 			$pairs = str_split($blocks[$i], 2);
1836
-			$blocks[$i] = '\\' . implode('\\', $pairs);
1836
+			$blocks[$i] = '\\'.implode('\\', $pairs);
1837 1837
 		}
1838 1838
 		return implode('', $blocks);
1839 1839
 	}
@@ -1849,12 +1849,12 @@  discard block
 block discarded – undo
1849 1849
 		$domainDN = $this->getDomainDNFromDN($dn);
1850 1850
 		$cacheKey = 'getSID-'.$domainDN;
1851 1851
 		$sid = $this->connection->getFromCache($cacheKey);
1852
-		if(!is_null($sid)) {
1852
+		if (!is_null($sid)) {
1853 1853
 			return $sid;
1854 1854
 		}
1855 1855
 
1856 1856
 		$objectSid = $this->readAttribute($domainDN, 'objectsid');
1857
-		if(!is_array($objectSid) || empty($objectSid)) {
1857
+		if (!is_array($objectSid) || empty($objectSid)) {
1858 1858
 			$this->connection->writeToCache($cacheKey, false);
1859 1859
 			return false;
1860 1860
 		}
@@ -1912,12 +1912,12 @@  discard block
 block discarded – undo
1912 1912
 		$belongsToBase = false;
1913 1913
 		$bases = $this->helper->sanitizeDN($bases);
1914 1914
 
1915
-		foreach($bases as $base) {
1915
+		foreach ($bases as $base) {
1916 1916
 			$belongsToBase = true;
1917
-			if(mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8')-mb_strlen($base, 'UTF-8'))) {
1917
+			if (mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8') - mb_strlen($base, 'UTF-8'))) {
1918 1918
 				$belongsToBase = false;
1919 1919
 			}
1920
-			if($belongsToBase) {
1920
+			if ($belongsToBase) {
1921 1921
 				break;
1922 1922
 			}
1923 1923
 		}
@@ -1946,16 +1946,16 @@  discard block
 block discarded – undo
1946 1946
 	 * @return string containing the key or empty if none is cached
1947 1947
 	 */
1948 1948
 	private function getPagedResultCookie($base, $filter, $limit, $offset) {
1949
-		if($offset === 0) {
1949
+		if ($offset === 0) {
1950 1950
 			return '';
1951 1951
 		}
1952 1952
 		$offset -= $limit;
1953 1953
 		//we work with cache here
1954
-		$cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . (int)$limit . '-' . (int)$offset;
1954
+		$cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.(int) $limit.'-'.(int) $offset;
1955 1955
 		$cookie = '';
1956
-		if(isset($this->cookies[$cacheKey])) {
1956
+		if (isset($this->cookies[$cacheKey])) {
1957 1957
 			$cookie = $this->cookies[$cacheKey];
1958
-			if(is_null($cookie)) {
1958
+			if (is_null($cookie)) {
1959 1959
 				$cookie = '';
1960 1960
 			}
1961 1961
 		}
@@ -1973,7 +1973,7 @@  discard block
 block discarded – undo
1973 1973
 	 * @return bool
1974 1974
 	 */
1975 1975
 	public function hasMoreResults() {
1976
-		if(empty($this->lastCookie) && $this->lastCookie !== '0') {
1976
+		if (empty($this->lastCookie) && $this->lastCookie !== '0') {
1977 1977
 			// as in RFC 2696, when all results are returned, the cookie will
1978 1978
 			// be empty.
1979 1979
 			return false;
@@ -1993,8 +1993,8 @@  discard block
 block discarded – undo
1993 1993
 	 */
1994 1994
 	private function setPagedResultCookie($base, $filter, $limit, $offset, $cookie) {
1995 1995
 		// allow '0' for 389ds
1996
-		if(!empty($cookie) || $cookie === '0') {
1997
-			$cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . (int)$limit . '-' . (int)$offset;
1996
+		if (!empty($cookie) || $cookie === '0') {
1997
+			$cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.(int) $limit.'-'.(int) $offset;
1998 1998
 			$this->cookies[$cacheKey] = $cookie;
1999 1999
 			$this->lastCookie = $cookie;
2000 2000
 		}
@@ -2024,16 +2024,16 @@  discard block
 block discarded – undo
2024 2024
 	private function initPagedSearch($filter, $bases, $attr, $limit, $offset) {
2025 2025
 		$pagedSearchOK = false;
2026 2026
 		if ($limit !== 0) {
2027
-			$offset = (int)$offset; //can be null
2027
+			$offset = (int) $offset; //can be null
2028 2028
 			\OCP\Util::writeLog('user_ldap',
2029 2029
 				'initializing paged search for  Filter '.$filter.' base '.print_r($bases, true)
2030
-				.' attr '.print_r($attr, true). ' limit ' .$limit.' offset '.$offset,
2030
+				.' attr '.print_r($attr, true).' limit '.$limit.' offset '.$offset,
2031 2031
 				ILogger::DEBUG);
2032 2032
 			//get the cookie from the search for the previous search, required by LDAP
2033
-			foreach($bases as $base) {
2033
+			foreach ($bases as $base) {
2034 2034
 
2035 2035
 				$cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset);
2036
-				if(empty($cookie) && $cookie !== "0" && ($offset > 0)) {
2036
+				if (empty($cookie) && $cookie !== "0" && ($offset > 0)) {
2037 2037
 					// no cookie known from a potential previous search. We need
2038 2038
 					// to start from 0 to come to the desired page. cookie value
2039 2039
 					// of '0' is valid, because 389ds
@@ -2043,17 +2043,17 @@  discard block
 block discarded – undo
2043 2043
 					//still no cookie? obviously, the server does not like us. Let's skip paging efforts.
2044 2044
 					// '0' is valid, because 389ds
2045 2045
 					//TODO: remember this, probably does not change in the next request...
2046
-					if(empty($cookie) && $cookie !== '0') {
2046
+					if (empty($cookie) && $cookie !== '0') {
2047 2047
 						$cookie = null;
2048 2048
 					}
2049 2049
 				}
2050
-				if(!is_null($cookie)) {
2050
+				if (!is_null($cookie)) {
2051 2051
 					//since offset = 0, this is a new search. We abandon other searches that might be ongoing.
2052 2052
 					$this->abandonPagedSearch();
2053 2053
 					$pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult',
2054 2054
 						$this->connection->getConnectionResource(), $limit,
2055 2055
 						false, $cookie);
2056
-					if(!$pagedSearchOK) {
2056
+					if (!$pagedSearchOK) {
2057 2057
 						return false;
2058 2058
 					}
2059 2059
 					\OCP\Util::writeLog('user_ldap', 'Ready for a paged search', ILogger::DEBUG);
@@ -2076,7 +2076,7 @@  discard block
 block discarded – undo
2076 2076
 			$this->abandonPagedSearch();
2077 2077
 			// in case someone set it to 0 … use 500, otherwise no results will
2078 2078
 			// be returned.
2079
-			$pageSize = (int)$this->connection->ldapPagingSize > 0 ? (int)$this->connection->ldapPagingSize : 500;
2079
+			$pageSize = (int) $this->connection->ldapPagingSize > 0 ? (int) $this->connection->ldapPagingSize : 500;
2080 2080
 			$pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult',
2081 2081
 				$this->connection->getConnectionResource(),
2082 2082
 				$pageSize, false, '');
Please login to merge, or discard this patch.