Skip to content

Commit b73f63b

Browse files
author
georgio
committed
fix code style
1 parent fbf70bb commit b73f63b

File tree

13 files changed

+105
-108
lines changed

13 files changed

+105
-108
lines changed

examples/bootstrap.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
<?php
2-
require_once __DIR__ . './../vendor/autoload.php';
2+
3+
require_once __DIR__ . './../vendor/autoload.php';

examples/index.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,23 @@
2828
$status = $result ? 'passed' : 'failed';
2929
echo "<li>{$label} ... <span class='{$status}'>{$status}</span></li>";
3030
}
31-
echo '</ul>';
32-
33-
?>
31+
echo '</ul>'; ?>
3432
<h2>Select provider for check</h2>
3533
<ul>
3634
<?php
37-
/** @var SplFileInfo $files */
35+
/** @var SplFileInfo $files */
3836
foreach ($helper->getFinder() as $files) {
3937
$basename = $files->getBasename();
40-
echo '<li><a href="/provider/'.$basename.'">'.$basename.'</a></li>';
41-
}
42-
?>
38+
echo '<li><a href="/provider/' . $basename . '">' . $basename . '</a></li>';
39+
} ?>
4340
</ul>
4441

4542
<?php
4643
} else {
47-
echo 'Requirement check:' . PHP_EOL;
48-
foreach ($requirements as $label => $result) {
49-
$status = $result ? '32m passed' : '31m failed';
50-
echo "{$label} ... \033[{$status}\033[0m" . PHP_EOL;
51-
}
52-
}
44+
echo 'Requirement check:' . PHP_EOL;
45+
foreach ($requirements as $label => $result) {
46+
$status = $result ? '32m passed' : '31m failed';
47+
echo "{$label} ... \033[{$status}\033[0m" . PHP_EOL;
48+
}
49+
}
5350
?>

examples/provider/amazon.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use OAuth\Helper\Example;
1717
use OAuth\OAuth2\Service\Amazon;
1818

19-
require_once __DIR__.'/../bootstrap.php';
19+
require_once __DIR__ . '/../bootstrap.php';
2020

2121
$helper = new Example();
2222
$storage = new Session();
@@ -29,13 +29,14 @@
2929
$credentials = new Credentials($_GET['key'], $_GET['secret'], $helper->getCurrentUrl());
3030
$vkService = new Amazon($credentials, $client, $storage);
3131
echo $helper->getHeader();
32-
echo '<a href="'.$vkService->getAuthorizationUri().'">get access token</a>';
32+
echo '<a href="' . $vkService->getAuthorizationUri() . '">get access token</a>';
3333
echo $helper->getFooter();
3434
} elseif (!empty($_GET['code'])) {
3535
$credentials = new Credentials($_GET['key'], $_GET['secret'], $helper->getCurrentUrl());
3636
$vkService = new Amazon($credentials, $client, $storage);
3737

3838
echo $helper->getHeader();
39+
3940
try {
4041
$token = $vkService->requestAccessToken($_GET['code']);
4142
echo 'access token: ' . $token->getAccessToken();

examples/provider/google.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use OAuth\Helper\Example;
88
use OAuth\OAuth2\Service\Google;
99

10-
require_once __DIR__.'/../bootstrap.php';
10+
require_once __DIR__ . '/../bootstrap.php';
1111

1212
$helper = new Example();
1313
$storage = new Session();
@@ -18,10 +18,11 @@
1818
echo $helper->getContent();
1919
} elseif (!empty($_GET['key']) && !empty($_GET['secret']) && $_GET['oauth'] !== 'redirect') {
2020
echo $helper->getHeader();
21+
2122
try {
2223
$credentials = new Credentials($_GET['key'], $_GET['secret'], $helper->getCurrentUrl());
2324
$google = new Google($credentials, $client, $storage, ['email']);
24-
echo '<a href="'.$google->getAuthorizationUri().'">get access token</a>';
25+
echo '<a href="' . $google->getAuthorizationUri() . '">get access token</a>';
2526
} catch (\Exception $exception) {
2627
$helper->getErrorMessage($exception);
2728
}
@@ -31,6 +32,7 @@
3132
$google = new Google($credentials, $client, $storage);
3233

3334
echo $helper->getHeader();
35+
3436
try {
3537
$token = $google->requestAccessToken($_GET['code']);
3638
echo 'access token: ' . $token->getAccessToken();

examples/provider/instagram.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use OAuth\Helper\Example;
88
use OAuth\OAuth2\Service\Instagram;
99

10-
1110
require_once __DIR__ . '/../bootstrap.php';
1211

1312
$helper = new Example();
@@ -16,7 +15,6 @@
1615

1716
$helper->setTitle('Instagram');
1817

19-
2018
if (empty($_GET)) {
2119
echo $helper->getContent();
2220
} elseif (!empty($_GET['key']) && !empty($_GET['secret']) && $_GET['oauth'] !== 'redirect') {
@@ -30,6 +28,7 @@
3028
$service = new Instagram($credentials, $client, $storage);
3129

3230
echo $helper->getHeader();
31+
3332
try {
3433
$token = $service->requestAccessToken($_GET['code']);
3534
echo 'access token: ' . $token->getAccessToken();
@@ -38,4 +37,3 @@
3837
}
3938
echo $helper->getFooter();
4039
}
41-

examples/provider/ustream.php

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,39 @@
1010
*/
1111

1212
use OAuth\Common\Consumer\Credentials;
13+
use OAuth\Common\Http\Client\CurlClient;
14+
use OAuth\Common\Http\Exception\TokenResponseException;
1315
use OAuth\Common\Storage\Session;
16+
use OAuth\Helper\Example;
1417
use OAuth\OAuth2\Service\Ustream;
1518

16-
/**
17-
* Bootstrap the example.
18-
*/
19-
require_once __DIR__ . '/bootstrap.php';
19+
require_once __DIR__ . '/../bootstrap.php';
2020

21-
// Session storage
21+
$helper = new Example();
2222
$storage = new Session();
23-
24-
// Setup the credentials for the requests
25-
$credentials = new Credentials(
26-
$servicesCredentials['ustream']['key'],
27-
$servicesCredentials['ustream']['secret'],
28-
$currentUri->getAbsoluteUri()
29-
);
30-
31-
// Instantiate the Ustream service using the credentials, http client and storage mechanism for the token
32-
/** @var Ustream $ustream */
33-
$ustream = $serviceFactory->createService('Ustream', $credentials, $storage, ['identity']);
34-
35-
if (!empty($_GET['code'])) {
36-
// retrieve the CSRF state parameter
37-
$state = $_GET['state'] ?? null;
38-
39-
// This was a callback request from Ustream, get the token
40-
$ustream->requestAccessToken($_GET['code'], $state);
41-
42-
$result = json_decode($ustream->request('users/self.json'), true);
43-
44-
echo 'Your unique Ustream user id is: ' . $result['id'] . ' and your username is ' . $result['username'];
45-
} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') {
46-
$url = $ustream->getAuthorizationUri();
47-
header('Location: ' . $url);
48-
} else {
49-
$url = $currentUri->getRelativeUri() . '?go=go';
50-
echo "<a href='$url'>Login with Ustream!</a>";
23+
$client = new CurlClient();
24+
25+
$helper->setTitle('Instagram');
26+
27+
if (empty($_GET)) {
28+
echo $helper->getContent();
29+
} elseif (!empty($_GET['key']) && !empty($_GET['secret']) && $_GET['oauth'] !== 'redirect') {
30+
$credentials = new Credentials($_GET['key'], $_GET['secret'], $helper->getCurrentUrl());
31+
$service = new Ustream($credentials, $client, $storage);
32+
echo $helper->getHeader();
33+
echo '<a href="' . $service->getAuthorizationUri() . '">get access token</a>';
34+
echo $helper->getFooter();
35+
} elseif (!empty($_GET['code'])) {
36+
$credentials = new Credentials($_GET['key'], $_GET['secret'], $helper->getCurrentUrl());
37+
$service = new Ustream($credentials, $client, $storage);
38+
39+
echo $helper->getHeader();
40+
41+
try {
42+
$token = $service->requestAccessToken($_GET['code']);
43+
echo 'access token: ' . $token->getAccessToken();
44+
} catch (TokenResponseException $exception) {
45+
$helper->getErrorMessage($exception);
46+
}
47+
echo $helper->getFooter();
5148
}

examples/provider/vkontakte.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use OAuth\Helper\Example;
88
use OAuth\OAuth2\Service\Vkontakte;
99

10-
require_once __DIR__.'/../bootstrap.php';
10+
require_once __DIR__ . '/../bootstrap.php';
1111

1212
$helper = new Example();
1313
$storage = new Session();
@@ -19,13 +19,14 @@
1919
$credentials = new Credentials($_GET['key'], $_GET['secret'], $helper->getCurrentUrl());
2020
$vkService = new Vkontakte($credentials, $client, $storage);
2121
echo $helper->getHeader();
22-
echo '<a href="'.$vkService->getAuthorizationUri().'">get access token</a>';
22+
echo '<a href="' . $vkService->getAuthorizationUri() . '">get access token</a>';
2323
echo $helper->getFooter();
2424
} elseif (!empty($_GET['code'])) {
2525
$credentials = new Credentials($_GET['key'], $_GET['secret'], $helper->getCurrentUrl());
2626
$vkService = new Vkontakte($credentials, $client, $storage);
2727

2828
echo $helper->getHeader();
29+
2930
try {
3031
$token = $vkService->requestAccessToken($_GET['code']);
3132
echo 'access token: ' . $token->getAccessToken();

src/OAuth/Helper/Example.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Example
1313
* @var Finder
1414
*/
1515
private $finder;
16+
1617
private $title;
1718

1819
public function __construct()
@@ -25,16 +26,17 @@ public function isCli(): bool
2526
return PHP_SAPI === 'cli';
2627
}
2728

28-
2929
public function getFinder(): Finder
3030
{
3131
$this->finder->in(__DIR__ . '/../../../examples/provider/');
32+
3233
return $this->finder;
3334
}
3435

3536
public function getHeader(): string
3637
{
3738
$title = $this->title;
39+
3840
return <<<HTML
3941
<html>
4042
<head>
@@ -100,10 +102,9 @@ public function getForm(): string
100102

101103
public function getContent(): string
102104
{
103-
104-
$response = $this->getHeader();
105-
$response .= $this->getForm();
106-
$response .= $this->getFooter();
105+
$response = $this->getHeader();
106+
$response .= $this->getForm();
107+
$response .= $this->getFooter();
107108

108109
return $response;
109110
}
@@ -115,19 +116,19 @@ public function isShowLink(): bool
115116

116117
public function getCurrentUrl(): string
117118
{
118-
return 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?oauth=redirect&key='. urldecode($_GET['key']) . '&secret=' . urldecode($_GET['secret']);
119+
return 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?oauth=redirect&key=' . urldecode($_GET['key']) . '&secret=' . urldecode($_GET['secret']);
119120
}
120121

121122
public function getErrorMessage($exception): void
122123
{
123124
echo '<div class="alert alert-danger">' . $exception->getMessage() . '</div>';
124125
echo '<pre>';
125-
print_r($exception) ;
126+
print_r($exception);
126127
echo '</pre>';
127128
}
128129

129130
public function setTitle(string $title): void
130131
{
131-
$this->title = 'PHPoAuthLib - ' . $title;
132+
$this->title = 'PHPoAuthLib - ' . $title;
132133
}
133134
}

src/OAuth/OAuth2/Service/AbstractService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public function request($path, $method = 'GET', $body = null, array $extraHeader
167167
} elseif (static::AUTHORIZATION_METHOD_HEADER_BEARER === $this->getAuthorizationMethod()) {
168168
$extraHeaders = array_merge(['Authorization' => 'Bearer ' . $token->getAccessToken()], $extraHeaders);
169169
} elseif (static::AUTHORIZATION_METHOD_HEADER_TOKEN === $this->getAuthorizationMethod()) {
170-
$extraHeaders = array_merge(array('Authorization' => 'token ' . $token->getAccessToken()), $extraHeaders);
170+
$extraHeaders = array_merge(['Authorization' => 'token ' . $token->getAccessToken()], $extraHeaders);
171171
}
172172

173173
$extraHeaders = array_merge($this->getExtraApiHeaders(), $extraHeaders);

src/OAuth/OAuth2/Service/Stripe.php

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

33
namespace OAuth\OAuth2\Service;
44

5-
use OAuth\OAuth2\Token\StdOAuth2Token;
6-
use OAuth\Common\Http\Exception\TokenResponseException;
7-
use OAuth\Common\Http\Uri\Uri;
85
use OAuth\Common\Consumer\CredentialsInterface;
96
use OAuth\Common\Http\Client\ClientInterface;
10-
use OAuth\Common\Storage\TokenStorageInterface;
7+
use OAuth\Common\Http\Exception\TokenResponseException;
8+
use OAuth\Common\Http\Uri\Uri;
119
use OAuth\Common\Http\Uri\UriInterface;
10+
use OAuth\Common\Storage\TokenStorageInterface;
11+
use OAuth\OAuth2\Token\StdOAuth2Token;
1212

1313
class Stripe extends AbstractService
1414
{
@@ -19,8 +19,8 @@ public function __construct(
1919
CredentialsInterface $credentials,
2020
ClientInterface $httpClient,
2121
TokenStorageInterface $storage,
22-
$scopes = array(),
23-
UriInterface $baseApiUri = null
22+
$scopes = [],
23+
?UriInterface $baseApiUri = null
2424
) {
2525
parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
2626

@@ -60,7 +60,7 @@ protected function parseAccessTokenResponse($responseBody)
6060
{
6161
$data = json_decode($responseBody, true);
6262

63-
if (null === $data || ! is_array($data)) {
63+
if (null === $data || !is_array($data)) {
6464
throw new TokenResponseException('Unable to parse response.');
6565
} elseif (isset($data['error'])) {
6666
throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');

0 commit comments

Comments
 (0)