Skip to content

Commit

Permalink
Merge pull request #6 from artyuum/patch-2
Browse files Browse the repository at this point in the history
Fixes #5
  • Loading branch information
Junker authored Feb 16, 2021
2 parents e35ab4a + e07df1a commit 08be64b
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/JsendResponse/JSendResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,8 @@ public function __construct(string $status, $data = null, string $message = null

$jsend['status'] = $status;

// the "data" key is required for this status
if ($status === self::STATUS_SUCCESS) {
$jsend['data'] = $data;
}

// the "data" key is optional for these statuses so we only add it if set
if (isset($data) && ($status === self::STATUS_FAIL || $status === self::STATUS_ERROR)) {
// the "data" key is required for these statuses
if ($status === self::STATUS_SUCCESS || $status === self::STATUS_FAIL) {
$jsend['data'] = $data;
}

Expand All @@ -68,6 +63,11 @@ public function __construct(string $status, $data = null, string $message = null
throw new JSendSpecificationViolation('The "message" key is required');
}

// the "data" key is optional for this status so we only add it if set
if (isset($data)) {
$jsend['data'] = $data;
}

$jsend['message'] = $message;

// adds the "code" key only if it's set (because it's optional)
Expand Down

0 comments on commit 08be64b

Please sign in to comment.