Passed
Push — master ( 087343...c1eff7 )
by Blizzz
13:03 queued 10s
created
apps/user_ldap/lib/Group_LDAP.php 1 patch
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 		parent::__construct($access);
72 72
 		$filter = $this->access->connection->ldapGroupFilter;
73 73
 		$gassoc = $this->access->connection->ldapGroupMemberAssocAttr;
74
-		if(!empty($filter) && !empty($gassoc)) {
74
+		if (!empty($filter) && !empty($gassoc)) {
75 75
 			$this->enabled = true;
76 76
 		}
77 77
 
@@ -90,25 +90,25 @@  discard block
 block discarded – undo
90 90
 	 * Checks whether the user is member of a group or not.
91 91
 	 */
92 92
 	public function inGroup($uid, $gid) {
93
-		if(!$this->enabled) {
93
+		if (!$this->enabled) {
94 94
 			return false;
95 95
 		}
96 96
 		$cacheKey = 'inGroup'.$uid.':'.$gid;
97 97
 		$inGroup = $this->access->connection->getFromCache($cacheKey);
98
-		if(!is_null($inGroup)) {
99
-			return (bool)$inGroup;
98
+		if (!is_null($inGroup)) {
99
+			return (bool) $inGroup;
100 100
 		}
101 101
 
102 102
 		$userDN = $this->access->username2dn($uid);
103 103
 
104
-		if(isset($this->cachedGroupMembers[$gid])) {
104
+		if (isset($this->cachedGroupMembers[$gid])) {
105 105
 			$isInGroup = in_array($userDN, $this->cachedGroupMembers[$gid]);
106 106
 			return $isInGroup;
107 107
 		}
108 108
 
109 109
 		$cacheKeyMembers = 'inGroup-members:'.$gid;
110 110
 		$members = $this->access->connection->getFromCache($cacheKeyMembers);
111
-		if(!is_null($members)) {
111
+		if (!is_null($members)) {
112 112
 			$this->cachedGroupMembers[$gid] = $members;
113 113
 			$isInGroup = in_array($userDN, $members, true);
114 114
 			$this->access->connection->writeToCache($cacheKey, $isInGroup);
@@ -117,34 +117,34 @@  discard block
 block discarded – undo
117 117
 
118 118
 		$groupDN = $this->access->groupname2dn($gid);
119 119
 		// just in case
120
-		if(!$groupDN || !$userDN) {
120
+		if (!$groupDN || !$userDN) {
121 121
 			$this->access->connection->writeToCache($cacheKey, false);
122 122
 			return false;
123 123
 		}
124 124
 
125 125
 		//check primary group first
126
-		if($gid === $this->getUserPrimaryGroup($userDN)) {
126
+		if ($gid === $this->getUserPrimaryGroup($userDN)) {
127 127
 			$this->access->connection->writeToCache($cacheKey, true);
128 128
 			return true;
129 129
 		}
130 130
 
131 131
 		//usually, LDAP attributes are said to be case insensitive. But there are exceptions of course.
132 132
 		$members = $this->_groupMembers($groupDN);
133
-		if(!is_array($members) || count($members) === 0) {
133
+		if (!is_array($members) || count($members) === 0) {
134 134
 			$this->access->connection->writeToCache($cacheKey, false);
135 135
 			return false;
136 136
 		}
137 137
 
138 138
 		//extra work if we don't get back user DNs
139
-		if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
139
+		if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
140 140
 			$dns = array();
141 141
 			$filterParts = array();
142 142
 			$bytes = 0;
143
-			foreach($members as $mid) {
143
+			foreach ($members as $mid) {
144 144
 				$filter = str_replace('%uid', $mid, $this->access->connection->ldapLoginFilter);
145 145
 				$filterParts[] = $filter;
146 146
 				$bytes += strlen($filter);
147
-				if($bytes >= 9000000) {
147
+				if ($bytes >= 9000000) {
148 148
 					// AD has a default input buffer of 10 MB, we do not want
149 149
 					// to take even the chance to exceed it
150 150
 					$filter = $this->access->combineFilterWithOr($filterParts);
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 					$dns = array_merge($dns, $users);
155 155
 				}
156 156
 			}
157
-			if(count($filterParts) > 0) {
157
+			if (count($filterParts) > 0) {
158 158
 				$filter = $this->access->combineFilterWithOr($filterParts);
159 159
 				$users = $this->access->fetchListOfUsers($filter, 'dn', count($filterParts));
160 160
 				$dns = array_merge($dns, $users);
@@ -197,14 +197,14 @@  discard block
 block discarded – undo
197 197
 			$pos = strpos($memberURLs[0], '(');
198 198
 			if ($pos !== false) {
199 199
 				$memberUrlFilter = substr($memberURLs[0], $pos);
200
-				$foundMembers = $this->access->searchUsers($memberUrlFilter,'dn');
200
+				$foundMembers = $this->access->searchUsers($memberUrlFilter, 'dn');
201 201
 				$dynamicMembers = array();
202
-				foreach($foundMembers as $value) {
202
+				foreach ($foundMembers as $value) {
203 203
 					$dynamicMembers[$value['dn'][0]] = 1;
204 204
 				}
205 205
 			} else {
206 206
 				\OCP\Util::writeLog('user_ldap', 'No search filter found on member url '.
207
-					'of group ' . $dnGroup, ILogger::DEBUG);
207
+					'of group '.$dnGroup, ILogger::DEBUG);
208 208
 			}
209 209
 		}
210 210
 		return $dynamicMembers;
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 		// used extensively in cron job, caching makes sense for nested groups
229 229
 		$cacheKey = '_groupMembers'.$dnGroup;
230 230
 		$groupMembers = $this->access->connection->getFromCache($cacheKey);
231
-		if($groupMembers !== null) {
231
+		if ($groupMembers !== null) {
232 232
 			return $groupMembers;
233 233
 		}
234 234
 		$seen[$dnGroup] = 1;
@@ -288,10 +288,10 @@  discard block
 block discarded – undo
288 288
 		$recordMode = is_array($list) && isset($list[0]) && is_array($list[0]) && isset($list[0]['dn'][0]);
289 289
 
290 290
 		if ($nesting !== 1) {
291
-			if($recordMode) {
291
+			if ($recordMode) {
292 292
 				// the keys are numeric, but should hold the DN
293
-				return array_reduce($list, function ($transformed, $record) use ($dn) {
294
-					if($record['dn'][0] != $dn) {
293
+				return array_reduce($list, function($transformed, $record) use ($dn) {
294
+					if ($record['dn'][0] != $dn) {
295 295
 						$transformed[$record['dn'][0]] = $record;
296 296
 					}
297 297
 					return $transformed;
@@ -322,9 +322,9 @@  discard block
 block discarded – undo
322 322
 	 * @return string|bool
323 323
 	 */
324 324
 	public function gidNumber2Name($gid, $dn) {
325
-		$cacheKey = 'gidNumberToName' . $gid;
325
+		$cacheKey = 'gidNumberToName'.$gid;
326 326
 		$groupName = $this->access->connection->getFromCache($cacheKey);
327
-		if(!is_null($groupName) && isset($groupName)) {
327
+		if (!is_null($groupName) && isset($groupName)) {
328 328
 			return $groupName;
329 329
 		}
330 330
 
@@ -332,10 +332,10 @@  discard block
 block discarded – undo
332 332
 		$filter = $this->access->combineFilterWithAnd([
333 333
 			$this->access->connection->ldapGroupFilter,
334 334
 			'objectClass=posixGroup',
335
-			$this->access->connection->ldapGidNumber . '=' . $gid
335
+			$this->access->connection->ldapGidNumber.'='.$gid
336 336
 		]);
337 337
 		$result = $this->access->searchGroups($filter, array('dn'), 1);
338
-		if(empty($result)) {
338
+		if (empty($result)) {
339 339
 			return false;
340 340
 		}
341 341
 		$dn = $result[0]['dn'][0];
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 	 */
359 359
 	private function getEntryGidNumber($dn, $attribute) {
360 360
 		$value = $this->access->readAttribute($dn, $attribute);
361
-		if(is_array($value) && !empty($value)) {
361
+		if (is_array($value) && !empty($value)) {
362 362
 			return $value[0];
363 363
 		}
364 364
 		return false;
@@ -380,9 +380,9 @@  discard block
 block discarded – undo
380 380
 	 */
381 381
 	public function getUserGidNumber($dn) {
382 382
 		$gidNumber = false;
383
-		if($this->access->connection->hasGidNumber) {
383
+		if ($this->access->connection->hasGidNumber) {
384 384
 			$gidNumber = $this->getEntryGidNumber($dn, $this->access->connection->ldapGidNumber);
385
-			if($gidNumber === false) {
385
+			if ($gidNumber === false) {
386 386
 				$this->access->connection->hasGidNumber = false;
387 387
 			}
388 388
 		}
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
 	 */
400 400
 	private function prepareFilterForUsersHasGidNumber($groupDN, $search = '') {
401 401
 		$groupID = $this->getGroupGidNumber($groupDN);
402
-		if($groupID === false) {
402
+		if ($groupID === false) {
403 403
 			throw new \Exception('Not a valid group');
404 404
 		}
405 405
 
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
 		if ($search !== '') {
409 409
 			$filterParts[] = $this->access->getFilterPartForUserSearch($search);
410 410
 		}
411
-		$filterParts[] = $this->access->connection->ldapGidNumber .'=' . $groupID;
411
+		$filterParts[] = $this->access->connection->ldapGidNumber.'='.$groupID;
412 412
 
413 413
 		return $this->access->combineFilterWithAnd($filterParts);
414 414
 	}
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
 		try {
451 451
 			$filter = $this->prepareFilterForUsersHasGidNumber($groupDN, $search);
452 452
 			$users = $this->access->countUsers($filter, ['dn'], $limit, $offset);
453
-			return (int)$users;
453
+			return (int) $users;
454 454
 		} catch (\Exception $e) {
455 455
 			return 0;
456 456
 		}
@@ -463,9 +463,9 @@  discard block
 block discarded – undo
463 463
 	 */
464 464
 	public function getUserGroupByGid($dn) {
465 465
 		$groupID = $this->getUserGidNumber($dn);
466
-		if($groupID !== false) {
466
+		if ($groupID !== false) {
467 467
 			$groupName = $this->gidNumber2Name($groupID, $dn);
468
-			if($groupName !== false) {
468
+			if ($groupName !== false) {
469 469
 				return $groupName;
470 470
 			}
471 471
 		}
@@ -482,22 +482,22 @@  discard block
 block discarded – undo
482 482
 	public function primaryGroupID2Name($gid, $dn) {
483 483
 		$cacheKey = 'primaryGroupIDtoName';
484 484
 		$groupNames = $this->access->connection->getFromCache($cacheKey);
485
-		if(!is_null($groupNames) && isset($groupNames[$gid])) {
485
+		if (!is_null($groupNames) && isset($groupNames[$gid])) {
486 486
 			return $groupNames[$gid];
487 487
 		}
488 488
 
489 489
 		$domainObjectSid = $this->access->getSID($dn);
490
-		if($domainObjectSid === false) {
490
+		if ($domainObjectSid === false) {
491 491
 			return false;
492 492
 		}
493 493
 
494 494
 		//we need to get the DN from LDAP
495 495
 		$filter = $this->access->combineFilterWithAnd(array(
496 496
 			$this->access->connection->ldapGroupFilter,
497
-			'objectsid=' . $domainObjectSid . '-' . $gid
497
+			'objectsid='.$domainObjectSid.'-'.$gid
498 498
 		));
499 499
 		$result = $this->access->searchGroups($filter, array('dn'), 1);
500
-		if(empty($result)) {
500
+		if (empty($result)) {
501 501
 			return false;
502 502
 		}
503 503
 		$dn = $result[0]['dn'][0];
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
 	 */
521 521
 	private function getEntryGroupID($dn, $attribute) {
522 522
 		$value = $this->access->readAttribute($dn, $attribute);
523
-		if(is_array($value) && !empty($value)) {
523
+		if (is_array($value) && !empty($value)) {
524 524
 			return $value[0];
525 525
 		}
526 526
 		return false;
@@ -542,9 +542,9 @@  discard block
 block discarded – undo
542 542
 	 */
543 543
 	public function getUserPrimaryGroupIDs($dn) {
544 544
 		$primaryGroupID = false;
545
-		if($this->access->connection->hasPrimaryGroups) {
545
+		if ($this->access->connection->hasPrimaryGroups) {
546 546
 			$primaryGroupID = $this->getEntryGroupID($dn, 'primaryGroupID');
547
-			if($primaryGroupID === false) {
547
+			if ($primaryGroupID === false) {
548 548
 				$this->access->connection->hasPrimaryGroups = false;
549 549
 			}
550 550
 		}
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
 	 */
562 562
 	private function prepareFilterForUsersInPrimaryGroup($groupDN, $search = '') {
563 563
 		$groupID = $this->getGroupPrimaryGroupID($groupDN);
564
-		if($groupID === false) {
564
+		if ($groupID === false) {
565 565
 			throw new \Exception('Not a valid group');
566 566
 		}
567 567
 
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
 		if ($search !== '') {
571 571
 			$filterParts[] = $this->access->getFilterPartForUserSearch($search);
572 572
 		}
573
-		$filterParts[] = 'primaryGroupID=' . $groupID;
573
+		$filterParts[] = 'primaryGroupID='.$groupID;
574 574
 
575 575
 		return $this->access->combineFilterWithAnd($filterParts);
576 576
 	}
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
 		try {
613 613
 			$filter = $this->prepareFilterForUsersInPrimaryGroup($groupDN, $search);
614 614
 			$users = $this->access->countUsers($filter, array('dn'), $limit, $offset);
615
-			return (int)$users;
615
+			return (int) $users;
616 616
 		} catch (\Exception $e) {
617 617
 			return 0;
618 618
 		}
@@ -625,9 +625,9 @@  discard block
 block discarded – undo
625 625
 	 */
626 626
 	public function getUserPrimaryGroup($dn) {
627 627
 		$groupID = $this->getUserPrimaryGroupIDs($dn);
628
-		if($groupID !== false) {
628
+		if ($groupID !== false) {
629 629
 			$groupName = $this->primaryGroupID2Name($groupID, $dn);
630
-			if($groupName !== false) {
630
+			if ($groupName !== false) {
631 631
 				return $groupName;
632 632
 			}
633 633
 		}
@@ -646,16 +646,16 @@  discard block
 block discarded – undo
646 646
 	 * This function includes groups based on dynamic group membership.
647 647
 	 */
648 648
 	public function getUserGroups($uid) {
649
-		if(!$this->enabled) {
649
+		if (!$this->enabled) {
650 650
 			return array();
651 651
 		}
652 652
 		$cacheKey = 'getUserGroups'.$uid;
653 653
 		$userGroups = $this->access->connection->getFromCache($cacheKey);
654
-		if(!is_null($userGroups)) {
654
+		if (!is_null($userGroups)) {
655 655
 			return $userGroups;
656 656
 		}
657 657
 		$userDN = $this->access->username2dn($uid);
658
-		if(!$userDN) {
658
+		if (!$userDN) {
659 659
 			$this->access->connection->writeToCache($cacheKey, array());
660 660
 			return array();
661 661
 		}
@@ -669,14 +669,14 @@  discard block
 block discarded – undo
669 669
 		if (!empty($dynamicGroupMemberURL)) {
670 670
 			// look through dynamic groups to add them to the result array if needed
671 671
 			$groupsToMatch = $this->access->fetchListOfGroups(
672
-				$this->access->connection->ldapGroupFilter,array('dn',$dynamicGroupMemberURL));
673
-			foreach($groupsToMatch as $dynamicGroup) {
672
+				$this->access->connection->ldapGroupFilter, array('dn', $dynamicGroupMemberURL));
673
+			foreach ($groupsToMatch as $dynamicGroup) {
674 674
 				if (!array_key_exists($dynamicGroupMemberURL, $dynamicGroup)) {
675 675
 					continue;
676 676
 				}
677 677
 				$pos = strpos($dynamicGroup[$dynamicGroupMemberURL][0], '(');
678 678
 				if ($pos !== false) {
679
-					$memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0],$pos);
679
+					$memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0], $pos);
680 680
 					// apply filter via ldap search to see if this user is in this
681 681
 					// dynamic group
682 682
 					$userMatch = $this->access->readAttribute(
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
 					if ($userMatch !== false) {
688 688
 						// match found so this user is in this group
689 689
 						$groupName = $this->access->dn2groupname($dynamicGroup['dn'][0]);
690
-						if(is_string($groupName)) {
690
+						if (is_string($groupName)) {
691 691
 							// be sure to never return false if the dn could not be
692 692
 							// resolved to a name, for whatever reason.
693 693
 							$groups[] = $groupName;
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
 					}
696 696
 				} else {
697 697
 					\OCP\Util::writeLog('user_ldap', 'No search filter found on member url '.
698
-						'of group ' . print_r($dynamicGroup, true), ILogger::DEBUG);
698
+						'of group '.print_r($dynamicGroup, true), ILogger::DEBUG);
699 699
 				}
700 700
 			}
701 701
 		}
@@ -703,15 +703,15 @@  discard block
 block discarded – undo
703 703
 		// if possible, read out membership via memberOf. It's far faster than
704 704
 		// performing a search, which still is a fallback later.
705 705
 		// memberof doesn't support memberuid, so skip it here.
706
-		if((int)$this->access->connection->hasMemberOfFilterSupport === 1
707
-			&& (int)$this->access->connection->useMemberOfToDetectMembership === 1
706
+		if ((int) $this->access->connection->hasMemberOfFilterSupport === 1
707
+			&& (int) $this->access->connection->useMemberOfToDetectMembership === 1
708 708
 		    && strtolower($this->access->connection->ldapGroupMemberAssocAttr) !== 'memberuid'
709 709
 		    ) {
710 710
 			$groupDNs = $this->_getGroupDNsFromMemberOf($userDN);
711 711
 			if (is_array($groupDNs)) {
712 712
 				foreach ($groupDNs as $dn) {
713 713
 					$groupName = $this->access->dn2groupname($dn);
714
-					if(is_string($groupName)) {
714
+					if (is_string($groupName)) {
715 715
 						// be sure to never return false if the dn could not be
716 716
 						// resolved to a name, for whatever reason.
717 717
 						$groups[] = $groupName;
@@ -719,10 +719,10 @@  discard block
 block discarded – undo
719 719
 				}
720 720
 			}
721 721
 
722
-			if($primaryGroup !== false) {
722
+			if ($primaryGroup !== false) {
723 723
 				$groups[] = $primaryGroup;
724 724
 			}
725
-			if($gidGroupName !== false) {
725
+			if ($gidGroupName !== false) {
726 726
 				$groups[] = $gidGroupName;
727 727
 			}
728 728
 			$this->access->connection->writeToCache($cacheKey, $groups);
@@ -730,14 +730,14 @@  discard block
 block discarded – undo
730 730
 		}
731 731
 
732 732
 		//uniqueMember takes DN, memberuid the uid, so we need to distinguish
733
-		if((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember')
733
+		if ((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember')
734 734
 			|| (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'member')
735 735
 		) {
736 736
 			$uid = $userDN;
737
-		} else if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
737
+		} else if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
738 738
 			$result = $this->access->readAttribute($userDN, 'uid');
739 739
 			if ($result === false) {
740
-				\OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN ' . $userDN . ' on '.
740
+				\OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN '.$userDN.' on '.
741 741
 					$this->access->connection->ldapHost, ILogger::DEBUG);
742 742
 			}
743 743
 			$uid = $result[0];
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
 			$uid = $userDN;
747 747
 		}
748 748
 
749
-		if(isset($this->cachedGroupsByMember[$uid])) {
749
+		if (isset($this->cachedGroupsByMember[$uid])) {
750 750
 			$groups = array_merge($groups, $this->cachedGroupsByMember[$uid]);
751 751
 		} else {
752 752
 			$groupsByMember = array_values($this->getGroupsByMember($uid));
@@ -755,10 +755,10 @@  discard block
 block discarded – undo
755 755
 			$groups = array_merge($groups, $groupsByMember);
756 756
 		}
757 757
 
758
-		if($primaryGroup !== false) {
758
+		if ($primaryGroup !== false) {
759 759
 			$groups[] = $primaryGroup;
760 760
 		}
761
-		if($gidGroupName !== false) {
761
+		if ($gidGroupName !== false) {
762 762
 			$groups[] = $gidGroupName;
763 763
 		}
764 764
 
@@ -787,8 +787,8 @@  discard block
 block discarded – undo
787 787
 		$groups = $this->access->fetchListOfGroups($filter,
788 788
 			[$this->access->connection->ldapGroupDisplayName, 'dn']);
789 789
 		if (is_array($groups)) {
790
-			$fetcher = function ($dn, &$seen) {
791
-				if(is_array($dn) && isset($dn['dn'][0])) {
790
+			$fetcher = function($dn, &$seen) {
791
+				if (is_array($dn) && isset($dn['dn'][0])) {
792 792
 					$dn = $dn['dn'][0];
793 793
 				}
794 794
 				return $this->getGroupsByMember($dn, $seen);
@@ -809,33 +809,33 @@  discard block
 block discarded – undo
809 809
 	 * @return array with user ids
810 810
 	 */
811 811
 	public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
812
-		if(!$this->enabled) {
812
+		if (!$this->enabled) {
813 813
 			return array();
814 814
 		}
815
-		if(!$this->groupExists($gid)) {
815
+		if (!$this->groupExists($gid)) {
816 816
 			return array();
817 817
 		}
818 818
 		$search = $this->access->escapeFilterPart($search, true);
819 819
 		$cacheKey = 'usersInGroup-'.$gid.'-'.$search.'-'.$limit.'-'.$offset;
820 820
 		// check for cache of the exact query
821 821
 		$groupUsers = $this->access->connection->getFromCache($cacheKey);
822
-		if(!is_null($groupUsers)) {
822
+		if (!is_null($groupUsers)) {
823 823
 			return $groupUsers;
824 824
 		}
825 825
 
826 826
 		// check for cache of the query without limit and offset
827 827
 		$groupUsers = $this->access->connection->getFromCache('usersInGroup-'.$gid.'-'.$search);
828
-		if(!is_null($groupUsers)) {
828
+		if (!is_null($groupUsers)) {
829 829
 			$groupUsers = array_slice($groupUsers, $offset, $limit);
830 830
 			$this->access->connection->writeToCache($cacheKey, $groupUsers);
831 831
 			return $groupUsers;
832 832
 		}
833 833
 
834
-		if($limit === -1) {
834
+		if ($limit === -1) {
835 835
 			$limit = null;
836 836
 		}
837 837
 		$groupDN = $this->access->groupname2dn($gid);
838
-		if(!$groupDN) {
838
+		if (!$groupDN) {
839 839
 			// group couldn't be found, return empty resultset
840 840
 			$this->access->connection->writeToCache($cacheKey, array());
841 841
 			return array();
@@ -844,7 +844,7 @@  discard block
 block discarded – undo
844 844
 		$primaryUsers = $this->getUsersInPrimaryGroup($groupDN, $search, $limit, $offset);
845 845
 		$posixGroupUsers = $this->getUsersInGidNumber($groupDN, $search, $limit, $offset);
846 846
 		$members = $this->_groupMembers($groupDN);
847
-		if(!$members && empty($posixGroupUsers) && empty($primaryUsers)) {
847
+		if (!$members && empty($posixGroupUsers) && empty($primaryUsers)) {
848 848
 			//in case users could not be retrieved, return empty result set
849 849
 			$this->access->connection->writeToCache($cacheKey, []);
850 850
 			return [];
@@ -853,29 +853,29 @@  discard block
 block discarded – undo
853 853
 		$groupUsers = array();
854 854
 		$isMemberUid = (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid');
855 855
 		$attrs = $this->access->userManager->getAttributes(true);
856
-		foreach($members as $member) {
857
-			if($isMemberUid) {
856
+		foreach ($members as $member) {
857
+			if ($isMemberUid) {
858 858
 				//we got uids, need to get their DNs to 'translate' them to user names
859 859
 				$filter = $this->access->combineFilterWithAnd(array(
860 860
 					str_replace('%uid', trim($member), $this->access->connection->ldapLoginFilter),
861 861
 					$this->access->getFilterPartForUserSearch($search)
862 862
 				));
863 863
 				$ldap_users = $this->access->fetchListOfUsers($filter, $attrs, 1);
864
-				if(count($ldap_users) < 1) {
864
+				if (count($ldap_users) < 1) {
865 865
 					continue;
866 866
 				}
867 867
 				$groupUsers[] = $this->access->dn2username($ldap_users[0]['dn'][0]);
868 868
 			} else {
869 869
 				//we got DNs, check if we need to filter by search or we can give back all of them
870 870
 				if ($search !== '') {
871
-					if(!$this->access->readAttribute($member,
871
+					if (!$this->access->readAttribute($member,
872 872
 						$this->access->connection->ldapUserDisplayName,
873 873
 						$this->access->getFilterPartForUserSearch($search))) {
874 874
 						continue;
875 875
 					}
876 876
 				}
877 877
 				// dn2username will also check if the users belong to the allowed base
878
-				if($ocname = $this->access->dn2username($member)) {
878
+				if ($ocname = $this->access->dn2username($member)) {
879 879
 					$groupUsers[] = $ocname;
880 880
 				}
881 881
 			}
@@ -903,16 +903,16 @@  discard block
 block discarded – undo
903 903
 		}
904 904
 
905 905
 		$cacheKey = 'countUsersInGroup-'.$gid.'-'.$search;
906
-		if(!$this->enabled || !$this->groupExists($gid)) {
906
+		if (!$this->enabled || !$this->groupExists($gid)) {
907 907
 			return false;
908 908
 		}
909 909
 		$groupUsers = $this->access->connection->getFromCache($cacheKey);
910
-		if(!is_null($groupUsers)) {
910
+		if (!is_null($groupUsers)) {
911 911
 			return $groupUsers;
912 912
 		}
913 913
 
914 914
 		$groupDN = $this->access->groupname2dn($gid);
915
-		if(!$groupDN) {
915
+		if (!$groupDN) {
916 916
 			// group couldn't be found, return empty result set
917 917
 			$this->access->connection->writeToCache($cacheKey, false);
918 918
 			return false;
@@ -920,7 +920,7 @@  discard block
 block discarded – undo
920 920
 
921 921
 		$members = $this->_groupMembers($groupDN);
922 922
 		$primaryUserCount = $this->countUsersInPrimaryGroup($groupDN, '');
923
-		if(!$members && $primaryUserCount === 0) {
923
+		if (!$members && $primaryUserCount === 0) {
924 924
 			//in case users could not be retrieved, return empty result set
925 925
 			$this->access->connection->writeToCache($cacheKey, false);
926 926
 			return false;
@@ -945,27 +945,27 @@  discard block
 block discarded – undo
945 945
 		//For now this is not important, because the only use of this method
946 946
 		//does not supply a search string
947 947
 		$groupUsers = array();
948
-		foreach($members as $member) {
949
-			if($isMemberUid) {
948
+		foreach ($members as $member) {
949
+			if ($isMemberUid) {
950 950
 				//we got uids, need to get their DNs to 'translate' them to user names
951 951
 				$filter = $this->access->combineFilterWithAnd(array(
952 952
 					str_replace('%uid', $member, $this->access->connection->ldapLoginFilter),
953 953
 					$this->access->getFilterPartForUserSearch($search)
954 954
 				));
955 955
 				$ldap_users = $this->access->fetchListOfUsers($filter, 'dn', 1);
956
-				if(count($ldap_users) < 1) {
956
+				if (count($ldap_users) < 1) {
957 957
 					continue;
958 958
 				}
959 959
 				$groupUsers[] = $this->access->dn2username($ldap_users[0]);
960 960
 			} else {
961 961
 				//we need to apply the search filter now
962
-				if(!$this->access->readAttribute($member,
962
+				if (!$this->access->readAttribute($member,
963 963
 					$this->access->connection->ldapUserDisplayName,
964 964
 					$this->access->getFilterPartForUserSearch($search))) {
965 965
 					continue;
966 966
 				}
967 967
 				// dn2username will also check if the users belong to the allowed base
968
-				if($ocname = $this->access->dn2username($member)) {
968
+				if ($ocname = $this->access->dn2username($member)) {
969 969
 					$groupUsers[] = $ocname;
970 970
 				}
971 971
 			}
@@ -988,7 +988,7 @@  discard block
 block discarded – undo
988 988
 	 * Returns a list with all groups (used by getGroups)
989 989
 	 */
990 990
 	protected function getGroupsChunk($search = '', $limit = -1, $offset = 0) {
991
-		if(!$this->enabled) {
991
+		if (!$this->enabled) {
992 992
 			return array();
993 993
 		}
994 994
 		$cacheKey = 'getGroups-'.$search.'-'.$limit.'-'.$offset;
@@ -996,13 +996,13 @@  discard block
 block discarded – undo
996 996
 		//Check cache before driving unnecessary searches
997 997
 		\OCP\Util::writeLog('user_ldap', 'getGroups '.$cacheKey, ILogger::DEBUG);
998 998
 		$ldap_groups = $this->access->connection->getFromCache($cacheKey);
999
-		if(!is_null($ldap_groups)) {
999
+		if (!is_null($ldap_groups)) {
1000 1000
 			return $ldap_groups;
1001 1001
 		}
1002 1002
 
1003 1003
 		// if we'd pass -1 to LDAP search, we'd end up in a Protocol
1004 1004
 		// error. With a limit of 0, we get 0 results. So we pass null.
1005
-		if($limit <= 0) {
1005
+		if ($limit <= 0) {
1006 1006
 			$limit = null;
1007 1007
 		}
1008 1008
 		$filter = $this->access->combineFilterWithAnd(array(
@@ -1034,11 +1034,11 @@  discard block
 block discarded – undo
1034 1034
 	 * (active directory has a limit of 1000 by default)
1035 1035
 	 */
1036 1036
 	public function getGroups($search = '', $limit = -1, $offset = 0) {
1037
-		if(!$this->enabled) {
1037
+		if (!$this->enabled) {
1038 1038
 			return array();
1039 1039
 		}
1040 1040
 		$search = $this->access->escapeFilterPart($search, true);
1041
-		$pagingSize = (int)$this->access->connection->ldapPagingSize;
1041
+		$pagingSize = (int) $this->access->connection->ldapPagingSize;
1042 1042
 		if ($pagingSize <= 0) {
1043 1043
 			return $this->getGroupsChunk($search, $limit, $offset);
1044 1044
 		}
@@ -1081,20 +1081,20 @@  discard block
 block discarded – undo
1081 1081
 	 */
1082 1082
 	public function groupExists($gid) {
1083 1083
 		$groupExists = $this->access->connection->getFromCache('groupExists'.$gid);
1084
-		if(!is_null($groupExists)) {
1085
-			return (bool)$groupExists;
1084
+		if (!is_null($groupExists)) {
1085
+			return (bool) $groupExists;
1086 1086
 		}
1087 1087
 
1088 1088
 		//getting dn, if false the group does not exist. If dn, it may be mapped
1089 1089
 		//only, requires more checking.
1090 1090
 		$dn = $this->access->groupname2dn($gid);
1091
-		if(!$dn) {
1091
+		if (!$dn) {
1092 1092
 			$this->access->connection->writeToCache('groupExists'.$gid, false);
1093 1093
 			return false;
1094 1094
 		}
1095 1095
 
1096 1096
 		//if group really still exists, we will be able to read its objectclass
1097
-		if(!is_array($this->access->readAttribute($dn, ''))) {
1097
+		if (!is_array($this->access->readAttribute($dn, ''))) {
1098 1098
 			$this->access->connection->writeToCache('groupExists'.$gid, false);
1099 1099
 			return false;
1100 1100
 		}
@@ -1112,7 +1112,7 @@  discard block
 block discarded – undo
1112 1112
 	* compared with GroupInterface::CREATE_GROUP etc.
1113 1113
 	*/
1114 1114
 	public function implementsActions($actions) {
1115
-		return (bool)((GroupInterface::COUNT_USERS |
1115
+		return (bool) ((GroupInterface::COUNT_USERS |
1116 1116
 				$this->groupPluginManager->getImplementedActions()) & $actions);
1117 1117
 	}
1118 1118
 
@@ -1229,7 +1229,7 @@  discard block
 block discarded – undo
1229 1229
 			return $this->groupPluginManager->getDisplayName($gid);
1230 1230
 		}
1231 1231
 
1232
-		$cacheKey = 'group_getDisplayName' . $gid;
1232
+		$cacheKey = 'group_getDisplayName'.$gid;
1233 1233
 		if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
1234 1234
 			return $displayName;
1235 1235
 		}
Please login to merge, or discard this patch.
apps/user_ldap/lib/User_LDAP.php 1 patch
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -103,16 +103,16 @@  discard block
 block discarded – undo
103 103
 			return $this->userPluginManager->canChangeAvatar($uid);
104 104
 		}
105 105
 
106
-		if(!$this->implementsActions(Backend::PROVIDE_AVATAR)) {
106
+		if (!$this->implementsActions(Backend::PROVIDE_AVATAR)) {
107 107
 			return true;
108 108
 		}
109 109
 
110 110
 		$user = $this->access->userManager->get($uid);
111
-		if(!$user instanceof User) {
111
+		if (!$user instanceof User) {
112 112
 			return false;
113 113
 		}
114 114
 		$imageData = $user->getAvatarImage();
115
-		if($imageData === false) {
115
+		if ($imageData === false) {
116 116
 			return true;
117 117
 		}
118 118
 		return !$user->updateAvatar(true);
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 	 * @throws \Exception
127 127
 	 */
128 128
 	public function loginName2UserName($loginName) {
129
-		$cacheKey = 'loginName2UserName-' . $loginName;
129
+		$cacheKey = 'loginName2UserName-'.$loginName;
130 130
 		$username = $this->access->connection->getFromCache($cacheKey);
131 131
 
132 132
 		if ($username !== null) {
@@ -172,9 +172,9 @@  discard block
 block discarded – undo
172 172
 		//find out dn of the user name
173 173
 		$attrs = $this->access->userManager->getAttributes();
174 174
 		$users = $this->access->fetchUsersByLoginName($loginName, $attrs);
175
-		if(count($users) < 1) {
176
-			throw new NotOnLDAP('No user available for the given login name on ' .
177
-				$this->access->connection->ldapHost . ':' . $this->access->connection->ldapPort);
175
+		if (count($users) < 1) {
176
+			throw new NotOnLDAP('No user available for the given login name on '.
177
+				$this->access->connection->ldapHost.':'.$this->access->connection->ldapPort);
178 178
 		}
179 179
 		return $users[0];
180 180
 	}
@@ -189,23 +189,23 @@  discard block
 block discarded – undo
189 189
 	public function checkPassword($uid, $password) {
190 190
 		try {
191 191
 			$ldapRecord = $this->getLDAPUserByLoginName($uid);
192
-		} catch(NotOnLDAP $e) {
192
+		} catch (NotOnLDAP $e) {
193 193
 			\OC::$server->getLogger()->logException($e, ['app' => 'user_ldap', 'level' => ILogger::DEBUG]);
194 194
 			return false;
195 195
 		}
196 196
 		$dn = $ldapRecord['dn'][0];
197 197
 		$user = $this->access->userManager->get($dn);
198 198
 
199
-		if(!$user instanceof User) {
199
+		if (!$user instanceof User) {
200 200
 			Util::writeLog('user_ldap',
201
-				'LDAP Login: Could not get user object for DN ' . $dn .
201
+				'LDAP Login: Could not get user object for DN '.$dn.
202 202
 				'. Maybe the LDAP entry has no set display name attribute?',
203 203
 				ILogger::WARN);
204 204
 			return false;
205 205
 		}
206
-		if($user->getUsername() !== false) {
206
+		if ($user->getUsername() !== false) {
207 207
 			//are the credentials OK?
208
-			if(!$this->access->areCredentialsValid($dn, $password)) {
208
+			if (!$this->access->areCredentialsValid($dn, $password)) {
209 209
 				return false;
210 210
 			}
211 211
 
@@ -232,14 +232,14 @@  discard block
 block discarded – undo
232 232
 
233 233
 		$user = $this->access->userManager->get($uid);
234 234
 
235
-		if(!$user instanceof User) {
236
-			throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid .
235
+		if (!$user instanceof User) {
236
+			throw new \Exception('LDAP setPassword: Could not get user object for uid '.$uid.
237 237
 				'. Maybe the LDAP entry has no set display name attribute?');
238 238
 		}
239
-		if($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) {
239
+		if ($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) {
240 240
 			$ldapDefaultPPolicyDN = $this->access->connection->ldapDefaultPPolicyDN;
241 241
 			$turnOnPasswordChange = $this->access->connection->turnOnPasswordChange;
242
-			if (!empty($ldapDefaultPPolicyDN) && ((int)$turnOnPasswordChange === 1)) {
242
+			if (!empty($ldapDefaultPPolicyDN) && ((int) $turnOnPasswordChange === 1)) {
243 243
 				//remove last password expiry warning if any
244 244
 				$notification = $this->notificationManager->createNotification();
245 245
 				$notification->setApp('user_ldap')
@@ -268,18 +268,18 @@  discard block
 block discarded – undo
268 268
 
269 269
 		//check if users are cached, if so return
270 270
 		$ldap_users = $this->access->connection->getFromCache($cachekey);
271
-		if(!is_null($ldap_users)) {
271
+		if (!is_null($ldap_users)) {
272 272
 			return $ldap_users;
273 273
 		}
274 274
 
275 275
 		// if we'd pass -1 to LDAP search, we'd end up in a Protocol
276 276
 		// error. With a limit of 0, we get 0 results. So we pass null.
277
-		if($limit <= 0) {
277
+		if ($limit <= 0) {
278 278
 			$limit = null;
279 279
 		}
280 280
 		$filter = $this->access->combineFilterWithAnd(array(
281 281
 			$this->access->connection->ldapUserFilter,
282
-			$this->access->connection->ldapUserDisplayName . '=*',
282
+			$this->access->connection->ldapUserDisplayName.'=*',
283 283
 			$this->access->getFilterPartForUserSearch($search)
284 284
 		));
285 285
 
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 			$this->access->userManager->getAttributes(true),
293 293
 			$limit, $offset);
294 294
 		$ldap_users = $this->access->nextcloudUserNames($ldap_users);
295
-		Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', ILogger::DEBUG);
295
+		Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users).' Users found', ILogger::DEBUG);
296 296
 
297 297
 		$this->access->connection->writeToCache($cachekey, $ldap_users);
298 298
 		return $ldap_users;
@@ -308,16 +308,16 @@  discard block
 block discarded – undo
308 308
 	 * @throws \OC\ServerNotAvailableException
309 309
 	 */
310 310
 	public function userExistsOnLDAP($user) {
311
-		if(is_string($user)) {
311
+		if (is_string($user)) {
312 312
 			$user = $this->access->userManager->get($user);
313 313
 		}
314
-		if(is_null($user)) {
314
+		if (is_null($user)) {
315 315
 			return false;
316 316
 		}
317 317
 
318 318
 		$dn = $user->getDN();
319 319
 		//check if user really still exists by reading its entry
320
-		if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) {
320
+		if (!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) {
321 321
 			try {
322 322
 				$uuid = $this->access->getUserMapper()->getUUIDByDN($dn);
323 323
 				if (!$uuid) {
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 			}
338 338
 		}
339 339
 
340
-		if($user instanceof OfflineUser) {
340
+		if ($user instanceof OfflineUser) {
341 341
 			$user->unmark();
342 342
 		}
343 343
 
@@ -352,18 +352,18 @@  discard block
 block discarded – undo
352 352
 	 */
353 353
 	public function userExists($uid) {
354 354
 		$userExists = $this->access->connection->getFromCache('userExists'.$uid);
355
-		if(!is_null($userExists)) {
356
-			return (bool)$userExists;
355
+		if (!is_null($userExists)) {
356
+			return (bool) $userExists;
357 357
 		}
358 358
 		//getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking.
359 359
 		$user = $this->access->userManager->get($uid);
360 360
 
361
-		if(is_null($user)) {
361
+		if (is_null($user)) {
362 362
 			Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '.
363 363
 				$this->access->connection->ldapHost, ILogger::DEBUG);
364 364
 			$this->access->connection->writeToCache('userExists'.$uid, false);
365 365
 			return false;
366
-		} else if($user instanceof OfflineUser) {
366
+		} else if ($user instanceof OfflineUser) {
367 367
 			//express check for users marked as deleted. Returning true is
368 368
 			//necessary for cleanup
369 369
 			return true;
@@ -386,13 +386,13 @@  discard block
 block discarded – undo
386 386
 		}
387 387
 
388 388
 		$marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0);
389
-		if((int)$marked === 0) {
389
+		if ((int) $marked === 0) {
390 390
 			\OC::$server->getLogger()->notice(
391
-				'User '.$uid . ' is not marked as deleted, not cleaning up.',
391
+				'User '.$uid.' is not marked as deleted, not cleaning up.',
392 392
 				array('app' => 'user_ldap'));
393 393
 			return false;
394 394
 		}
395
-		\OC::$server->getLogger()->info('Cleaning up after user ' . $uid,
395
+		\OC::$server->getLogger()->info('Cleaning up after user '.$uid,
396 396
 			array('app' => 'user_ldap'));
397 397
 
398 398
 		$this->access->getUserMapper()->unmap($uid); // we don't emit unassign signals here, since it is implicit to delete signals fired from core
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
 	 */
411 411
 	public function getHome($uid) {
412 412
 		// user Exists check required as it is not done in user proxy!
413
-		if(!$this->userExists($uid)) {
413
+		if (!$this->userExists($uid)) {
414 414
 			return false;
415 415
 		}
416 416
 
@@ -420,22 +420,22 @@  discard block
 block discarded – undo
420 420
 
421 421
 		$cacheKey = 'getHome'.$uid;
422 422
 		$path = $this->access->connection->getFromCache($cacheKey);
423
-		if(!is_null($path)) {
423
+		if (!is_null($path)) {
424 424
 			return $path;
425 425
 		}
426 426
 
427 427
 		// early return path if it is a deleted user
428 428
 		$user = $this->access->userManager->get($uid);
429
-		if($user instanceof OfflineUser) {
430
-			if($this->currentUserInDeletionProcess !== null
429
+		if ($user instanceof OfflineUser) {
430
+			if ($this->currentUserInDeletionProcess !== null
431 431
 				&& $this->currentUserInDeletionProcess === $user->getOCName()
432 432
 			) {
433 433
 				return $user->getHomePath();
434 434
 			} else {
435
-				throw new NoUserException($uid . ' is not a valid user anymore');
435
+				throw new NoUserException($uid.' is not a valid user anymore');
436 436
 			}
437 437
 		} else if ($user === null) {
438
-			throw new NoUserException($uid . ' is not a valid user anymore');
438
+			throw new NoUserException($uid.' is not a valid user anymore');
439 439
 		}
440 440
 
441 441
 		$path = $user->getHomePath();
@@ -454,12 +454,12 @@  discard block
 block discarded – undo
454 454
 			return $this->userPluginManager->getDisplayName($uid);
455 455
 		}
456 456
 
457
-		if(!$this->userExists($uid)) {
457
+		if (!$this->userExists($uid)) {
458 458
 			return false;
459 459
 		}
460 460
 
461 461
 		$cacheKey = 'getDisplayName'.$uid;
462
-		if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
462
+		if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
463 463
 			return $displayName;
464 464
 		}
465 465
 
@@ -476,10 +476,10 @@  discard block
 block discarded – undo
476 476
 			$this->access->username2dn($uid),
477 477
 			$this->access->connection->ldapUserDisplayName);
478 478
 
479
-		if($displayName && (count($displayName) > 0)) {
479
+		if ($displayName && (count($displayName) > 0)) {
480 480
 			$displayName = $displayName[0];
481 481
 
482
-			if (is_array($displayName2)){
482
+			if (is_array($displayName2)) {
483 483
 				$displayName2 = count($displayName2) > 0 ? $displayName2[0] : '';
484 484
 			}
485 485
 
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
 	 */
524 524
 	public function getDisplayNames($search = '', $limit = null, $offset = null) {
525 525
 		$cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset;
526
-		if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) {
526
+		if (!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) {
527 527
 			return $displayNames;
528 528
 		}
529 529
 
@@ -545,12 +545,12 @@  discard block
 block discarded – undo
545 545
 	* compared with \OC\User\Backend::CREATE_USER etc.
546 546
 	*/
547 547
 	public function implementsActions($actions) {
548
-		return (bool)((Backend::CHECK_PASSWORD
548
+		return (bool) ((Backend::CHECK_PASSWORD
549 549
 			| Backend::GET_HOME
550 550
 			| Backend::GET_DISPLAYNAME
551 551
 			| (($this->access->connection->ldapUserAvatarRule !== 'none') ? Backend::PROVIDE_AVATAR : 0)
552 552
 			| Backend::COUNT_USERS
553
-			| (((int)$this->access->connection->turnOnPasswordChange === 1)? Backend::SET_PASSWORD :0)
553
+			| (((int) $this->access->connection->turnOnPasswordChange === 1) ? Backend::SET_PASSWORD : 0)
554 554
 			| $this->userPluginManager->getImplementedActions())
555 555
 			& $actions);
556 556
 	}
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
 
575 575
 		$filter = $this->access->getFilterForUserCount();
576 576
 		$cacheKey = 'countUsers-'.$filter;
577
-		if(!is_null($entries = $this->access->connection->getFromCache($cacheKey))) {
577
+		if (!is_null($entries = $this->access->connection->getFromCache($cacheKey))) {
578 578
 			return $entries;
579 579
 		}
580 580
 		$entries = $this->access->countUsers($filter);
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
 	 * Backend name to be shown in user management
587 587
 	 * @return string the name of the backend to be shown
588 588
 	 */
589
-	public function getBackendName(){
589
+	public function getBackendName() {
590 590
 		return 'LDAP';
591 591
 	}
592 592
 	
@@ -624,7 +624,7 @@  discard block
 block discarded – undo
624 624
 				if (is_string($dn)) {
625 625
 					// the NC user creation work flow requires a know user id up front
626 626
 					$uuid = $this->access->getUUID($dn, true);
627
-					if(is_string($uuid)) {
627
+					if (is_string($uuid)) {
628 628
 						$this->access->mapAndAnnounceIfApplicable(
629 629
 							$this->access->getUserMapper(),
630 630
 							$dn,
Please login to merge, or discard this patch.
apps/provisioning_api/lib/Controller/UsersController.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 		// Admin? Or SubAdmin?
128 128
 		$uid = $user->getUID();
129 129
 		$subAdminManager = $this->groupManager->getSubAdmin();
130
-		if ($this->groupManager->isAdmin($uid)){
130
+		if ($this->groupManager->isAdmin($uid)) {
131 131
 			$users = $this->userManager->search($search, $limit, $offset);
132 132
 		} else if ($subAdminManager->isSubAdmin($user)) {
133 133
 			$subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user);
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 		// Admin? Or SubAdmin?
161 161
 		$uid = $currentUser->getUID();
162 162
 		$subAdminManager = $this->groupManager->getSubAdmin();
163
-		if ($this->groupManager->isAdmin($uid)){
163
+		if ($this->groupManager->isAdmin($uid)) {
164 164
 			$users = $this->userManager->search($search, $limit, $offset);
165 165
 			$users = array_keys($users);
166 166
 		} else if ($subAdminManager->isSubAdmin($currentUser)) {
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 		$isAdmin = $this->groupManager->isAdmin($user->getUID());
238 238
 		$subAdminManager = $this->groupManager->getSubAdmin();
239 239
 
240
-		if(empty($userid) && $this->config->getAppValue('core', 'newUser.generateUserID', 'no') === 'yes') {
240
+		if (empty($userid) && $this->config->getAppValue('core', 'newUser.generateUserID', 'no') === 'yes') {
241 241
 			$userid = $this->createNewUserId();
242 242
 		}
243 243
 
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 					throw new OCSException('group '.$group.' does not exist', 104);
253 253
 				}
254 254
 				if (!$isAdmin && !$subAdminManager->isSubAdminOfGroup($user, $this->groupManager->get($group))) {
255
-					throw new OCSException('insufficient privileges for group '. $group, 105);
255
+					throw new OCSException('insufficient privileges for group '.$group, 105);
256 256
 				}
257 257
 			}
258 258
 		} else {
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 				$group = $this->groupManager->get($groupid);
268 268
 				// Check if group exists
269 269
 				if ($group === null) {
270
-					throw new OCSException('Subadmin group does not exist',  102);
270
+					throw new OCSException('Subadmin group does not exist', 102);
271 271
 				}
272 272
 				// Check if trying to make subadmin of admin group
273 273
 				if ($group->getGID() === 'admin') {
@@ -299,11 +299,11 @@  discard block
 block discarded – undo
299 299
 
300 300
 		try {
301 301
 			$newUser = $this->userManager->createUser($userid, $password);
302
-			$this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']);
302
+			$this->logger->info('Successful addUser call with userid: '.$userid, ['app' => 'ocs_api']);
303 303
 
304 304
 			foreach ($groups as $group) {
305 305
 				$this->groupManager->get($group)->addUser($newUser);
306
-				$this->logger->info('Added userid ' . $userid . ' to group ' . $group, ['app' => 'ocs_api']);
306
+				$this->logger->info('Added userid '.$userid.' to group '.$group, ['app' => 'ocs_api']);
307 307
 			}
308 308
 			foreach ($subadminGroups as $group) {
309 309
 				$subAdminManager->createSubAdmin($newUser, $group);
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
 
340 340
 			return new DataResponse(['UserID' => $userid]);
341 341
 
342
-		} catch (HintException $e ) {
342
+		} catch (HintException $e) {
343 343
 			$this->logger->logException($e, [
344 344
 				'message' => 'Failed addUser attempt with hint exception.',
345 345
 				'level' => ILogger::WARN,
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
 	public function getCurrentUser(): DataResponse {
388 388
 		$user = $this->userSession->getUser();
389 389
 		if ($user) {
390
-			$data =  $this->getUserData($user->getUID());
390
+			$data = $this->getUserData($user->getUID());
391 391
 			// rename "displayname" to "display-name" only for this call to keep
392 392
 			// the API stable.
393 393
 			$data['display-name'] = $data['displayname'];
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
 			throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
510 510
 		}
511 511
 		// Process the edit
512
-		switch($key) {
512
+		switch ($key) {
513 513
 			case 'display':
514 514
 			case AccountManager::PROPERTY_DISPLAYNAME:
515 515
 				$targetUser->setDisplayName($value);
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
 		} else if (!$this->groupManager->isAdmin($loggedInUser->getUID())) {
788 788
 			/** @var IGroup[] $subAdminGroups */
789 789
 			$subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser);
790
-			$subAdminGroups = array_map(function (IGroup $subAdminGroup) {
790
+			$subAdminGroups = array_map(function(IGroup $subAdminGroup) {
791 791
 				return $subAdminGroup->getGID();
792 792
 			}, $subAdminGroups);
793 793
 			$userGroups = $this->groupManager->getUserGroupIds($targetUser);
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
 		}
825 825
 		// Check if group exists
826 826
 		if ($group === null) {
827
-			throw new OCSException('Group does not exist',  102);
827
+			throw new OCSException('Group does not exist', 102);
828 828
 		}
829 829
 		// Check if trying to make subadmin of admin group
830 830
 		if ($group->getGID() === 'admin') {
@@ -921,7 +921,7 @@  discard block
 block discarded – undo
921 921
 		try {
922 922
 			$emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false);
923 923
 			$this->newUserMailHelper->sendMail($targetUser, $emailTemplate);
924
-		} catch(\Exception $e) {
924
+		} catch (\Exception $e) {
925 925
 			$this->logger->logException($e, [
926 926
 				'message' => "Can't send new user mail to $email",
927 927
 				'level' => ILogger::ERROR,
Please login to merge, or discard this patch.