Skip to content

Commit ea2d79c

Browse files
authored
chore: misc code style fixes (#2253)
1 parent 8be2186 commit ea2d79c

33 files changed

+444
-411
lines changed

examples/batch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
$batch = $service->createBatch();
6464

6565
$query = 'Henry David Thoreau';
66-
$optParams = array('filter' => 'free-ebooks');
66+
$optParams = ['filter' => 'free-ebooks'];
6767
$req1 = $service->volumes->listVolumes($query, $optParams);
6868
$batch->add($req1, "thoreau");
6969
$query = 'George Bernard Shaw';

examples/multi-api.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@
8888
if ($client->getAccessToken()) {
8989
$_SESSION['multi-api-token'] = $client->getAccessToken();
9090

91-
$dr_results = $dr_service->files->listFiles(array('pageSize' => 10));
91+
$dr_results = $dr_service->files->listFiles(['pageSize' => 10]);
9292

93-
$yt_channels = $yt_service->channels->listChannels('contentDetails', array("mine" => true));
93+
$yt_channels = $yt_service->channels->listChannels('contentDetails', ["mine" => true]);
9494
$likePlaylist = $yt_channels[0]->contentDetails->relatedPlaylists->likes;
9595
$yt_results = $yt_service->playlistItems->listPlaylistItems(
9696
"snippet",
97-
array("playlistId" => $likePlaylist)
97+
["playlistId" => $likePlaylist]
9898
);
9999
}
100100
?>

examples/service-account.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@
6060
simple query as an example.
6161
************************************************/
6262
$query = 'Henry David Thoreau';
63-
$optParams = array(
63+
$optParams = [
6464
'filter' => 'free-ebooks',
65-
);
65+
];
6666
$results = $service->volumes->listVolumes($query, $optParams);
6767
?>
6868

examples/simple-file-upload.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,23 @@
9191
$file = new Google\Service\Drive\DriveFile();
9292
$result = $service->files->create(
9393
$file,
94-
array(
94+
[
9595
'data' => file_get_contents(TESTFILE),
9696
'mimeType' => 'application/octet-stream',
9797
'uploadType' => 'media'
98-
)
98+
]
9999
);
100100

101101
// Now lets try and send the metadata as well using multipart!
102102
$file = new Google\Service\Drive\DriveFile();
103103
$file->setName("Hello World!");
104104
$result2 = $service->files->create(
105105
$file,
106-
array(
106+
[
107107
'data' => file_get_contents(TESTFILE),
108108
'mimeType' => 'application/octet-stream',
109109
'uploadType' => 'multipart'
110-
)
110+
]
111111
);
112112
}
113113
?>

examples/simple-query.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@
4848
parameters.
4949
************************************************/
5050
$query = 'Henry David Thoreau';
51-
$optParams = array(
51+
$optParams = [
5252
'filter' => 'free-ebooks',
53-
);
53+
];
5454
$results = $service->volumes->listVolumes($query, $optParams);
5555

5656
/************************************************
5757
This is an example of deferring a call.
5858
***********************************************/
5959
$client->setDefer(true);
6060
$query = 'Henry David Thoreau';
61-
$optParams = array(
61+
$optParams = [
6262
'filter' => 'free-ebooks',
63-
);
63+
];
6464
$request = $service->volumes->listVolumes($query, $optParams);
6565
$resultsDeferred = $client->execute($request);
6666

phpcs.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
<severity>0</severity>
6565
</rule>
6666

67+
<!-- Require arrays to be defined by [] instead of array(). -->
68+
<rule ref="Generic.Arrays.DisallowLongArraySyntax" />
69+
6770
<!-- There MUST NOT be more than one statement per line. -->
6871
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
6972

src/AccessToken/Revoke.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function revokeToken($token)
6161
}
6262
}
6363

64-
$body = Psr7\Utils::streamFor(http_build_query(array('token' => $token)));
64+
$body = Psr7\Utils::streamFor(http_build_query(['token' => $token]));
6565
$request = new Request(
6666
'POST',
6767
Client::OAUTH2_REVOKE_URI,

src/AccessToken/Verify.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@
1818

1919
namespace Google\AccessToken;
2020

21+
use DateTime;
22+
use DomainException;
23+
use Exception;
24+
use ExpiredException;
2125
use Firebase\JWT\ExpiredException as ExpiredExceptionV3;
22-
use Firebase\JWT\SignatureInvalidException;
2326
use Firebase\JWT\Key;
27+
use Firebase\JWT\SignatureInvalidException;
28+
use Google\Auth\Cache\MemoryCacheItemPool;
29+
use Google\Exception as GoogleException;
2430
use GuzzleHttp\Client;
2531
use GuzzleHttp\ClientInterface;
2632
use InvalidArgumentException;
33+
use LogicException;
2734
use phpseclib3\Crypt\PublicKeyLoader;
28-
use phpseclib3\Crypt\RSA\PublicKey;
35+
use phpseclib3\Crypt\RSA\PublicKey; // Firebase v2
2936
use Psr\Cache\CacheItemPoolInterface;
30-
use Google\Auth\Cache\MemoryCacheItemPool;
31-
use Google\Exception as GoogleException;
32-
use DateTime;
33-
use DomainException;
34-
use Exception;
35-
use ExpiredException; // Firebase v2
36-
use LogicException;
3737

3838
/**
3939
* Wrapper around Google Access Tokens which provides convenience functions
@@ -74,7 +74,7 @@ public function __construct(
7474
}
7575

7676
if (null === $cache) {
77-
$cache = new MemoryCacheItemPool;
77+
$cache = new MemoryCacheItemPool();
7878
}
7979

8080
$this->http = $http;
@@ -123,7 +123,7 @@ public function verifyIdToken($idToken, $audience = null)
123123

124124
// support HTTP and HTTPS issuers
125125
// @see https://developers.google.com/identity/sign-in/web/backend-auth
126-
$issuers = array(self::OAUTH2_ISSUER, self::OAUTH2_ISSUER_HTTPS);
126+
$issuers = [self::OAUTH2_ISSUER, self::OAUTH2_ISSUER_HTTPS];
127127
if (!isset($payload->iss) || !in_array($payload->iss, $issuers)) {
128128
return false;
129129
}
@@ -231,15 +231,15 @@ private function getJwtService()
231231
}
232232

233233
// @phpstan-ignore-next-line
234-
return new $jwtClass;
234+
return new $jwtClass();
235235
}
236236

237237
private function getPublicKey($cert)
238238
{
239239
$bigIntClass = $this->getBigIntClass();
240240
$modulus = new $bigIntClass($this->jwt->urlsafeB64Decode($cert['n']), 256);
241241
$exponent = new $bigIntClass($this->jwt->urlsafeB64Decode($cert['e']), 256);
242-
$component = array('n' => $modulus, 'e' => $exponent);
242+
$component = ['n' => $modulus, 'e' => $exponent];
243243

244244
if (class_exists('phpseclib3\Crypt\RSA\PublicKey')) {
245245
/** @var PublicKey $loader */

src/AuthHandler/AuthHandlerFactory.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717

1818
namespace Google\AuthHandler;
1919

20-
use GuzzleHttp\Client;
21-
use GuzzleHttp\ClientInterface;
2220
use Exception;
21+
use GuzzleHttp\ClientInterface;
2322

2423
class AuthHandlerFactory
2524
{

src/AuthHandler/Guzzle5AuthHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace Google\AuthHandler;
44

55
use Google\Auth\CredentialsLoader;
6-
use Google\Auth\HttpHandler\HttpHandlerFactory;
76
use Google\Auth\FetchAuthTokenCache;
7+
use Google\Auth\HttpHandler\HttpHandlerFactory;
88
use Google\Auth\Subscriber\AuthTokenSubscriber;
99
use Google\Auth\Subscriber\ScopedAccessTokenSubscriber;
1010
use Google\Auth\Subscriber\SimpleSubscriber;

src/AuthHandler/Guzzle6AuthHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace Google\AuthHandler;
44

55
use Google\Auth\CredentialsLoader;
6-
use Google\Auth\HttpHandler\HttpHandlerFactory;
76
use Google\Auth\FetchAuthTokenCache;
7+
use Google\Auth\HttpHandler\HttpHandlerFactory;
88
use Google\Auth\Middleware\AuthTokenMiddleware;
99
use Google\Auth\Middleware\ScopedAccessTokenMiddleware;
1010
use Google\Auth\Middleware\SimpleMiddleware;

src/Client.php

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,32 @@
1717

1818
namespace Google;
1919

20+
use BadMethodCallException;
21+
use DomainException;
2022
use Google\AccessToken\Revoke;
2123
use Google\AccessToken\Verify;
2224
use Google\Auth\ApplicationDefaultCredentials;
2325
use Google\Auth\Cache\MemoryCacheItemPool;
26+
use Google\Auth\Credentials\ServiceAccountCredentials;
27+
use Google\Auth\Credentials\UserRefreshCredentials;
2428
use Google\Auth\CredentialsLoader;
2529
use Google\Auth\FetchAuthTokenCache;
2630
use Google\Auth\HttpHandler\HttpHandlerFactory;
2731
use Google\Auth\OAuth2;
28-
use Google\Auth\Credentials\ServiceAccountCredentials;
29-
use Google\Auth\Credentials\UserRefreshCredentials;
3032
use Google\AuthHandler\AuthHandlerFactory;
3133
use Google\Http\REST;
3234
use GuzzleHttp\Client as GuzzleClient;
3335
use GuzzleHttp\ClientInterface;
3436
use GuzzleHttp\Ring\Client\StreamHandler;
37+
use InvalidArgumentException;
38+
use LogicException;
39+
use Monolog\Handler\StreamHandler as MonologStreamHandler;
40+
use Monolog\Handler\SyslogHandler as MonologSyslogHandler;
41+
use Monolog\Logger;
3542
use Psr\Cache\CacheItemPoolInterface;
3643
use Psr\Http\Message\RequestInterface;
3744
use Psr\Http\Message\ResponseInterface;
3845
use Psr\Log\LoggerInterface;
39-
use Monolog\Logger;
40-
use Monolog\Handler\StreamHandler as MonologStreamHandler;
41-
use Monolog\Handler\SyslogHandler as MonologSyslogHandler;
42-
use BadMethodCallException;
43-
use DomainException;
44-
use InvalidArgumentException;
45-
use LogicException;
4646
use UnexpectedValueException;
4747

4848
/**
@@ -107,7 +107,7 @@ class Client
107107
*
108108
* @param array $config
109109
*/
110-
public function __construct(array $config = array())
110+
public function __construct(array $config = [])
111111
{
112112
$this->config = array_merge([
113113
'application_name' => '',
@@ -157,7 +157,7 @@ public function __construct(array $config = array())
157157

158158
// Task Runner retry configuration
159159
// @see Google\Task\Runner
160-
'retry' => array(),
160+
'retry' => [],
161161
'retry_map' => null,
162162

163163
// Cache class implementing Psr\Cache\CacheItemPoolInterface.
@@ -185,7 +185,7 @@ public function __construct(array $config = array())
185185
} else {
186186
$this->setAuthConfig($this->config['credentials']);
187187
}
188-
unset($this->config['credentials']);
188+
unset($this->config['credentials']);
189189
}
190190

191191
if (!is_null($this->config['scopes'])) {
@@ -446,11 +446,11 @@ public function authorize(ClientInterface $http = null)
446446
$scopes,
447447
$token['refresh_token']
448448
);
449-
return $authHandler->attachCredentials(
450-
$http,
451-
$credentials,
452-
$this->config['token_callback']
453-
);
449+
return $authHandler->attachCredentials(
450+
$http,
451+
$credentials,
452+
$this->config['token_callback']
453+
);
454454
}
455455

456456
return $authHandler->attachToken($http, $token, (array) $scopes);
@@ -508,9 +508,9 @@ public function setAccessToken($token)
508508
$token = $json;
509509
} else {
510510
// assume $token is just the token string
511-
$token = array(
511+
$token = [
512512
'access_token' => $token,
513-
);
513+
];
514514
}
515515
}
516516
if ($token == null) {
@@ -826,7 +826,7 @@ public function verifyIdToken($idToken = null)
826826
*/
827827
public function setScopes($scope_or_scopes)
828828
{
829-
$this->requestedScopes = array();
829+
$this->requestedScopes = [];
830830
$this->addScope($scope_or_scopes);
831831
}
832832

@@ -1142,7 +1142,7 @@ protected function createDefaultLogger()
11421142

11431143
protected function createDefaultCache()
11441144
{
1145-
return new MemoryCacheItemPool;
1145+
return new MemoryCacheItemPool();
11461146
}
11471147

11481148
/**
@@ -1224,13 +1224,13 @@ private function createApplicationDefaultCredentials()
12241224

12251225
// create credentials using values supplied in setAuthConfig
12261226
if ($signingKey) {
1227-
$serviceAccountCredentials = array(
1227+
$serviceAccountCredentials = [
12281228
'client_id' => $this->config['client_id'],
12291229
'client_email' => $this->config['client_email'],
12301230
'private_key' => $signingKey,
12311231
'type' => 'service_account',
12321232
'quota_project_id' => $this->config['quota_project'],
1233-
);
1233+
];
12341234
$credentials = CredentialsLoader::makeCredentials(
12351235
$scopes,
12361236
$serviceAccountCredentials
@@ -1284,13 +1284,11 @@ protected function getAuthHandler()
12841284

12851285
private function createUserRefreshCredentials($scope, $refreshToken)
12861286
{
1287-
$creds = array_filter(
1288-
array(
1287+
$creds = array_filter([
12891288
'client_id' => $this->getClientId(),
12901289
'client_secret' => $this->getClientSecret(),
12911290
'refresh_token' => $refreshToken,
1292-
)
1293-
);
1291+
]);
12941292

12951293
return new UserRefreshCredentials($scope, $creds);
12961294
}

0 commit comments

Comments
 (0)