Skip to content

Commit

Permalink
Extract Version::listing()
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Jul 9, 2024
1 parent 4441921 commit 64e8df4
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/Redmine/Api/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,7 @@ public function listing($project, $forceUpdate = false, $reverse = true, array $
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNamesByProject()` instead.', E_USER_DEPRECATED);

if (true === $forceUpdate || empty($this->versions)) {
$this->versions = $this->listByProject($project, $params);
}
$ret = [];
foreach ($this->versions['versions'] as $e) {
$ret[(int) $e['id']] = $e['name'];
}

return $reverse ? array_flip($ret) : $ret;
return $this->doListing($project, $forceUpdate, $reverse, $params);
}

/**
Expand All @@ -161,7 +153,8 @@ public function listing($project, $forceUpdate = false, $reverse = true, array $
*/
public function getIdByName($project, $name, array $params = [])
{
$arr = $this->listing($project, false, true, $params);
$arr = $this->doListing($project, false, true, $params);

if (!isset($arr[$name])) {
return false;
}
Expand Down Expand Up @@ -319,4 +312,19 @@ public function remove($id)

return $this->lastResponse->getContent();
}

private function doListing($project, bool $forceUpdate, bool $reverse, array $params)
{
if (true === $forceUpdate || empty($this->versions)) {
$this->versions = $this->listByProject($project, $params);
}

$ret = [];

foreach ($this->versions['versions'] as $e) {
$ret[(int) $e['id']] = $e['name'];
}

return $reverse ? array_flip($ret) : $ret;
}
}

0 comments on commit 64e8df4

Please sign in to comment.