Skip to content

Commit 64e8df4

Browse files
committed
Extract Version::listing()
1 parent 4441921 commit 64e8df4

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/Redmine/Api/Version.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,7 @@ public function listing($project, $forceUpdate = false, $reverse = true, array $
139139
{
140140
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNamesByProject()` instead.', E_USER_DEPRECATED);
141141

142-
if (true === $forceUpdate || empty($this->versions)) {
143-
$this->versions = $this->listByProject($project, $params);
144-
}
145-
$ret = [];
146-
foreach ($this->versions['versions'] as $e) {
147-
$ret[(int) $e['id']] = $e['name'];
148-
}
149-
150-
return $reverse ? array_flip($ret) : $ret;
142+
return $this->doListing($project, $forceUpdate, $reverse, $params);
151143
}
152144

153145
/**
@@ -161,7 +153,8 @@ public function listing($project, $forceUpdate = false, $reverse = true, array $
161153
*/
162154
public function getIdByName($project, $name, array $params = [])
163155
{
164-
$arr = $this->listing($project, false, true, $params);
156+
$arr = $this->doListing($project, false, true, $params);
157+
165158
if (!isset($arr[$name])) {
166159
return false;
167160
}
@@ -319,4 +312,19 @@ public function remove($id)
319312

320313
return $this->lastResponse->getContent();
321314
}
315+
316+
private function doListing($project, bool $forceUpdate, bool $reverse, array $params)
317+
{
318+
if (true === $forceUpdate || empty($this->versions)) {
319+
$this->versions = $this->listByProject($project, $params);
320+
}
321+
322+
$ret = [];
323+
324+
foreach ($this->versions['versions'] as $e) {
325+
$ret[(int) $e['id']] = $e['name'];
326+
}
327+
328+
return $reverse ? array_flip($ret) : $ret;
329+
}
322330
}

0 commit comments

Comments
 (0)