Passed
Push — master ( 8355f9...6d2471 )
by Blizzz
12:04 queued 10s
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;
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 			return [];
241 241
 		}
242 242
 		// used extensively in cron job, caching makes sense for nested groups
243
-		$cacheKey = '_groupMembers' . $dnGroup;
243
+		$cacheKey = '_groupMembers'.$dnGroup;
244 244
 		$groupMembers = $this->access->connection->getFromCache($cacheKey);
245 245
 		if ($groupMembers !== null) {
246 246
 			return $groupMembers;
@@ -255,14 +255,14 @@  discard block
 block discarded – undo
255 255
 			// compatibility hack with servers supporting :1.2.840.113556.1.4.1941:, and others)
256 256
 			$filter = $this->access->combineFilterWithAnd([
257 257
 				$this->access->connection->ldapUserFilter,
258
-				$this->access->connection->ldapUserDisplayName . '=*',
259
-				'memberof:1.2.840.113556.1.4.1941:=' . $dnGroup
258
+				$this->access->connection->ldapUserDisplayName.'=*',
259
+				'memberof:1.2.840.113556.1.4.1941:='.$dnGroup
260 260
 			]);
261 261
 			$memberRecords = $this->access->fetchListOfUsers(
262 262
 				$filter,
263 263
 				$this->access->userManager->getAttributes(true)
264 264
 			);
265
-			$result = array_reduce($memberRecords, function ($carry, $record) {
265
+			$result = array_reduce($memberRecords, function($carry, $record) {
266 266
 				$carry[] = $record['dn'][0];
267 267
 				return $carry;
268 268
 			}, []);
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 		$seen[$dnGroup] = 1;
280 280
 		$members = $this->access->readAttribute($dnGroup, $this->access->connection->ldapGroupMemberAssocAttr);
281 281
 		if (is_array($members)) {
282
-			$fetcher = function ($memberDN, &$seen) {
282
+			$fetcher = function($memberDN, &$seen) {
283 283
 				return $this->_groupMembers($memberDN, $seen);
284 284
 			};
285 285
 			$allMembers = $this->walkNestedGroups($dnGroup, $fetcher, $members);
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
 			return [];
308 308
 		}
309 309
 
310
-		$fetcher = function ($groupDN) {
310
+		$fetcher = function($groupDN) {
311 311
 			if (isset($this->cachedNestedGroups[$groupDN])) {
312 312
 				$nestedGroups = $this->cachedNestedGroups[$groupDN];
313 313
 			} else {
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 	}
326 326
 
327 327
 	private function walkNestedGroups(string $dn, Closure $fetcher, array $list): array {
328
-		$nesting = (int)$this->access->connection->ldapNestedGroups;
328
+		$nesting = (int) $this->access->connection->ldapNestedGroups;
329 329
 		// depending on the input, we either have a list of DNs or a list of LDAP records
330 330
 		// also, the output expects either DNs or records. Testing the first element should suffice.
331 331
 		$recordMode = is_array($list) && isset($list[0]) && is_array($list[0]) && isset($list[0]['dn'][0]);
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 		if ($nesting !== 1) {
334 334
 			if ($recordMode) {
335 335
 				// the keys are numeric, but should hold the DN
336
-				return array_reduce($list, function ($transformed, $record) use ($dn) {
336
+				return array_reduce($list, function($transformed, $record) use ($dn) {
337 337
 					if ($record['dn'][0] != $dn) {
338 338
 						$transformed[$record['dn'][0]] = $record;
339 339
 					}
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
 	 * @throws ServerNotAvailableException
367 367
 	 */
368 368
 	public function gidNumber2Name(string $gid, string $dn) {
369
-		$cacheKey = 'gidNumberToName' . $gid;
369
+		$cacheKey = 'gidNumberToName'.$gid;
370 370
 		$groupName = $this->access->connection->getFromCache($cacheKey);
371 371
 		if (!is_null($groupName) && isset($groupName)) {
372 372
 			return $groupName;
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
 		$filter = $this->access->combineFilterWithAnd([
377 377
 			$this->access->connection->ldapGroupFilter,
378 378
 			'objectClass=posixGroup',
379
-			$this->access->connection->ldapGidNumber . '=' . $gid
379
+			$this->access->connection->ldapGidNumber.'='.$gid
380 380
 		]);
381 381
 		return $this->getNameOfGroup($filter, $cacheKey) ?? false;
382 382
 	}
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
 		if ($search !== '') {
457 457
 			$filterParts[] = $this->access->getFilterPartForUserSearch($search);
458 458
 		}
459
-		$filterParts[] = $this->access->connection->ldapGidNumber . '=' . $groupID;
459
+		$filterParts[] = $this->access->connection->ldapGidNumber.'='.$groupID;
460 460
 
461 461
 		return $this->access->combineFilterWithAnd($filterParts);
462 462
 	}
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
 		//we need to get the DN from LDAP
527 527
 		$filter = $this->access->combineFilterWithAnd([
528 528
 			$this->access->connection->ldapGroupFilter,
529
-			'objectsid=' . $domainObjectSid . '-' . $gid
529
+			'objectsid='.$domainObjectSid.'-'.$gid
530 530
 		]);
531 531
 		return $this->getNameOfGroup($filter, $cacheKey) ?? false;
532 532
 	}
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
 		if ($search !== '') {
584 584
 			$filterParts[] = $this->access->getFilterPartForUserSearch($search);
585 585
 		}
586
-		$filterParts[] = 'primaryGroupID=' . $groupID;
586
+		$filterParts[] = 'primaryGroupID='.$groupID;
587 587
 
588 588
 		return $this->access->combineFilterWithAnd($filterParts);
589 589
 	}
@@ -625,7 +625,7 @@  discard block
 block discarded – undo
625 625
 		try {
626 626
 			$filter = $this->prepareFilterForUsersInPrimaryGroup($groupDN, $search);
627 627
 			$users = $this->access->countUsers($filter, ['dn'], $limit, $offset);
628
-			return (int)$users;
628
+			return (int) $users;
629 629
 		} catch (ServerNotAvailableException $e) {
630 630
 			throw $e;
631 631
 		} catch (Exception $e) {
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
 		if (!$this->enabled) {
665 665
 			return [];
666 666
 		}
667
-		$cacheKey = 'getUserGroups' . $uid;
667
+		$cacheKey = 'getUserGroups'.$uid;
668 668
 		$userGroups = $this->access->connection->getFromCache($cacheKey);
669 669
 		if (!is_null($userGroups)) {
670 670
 			return $userGroups;
@@ -722,8 +722,8 @@  discard block
 block discarded – undo
722 722
 		// if possible, read out membership via memberOf. It's far faster than
723 723
 		// performing a search, which still is a fallback later.
724 724
 		// memberof doesn't support memberuid, so skip it here.
725
-		if ((int)$this->access->connection->hasMemberOfFilterSupport === 1
726
-			&& (int)$this->access->connection->useMemberOfToDetectMembership === 1
725
+		if ((int) $this->access->connection->hasMemberOfFilterSupport === 1
726
+			&& (int) $this->access->connection->useMemberOfToDetectMembership === 1
727 727
 			&& $this->ldapGroupMemberAssocAttr !== 'memberuid'
728 728
 			&& $this->ldapGroupMemberAssocAttr !== 'zimbramailforwardingaddress') {
729 729
 			$groupDNs = $this->_getGroupDNsFromMemberOf($userDN);
@@ -815,14 +815,14 @@  discard block
 block discarded – undo
815 815
 		}
816 816
 		$allGroups = [];
817 817
 		$seen[$dn] = true;
818
-		$filter = $this->access->connection->ldapGroupMemberAssocAttr . '=' . $dn;
818
+		$filter = $this->access->connection->ldapGroupMemberAssocAttr.'='.$dn;
819 819
 
820 820
 		if ($this->ldapGroupMemberAssocAttr === 'zimbramailforwardingaddress') {
821 821
 			//in this case the member entries are email addresses
822 822
 			$filter .= '@*';
823 823
 		}
824 824
 
825
-		$nesting = (int)$this->access->connection->ldapNestedGroups;
825
+		$nesting = (int) $this->access->connection->ldapNestedGroups;
826 826
 		if ($nesting === 0) {
827 827
 			$filter = $this->access->combineFilterWithAnd([$filter, $this->access->connection->ldapGroupFilter]);
828 828
 		}
@@ -830,7 +830,7 @@  discard block
 block discarded – undo
830 830
 		$groups = $this->access->fetchListOfGroups($filter,
831 831
 			[strtolower($this->access->connection->ldapGroupMemberAssocAttr), $this->access->connection->ldapGroupDisplayName, 'dn']);
832 832
 		if (is_array($groups)) {
833
-			$fetcher = function ($dn, &$seen) {
833
+			$fetcher = function($dn, &$seen) {
834 834
 				if (is_array($dn) && isset($dn['dn'][0])) {
835 835
 					$dn = $dn['dn'][0];
836 836
 				}
@@ -866,7 +866,7 @@  discard block
 block discarded – undo
866 866
 			return [];
867 867
 		}
868 868
 		$search = $this->access->escapeFilterPart($search, true);
869
-		$cacheKey = 'usersInGroup-' . $gid . '-' . $search . '-' . $limit . '-' . $offset;
869
+		$cacheKey = 'usersInGroup-'.$gid.'-'.$search.'-'.$limit.'-'.$offset;
870 870
 		// check for cache of the exact query
871 871
 		$groupUsers = $this->access->connection->getFromCache($cacheKey);
872 872
 		if (!is_null($groupUsers)) {
@@ -877,7 +877,7 @@  discard block
 block discarded – undo
877 877
 			$limit = null;
878 878
 		}
879 879
 		// check for cache of the query without limit and offset
880
-		$groupUsers = $this->access->connection->getFromCache('usersInGroup-' . $gid . '-' . $search);
880
+		$groupUsers = $this->access->connection->getFromCache('usersInGroup-'.$gid.'-'.$search);
881 881
 		if (!is_null($groupUsers)) {
882 882
 			$groupUsers = array_slice($groupUsers, $offset, $limit);
883 883
 			$this->access->connection->writeToCache($cacheKey, $groupUsers);
@@ -931,7 +931,7 @@  discard block
 block discarded – undo
931 931
 						break;
932 932
 					}
933 933
 
934
-					$cacheKey = 'userExistsOnLDAP' . $uid;
934
+					$cacheKey = 'userExistsOnLDAP'.$uid;
935 935
 					$userExists = $this->access->connection->getFromCache($cacheKey);
936 936
 					if ($userExists === false) {
937 937
 						break;
@@ -957,7 +957,7 @@  discard block
 block discarded – undo
957 957
 
958 958
 		$groupUsers = array_unique(array_merge($groupUsers, $primaryUsers, $posixGroupUsers));
959 959
 		natsort($groupUsers);
960
-		$this->access->connection->writeToCache('usersInGroup-' . $gid . '-' . $search, $groupUsers);
960
+		$this->access->connection->writeToCache('usersInGroup-'.$gid.'-'.$search, $groupUsers);
961 961
 		$groupUsers = array_slice($groupUsers, $offset, $limit);
962 962
 
963 963
 		$this->access->connection->writeToCache($cacheKey, $groupUsers);
@@ -979,7 +979,7 @@  discard block
 block discarded – undo
979 979
 			return $this->groupPluginManager->countUsersInGroup($gid, $search);
980 980
 		}
981 981
 
982
-		$cacheKey = 'countUsersInGroup-' . $gid . '-' . $search;
982
+		$cacheKey = 'countUsersInGroup-'.$gid.'-'.$search;
983 983
 		if (!$this->enabled || !$this->groupExists($gid)) {
984 984
 			return false;
985 985
 		}
@@ -1077,7 +1077,7 @@  discard block
 block discarded – undo
1077 1077
 		if (!$this->enabled) {
1078 1078
 			return [];
1079 1079
 		}
1080
-		$cacheKey = 'getGroups-' . $search . '-' . $limit . '-' . $offset;
1080
+		$cacheKey = 'getGroups-'.$search.'-'.$limit.'-'.$offset;
1081 1081
 
1082 1082
 		//Check cache before driving unnecessary searches
1083 1083
 		$ldap_groups = $this->access->connection->getFromCache($cacheKey);
@@ -1112,31 +1112,31 @@  discard block
 block discarded – undo
1112 1112
 	 * @throws ServerNotAvailableException
1113 1113
 	 */
1114 1114
 	public function groupExists($gid) {
1115
-		$groupExists = $this->access->connection->getFromCache('groupExists' . $gid);
1115
+		$groupExists = $this->access->connection->getFromCache('groupExists'.$gid);
1116 1116
 		if (!is_null($groupExists)) {
1117
-			return (bool)$groupExists;
1117
+			return (bool) $groupExists;
1118 1118
 		}
1119 1119
 
1120 1120
 		//getting dn, if false the group does not exist. If dn, it may be mapped
1121 1121
 		//only, requires more checking.
1122 1122
 		$dn = $this->access->groupname2dn($gid);
1123 1123
 		if (!$dn) {
1124
-			$this->access->connection->writeToCache('groupExists' . $gid, false);
1124
+			$this->access->connection->writeToCache('groupExists'.$gid, false);
1125 1125
 			return false;
1126 1126
 		}
1127 1127
 
1128 1128
 		if (!$this->access->isDNPartOfBase($dn, $this->access->connection->ldapBaseGroups)) {
1129
-			$this->access->connection->writeToCache('groupExists' . $gid, false);
1129
+			$this->access->connection->writeToCache('groupExists'.$gid, false);
1130 1130
 			return false;
1131 1131
 		}
1132 1132
 
1133 1133
 		//if group really still exists, we will be able to read its objectClass
1134 1134
 		if (!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapGroupFilter))) {
1135
-			$this->access->connection->writeToCache('groupExists' . $gid, false);
1135
+			$this->access->connection->writeToCache('groupExists'.$gid, false);
1136 1136
 			return false;
1137 1137
 		}
1138 1138
 
1139
-		$this->access->connection->writeToCache('groupExists' . $gid, true);
1139
+		$this->access->connection->writeToCache('groupExists'.$gid, true);
1140 1140
 		return true;
1141 1141
 	}
1142 1142
 
@@ -1169,7 +1169,7 @@  discard block
 block discarded – undo
1169 1169
 	 * compared with GroupInterface::CREATE_GROUP etc.
1170 1170
 	 */
1171 1171
 	public function implementsActions($actions) {
1172
-		return (bool)((GroupInterface::COUNT_USERS |
1172
+		return (bool) ((GroupInterface::COUNT_USERS |
1173 1173
 				$this->groupPluginManager->getImplementedActions()) & $actions);
1174 1174
 	}
1175 1175
 
@@ -1223,7 +1223,7 @@  discard block
 block discarded – undo
1223 1223
 			if ($ret = $this->groupPluginManager->deleteGroup($gid)) {
1224 1224
 				#delete group in nextcloud internal db
1225 1225
 				$this->access->getGroupMapper()->unmap($gid);
1226
-				$this->access->connection->writeToCache("groupExists" . $gid, false);
1226
+				$this->access->connection->writeToCache("groupExists".$gid, false);
1227 1227
 			}
1228 1228
 			return $ret;
1229 1229
 		}
@@ -1304,7 +1304,7 @@  discard block
 block discarded – undo
1304 1304
 			return $this->groupPluginManager->getDisplayName($gid);
1305 1305
 		}
1306 1306
 
1307
-		$cacheKey = 'group_getDisplayName' . $gid;
1307
+		$cacheKey = 'group_getDisplayName'.$gid;
1308 1308
 		if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
1309 1309
 			return $displayName;
1310 1310
 		}
Please login to merge, or discard this patch.