From c0626cdb5b1a149a1477e3e8e42afd986eeb2cd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanislav=20Janu=CC=8A?= Date: Thu, 28 Nov 2024 14:04:23 +0100 Subject: [PATCH] PHP 8.4 deprecations fix --- src/Authentication/OAuth2Client.php | 2 +- src/BatchRequest.php | 15 ++++---- src/Client.php | 2 +- src/Exception/ResponseException.php | 2 +- src/Facebook.php | 38 ++++++++++----------- src/GraphNode/GraphNodeFactory.php | 20 +++++------ src/Helper/RedirectLoginHelper.php | 6 ++-- src/Helper/SignedRequestFromInputHelper.php | 2 +- src/Http/RequestBodyMultipart.php | 2 +- src/Request.php | 12 +++---- src/Response.php | 4 +-- src/SignedRequest.php | 2 +- 12 files changed, 54 insertions(+), 53 deletions(-) diff --git a/src/Authentication/OAuth2Client.php b/src/Authentication/OAuth2Client.php index 6e91ddf..9872d75 100755 --- a/src/Authentication/OAuth2Client.php +++ b/src/Authentication/OAuth2Client.php @@ -221,7 +221,7 @@ protected function requestAnAccessToken(array $params): AccessToken protected function sendRequestWithClientParams( string $endpoint, array $params, - AccessToken|string $accessToken = null, + AccessToken|string|null $accessToken = null, ): Response { $params += $this->getClientParams(); diff --git a/src/BatchRequest.php b/src/BatchRequest.php index b4774a1..33da83d 100755 --- a/src/BatchRequest.php +++ b/src/BatchRequest.php @@ -47,9 +47,9 @@ class BatchRequest extends Request implements IteratorAggregate, ArrayAccess * @param Request[] $requests */ public function __construct( - Application $application = null, + ?Application $application = null, array $requests = [], - AccessToken|string $accessToken = null, + AccessToken|string|null $accessToken = null, ?string $graphVersion = null, ) { parent::__construct($application, $accessToken, 'POST', '', [], null, $graphVersion); @@ -221,15 +221,16 @@ public function validateBatchRequestCount(): void /** * Converts a Request entity into an array that is batch-friendly. * - * @param Request $request the request entity to convert - * @param mixed[]|string $options Array of batch request options e.g. 'name', 'omit_response_on_success'. If a string is given, it is the value of the 'name' option. - * @param string|null $attachedFiles names of files associated with the request + * @param Request $request the request entity to convert + * @param string|mixed[]|null $options Array of batch request options e.g. 'name', 'omit_response_on_success'. If a string is given, it is the value of the 'name' option. + * @param string|null $attachedFiles names of files associated with the request + * * @return mixed[] */ public function requestEntityToBatchArray( Request $request, - array|string $options = null, - string $attachedFiles = null, + array|string|null $options = null, + ?string $attachedFiles = null, ): array { if ($options === null) { diff --git a/src/Client.php b/src/Client.php index dde6f2d..ae3e3c7 100755 --- a/src/Client.php +++ b/src/Client.php @@ -60,7 +60,7 @@ class Client * Instantiates a new Client object. */ public function __construct( - ClientInterface $httpClient = null, + ?ClientInterface $httpClient = null, protected bool $enableBetaMode = false, ) { $this->httpClient = $httpClient ?? Psr18ClientDiscovery::find(); diff --git a/src/Exception/ResponseException.php b/src/Exception/ResponseException.php index bd85e9c..8f8810b 100755 --- a/src/Exception/ResponseException.php +++ b/src/Exception/ResponseException.php @@ -32,7 +32,7 @@ class ResponseException extends SDKException public function __construct( protected Response $response, - SDKException $sdkException = null, + ?SDKException $sdkException = null, ) { $this->responseData = $response->getDecodedBody(); diff --git a/src/Facebook.php b/src/Facebook.php index b750256..31a5ddc 100755 --- a/src/Facebook.php +++ b/src/Facebook.php @@ -289,9 +289,9 @@ public function getPageTabHelper(): PageTabHelper */ public function get( string $endpoint, - AccessToken|string $accessToken = null, - string $eTag = null, - string $graphVersion = null, + AccessToken|string|null $accessToken = null, + ?string $eTag = null, + ?string $graphVersion = null, ): Response { return $this->sendRequest('GET', $endpoint, [], $accessToken, $eTag, $graphVersion); @@ -306,9 +306,9 @@ public function get( public function post( string $endpoint, array $params = [], - AccessToken|string $accessToken = null, - string $eTag = null, - string $graphVersion = null, + AccessToken|string|null $accessToken = null, + ?string $eTag = null, + ?string $graphVersion = null, ): Response { return $this->sendRequest('POST', $endpoint, $params, $accessToken, $eTag, $graphVersion); @@ -323,9 +323,9 @@ public function post( public function delete( string $endpoint, array $params = [], - AccessToken|string $accessToken = null, - string $eTag = null, - string $graphVersion = null, + AccessToken|string|null $accessToken = null, + ?string $eTag = null, + ?string $graphVersion = null, ): Response { return $this->sendRequest('DELETE', $endpoint, $params, $accessToken, $eTag, $graphVersion); @@ -392,9 +392,9 @@ public function sendRequest( string $method, string $endpoint, array $params = [], - AccessToken|string $accessToken = null, - string $eTag = null, - string $graphVersion = null, + AccessToken|string|null $accessToken = null, + ?string $eTag = null, + ?string $graphVersion = null, ): Response { $accessToken ??= $this->defaultAccessToken; @@ -413,8 +413,8 @@ public function sendRequest( */ public function sendBatchRequest( array $requests, - AccessToken|string $accessToken = null, - string $graphVersion = null, + AccessToken|string|null $accessToken = null, + ?string $graphVersion = null, ): BatchResponse { $accessToken ??= $this->defaultAccessToken; @@ -433,7 +433,7 @@ public function sendBatchRequest( */ public function newBatchRequest( AccessToken|string|null $accessToken = null, - string $graphVersion = null, + ?string $graphVersion = null, ): BatchRequest { $accessToken ??= $this->defaultAccessToken; @@ -454,9 +454,9 @@ public function request( string $method, string $endpoint, array $params = [], - AccessToken|string $accessToken = null, - string $eTag = null, - string $graphVersion = null, + AccessToken|string|null $accessToken = null, + ?string $eTag = null, + ?string $graphVersion = null, ): Request { $accessToken ??= $this->defaultAccessToken; @@ -507,7 +507,7 @@ public function uploadVideo( array $metadata = [], string|AccessToken|null $accessToken = null, int $maxTransferTries = 5, - string $graphVersion = null, + ?string $graphVersion = null, ): array { $accessToken ??= $this->defaultAccessToken; diff --git a/src/GraphNode/GraphNodeFactory.php b/src/GraphNode/GraphNodeFactory.php index 648eaf3..beefe00 100755 --- a/src/GraphNode/GraphNodeFactory.php +++ b/src/GraphNode/GraphNodeFactory.php @@ -80,7 +80,7 @@ public function __construct( * @throws SDKException */ public function makeGraphNode( - string $subclassName = null, + ?string $subclassName = null, ): GraphNode { $this->validateResponseCastableAsGraphNode(); @@ -97,7 +97,7 @@ public function makeGraphNode( * * @throws SDKException */ - public function makeGraphEdge(string $subclassName = null, bool $auto_prefix = true): GraphEdge + public function makeGraphEdge(?string $subclassName = null, bool $auto_prefix = true): GraphEdge { $this->validateResponseCastableAsGraphEdge(); @@ -141,7 +141,7 @@ public function validateResponseCastableAsGraphEdge(): void * * @throws SDKException */ - public function safelyMakeGraphNode(array $data, string $subclassName = null): GraphNode + public function safelyMakeGraphNode(array $data, ?string $subclassName = null): GraphNode { $subclassName ??= static::BaseGraphNodeClass; static::validateSubclass($subclassName); @@ -174,18 +174,18 @@ public function safelyMakeGraphNode(array $data, string $subclassName = null): G /** * Takes an array of values and determines how to cast each node. * - * @param array $data the array of data to iterate over - * @param string|null $subclassName the subclass to cast this collection to - * @param string|int $parentKey the key of this data (Graph edge) - * @param string|null $parentNodeId the parent Graph node ID + * @param array $data the array of data to iterate over + * @param string|null $subclassName the subclass to cast this collection to + * @param string|int|null $parentKey the key of this data (Graph edge) + * @param string|null $parentNodeId the parent Graph node ID * * @throws SDKException */ public function castAsGraphNodeOrGraphEdge( array $data, - string $subclassName = null, - string|int $parentKey = null, - string $parentNodeId = null, + ?string $subclassName = null, + string|int|null $parentKey = null, + ?string $parentNodeId = null, ): GraphEdge|GraphNode { if (isset($data['data'])) { diff --git a/src/Helper/RedirectLoginHelper.php b/src/Helper/RedirectLoginHelper.php index eabee0a..68291ef 100755 --- a/src/Helper/RedirectLoginHelper.php +++ b/src/Helper/RedirectLoginHelper.php @@ -50,8 +50,8 @@ class RedirectLoginHelper */ public function __construct( protected OAuth2Client $oAuth2Client, - PersistentDataInterface $persistentData = null, - UrlDetectionInterface $urlDetection = null, + ?PersistentDataInterface $persistentData = null, + ?UrlDetectionInterface $urlDetection = null, ) { $this->persistentDataHandler = $persistentData ?? new SessionPersistentDataHandler; $this->urlDetectionHandler = $urlDetection ?? new UrlDetectionHandler; @@ -177,7 +177,7 @@ public function getReAuthenticationUrl(string $redirectUrl, array $scope = [], s * * @throws SDKException */ - public function getAccessToken(string $redirectUrl = null): ?AccessToken + public function getAccessToken(?string $redirectUrl = null): ?AccessToken { $code = $this->getCode(); if ($code === null) { diff --git a/src/Helper/SignedRequestFromInputHelper.php b/src/Helper/SignedRequestFromInputHelper.php index 98692da..4e2d01f 100755 --- a/src/Helper/SignedRequestFromInputHelper.php +++ b/src/Helper/SignedRequestFromInputHelper.php @@ -57,7 +57,7 @@ public function __construct( /** * Instantiates a new SignedRequest entity. */ - public function instantiateSignedRequest(string $rawSignedRequest = null): void + public function instantiateSignedRequest(?string $rawSignedRequest = null): void { $rawSignedRequest ??= $this->getRawSignedRequest(); diff --git a/src/Http/RequestBodyMultipart.php b/src/Http/RequestBodyMultipart.php index c043ec9..53a9d2a 100755 --- a/src/Http/RequestBodyMultipart.php +++ b/src/Http/RequestBodyMultipart.php @@ -47,7 +47,7 @@ class RequestBodyMultipart implements RequestBodyInterface public function __construct( private readonly array $params = [], private readonly array $files = [], - string $boundary = null, + ?string $boundary = null, ) { $this->boundary = $boundary ?? uniqid(); } diff --git a/src/Request.php b/src/Request.php index 4259860..6800adf 100755 --- a/src/Request.php +++ b/src/Request.php @@ -68,12 +68,12 @@ class Request * @throws SDKException */ public function __construct( - Application $application = null, - AccessToken|string $accessToken = null, - string $method = null, - string $endpoint = null, + ?Application $application = null, + AccessToken|string|null $accessToken = null, + ?string $method = null, + ?string $endpoint = null, array $params = [], - string $eTag = null, + ?string $eTag = null, protected ?string $graphVersion = null, ) { $this->setApp($application); @@ -135,7 +135,7 @@ public function getAccessTokenEntity(): ?AccessToken /** * Set the Application entity used for this request. */ - public function setApp(Application $application = null): void + public function setApp(?Application $application = null): void { $this->app = $application; } diff --git a/src/Response.php b/src/Response.php index 013240f..428d94d 100755 --- a/src/Response.php +++ b/src/Response.php @@ -222,7 +222,7 @@ public function decodeBody(): void * * @throws SDKException */ - public function getGraphNode(string $subclassName = null): GraphNode + public function getGraphNode(?string $subclassName = null): GraphNode { $graphNodeFactory = new GraphNodeFactory($this); @@ -238,7 +238,7 @@ public function getGraphNode(string $subclassName = null): GraphNode * * @throws SDKException */ - public function getGraphEdge(string $subclassName = null, bool $auto_prefix = true): GraphEdge + public function getGraphEdge(?string $subclassName = null, bool $auto_prefix = true): GraphEdge { $graphNodeFactory = new GraphNodeFactory($this); diff --git a/src/SignedRequest.php b/src/SignedRequest.php index 59b28d8..529ed1b 100755 --- a/src/SignedRequest.php +++ b/src/SignedRequest.php @@ -47,7 +47,7 @@ class SignedRequest */ public function __construct( protected Application $application, - string $rawSignedRequest = null, + ?string $rawSignedRequest = null, ) { if ($rawSignedRequest === null) { return;