Skip to content

Commit a33afca

Browse files
committed
Api methods (except those that return issue lists) now consistently return as associative arrays instead of Result
1 parent 8c86e6f commit a33afca

File tree

2 files changed

+40
-45
lines changed

2 files changed

+40
-45
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
2323
- Remove trailing slash from endpoint url by [@Procta].
2424
- Added local cache to getResolutions by [@jpastoor].
2525
- Renamed Api::api() parameter $return_as_json to $return_as_array by [@jpastoor].
26+
- Changed default Api::api() parameter $return_as_array to TRUE by [@jpastoor].
27+
- Api methods (except those that return issue lists) now consistently return as associative arrays instead of Result by [@jpastoor].
2628

2729
### Removed
2830
...

src/Jira/Api.php

+38-45
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,14 @@ protected function clearLocalCaches()
173173
/**
174174
* Get fields definitions.
175175
*
176-
* @return array
176+
* @return array|false
177177
*/
178178
public function getFields()
179179
{
180180
// Fetch fields when the method is called for the first time.
181181
if ( $this->fields === null ) {
182182
$fields = array();
183-
$result = $this->api(self::REQUEST_GET, '/rest/api/2/field', array(), true);
183+
$result = $this->api(self::REQUEST_GET, '/rest/api/2/field');
184184

185185
/* set hash key as custom field id */
186186
foreach ( $result as $field ) {
@@ -199,7 +199,7 @@ public function getFields()
199199
* @param string $issue_key Issue key should be "YOURPROJ-221".
200200
* @param string $expand Expand.
201201
*
202-
* @return Result|false
202+
* @return array|false
203203
*/
204204
public function getIssue($issue_key, $expand = '')
205205
{
@@ -212,7 +212,7 @@ public function getIssue($issue_key, $expand = '')
212212
* @param string $issue_key Issue key.
213213
* @param array $params Params.
214214
*
215-
* @return Result|false
215+
* @return array|false
216216
*/
217217
public function editIssue($issue_key, array $params)
218218
{
@@ -222,7 +222,7 @@ public function editIssue($issue_key, array $params)
222222
/**
223223
* Gets attachments meta information.
224224
*
225-
* @return array
225+
* @return array|false
226226
* @since 2.0.0
227227
*/
228228
public function getAttachmentsMetaInformation()
@@ -239,13 +239,13 @@ public function getAttachmentsMetaInformation()
239239
*/
240240
public function getAttachment($attachment_id)
241241
{
242-
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/attachment/%s', $attachment_id), array(), true);
242+
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/attachment/%s', $attachment_id));
243243
}
244244

245245
/**
246246
* Returns all projects.
247247
*
248-
* @return Result|false
248+
* @return array|false
249249
*/
250250
public function getProjects()
251251
{
@@ -261,7 +261,7 @@ public function getProjects()
261261
*/
262262
public function getProject($project_key)
263263
{
264-
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/project/%s', $project_key), array(), true);
264+
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/project/%s', $project_key));
265265
}
266266

267267
/**
@@ -273,7 +273,7 @@ public function getProject($project_key)
273273
*/
274274
public function getRoles($project_key)
275275
{
276-
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/project/%s/role', $project_key), array(), true);
276+
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/project/%s/role', $project_key));
277277
}
278278

279279
/**
@@ -286,12 +286,7 @@ public function getRoles($project_key)
286286
*/
287287
public function getRoleDetails($project_key, $role_id)
288288
{
289-
return $this->api(
290-
self::REQUEST_GET,
291-
sprintf('/rest/api/2/project/%s/role/%s', $project_key, $role_id),
292-
array(),
293-
true
294-
);
289+
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/project/%s/role/%s', $project_key, $role_id));
295290
}
296291

297292
/**
@@ -350,7 +345,7 @@ public function getCreateMeta(
350345
$data['expand'] = implode(',', $expand);
351346
}
352347

353-
return $this->api(self::REQUEST_GET, '/rest/api/2/issue/createmeta', $data, true);
348+
return $this->api(self::REQUEST_GET, '/rest/api/2/issue/createmeta', $data);
354349
}
355350

356351
/**
@@ -359,7 +354,7 @@ public function getCreateMeta(
359354
* @param string $issue_key Issue key should be "YOURPROJ-221".
360355
* @param array|string $params Params.
361356
*
362-
* @return Result|false
357+
* @return array|false
363358
*/
364359
public function addComment($issue_key, $params)
365360
{
@@ -379,7 +374,7 @@ public function addComment($issue_key, $params)
379374
* @param string $issue_key Issue key should be "YOURPROJ-22".
380375
* @param array $params Params.
381376
*
382-
* @return Result|false
377+
* @return array|false
383378
* @since 2.0.0
384379
*/
385380
public function getWorklogs($issue_key, array $params)
@@ -393,7 +388,7 @@ public function getWorklogs($issue_key, array $params)
393388
* @param string $issue_key Issue key should be "YOURPROJ-22".
394389
* @param array $params Params.
395390
*
396-
* @return Result|false
391+
* @return array|false
397392
*/
398393
public function getTransitions($issue_key, array $params)
399394
{
@@ -406,7 +401,7 @@ public function getTransitions($issue_key, array $params)
406401
* @param string $issue_key Issue key should be "YOURPROJ-22".
407402
* @param array $params Params.
408403
*
409-
* @return Result|false
404+
* @return array|false
410405
*/
411406
public function transition($issue_key, array $params)
412407
{
@@ -421,7 +416,7 @@ public function transition($issue_key, array $params)
421416
public function getIssueTypes()
422417
{
423418
$result = array();
424-
$types = $this->api(self::REQUEST_GET, '/rest/api/2/issuetype', array(), true);
419+
$types = $this->api(self::REQUEST_GET, '/rest/api/2/issuetype');
425420

426421
foreach ( $types as $issue_type ) {
427422
$result[] = new IssueType($issue_type);
@@ -439,7 +434,7 @@ public function getIssueTypes()
439434
*/
440435
public function getVersions($project_key)
441436
{
442-
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/project/%s/versions', $project_key), array(), true);
437+
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/project/%s/versions', $project_key));
443438
}
444439

445440
/**
@@ -473,15 +468,15 @@ public function findVersionByName($project_key, $name)
473468
/**
474469
* Get available priorities.
475470
*
476-
* @return array
471+
* @return array|false
477472
* @since 2.0.0
478473
*/
479474
public function getPriorities()
480475
{
481476
// Fetch priorities when the method is called for the first time.
482477
if ( $this->priorities === null ) {
483478
$priorities = array();
484-
$result = $this->api(self::REQUEST_GET, '/rest/api/2/priority', array(), true);
479+
$result = $this->api(self::REQUEST_GET, '/rest/api/2/priority');
485480

486481
/* set hash key as custom field id */
487482
foreach ( $result as $priority ) {
@@ -504,7 +499,7 @@ public function getStatuses()
504499
// Fetch statuses when the method is called for the first time.
505500
if ( $this->statuses === null ) {
506501
$statuses = array();
507-
$result = $this->api(self::REQUEST_GET, '/rest/api/2/status', array(), true);
502+
$result = $this->api(self::REQUEST_GET, '/rest/api/2/status');
508503

509504
/* set hash key as custom field id */
510505
foreach ( $result as $status ) {
@@ -525,7 +520,7 @@ public function getStatuses()
525520
* @param string $issue_type Issue type.
526521
* @param array $options Options.
527522
*
528-
* @return Result|false
523+
* @return array|false
529524
*/
530525
public function createIssue($project_key, $summary, $issue_type, array $options = array())
531526
{
@@ -564,7 +559,7 @@ public function search($jql, $start_at = 0, $max_results = 20, $fields = '*navig
564559
'startAt' => $start_at,
565560
'maxResults' => $max_results,
566561
'fields' => $fields,
567-
)
562+
), false
568563
);
569564

570565
return $result;
@@ -577,7 +572,7 @@ public function search($jql, $start_at = 0, $max_results = 20, $fields = '*navig
577572
* @param string $version Version.
578573
* @param array $options Options.
579574
*
580-
* @return Result|false
575+
* @return array|false
581576
*/
582577
public function createVersion($project_key, $version, array $options = array())
583578
{
@@ -603,7 +598,7 @@ public function createVersion($project_key, $version, array $options = array())
603598
* @param integer $version_id Version ID.
604599
* @param array $params Key->Value list to update the version with.
605600
*
606-
* @return false
601+
* @return array|false
607602
* @since 2.0.0
608603
* @link https://docs.atlassian.com/jira/REST/latest/#api/2/version-updateVersion
609604
*/
@@ -646,7 +641,7 @@ public function releaseVersion($version_id, $release_date = null, array $params
646641
* @param string $filename Filename.
647642
* @param array $options Options.
648643
*
649-
* @return Result|false
644+
* @return array|false
650645
*/
651646
public function createAttachment($issue_key, $filename, array $options = array())
652647
{
@@ -661,7 +656,7 @@ public function createAttachment($issue_key, $filename, array $options = array()
661656
self::REQUEST_POST,
662657
sprintf('/rest/api/2/issue/%s/attachments', $issue_key),
663658
$options,
664-
false,
659+
true,
665660
true
666661
);
667662
}
@@ -695,7 +690,7 @@ public function createRemotelink(
695690
$options['application'] = $application;
696691
}
697692

698-
return $this->api(self::REQUEST_POST, sprintf('/rest/api/2/issue/%s/remotelink', $issue_key), $options, true);
693+
return $this->api(self::REQUEST_POST, sprintf('/rest/api/2/issue/%s/remotelink', $issue_key), $options);
699694
}
700695

701696
/**
@@ -714,7 +709,7 @@ public function api(
714709
$method = self::REQUEST_GET,
715710
$url,
716711
$data = array(),
717-
$return_as_array = false,
712+
$return_as_array = true,
718713
$is_file = false,
719714
$debug = false
720715
) {
@@ -810,7 +805,7 @@ protected function automapFields(array $issue)
810805
* @param string $issue_key Issue key.
811806
* @param array $watchers Watchers.
812807
*
813-
* @return Result|false
808+
* @return array|false
814809
*/
815810
public function setWatchers($issue_key, array $watchers)
816811
{
@@ -828,20 +823,18 @@ public function setWatchers($issue_key, array $watchers)
828823
*
829824
* @param string $issue_key Issue key.
830825
*
831-
* @return Result|array
826+
* @return array|false
832827
* @TODO: Should have parameters? (e.g comment)
833828
*/
834829
public function closeIssue($issue_key)
835830
{
836831
$result = array();
837832

838833
// Get available transitions.
839-
$tmp_transitions = $this->getTransitions($issue_key, array());
840-
$tmp_transitions_result = $tmp_transitions->getResult();
841-
$transitions = $tmp_transitions_result['transitions'];
834+
$transitions = $this->getTransitions($issue_key, array());
842835

843836
// Look for "Close Issue" transition in issue transitions.
844-
foreach ( $transitions as $v ) {
837+
foreach ( $transitions['transitions'] as $v ) {
845838
// Close issue if required id was found.
846839
if ( $v['name'] == 'Close Issue' ) {
847840
$result = $this->transition(
@@ -862,39 +855,39 @@ public function closeIssue($issue_key)
862855
*
863856
* @param string $project_key Project key.
864857
*
865-
* @return array
858+
* @return array|false
866859
* @since 2.0.0
867860
*/
868861
public function getProjectComponents($project_key)
869862
{
870-
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/project/%s/components', $project_key), array(), true);
863+
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/project/%s/components', $project_key));
871864
}
872865

873866
/**
874867
* Get all issue types with valid status values for a project.
875868
*
876869
* @param string $project_key Project key.
877870
*
878-
* @return array
871+
* @return array|false
879872
* @since 2.0.0
880873
*/
881874
public function getProjectIssueTypes($project_key)
882875
{
883-
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/project/%s/statuses', $project_key), array(), true);
876+
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/project/%s/statuses', $project_key));
884877
}
885878

886879
/**
887880
* Returns a list of all resolutions.
888881
*
889-
* @return array
882+
* @return array|false
890883
* @since 2.0.0
891884
*/
892885
public function getResolutions()
893886
{
894887
// Fetch resolutions when the method is called for the first time.
895888
if ( $this->resolutions === null ) {
896889
$resolutions = array();
897-
$result = $this->api(self::REQUEST_GET, '/rest/api/2/resolution', array(), true);
890+
$result = $this->api(self::REQUEST_GET, '/rest/api/2/resolution');
898891

899892
foreach ( $result as $resolution ) {
900893
$resolutions[$resolution['id']] = $resolution;

0 commit comments

Comments
 (0)