Skip to content

Commit b9b0551

Browse files
authored
Merge pull request richp10#14 from richp10/martinduparc-patch-1
Code refactoring
2 parents f805799 + 2f6e068 commit b9b0551

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/DiscourseAPI.php

+4-12
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ public function getGroups()
4343
* @return mixed HTTP return code and API return object
4444
*/
4545

46-
public function getGroup($group)
46+
public function getGroup($groupname)
4747
{
48-
return $this->_getRequest('/groups/' . $group . '.json');
48+
return $this->_getRequest('/groups/' . $groupname . '.json');
4949
}
5050

5151
/**
@@ -79,20 +79,12 @@ public function joinGroup($groupname, $username)
7979
*/
8080
public function getGroupIdByGroupName($groupname)
8181
{
82-
$obj = $this->getGroups();
82+
$obj = $this->getGroup($groupname);
8383
if ($obj->http_code !== 200) {
8484
return false;
8585
}
8686

87-
foreach ($obj->apiresult as $group) {
88-
if ($group->name === $groupname) {
89-
$groupId = (int)$group->id;
90-
break;
91-
}
92-
$groupId = false;
93-
}
94-
95-
return $groupId;
87+
return $obj->apiresult->group->id;
9688
}
9789

9890
/**

0 commit comments

Comments
 (0)