Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix php 8.4 Deprecated warnings #207

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/Contracts/ErrorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
/**
* A contract for creating errors.
*
* @package flugger/laravel-responder
* @author Alexander Tømmerås <flugged@gmail.com>
* @license The MIT License
*/
Expand All @@ -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;
}
public function make(ErrorSerializer $serializer, $errorCode = null, ?string $message = null, ?array $data = null): array;
}
7 changes: 3 additions & 4 deletions src/Contracts/ErrorSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
/**
* A contract for formatting error arrays.
*
* @package flugger/laravel-responder
* @author Alexander Tømmerås <flugged@gmail.com>
* @license The MIT License
*/
Expand All @@ -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;
}
public function format($errorCode = null, ?string $message = null, ?array $data = null): array;
}
11 changes: 5 additions & 6 deletions src/Contracts/Resources/ResourceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
/**
* A contract for creating resources.
*
* @package flugger/laravel-responder
* @author Alexander Tømmerås <flugged@gmail.com>
* @license The MIT License
*/
Expand All @@ -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;
}
public function make($data = null, $transformer = null, ?string $resourceKey = null): ResourceInterface;
}
15 changes: 7 additions & 8 deletions src/Contracts/Responder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
/**
* A contract for responding with error- and success responses.
*
* @package flugger/laravel-responder
* @author Alexander Tømmerås <flugged@gmail.com>
* @license The MIT License
*/
Expand All @@ -17,19 +16,19 @@ 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;
public function success($data = null, $transformer = null, ?string $resourceKey = null): SuccessResponseBuilder;

/**
* 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;
}
public function error($errorCode = null, ?string $message = null): ErrorResponseBuilder;
}
11 changes: 5 additions & 6 deletions src/Contracts/SimpleTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
/**
* A contract for transforming data, without the serializing.
*
* @package flugger/laravel-responder
* @author Alexander Tømmerås <flugged@gmail.com>
* @license The MIT License
*/
Expand All @@ -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;
}
public function make($data = null, $transformer = null, ?string $resourceKey = null): TransformBuilder;
}
15 changes: 7 additions & 8 deletions src/ErrorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/**
* A factory class responsible for creating error arrays.
*
* @package flugger/laravel-responder
* @author Alexander Tømmerås <flugged@gmail.com>
* @license The MIT License
*/
Expand All @@ -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)
{
Expand All @@ -35,18 +34,18 @@ 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
public function make(ErrorSerializer $serializer, $errorCode = null, ?string $message = null, ?array $data = null): array
{
if (isset($errorCode) && ! isset($message)) {
$message = $this->messageResolver->resolve($errorCode);
}

return $serializer->format($errorCode, $message, $data);
}
}
}
9 changes: 4 additions & 5 deletions src/Exceptions/Http/HttpException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
/**
* An abstract exception responsible for holding error response data.
*
* @package flugger/laravel-responder
* @author Alexander Tømmerås <flugged@gmail.com>
* @license The MIT License
*/
Expand Down Expand Up @@ -51,16 +50,16 @@ 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)
public function __construct(?string $message = null, ?array $headers = null)
{
parent::__construct($this->status, $message ?? $this->message, null, $headers ?? $this->headers);
}

/**
* Retrieve the HTTP status code,
* Retrieve the HTTP status code,.
*
* @return int
*/
Expand Down
15 changes: 7 additions & 8 deletions src/Http/MakesResponses.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <flugged@gmail.com>
* @license The MIT License
*/
Expand All @@ -18,12 +17,12 @@ 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
public function success($data = null, $transformer = null, ?string $resourceKey = null): SuccessResponseBuilder
{
return app(Responder::class)->success(...func_get_args());
}
Expand All @@ -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
public function error($errorCode = null, ?string $message = null): ErrorResponseBuilder
{
return app(Responder::class)->error(...func_get_args());
}
}
}
19 changes: 10 additions & 9 deletions src/Http/Responses/ErrorResponseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
/**
* A builder class for building error responses.
*
* @package flugger/laravel-responder
* @author Alexander Tømmerås <flugged@gmail.com>
* @license The MIT License
*/
Expand Down Expand Up @@ -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)
{
Expand All @@ -76,10 +75,10 @@ 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)
public function error($errorCode = null, ?string $message = null)
{
$this->errorCode = $errorCode;
$this->message = $message;
Expand All @@ -90,10 +89,10 @@ 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)
public function data(?array $data = null)
{
$this->data = array_merge((array) $this->data, (array) $data);

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 9 additions & 10 deletions src/Http/Responses/ResponseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
/**
* An abstract builder class for building responses.
*
* @package flugger/laravel-responder
* @author Alexander Tømmerås <flugged@gmail.com>
* @license The MIT License
*/
Expand All @@ -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)
{
Expand All @@ -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)
Expand All @@ -53,19 +52,19 @@ public function decorator($decorator)

foreach ($decorators as $decorator) {
$this->responseFactory = new $decorator($this->responseFactory);
};
}

return $this;
}

/**
* 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
public function respond(?int $status = null, array $headers = []): JsonResponse
{
if (! is_null($status)) {
$this->setStatusCode($status);
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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);
Expand Down
Loading