Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit db7b6d5

Browse files
committed
🚿
1 parent d66557e commit db7b6d5

File tree

10 files changed

+91
-42
lines changed

10 files changed

+91
-42
lines changed

examples/misc/flickr-create-endpoint-map.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77
* @license MIT
88
*/
99

10-
use chillerlan\HTTP\Psr7;
10+
namespace chillerlan\OAuthExamples\misc;
11+
1112
use chillerlan\OAuth\Providers\Flickr\Flickr;
13+
use ReflectionClass;
14+
15+
use function chillerlan\HTTP\Psr7\get_json;
16+
use function array_column, array_shift, date, explode, file_put_contents, implode, lcfirst, ucfirst;
1217

1318
$ENVVAR = 'FLICKR';
1419

@@ -22,21 +27,21 @@
2227
*/
2328

2429
$flickr = new Flickr($http, $storage, $options, $logger);
25-
$epr = new \ReflectionClass($flickr->endpoints);
30+
$epr = new ReflectionClass($flickr->endpoints);
2631
$classfile = $epr->getFileName();
2732

2833
// fetch a list of available methods
2934
$r = $flickr->request('flickr.reflection.getMethods', [], 'GET');
30-
$methods = \array_column(Psr7\get_json($r)->methods->method, '_content');
35+
$methods = array_column(get_json($r)->methods->method, '_content');
3136

3237
// now walk through the array and get the method info
3338
$str = [];
3439
foreach($methods as $methodname){
3540
$methodInfo = $flickr->request('flickr.reflection.getMethodInfo', ['method_name' => $methodname], 'GET');
36-
$m = Psr7\get_json($methodInfo);
41+
$m = get_json($methodInfo);
3742

3843
if(!$m || !isset($m->method)){
39-
$logger->debug($methodname, (array)$methodInfo->headers);
44+
$logger->debug($methodname);
4045

4146
continue;
4247
}
@@ -52,12 +57,12 @@
5257
}
5358

5459
// convert from dot.notation to camelCase
55-
$name = \explode('.', $m->method->name);
60+
$name = explode('.', $m->method->name);
5661

57-
\array_shift($name); // remove the "flickr"
62+
array_shift($name); // remove the "flickr"
5863

5964
foreach($name as $k => $parts){
60-
$name[$k] = \ucfirst($parts);
65+
$name[$k] = ucfirst($parts);
6166
}
6267

6368
// create a docblock
@@ -66,9 +71,9 @@
6671
/**
6772
* @link https://www.flickr.com/services/api/'.$m->method->name.'.html
6873
*/
69-
protected $'.\lcfirst(\implode('', $name)).' = [
74+
protected $'.lcfirst(implode('', $name)).' = [
7075
\'path\' => \''.$m->method->name.'\',
71-
\'query\' => ['.(!empty($args) ? '\''.\implode('\', \'', $args).'\'' : '').'],
76+
\'query\' => ['.(!empty($args) ? '\''.implode('\', \'', $args).'\'' : '').'],
7277
];';
7378

7479
$logger->info($m->method->name);
@@ -82,7 +87,7 @@
8287
* @link https://www.flickr.com/services/api/
8388
*
8489
* @filesource '.$epr->getShortName().'.php
85-
* @created '.\date('d.m.Y').'
90+
* @created '.date('d.m.Y').'
8691
* @package '.$epr->getNamespaceName().'
8792
* @license MIT
8893
*/
@@ -92,11 +97,11 @@
9297
use chillerlan\\HTTP\\MagicAPI\\EndpointMap;
9398
9499
class '.$epr->getShortName().' extends EndpointMap{
95-
'.\implode(PHP_EOL, $str).'
100+
'.implode(PHP_EOL, $str).'
96101
97102
}
98103
';
99104

100-
\file_put_contents($classfile, $content);
105+
file_put_contents($classfile, $content);
101106

102107
exit;

examples/misc/gw2-create-endpoint-map.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77
* @license MIT
88
*/
99

10+
namespace chillerlan\OAuthExamples\misc;
11+
1012
use chillerlan\OAuth\Providers\GuildWars2\GuildWars2;
1113

12-
$ENVVAR = '';
14+
use function array_merge, count, date, explode, file_get_contents, file_put_contents,
15+
implode, json_decode, lcfirst, strpos, substr, trim, ucfirst, uksort;
16+
17+
use const PHP_EOL;
1318

1419
require_once __DIR__.'/../provider-example-common.php';
1520

@@ -105,13 +110,11 @@
105110
$api[] = ['path' => '/v2/wvw/ranks/:id', 'lang' => true, 'auth' => false, 'active' => true];
106111
$api[] = ['path' => '/v2/wvw/upgrades/:id', 'lang' => true, 'auth' => false, 'active' => true];
107112

108-
109113
foreach($api as $endpoint){
110-
$query = [];
114+
$query = [];
111115
$path_elements = [];
112-
$path = explode('/', trim($endpoint['path'], '/v2 '));
113-
$name = $path;
114-
116+
$path = explode('/', trim($endpoint['path'], '/v2 '));
117+
$name = $path;
115118

116119
$i = 1;
117120
foreach($path as $k => $el){
@@ -124,10 +127,10 @@
124127
}
125128

126129
if(strpos($el, ':') === 0){
127-
$pe = substr($el, 1);
130+
$pe = substr($el, 1);
128131
$path_elements[] = substr($el, 1);
129-
$path[$k] = '%'.$i.'$s';
130-
$name[$k] = ($pe !== 'id' ? ucfirst(explode('_', $pe)[0]) : '').'Id';
132+
$path[$k] = '%'.$i.'$s';
133+
$name[$k] = ($pe !== 'id' ? ucfirst(explode('_', $pe)[0]) : '').'Id';
131134
$i++;
132135
}
133136
}
@@ -161,8 +164,8 @@
161164
$str[] = '
162165
protected $'.explode('?', $method)[0].' = [
163166
\'path\' => \''.$args['path'].'\',
164-
\'query\' => ['.(!empty($args['query']) ? '\''.\implode('\', \'', $args['query']).'\'' : '').'],
165-
\'path_elements\' => ['.(!empty($args['path_elements']) ? '\''.\implode('\', \'', $args['path_elements']).'\'' : '').'],
167+
\'query\' => ['.(!empty($args['query']) ? '\''.implode('\', \'', $args['query']).'\'' : '').'],
168+
\'path_elements\' => ['.(!empty($args['path_elements']) ? '\''.implode('\', \'', $args['path_elements']).'\'' : '').'],
166169
];';
167170

168171
$logger->info($method);
@@ -177,7 +180,7 @@
177180
* @link https://api.guildwars2.com/v2.json
178181
*
179182
* @filesource '.$epr->getShortName().'.php
180-
* @created '.\date('d.m.Y').'
183+
* @created '.date('d.m.Y').'
181184
* @package '.$epr->getNamespaceName().'
182185
* @license MIT
183186
*/
@@ -187,9 +190,9 @@
187190
use chillerlan\\HTTP\\MagicAPI\\EndpointMap;
188191
189192
class '.$epr->getShortName().' extends EndpointMap{
190-
'.\implode(PHP_EOL, $str).'
193+
'.implode(PHP_EOL, $str).'
191194
192195
}
193196
';
194197

195-
\file_put_contents($classfile, $content);
198+
file_put_contents($classfile, $content);

examples/misc/opencaching-create-endpoint-map.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@
77
* @license MIT
88
*/
99

10-
namespace chillerlan\OAuthExamples\OpenCaching;
10+
namespace chillerlan\OAuthExamples\misc;
1111

12-
use chillerlan\HTTP\Psr7;
1312
use chillerlan\OAuth\Providers\OpenCaching\OpenCaching;
13+
use ReflectionClass;
14+
15+
use function chillerlan\HTTP\Psr7\get_json;
16+
use function array_column, date, explode, file_put_contents, implode, lcfirst, str_replace, strpos, ucfirst;
17+
18+
use const PHP_EOL;
1419

1520
$ENVVAR = 'OKAPI';
1621

@@ -24,12 +29,12 @@
2429
*/
2530

2631
$okapi = new OpenCaching($http, $storage, $options, $logger);
27-
$epr = new \ReflectionClass($okapi->endpoints);
32+
$epr = new ReflectionClass($okapi->endpoints);
2833
$classfile = $epr->getFileName();
2934

3035
// fetch a list of available methods
3136
$r = $okapi->request('/apiref/method_index', [], 'GET');
32-
$methods = array_column(Psr7\get_json($r), 'name');
37+
$methods = array_column(get_json($r), 'name');
3338

3439
// now walk through the array and get the method info
3540
$str = [];
@@ -42,7 +47,7 @@
4247
}
4348

4449
$methodInfo = $okapi->request('/apiref/method', ['name' => $methodname], 'GET');
45-
$m = Psr7\get_json($methodInfo);
50+
$m = get_json($methodInfo);
4651
$p = str_replace('services/', '/', $m->name);
4752

4853
$args = [];

src/BattleNet/BattleNet.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ class BattleNet extends OAuth2Provider implements ClientCredentials, CSRFToken{
4545
* @param \chillerlan\Settings\SettingsContainerInterface $options
4646
* @param \Psr\Log\LoggerInterface|null $logger
4747
*/
48-
public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options, LoggerInterface $logger = null){
48+
public function __construct(
49+
ClientInterface $http,
50+
OAuthStorageInterface $storage,
51+
SettingsContainerInterface $options,
52+
LoggerInterface $logger = null
53+
){
4954
parent::__construct($http, $storage, $options, $logger);
5055

5156
$this->setRegion('eu');

src/Flickr/Flickr.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,13 @@ class Flickr extends OAuth1Provider{
268268
*
269269
* @return \Psr\Http\Message\ResponseInterface
270270
*/
271-
public function request(string $path, array $params = null, string $method = null, $body = null, array $headers = null):ResponseInterface{
271+
public function request(
272+
string $path,
273+
array $params = null,
274+
string $method = null,
275+
$body = null,
276+
array $headers = null
277+
):ResponseInterface{
272278
$method = $method ?? 'POST';
273279

274280
$params = \array_merge($params ?? [], [

src/Foursquare/Foursquare.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ class Foursquare extends OAuth2Provider{
4848
*
4949
* @return \Psr\Http\Message\ResponseInterface
5050
*/
51-
public function request(string $path, array $params = null, string $method = null, $body = null, array $headers = null):ResponseInterface{
51+
public function request(
52+
string $path,
53+
array $params = null,
54+
string $method = null,
55+
$body = null, array
56+
$headers = null
57+
):ResponseInterface{
5258

5359
parse_str(parse_url($this->apiURL.$path, PHP_URL_QUERY), $query);
5460

src/LastFM/LastFM.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,13 @@ protected function requestParams(string $apiMethod, array $params, array $body):
217217
*
218218
* @return \Psr\Http\Message\ResponseInterface
219219
*/
220-
public function request(string $path, array $params = null, string $method = null, $body = null, array $headers = null):ResponseInterface{
220+
public function request(
221+
string $path,
222+
array $params = null,
223+
string $method = null,
224+
$body = null,
225+
array $headers = null
226+
):ResponseInterface{
221227
$method = $method ?? 'GET';
222228
$params = $this->requestParams($path, $params ?? [], $body ?? []);
223229

src/MailChimp/MailChimp.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ public function getTokenMetadata(AccessToken $token = null):AccessToken{
7878
*
7979
* @inheritdoc
8080
*/
81-
public function request(string $path, array $params = null, string $method = null, $body = null, array $headers = null):ResponseInterface{
81+
public function request(
82+
string $path,
83+
array $params = null,
84+
string $method = null,
85+
$body = null,
86+
array $headers = null
87+
):ResponseInterface{
8288
$token = $this->storage->getAccessToken($this->serviceName);
8389

8490
$this->apiURL = sprintf($this::API_BASE, $token->extraParams['dc']);

src/MusicBrainz/MusicBrainz.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ public function refreshAccessToken(AccessToken $token = null):AccessToken{
9393
$refreshToken = $token->refreshToken;
9494

9595
if(empty($refreshToken)){
96-
throw new ProviderException(sprintf('no refresh token available, token expired [%s]', date('Y-m-d h:i:s A', $token->expires)));
96+
throw new ProviderException(
97+
sprintf('no refresh token available, token expired [%s]', date('Y-m-d h:i:s A', $token->expires))
98+
);
9799
}
98100

99101
$body = [
@@ -130,7 +132,13 @@ public function refreshAccessToken(AccessToken $token = null):AccessToken{
130132
*
131133
* @return \Psr\Http\Message\ResponseInterface
132134
*/
133-
public function request(string $path, array $params = null, string $method = null, $body = null, array $headers = null):ResponseInterface{
135+
public function request(
136+
string $path,
137+
array $params = null,
138+
string $method = null,
139+
$body = null,
140+
array $headers = null
141+
):ResponseInterface{
134142
$params = $params ?? [];
135143
$method = strtoupper($method);
136144
$token = $this->storage->getAccessToken($this->serviceName);

tests/FunctionTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@
1313
namespace chillerlan\OAuthTest\Providers;
1414

1515
use chillerlan\OAuth\Core\OAuthInterface;
16-
use chillerlan\OAuth\Providers;
16+
use function chillerlan\OAuth\Providers\getProviders;
1717

1818
use PHPUnit\Framework\TestCase;
1919

2020
class FunctionTest extends TestCase{
2121

2222
public function testGetProviders(){
23-
$providers = Providers\getProviders();
2423

25-
foreach($providers as $p){
24+
foreach(getProviders() as $p){
2625
$this->assertTrue((new \ReflectionClass($p['fqcn']))->implementsInterface(OAuthInterface::class));
2726
}
2827

0 commit comments

Comments
 (0)