Skip to content

Commit

Permalink
fix: add PHP 8.4 compatibility to last release compatible with PHP 7.4 (
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer authored Dec 11, 2024
1 parent 54a863e commit e400e24
Show file tree
Hide file tree
Showing 19 changed files with 45 additions and 45 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ "7.4", "8.0", "8.1", "8.2", "8.3" ]
php: [ "7.4", "8.0", "8.1", "8.2", "8.3", "8.4" ]
extensions: [""]
tools: [""]
composerflags: [""]
Expand Down Expand Up @@ -74,5 +74,5 @@ jobs:
- name: Run Script
run: |
composer install
composer global require phpstan/phpstan
composer global require phpstan/phpstan:^1.0
~/.composer/vendor/bin/phpstan analyse
12 changes: 6 additions & 6 deletions src/ApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ApiException extends Exception
public function __construct(
string $message,
int $code,
string $status = null,
?string $status = null,
array $optionalArgs = []
) {
$optionalArgs += [
Expand Down Expand Up @@ -163,8 +163,8 @@ public static function createFromStdClass(stdClass $status)
public static function createFromApiResponse(
$basicMessage,
$rpcCode,
array $metadata = null,
Exception $previous = null
?array $metadata = null,
?Exception $previous = null
) {
return self::create(
$basicMessage,
Expand All @@ -187,8 +187,8 @@ public static function createFromApiResponse(
public static function createFromRestApiResponse(
$basicMessage,
$rpcCode,
array $metadata = null,
Exception $previous = null
?array $metadata = null,
?Exception $previous = null
) {
return self::create(
$basicMessage,
Expand Down Expand Up @@ -244,7 +244,7 @@ private static function create(
int $rpcCode,
$metadata,
array $decodedMetadata,
Exception $previous = null
?Exception $previous = null
) {
$containsErrorInfo = self::containsErrorInfo($decodedMetadata);
$rpcStatus = ApiStatus::statusFromRpcCode($rpcCode);
Expand Down
2 changes: 1 addition & 1 deletion src/Call.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Call
*/
public function __construct(
string $method,
string $decodeType = null,
?string $decodeType = null,
$message = null,
$descriptor = [],
int $callType = Call::UNARY_CALL
Expand Down
14 changes: 7 additions & 7 deletions src/CredentialsWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class CredentialsWrapper implements ProjectIdProviderInterface
*/
public function __construct(
FetchAuthTokenInterface $credentialsFetcher,
callable $authHttpHandler = null,
?callable $authHttpHandler = null,
string $universeDomain = GetUniverseDomainInterface::DEFAULT_UNIVERSE_DOMAIN
) {
$this->credentialsFetcher = $credentialsFetcher;
Expand Down Expand Up @@ -203,7 +203,7 @@ public function getQuotaProject()
return null;
}

public function getProjectId(callable $httpHandler = null): ?string
public function getProjectId(?callable $httpHandler = null): ?string
{
// Ensure that FetchAuthTokenCache does not throw an exception
if ($this->credentialsFetcher instanceof FetchAuthTokenCache
Expand Down Expand Up @@ -313,12 +313,12 @@ private static function buildHttpHandlerFactory()
* @throws ValidationException
*/
private static function buildApplicationDefaultCredentials(
array $scopes = null,
callable $authHttpHandler = null,
array $authCacheOptions = null,
CacheItemPoolInterface $authCache = null,
?array $scopes = null,
?callable $authHttpHandler = null,
?array $authCacheOptions = null,
?CacheItemPoolInterface $authCache = null,
$quotaProject = null,
array $defaultScopes = null
?array $defaultScopes = null
) {
try {
return ApplicationDefaultCredentials::getCredentials(
Expand Down
20 changes: 10 additions & 10 deletions src/GapicClientTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ private function createTransport(
string $apiEndpoint,
$transport,
$transportConfig,
callable $clientCertSource = null
?callable $clientCertSource = null
) {
if (!is_string($transport)) {
throw new ValidationException(
Expand Down Expand Up @@ -511,7 +511,7 @@ private function startAsyncCall(
*/
private function startApiCall(
string $methodName,
Message $request = null,
?Message $request = null,
array $optionalArgs = []
) {
$methodDescriptors =$this->validateCallConfig($methodName);
Expand Down Expand Up @@ -573,9 +573,9 @@ private function startCall(
string $methodName,
string $decodeType,
array $optionalArgs = [],
Message $request = null,
?Message $request = null,
int $callType = Call::UNARY_CALL,
string $interfaceName = null
?string $interfaceName = null
) {
$optionalArgs = $this->configureCallOptions($optionalArgs);
$callStack = $this->createCallStack(
Expand Down Expand Up @@ -713,8 +713,8 @@ private function startOperationsCall(
array $optionalArgs,
Message $request,
$client,
string $interfaceName = null,
string $operationClass = null
?string $interfaceName = null,
?string $operationClass = null
) {
$optionalArgs = $this->configureCallOptions($optionalArgs);
$callStack = $this->createCallStack(
Expand Down Expand Up @@ -769,7 +769,7 @@ private function getPagedListResponse(
array $optionalArgs,
string $decodeType,
Message $request,
string $interfaceName = null
?string $interfaceName = null
) {
return $this->getPagedListResponseAsync(
$methodName,
Expand All @@ -794,7 +794,7 @@ private function getPagedListResponseAsync(
array $optionalArgs,
string $decodeType,
Message $request,
string $interfaceName = null
?string $interfaceName = null
) {
$optionalArgs = $this->configureCallOptions($optionalArgs);
$callStack = $this->createCallStack(
Expand Down Expand Up @@ -825,7 +825,7 @@ private function getPagedListResponseAsync(
*
* @return string
*/
private function buildMethod(string $interfaceName = null, string $methodName = null)
private function buildMethod(?string $interfaceName = null, ?string $methodName = null)
{
return sprintf(
'%s/%s',
Expand All @@ -840,7 +840,7 @@ private function buildMethod(string $interfaceName = null, string $methodName =
*
* @return array
*/
private function buildRequestParamsHeader(array $headerParams, Message $request = null)
private function buildRequestParamsHeader(array $headerParams, ?Message $request = null)
{
$headers = [];

Expand Down
2 changes: 1 addition & 1 deletion src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function getNextPageToken()
* @throws ApiException if the call to fetch the next page fails.
* @return Page
*/
public function getNextPage(int $pageSize = null)
public function getNextPage(?int $pageSize = null)
{
if (!$this->hasNextPage()) {
throw new ValidationException(
Expand Down
2 changes: 1 addition & 1 deletion src/PathTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class PathTemplate implements ResourceTemplateInterface
* @param string $path A path template string
* @throws ValidationException When $path cannot be parsed into a valid PathTemplate
*/
public function __construct(string $path = null)
public function __construct(?string $path = null)
{
if (empty($path)) {
throw new ValidationException('Cannot construct PathTemplate from empty string');
Expand Down
2 changes: 1 addition & 1 deletion src/RequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private function buildBindings(array $placeholders, Message $message)
foreach ($placeholders as $placeholder => $metadata) {
$value = array_reduce(
$metadata['getters'],
function (Message $result = null, $getter) {
function (?Message $result = null, $getter = null) {
if ($result) {
return $result->$getter();
}
Expand Down
2 changes: 1 addition & 1 deletion src/ResourceHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private static function getPathTemplate(string $key)
return self::$templateMap[$key] ?? null;
}

private static function parseFormattedName(string $formattedName, string $template = null): array
private static function parseFormattedName(string $formattedName, ?string $template = null): array
{
if (is_null(self::$templateMap)) {
self::registerPathTemplates();
Expand Down
2 changes: 1 addition & 1 deletion src/ResourceTemplate/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Parser
* @return array
* @throws ValidationException
*/
public static function parseSegments(string $path = null)
public static function parseSegments(?string $path = null)
{
if (empty($path)) {
throw new ValidationException("Cannot parse empty path");
Expand Down
2 changes: 1 addition & 1 deletion src/ResourceTemplate/RelativeResourceTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ private function renderingException(array $bindings, string $reason)
* @param string|null $separator An optional string separator
* @return array[] A list of [string, Segment] tuples
*/
private static function buildKeySegmentTuples(array $segments, string $separator = null)
private static function buildKeySegmentTuples(array $segments, ?string $separator = null)
{
$keySegmentTuples = [];
$positionalArgumentCounter = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/ResourceTemplate/Segment.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ class Segment
*/
public function __construct(
int $segmentType,
string $value = null,
string $key = null,
RelativeResourceTemplate $template = null,
?string $value = null,
?string $key = null,
?RelativeResourceTemplate $template = null,
string $separator = '/'
) {
$this->segmentType = $segmentType;
Expand Down
2 changes: 1 addition & 1 deletion src/Testing/MockBidiStreamingCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class MockBidiStreamingCall extends Grpc\BidiStreamingCall
* @param mixed|null $deserialize An optional deserialize method for the response object.
* @param stdClass|null $status An optional status object. If set to null, a status of OK is used.
*/
public function __construct(array $responses, $deserialize = null, stdClass $status = null)
public function __construct(array $responses, $deserialize = null, ?stdClass $status = null)
{
$this->responses = $responses;
$this->deserialize = $deserialize;
Expand Down
2 changes: 1 addition & 1 deletion src/Testing/MockClientStreamingCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class MockClientStreamingCall extends Grpc\ClientStreamingCall
* @param callable|array|null $deserialize An optional deserialize method for the response object.
* @param stdClass|null $status An optional status object. If set to null, a status of OK is used.
*/
public function __construct($response, $deserialize = null, stdClass $status = null)
public function __construct($response, $deserialize = null, ?stdClass $status = null)
{
$this->mockUnaryCall = new MockUnaryCall($response, $deserialize, $status);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Testing/MockServerStreamingCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MockServerStreamingCall extends \Grpc\ServerStreamingCall implements Serve
* @param callable|array|null $deserialize An optional deserialize method for the response object.
* @param stdClass|null $status An optional status object. If set to null, a status of OK is used.
*/
public function __construct(array $responses, $deserialize = null, stdClass $status = null)
public function __construct(array $responses, $deserialize = null, ?stdClass $status = null)
{
$this->responses = $responses;
$this->deserialize = $deserialize;
Expand Down
2 changes: 1 addition & 1 deletion src/Testing/MockStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MockStatus extends stdClass
public $code;
public $details;
public $metadata;
public function __construct($code, string $details = null, array $metadata = [])
public function __construct($code, ?string $details = null, array $metadata = [])
{
$this->code = $code;
$this->details = $details;
Expand Down
8 changes: 4 additions & 4 deletions src/Testing/MockStubTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ trait MockStubTrait
private $callObjects = [];
private $deserialize;

public function __construct(callable $deserialize = null)
public function __construct(?callable $deserialize = null)
{
$this->deserialize = $deserialize;
}
Expand Down Expand Up @@ -196,7 +196,7 @@ public static function stripStatusFromResponses($responses)
* @param \Google\Protobuf\Internal\Message $response
* @param stdClass $status
*/
public function addResponse($response, stdClass $status = null)
public function addResponse($response, ?stdClass $status = null)
{
if (!$this->deserialize && $response) {
$this->deserialize = [get_class($response), 'decode'];
Expand Down Expand Up @@ -263,7 +263,7 @@ public function isExhausted()
* @param callable $deserialize
* @return static An instance of the current class type.
*/
public static function create($responseObject, stdClass $status = null, callable $deserialize = null)
public static function create($responseObject, ?stdClass $status = null, ?callable $deserialize = null)
{
$stub = new static($deserialize); // @phpstan-ignore-line
$stub->addResponse($responseObject, $status);
Expand All @@ -277,7 +277,7 @@ public static function create($responseObject, stdClass $status = null, callable
* @param stdClass $finalStatus
* @return static An instance of the current class type.
*/
public static function createWithResponseSequence(array $sequence, callable $deserialize = null, stdClass $finalStatus = null)
public static function createWithResponseSequence(array $sequence, ?callable $deserialize = null, ?stdClass $finalStatus = null)
{
$stub = new static($deserialize); // @phpstan-ignore-line
foreach ($sequence as $elem) {
Expand Down
2 changes: 1 addition & 1 deletion src/Testing/MockUnaryCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class MockUnaryCall extends \Grpc\UnaryCall
* @param callable|array|null $deserialize An optional deserialize method for the response object.
* @param stdClass|null $status An optional status object. If set to null, a status of OK is used.
*/
public function __construct($response = null, $deserialize = null, stdClass $status = null)
public function __construct($response = null, $deserialize = null, ?stdClass $status = null)
{
$this->response = $response;
$this->deserialize = $deserialize;
Expand Down
2 changes: 1 addition & 1 deletion src/Transport/GrpcTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class GrpcTransport extends BaseStub implements TransportInterface
* extends {@see Grpc\Interceptor}.
* @throws Exception
*/
public function __construct(string $hostname, array $opts, Channel $channel = null, array $interceptors = [])
public function __construct(string $hostname, array $opts, ?Channel $channel = null, array $interceptors = [])
{
if ($interceptors) {
$channel = Interceptor::intercept(
Expand Down

0 comments on commit e400e24

Please sign in to comment.