Skip to content

Commit d1bedce

Browse files
authored
Fix PHP 8+ compat issues (#126)
1 parent 8df338b commit d1bedce

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

lib/Tumblr/API/Client.php

+14-10
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@
77
*/
88
class Client
99
{
10-
10+
/** @var string */
1111
private $apiKey;
1212

13+
/** @var RequestHandler */
14+
public $requestHandler;
15+
1316
/**
1417
* Create a new Client
1518
*
1619
* @param string $consumerKey the consumer key
17-
* @param string $consumerSecret the consumer secret
18-
* @param string $token oauth token
19-
* @param string $secret oauth token secret
20+
* @param string|null $consumerSecret the consumer secret
21+
* @param string|null $token oauth token
22+
* @param string|null $secret oauth token secret
2023
*/
2124
public function __construct($consumerKey, $consumerSecret = null, $token = null, $secret = null)
2225
{
@@ -32,7 +35,8 @@ public function __construct($consumerKey, $consumerSecret = null, $token = null,
3235
* Set the consumer for this client
3336
*
3437
* @param string $consumerKey the consumer key
35-
* @param string $consumerSecret the consumer secret
38+
* @param string|null $consumerSecret the consumer secret
39+
* @return void
3640
*/
3741
public function setConsumer($consumerKey, $consumerSecret)
3842
{
@@ -265,7 +269,7 @@ public function getBlogInfo($blogName)
265269
* @param string $blogName the nae of the blog to look up
266270
* @param int $size the size to retrieve
267271
*
268-
* @return string the avatar url
272+
* @return string|null the avatar url
269273
*/
270274
public function getBlogAvatar($blogName, $size = null)
271275
{
@@ -375,7 +379,7 @@ public function getSubmissionPosts($blogName, $options = null)
375379
* Make a GET request to the given endpoint and return the response
376380
*
377381
* @param string $path the path to call on
378-
* @param array $options the options to call with
382+
* @param array|null $options the options to call with
379383
* @param bool $addApiKey whether or not to add the api key
380384
*
381385
* @return array the response object (parsed)
@@ -432,10 +436,10 @@ private function parseResponse($response)
432436
* Make a GET request to the given endpoint and return the response
433437
*
434438
* @param string $path the path to call on
435-
* @param array $options the options to call with
439+
* @param array|null $options the options to call with
436440
* @param bool $addApiKey whether or not to add the api key
437441
*
438-
* @return string url redirected to (or null)
442+
* @return string|null url redirected to (or null)
439443
*/
440444
private function getRedirect($path, $options, $addApiKey)
441445
{
@@ -452,7 +456,7 @@ private function getRedirect($path, $options, $addApiKey)
452456
*
453457
* @param string $method the method to call: GET, POST
454458
* @param string $path the path to call on
455-
* @param array $options the options to call with
459+
* @param array|null $options the options to call with
456460
* @param bool $addApiKey whether or not to add the api key
457461
*
458462
* @return \stdClass the response object (not parsed)

lib/Tumblr/API/RequestException.php

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
class RequestException extends \Exception
66
{
7+
/** @var string|int */
8+
public $statusCode;
79

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

32+
/**
33+
* @return string
34+
*/
35+
#[\ReturnTypeWillChange]
3036
public function __toString()
3137
{
3238
return __CLASS__ . ": [$this->statusCode]: $this->message\n";

lib/Tumblr/API/RequestHandler.php

+15-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,22 @@
88
*/
99
class RequestHandler
1010
{
11-
11+
/** @var \Eher\OAuth\Consumer */
1212
private $consumer;
13+
/** @var \Eher\OAuth\Token */
1314
private $token;
15+
/** @var \Eher\OAuth\HmacSha1 */
1416
private $signatureMethod;
1517

18+
/** @var string */
1619
private $baseUrl;
20+
21+
/** @var string */
1722
private $version;
1823

24+
/** @var \GuzzleHttp\Client */
25+
public $client;
26+
1927
/**
2028
* Instantiate a new RequestHandler
2129
*/
@@ -34,7 +42,8 @@ public function __construct()
3442
* Set the consumer for this request handler
3543
*
3644
* @param string $key the consumer key
37-
* @param string $secret the consumer secret
45+
* @param string|null $secret the consumer secret
46+
* @return void
3847
*/
3948
public function setConsumer($key, $secret)
4049
{
@@ -46,6 +55,7 @@ public function setConsumer($key, $secret)
4655
*
4756
* @param string $token the oauth token
4857
* @param string $secret the oauth secret
58+
* @return void
4959
*/
5060
public function setToken($token, $secret)
5161
{
@@ -56,6 +66,7 @@ public function setToken($token, $secret)
5666
* Set the base url for this request handler.
5767
*
5868
* @param string $url The base url (e.g. https://api.tumblr.com)
69+
* @return void
5970
*/
6071
public function setBaseUrl($url)
6172
{
@@ -72,7 +83,7 @@ public function setBaseUrl($url)
7283
*
7384
* @param string $method one of GET, POST
7485
* @param string $path the path to hit
75-
* @param array $options the array of params
86+
* @param array|null $options the array of params
7687
*
7788
* @return \stdClass response object
7889
*/
@@ -96,7 +107,7 @@ public function request($method, $path, $options)
96107
);
97108
$oauth->sign_request($this->signatureMethod, $this->consumer, $this->token);
98109
$authHeader = $oauth->to_header();
99-
$pieces = explode(' ', $authHeader, 2);
110+
$pieces = explode(' ', $authHeader, 2) + [1 => ''];
100111
$authString = $pieces[1];
101112

102113

0 commit comments

Comments
 (0)