Skip to content

Feature: support PHP 8.4 by removing deprecation notices #649

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2025
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Broadcasting/BroadcastsData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/Client/AbstractClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ abstract class AbstractClient implements ClientInterface
abstract protected function request(
$method,
$uri,
array $payload = null,
?array $payload = null,
array $parameters = []
);

Expand Down
2 changes: 1 addition & 1 deletion src/Client/GuzzleClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/Codec/Encoding.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Encoding
public static function create(
$mediaType,
int $options = 0,
string $urlPrefix = null,
?string $urlPrefix = null,
int $depth = 512
): self
{
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Codec/EncodingList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/Schema/SchemaProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions src/Document/Error/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 8 additions & 7 deletions src/Document/Error/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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(
Expand All @@ -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);
}
Expand Down
15 changes: 8 additions & 7 deletions src/Eloquent/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Encoder/EncoderOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions src/Exceptions/ClientException.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace CloudCreativity\LaravelJsonApi\Exceptions;

use Exception;
use Illuminate\Support\Collection;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -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.',
Expand Down Expand Up @@ -104,7 +105,7 @@ public function getErrors()

try {
$this->errors = $this->parse();
} catch (\Exception $ex) {
} catch (Exception $ex) {
$this->errors = [];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/DocumentRequiredException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/Exceptions/InvalidJsonException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/Exceptions/JsonApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/Exceptions/ResourceNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace CloudCreativity\LaravelJsonApi\Exceptions;

use Exception;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class ResourceNotFoundException extends NotFoundHttpException
Expand All @@ -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 = []
) {
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/ValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading
Loading