Skip to content

Commit e095168

Browse files
authored
Merge pull request #70 from imdhemy/depend-on-client-interface
[1.x] Depend on client interface
2 parents 98fd9fe + ea2fd7e commit e095168

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

src/ClientFactory.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Imdhemy\AppStore;
44

55
use GuzzleHttp\Client;
6+
use GuzzleHttp\ClientInterface;
67
use GuzzleHttp\Handler\MockHandler;
78
use GuzzleHttp\HandlerStack;
89
use GuzzleHttp\Middleware;
@@ -24,9 +25,9 @@ class ClientFactory
2425
* @param bool $sandbox
2526
* @param array $options
2627
*
27-
* @return Client
28+
* @return ClientInterface
2829
*/
29-
public static function create(bool $sandbox = false, array $options = []): Client
30+
public static function create(bool $sandbox = false, array $options = []): ClientInterface
3031
{
3132
if (empty($options['base_uri'])) {
3233
$options['base_uri'] = $sandbox ? self::BASE_URI_SANDBOX : self::BASE_URI;
@@ -36,9 +37,9 @@ public static function create(bool $sandbox = false, array $options = []): Clien
3637
}
3738

3839
/**
39-
* @return Client
40+
* @return ClientInterface
4041
*/
41-
public static function createSandbox(): Client
42+
public static function createSandbox(): ClientInterface
4243
{
4344
return self::create(true);
4445
}
@@ -50,9 +51,9 @@ public static function createSandbox(): Client
5051
* @param array $transactions
5152
*
5253
* @psalm-suppress ReferenceConstraintViolation
53-
* @return Client
54+
* @return ClientInterface
5455
*/
55-
public static function mock(ResponseInterface $responseMock, array &$transactions = []): Client
56+
public static function mock(ResponseInterface $responseMock, array &$transactions = []): ClientInterface
5657
{
5758
$mockHandler = new MockHandler([$responseMock]);
5859
$handlerStack = HandlerStack::create($mockHandler);
@@ -68,9 +69,9 @@ public static function mock(ResponseInterface $responseMock, array &$transaction
6869
* @param array $transactions
6970
*
7071
* @psalm-suppress ReferenceConstraintViolation
71-
* @return Client
72+
* @return ClientInterface
7273
*/
73-
public static function mockQueue(array $responseQueue, array &$transactions = []): Client
74+
public static function mockQueue(array $responseQueue, array &$transactions = []): ClientInterface
7475
{
7576
$mockHandler = new MockHandler($responseQueue);
7677
$handlerStack = HandlerStack::create($mockHandler);
@@ -86,9 +87,9 @@ public static function mockQueue(array $responseQueue, array &$transactions = []
8687
* @param array $transactions
8788
*
8889
* @psalm-suppress ReferenceConstraintViolation
89-
* @return Client
90+
* @return ClientInterface
9091
*/
91-
public static function mockError(RequestExceptionInterface $error, array &$transactions = []): Client
92+
public static function mockError(RequestExceptionInterface $error, array &$transactions = []): ClientInterface
9293
{
9394
$mockHandler = new MockHandler([$error]);
9495
$handlerStack = HandlerStack::create($mockHandler);

src/Receipts/Verifier.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Imdhemy\AppStore\Receipts;
44

55
use GuzzleHttp\Client;
6+
use GuzzleHttp\ClientInterface;
67
use GuzzleHttp\Exception\GuzzleException;
78
use Imdhemy\AppStore\ClientFactory;
89
use Imdhemy\AppStore\Exceptions\InvalidReceiptException;
@@ -21,7 +22,7 @@ class Verifier
2122
public const VERIFY_RECEIPT_PATH = '/verifyReceipt';
2223

2324
/**
24-
* @var Client
25+
* @var ClientInterface
2526
*/
2627
protected $client;
2728

@@ -38,25 +39,25 @@ class Verifier
3839
/**
3940
* Receipt constructor.
4041
*
41-
* @param Client $client
42+
* @param ClientInterface $client
4243
* @param string $receiptData
4344
* @param string $password
4445
*/
45-
public function __construct(Client $client, string $receiptData, string $password)
46+
public function __construct(ClientInterface $client, string $receiptData, string $password)
4647
{
4748
$this->client = $client;
4849
$this->receiptData = $receiptData;
4950
$this->password = $password;
5051
}
5152

5253
/**
53-
* @param Client|null $sandboxClient
54+
* @param ClientInterface|null $sandboxClient
5455
*
5556
* @return ReceiptResponse
5657
* @throws GuzzleException|InvalidReceiptException
5758
* @deprecated Use verify() instead - this method will be removed in the next major release
5859
*/
59-
public function verifyRenewable(?Client $sandboxClient = null): ReceiptResponse
60+
public function verifyRenewable(?ClientInterface $sandboxClient = null): ReceiptResponse
6061
{
6162
return $this->verify(true, $sandboxClient);
6263
}
@@ -68,8 +69,10 @@ public function verifyRenewable(?Client $sandboxClient = null): ReceiptResponse
6869
* @return ReceiptResponse
6970
* @throws GuzzleException|InvalidReceiptException
7071
*/
71-
public function verify(bool $excludeOldTransactions = false, ?Client $sandboxClient = null): ReceiptResponse
72-
{
72+
public function verify(
73+
bool $excludeOldTransactions = false,
74+
?ClientInterface $sandboxClient = null
75+
): ReceiptResponse {
7376
$responseBody = $this->sendVerifyRequest($excludeOldTransactions);
7477
$status = $responseBody['status'];
7578

@@ -87,12 +90,12 @@ public function verify(bool $excludeOldTransactions = false, ?Client $sandboxCli
8790

8891
/**
8992
* @param bool $excludeOldTransactions
90-
* @param Client|null $client
93+
* @param ClientInterface|null $client
9194
*
9295
* @return array
9396
* @throws GuzzleException
9497
*/
95-
private function sendVerifyRequest(bool $excludeOldTransactions = false, ?Client $client = null): array
98+
private function sendVerifyRequest(bool $excludeOldTransactions = false, ?ClientInterface $client = null): array
9699
{
97100
$client = $client ?? $this->client;
98101
$options = $this->buildRequestOptions($excludeOldTransactions);

src/ServerNotifications/TestNotificationService.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Imdhemy\AppStore\ServerNotifications;
66

7-
use GuzzleHttp\Client;
7+
use GuzzleHttp\ClientInterface;
88
use GuzzleHttp\Exception\GuzzleException;
99
use Imdhemy\AppStore\Jws\JwsGenerator;
1010
use Psr\Http\Message\ResponseInterface;
@@ -16,20 +16,20 @@
1616
final class TestNotificationService
1717
{
1818
/**
19-
* @var Client
19+
* @var ClientInterface
2020
*/
21-
private Client $client;
21+
private ClientInterface $client;
2222

2323
/**
2424
* @var JwsGenerator
2525
*/
2626
private JwsGenerator $jwsGenerator;
2727

2828
/**
29-
* @param Client $client
29+
* @param ClientInterface $client
3030
* @param JwsGenerator $jwsGenerator
3131
*/
32-
public function __construct(Client $client, JwsGenerator $jwsGenerator)
32+
public function __construct(ClientInterface $client, JwsGenerator $jwsGenerator)
3333
{
3434
$this->client = $client;
3535
$this->jwsGenerator = $jwsGenerator;

0 commit comments

Comments
 (0)