Skip to content

Commit 369758e

Browse files
authored
Merge pull request #4 from dereuromark/assoc-array
Consistent API return as assoc array
2 parents bb3b31d + bd46f73 commit 369758e

12 files changed

+838
-31
lines changed

src/Jira/Api.php

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,13 @@ protected function clearLocalCaches() {
187187
/**
188188
* Get fields definitions.
189189
*
190-
* @return array
190+
* @return array|null
191191
*/
192192
public function getFields() {
193193
// Fetch fields when the method is called for the first time.
194194
if ($this->fields === null) {
195195
$fields = [];
196-
$result = $this->api(static::REQUEST_GET, '/rest/api/2/field', [], true);
196+
$result = $this->api(static::REQUEST_GET, '/rest/api/2/field');
197197

198198
/* set hash key as custom field id */
199199
foreach ($result as $field) {
@@ -254,7 +254,7 @@ public function deleteIssue($issueKey, bool $deleteSubtasks = true, array $param
254254
/**
255255
* Gets attachments meta information.
256256
*
257-
* @return array
257+
* @return array|false
258258
*/
259259
public function getAttachmentsMetaInformation() {
260260
return $this->api(static::REQUEST_GET, '/rest/api/2/attachment/meta');
@@ -268,7 +268,7 @@ public function getAttachmentsMetaInformation() {
268268
* @return array|false
269269
*/
270270
public function getAttachment($attachment_id) {
271-
return $this->api(static::REQUEST_GET, sprintf('/rest/api/2/attachment/%s', $attachment_id), [], true);
271+
return $this->api(static::REQUEST_GET, sprintf('/rest/api/2/attachment/%s', $attachment_id));
272272
}
273273

274274
/**
@@ -283,37 +283,37 @@ public function getProjects() {
283283
/**
284284
* Returns one project.
285285
*
286-
* @param string $project_key Project key.
286+
* @param string $projectKey Project ID or key.
287287
*
288288
* @return array|false
289289
*/
290-
public function getProject($project_key) {
291-
return $this->api(static::REQUEST_GET, sprintf('/rest/api/2/project/%s', $project_key), [], true);
290+
public function getProject($projectKey) {
291+
return $this->api(static::REQUEST_GET, sprintf('/rest/api/2/project/%s', $projectKey));
292292
}
293293

294294
/**
295295
* Returns all roles of a project.
296296
*
297-
* @param string $project_key Project key.
297+
* @param string $projectKey Project ID or key.
298298
*
299299
* @return array|false
300300
*/
301-
public function getRoles($project_key) {
302-
return $this->api(static::REQUEST_GET, sprintf('/rest/api/2/project/%s/role', $project_key), [], true);
301+
public function getRoles($projectKey) {
302+
return $this->api(static::REQUEST_GET, sprintf('/rest/api/2/project/%s/role', $projectKey));
303303
}
304304

305305
/**
306306
* Returns role details.
307307
*
308-
* @param string $project_key Project key.
309-
* @param string $role_id Role ID.
308+
* @param string $projectKey Project key.
309+
* @param string $roleId Role ID.
310310
*
311311
* @return array|false
312312
*/
313-
public function getRoleDetails($project_key, $role_id) {
313+
public function getRoleDetails($projectKey, $roleId) {
314314
return $this->api(
315315
static::REQUEST_GET,
316-
sprintf('/rest/api/2/project/%s/role/%s', $project_key, $role_id),
316+
sprintf('/rest/api/2/project/%s/role/%s', $projectKey, $roleId),
317317
[],
318318
true,
319319
);
@@ -322,7 +322,7 @@ public function getRoleDetails($project_key, $role_id) {
322322
/**
323323
* Returns the meta data for creating issues.
324324
* This includes the available projects, issue types
325-
* and fields, including field types and whether or not those fields are required.
325+
* and fields, including field types and whether those fields are required.
326326
* Projects will not be returned if the user does not have permission to create issues in that project.
327327
* Fields will only be returned if "projects.issuetypes.fields" is added as expand parameter.
328328
*
@@ -472,7 +472,7 @@ public function transition($issueKey, array $params = []) {
472472
*/
473473
public function getIssueTypes() {
474474
$result = [];
475-
$types = $this->api(static::REQUEST_GET, '/rest/api/2/issuetype', [], true);
475+
$types = $this->api(static::REQUEST_GET, '/rest/api/2/issuetype');
476476

477477
foreach ($types as $type) {
478478
$result[] = new IssueType($type);
@@ -489,7 +489,7 @@ public function getIssueTypes() {
489489
* @return array|false
490490
*/
491491
public function getVersions($project_key) {
492-
return $this->api(static::REQUEST_GET, sprintf('/rest/api/2/project/%s/versions', $project_key), [], true);
492+
return $this->api(static::REQUEST_GET, sprintf('/rest/api/2/project/%s/versions', $project_key));
493493
}
494494

495495
/**
@@ -521,13 +521,13 @@ public function findVersionByName($project_key, $name) {
521521
/**
522522
* Get available priorities.
523523
*
524-
* @return array
524+
* @return array|false
525525
*/
526526
public function getPriorities() {
527527
// Fetch priorities when the method is called for the first time.
528528
if ($this->priorities === null) {
529529
$priorities = [];
530-
$result = $this->api(static::REQUEST_GET, '/rest/api/2/priority', [], true);
530+
$result = $this->api(static::REQUEST_GET, '/rest/api/2/priority');
531531

532532
/* set hash key as custom field id */
533533
foreach ($result as $priority) {
@@ -549,7 +549,7 @@ public function getStatuses() {
549549
// Fetch statuses when the method is called for the first time.
550550
if ($this->statuses === null) {
551551
$statuses = [];
552-
$result = $this->api(static::REQUEST_GET, '/rest/api/2/status', [], true);
552+
$result = $this->api(static::REQUEST_GET, '/rest/api/2/status');
553553

554554
/* set hash key as custom field id */
555555
foreach ($result as $status) {
@@ -643,7 +643,7 @@ public function createVersion($projectKey, $version, array $options = []) {
643643
* @param int $version_id Version ID.
644644
* @param array $params Key->Value list to update the version with.
645645
*
646-
* @return false
646+
* @return array|false
647647
*/
648648
public function updateVersion($version_id, array $params = []) {
649649
return $this->api(static::REQUEST_PUT, sprintf('/rest/api/2/version/%d', $version_id), $params);
@@ -690,7 +690,7 @@ public function createAttachment($issueKey, $filename, $name = null) {
690690
static::REQUEST_POST,
691691
sprintf('/rest/api/2/issue/%s/attachments', $issueKey),
692692
$options,
693-
false,
693+
true,
694694
true,
695695
);
696696
}
@@ -742,7 +742,7 @@ public function api(
742742
$method,
743743
$url,
744744
$data = [],
745-
$return_as_array = false,
745+
$return_as_array = true,
746746
$is_file = false,
747747
$debug = false
748748
) {
@@ -884,33 +884,33 @@ public function closeIssue($issueKey) {
884884
*
885885
* @param string $project_key Project key.
886886
*
887-
* @return array
887+
* @return array|false
888888
*/
889889
public function getProjectComponents($project_key) {
890-
return $this->api(static::REQUEST_GET, sprintf('/rest/api/2/project/%s/components', $project_key), [], true);
890+
return $this->api(static::REQUEST_GET, sprintf('/rest/api/2/project/%s/components', $project_key));
891891
}
892892

893893
/**
894894
* Get all issue types with valid status values for a project.
895895
*
896896
* @param string $project_key Project key.
897897
*
898-
* @return array
898+
* @return array|false
899899
*/
900900
public function getProjectIssueTypes($project_key) {
901-
return $this->api(static::REQUEST_GET, sprintf('/rest/api/2/project/%s/statuses', $project_key), [], true);
901+
return $this->api(static::REQUEST_GET, sprintf('/rest/api/2/project/%s/statuses', $project_key));
902902
}
903903

904904
/**
905905
* Returns a list of all resolutions.
906906
*
907-
* @return array
907+
* @return array|false
908908
*/
909909
public function getResolutions() {
910910
// Fetch resolutions when the method is called for the first time.
911911
if ($this->resolutions === null) {
912912
$resolutions = [];
913-
$result = $this->api(static::REQUEST_GET, '/rest/api/2/resolution', [], true);
913+
$result = $this->api(static::REQUEST_GET, '/rest/api/2/resolution');
914914

915915
foreach ($result as $resolution) {
916916
$resolutions[$resolution['id']] = $resolution;

0 commit comments

Comments
 (0)