Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
Update to latest PHP 8.1 syntax
Browse files Browse the repository at this point in the history
Signed-off-by: Abdul Malik Ikhsan <[email protected]>
  • Loading branch information
samsonasik committed Nov 2, 2024
1 parent 5182456 commit d5a54d6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 34 deletions.
25 changes: 10 additions & 15 deletions src/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,16 @@ public function getRequestSchemeQueryStringClient(array $params, $url)
*/
protected function assessRequestAttempt(?Response $response = null)
{
switch ($this->preferredRequestScheme) {
case OAuth::REQUEST_SCHEME_HEADER:
$this->preferredRequestScheme = OAuth::REQUEST_SCHEME_POSTBODY;
break;
case OAuth::REQUEST_SCHEME_POSTBODY:
$this->preferredRequestScheme = OAuth::REQUEST_SCHEME_QUERYSTRING;
break;
default:
throw new Exception\RuntimeException(
'Could not retrieve a valid Token response from Token URL:'
. ($response !== null
? PHP_EOL . $response->getBody()
: ' No body - check for headers')
);
}
$this->preferredRequestScheme = match ($this->preferredRequestScheme) {
OAuth::REQUEST_SCHEME_HEADER => OAuth::REQUEST_SCHEME_POSTBODY,
OAuth::REQUEST_SCHEME_POSTBODY => OAuth::REQUEST_SCHEME_QUERYSTRING,
default => throw new Exception\RuntimeException(
'Could not retrieve a valid Token response from Token URL:'
. ($response !== null
? PHP_EOL . $response->getBody()
: ' No body - check for headers')
),
};
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Http/Utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
use function explode;
use function implode;
use function md5;
use function mt_getrandmax;
use function preg_match;
use function rand;
use function random_int;
use function rawurldecode;
use function rawurlencode;
use function str_replace;
Expand Down Expand Up @@ -179,7 +180,7 @@ public function parseQueryString($query)
*/
public function generateNonce()
{
return md5(uniqid(rand(), true));
return md5(uniqid(random_int(0, mt_getrandmax()), true));
}

/**
Expand Down
18 changes: 8 additions & 10 deletions src/Signature/AbstractSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ abstract class AbstractSignature implements SignatureInterface
*/
protected $key;

/**
* Consumer secret
*
* @var string
*/
protected $consumerSecret;

/**
* Token secret
*
Expand All @@ -51,9 +44,14 @@ abstract class AbstractSignature implements SignatureInterface
* @param null|string $hashAlgo
* @return void
*/
public function __construct($consumerSecret, $tokenSecret = null, $hashAlgo = null)
{
$this->consumerSecret = $consumerSecret;
public function __construct(
/**
* Consumer secret
*/
protected $consumerSecret,
$tokenSecret = null,
$hashAlgo = null
) {
if (isset($tokenSecret)) {
$this->tokenSecret = $tokenSecret;
}
Expand Down
9 changes: 2 additions & 7 deletions src/Token/AbstractToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,7 @@ public function setParams(array $params)
*/
public function getParam($key)
{
if (isset($this->params[$key])) {
return $this->params[$key];
}
return null;
return $this->params[$key] ?? null;
}

/**
Expand Down Expand Up @@ -213,10 +210,8 @@ public function toString()
/**
* Convert Token to a string, specifically a raw encoded query string.
* Aliases to self::toString()
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return $this->toString();
}
Expand Down

0 comments on commit d5a54d6

Please sign in to comment.