Skip to content

Commit 9f0625b

Browse files
committed
Fix style issues
1 parent 7458a48 commit 9f0625b

File tree

6 files changed

+40
-9
lines changed

6 files changed

+40
-9
lines changed

BigQuery/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"minimum-stability": "stable",
66
"require": {
77
"php": "^8.1",
8-
"google/cloud-core": "^1.64",
8+
"google/cloud-core": "^1.65",
99
"ramsey/uuid": "^3.0|^4.0"
1010
},
1111
"require-dev": {

BigQuery/src/BigQueryClient.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,10 +1100,9 @@ private function getLogger(array $config): LoggerInterface|false|null
11001100
return ApplicationDefaultCredentials::getDefaultLogger();
11011101
}
11021102

1103-
if (
1104-
$configuration !== null &&
1105-
$configuration !== false &&
1106-
!$configuration instanceof LoggerInterface
1103+
if ($configuration !== null
1104+
&& $configuration !== false
1105+
&& !$configuration instanceof LoggerInterface
11071106
) {
11081107
throw new ValidationException(
11091108
'The "logger" option in the options array should be PSR-3 LoggerInterface compatible.'

BigQuery/src/Connection/Rest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ public function testTableIamPermissions(array $args = [])
432432
private function getRequestWrapper(array $config): RequestWrapper
433433
{
434434
// Because we are setting a logger, we build a handler here instead of using the default
435-
$config['httpHandler'] = $config['httpHandler'] ?? HttpHandlerFactory::build(logger:$config['logger']);
435+
$config['httpHandler'] = $config['httpHandler'] ?? HttpHandlerFactory::build(logger: $config['logger']);
436436
$config['restRetryListener'] = $this->getRetryListener();
437437
return new RequestWrapper($config);
438438
}

BigQuery/tests/Unit/BigQueryClientTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ public function testRetryLogging()
777777
$retryHeaderAppeared = false;
778778
$logger = $this->prophesize(LoggerInterface::class);
779779
$logger->debug(
780-
Argument::that(function(string $jsonString) use (&$retryHeaderAppeared) {
780+
Argument::that(function (string $jsonString) use (&$retryHeaderAppeared) {
781781
$jsonParsed = json_decode($jsonString, true);
782782
if (isset($jsonParsed['jsonPayload']['retryAttempt'])) {
783783
$retryHeaderAppeared = true;

Core/src/RequestWrapper.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ class RequestWrapper
8383
*/
8484
private $retryFunction;
8585

86+
/**
87+
* @var callable|null Lets the user listen for retries and
88+
* modify the next retry arguments
89+
*/
90+
private $retryListener;
91+
8692
/**
8793
* @var callable Executes a delay.
8894
*/
@@ -136,6 +142,8 @@ class RequestWrapper
136142
* determining how long to wait between attempts to retry. Function
137143
* signature should match: `function (int $attempt) : int`.
138144
* @type string $universeDomain The expected universe of the credentials. Defaults to "googleapis.com".
145+
* @type callable $restRetryListener A function to run custom logic between retries. This function can modify
146+
* the next server call arguments for the next retry.
139147
* }
140148
*/
141149
public function __construct(array $config = [])
@@ -151,6 +159,7 @@ public function __construct(array $config = [])
151159
'componentVersion' => null,
152160
'restRetryFunction' => null,
153161
'restDelayFunction' => null,
162+
'restRetryListener' => null,
154163
'restCalcDelayFunction' => null,
155164
'universeDomain' => GetUniverseDomainInterface::DEFAULT_UNIVERSE_DOMAIN,
156165
];
@@ -160,6 +169,7 @@ public function __construct(array $config = [])
160169
$this->restOptions = $config['restOptions'];
161170
$this->shouldSignRequest = $config['shouldSignRequest'];
162171
$this->retryFunction = $config['restRetryFunction'] ?: $this->getRetryFunction();
172+
$this->retryListener = $config['restRetryListener'];
163173
$this->delayFunction = $config['restDelayFunction'] ?: function ($delay) {
164174
usleep($delay);
165175
};
@@ -362,7 +372,7 @@ private function applyHeaders(RequestInterface $request, array $options = [])
362372
*/
363373
private function addAuthHeaders(RequestInterface $request, FetchAuthTokenInterface $fetcher)
364374
{
365-
$backoff = new ExponentialBackoff($this->retries, $this->getRetryFunction());
375+
$backoff = new ExponentialBackoff($this->retries, $this->getRetryFunction(), $this->retryListener);
366376

367377
try {
368378
return $backoff->execute(
@@ -485,7 +495,7 @@ private function getRetryOptions(array $options)
485495
: $this->retryFunction,
486496
'retryListener' => isset($options['restRetryListener'])
487497
? $options['restRetryListener']
488-
: null,
498+
: $this->retryListener,
489499
'delayFunction' => isset($options['restDelayFunction'])
490500
? $options['restDelayFunction']
491501
: $this->delayFunction,

Core/tests/Unit/RequestWrapperTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
use PHPUnit\Framework\TestCase;
4141
use Prophecy\Argument;
4242
use Prophecy\PhpUnit\ProphecyTrait;
43+
use ReflectionClass;
4344

4445
/**
4546
* @group core
@@ -859,6 +860,27 @@ public function testCheckUniverseDomainPasses(?string $universeDomain, ?string $
859860
$this->assertTrue($called);
860861
}
861862

863+
public function testRetryListenerOnConstructor()
864+
{
865+
$listener = function ($_, int $__, array &$___) {
866+
return;
867+
};
868+
$wrapper = new RequestWrapper([
869+
'restRetryListener' => $listener
870+
]);
871+
872+
$reflectionClass = new ReflectionClass($wrapper);
873+
$property = $reflectionClass->getProperty('retryListener');
874+
$property->setAccessible(true);
875+
876+
$this->assertNotEmpty($property->getValue($wrapper), 'The retryListener property should be set.');
877+
$this->assertEquals(
878+
$listener,
879+
$property->getValue($wrapper),
880+
'The retryListener should be the same as the one passed via options.'
881+
);
882+
}
883+
862884
public function provideCheckUniverseDomainPasses()
863885
{
864886
return [

0 commit comments

Comments
 (0)