Skip to content

Commit b5c653f

Browse files
committed
Improve HTTP Client structure
1 parent 590fb49 commit b5c653f

8 files changed

+26
-23
lines changed

app/Notification/AppNotificationInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66

77
use App\Notification\Client\HTTPClientAdapterInterface;
8-
use App\Notification\Client\ResponseAdapterInterface;
8+
use App\Notification\Client\HTTPResponseInterface;
99

1010
interface AppNotificationInterface
1111
{
1212
public function __construct(HTTPClientAdapterInterface $client, string $message, string $messageType);
1313

14-
public function notify(): ResponseAdapterInterface;
14+
public function notify(): HTTPResponseInterface;
1515
}

app/Notification/Client/Guzzle/GuzzleHTTPClient.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55

66

77
use App\Notification\Client\HTTPClientAdapterInterface;
8-
use App\Notification\Client\ResponseAdapterInterface;
8+
use App\Notification\Client\HTTPResponseInterface;
99
use GuzzleHttp\Client;
10-
use Psr\Http\Message\ResponseInterface;
1110

1211
class GuzzleHTTPClient implements HTTPClientAdapterInterface
1312
{
@@ -18,15 +17,15 @@ public function __construct()
1817
$this->client = new Client();
1918
}
2019

21-
public function post(string $url, array $params): ResponseAdapterInterface
20+
public function post(string $url, array $params): HTTPResponseInterface
2221
{
23-
$clientResponse = $this->client->post(
22+
$guzzleResponse = $this->client->post(
2423
$url,
2524
[
2625
'json' => $params
2726
]
2827
);
2928

30-
return new GuzzleResponse($clientResponse);
29+
return new HTTPResponse($guzzleResponse);
3130
}
3231
}

app/Notification/Client/Guzzle/GuzzleResponse.php renamed to app/Notification/Client/Guzzle/HTTPResponse.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
namespace App\Notification\Client\Guzzle;
55

66

7-
use App\Notification\Client\ResponseAdapterInterface;
7+
use App\Notification\Client\HTTPResponseInterface;
88
use Psr\Http\Message\ResponseInterface;
99

10-
class GuzzleResponse implements ResponseAdapterInterface
10+
class HTTPResponse implements HTTPResponseInterface
1111
{
1212
private ResponseInterface $clientResponse;
1313

app/Notification/Client/HTTPClientAdapterInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77
interface HTTPClientAdapterInterface
88
{
9-
public function post(string $url, array $params): ResponseAdapterInterface;
9+
public function post(string $url, array $params): HTTPResponseInterface;
1010
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
4+
namespace App\Notification\Client;
5+
6+
7+
use Psr\Http\Message\ResponseInterface;
8+
9+
interface HTTPResponseInterface
10+
{
11+
public function __construct(ResponseInterface $clientResponse);
12+
13+
public function getResponse(): array;
14+
}

app/Notification/Client/ResponseAdapterInterface.php

-10
This file was deleted.

app/Notification/Slack/SlackNotification.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use App\Notification\AppNotificationInterface;
88
use App\Notification\Client\HTTPClientAdapterInterface;
9-
use App\Notification\Client\ResponseAdapterInterface;
9+
use App\Notification\Client\HTTPResponseInterface;
1010

1111
final class SlackNotification implements AppNotificationInterface
1212
{
@@ -19,7 +19,7 @@ public function __construct(HTTPClientAdapterInterface $client, string $message,
1919
$this->client = $client;
2020
}
2121

22-
public function notify(): ResponseAdapterInterface
22+
public function notify(): HTTPResponseInterface
2323
{
2424
return $this->client->post(
2525
getenv('SLACK_API_WEBHOOK'),

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@
4141
"phpunit/phpunit": "8.5.*"
4242
},
4343
"scripts": {
44-
"tests": "./vendor/bin/phpunit tests --color=always --stop-on-failure",
44+
"tests": "./vendor/bin/phpunit tests --color=always --stop-on-failure"
4545
}
4646
}

0 commit comments

Comments
 (0)