Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PHP 8+ compat issues #126

Merged
merged 1 commit into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 14 additions & 10 deletions lib/Tumblr/API/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@
*/
class Client
{

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

/** @var RequestHandler */
public $requestHandler;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These properties were effectively public before, so to avoid BC breaks we have to keep them public as well.


/**
* 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 => ''];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only code change here: to guard against $authHeader having no space.

$authString = $pieces[1];


Expand Down