From 68fd8be4d0313b401a9de9c63a3f2e91248d6515 Mon Sep 17 00:00:00 2001 From: Michiel Vugteveen Date: Mon, 23 Dec 2024 14:26:35 +0100 Subject: [PATCH 1/2] fix php 8.4 Deprecated warnings --- src/Contracts/ErrorFactory.php | 2 +- src/Contracts/ErrorSerializer.php | 2 +- src/Contracts/Resources/ResourceFactory.php | 2 +- src/Contracts/Responder.php | 4 ++-- src/Contracts/SimpleTransformer.php | 2 +- src/ErrorFactory.php | 2 +- src/Exceptions/Http/HttpException.php | 2 +- src/Http/MakesResponses.php | 4 ++-- src/Http/Responses/ErrorResponseBuilder.php | 4 ++-- src/Http/Responses/ResponseBuilder.php | 2 +- src/Http/Responses/SuccessResponseBuilder.php | 2 +- src/Resources/ResourceFactory.php | 8 ++++---- src/Responder.php | 4 ++-- src/Serializers/ErrorSerializer.php | 2 +- src/Testing/MakesApiRequests.php | 6 +++--- src/TransformBuilder.php | 2 +- src/Transformation.php | 2 +- src/Transformers/Concerns/MakesResources.php | 2 +- tests/TestCase.php | 2 +- 19 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/Contracts/ErrorFactory.php b/src/Contracts/ErrorFactory.php index fce9c88..10b580c 100644 --- a/src/Contracts/ErrorFactory.php +++ b/src/Contracts/ErrorFactory.php @@ -20,5 +20,5 @@ interface ErrorFactory * @param array|null $data * @return array */ - public function make(ErrorSerializer $serializer, $errorCode = null, string $message = null, array $data = null): array; + public function make(ErrorSerializer $serializer, $errorCode = null, ?string $message = null, ?array $data = null): array; } \ No newline at end of file diff --git a/src/Contracts/ErrorSerializer.php b/src/Contracts/ErrorSerializer.php index faaaec5..247a0d5 100644 --- a/src/Contracts/ErrorSerializer.php +++ b/src/Contracts/ErrorSerializer.php @@ -19,5 +19,5 @@ interface ErrorSerializer * @param array|null $data * @return array */ - public function format($errorCode = null, string $message = null, array $data = null): array; + public function format($errorCode = null, ?string $message = null, ?array $data = null): array; } \ No newline at end of file diff --git a/src/Contracts/Resources/ResourceFactory.php b/src/Contracts/Resources/ResourceFactory.php index 358505b..6b7ebf8 100644 --- a/src/Contracts/Resources/ResourceFactory.php +++ b/src/Contracts/Resources/ResourceFactory.php @@ -21,5 +21,5 @@ interface ResourceFactory * @param string|null $resourceKey * @return \League\Fractal\Resource\ResourceInterface */ - public function make($data = null, $transformer = null, string $resourceKey = null): ResourceInterface; + public function make($data = null, $transformer = null, ?string $resourceKey = null): ResourceInterface; } \ No newline at end of file diff --git a/src/Contracts/Responder.php b/src/Contracts/Responder.php index aa8d48d..5887eda 100644 --- a/src/Contracts/Responder.php +++ b/src/Contracts/Responder.php @@ -22,7 +22,7 @@ interface Responder * @param string|null $resourceKey * @return \Flugg\Responder\Http\Responses\SuccessResponseBuilder */ - public function success($data = null, $transformer = null, string $resourceKey = null): SuccessResponseBuilder; + public function success($data = null, $transformer = null, ?string $resourceKey = null): SuccessResponseBuilder; /** * Build an error response. @@ -31,5 +31,5 @@ public function success($data = null, $transformer = null, string $resourceKey = * @param string|null $message * @return \Flugg\Responder\Http\Responses\ErrorResponseBuilder */ - public function error($errorCode = null, string $message = null): ErrorResponseBuilder; + public function error($errorCode = null, ?string $message = null): ErrorResponseBuilder; } \ No newline at end of file diff --git a/src/Contracts/SimpleTransformer.php b/src/Contracts/SimpleTransformer.php index 43bb31b..8ce9584 100644 --- a/src/Contracts/SimpleTransformer.php +++ b/src/Contracts/SimpleTransformer.php @@ -21,5 +21,5 @@ interface SimpleTransformer * @param string|null $resourceKey * @return \Flugg\Responder\TransformBuilder */ - public function make($data = null, $transformer = null, string $resourceKey = null): TransformBuilder; + public function make($data = null, $transformer = null, ?string $resourceKey = null): TransformBuilder; } \ No newline at end of file diff --git a/src/ErrorFactory.php b/src/ErrorFactory.php index 97ca8d1..d145428 100644 --- a/src/ErrorFactory.php +++ b/src/ErrorFactory.php @@ -41,7 +41,7 @@ public function __construct(ErrorMessageResolverContract $messageResolver) * @param array|null $data * @return array */ - public function make(ErrorSerializer $serializer, $errorCode = null, string $message = null, array $data = null): array + public function make(ErrorSerializer $serializer, $errorCode = null, ?string $message = null, ?array $data = null): array { if (isset($errorCode) && ! isset($message)) { $message = $this->messageResolver->resolve($errorCode); diff --git a/src/Exceptions/Http/HttpException.php b/src/Exceptions/Http/HttpException.php index 876a7d2..cdab6a7 100644 --- a/src/Exceptions/Http/HttpException.php +++ b/src/Exceptions/Http/HttpException.php @@ -54,7 +54,7 @@ abstract class HttpException extends BaseHttpException * @param string|null $message * @param array|null $headers */ - public function __construct(string $message = null, array $headers = null) + public function __construct(?string $message = null, ?array $headers = null) { parent::__construct($this->status, $message ?? $this->message, null, $headers ?? $this->headers); } diff --git a/src/Http/MakesResponses.php b/src/Http/MakesResponses.php index 5574810..3b1888d 100644 --- a/src/Http/MakesResponses.php +++ b/src/Http/MakesResponses.php @@ -23,7 +23,7 @@ trait MakesResponses * @param string|null $resourceKey * @return \Flugg\Responder\Http\Responses\SuccessResponseBuilder */ - public function success($data = null, $transformer = null, string $resourceKey = null): SuccessResponseBuilder + public function success($data = null, $transformer = null, ?string $resourceKey = null): SuccessResponseBuilder { return app(Responder::class)->success(...func_get_args()); } @@ -35,7 +35,7 @@ public function success($data = null, $transformer = null, string $resourceKey = * @param string|null $message * @return \Flugg\Responder\Http\Responses\ErrorResponseBuilder */ - public function error($errorCode = null, string $message = null): ErrorResponseBuilder + public function error($errorCode = null, ?string $message = null): ErrorResponseBuilder { return app(Responder::class)->error(...func_get_args()); } diff --git a/src/Http/Responses/ErrorResponseBuilder.php b/src/Http/Responses/ErrorResponseBuilder.php index ab6e10d..8ac1b71 100644 --- a/src/Http/Responses/ErrorResponseBuilder.php +++ b/src/Http/Responses/ErrorResponseBuilder.php @@ -79,7 +79,7 @@ public function __construct(ResponseFactory $responseFactory, ErrorFactory $erro * @param string|null $message * @return $this */ - public function error($errorCode = null, string $message = null) + public function error($errorCode = null, ?string $message = null) { $this->errorCode = $errorCode; $this->message = $message; @@ -93,7 +93,7 @@ public function error($errorCode = null, string $message = null) * @param array|null $data * @return $this */ - public function data(array $data = null) + public function data(?array $data = null) { $this->data = array_merge((array) $this->data, (array) $data); diff --git a/src/Http/Responses/ResponseBuilder.php b/src/Http/Responses/ResponseBuilder.php index 71971c6..4e0c777 100644 --- a/src/Http/Responses/ResponseBuilder.php +++ b/src/Http/Responses/ResponseBuilder.php @@ -65,7 +65,7 @@ public function decorator($decorator) * @param array $headers * @return \Illuminate\Http\JsonResponse */ - public function respond(int $status = null, array $headers = []): JsonResponse + public function respond(?int $status = null, array $headers = []): JsonResponse { if (! is_null($status)) { $this->setStatusCode($status); diff --git a/src/Http/Responses/SuccessResponseBuilder.php b/src/Http/Responses/SuccessResponseBuilder.php index 040ace5..21f6f1d 100644 --- a/src/Http/Responses/SuccessResponseBuilder.php +++ b/src/Http/Responses/SuccessResponseBuilder.php @@ -61,7 +61,7 @@ public function __construct(ResponseFactory $responseFactory, TransformBuilder $ * @param string|null $resourceKey * @return self */ - public function transform($data = null, $transformer = null, string $resourceKey = null): SuccessResponseBuilder + public function transform($data = null, $transformer = null, ?string $resourceKey = null): SuccessResponseBuilder { $this->transformBuilder->resource($data, $transformer, $resourceKey); diff --git a/src/Resources/ResourceFactory.php b/src/Resources/ResourceFactory.php index df1e54f..7aa25d9 100644 --- a/src/Resources/ResourceFactory.php +++ b/src/Resources/ResourceFactory.php @@ -65,7 +65,7 @@ public function __construct(DataNormalizer $normalizer, TransformerResolver $tra * @param string|null $resourceKey * @return \League\Fractal\Resource\ResourceInterface */ - public function make($data = null, $transformer = null, string $resourceKey = null): ResourceInterface + public function make($data = null, $transformer = null, ?string $resourceKey = null): ResourceInterface { if ($data instanceof ResourceInterface) { return $this->makeFromResource($data, $transformer, $resourceKey); @@ -87,7 +87,7 @@ public function make($data = null, $transformer = null, string $resourceKey = nu * @param string|null $resourceKey * @return \League\Fractal\Resource\ResourceInterface */ - public function makeFromResource(ResourceInterface $resource, $transformer = null, string $resourceKey = null): ResourceInterface + public function makeFromResource(ResourceInterface $resource, $transformer = null, ?string $resourceKey = null): ResourceInterface { $transformer = $this->resolveTransformer($resource->getData(), $transformer ?: $resource->getTransformer()); $resourceKey = $this->resolveResourceKey($resource->getData(), $resourceKey ?: $resource->getResourceKey()); @@ -103,7 +103,7 @@ public function makeFromResource(ResourceInterface $resource, $transformer = nul * @param string|null $resourceKey * @return \League\Fractal\Resource\ResourceInterface */ - protected function instatiateResource($data, $transformer = null, string $resourceKey = null): ResourceInterface + protected function instatiateResource($data, $transformer = null, ?string $resourceKey = null): ResourceInterface { if (is_null($data)) { return new NullResource(null, null, $resourceKey); @@ -154,7 +154,7 @@ protected function resolveTransformer($data, $transformer) * @param string|null $resourceKey * @return null|string */ - protected function resolveResourceKey($data, string $resourceKey = null) + protected function resolveResourceKey($data, ?string $resourceKey = null) { return ! empty($resourceKey) ? $resourceKey : $this->resourceKeyResolver->resolve($data); } diff --git a/src/Responder.php b/src/Responder.php index 750a950..4f8ac50 100644 --- a/src/Responder.php +++ b/src/Responder.php @@ -49,7 +49,7 @@ public function __construct(SuccessResponseBuilder $successResponseBuilder, Erro * @param string|null $resourceKey * @return \Flugg\Responder\Http\Responses\SuccessResponseBuilder */ - public function success($data = null, $transformer = null, string $resourceKey = null): SuccessResponseBuilder + public function success($data = null, $transformer = null, ?string $resourceKey = null): SuccessResponseBuilder { return $this->successResponseBuilder->transform($data, $transformer, $resourceKey); } @@ -61,7 +61,7 @@ public function success($data = null, $transformer = null, string $resourceKey = * @param string|null $message * @return \Flugg\Responder\Http\Responses\ErrorResponseBuilder */ - public function error($errorCode = null, string $message = null): ErrorResponseBuilder + public function error($errorCode = null, ?string $message = null): ErrorResponseBuilder { return $this->errorResponseBuilder->error($errorCode, $message); } diff --git a/src/Serializers/ErrorSerializer.php b/src/Serializers/ErrorSerializer.php index 1550898..d99e87e 100644 --- a/src/Serializers/ErrorSerializer.php +++ b/src/Serializers/ErrorSerializer.php @@ -21,7 +21,7 @@ class ErrorSerializer implements ErrorSerializerContract * @param array|null $data * @return array */ - public function format($errorCode = null, string $message = null, array $data = null): array + public function format($errorCode = null, ?string $message = null, ?array $data = null): array { $response = [ 'error' => [ diff --git a/src/Testing/MakesApiRequests.php b/src/Testing/MakesApiRequests.php index d1fe6c8..b44f8b1 100644 --- a/src/Testing/MakesApiRequests.php +++ b/src/Testing/MakesApiRequests.php @@ -129,7 +129,7 @@ protected function getSuccessData($attributes = null) * @param int|null $status * @return $this */ - protected function seeError(string $error, int $status = null) + protected function seeError(string $error, ?int $status = null) { if (! is_null($status)) { $this->seeStatusCode($status); @@ -165,7 +165,7 @@ abstract protected function seeStatusCode($status); * @param bool $negate * @return $this */ - abstract public function seeJson(array $data = null, $negate = false); + abstract public function seeJson(?array $data = null, $negate = false); /** * Assert that the JSON response has a given structure. @@ -174,7 +174,7 @@ abstract public function seeJson(array $data = null, $negate = false); * @param array|null $responseData * @return $this */ - abstract public function seeJsonStructure(array $structure = null, $responseData = null); + abstract public function seeJsonStructure(?array $structure = null, $responseData = null); /** * Assert that the response is a superset of the given JSON. diff --git a/src/TransformBuilder.php b/src/TransformBuilder.php index 60fc772..ca71873 100644 --- a/src/TransformBuilder.php +++ b/src/TransformBuilder.php @@ -105,7 +105,7 @@ public function __construct(ResourceFactory $resourceFactory, TransformFactory $ * @param string|null $resourceKey * @return $this */ - public function resource($data = null, $transformer = null, string $resourceKey = null) + public function resource($data = null, $transformer = null, ?string $resourceKey = null) { $this->resource = $this->resourceFactory->make($data, $transformer, $resourceKey); diff --git a/src/Transformation.php b/src/Transformation.php index 78f1229..60966e1 100644 --- a/src/Transformation.php +++ b/src/Transformation.php @@ -38,7 +38,7 @@ public function __construct(TransformBuilder $transformBuilder) * @param string|null $resourceKey * @return \Flugg\Responder\TransformBuilder */ - public function make($data = null, $transformer = null, string $resourceKey = null): TransformBuilder + public function make($data = null, $transformer = null, ?string $resourceKey = null): TransformBuilder { return $this->transformBuilder->resource($data, $transformer, $resourceKey)->serializer(new NoopSerializer); } diff --git a/src/Transformers/Concerns/MakesResources.php b/src/Transformers/Concerns/MakesResources.php index 36a0f7d..c227bfe 100644 --- a/src/Transformers/Concerns/MakesResources.php +++ b/src/Transformers/Concerns/MakesResources.php @@ -34,7 +34,7 @@ trait MakesResources * @param string|null $resourceKey * @return \League\Fractal\Resource\ResourceInterface */ - protected function resource($data = null, $transformer = null, string $resourceKey = null): ResourceInterface + protected function resource($data = null, $transformer = null, ?string $resourceKey = null): ResourceInterface { if ($data instanceof ResourceInterface) { return $data; diff --git a/tests/TestCase.php b/tests/TestCase.php index eb7d03b..028ee82 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -266,7 +266,7 @@ protected function mockFractalManager(): MockInterface * @param string|null $className * @return \Mockery\MockInterface */ - protected function mockResource(string $className = null): MockInterface + protected function mockResource(?string $className = null): MockInterface { $resource = Mockery::mock($className ?: Collection::class); From e3c0ebabe5a727f1b49825c89d16b81a746973bd Mon Sep 17 00:00:00 2001 From: Michiel Vugteveen Date: Sat, 4 Jan 2025 17:30:27 +0100 Subject: [PATCH 2/2] fix styling --- src/Contracts/ErrorFactory.php | 11 ++-- src/Contracts/ErrorSerializer.php | 5 +- src/Contracts/Resources/ResourceFactory.php | 9 ++-- src/Contracts/Responder.php | 11 ++-- src/Contracts/SimpleTransformer.php | 9 ++-- src/ErrorFactory.php | 13 +++-- src/Exceptions/Http/HttpException.php | 7 ++- src/Http/MakesResponses.php | 11 ++-- src/Http/Responses/ErrorResponseBuilder.php | 15 +++--- src/Http/Responses/ResponseBuilder.php | 17 +++---- src/Http/Responses/SuccessResponseBuilder.php | 16 +++--- src/Resources/ResourceFactory.php | 37 +++++++------- src/Responder.php | 15 +++--- src/Serializers/ErrorSerializer.php | 3 +- src/Testing/MakesApiRequests.php | 37 +++++++------- src/TransformBuilder.php | 51 ++++++++++--------- src/Transformation.php | 11 ++-- src/Transformers/Concerns/MakesResources.php | 38 +++++++------- tests/TestCase.php | 14 +++-- 19 files changed, 158 insertions(+), 172 deletions(-) diff --git a/src/Contracts/ErrorFactory.php b/src/Contracts/ErrorFactory.php index 10b580c..067134a 100644 --- a/src/Contracts/ErrorFactory.php +++ b/src/Contracts/ErrorFactory.php @@ -5,7 +5,6 @@ /** * A contract for creating errors. * - * @package flugger/laravel-responder * @author Alexander Tømmerås * @license The MIT License */ @@ -14,11 +13,11 @@ interface ErrorFactory /** * Make an error array from the given error code, message and error data. * - * @param \Flugg\Responder\Contracts\ErrorSerializer $serializer - * @param mixed|null $errorCode - * @param string|null $message - * @param array|null $data + * @param \Flugg\Responder\Contracts\ErrorSerializer $serializer + * @param mixed|null $errorCode + * @param string|null $message + * @param array|null $data * @return array */ public function make(ErrorSerializer $serializer, $errorCode = null, ?string $message = null, ?array $data = null): array; -} \ No newline at end of file +} diff --git a/src/Contracts/ErrorSerializer.php b/src/Contracts/ErrorSerializer.php index 247a0d5..60e39c6 100644 --- a/src/Contracts/ErrorSerializer.php +++ b/src/Contracts/ErrorSerializer.php @@ -5,7 +5,6 @@ /** * A contract for formatting error arrays. * - * @package flugger/laravel-responder * @author Alexander Tømmerås * @license The MIT License */ @@ -15,9 +14,9 @@ interface ErrorSerializer * Format the error data. * * @param mixed|null $errorCode - * @param string|null $message + * @param string|null $message * @param array|null $data * @return array */ public function format($errorCode = null, ?string $message = null, ?array $data = null): array; -} \ No newline at end of file +} diff --git a/src/Contracts/Resources/ResourceFactory.php b/src/Contracts/Resources/ResourceFactory.php index 6b7ebf8..56ab9fb 100644 --- a/src/Contracts/Resources/ResourceFactory.php +++ b/src/Contracts/Resources/ResourceFactory.php @@ -7,7 +7,6 @@ /** * A contract for creating resources. * - * @package flugger/laravel-responder * @author Alexander Tømmerås * @license The MIT License */ @@ -16,10 +15,10 @@ interface ResourceFactory /** * Make resource from the given data. * - * @param mixed $data - * @param \Flugg\Responder\Transformers\Transformer|string|callable|null $transformer - * @param string|null $resourceKey + * @param mixed $data + * @param \Flugg\Responder\Transformers\Transformer|string|callable|null $transformer + * @param string|null $resourceKey * @return \League\Fractal\Resource\ResourceInterface */ public function make($data = null, $transformer = null, ?string $resourceKey = null): ResourceInterface; -} \ No newline at end of file +} diff --git a/src/Contracts/Responder.php b/src/Contracts/Responder.php index 5887eda..7def4a7 100644 --- a/src/Contracts/Responder.php +++ b/src/Contracts/Responder.php @@ -8,7 +8,6 @@ /** * A contract for responding with error- and success responses. * - * @package flugger/laravel-responder * @author Alexander Tømmerås * @license The MIT License */ @@ -17,9 +16,9 @@ interface Responder /** * Build a successful response. * - * @param mixed $data - * @param callable|string|\Flugg\Responder\Transformers\Transformer|null $transformer - * @param string|null $resourceKey + * @param mixed $data + * @param callable|string|\Flugg\Responder\Transformers\Transformer|null $transformer + * @param string|null $resourceKey * @return \Flugg\Responder\Http\Responses\SuccessResponseBuilder */ public function success($data = null, $transformer = null, ?string $resourceKey = null): SuccessResponseBuilder; @@ -28,8 +27,8 @@ public function success($data = null, $transformer = null, ?string $resourceKey * Build an error response. * * @param mixed|null $errorCode - * @param string|null $message + * @param string|null $message * @return \Flugg\Responder\Http\Responses\ErrorResponseBuilder */ public function error($errorCode = null, ?string $message = null): ErrorResponseBuilder; -} \ No newline at end of file +} diff --git a/src/Contracts/SimpleTransformer.php b/src/Contracts/SimpleTransformer.php index 8ce9584..ca8cdc8 100644 --- a/src/Contracts/SimpleTransformer.php +++ b/src/Contracts/SimpleTransformer.php @@ -7,7 +7,6 @@ /** * A contract for transforming data, without the serializing. * - * @package flugger/laravel-responder * @author Alexander Tømmerås * @license The MIT License */ @@ -16,10 +15,10 @@ interface SimpleTransformer /** * Transform the data without serializing, using the given transformer. * - * @param mixed $data - * @param \Flugg\Responder\Transformers\Transformer|callable|string|null $transformer - * @param string|null $resourceKey + * @param mixed $data + * @param \Flugg\Responder\Transformers\Transformer|callable|string|null $transformer + * @param string|null $resourceKey * @return \Flugg\Responder\TransformBuilder */ public function make($data = null, $transformer = null, ?string $resourceKey = null): TransformBuilder; -} \ No newline at end of file +} diff --git a/src/ErrorFactory.php b/src/ErrorFactory.php index d145428..65b0266 100644 --- a/src/ErrorFactory.php +++ b/src/ErrorFactory.php @@ -9,7 +9,6 @@ /** * A factory class responsible for creating error arrays. * - * @package flugger/laravel-responder * @author Alexander Tømmerås * @license The MIT License */ @@ -25,7 +24,7 @@ class ErrorFactory implements ErrorFactoryContract /** * Construct the factory class. * - * @param \Flugg\Responder\Contracts\ErrorMessageResolver $messageResolver + * @param \Flugg\Responder\Contracts\ErrorMessageResolver $messageResolver */ public function __construct(ErrorMessageResolverContract $messageResolver) { @@ -35,10 +34,10 @@ public function __construct(ErrorMessageResolverContract $messageResolver) /** * Make an error array from the given error code and message. * - * @param \Flugg\Responder\Contracts\ErrorSerializer $serializer - * @param mixed|null $errorCode - * @param string|null $message - * @param array|null $data + * @param \Flugg\Responder\Contracts\ErrorSerializer $serializer + * @param mixed|null $errorCode + * @param string|null $message + * @param array|null $data * @return array */ public function make(ErrorSerializer $serializer, $errorCode = null, ?string $message = null, ?array $data = null): array @@ -49,4 +48,4 @@ public function make(ErrorSerializer $serializer, $errorCode = null, ?string $me return $serializer->format($errorCode, $message, $data); } -} \ No newline at end of file +} diff --git a/src/Exceptions/Http/HttpException.php b/src/Exceptions/Http/HttpException.php index cdab6a7..d48e0cc 100644 --- a/src/Exceptions/Http/HttpException.php +++ b/src/Exceptions/Http/HttpException.php @@ -7,7 +7,6 @@ /** * An abstract exception responsible for holding error response data. * - * @package flugger/laravel-responder * @author Alexander Tømmerås * @license The MIT License */ @@ -51,8 +50,8 @@ abstract class HttpException extends BaseHttpException /** * Construct the exception class. * - * @param string|null $message - * @param array|null $headers + * @param string|null $message + * @param array|null $headers */ public function __construct(?string $message = null, ?array $headers = null) { @@ -60,7 +59,7 @@ public function __construct(?string $message = null, ?array $headers = null) } /** - * Retrieve the HTTP status code, + * Retrieve the HTTP status code,. * * @return int */ diff --git a/src/Http/MakesResponses.php b/src/Http/MakesResponses.php index 3b1888d..0921561 100644 --- a/src/Http/MakesResponses.php +++ b/src/Http/MakesResponses.php @@ -9,7 +9,6 @@ /** * A trait to be used by controllers to easily make success- and error responses. * - * @package flugger/laravel-responder * @author Alexander Tømmerås * @license The MIT License */ @@ -18,9 +17,9 @@ trait MakesResponses /** * Build a successful response. * - * @param mixed $data - * @param callable|string|\Flugg\Responder\Transformers\Transformer|null $transformer - * @param string|null $resourceKey + * @param mixed $data + * @param callable|string|\Flugg\Responder\Transformers\Transformer|null $transformer + * @param string|null $resourceKey * @return \Flugg\Responder\Http\Responses\SuccessResponseBuilder */ public function success($data = null, $transformer = null, ?string $resourceKey = null): SuccessResponseBuilder @@ -32,11 +31,11 @@ public function success($data = null, $transformer = null, ?string $resourceKey * Build an error response. * * @param mixed|null $errorCode - * @param string|null $message + * @param string|null $message * @return \Flugg\Responder\Http\Responses\ErrorResponseBuilder */ public function error($errorCode = null, ?string $message = null): ErrorResponseBuilder { return app(Responder::class)->error(...func_get_args()); } -} \ No newline at end of file +} diff --git a/src/Http/Responses/ErrorResponseBuilder.php b/src/Http/Responses/ErrorResponseBuilder.php index 8ac1b71..d255558 100644 --- a/src/Http/Responses/ErrorResponseBuilder.php +++ b/src/Http/Responses/ErrorResponseBuilder.php @@ -11,7 +11,6 @@ /** * A builder class for building error responses. * - * @package flugger/laravel-responder * @author Alexander Tømmerås * @license The MIT License */ @@ -62,8 +61,8 @@ class ErrorResponseBuilder extends ResponseBuilder /** * Construct the builder class. * - * @param \Flugg\Responder\Contracts\ResponseFactory $responseFactory - * @param \Flugg\Responder\Contracts\ErrorFactory $errorFactory + * @param \Flugg\Responder\Contracts\ResponseFactory $responseFactory + * @param \Flugg\Responder\Contracts\ErrorFactory $errorFactory */ public function __construct(ResponseFactory $responseFactory, ErrorFactory $errorFactory) { @@ -76,7 +75,7 @@ public function __construct(ResponseFactory $responseFactory, ErrorFactory $erro * Set the error code and message. * * @param mixed|null $errorCode - * @param string|null $message + * @param string|null $message * @return $this */ public function error($errorCode = null, ?string $message = null) @@ -90,7 +89,7 @@ public function error($errorCode = null, ?string $message = null) /** * Add additional data to the error. * - * @param array|null $data + * @param array|null $data * @return $this */ public function data(?array $data = null) @@ -103,8 +102,9 @@ public function data(?array $data = null) /** * Set the error serializer. * - * @param \Flugg\Responder\Contracts\ErrorSerializer|string $serializer + * @param \Flugg\Responder\Contracts\ErrorSerializer|string $serializer * @return $this + * * @throws \Flugg\Responder\Exceptions\InvalidErrorSerializerException */ public function serializer($serializer) @@ -135,8 +135,9 @@ protected function getOutput(): array /** * Validate the HTTP status code for the response. * - * @param int $status + * @param int $status * @return void + * * @throws \InvalidArgumentException */ protected function validateStatusCode(int $status) diff --git a/src/Http/Responses/ResponseBuilder.php b/src/Http/Responses/ResponseBuilder.php index 4e0c777..09746d3 100644 --- a/src/Http/Responses/ResponseBuilder.php +++ b/src/Http/Responses/ResponseBuilder.php @@ -11,7 +11,6 @@ /** * An abstract builder class for building responses. * - * @package flugger/laravel-responder * @author Alexander Tømmerås * @license The MIT License */ @@ -34,7 +33,7 @@ abstract class ResponseBuilder implements Arrayable, Jsonable /** * Construct the builder class. * - * @param \Flugg\Responder\Contracts\ResponseFactory $responseFactory + * @param \Flugg\Responder\Contracts\ResponseFactory $responseFactory */ public function __construct(ResponseFactory $responseFactory) { @@ -44,7 +43,7 @@ public function __construct(ResponseFactory $responseFactory) /** * Decorate the response with the given decorator. * - * @param string[]|string $decorator + * @param string[]|string $decorator * @return $this */ public function decorator($decorator) @@ -53,7 +52,7 @@ public function decorator($decorator) foreach ($decorators as $decorator) { $this->responseFactory = new $decorator($this->responseFactory); - }; + } return $this; } @@ -61,8 +60,8 @@ public function decorator($decorator) /** * Respond with an HTTP response. * - * @param int|null $status - * @param array $headers + * @param int|null $status + * @param array $headers * @return \Illuminate\Http\JsonResponse */ public function respond(?int $status = null, array $headers = []): JsonResponse @@ -97,7 +96,7 @@ public function toCollection(): Collection /** * Convert the response to JSON. * - * @param int $options + * @param int $options * @return string */ public function toJson($options = 0): string @@ -108,7 +107,7 @@ public function toJson($options = 0): string /** * Set the HTTP status code for the response. * - * @param int $status + * @param int $status * @return void */ protected function setStatusCode(int $status) @@ -126,7 +125,7 @@ abstract protected function getOutput(): array; /** * Convert the response to an array. * - * @param int $status + * @param int $status * @return void */ abstract protected function validateStatusCode(int $status); diff --git a/src/Http/Responses/SuccessResponseBuilder.php b/src/Http/Responses/SuccessResponseBuilder.php index 21f6f1d..93747b8 100644 --- a/src/Http/Responses/SuccessResponseBuilder.php +++ b/src/Http/Responses/SuccessResponseBuilder.php @@ -13,7 +13,6 @@ /** * A builder class for building success responses. * - * @package flugger/laravel-responder * @author Alexander Tømmerås * @license The MIT License * @@ -43,8 +42,8 @@ class SuccessResponseBuilder extends ResponseBuilder /** * Construct the builder class. * - * @param \Flugg\Responder\Contracts\ResponseFactory $responseFactory - * @param \Flugg\Responder\TransformBuilder $transformBuilder + * @param \Flugg\Responder\Contracts\ResponseFactory $responseFactory + * @param \Flugg\Responder\TransformBuilder $transformBuilder */ public function __construct(ResponseFactory $responseFactory, TransformBuilder $transformBuilder) { @@ -56,9 +55,9 @@ public function __construct(ResponseFactory $responseFactory, TransformBuilder $ /** * Set resource data for the transformation. * - * @param mixed $data - * @param \Flugg\Responder\Transformers\Transformer|callable|string|null $transformer - * @param string|null $resourceKey + * @param mixed $data + * @param \Flugg\Responder\Transformers\Transformer|callable|string|null $transformer + * @param string|null $resourceKey * @return self */ public function transform($data = null, $transformer = null, ?string $resourceKey = null): SuccessResponseBuilder @@ -71,7 +70,7 @@ public function transform($data = null, $transformer = null, ?string $resourceKe /** * Dynamically send calls to the transform builder. * - * @param string $name + * @param string $name * @param array $arguments * @return self|void */ @@ -99,8 +98,9 @@ protected function getOutput(): array /** * Validate the HTTP status code for the response. * - * @param int $status + * @param int $status * @return void + * * @throws \InvalidArgumentException */ protected function validateStatusCode(int $status) diff --git a/src/Resources/ResourceFactory.php b/src/Resources/ResourceFactory.php index 7aa25d9..62fae10 100644 --- a/src/Resources/ResourceFactory.php +++ b/src/Resources/ResourceFactory.php @@ -16,7 +16,6 @@ /** * This class is responsible for making Fractal resources from a variety of data types. * - * @package flugger/laravel-responder * @author Alexander Tømmerås * @license The MIT License */ @@ -46,9 +45,9 @@ class ResourceFactory implements ResourceFactoryContract /** * Construct the factory class. * - * @param \Flugg\Responder\Resources\DataNormalizer $normalizer - * @param \Flugg\Responder\Contracts\Transformers\TransformerResolver $transformerResolver - * @param \Flugg\Responder\Contracts\Resources\ResourceKeyResolver $resourceKeyResolver + * @param \Flugg\Responder\Resources\DataNormalizer $normalizer + * @param \Flugg\Responder\Contracts\Transformers\TransformerResolver $transformerResolver + * @param \Flugg\Responder\Contracts\Resources\ResourceKeyResolver $resourceKeyResolver */ public function __construct(DataNormalizer $normalizer, TransformerResolver $transformerResolver, ResourceKeyResolverContract $resourceKeyResolver) { @@ -60,9 +59,9 @@ public function __construct(DataNormalizer $normalizer, TransformerResolver $tra /** * Make resource from the given data. * - * @param mixed $data - * @param \Flugg\Responder\Transformers\Transformer|string|callable|null $transformer - * @param string|null $resourceKey + * @param mixed $data + * @param \Flugg\Responder\Transformers\Transformer|string|callable|null $transformer + * @param string|null $resourceKey * @return \League\Fractal\Resource\ResourceInterface */ public function make($data = null, $transformer = null, ?string $resourceKey = null): ResourceInterface @@ -82,9 +81,9 @@ public function make($data = null, $transformer = null, ?string $resourceKey = n /** * Make resource from the given resource. * - * @param \League\Fractal\Resource\ResourceInterface $resource - * @param \Flugg\Responder\Transformers\Transformer|string|callable|null $transformer - * @param string|null $resourceKey + * @param \League\Fractal\Resource\ResourceInterface $resource + * @param \Flugg\Responder\Transformers\Transformer|string|callable|null $transformer + * @param string|null $resourceKey * @return \League\Fractal\Resource\ResourceInterface */ public function makeFromResource(ResourceInterface $resource, $transformer = null, ?string $resourceKey = null): ResourceInterface @@ -98,9 +97,9 @@ public function makeFromResource(ResourceInterface $resource, $transformer = nul /** * Instatiate a new resource instance. * - * @param mixed $data - * @param \Flugg\Responder\Transformers\Transformer|callable|null $transformer - * @param string|null $resourceKey + * @param mixed $data + * @param \Flugg\Responder\Transformers\Transformer|callable|null $transformer + * @param string|null $resourceKey * @return \League\Fractal\Resource\ResourceInterface */ protected function instatiateResource($data, $transformer = null, ?string $resourceKey = null): ResourceInterface @@ -119,7 +118,7 @@ protected function instatiateResource($data, $transformer = null, ?string $resou /** * Indicates if the data belongs to a collection resource. * - * @param mixed $data + * @param mixed $data * @return bool */ protected function shouldCreateCollection($data): bool @@ -134,8 +133,8 @@ protected function shouldCreateCollection($data): bool /** * Resolve a transformer. * - * @param mixed $data - * @param \Flugg\Responder\Transformers\Transformer|string|callable|null $transformer + * @param mixed $data + * @param \Flugg\Responder\Transformers\Transformer|string|callable|null $transformer * @return \Flugg\Responder\Transformers\Transformer|callable */ protected function resolveTransformer($data, $transformer) @@ -150,12 +149,12 @@ protected function resolveTransformer($data, $transformer) /** * Resolve a resource key. * - * @param mixed $data - * @param string|null $resourceKey + * @param mixed $data + * @param string|null $resourceKey * @return null|string */ protected function resolveResourceKey($data, ?string $resourceKey = null) { return ! empty($resourceKey) ? $resourceKey : $this->resourceKeyResolver->resolve($data); } -} \ No newline at end of file +} diff --git a/src/Responder.php b/src/Responder.php index 4f8ac50..c04b7cd 100644 --- a/src/Responder.php +++ b/src/Responder.php @@ -9,7 +9,6 @@ /** * A service class responsible for building responses. * - * @package flugger/laravel-responder * @author Alexander Tømmerås * @license The MIT License */ @@ -32,8 +31,8 @@ class Responder implements ResponderContract /** * Construct the service class. * - * @param \Flugg\Responder\Http\Responses\SuccessResponseBuilder $successResponseBuilder - * @param \Flugg\Responder\Http\Responses\ErrorResponseBuilder $errorResponseBuilder + * @param \Flugg\Responder\Http\Responses\SuccessResponseBuilder $successResponseBuilder + * @param \Flugg\Responder\Http\Responses\ErrorResponseBuilder $errorResponseBuilder */ public function __construct(SuccessResponseBuilder $successResponseBuilder, ErrorResponseBuilder $errorResponseBuilder) { @@ -44,9 +43,9 @@ public function __construct(SuccessResponseBuilder $successResponseBuilder, Erro /** * Build a successful response. * - * @param mixed $data - * @param callable|string|\Flugg\Responder\Transformers\Transformer|null $transformer - * @param string|null $resourceKey + * @param mixed $data + * @param callable|string|\Flugg\Responder\Transformers\Transformer|null $transformer + * @param string|null $resourceKey * @return \Flugg\Responder\Http\Responses\SuccessResponseBuilder */ public function success($data = null, $transformer = null, ?string $resourceKey = null): SuccessResponseBuilder @@ -58,11 +57,11 @@ public function success($data = null, $transformer = null, ?string $resourceKey * Build an error response. * * @param mixed|null $errorCode - * @param string|null $message + * @param string|null $message * @return \Flugg\Responder\Http\Responses\ErrorResponseBuilder */ public function error($errorCode = null, ?string $message = null): ErrorResponseBuilder { return $this->errorResponseBuilder->error($errorCode, $message); } -} \ No newline at end of file +} diff --git a/src/Serializers/ErrorSerializer.php b/src/Serializers/ErrorSerializer.php index d99e87e..18731a4 100644 --- a/src/Serializers/ErrorSerializer.php +++ b/src/Serializers/ErrorSerializer.php @@ -7,7 +7,6 @@ /** * A serializer class responsible for formatting error data. * - * @package flugger/laravel-responder * @author Alexander Tømmerås * @license The MIT License */ @@ -17,7 +16,7 @@ class ErrorSerializer implements ErrorSerializerContract * Format the error data. * * @param mixed|null $errorCode - * @param string|null $message + * @param string|null $message * @param array|null $data * @return array */ diff --git a/src/Testing/MakesApiRequests.php b/src/Testing/MakesApiRequests.php index b44f8b1..6302ed3 100644 --- a/src/Testing/MakesApiRequests.php +++ b/src/Testing/MakesApiRequests.php @@ -8,7 +8,6 @@ /** * A trait to be used by test case classes to give access to additional assertion methods. * - * @package flugger/laravel-responder * @author Alexander Tømmerås * @license The MIT License */ @@ -17,8 +16,8 @@ trait MakesApiRequests /** * Assert that the response is a valid success response. * - * @param mixed $data - * @param int $status + * @param mixed $data + * @param int $status * @return $this */ protected function seeSuccess($data = null, $status = 200) @@ -32,8 +31,8 @@ protected function seeSuccess($data = null, $status = 200) /** * Assert that the response is a valid success response. * - * @param mixed $data - * @param int $status + * @param mixed $data + * @param int $status * @return $this */ protected function seeSuccessEquals($data = null, $status = 200) @@ -47,7 +46,7 @@ protected function seeSuccessEquals($data = null, $status = 200) /** * Assert that the response data contains the given structure. * - * @param mixed $data + * @param mixed $data * @return $this */ protected function seeSuccessStructure($data = null) @@ -62,8 +61,8 @@ protected function seeSuccessStructure($data = null) /** * Assert that the response is a valid success response. * - * @param mixed $data - * @param int $status + * @param mixed $data + * @param int $status * @return \Illuminate\Http\JsonResponse */ protected function seeSuccessResponse($data = null, $status = 200): JsonResponse @@ -81,7 +80,7 @@ protected function seeSuccessResponse($data = null, $status = 200): JsonResponse /** * Assert that the response data contains given values. * - * @param mixed $data + * @param mixed $data * @return $this */ protected function seeSuccessData($data = null) @@ -100,7 +99,7 @@ protected function seeSuccessData($data = null) /** * Decodes JSON response and returns the data. * - * @param string|array|null $attributes + * @param string|array|null $attributes * @return array */ protected function getSuccessData($attributes = null) @@ -125,8 +124,8 @@ protected function getSuccessData($attributes = null) /** * Assert that the response is a valid error response. * - * @param string $error - * @param int|null $status + * @param string $error + * @param int|null $status * @return $this */ protected function seeError(string $error, ?int $status = null) @@ -153,7 +152,7 @@ protected function seeError(string $error, ?int $status = null) /** * Asserts that the status code of the response matches the given code. * - * @param int $status + * @param int $status * @return $this */ abstract protected function seeStatusCode($status); @@ -161,8 +160,8 @@ abstract protected function seeStatusCode($status); /** * Assert that the response contains JSON. * - * @param array|null $data - * @param bool $negate + * @param array|null $data + * @param bool $negate * @return $this */ abstract public function seeJson(?array $data = null, $negate = false); @@ -170,8 +169,8 @@ abstract public function seeJson(?array $data = null, $negate = false); /** * Assert that the JSON response has a given structure. * - * @param array|null $structure - * @param array|null $responseData + * @param array|null $structure + * @param array|null $responseData * @return $this */ abstract public function seeJsonStructure(?array $structure = null, $responseData = null); @@ -179,7 +178,7 @@ abstract public function seeJsonStructure(?array $structure = null, $responseDat /** * Assert that the response is a superset of the given JSON. * - * @param array $data + * @param array $data * @return $this */ abstract protected function seeJsonSubset(array $data); @@ -187,7 +186,7 @@ abstract protected function seeJsonSubset(array $data); /** * Assert that the response contains an exact JSON array. * - * @param array $data + * @param array $data * @return $this */ abstract public function seeJsonEquals(array $data); diff --git a/src/TransformBuilder.php b/src/TransformBuilder.php index ca71873..bcbfa4e 100644 --- a/src/TransformBuilder.php +++ b/src/TransformBuilder.php @@ -21,7 +21,6 @@ /** * A builder class responsible for building transformed arrays. * - * @package flugger/laravel-responder * @author Alexander Tømmerås * @license The MIT License */ @@ -86,9 +85,9 @@ class TransformBuilder /** * Construct the builder class. * - * @param \Flugg\Responder\Contracts\Resources\ResourceFactory $resourceFactory - * @param \Flugg\Responder\Contracts\TransformFactory $transformFactory - * @param \Flugg\Responder\Contracts\Pagination\PaginatorFactory $paginatorFactory + * @param \Flugg\Responder\Contracts\Resources\ResourceFactory $resourceFactory + * @param \Flugg\Responder\Contracts\TransformFactory $transformFactory + * @param \Flugg\Responder\Contracts\Pagination\PaginatorFactory $paginatorFactory */ public function __construct(ResourceFactory $resourceFactory, TransformFactory $transformFactory, PaginatorFactory $paginatorFactory) { @@ -100,9 +99,9 @@ public function __construct(ResourceFactory $resourceFactory, TransformFactory $ /** * Make a resource from the given data and transformer and set the resource key. * - * @param mixed $data - * @param \Flugg\Responder\Transformers\Transformer|callable|string|null $transformer - * @param string|null $resourceKey + * @param mixed $data + * @param \Flugg\Responder\Transformers\Transformer|callable|string|null $transformer + * @param string|null $resourceKey * @return $this */ public function resource($data = null, $transformer = null, ?string $resourceKey = null) @@ -121,7 +120,7 @@ public function resource($data = null, $transformer = null, ?string $resourceKey /** * Manually set the cursor on the resource. * - * @param \League\Fractal\Pagination\Cursor $cursor + * @param \League\Fractal\Pagination\Cursor $cursor * @return $this */ public function cursor(Cursor $cursor) @@ -136,7 +135,7 @@ public function cursor(Cursor $cursor) /** * Manually set the paginator on the resource. * - * @param \League\Fractal\Pagination\IlluminatePaginatorAdapter $paginator + * @param \League\Fractal\Pagination\IlluminatePaginatorAdapter $paginator * @return $this */ public function paginator(IlluminatePaginatorAdapter $paginator) @@ -151,7 +150,7 @@ public function paginator(IlluminatePaginatorAdapter $paginator) /** * Add meta data appended to the response data. * - * @param array $data + * @param array $data * @return $this */ public function meta(array $data) @@ -164,7 +163,7 @@ public function meta(array $data) /** * Include relations to the transform. * - * @param string[]|string $relations + * @param string[]|string $relations * @return $this */ public function with($relations) @@ -186,7 +185,7 @@ public function with($relations) /** * Exclude relations from the transform. * - * @param string[]|string $relations + * @param string[]|string $relations * @return $this */ public function without($relations) @@ -199,7 +198,7 @@ public function without($relations) /** * Filter fields to output using sparse fieldsets. * - * @param string[]|string $fields + * @param string[]|string $fields * @return $this */ public function only($fields) @@ -212,8 +211,9 @@ public function only($fields) /** * Set the serializer. * - * @param \League\Fractal\Serializer\SerializerAbstract|string $serializer + * @param \League\Fractal\Serializer\SerializerAbstract|string $serializer * @return $this + * * @throws \Flugg\Responder\Exceptions\InvalidSuccessSerializerException */ public function serializer($serializer) @@ -250,8 +250,8 @@ public function transform() /** * Prepare requested relations for the transformation. * - * @param mixed $data - * @param \Flugg\Responder\Transformers\Transformer|callable|string|null $transformer + * @param mixed $data + * @param \Flugg\Responder\Transformers\Transformer|callable|string|null $transformer * @return void */ protected function prepareRelations($data, $transformer) @@ -272,7 +272,7 @@ protected function prepareRelations($data, $transformer) /** * Filter out relations that have been explicitly excluded using the [without] method. * - * @param array $relations + * @param array $relations * @return array */ protected function removeExcludedRelations(array $relations): array @@ -286,7 +286,7 @@ protected function removeExcludedRelations(array $relations): array * Strip parameter suffix from the relation string by only taking what is in front of * the colon. * - * @param string $relation + * @param string $relation * @return string */ protected function stripParametersFromRelation(string $relation): string @@ -299,9 +299,9 @@ protected function stripParametersFromRelation(string $relation): string * in the transformers. We also strip away any parameters from the relation name * and normalize relations by swapping "null" constraints to empty closures. * - * @param mixed $data - * @param array $requested - * @param \Flugg\Responder\Transformers\Transformer|callable|string|null $transformer + * @param mixed $data + * @param array $requested + * @param \Flugg\Responder\Transformers\Transformer|callable|string|null $transformer * @return void */ protected function eagerLoadRelations($data, array $requested, $transformer) @@ -309,17 +309,18 @@ protected function eagerLoadRelations($data, array $requested, $transformer) $relations = collect(array_keys($requested))->reduce(function ($eagerLoads, $relation) use ($requested, $transformer) { $identifier = $this->stripParametersFromRelation($relation); - if(config('responder.use_camel_case_relations')) { + if (config('responder.use_camel_case_relations')) { $identifier = Str::camel($identifier); } - if (method_exists($transformer, 'include' . ucfirst($identifier))) { + if (method_exists($transformer, 'include'.ucfirst($identifier))) { return $eagerLoads; } - return array_merge($eagerLoads, [$identifier => $requested[$relation] ?: function () { }]); + return array_merge($eagerLoads, [$identifier => $requested[$relation] ?: function () { + }]); }, []); $data->loadMissing($relations); } -} \ No newline at end of file +} diff --git a/src/Transformation.php b/src/Transformation.php index 60966e1..77aeb79 100644 --- a/src/Transformation.php +++ b/src/Transformation.php @@ -7,7 +7,6 @@ /** * A class responsible for obtaining a transformation to transform data without serializing. * - * @package flugger/laravel-responder * @author Alexander Tømmerås * @license The MIT License */ @@ -23,7 +22,7 @@ class Transformation /** * Construct the service class. * - * @param \Flugg\Responder\TransformBuilder $transformBuilder + * @param \Flugg\Responder\TransformBuilder $transformBuilder */ public function __construct(TransformBuilder $transformBuilder) { @@ -33,13 +32,13 @@ public function __construct(TransformBuilder $transformBuilder) /** * Make a new transformation to transform data without serializing. * - * @param mixed $data - * @param \Flugg\Responder\Transformers\Transformer|callable|string|null $transformer - * @param string|null $resourceKey + * @param mixed $data + * @param \Flugg\Responder\Transformers\Transformer|callable|string|null $transformer + * @param string|null $resourceKey * @return \Flugg\Responder\TransformBuilder */ public function make($data = null, $transformer = null, ?string $resourceKey = null): TransformBuilder { return $this->transformBuilder->resource($data, $transformer, $resourceKey)->serializer(new NoopSerializer); } -} \ No newline at end of file +} diff --git a/src/Transformers/Concerns/MakesResources.php b/src/Transformers/Concerns/MakesResources.php index c227bfe..8d4d869 100644 --- a/src/Transformers/Concerns/MakesResources.php +++ b/src/Transformers/Concerns/MakesResources.php @@ -13,7 +13,6 @@ /** * A trait to be used by a transformer to make related resources. * - * @package flugger/laravel-responder * @author Alexander Tømmerås * @license The MIT License */ @@ -29,9 +28,9 @@ trait MakesResources /** * Make a resource. * - * @param mixed $data - * @param \Flugg\Responder\Transformers\Transformer|string|callable|null $transformer - * @param string|null $resourceKey + * @param mixed $data + * @param \Flugg\Responder\Transformers\Transformer|string|callable|null $transformer + * @param string|null $resourceKey * @return \League\Fractal\Resource\ResourceInterface */ protected function resource($data = null, $transformer = null, ?string $resourceKey = null): ResourceInterface @@ -48,26 +47,27 @@ protected function resource($data = null, $transformer = null, ?string $resource /** * Include a related resource. * - * @param string $identifier + * @param string $identifier * @param mixed $data * @param array $parameters * @return \League\Fractal\Resource\ResourceInterface + * * @throws \LogicException */ protected function includeResource(string $identifier, $data, array $parameters): ResourceInterface { $transformer = $this->mappedTransformerClass($identifier); - if(config('responder.use_camel_case_relations')) { + if (config('responder.use_camel_case_relations')) { $identifier = Str::camel($identifier); } - if (method_exists($this, $method = 'include' . ucfirst($identifier))) { + if (method_exists($this, $method = 'include'.ucfirst($identifier))) { $resource = $this->resource($this->$method($data, collect($parameters)), $transformer, $identifier); } elseif ($data instanceof Model) { $resource = $this->includeResourceFromModel($data, $identifier, $transformer); } else { - throw new LogicException('Relation [' . $identifier . '] not found in [' . get_class($this) . '].'); + throw new LogicException('Relation ['.$identifier.'] not found in ['.get_class($this).'].'); } return $resource; @@ -76,9 +76,9 @@ protected function includeResource(string $identifier, $data, array $parameters) /** * Include a related resource from a model and cache the resource type for following calls. * - * @param \Illuminate\Database\Eloquent\Model $model - * @param string $identifier - * @param \Flugg\Responder\Transformers\Transformer|string|callable|null $transformer + * @param \Illuminate\Database\Eloquent\Model $model + * @param string $identifier + * @param \Flugg\Responder\Transformers\Transformer|string|callable|null $transformer * @return \League\Fractal\Resource\ResourceInterface */ protected function includeResourceFromModel(Model $model, string $identifier, $transformer = null): ResourceInterface @@ -97,7 +97,7 @@ protected function includeResourceFromModel(Model $model, string $identifier, $t /** * Indicates if the resource should be cached. * - * @param mixed $data + * @param mixed $data * @return bool */ protected function shouldCacheResource($data): bool @@ -110,22 +110,22 @@ protected function shouldCacheResource($data): bool * * @return \Illuminate\Contracts\Container\Container */ - protected abstract function resolveContainer(): Container; + abstract protected function resolveContainer(): Container; /** * Resolve relation data from a model. * - * @param \Illuminate\Database\Eloquent\Model $model - * @param string $identifier + * @param \Illuminate\Database\Eloquent\Model $model + * @param string $identifier * @return mixed */ - protected abstract function resolveRelation(Model $model, string $identifier); + abstract protected function resolveRelation(Model $model, string $identifier); /** * Get a related transformer class mapped to a relation identifier. * - * @param string $identifier + * @param string $identifier * @return string */ - protected abstract function mappedTransformerClass(string $identifier); -} \ No newline at end of file + abstract protected function mappedTransformerClass(string $identifier); +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 028ee82..9bed1c7 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -5,7 +5,6 @@ use Flugg\Responder\Contracts\ResponseFactory; use Flugg\Responder\Http\Responses\ErrorResponseBuilder; use Flugg\Responder\Http\Responses\SuccessResponseBuilder; -use Flugg\Responder\Resources\ResourceBuilder; use Flugg\Responder\ResponderServiceProvider; use Flugg\Responder\TransformBuilder; use Flugg\Responder\Transformers\Transformer; @@ -22,7 +21,6 @@ /** * The base test case class, responsible for bootstrapping the testing environment. * - * @package flugger/laravel-responder * @author Alexander Tømmerås * @license The MIT License */ @@ -78,7 +76,7 @@ public function setUp(): void /** * Define environment setup. * - * @param \Illuminate\Foundation\Application $app + * @param \Illuminate\Foundation\Application $app * @return void */ protected function getEnvironmentSetUp($app) @@ -136,7 +134,7 @@ private function runTestMigrations() /** * Get package service providers. * - * @param \Illuminate\Foundation\Application $app + * @param \Illuminate\Foundation\Application $app * @return array */ protected function getPackageProviders($app) @@ -150,8 +148,8 @@ protected function getPackageProviders($app) * Merge given data with the skeleton of a serialization using the default [SuccessSerializer]. * * @param null $data - * @param array $meta - * @param int $status + * @param array $meta + * @param int $status * @return array */ protected function responseData($data = null, $meta = [], $status = 200): array @@ -263,7 +261,7 @@ protected function mockFractalManager(): MockInterface /** * Create a mock of a [ResourceInterface]. * - * @param string|null $className + * @param string|null $className * @return \Mockery\MockInterface */ protected function mockResource(?string $className = null): MockInterface @@ -380,4 +378,4 @@ public function transform(Customer $customer) { return $customer->fresh()->toArray(); } -} \ No newline at end of file +}