From e07df1ace5d7e046b87a6212cd5ce1d0457f7bb7 Mon Sep 17 00:00:00 2001 From: Artyum Petrov Date: Sun, 24 Jan 2021 20:32:07 +0400 Subject: [PATCH] Fixes #5 --- src/JsendResponse/JSendResponse.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/JsendResponse/JSendResponse.php b/src/JsendResponse/JSendResponse.php index 42b4461..8c73d6b 100644 --- a/src/JsendResponse/JSendResponse.php +++ b/src/JsendResponse/JSendResponse.php @@ -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; } @@ -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)