From 9eff3c5e38f376c830d3d8c50f8160219872fabb Mon Sep 17 00:00:00 2001 From: jld3103 Date: Wed, 25 Jan 2023 15:10:31 +0100 Subject: [PATCH] Add generic templates for DataResponse and JSONResponse Signed-off-by: jld3103 --- lib/public/AppFramework/Http/DataResponse.php | 9 +++++---- lib/public/AppFramework/Http/JSONResponse.php | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/public/AppFramework/Http/DataResponse.php b/lib/public/AppFramework/Http/DataResponse.php index e329b9c297564..561864e8ffaf5 100644 --- a/lib/public/AppFramework/Http/DataResponse.php +++ b/lib/public/AppFramework/Http/DataResponse.php @@ -30,17 +30,18 @@ * A generic DataResponse class that is used to return generic data responses * for responders to transform * @since 8.0.0 + * @template T */ class DataResponse extends Response { /** * response data - * @var array|int|float|string|bool|object + * @var T */ protected $data; /** - * @param array|int|float|string|bool|object $data the object or array that should be transformed + * @param T $data the object or array that should be transformed * @param int $statusCode the Http status code, defaults to 200 * @param array $headers additional key value based headers * @since 8.0.0 @@ -57,7 +58,7 @@ public function __construct($data = [], $statusCode = Http::STATUS_OK, /** * Sets values in the data json array - * @param array|int|float|string|object $data an array or object which will be transformed + * @param T $data an array or object which will be transformed * @return DataResponse Reference to this object * @since 8.0.0 */ @@ -70,7 +71,7 @@ public function setData($data) { /** * Used to get the set parameters - * @return array|int|float|string|bool|object the data + * @return T the data * @since 8.0.0 */ public function getData() { diff --git a/lib/public/AppFramework/Http/JSONResponse.php b/lib/public/AppFramework/Http/JSONResponse.php index d31a276167373..4772df8d091e6 100644 --- a/lib/public/AppFramework/Http/JSONResponse.php +++ b/lib/public/AppFramework/Http/JSONResponse.php @@ -32,18 +32,19 @@ /** * A renderer for JSON calls * @since 6.0.0 + * @template T */ class JSONResponse extends Response { /** * response data - * @var array|object + * @var T */ protected $data; /** * constructor of JSONResponse - * @param array|object $data the object or array that should be transformed + * @param T $data the object or array that should be transformed * @param int $statusCode the Http status code, defaults to 200 * @since 6.0.0 */ @@ -68,7 +69,7 @@ public function render() { /** * Sets values in the data json array - * @param array|object $data an array or object which will be transformed + * @param T $data an array or object which will be transformed * to JSON * @return JSONResponse Reference to this object * @since 6.0.0 - return value was added in 7.0.0 @@ -82,7 +83,7 @@ public function setData($data) { /** * Used to get the set parameters - * @return array the data + * @return T the data * @since 6.0.0 */ public function getData() {