Skip to content

Instantly share code, notes, and snippets.

@gsherwood
Created August 18, 2015 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsherwood/524a798cb1caf26f9ad2 to your computer and use it in GitHub Desktop.
Save gsherwood/524a798cb1caf26f9ad2 to your computer and use it in GitHub Desktop.
$ cat temp.php
<?php
class Client extends GuzzleClient implements ClientInterface {
/**
* {@inheritdoc}
*/
public function authenticatedRequest($method = 'GET', $url = null, UserInterface $user, $options = []) {
$duration = isset($options['timeout']) ? $options['timeout'] : NULL;
$options['query']['token'] = $user->acquireToken($duration);
try {
$response = $this->send($this->createRequest($method, $url, $options));
return $response;
}
catch (ApiException $exception) {
// If the token is invalid, we should delete it from storage so that a
// fresh token is fetched on the next request.
if ($exception->getCode() == 401) {
// Ensure the token will be deleted.
$user->invalidateToken();
}
throw $exception;
}
}
}
$ phpcbf temp.php --standard=PSR2
Changing into directory *removed*
Processing temp.php [PHP => 205 tokens in 25 lines]... DONE in 8ms (15 fixable violations)
=> Fixing file: 0/15 violations remaining [made 5 passes]... DONE in 41ms
Patched 1 file
Time: 76ms; Memory: 4.5Mb
$ cat temp.php
<?php
class Client extends GuzzleClient implements ClientInterface
{
/**
* {@inheritdoc}
*/
public function authenticatedRequest($method = 'GET', $url = null, UserInterface $user, $options = [])
{
$duration = isset($options['timeout']) ? $options['timeout'] : null;
$options['query']['token'] = $user->acquireToken($duration);
try {
$response = $this->send($this->createRequest($method, $url, $options));
return $response;
} catch (ApiException $exception) {
// If the token is invalid, we should delete it from storage so that a
// fresh token is fetched on the next request.
if ($exception->getCode() == 401) {
// Ensure the token will be deleted.
$user->invalidateToken();
}
throw $exception;
}
}
}
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment