Skip to content

Commit b567d09

Browse files
authored
chore: make whitespace consistent with our other libraries (#2251)
1 parent c6d5a7b commit b567d09

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+7650
-7653
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,5 @@ jobs:
5353
max_attempts: 3
5454
command: composer install
5555
- name: Run Script
56-
run: vendor/bin/phpcs src --standard=phpcs.xml.dist -np
56+
run: vendor/bin/phpcs src tests examples --standard=phpcs.xml.dist -nps
57+

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
"guzzlehttp/psr7": "^1.8.4||^2.2.1"
1717
},
1818
"require-dev": {
19-
"squizlabs/php_codesniffer": "~2.3",
19+
"squizlabs/php_codesniffer": "^3.0",
2020
"symfony/dom-crawler": "~2.1",
2121
"symfony/css-selector": "~2.1",
2222
"cache/filesystem-adapter": "^0.3.2|^1.1",
2323
"phpcompatibility/php-compatibility": "^9.2",
24-
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
2524
"composer/composer": "^1.10.22",
2625
"yoast/phpunit-polyfills": "^1.0",
2726
"phpspec/prophecy-phpunit": "^1.1||^2.0",

examples/batch.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737

3838
// Warn if the API key isn't set.
3939
if (!$apiKey = getApiKey()) {
40-
echo missingApiKeyWarning();
41-
return;
40+
echo missingApiKeyWarning();
41+
return;
4242
}
4343
$client->setDeveloperKey($apiKey);
4444

@@ -79,15 +79,15 @@
7979
?>
8080

8181
<h3>Results Of Call 1:</h3>
82-
<?php foreach ($results['response-thoreau'] as $item): ?>
83-
<?= $item['volumeInfo']['title'] ?>
82+
<?php foreach ($results['response-thoreau'] as $item) : ?>
83+
<?= $item['volumeInfo']['title'] ?>
8484
<br />
8585
<?php endforeach ?>
8686

8787
<h3>Results Of Call 2:</h3>
88-
<?php foreach ($results['response-shaw'] as $item): ?>
89-
<?= $item['volumeInfo']['title'] ?>
88+
<?php foreach ($results['response-shaw'] as $item) : ?>
89+
<?= $item['volumeInfo']['title'] ?>
9090
<br />
9191
<?php endforeach ?>
9292

93-
<?= pageFooter(__FILE__) ?>
93+
<?= pageFooter(__FILE__)

examples/idtoken.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
* Ensure you've downloaded your oauth credentials
2525
************************************************/
2626
if (!$oauth_credentials = getOAuthCredentialsFile()) {
27-
echo missingOAuth2CredentialsWarning();
28-
return;
27+
echo missingOAuth2CredentialsWarning();
28+
return;
2929
}
3030

3131
/************************************************
@@ -45,7 +45,7 @@
4545
* local access token in this case
4646
************************************************/
4747
if (isset($_REQUEST['logout'])) {
48-
unset($_SESSION['id_token_token']);
48+
unset($_SESSION['id_token_token']);
4949
}
5050

5151

@@ -57,14 +57,14 @@
5757
* bundle in the session, and redirect to ourself.
5858
************************************************/
5959
if (isset($_GET['code'])) {
60-
$token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
60+
$token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
6161

62-
// store in the session also
63-
$_SESSION['id_token_token'] = $token;
62+
// store in the session also
63+
$_SESSION['id_token_token'] = $token;
6464

65-
// redirect back to the example
66-
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
67-
return;
65+
// redirect back to the example
66+
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
67+
return;
6868
}
6969

7070
/************************************************
@@ -75,9 +75,9 @@
7575
!empty($_SESSION['id_token_token'])
7676
&& isset($_SESSION['id_token_token']['id_token'])
7777
) {
78-
$client->setAccessToken($_SESSION['id_token_token']);
78+
$client->setAccessToken($_SESSION['id_token_token']);
7979
} else {
80-
$authUrl = $client->createAuthUrl();
80+
$authUrl = $client->createAuthUrl();
8181
}
8282

8383
/************************************************
@@ -89,21 +89,21 @@
8989
and that can be cached.
9090
************************************************/
9191
if ($client->getAccessToken()) {
92-
$token_data = $client->verifyIdToken();
92+
$token_data = $client->verifyIdToken();
9393
}
9494
?>
9595

9696
<div class="box">
97-
<?php if (isset($authUrl)): ?>
97+
<?php if (isset($authUrl)) : ?>
9898
<div class="request">
9999
<a class='login' href='<?= $authUrl ?>'>Connect Me!</a>
100100
</div>
101-
<?php else: ?>
101+
<?php else : ?>
102102
<div class="data">
103103
<p>Here is the data from your Id Token:</p>
104104
<pre><?php var_export($token_data) ?></pre>
105105
</div>
106106
<?php endif ?>
107107
</div>
108108

109-
<?= pageFooter(__FILE__) ?>
109+
<?= pageFooter(__FILE__)

examples/index.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
<?php include_once "templates/base.php" ?>
22

3-
<?php if (!isWebRequest()): ?>
4-
To view this example, run the following command from the root directory of this repository:
3+
<?php if (!isWebRequest()) : ?>
4+
To view this example, run the following command from the root directory of this repository:
55

6-
php -S localhost:8080 -t examples/
6+
php -S localhost:8080 -t examples/
77

8-
And then browse to "localhost:8080" in your web browser
9-
<?php return ?>
8+
And then browse to "localhost:8080" in your web browser
9+
<?php return ?>
1010
<?php endif ?>
1111

1212
<?= pageHeader("PHP Library Examples"); ?>
1313

14-
<?php if (isset($_POST['api_key'])): ?>
15-
<?php setApiKey($_POST['api_key']) ?>
16-
<span class="warn">
17-
API Key set!
18-
</span>
14+
<?php if (isset($_POST['api_key'])) : ?>
15+
<?php setApiKey($_POST['api_key']) ?>
16+
<span class="warn">
17+
API Key set!
18+
</span>
1919
<?php endif ?>
2020

21-
<?php if (!getApiKey()): ?>
21+
<?php if (!getApiKey()) : ?>
2222
<div class="api-key">
2323
<strong>You have not entered your API key</strong>
2424
<form action="<?= htmlspecialchars($_SERVER["PHP_SELF"]) ?>" method="POST">
@@ -40,4 +40,4 @@
4040
<li><a href="multi-api.php">An example of using multiple APIs.</a></li>
4141
</ul>
4242

43-
<?= pageFooter(); ?>
43+
<?= pageFooter();

examples/large-file-download.php

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
* Ensure you've downloaded your oauth credentials
2525
************************************************/
2626
if (!$oauth_credentials = getOAuthCredentialsFile()) {
27-
echo missingOAuth2CredentialsWarning();
28-
return;
27+
echo missingOAuth2CredentialsWarning();
28+
return;
2929
}
3030

3131
/************************************************
@@ -48,102 +48,102 @@
4848
* bundle in the session, and redirect to ourself.
4949
************************************************/
5050
if (isset($_GET['code'])) {
51-
$token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
52-
$client->setAccessToken($token);
51+
$token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
52+
$client->setAccessToken($token);
5353

54-
// store in the session also
55-
$_SESSION['upload_token'] = $token;
54+
// store in the session also
55+
$_SESSION['upload_token'] = $token;
5656

57-
// redirect back to the example
58-
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
57+
// redirect back to the example
58+
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
5959
}
6060

6161
// set the access token as part of the client
6262
if (!empty($_SESSION['upload_token'])) {
63-
$client->setAccessToken($_SESSION['upload_token']);
64-
if ($client->isAccessTokenExpired()) {
65-
unset($_SESSION['upload_token']);
66-
}
63+
$client->setAccessToken($_SESSION['upload_token']);
64+
if ($client->isAccessTokenExpired()) {
65+
unset($_SESSION['upload_token']);
66+
}
6767
} else {
68-
$authUrl = $client->createAuthUrl();
68+
$authUrl = $client->createAuthUrl();
6969
}
7070

7171
/************************************************
7272
* If we're signed in then lets try to download our
7373
* file.
7474
************************************************/
7575
if ($client->getAccessToken()) {
76-
// Check for "Big File" and include the file ID and size
77-
$files = $service->files->listFiles([
78-
'q' => "name='Big File'",
79-
'fields' => 'files(id,size)'
80-
]);
81-
82-
if (count($files) == 0) {
83-
echo "
76+
// Check for "Big File" and include the file ID and size
77+
$files = $service->files->listFiles([
78+
'q' => "name='Big File'",
79+
'fields' => 'files(id,size)'
80+
]);
81+
82+
if (count($files) == 0) {
83+
echo "
8484
<h3 class='warn'>
8585
Before you can use this sample, you need to
8686
<a href='/large-file-upload.php'>upload a large file to Drive</a>.
8787
</h3>";
88-
return;
89-
}
90-
91-
// If this is a POST, download the file
92-
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
93-
// Determine the file's size and ID
94-
$fileId = $files[0]->id;
95-
$fileSize = intval($files[0]->size);
96-
97-
// Get the authorized Guzzle HTTP client
98-
$http = $client->authorize();
99-
100-
// Open a file for writing
101-
$fp = fopen('Big File (downloaded)', 'w');
102-
103-
// Download in 1 MB chunks
104-
$chunkSizeBytes = 1 * 1024 * 1024;
105-
$chunkStart = 0;
106-
107-
// Iterate over each chunk and write it to our file
108-
while ($chunkStart < $fileSize) {
109-
$chunkEnd = $chunkStart + $chunkSizeBytes;
110-
$response = $http->request(
111-
'GET',
112-
sprintf('/drive/v3/files/%s', $fileId),
113-
[
114-
'query' => ['alt' => 'media'],
115-
'headers' => [
116-
'Range' => sprintf('bytes=%s-%s', $chunkStart, $chunkEnd)
117-
]
118-
]
119-
);
120-
$chunkStart = $chunkEnd + 1;
121-
fwrite($fp, $response->getBody()->getContents());
88+
return;
12289
}
123-
// close the file pointer
124-
fclose($fp);
12590

126-
// redirect back to this example
127-
header('Location: ' . filter_var($redirect_uri . '?downloaded', FILTER_SANITIZE_URL));
128-
}
91+
// If this is a POST, download the file
92+
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
93+
// Determine the file's size and ID
94+
$fileId = $files[0]->id;
95+
$fileSize = intval($files[0]->size);
96+
97+
// Get the authorized Guzzle HTTP client
98+
$http = $client->authorize();
99+
100+
// Open a file for writing
101+
$fp = fopen('Big File (downloaded)', 'w');
102+
103+
// Download in 1 MB chunks
104+
$chunkSizeBytes = 1 * 1024 * 1024;
105+
$chunkStart = 0;
106+
107+
// Iterate over each chunk and write it to our file
108+
while ($chunkStart < $fileSize) {
109+
$chunkEnd = $chunkStart + $chunkSizeBytes;
110+
$response = $http->request(
111+
'GET',
112+
sprintf('/drive/v3/files/%s', $fileId),
113+
[
114+
'query' => ['alt' => 'media'],
115+
'headers' => [
116+
'Range' => sprintf('bytes=%s-%s', $chunkStart, $chunkEnd)
117+
]
118+
]
119+
);
120+
$chunkStart = $chunkEnd + 1;
121+
fwrite($fp, $response->getBody()->getContents());
122+
}
123+
// close the file pointer
124+
fclose($fp);
125+
126+
// redirect back to this example
127+
header('Location: ' . filter_var($redirect_uri . '?downloaded', FILTER_SANITIZE_URL));
128+
}
129129
}
130130
?>
131131

132132
<div class="box">
133-
<?php if (isset($authUrl)): ?>
133+
<?php if (isset($authUrl)) : ?>
134134
<div class="request">
135135
<a class='login' href='<?= $authUrl ?>'>Connect Me!</a>
136136
</div>
137-
<?php elseif(isset($_GET['downloaded'])): ?>
137+
<?php elseif (isset($_GET['downloaded'])) : ?>
138138
<div class="shortened">
139139
<p>Your call was successful! Check your filesystem for the file:</p>
140140
<p><code><?= __DIR__ . DIRECTORY_SEPARATOR ?>Big File (downloaded)</code></p>
141141
</div>
142-
<?php else: ?>
142+
<?php else : ?>
143143
<form method="POST">
144144
<input type="submit" value="Click here to download a large (20MB) test file" />
145145
</form>
146146
<?php endif ?>
147147
</div>
148148

149-
<?= pageFooter(__FILE__) ?>
149+
<?= pageFooter(__FILE__)

0 commit comments

Comments
 (0)