diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7f59b9a2..c92f166a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: true matrix: - php: [8.2, 8.3] + php: [8.2, 8.3, 8.4] laravel: [11] steps: diff --git a/CHANGELOG.md b/CHANGELOG.md index 118e3b11..7ebc2cca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. This projec ## Unreleased +### Changed + +- Removed PHP 8.4 deprecation notices. + ## [7.0.0] - 2024-03-14 ### Changed diff --git a/composer.json b/composer.json index 790fa7c4..26a21ce6 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "require": { "php": "^8.2", "ext-json": "*", - "laravel-json-api/neomerx-json-api": "^5.0.2", + "laravel-json-api/neomerx-json-api": "^5.0.3", "laravel/framework": "^11.0", "nyholm/psr7": "^1.8", "ramsey/uuid": "^4.0", diff --git a/src/Api/Repository.php b/src/Api/Repository.php index 10d8cfdd..4d38efc4 100644 --- a/src/Api/Repository.php +++ b/src/Api/Repository.php @@ -72,7 +72,7 @@ public function exists($apiName) * route parameters, if needed. * @return Api */ - public function createApi(string $apiName, string $host = null, array $parameters = []) + public function createApi(string $apiName, ?string $host = null, array $parameters = []) { $config = $this->configFor($apiName); $config = $this->normalize($config, $host); diff --git a/src/Broadcasting/BroadcastsData.php b/src/Broadcasting/BroadcastsData.php index a2dfefbd..8ae523e1 100644 --- a/src/Broadcasting/BroadcastsData.php +++ b/src/Broadcasting/BroadcastsData.php @@ -51,7 +51,7 @@ protected function broadcastEncoder() * @param array|null $fieldsets * @return array */ - protected function serializeData($data, $includePaths = null, array $fieldsets = null) + protected function serializeData($data, $includePaths = null, ?array $fieldsets = null) { $params = new QueryParameters($includePaths ? (array) $includePaths : null, $fieldsets); diff --git a/src/Client/AbstractClient.php b/src/Client/AbstractClient.php index b65db7ec..3a5c488e 100644 --- a/src/Client/AbstractClient.php +++ b/src/Client/AbstractClient.php @@ -72,7 +72,7 @@ abstract class AbstractClient implements ClientInterface abstract protected function request( $method, $uri, - array $payload = null, + ?array $payload = null, array $parameters = [] ); diff --git a/src/Client/GuzzleClient.php b/src/Client/GuzzleClient.php index d67dc6cc..2a75b629 100644 --- a/src/Client/GuzzleClient.php +++ b/src/Client/GuzzleClient.php @@ -60,7 +60,7 @@ public function __construct( protected function request( $method, $uri, - array $payload = null, + ?array $payload = null, array $parameters = [] ) { $request = new Request($method, $uri); diff --git a/src/Codec/Encoding.php b/src/Codec/Encoding.php index 81353544..1801b164 100644 --- a/src/Codec/Encoding.php +++ b/src/Codec/Encoding.php @@ -54,7 +54,7 @@ class Encoding public static function create( $mediaType, int $options = 0, - string $urlPrefix = null, + ?string $urlPrefix = null, int $depth = 512 ): self { @@ -73,7 +73,7 @@ public static function create( * @param int $depth * @return Encoding */ - public static function jsonApi(int $options = 0, string $urlPrefix = null, int $depth = 512): self + public static function jsonApi(int $options = 0, ?string $urlPrefix = null, int $depth = 512): self { return self::create( MediaTypeInterface::JSON_API_MEDIA_TYPE, @@ -104,7 +104,7 @@ public static function custom($mediaType): self * @param string|null $urlPrefix * @return Encoding */ - public static function fromArray($key, $value, string $urlPrefix = null): self + public static function fromArray($key, $value, ?string $urlPrefix = null): self { if (is_numeric($key)) { $key = $value; diff --git a/src/Codec/EncodingList.php b/src/Codec/EncodingList.php index 87eac050..caf408b1 100644 --- a/src/Codec/EncodingList.php +++ b/src/Codec/EncodingList.php @@ -47,7 +47,7 @@ class EncodingList implements IteratorAggregate, Countable * @param string|null $urlPrefix * @return EncodingList */ - public static function fromArray(iterable $config, string $urlPrefix = null): self + public static function fromArray(iterable $config, ?string $urlPrefix = null): self { $values = Collection::make($config) ->map(fn($value, $key) => Encoding::fromArray($key, $value, $urlPrefix)) diff --git a/src/Container.php b/src/Container.php index 903d7a82..4c1362fa 100644 --- a/src/Container.php +++ b/src/Container.php @@ -379,7 +379,7 @@ protected function getCreatedAdapter($resourceType) * @param ResourceAdapterInterface|null $adapter * @return void */ - protected function setCreatedAdapter($resourceType, ResourceAdapterInterface $adapter = null) + protected function setCreatedAdapter($resourceType, ?ResourceAdapterInterface $adapter = null) { $this->createdAdapters[$resourceType] = $adapter; } @@ -467,7 +467,7 @@ protected function getCreatedAuthorizer($resourceType) * @param AuthorizerInterface|null $authorizer * @return void */ - protected function setCreatedAuthorizer($resourceType, AuthorizerInterface $authorizer = null) + protected function setCreatedAuthorizer($resourceType, ?AuthorizerInterface $authorizer = null) { $this->createdAuthorizers[$resourceType] = $authorizer; } diff --git a/src/Contracts/Schema/SchemaProviderInterface.php b/src/Contracts/Schema/SchemaProviderInterface.php index 910bc25c..3753a6a6 100644 --- a/src/Contracts/Schema/SchemaProviderInterface.php +++ b/src/Contracts/Schema/SchemaProviderInterface.php @@ -78,7 +78,7 @@ public function getRelationships(object $resource, bool $isPrimary, array $inclu * @param object|null $resource * @return string */ - public function getSelfSubUrl(object $resource = null): string; + public function getSelfSubUrl(?object $resource = null): string; /** * Get the resource self sub link. diff --git a/src/Document/Error/Error.php b/src/Document/Error/Error.php index 6937a41c..f2f7a195 100644 --- a/src/Document/Error/Error.php +++ b/src/Document/Error/Error.php @@ -134,12 +134,12 @@ public static function fromArray(array $input): self public function __construct( $id = null, $status = null, - string $code = null, - string $title = null, - string $detail = null, - iterable $source = null, - iterable $links = null, - iterable $meta = null + ?string $code = null, + ?string $title = null, + ?string $detail = null, + ?iterable $source = null, + ?iterable $links = null, + ?iterable $meta = null ) { $this->setId($id); diff --git a/src/Document/Error/Translator.php b/src/Document/Error/Translator.php index 5f5fd032..ca7b5963 100644 --- a/src/Document/Error/Translator.php +++ b/src/Document/Error/Translator.php @@ -17,6 +17,7 @@ namespace CloudCreativity\LaravelJsonApi\Document\Error; +use Closure; use CloudCreativity\LaravelJsonApi\Exceptions\ValidationException; use CloudCreativity\LaravelJsonApi\LaravelJsonApi; use CloudCreativity\LaravelJsonApi\Utils\Str; @@ -402,7 +403,7 @@ public function resourceFieldExistsInAttributesAndRelationships( * @param string|null $detail * @return ErrorInterface */ - public function resourceCannotBeDeleted(string $detail = null): ErrorInterface + public function resourceCannotBeDeleted(?string $detail = null): ErrorInterface { return new NeomerxError( null, @@ -475,11 +476,11 @@ public function invalidQueryParameter(string $param, ?string $detail = null, arr * Create errors for a failed validator. * * @param ValidatorContract $validator - * @param \Closure|null $closure + * @param Closure|null $closure * a closure that is bound to the translator. * @return ErrorCollection */ - public function failedValidator(ValidatorContract $validator, \Closure $closure = null): ErrorCollection + public function failedValidator(ValidatorContract $validator, ?Closure $closure = null): ErrorCollection { $failed = $this->doesIncludeFailed() ? $validator->failed() : []; $errors = new ErrorCollection(); @@ -513,12 +514,12 @@ public function failedValidator(ValidatorContract $validator, \Closure $closure * Create a JSON API exception for a failed validator. * * @param ValidatorContract $validator - * @param \Closure|null $closure + * @param Closure|null $closure * @return JsonApiException */ public function failedValidatorException( ValidatorContract $validator, - \Closure $closure = null + ?Closure $closure = null ): JsonApiException { return new ValidationException( @@ -529,11 +530,11 @@ public function failedValidatorException( /** * Create an error by calling the closure with it bound to the error translator. * - * @param \Closure $closure + * @param Closure $closure * @param mixed ...$args * @return ErrorInterface */ - public function call(\Closure $closure, ...$args): ErrorInterface + public function call(Closure $closure, ...$args): ErrorInterface { return $closure->call($this, ...$args); } diff --git a/src/Eloquent/AbstractAdapter.php b/src/Eloquent/AbstractAdapter.php index 02a4a64f..5129855d 100644 --- a/src/Eloquent/AbstractAdapter.php +++ b/src/Eloquent/AbstractAdapter.php @@ -17,6 +17,7 @@ namespace CloudCreativity\LaravelJsonApi\Eloquent; +use Closure; use CloudCreativity\LaravelJsonApi\Adapter\AbstractResourceAdapter; use CloudCreativity\LaravelJsonApi\Contracts\Adapter\HasManyAdapterInterface; use CloudCreativity\LaravelJsonApi\Contracts\Adapter\RelationshipAdapterInterface; @@ -115,7 +116,7 @@ abstract protected function filter($query, Collection $filters); * @param Model $model * @param PagingStrategyInterface|null $paging */ - public function __construct(Model $model, PagingStrategyInterface $paging = null) + public function __construct(Model $model, ?PagingStrategyInterface $paging = null) { $this->model = $model; $this->paging = $paging; @@ -259,11 +260,11 @@ public function addScopes(Scope ...$scopes): self /** * Add a global scope using a closure. * - * @param \Closure $scope + * @param Closure $scope * @param string|null $identifier * @return $this */ - public function addClosureScope(\Closure $scope, string $identifier = null): self + public function addClosureScope(Closure $scope, ?string $identifier = null): self { $identifier = $identifier ?: spl_object_hash($scope); @@ -616,20 +617,20 @@ protected function morphMany(HasManyAdapterInterface ...$adapters) } /** - * @param \Closure $factory + * @param Closure $factory * a factory that creates a new Eloquent query builder. * @return QueriesMany */ - protected function queriesMany(\Closure $factory) + protected function queriesMany(Closure $factory) { return new QueriesMany($factory); } /** - * @param \Closure $factory + * @param Closure $factory * @return QueriesOne */ - protected function queriesOne(\Closure $factory) + protected function queriesOne(Closure $factory) { return new QueriesOne($factory); } diff --git a/src/Encoder/EncoderOptions.php b/src/Encoder/EncoderOptions.php index 400e6e93..65b0b0ca 100644 --- a/src/Encoder/EncoderOptions.php +++ b/src/Encoder/EncoderOptions.php @@ -43,7 +43,7 @@ class EncoderOptions * @param string|null $urlPrefix * @param int $depth */ - public function __construct(int $options = 0, string $urlPrefix = null, int $depth = 512) + public function __construct(int $options = 0, ?string $urlPrefix = null, int $depth = 512) { $this->options = $options; $this->depth = $depth; diff --git a/src/Exceptions/ClientException.php b/src/Exceptions/ClientException.php index 870d7486..df6fd921 100644 --- a/src/Exceptions/ClientException.php +++ b/src/Exceptions/ClientException.php @@ -17,6 +17,7 @@ namespace CloudCreativity\LaravelJsonApi\Exceptions; +use Exception; use Illuminate\Support\Collection; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -50,12 +51,12 @@ class ClientException extends \RuntimeException * * @param RequestInterface $request * @param ResponseInterface|null $response - * @param \Exception|null $previous + * @param Exception|null $previous */ public function __construct( RequestInterface $request, - ResponseInterface $response = null, - \Exception $previous = null + ?ResponseInterface $response = null, + ?Exception $previous = null ) { parent::__construct( $previous ? $previous->getMessage() : 'Client encountered an error.', @@ -104,7 +105,7 @@ public function getErrors() try { $this->errors = $this->parse(); - } catch (\Exception $ex) { + } catch (Exception $ex) { $this->errors = []; } diff --git a/src/Exceptions/DocumentRequiredException.php b/src/Exceptions/DocumentRequiredException.php index 82c8b047..c5d15750 100644 --- a/src/Exceptions/DocumentRequiredException.php +++ b/src/Exceptions/DocumentRequiredException.php @@ -35,7 +35,7 @@ class DocumentRequiredException extends InvalidJsonException * * @param Exception|null $previous */ - public function __construct(Exception $previous = null) + public function __construct(?Exception $previous = null) { parent::__construct( null, diff --git a/src/Exceptions/InvalidJsonException.php b/src/Exceptions/InvalidJsonException.php index 88ff9d05..dcc4586e 100644 --- a/src/Exceptions/InvalidJsonException.php +++ b/src/Exceptions/InvalidJsonException.php @@ -44,7 +44,7 @@ class InvalidJsonException extends JsonApiException * @param Exception|null $previous * @return InvalidJsonException */ - public static function create($defaultHttpCode = self::HTTP_CODE_BAD_REQUEST, Exception $previous = null) + public static function create($defaultHttpCode = self::HTTP_CODE_BAD_REQUEST, ?Exception $previous = null) { return new self(json_last_error(), json_last_error_msg(), $defaultHttpCode, $previous); } @@ -61,7 +61,7 @@ public function __construct( $jsonError = null, $jsonErrorMessage = null, $defaultHttpCode = self::HTTP_CODE_BAD_REQUEST, - Exception $previous = null + ?Exception $previous = null ) { parent::__construct([], $defaultHttpCode, $previous); diff --git a/src/Exceptions/JsonApiException.php b/src/Exceptions/JsonApiException.php index e76207e8..ee3fbafc 100644 --- a/src/Exceptions/JsonApiException.php +++ b/src/Exceptions/JsonApiException.php @@ -46,7 +46,7 @@ class JsonApiException extends Exception implements HttpExceptionInterface, Resp * @param Throwable|null $previous * @return static */ - public static function make($errors, Throwable $previous = null): self + public static function make($errors, ?Throwable $previous = null): self { return new self($errors, $previous); } @@ -58,7 +58,7 @@ public static function make($errors, Throwable $previous = null): self * @param Throwable|null $previous * @param array $headers */ - public function __construct($errors, Throwable $previous = null, array $headers = []) + public function __construct($errors, ?Throwable $previous = null, array $headers = []) { parent::__construct('JSON API error', 0, $previous); $this->errors = Errors::cast($errors); diff --git a/src/Exceptions/ResourceNotFoundException.php b/src/Exceptions/ResourceNotFoundException.php index d39c1d62..63772d58 100644 --- a/src/Exceptions/ResourceNotFoundException.php +++ b/src/Exceptions/ResourceNotFoundException.php @@ -17,6 +17,7 @@ namespace CloudCreativity\LaravelJsonApi\Exceptions; +use Exception; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; class ResourceNotFoundException extends NotFoundHttpException @@ -37,14 +38,14 @@ class ResourceNotFoundException extends NotFoundHttpException * * @param string $type * @param string $id - * @param \Exception|null $previous + * @param Exception|null $previous * @param int $code * @param array $headers */ public function __construct( string $type, string $id, - \Exception $previous = null, + ?Exception $previous = null, int $code = 0, array $headers = [] ) { diff --git a/src/Exceptions/ValidationException.php b/src/Exceptions/ValidationException.php index df909d16..076c95d4 100644 --- a/src/Exceptions/ValidationException.php +++ b/src/Exceptions/ValidationException.php @@ -59,7 +59,7 @@ public static function create(ValidatorInterface $validator): self * @param string|int|null $defaultHttpCode * @param Exception|null $previous */ - public function __construct($errors, $defaultHttpCode = self::DEFAULT_HTTP_CODE, Exception $previous = null) + public function __construct($errors, $defaultHttpCode = self::DEFAULT_HTTP_CODE, ?Exception $previous = null) { parent::__construct( $errors, diff --git a/src/Factories/Factory.php b/src/Factories/Factory.php index 1f732964..4cbea344 100644 --- a/src/Factories/Factory.php +++ b/src/Factories/Factory.php @@ -19,6 +19,7 @@ namespace CloudCreativity\LaravelJsonApi\Factories; +use Closure; use CloudCreativity\LaravelJsonApi\Api\AbstractProvider; use CloudCreativity\LaravelJsonApi\Api\Api; use CloudCreativity\LaravelJsonApi\Api\LinkGenerator; @@ -217,12 +218,12 @@ public function createStore(ContainerInterface $container): StoreInterface */ public function createPage( $data, - LinkInterface $first = null, - LinkInterface $previous = null, - LinkInterface $next = null, - LinkInterface $last = null, + ?LinkInterface $first = null, + ?LinkInterface $previous = null, + ?LinkInterface $next = null, + ?LinkInterface $last = null, $meta = null, - string $metaKey = null + ?string $metaKey = null ): PageInterface { return new Page($data, $first, $previous, $next, $last, $meta, $metaKey); @@ -285,12 +286,12 @@ public function createLinkGenerator(UrlGenerator $urls): LinkGenerator * @return QueryParameters */ public function createQueryParameters( - array $includePaths = null, - array $fieldSets = null, - array $sortParameters = null, - array $pagingParameters = null, - array $filteringParameters = null, - array $unrecognizedParams = null + ?array $includePaths = null, + ?array $fieldSets = null, + ?array $sortParameters = null, + ?array $pagingParameters = null, + ?array $filteringParameters = null, + ?array $unrecognizedParams = null ) { return new QueryParameters( $includePaths, @@ -420,7 +421,7 @@ public function createDocumentMapper(): Mapper * @param array $rules * @param array $messages * @param array $customAttributes - * @param \Closure|null $callback + * @param Closure|null $callback * a closure for creating an error, that will be bound to the error translator. * @return ValidatorInterface */ @@ -429,7 +430,7 @@ public function createValidator( array $rules, array $messages = [], array $customAttributes = [], - \Closure $callback = null + ?Closure $callback = null ): ValidatorInterface { $translator = $this->createErrorTranslator(); diff --git a/src/Http/Headers/HeaderParameters.php b/src/Http/Headers/HeaderParameters.php index f9c64a51..80f939d4 100644 --- a/src/Http/Headers/HeaderParameters.php +++ b/src/Http/Headers/HeaderParameters.php @@ -41,7 +41,7 @@ class HeaderParameters implements HeaderParametersInterface * @param AcceptHeaderInterface $accept * @param HeaderInterface|null $contentType */ - public function __construct(AcceptHeaderInterface $accept, HeaderInterface $contentType = null) + public function __construct(AcceptHeaderInterface $accept, ?HeaderInterface $contentType = null) { $this->accept = $accept; $this->contentType = $contentType; diff --git a/src/Http/Middleware/NegotiateContent.php b/src/Http/Middleware/NegotiateContent.php index e15002fe..4145f5d5 100644 --- a/src/Http/Middleware/NegotiateContent.php +++ b/src/Http/Middleware/NegotiateContent.php @@ -80,7 +80,7 @@ public function __construct(Container $container, Factory $factory, Route $route * @return mixed * @throws HttpException */ - public function handle($request, \Closure $next, string $default = null) + public function handle($request, \Closure $next, ?string $default = null) { $api = $this->container->make(Api::class); /** @var HeaderParametersInterface $headers */ diff --git a/src/Http/Query/QueryParameters.php b/src/Http/Query/QueryParameters.php index 2b6d3da1..80afd8e5 100644 --- a/src/Http/Query/QueryParameters.php +++ b/src/Http/Query/QueryParameters.php @@ -93,12 +93,12 @@ public static function cast(QueryParametersInterface $parameters) * @param array|null $unrecognizedParams */ public function __construct( - array $includePaths = null, - array $fieldSets = null, - array $sortParameters = null, - array $pagingParameters = null, - array $filteringParameters = null, - array $unrecognizedParams = null + ?array $includePaths = null, + ?array $fieldSets = null, + ?array $sortParameters = null, + ?array $pagingParameters = null, + ?array $filteringParameters = null, + ?array $unrecognizedParams = null ) { $this->fieldSets = $fieldSets; $this->includePaths = $includePaths; diff --git a/src/Http/Responses/Responses.php b/src/Http/Responses/Responses.php index 6cdde794..d571afda 100644 --- a/src/Http/Responses/Responses.php +++ b/src/Http/Responses/Responses.php @@ -262,7 +262,7 @@ public function content( public function getContentResponseBackwardsCompat( $data, int $statusCode = self::HTTP_OK, - array $links = null, + ?array $links = null, $meta = null, array $headers = [] ): Response @@ -423,7 +423,7 @@ public function relationship( public function getIdentifiersResponseBackwardsCompat( $data, int $statusCode = self::HTTP_OK, - array $links = null, + ?array $links = null, $meta = null, array $headers = [] ): Response { @@ -444,7 +444,7 @@ public function getIdentifiersResponseBackwardsCompat( * @param array $headers * @return Response */ - public function error($error, int $defaultStatusCode = null, array $headers = []): Response + public function error($error, ?int $defaultStatusCode = null, array $headers = []): Response { if (!$error instanceof ErrorInterface) { $error = $this->factory->createDocumentMapper()->createError( @@ -468,7 +468,7 @@ public function error($error, int $defaultStatusCode = null, array $headers = [] * * @return Response */ - public function errors(iterable $errors, int $defaultStatusCode = null, array $headers = []): Response + public function errors(iterable $errors, ?int $defaultStatusCode = null, array $headers = []): Response { $errors = $this->factory->createDocumentMapper()->createErrors($errors); $statusCode = Helpers::httpErrorStatus($errors, $defaultStatusCode); diff --git a/src/Pagination/Page.php b/src/Pagination/Page.php index 37d3bf70..f04f31be 100644 --- a/src/Pagination/Page.php +++ b/src/Pagination/Page.php @@ -76,12 +76,12 @@ class Page implements PageInterface */ public function __construct( $data, - LinkInterface $first = null, - LinkInterface $previous = null, - LinkInterface $next = null, - LinkInterface $last = null, + ?LinkInterface $first = null, + ?LinkInterface $previous = null, + ?LinkInterface $next = null, + ?LinkInterface $last = null, $meta = null, - string $metaKey = null + ?string $metaKey = null ) { $this->data = $data; $this->first = $first; diff --git a/src/Queue/AsyncSchema.php b/src/Queue/AsyncSchema.php index 285b1cbf..f667a340 100644 --- a/src/Queue/AsyncSchema.php +++ b/src/Queue/AsyncSchema.php @@ -38,7 +38,7 @@ public function getResourceType(): string * @param AsynchronousProcess|object|null $resource * @return string */ - public function getSelfSubUrl(object $resource = null): string + public function getSelfSubUrl(?object $resource = null): string { if (!$resource) { return '/' . $this->getResourceType(); diff --git a/src/Queue/ClientDispatch.php b/src/Queue/ClientDispatch.php index a538a22a..a30b1c34 100644 --- a/src/Queue/ClientDispatch.php +++ b/src/Queue/ClientDispatch.php @@ -83,7 +83,7 @@ public function setApi(string $api): ClientDispatch * @param string|null $id * @return ClientDispatch */ - public function setResource(string $type, string $id = null): ClientDispatch + public function setResource(string $type, ?string $id = null): ClientDispatch { $this->resourceType = $type; $this->resourceId = $id; diff --git a/src/Routing/JsonApiRegistrar.php b/src/Routing/JsonApiRegistrar.php index 7cb0ff36..1edad1f7 100644 --- a/src/Routing/JsonApiRegistrar.php +++ b/src/Routing/JsonApiRegistrar.php @@ -73,7 +73,7 @@ public function register(string $api): ApiRegistration * @param Closure|null $routes * @return ApiRegistration */ - public function api(string $apiName, $options = [], Closure $routes = null): ApiRegistration + public function api(string $apiName, $options = [], ?Closure $routes = null): ApiRegistration { if ($options instanceof Closure) { $routes = $options; diff --git a/src/Routing/RelationshipsRegistration.php b/src/Routing/RelationshipsRegistration.php index 8312856d..66cddb0a 100644 --- a/src/Routing/RelationshipsRegistration.php +++ b/src/Routing/RelationshipsRegistration.php @@ -55,7 +55,7 @@ public function __construct($hasOne = [], $hasMany = []) * @param string|null $inverse * @return RelationshipRegistration */ - public function hasOne(string $field, string $inverse = null): RelationshipRegistration + public function hasOne(string $field, ?string $inverse = null): RelationshipRegistration { $rel = $this->hasOne[$field] ?? new RelationshipRegistration(); @@ -71,7 +71,7 @@ public function hasOne(string $field, string $inverse = null): RelationshipRegis * @param string|null $inverse * @return RelationshipRegistration */ - public function hasMany(string $field, string $inverse = null): RelationshipRegistration + public function hasMany(string $field, ?string $inverse = null): RelationshipRegistration { $rel = $this->hasMany[$field] ?? new RelationshipRegistration(); diff --git a/src/Routing/ResourceRegistrar.php b/src/Routing/ResourceRegistrar.php index 5570bd46..6d511678 100644 --- a/src/Routing/ResourceRegistrar.php +++ b/src/Routing/ResourceRegistrar.php @@ -17,6 +17,7 @@ namespace CloudCreativity\LaravelJsonApi\Routing; +use Closure; use Illuminate\Contracts\Routing\Registrar; use Illuminate\Routing\Route; use Illuminate\Support\Str; @@ -50,7 +51,7 @@ final class ResourceRegistrar use RegistersResources; /** - * @var \Closure|null + * @var Closure|null */ private $group; @@ -60,9 +61,9 @@ final class ResourceRegistrar * @param Registrar $router * @param string $resourceType * @param array $options - * @param \Closure|null $group + * @param Closure|null $group */ - public function __construct(Registrar $router, string $resourceType, array $options = [], \Closure $group = null) + public function __construct(Registrar $router, string $resourceType, array $options = [], ?Closure $group = null) { $this->router = $router; $this->resourceType = $resourceType; diff --git a/src/Routing/RouteRegistration.php b/src/Routing/RouteRegistration.php index 4c61555a..98dfc5d7 100644 --- a/src/Routing/RouteRegistration.php +++ b/src/Routing/RouteRegistration.php @@ -79,7 +79,7 @@ public function controller(string $controller): self * @param string|null $inverse * @return $this */ - public function field(string $field, string $inverse = null): self + public function field(string $field, ?string $inverse = null): self { $this->defaults = array_merge($this->defaults, [ ResourceRegistrar::PARAM_RELATIONSHIP_NAME => $field, diff --git a/src/Rules/AbstractAllowedRule.php b/src/Rules/AbstractAllowedRule.php index 29d30556..59c8edd6 100644 --- a/src/Rules/AbstractAllowedRule.php +++ b/src/Rules/AbstractAllowedRule.php @@ -54,7 +54,7 @@ abstract protected function extract($value): Collection; * * @param array|null $allowed */ - public function __construct(array $allowed = null) + public function __construct(?array $allowed = null) { $this->all = is_null($allowed); $this->allowed = collect($allowed)->combine($allowed); diff --git a/src/Rules/AllowedFieldSets.php b/src/Rules/AllowedFieldSets.php index becc63f7..c975dca4 100644 --- a/src/Rules/AllowedFieldSets.php +++ b/src/Rules/AllowedFieldSets.php @@ -50,7 +50,7 @@ class AllowedFieldSets implements Rule * * @param array|null $allowed */ - public function __construct(array $allowed = null) + public function __construct(?array $allowed = null) { $this->all = is_null($allowed); $this->allowed = collect($allowed); @@ -64,7 +64,7 @@ public function __construct(array $allowed = null) * the allowed fields, empty array for none allowed, or null for all allowed. * @return $this */ - public function allow(string $resourceType, array $fields = null): self + public function allow(string $resourceType, ?array $fields = null): self { $this->all = false; $this->allowed[$resourceType] = $fields; diff --git a/src/Schema/Schema.php b/src/Schema/Schema.php index 08906daf..babee392 100644 --- a/src/Schema/Schema.php +++ b/src/Schema/Schema.php @@ -47,7 +47,7 @@ class Schema extends BaseSchema public function __construct( FactoryInterface $factory, SchemaProviderInterface $provider, - SchemaFields $fields = null + ?SchemaFields $fields = null, ) { parent::__construct($factory); $this->provider = $provider; diff --git a/src/Schema/SchemaContainer.php b/src/Schema/SchemaContainer.php index 1738ce1f..abafdfd5 100644 --- a/src/Schema/SchemaContainer.php +++ b/src/Schema/SchemaContainer.php @@ -48,7 +48,7 @@ class SchemaContainer implements SchemaContainerInterface * @param FactoryInterface $factory * @param SchemaFields|null $fields */ - public function __construct(ContainerInterface $container, FactoryInterface $factory, SchemaFields $fields = null) + public function __construct(ContainerInterface $container, FactoryInterface $factory, ?SchemaFields $fields = null) { $this->container = $container; $this->factory = $factory; diff --git a/src/Schema/SchemaFields.php b/src/Schema/SchemaFields.php index 3a70c579..47a20b3b 100644 --- a/src/Schema/SchemaFields.php +++ b/src/Schema/SchemaFields.php @@ -83,7 +83,7 @@ public static function make(?QueryParametersInterface $parameters): self * @param iterable|null $paths * @param iterable|null $fieldSets */ - public function __construct(iterable $paths = null, iterable $fieldSets = null) + public function __construct(?iterable $paths = null, ?iterable $fieldSets = null) { if (null !== $paths) { foreach ($paths as $path) { diff --git a/src/Schema/SchemaProvider.php b/src/Schema/SchemaProvider.php index 91152d6b..698529f5 100644 --- a/src/Schema/SchemaProvider.php +++ b/src/Schema/SchemaProvider.php @@ -116,7 +116,7 @@ public function getRelationships(object $resource, bool $isPrimary, array $inclu /** * @inheritDoc */ - public function getSelfSubUrl(object $resource = null): string + public function getSelfSubUrl(?object $resource = null): string { if (empty($this->selfSubUrl)) { $this->selfSubUrl = '/' . $this->getResourceType(); @@ -213,7 +213,7 @@ protected function getContext(): ContextInterface * @param bool $treatAsHref * @return LinkInterface */ - protected function createLink(string $subHref, array $meta = null, bool $treatAsHref = false): LinkInterface + protected function createLink(string $subHref, ?array $meta = null, bool $treatAsHref = false): LinkInterface { return $this->factory->createLink(!$treatAsHref, $subHref, !empty($meta), $meta); } diff --git a/src/Services/JsonApiService.php b/src/Services/JsonApiService.php index e5897975..bc323df8 100644 --- a/src/Services/JsonApiService.php +++ b/src/Services/JsonApiService.php @@ -115,7 +115,7 @@ public function requestApiOrFail() * @param Closure|null $routes * @return ApiRegistration */ - public function register($apiName, $options = [], Closure $routes = null): ApiRegistration + public function register($apiName, $options = [], ?Closure $routes = null): ApiRegistration { /** @var JsonApiRegistrar $registrar */ $registrar = app('json-api.registrar'); diff --git a/src/Utils/Helpers.php b/src/Utils/Helpers.php index 01aaf6bb..e22f1706 100644 --- a/src/Utils/Helpers.php +++ b/src/Utils/Helpers.php @@ -162,7 +162,7 @@ public static function isJsonApi($request) * @see https://jsonapi.org/format/#errors * @deprecated 3.0.0 use `Document\Error\Errors::getStatus()` */ - public static function httpErrorStatus($errors, int $default = null): int + public static function httpErrorStatus($errors, ?int $default = null): int { if (\is_null($default)) { $default = SymfonyResponse::HTTP_BAD_REQUEST; diff --git a/src/Validation/Validator.php b/src/Validation/Validator.php index 256b46aa..fa44d8d8 100644 --- a/src/Validation/Validator.php +++ b/src/Validation/Validator.php @@ -17,6 +17,7 @@ namespace CloudCreativity\LaravelJsonApi\Validation; +use Closure; use CloudCreativity\LaravelJsonApi\Contracts\Validation\ValidatorInterface; use CloudCreativity\LaravelJsonApi\Document\Error\Translator as ErrorTranslator; use Illuminate\Contracts\Validation\Validator as ValidatorContract; @@ -41,7 +42,7 @@ class Validator implements ValidatorInterface protected $translator; /** - * @var \Closure|null + * @var Closure|null */ protected $callback; @@ -50,12 +51,12 @@ class Validator implements ValidatorInterface * * @param ValidatorContract $validator * @param ErrorTranslator $translator - * @param \Closure|null $callback + * @param Closure|null $callback */ public function __construct( ValidatorContract $validator, ErrorTranslator $translator, - \Closure $callback = null + ?Closure $callback = null ) { $this->validator = $validator; $this->translator = $translator; diff --git a/tests/lib/Integration/Client/TestCase.php b/tests/lib/Integration/Client/TestCase.php index b47c2331..aea3689d 100644 --- a/tests/lib/Integration/Client/TestCase.php +++ b/tests/lib/Integration/Client/TestCase.php @@ -83,7 +83,7 @@ protected function willSeeIdentifiers($data, $status = 200, array $headers = []) * @param array $headers * @return Response */ - protected function willSeeResponse(array $json = null, $status = 200, array $headers = []) + protected function willSeeResponse(?array $json = null, $status = 200, array $headers = []) { if ($json) { $body = json_encode($json); diff --git a/tests/lib/Integration/Http/Controllers/TestEvent.php b/tests/lib/Integration/Http/Controllers/TestEvent.php index a7a7a7aa..da25c2c1 100644 --- a/tests/lib/Integration/Http/Controllers/TestEvent.php +++ b/tests/lib/Integration/Http/Controllers/TestEvent.php @@ -58,7 +58,7 @@ class TestEvent public function __construct( $hook, $record, - ValidatedRequest $request = null, + ?ValidatedRequest $request = null, $related = null ) { $this->hook = $hook; diff --git a/tests/lib/Unit/View/RendererTest.php b/tests/lib/Unit/View/RendererTest.php index 5dea7b12..8f81fb08 100644 --- a/tests/lib/Unit/View/RendererTest.php +++ b/tests/lib/Unit/View/RendererTest.php @@ -122,7 +122,7 @@ public function testEncodeWithParameters() * @param QueryParameters|null $parameters * @return object */ - private function withEncoder($name = null, $options = 0, $depth = 512, QueryParameters $parameters = null) + private function withEncoder($name = null, $options = 0, $depth = 512, ?QueryParameters $parameters = null) { $post = (object) ['type' => 'posts', 'id' => '1'];