Skip to content

Commit bcec11b

Browse files
committed
coding style
1 parent 5b7dcbb commit bcec11b

5 files changed

Lines changed: 54 additions & 22 deletions

File tree

examples/custom-request.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
<title>Twitter retweets of me</title>
1717

1818
<ul>
19-
<?php foreach ($statuses as $status): ?>
19+
<?php foreach ($statuses as $status) { ?>
2020
<li><a href="http://twitter.com/<?php echo $status->user->screen_name ?>"><img src="<?php echo htmlspecialchars($status->user->profile_image_url_https) ?>">
2121
<?php echo htmlspecialchars($status->user->name) ?></a>:
2222
<?php echo Twitter::clickable($status) ?>
2323
<small>at <?php echo date('j.n.Y H:i', strtotime($status->created_at)) ?></small>
2424
</li>
25-
<?php endforeach ?>
25+
<?php } ?>
2626
</ul>

examples/load.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
<title>Twitter timeline demo</title>
2020

2121
<ul>
22-
<?php foreach ($statuses as $status): ?>
22+
<?php foreach ($statuses as $status) { ?>
2323
<li><a href="https://twitter.com/<?php echo $status->user->screen_name ?>"><img src="<?php echo htmlspecialchars($status->user->profile_image_url_https) ?>">
2424
<?php echo htmlspecialchars($status->user->name) ?></a>:
2525
<?php echo Twitter::clickable($status) ?>
2626
<small>at <?php echo date('j.n.Y H:i', strtotime($status->created_at)) ?></small>
2727
</li>
28-
<?php endforeach ?>
28+
<?php } ?>
2929
</ul>

examples/search.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
<title>Twitter search demo</title>
1717

1818
<ul>
19-
<?php foreach ($results as $status): ?>
19+
<?php foreach ($results as $status) { ?>
2020
<li><a href="https://twitter.com/<?php echo $status->user->screen_name ?>"><img src="<?php echo htmlspecialchars($status->user->profile_image_url_https) ?>">
2121
<?php echo htmlspecialchars($status->user->name) ?></a>:
2222
<?php echo Twitter::clickable($status) ?>
2323
<small>at <?php echo date('j.n.Y H:i', strtotime($status->created_at)) ?></small>
2424
</li>
25-
<?php endforeach ?>
25+
<?php } ?>
2626
</ul>

src/OAuth.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,18 @@ public function __construct(string $http_method, string $http_url, array $parame
302302
/**
303303
* attempt to build up a request from what was passed to the server
304304
*/
305-
public static function from_request(string $http_method = null, string $http_url = null, array $parameters = null): self
305+
public static function from_request(
306+
string $http_method = null,
307+
string $http_url = null,
308+
array $parameters = null
309+
): self
306310
{
307311
$scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')
308312
? 'http'
309313
: 'https';
310-
$http_url = ($http_url) ? $http_url : $scheme .
314+
$http_url = ($http_url)
315+
? $http_url
316+
: $scheme .
311317
'://' . $_SERVER['HTTP_HOST'] .
312318
':' .
313319
$_SERVER['SERVER_PORT'] .
@@ -339,7 +345,10 @@ public static function from_request(string $http_method = null, string $http_url
339345

340346
// We have a Authorization-header with OAuth data. Parse the header
341347
// and add those overriding any duplicates from GET or POST
342-
if (isset($request_headers['Authorization']) && substr($request_headers['Authorization'], 0, 6) == 'OAuth ') {
348+
if (
349+
isset($request_headers['Authorization'])
350+
&& substr($request_headers['Authorization'], 0, 6) == 'OAuth '
351+
) {
343352
$header_parameters = Util::split_header(
344353
$request_headers['Authorization']
345354
);
@@ -354,7 +363,13 @@ public static function from_request(string $http_method = null, string $http_url
354363
/**
355364
* pretty much a helper function to set up the request
356365
*/
357-
public static function from_consumer_and_token(Consumer $consumer, ?Token $token, string $http_method, string $http_url, array $parameters = null): self
366+
public static function from_consumer_and_token(
367+
Consumer $consumer,
368+
?Token $token,
369+
string $http_method,
370+
string $http_url,
371+
array $parameters = null
372+
): self
358373
{
359374
$parameters = $parameters ?: [];
360375
$defaults = [
@@ -392,7 +407,7 @@ public function set_parameter(string $name, $value, bool $allow_duplicates = tru
392407

393408
public function get_parameter(string $name)
394409
{
395-
return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
410+
return $this->parameters[$name] ?? null;
396411
}
397412

398413

@@ -465,7 +480,9 @@ public function get_normalized_http_url(): string
465480
$parts = parse_url($this->http_url);
466481

467482
$scheme = (isset($parts['scheme'])) ? $parts['scheme'] : 'http';
468-
$port = (isset($parts['port'])) ? $parts['port'] : (($scheme == 'https') ? '443' : '80');
483+
$port = (isset($parts['port']))
484+
? $parts['port']
485+
: (($scheme == 'https') ? '443' : '80');
469486
$host = (isset($parts['host'])) ? $parts['host'] : '';
470487
$path = (isset($parts['path'])) ? $parts['path'] : '';
471488

@@ -581,7 +598,7 @@ class Util
581598
public static function urlencode_rfc3986($input)
582599
{
583600
if (is_array($input)) {
584-
return array_map([__CLASS__, 'urlencode_rfc3986'], $input);
601+
return array_map([self::class, 'urlencode_rfc3986'], $input);
585602
} elseif (is_scalar($input)) {
586603
return str_replace('+', ' ', str_replace('%7E', '~', rawurlencode((string) $input)));
587604
} else {

src/Twitter.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ class Twitter
5454
* Creates object using consumer and access keys.
5555
* @throws Exception when CURL extension is not loaded
5656
*/
57-
public function __construct(string $consumerKey, string $consumerSecret, string $accessToken = null, string $accessTokenSecret = null)
58-
{
57+
public function __construct(
58+
string $consumerKey,
59+
string $consumerSecret,
60+
string $accessToken = null,
61+
string $accessTokenSecret = null
62+
) {
5963
if (!extension_loaded('curl')) {
6064
throw new Exception('PHP extension CURL is not loaded.');
6165
}
@@ -196,7 +200,12 @@ public function loadUserInfoById(string $id): stdClass
196200
* https://dev.twitter.com/rest/reference/get/followers/ids
197201
* @throws Exception
198202
*/
199-
public function loadUserFollowers(string $username, int $count = 5000, int $cursor = -1, $cacheExpiry = null): stdClass
203+
public function loadUserFollowers(
204+
string $username,
205+
int $count = 5000,
206+
int $cursor = -1,
207+
$cacheExpiry = null
208+
): stdClass
200209
{
201210
return $this->cachedRequest('followers/ids', [
202211
'screen_name' => $username,
@@ -211,7 +220,12 @@ public function loadUserFollowers(string $username, int $count = 5000, int $curs
211220
* https://dev.twitter.com/rest/reference/get/followers/list
212221
* @throws Exception
213222
*/
214-
public function loadUserFollowersList(string $username, int $count = 200, int $cursor = -1, $cacheExpiry = null): stdClass
223+
public function loadUserFollowersList(
224+
string $username,
225+
int $count = 200,
226+
int $cursor = -1,
227+
$cacheExpiry = null
228+
): stdClass
215229
{
216230
return $this->cachedRequest('followers/list', [
217231
'screen_name' => $username,
@@ -347,9 +361,8 @@ public function request(string $resource, string $method, array $data = [], arra
347361

348362
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
349363
if ($code >= 400) {
350-
throw new Exception(isset($payload->errors[0]->message)
351-
? $payload->errors[0]->message
352-
: "Server error #$code with answer $result",
364+
throw new Exception(
365+
$payload->errors[0]->message ?? "Server error #$code with answer $result",
353366
$code
354367
);
355368
} elseif ($code === 204) {
@@ -379,7 +392,9 @@ public function cachedRequest(string $resource, array $data = [], $cacheExpire =
379392
. '.json';
380393

381394
$cache = @json_decode((string) @file_get_contents($cacheFile)); // intentionally @
382-
$expiration = is_string($cacheExpire) ? strtotime($cacheExpire) - time() : $cacheExpire;
395+
$expiration = is_string($cacheExpire)
396+
? strtotime($cacheExpire) - time()
397+
: $cacheExpire;
383398
if ($cache && @filemtime($cacheFile) + $expiration > time()) { // intentionally @
384399
return $cache;
385400
}
@@ -424,7 +439,7 @@ public static function clickable(stdClass $status): string
424439
}
425440

426441
krsort($all);
427-
$s = isset($status->full_text) ? $status->full_text : $status->text;
442+
$s = $status->full_text ?? $status->text;
428443
foreach ($all as $pos => $item) {
429444
$s = iconv_substr($s, 0, $pos, 'UTF-8')
430445
. '<a href="' . htmlspecialchars($item[0]) . '">' . htmlspecialchars($item[1]) . '</a>'

0 commit comments

Comments
 (0)