Skip to content

Commit

Permalink
Fix PHP 8+ compat issues (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanmai committed Apr 4, 2023
1 parent 8df338b commit d1bedce
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
24 changes: 14 additions & 10 deletions lib/Tumblr/API/Client.php
Expand Up @@ -7,16 +7,19 @@
*/
class Client
{

/** @var string */
private $apiKey;

/** @var RequestHandler */
public $requestHandler;

/**
* Create a new Client
*
* @param string $consumerKey the consumer key
* @param string $consumerSecret the consumer secret
* @param string $token oauth token
* @param string $secret oauth token secret
* @param string|null $consumerSecret the consumer secret
* @param string|null $token oauth token
* @param string|null $secret oauth token secret
*/
public function __construct($consumerKey, $consumerSecret = null, $token = null, $secret = null)
{
Expand All @@ -32,7 +35,8 @@ public function __construct($consumerKey, $consumerSecret = null, $token = null,
* Set the consumer for this client
*
* @param string $consumerKey the consumer key
* @param string $consumerSecret the consumer secret
* @param string|null $consumerSecret the consumer secret
* @return void
*/
public function setConsumer($consumerKey, $consumerSecret)
{
Expand Down Expand Up @@ -265,7 +269,7 @@ public function getBlogInfo($blogName)
* @param string $blogName the nae of the blog to look up
* @param int $size the size to retrieve
*
* @return string the avatar url
* @return string|null the avatar url
*/
public function getBlogAvatar($blogName, $size = null)
{
Expand Down Expand Up @@ -375,7 +379,7 @@ public function getSubmissionPosts($blogName, $options = null)
* Make a GET request to the given endpoint and return the response
*
* @param string $path the path to call on
* @param array $options the options to call with
* @param array|null $options the options to call with
* @param bool $addApiKey whether or not to add the api key
*
* @return array the response object (parsed)
Expand Down Expand Up @@ -432,10 +436,10 @@ private function parseResponse($response)
* Make a GET request to the given endpoint and return the response
*
* @param string $path the path to call on
* @param array $options the options to call with
* @param array|null $options the options to call with
* @param bool $addApiKey whether or not to add the api key
*
* @return string url redirected to (or null)
* @return string|null url redirected to (or null)
*/
private function getRedirect($path, $options, $addApiKey)
{
Expand All @@ -452,7 +456,7 @@ private function getRedirect($path, $options, $addApiKey)
*
* @param string $method the method to call: GET, POST
* @param string $path the path to call on
* @param array $options the options to call with
* @param array|null $options the options to call with
* @param bool $addApiKey whether or not to add the api key
*
* @return \stdClass the response object (not parsed)
Expand Down
6 changes: 6 additions & 0 deletions lib/Tumblr/API/RequestException.php
Expand Up @@ -4,6 +4,8 @@

class RequestException extends \Exception
{
/** @var string|int */
public $statusCode;

/**
* @param \stdClass $response
Expand All @@ -27,6 +29,10 @@ public function __construct($response)
parent::__construct($this->message, $this->statusCode);
}

/**
* @return string
*/
#[\ReturnTypeWillChange]
public function __toString()
{
return __CLASS__ . ": [$this->statusCode]: $this->message\n";
Expand Down
19 changes: 15 additions & 4 deletions lib/Tumblr/API/RequestHandler.php
Expand Up @@ -8,14 +8,22 @@
*/
class RequestHandler
{

/** @var \Eher\OAuth\Consumer */
private $consumer;
/** @var \Eher\OAuth\Token */
private $token;
/** @var \Eher\OAuth\HmacSha1 */
private $signatureMethod;

/** @var string */
private $baseUrl;

/** @var string */
private $version;

/** @var \GuzzleHttp\Client */
public $client;

/**
* Instantiate a new RequestHandler
*/
Expand All @@ -34,7 +42,8 @@ public function __construct()
* Set the consumer for this request handler
*
* @param string $key the consumer key
* @param string $secret the consumer secret
* @param string|null $secret the consumer secret
* @return void
*/
public function setConsumer($key, $secret)
{
Expand All @@ -46,6 +55,7 @@ public function setConsumer($key, $secret)
*
* @param string $token the oauth token
* @param string $secret the oauth secret
* @return void
*/
public function setToken($token, $secret)
{
Expand All @@ -56,6 +66,7 @@ public function setToken($token, $secret)
* Set the base url for this request handler.
*
* @param string $url The base url (e.g. https://api.tumblr.com)
* @return void
*/
public function setBaseUrl($url)
{
Expand All @@ -72,7 +83,7 @@ public function setBaseUrl($url)
*
* @param string $method one of GET, POST
* @param string $path the path to hit
* @param array $options the array of params
* @param array|null $options the array of params
*
* @return \stdClass response object
*/
Expand All @@ -96,7 +107,7 @@ public function request($method, $path, $options)
);
$oauth->sign_request($this->signatureMethod, $this->consumer, $this->token);
$authHeader = $oauth->to_header();
$pieces = explode(' ', $authHeader, 2);
$pieces = explode(' ', $authHeader, 2) + [1 => ''];
$authString = $pieces[1];


Expand Down

0 comments on commit d1bedce

Please sign in to comment.