Skip to content

fix: remove PHP 8.4 deprecation warning #167

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

Closed
wants to merge 4 commits into from
Closed
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/test-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
timeout-minutes: 20
strategy:
matrix:
php: [ '7.3', '7.4', '8.0', '8.1' ]
php: [ '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]
dependencies:
- "lowest"
- "highest"
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ We welcome direct contributions to the php-http-client code base. Thank you!

##### Prerequisites #####

- PHP version 7.3, 7.4, 8.0, or 8.1
- PHP version 7.3+
- [Composer](https://getcomposer.org/)

##### Initial setup: #####
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (C) 2023, Twilio SendGrid, Inc. <[email protected]>
Copyright (C) 2025, Twilio SendGrid, Inc. <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ All updates to this library are documented in our [CHANGELOG](CHANGELOG.md).

## Prerequisites

- PHP version 7.3, 7.4, 8.0, or 8.1
- PHP version 7.3+

## Install with Composer

Expand Down
60 changes: 34 additions & 26 deletions lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,22 +217,30 @@ class Client
/**
* Initialize the client.
*
* @param string $host the base url (e.g. https://api.sendgrid.com)
* @param array $headers global request headers
* @param string $version api version (configurable) - this is specific to the SendGrid API
* @param array $path holds the segments of the url path
* @param array $curlOptions extra options to set during curl initialization
* @param bool $retryOnLimit set default retry on limit flag
* @param bool $verifySSLCerts set default verify certificates flag
/**
* @param string $host The base URL (e.g., https://api.sendgrid.com).
* @param array|null $headers Global request headers. If provided, these headers will be included in every request.
* @param string|null $version API version (configurable). This is specific to the SendGrid API.
* @param array|null $path Holds the segments of the URL path.
* @param array|null $curlOptions Extra options to set during cURL initialization.
* @param bool $retryOnLimit Set default retry on limit flag.
* @param bool $verifySSLCerts Set default verify SSL certificates flag.
*/
* @param array|null $headers global request headers
* @param string|null $version api version (configurable) - this is specific to the SendGrid API
* @param array|null $path holds the segments of the url path
* @param array|null $curlOptions extra options to set during curl initialization
* @param bool $retryOnLimit set default retry on limit flag
* @param bool $verifySSLCerts set default verify certificates flag
*/
public function __construct(
$host,
$headers = null,
$version = null,
$path = null,
$curlOptions = null,
$retryOnLimit = false,
$verifySSLCerts = true
?array $headers = null,
?string $version = null,
?array $path = null,
?array $curlOptions = null,
bool $retryOnLimit = false,
bool $verifySSLCerts = true
) {
$this->host = $host;
$this->headers = $headers ?: [];
Expand Down Expand Up @@ -263,7 +271,7 @@ public function getHost()
public function setHost(string $host)
{
$this->host = $host;

return $this;
}

Expand Down Expand Up @@ -358,13 +366,13 @@ public function setIsConcurrentRequest($isConcurrent)
/**
* Build the final URL to be passed.
*
* @param array $queryParams an array of all the query parameters
* @param array|null \$queryParams An array of all the query parameters.
*
* Nested arrays will resolve to multiple instances of the same parameter
*
* @return string
*/
private function buildUrl($queryParams = null)
private function buildUrl(?array $queryParams = null)
{
$path = '/' . implode('/', $this->path);
if (isset($queryParams)) {
Expand All @@ -380,12 +388,12 @@ private function buildUrl($queryParams = null)
* this function does not mutate any private variables.
*
* @param string $method
* @param array $body
* @param array $headers
* @param array|null $body
* @param array|null $headers
*
* @return array
*/
private function createCurlOptions($method, $body = null, $headers = null)
private function createCurlOptions($method, ?array $body = null, ?array $headers = null)
{
$options = [
CURLOPT_RETURNTRANSFER => true,
Expand Down Expand Up @@ -498,17 +506,17 @@ private function retryRequest(array $responseHeaders, $method, $url, $body, $hea
* Make the API call and return the response.
* This is separated into it's own function, so we can mock it easily for testing.
*
* @param string $method the HTTP verb
* @param string $url the final url to call
* @param array $body request body
* @param array $headers any additional request headers
* @param bool $retryOnLimit should retry if rate limit is reach?
* @param string $method the HTTP verb
Copy link

@manisha1997 manisha1997 Apr 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param string $method the HTTP verb
* @param string $method The HTTP verb.
* @param string $url The final URL to call.
* @param array|null $body The request body.
* @param array|null $headers Any additional request headers.
* @param bool $retryOnLimit Should retry if the rate limit is reached?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add backslashes before the parameter names?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

* @param string $url the final url to call
* @param array|null $body request body
* @param array|null $headers any additional request headers
* @param bool $retryOnLimit should retry if rate limit is reach?
*
* @return Response object
*
* @throws InvalidRequest
*/
public function makeRequest($method, $url, $body = null, $headers = null, $retryOnLimit = false)
public function makeRequest($method, $url, ?array $body = null, ?array $headers = null, $retryOnLimit = false)
{
$channel = curl_init($url);

Expand Down Expand Up @@ -604,7 +612,7 @@ public function makeAllRequests(array $requests = [])
*
* @return Client object
*/
public function _($name = null)
public function _(?string $name = null)
{
if (isset($name)) {
$this->path[] = $name;
Expand Down
2 changes: 1 addition & 1 deletion lib/Exception/InvalidRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class InvalidRequest extends \Exception
public function __construct(
$message = '',
$code = 0,
\Exception $previous = null
?\Exception $previous = null
) {
$message = 'Could not send request to server. ' .
'CURL error ' . $code . ': ' . $message;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/MockClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MockClient extends Client
public $requestHeaders;
public $url;

public function makeRequest($method, $url, $requestBody = null, $requestHeaders = null, $retryOnLimit = false)
public function makeRequest($method, $url, ?array $requestBody = null, ?array $requestHeaders = null, $retryOnLimit = false)
{
$this->requestBody = $requestBody;
$this->requestHeaders = $requestHeaders;
Expand Down
Loading