Passed
Push — master ( 01f082...9cd39b )
by Blizzz
19:42 queued 06:16
created
apps/user_ldap/lib/Group_LDAP.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -100,10 +100,10 @@  discard block
 block discarded – undo
100 100
 		if (!$this->enabled) {
101 101
 			return false;
102 102
 		}
103
-		$cacheKey = 'inGroup' . $uid . ':' . $gid;
103
+		$cacheKey = 'inGroup'.$uid.':'.$gid;
104 104
 		$inGroup = $this->access->connection->getFromCache($cacheKey);
105 105
 		if (!is_null($inGroup)) {
106
-			return (bool)$inGroup;
106
+			return (bool) $inGroup;
107 107
 		}
108 108
 
109 109
 		$userDN = $this->access->username2dn($uid);
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 			return in_array($userDN, $this->cachedGroupMembers[$gid]);
113 113
 		}
114 114
 
115
-		$cacheKeyMembers = 'inGroup-members:' . $gid;
115
+		$cacheKeyMembers = 'inGroup-members:'.$gid;
116 116
 		$members = $this->access->connection->getFromCache($cacheKeyMembers);
117 117
 		if (!is_null($members)) {
118 118
 			$this->cachedGroupMembers[$gid] = $members;
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 			return [];
255 255
 		}
256 256
 		// used extensively in cron job, caching makes sense for nested groups
257
-		$cacheKey = '_groupMembers' . $dnGroup;
257
+		$cacheKey = '_groupMembers'.$dnGroup;
258 258
 		$groupMembers = $this->access->connection->getFromCache($cacheKey);
259 259
 		if ($groupMembers !== null) {
260 260
 			return $groupMembers;
@@ -269,14 +269,14 @@  discard block
 block discarded – undo
269 269
 			// compatibility hack with servers supporting :1.2.840.113556.1.4.1941:, and others)
270 270
 			$filter = $this->access->combineFilterWithAnd([
271 271
 				$this->access->connection->ldapUserFilter,
272
-				$this->access->connection->ldapUserDisplayName . '=*',
273
-				'memberof:1.2.840.113556.1.4.1941:=' . $dnGroup
272
+				$this->access->connection->ldapUserDisplayName.'=*',
273
+				'memberof:1.2.840.113556.1.4.1941:='.$dnGroup
274 274
 			]);
275 275
 			$memberRecords = $this->access->fetchListOfUsers(
276 276
 				$filter,
277 277
 				$this->access->userManager->getAttributes(true)
278 278
 			);
279
-			$result = array_reduce($memberRecords, function ($carry, $record) {
279
+			$result = array_reduce($memberRecords, function($carry, $record) {
280 280
 				$carry[] = $record['dn'][0];
281 281
 				return $carry;
282 282
 			}, []);
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
 		$seen[$dnGroup] = 1;
294 294
 		$members = $this->access->readAttribute($dnGroup, $this->access->connection->ldapGroupMemberAssocAttr);
295 295
 		if (is_array($members)) {
296
-			$fetcher = function ($memberDN) use (&$seen) {
296
+			$fetcher = function($memberDN) use (&$seen) {
297 297
 				return $this->_groupMembers($memberDN, $seen);
298 298
 			};
299 299
 			$allMembers = $this->walkNestedGroups($dnGroup, $fetcher, $members, $seen);
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 			return [];
328 328
 		}
329 329
 
330
-		$fetcher = function ($groupDN) {
330
+		$fetcher = function($groupDN) {
331 331
 			if (isset($this->cachedNestedGroups[$groupDN])) {
332 332
 				$nestedGroups = $this->cachedNestedGroups[$groupDN];
333 333
 			} else {
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 	}
346 346
 
347 347
 	private function walkNestedGroups(string $dn, Closure $fetcher, array $list, array &$seen = []): array {
348
-		$nesting = (int)$this->access->connection->ldapNestedGroups;
348
+		$nesting = (int) $this->access->connection->ldapNestedGroups;
349 349
 		// depending on the input, we either have a list of DNs or a list of LDAP records
350 350
 		// also, the output expects either DNs or records. Testing the first element should suffice.
351 351
 		$recordMode = is_array($list) && isset($list[0]) && is_array($list[0]) && isset($list[0]['dn'][0]);
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 		if ($nesting !== 1) {
354 354
 			if ($recordMode) {
355 355
 				// the keys are numeric, but should hold the DN
356
-				return array_reduce($list, function ($transformed, $record) use ($dn) {
356
+				return array_reduce($list, function($transformed, $record) use ($dn) {
357 357
 					if ($record['dn'][0] != $dn) {
358 358
 						$transformed[$record['dn'][0]] = $record;
359 359
 					}
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
 	 * @throws ServerNotAvailableException
389 389
 	 */
390 390
 	public function gidNumber2Name(string $gid, string $dn) {
391
-		$cacheKey = 'gidNumberToName' . $gid;
391
+		$cacheKey = 'gidNumberToName'.$gid;
392 392
 		$groupName = $this->access->connection->getFromCache($cacheKey);
393 393
 		if (!is_null($groupName) && isset($groupName)) {
394 394
 			return $groupName;
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
 		$filter = $this->access->combineFilterWithAnd([
399 399
 			$this->access->connection->ldapGroupFilter,
400 400
 			'objectClass=posixGroup',
401
-			$this->access->connection->ldapGidNumber . '=' . $gid
401
+			$this->access->connection->ldapGidNumber.'='.$gid
402 402
 		]);
403 403
 		return $this->getNameOfGroup($filter, $cacheKey) ?? false;
404 404
 	}
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
 		if ($search !== '') {
479 479
 			$filterParts[] = $this->access->getFilterPartForUserSearch($search);
480 480
 		}
481
-		$filterParts[] = $this->access->connection->ldapGidNumber . '=' . $groupID;
481
+		$filterParts[] = $this->access->connection->ldapGidNumber.'='.$groupID;
482 482
 
483 483
 		return $this->access->combineFilterWithAnd($filterParts);
484 484
 	}
@@ -548,7 +548,7 @@  discard block
 block discarded – undo
548 548
 		//we need to get the DN from LDAP
549 549
 		$filter = $this->access->combineFilterWithAnd([
550 550
 			$this->access->connection->ldapGroupFilter,
551
-			'objectsid=' . $domainObjectSid . '-' . $gid
551
+			'objectsid='.$domainObjectSid.'-'.$gid
552 552
 		]);
553 553
 		return $this->getNameOfGroup($filter, $cacheKey) ?? false;
554 554
 	}
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
 		if ($search !== '') {
606 606
 			$filterParts[] = $this->access->getFilterPartForUserSearch($search);
607 607
 		}
608
-		$filterParts[] = 'primaryGroupID=' . $groupID;
608
+		$filterParts[] = 'primaryGroupID='.$groupID;
609 609
 
610 610
 		return $this->access->combineFilterWithAnd($filterParts);
611 611
 	}
@@ -647,7 +647,7 @@  discard block
 block discarded – undo
647 647
 		try {
648 648
 			$filter = $this->prepareFilterForUsersInPrimaryGroup($groupDN, $search);
649 649
 			$users = $this->access->countUsers($filter, ['dn'], $limit, $offset);
650
-			return (int)$users;
650
+			return (int) $users;
651 651
 		} catch (ServerNotAvailableException $e) {
652 652
 			throw $e;
653 653
 		} catch (Exception $e) {
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
 		if (!$this->enabled) {
687 687
 			return [];
688 688
 		}
689
-		$cacheKey = 'getUserGroups' . $uid;
689
+		$cacheKey = 'getUserGroups'.$uid;
690 690
 		$userGroups = $this->access->connection->getFromCache($cacheKey);
691 691
 		if (!is_null($userGroups)) {
692 692
 			return $userGroups;
@@ -744,8 +744,8 @@  discard block
 block discarded – undo
744 744
 		// if possible, read out membership via memberOf. It's far faster than
745 745
 		// performing a search, which still is a fallback later.
746 746
 		// memberof doesn't support memberuid, so skip it here.
747
-		if ((int)$this->access->connection->hasMemberOfFilterSupport === 1
748
-			&& (int)$this->access->connection->useMemberOfToDetectMembership === 1
747
+		if ((int) $this->access->connection->hasMemberOfFilterSupport === 1
748
+			&& (int) $this->access->connection->useMemberOfToDetectMembership === 1
749 749
 			&& $this->ldapGroupMemberAssocAttr !== 'memberuid'
750 750
 			&& $this->ldapGroupMemberAssocAttr !== 'zimbramailforwardingaddress') {
751 751
 			$groupDNs = $this->_getGroupDNsFromMemberOf($userDN);
@@ -837,14 +837,14 @@  discard block
 block discarded – undo
837 837
 		}
838 838
 		$allGroups = [];
839 839
 		$seen[$dn] = true;
840
-		$filter = $this->access->connection->ldapGroupMemberAssocAttr . '=' . $dn;
840
+		$filter = $this->access->connection->ldapGroupMemberAssocAttr.'='.$dn;
841 841
 
842 842
 		if ($this->ldapGroupMemberAssocAttr === 'zimbramailforwardingaddress') {
843 843
 			//in this case the member entries are email addresses
844 844
 			$filter .= '@*';
845 845
 		}
846 846
 
847
-		$nesting = (int)$this->access->connection->ldapNestedGroups;
847
+		$nesting = (int) $this->access->connection->ldapNestedGroups;
848 848
 		if ($nesting === 0) {
849 849
 			$filter = $this->access->combineFilterWithAnd([$filter, $this->access->connection->ldapGroupFilter]);
850 850
 		}
@@ -852,7 +852,7 @@  discard block
 block discarded – undo
852 852
 		$groups = $this->access->fetchListOfGroups($filter,
853 853
 			[strtolower($this->access->connection->ldapGroupMemberAssocAttr), $this->access->connection->ldapGroupDisplayName, 'dn']);
854 854
 		if (is_array($groups)) {
855
-			$fetcher = function ($dn) use (&$seen) {
855
+			$fetcher = function($dn) use (&$seen) {
856 856
 				if (is_array($dn) && isset($dn['dn'][0])) {
857 857
 					$dn = $dn['dn'][0];
858 858
 				}
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
 			return [];
889 889
 		}
890 890
 		$search = $this->access->escapeFilterPart($search, true);
891
-		$cacheKey = 'usersInGroup-' . $gid . '-' . $search . '-' . $limit . '-' . $offset;
891
+		$cacheKey = 'usersInGroup-'.$gid.'-'.$search.'-'.$limit.'-'.$offset;
892 892
 		// check for cache of the exact query
893 893
 		$groupUsers = $this->access->connection->getFromCache($cacheKey);
894 894
 		if (!is_null($groupUsers)) {
@@ -899,7 +899,7 @@  discard block
 block discarded – undo
899 899
 			$limit = null;
900 900
 		}
901 901
 		// check for cache of the query without limit and offset
902
-		$groupUsers = $this->access->connection->getFromCache('usersInGroup-' . $gid . '-' . $search);
902
+		$groupUsers = $this->access->connection->getFromCache('usersInGroup-'.$gid.'-'.$search);
903 903
 		if (!is_null($groupUsers)) {
904 904
 			$groupUsers = array_slice($groupUsers, $offset, $limit);
905 905
 			$this->access->connection->writeToCache($cacheKey, $groupUsers);
@@ -954,7 +954,7 @@  discard block
 block discarded – undo
954 954
 						break;
955 955
 					}
956 956
 
957
-					$cacheKey = 'userExistsOnLDAP' . $uid;
957
+					$cacheKey = 'userExistsOnLDAP'.$uid;
958 958
 					$userExists = $this->access->connection->getFromCache($cacheKey);
959 959
 					if ($userExists === false) {
960 960
 						break;
@@ -980,7 +980,7 @@  discard block
 block discarded – undo
980 980
 
981 981
 		$groupUsers = array_unique(array_merge($groupUsers, $primaryUsers, $posixGroupUsers));
982 982
 		natsort($groupUsers);
983
-		$this->access->connection->writeToCache('usersInGroup-' . $gid . '-' . $search, $groupUsers);
983
+		$this->access->connection->writeToCache('usersInGroup-'.$gid.'-'.$search, $groupUsers);
984 984
 		$groupUsers = array_slice($groupUsers, $offset, $limit);
985 985
 
986 986
 		$this->access->connection->writeToCache($cacheKey, $groupUsers);
@@ -1002,7 +1002,7 @@  discard block
 block discarded – undo
1002 1002
 			return $this->groupPluginManager->countUsersInGroup($gid, $search);
1003 1003
 		}
1004 1004
 
1005
-		$cacheKey = 'countUsersInGroup-' . $gid . '-' . $search;
1005
+		$cacheKey = 'countUsersInGroup-'.$gid.'-'.$search;
1006 1006
 		if (!$this->enabled || !$this->groupExists($gid)) {
1007 1007
 			return false;
1008 1008
 		}
@@ -1101,7 +1101,7 @@  discard block
 block discarded – undo
1101 1101
 			return [];
1102 1102
 		}
1103 1103
 		$search = $this->access->escapeFilterPart($search, true);
1104
-		$cacheKey = 'getGroups-' . $search . '-' . $limit . '-' . $offset;
1104
+		$cacheKey = 'getGroups-'.$search.'-'.$limit.'-'.$offset;
1105 1105
 
1106 1106
 		//Check cache before driving unnecessary searches
1107 1107
 		$ldap_groups = $this->access->connection->getFromCache($cacheKey);
@@ -1136,31 +1136,31 @@  discard block
 block discarded – undo
1136 1136
 	 * @throws ServerNotAvailableException
1137 1137
 	 */
1138 1138
 	public function groupExists($gid) {
1139
-		$groupExists = $this->access->connection->getFromCache('groupExists' . $gid);
1139
+		$groupExists = $this->access->connection->getFromCache('groupExists'.$gid);
1140 1140
 		if (!is_null($groupExists)) {
1141
-			return (bool)$groupExists;
1141
+			return (bool) $groupExists;
1142 1142
 		}
1143 1143
 
1144 1144
 		//getting dn, if false the group does not exist. If dn, it may be mapped
1145 1145
 		//only, requires more checking.
1146 1146
 		$dn = $this->access->groupname2dn($gid);
1147 1147
 		if (!$dn) {
1148
-			$this->access->connection->writeToCache('groupExists' . $gid, false);
1148
+			$this->access->connection->writeToCache('groupExists'.$gid, false);
1149 1149
 			return false;
1150 1150
 		}
1151 1151
 
1152 1152
 		if (!$this->access->isDNPartOfBase($dn, $this->access->connection->ldapBaseGroups)) {
1153
-			$this->access->connection->writeToCache('groupExists' . $gid, false);
1153
+			$this->access->connection->writeToCache('groupExists'.$gid, false);
1154 1154
 			return false;
1155 1155
 		}
1156 1156
 
1157 1157
 		//if group really still exists, we will be able to read its objectClass
1158 1158
 		if (!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapGroupFilter))) {
1159
-			$this->access->connection->writeToCache('groupExists' . $gid, false);
1159
+			$this->access->connection->writeToCache('groupExists'.$gid, false);
1160 1160
 			return false;
1161 1161
 		}
1162 1162
 
1163
-		$this->access->connection->writeToCache('groupExists' . $gid, true);
1163
+		$this->access->connection->writeToCache('groupExists'.$gid, true);
1164 1164
 		return true;
1165 1165
 	}
1166 1166
 
@@ -1193,7 +1193,7 @@  discard block
 block discarded – undo
1193 1193
 	 * compared with GroupInterface::CREATE_GROUP etc.
1194 1194
 	 */
1195 1195
 	public function implementsActions($actions) {
1196
-		return (bool)((GroupInterface::COUNT_USERS |
1196
+		return (bool) ((GroupInterface::COUNT_USERS |
1197 1197
 				$this->groupPluginManager->getImplementedActions()) & $actions);
1198 1198
 	}
1199 1199
 
@@ -1247,7 +1247,7 @@  discard block
 block discarded – undo
1247 1247
 			if ($ret = $this->groupPluginManager->deleteGroup($gid)) {
1248 1248
 				#delete group in nextcloud internal db
1249 1249
 				$this->access->getGroupMapper()->unmap($gid);
1250
-				$this->access->connection->writeToCache("groupExists" . $gid, false);
1250
+				$this->access->connection->writeToCache("groupExists".$gid, false);
1251 1251
 			}
1252 1252
 			return $ret;
1253 1253
 		}
@@ -1328,7 +1328,7 @@  discard block
 block discarded – undo
1328 1328
 			return $this->groupPluginManager->getDisplayName($gid);
1329 1329
 		}
1330 1330
 
1331
-		$cacheKey = 'group_getDisplayName' . $gid;
1331
+		$cacheKey = 'group_getDisplayName'.$gid;
1332 1332
 		if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
1333 1333
 			return $displayName;
1334 1334
 		}
Please login to merge, or discard this patch.