Skip to content

Commit 878607c

Browse files
Do not extend Guzzle\Client
Extending Guzzle\Client is deprecated since Guzzle 7.1 and the class is annotated as @Final. The class will be actually final in Guzzle 8.0
1 parent 9bed0f6 commit 878607c

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ $twitch_client_id = 'TWITCH_CLIENT_ID';
4040
$twitch_client_secret = 'TWITCH_CLIENT_SECRET';
4141
$twitch_scopes = '';
4242

43-
$helixGuzzleClient = new \NewTwitchApi\HelixGuzzleClient($twitch_client_id);
43+
$helixGuzzleClient = \NewTwitchApi\HelixGuzzleClient::getClient($twitch_client_id);
4444
$newTwitchApi = new \NewTwitchApi\NewTwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret);
4545
$oauth = $newTwitchApi->getOauthApi();
4646

@@ -62,7 +62,7 @@ $twitch_client_id = 'TWITCH_CLIENT_ID';
6262
$twitch_client_secret = 'TWITCH_CLIENT_SECRET';
6363
$twitch_scopes = '';
6464

65-
$helixGuzzleClient = new \NewTwitchApi\HelixGuzzleClient($twitch_client_id);
65+
$helixGuzzleClient = \NewTwitchApi\HelixGuzzleClient::getClient($twitch_client_id);
6666
$newTwitchApi = new \NewTwitchApi\NewTwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret);
6767
$oauth = $newTwitchApi->getOauthApi();
6868

@@ -104,7 +104,7 @@ $twitch_client_secret = 'TWITCH_CLIENT_SECRET';
104104
$twitch_scopes = '';
105105
$user_refresh_token = 'REFRESH_TOKEN';
106106

107-
$helixGuzzleClient = new \NewTwitchApi\HelixGuzzleClient($twitch_client_id);
107+
$helixGuzzleClient = \NewTwitchApi\HelixGuzzleClient::getClient($twitch_client_id);
108108
$newTwitchApi = new \NewTwitchApi\NewTwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret);
109109
$oauth = $newTwitchApi->getOauthApi();
110110

@@ -140,7 +140,7 @@ $twitch_access_token = 'the token';
140140

141141
// The Guzzle client used can be the included `HelixGuzzleClient` class, for convenience.
142142
// You can also use a mock, fake, or other double for testing, of course.
143-
$helixGuzzleClient = new HelixGuzzleClient($twitch_client_id);
143+
$helixGuzzleClient = \NewTwitchApi\HelixGuzzleClient::getClient($twitch_client_id);
144144

145145
// Instantiate NewTwitchApi. Can be done in a service layer and injected as well.
146146
$newTwitchApi = new NewTwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret);

src/NewTwitchApi/Auth/AuthGuzzleClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
use GuzzleHttp\Client;
88

9-
class AuthGuzzleClient extends Client
9+
class AuthGuzzleClient
1010
{
1111
private const BASE_URI = 'https://id.twitch.tv/oauth2/';
1212

13-
public function __construct(array $config = [])
13+
public static function getClient(array $config = []): Client
1414
{
15-
parent::__construct($config + [
15+
return new Client($config + [
1616
'base_uri' => self::BASE_URI,
1717
]);
1818
}

src/NewTwitchApi/Auth/OauthApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct(string $clientId, string $clientSecret, Client $guzz
2020
{
2121
$this->clientId = $clientId;
2222
$this->clientSecret = $clientSecret;
23-
$this->guzzleClient = $guzzleClient ?? new AuthGuzzleClient();
23+
$this->guzzleClient = $guzzleClient ?? AuthGuzzleClient::getClient();
2424
}
2525

2626
/**

src/NewTwitchApi/HelixGuzzleClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
use GuzzleHttp\Client;
88

9-
class HelixGuzzleClient extends Client
9+
class HelixGuzzleClient
1010
{
1111
private const BASE_URI = 'https://api.twitch.tv/helix/';
1212

13-
public function __construct(string $clientId, array $config = [])
13+
public static function getClient(string $clientId, array $config = []): Client
1414
{
15-
parent::__construct($config + [
15+
return new Client($config + [
1616
'base_uri' => self::BASE_URI,
1717
'timeout' => 30,
1818
'headers' => ['Client-ID' => $clientId, 'Content-Type' => 'application/json'],

src/NewTwitchApi/Webhooks/WebhooksSubscriptionApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct(string $clientId, string $secret, Client $guzzleClie
2020
{
2121
$this->clientId = $clientId;
2222
$this->secret = $secret;
23-
$this->guzzleClient = $guzzleClient ?? new HelixGuzzleClient($clientId);
23+
$this->guzzleClient = $guzzleClient ?? HelixGuzzleClient::getClient($clientId);
2424
}
2525

2626
public function subscribeToStream(string $twitchId, string $callback, string $bearer, int $leaseSeconds = 0): void

0 commit comments

Comments
 (0)