Skip to content

Commit 516115e

Browse files
committed
Extract Project::listing()
1 parent aa78b81 commit 516115e

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

src/Redmine/Api/CustomField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function getIdByName($name, array $params = [])
138138
return $arr[(string) $name];
139139
}
140140

141-
private function doListing($forceUpdate = false, array $params = [])
141+
private function doListing(bool $forceUpdate, array $params)
142142
{
143143
if (empty($this->customFields) || $forceUpdate) {
144144
$this->customFields = $this->list($params);

src/Redmine/Api/IssueCategory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function getIdByName($project, $name)
155155
{
156156
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNamesByProject()` instead.', E_USER_DEPRECATED);
157157

158-
$arr = $this->doListing($project);
158+
$arr = $this->doListing($project, false);
159159

160160
if (!isset($arr[$name])) {
161161
return false;
@@ -282,7 +282,7 @@ public function remove($id, array $params = [])
282282
return $this->lastResponse->getContent();
283283
}
284284

285-
private function doListing($project, $forceUpdate = false)
285+
private function doListing($project, bool $forceUpdate)
286286
{
287287
if (true === $forceUpdate || empty($this->issueCategories)) {
288288
$this->issueCategories = $this->listByProject($project);

src/Redmine/Api/Project.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,7 @@ public function listing($forceUpdate = false, $reverse = true, array $params = [
132132
{
133133
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED);
134134

135-
if (true === $forceUpdate || empty($this->projects)) {
136-
$this->projects = $this->list($params);
137-
}
138-
$ret = [];
139-
foreach ($this->projects['projects'] as $e) {
140-
$ret[(int) $e['id']] = $e['name'];
141-
}
142-
143-
return $reverse ? array_flip($ret) : $ret;
135+
return $this->doListing($forceUpdate, $reverse, $params);
144136
}
145137

146138
/**
@@ -153,7 +145,8 @@ public function listing($forceUpdate = false, $reverse = true, array $params = [
153145
*/
154146
public function getIdByName($name, array $params = [])
155147
{
156-
$arr = $this->listing(false, true, $params);
148+
$arr = $this->doListing(false, true, $params);
149+
157150
if (!isset($arr[$name])) {
158151
return false;
159152
}
@@ -447,4 +440,19 @@ public function remove($id)
447440

448441
return $this->lastResponse->getContent();
449442
}
443+
444+
private function doListing(bool $forceUpdate, bool $reverse, array $params)
445+
{
446+
if (true === $forceUpdate || empty($this->projects)) {
447+
$this->projects = $this->list($params);
448+
}
449+
450+
$ret = [];
451+
452+
foreach ($this->projects['projects'] as $e) {
453+
$ret[(int) $e['id']] = $e['name'];
454+
}
455+
456+
return $reverse ? array_flip($ret) : $ret;
457+
}
450458
}

0 commit comments

Comments
 (0)