Skip to content

Commit daf2fc1

Browse files
committed
coding style
1 parent 5b7dcbb commit daf2fc1

5 files changed

Lines changed: 54 additions & 26 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 & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,17 @@ 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
306-
{
305+
public static function from_request(
306+
string $http_method = null,
307+
string $http_url = null,
308+
array $parameters = null
309+
): self {
307310
$scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')
308311
? 'http'
309312
: 'https';
310-
$http_url = ($http_url) ? $http_url : $scheme .
313+
$http_url = ($http_url)
314+
? $http_url
315+
: $scheme .
311316
'://' . $_SERVER['HTTP_HOST'] .
312317
':' .
313318
$_SERVER['SERVER_PORT'] .
@@ -339,7 +344,10 @@ public static function from_request(string $http_method = null, string $http_url
339344

340345
// We have a Authorization-header with OAuth data. Parse the header
341346
// and add those overriding any duplicates from GET or POST
342-
if (isset($request_headers['Authorization']) && substr($request_headers['Authorization'], 0, 6) == 'OAuth ') {
347+
if (
348+
isset($request_headers['Authorization'])
349+
&& substr($request_headers['Authorization'], 0, 6) == 'OAuth '
350+
) {
343351
$header_parameters = Util::split_header(
344352
$request_headers['Authorization']
345353
);
@@ -354,8 +362,13 @@ public static function from_request(string $http_method = null, string $http_url
354362
/**
355363
* pretty much a helper function to set up the request
356364
*/
357-
public static function from_consumer_and_token(Consumer $consumer, ?Token $token, string $http_method, string $http_url, array $parameters = null): self
358-
{
365+
public static function from_consumer_and_token(
366+
Consumer $consumer,
367+
?Token $token,
368+
string $http_method,
369+
string $http_url,
370+
array $parameters = null
371+
): self {
359372
$parameters = $parameters ?: [];
360373
$defaults = [
361374
'oauth_version' => self::$version,
@@ -392,7 +405,7 @@ public function set_parameter(string $name, $value, bool $allow_duplicates = tru
392405

393406
public function get_parameter(string $name)
394407
{
395-
return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
408+
return $this->parameters[$name] ?? null;
396409
}
397410

398411

@@ -465,7 +478,9 @@ public function get_normalized_http_url(): string
465478
$parts = parse_url($this->http_url);
466479

467480
$scheme = (isset($parts['scheme'])) ? $parts['scheme'] : 'http';
468-
$port = (isset($parts['port'])) ? $parts['port'] : (($scheme == 'https') ? '443' : '80');
481+
$port = (isset($parts['port']))
482+
? $parts['port']
483+
: (($scheme == 'https') ? '443' : '80');
469484
$host = (isset($parts['host'])) ? $parts['host'] : '';
470485
$path = (isset($parts['path'])) ? $parts['path'] : '';
471486

@@ -581,7 +596,7 @@ class Util
581596
public static function urlencode_rfc3986($input)
582597
{
583598
if (is_array($input)) {
584-
return array_map([__CLASS__, 'urlencode_rfc3986'], $input);
599+
return array_map([self::class, 'urlencode_rfc3986'], $input);
585600
} elseif (is_scalar($input)) {
586601
return str_replace('+', ' ', str_replace('%7E', '~', rawurlencode((string) $input)));
587602
} else {

src/Twitter.php

Lines changed: 24 additions & 11 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,8 +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
200-
{
203+
public function loadUserFollowers(
204+
string $username,
205+
int $count = 5000,
206+
int $cursor = -1,
207+
$cacheExpiry = null
208+
): stdClass {
201209
return $this->cachedRequest('followers/ids', [
202210
'screen_name' => $username,
203211
'count' => $count,
@@ -211,8 +219,12 @@ public function loadUserFollowers(string $username, int $count = 5000, int $curs
211219
* https://dev.twitter.com/rest/reference/get/followers/list
212220
* @throws Exception
213221
*/
214-
public function loadUserFollowersList(string $username, int $count = 200, int $cursor = -1, $cacheExpiry = null): stdClass
215-
{
222+
public function loadUserFollowersList(
223+
string $username,
224+
int $count = 200,
225+
int $cursor = -1,
226+
$cacheExpiry = null
227+
): stdClass {
216228
return $this->cachedRequest('followers/list', [
217229
'screen_name' => $username,
218230
'count' => $count,
@@ -347,9 +359,8 @@ public function request(string $resource, string $method, array $data = [], arra
347359

348360
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
349361
if ($code >= 400) {
350-
throw new Exception(isset($payload->errors[0]->message)
351-
? $payload->errors[0]->message
352-
: "Server error #$code with answer $result",
362+
throw new Exception(
363+
$payload->errors[0]->message ?? "Server error #$code with answer $result",
353364
$code
354365
);
355366
} elseif ($code === 204) {
@@ -379,7 +390,9 @@ public function cachedRequest(string $resource, array $data = [], $cacheExpire =
379390
. '.json';
380391

381392
$cache = @json_decode((string) @file_get_contents($cacheFile)); // intentionally @
382-
$expiration = is_string($cacheExpire) ? strtotime($cacheExpire) - time() : $cacheExpire;
393+
$expiration = is_string($cacheExpire)
394+
? strtotime($cacheExpire) - time()
395+
: $cacheExpire;
383396
if ($cache && @filemtime($cacheFile) + $expiration > time()) { // intentionally @
384397
return $cache;
385398
}
@@ -424,7 +437,7 @@ public static function clickable(stdClass $status): string
424437
}
425438

426439
krsort($all);
427-
$s = isset($status->full_text) ? $status->full_text : $status->text;
440+
$s = $status->full_text ?? $status->text;
428441
foreach ($all as $pos => $item) {
429442
$s = iconv_substr($s, 0, $pos, 'UTF-8')
430443
. '<a href="' . htmlspecialchars($item[0]) . '">' . htmlspecialchars($item[1]) . '</a>'

0 commit comments

Comments
 (0)