Skip to content

Commit 057a289

Browse files
committed
Extract User::listing()
1 parent 1bacd63 commit 057a289

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/Redmine/Api/User.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,7 @@ public function listing($forceUpdate = false, array $params = [])
130130
{
131131
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listLogins()` instead.', E_USER_DEPRECATED);
132132

133-
if (empty($this->users) || $forceUpdate) {
134-
$this->users = $this->list($params);
135-
}
136-
$ret = [];
137-
if (is_array($this->users) && isset($this->users['users'])) {
138-
foreach ($this->users['users'] as $e) {
139-
$ret[$e['login']] = (int) $e['id'];
140-
}
141-
}
142-
143-
return $ret;
133+
return $this->doListing($forceUpdate, $params);
144134
}
145135

146136
/**
@@ -167,7 +157,8 @@ public function getCurrentUser(array $params = [])
167157
*/
168158
public function getIdByUsername($username, array $params = [])
169159
{
170-
$arr = $this->listing(false, $params);
160+
$arr = $this->doListing(false, $params);
161+
171162
if (!isset($arr[$username])) {
172163
return false;
173164
}
@@ -318,4 +309,21 @@ public function remove($id)
318309

319310
return $this->lastResponse->getContent();
320311
}
312+
313+
private function doListing(bool $forceUpdate, array $params)
314+
{
315+
if (empty($this->users) || $forceUpdate) {
316+
$this->users = $this->list($params);
317+
}
318+
319+
$ret = [];
320+
321+
if (is_array($this->users) && isset($this->users['users'])) {
322+
foreach ($this->users['users'] as $e) {
323+
$ret[$e['login']] = (int) $e['id'];
324+
}
325+
}
326+
327+
return $ret;
328+
}
321329
}

0 commit comments

Comments
 (0)