@@ -33,8 +33,6 @@ public function addGroup(string ...$groups): self
3333 {
3434 $ this ->populateGroups ();
3535
36- $ configGroups = $ this ->getConfigGroups ();
37-
3836 $ groupCount = count ($ this ->groupCache );
3937
4038 foreach ($ groups as $ group ) {
@@ -46,7 +44,7 @@ public function addGroup(string ...$groups): self
4644 }
4745
4846 // make sure it's a valid group
49- if (! in_array ($ group, $ configGroups , true )) {
47+ if (! $ this -> isValidGroup ($ group )) {
5048 throw AuthorizationException::forUnknownGroup ($ group );
5149 }
5250
@@ -61,6 +59,18 @@ public function addGroup(string ...$groups): self
6159 return $ this ;
6260 }
6361
62+ /**
63+ * @TODO duplicate of UserModel::isValidGroup()
64+ *
65+ * @param non-empty-string $group
66+ */
67+ private function isValidGroup (string $ group ): bool
68+ {
69+ $ allowedGroups = array_keys (setting ('AuthGroups.groups ' ));
70+
71+ return (bool ) (in_array ($ group , $ allowedGroups , true ));
72+ }
73+
6474 /**
6575 * Removes one or more groups from the user.
6676 *
@@ -96,10 +106,8 @@ public function syncGroups(string ...$groups): self
96106 {
97107 $ this ->populateGroups ();
98108
99- $ configGroups = $ this ->getConfigGroups ();
100-
101109 foreach ($ groups as $ group ) {
102- if (! in_array ($ group, $ configGroups , true )) {
110+ if (! $ this -> isValidGroup ($ group )) {
103111 throw AuthorizationException::forUnknownGroup ($ group );
104112 }
105113 }
@@ -398,14 +406,6 @@ private function saveGroupsOrPermissions(string $type, $model, array $cache): vo
398406 }
399407 }
400408
401- /**
402- * @return list<string>
403- */
404- private function getConfigGroups (): array
405- {
406- return array_keys (setting ('AuthGroups.groups ' ));
407- }
408-
409409 /**
410410 * @return list<string>
411411 */
0 commit comments