Skip to content

Commit 6e19ef3

Browse files
committed
initial code review
1 parent 87dd00e commit 6e19ef3

File tree

6 files changed

+35
-28
lines changed

6 files changed

+35
-28
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ class GameChallengeNotification extends Notification
125125
126126
public function toDiscord($notifiable)
127127
{
128-
return (new DiscordMessage)
129-
->body("You have been challenged to a game of *{$this->game->name}* by **{$this->channelger->name}**!");
128+
return DiscordMessage::create("You have been challenged to a game of *{$this->game->name}* by **{$this->channelger->name}**!");
130129
}
131130
}
132131
```

src/Commands/SetupCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function handle()
4141

4242
$gateway = Arr::get(json_decode($response->getBody(), true), 'url', $gateway);
4343
} catch (\Excetion $e) {
44-
$this->warn("Could not get a WebSocket gateway address, defaulting to '$gateway'.");
44+
$this->warn("Could not get a WebSocket gateway address, defaulting to {$gateway}.");
4545
}
4646

4747
$this->warn("Connecting to '$gateway'...");

src/Discord.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,21 @@
22

33
namespace NotificationChannels\Discord;
44

5+
use Exception;
56
use Illuminate\Support\Arr;
67
use GuzzleHttp\Client as HttpClient;
78
use GuzzleHttp\Exception\RequestException;
89
use NotificationChannels\Discord\Exceptions\CouldNotSendNotification;
910

1011
class Discord
1112
{
12-
/**
13-
* @var string
14-
*/
13+
/** @var string */
1514
protected $baseUrl = 'https://discordapp.com/api';
1615

17-
/**
18-
* @var \GuzzleHttp\Client
19-
*/
20-
protected $http;
16+
/** @var \GuzzleHttp\Client */
17+
protected $httpClient;
2118

22-
/**
23-
* @var string
24-
*/
19+
/** @var string */
2520
protected $token;
2621

2722
/**
@@ -30,13 +25,14 @@ class Discord
3025
*/
3126
public function __construct(HttpClient $http, $token)
3227
{
33-
$this->http = $http;
28+
$this->httpClient = $http;
3429
$this->token = $token;
3530
}
3631

3732
/**
3833
* @param string $channel
3934
* @param array $data
35+
*
4036
* @return \Psr\Http\Message\ResponseInterface
4137
*/
4238
public function send($channel, array $data)
@@ -46,6 +42,7 @@ public function send($channel, array $data)
4642

4743
/**
4844
* @param mixed $user
45+
*
4946
* @return string
5047
*/
5148
public function getPrivateChannel($user)
@@ -54,26 +51,29 @@ public function getPrivateChannel($user)
5451
}
5552

5653
/**
57-
* @param string $endpoint
58-
* @param array $data
54+
* @param $verb
55+
* @param string $endpoint
56+
* @param array $data
57+
*
5958
* @return array
59+
*
6060
* @throws \NotificationChannels\Discord\Exceptions\CouldNotSendNotification
6161
*/
6262
protected function request($verb, $endpoint, array $data)
6363
{
6464
$url = rtrim($this->baseUrl, '/').'/'.ltrim($endpoint, '/');
6565

6666
try {
67-
$response = $this->http->request($verb, $url, [
67+
$response = $this->httpClient->request($verb, $url, [
6868
'headers' => [
6969
'Authorization' => 'Bot '.$this->token,
7070
],
7171
'json' => $data,
7272
]);
73-
} catch (RequestException $e) {
74-
throw CouldNotSendNotification::serviceRespondedWithAnHttpError($e->getResponse());
75-
} catch (\Exception $e) {
76-
throw CouldNotSendNotification::serviceCommunicationError($e);
73+
} catch (RequestException $exception) {
74+
throw CouldNotSendNotification::serviceRespondedWithAnHttpError($exception->getResponse());
75+
} catch (Exception $exception) {
76+
throw CouldNotSendNotification::serviceCommunicationError($exception);
7777
}
7878

7979
$body = json_decode($response->getBody(), true);

src/DiscordChannel.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
class DiscordChannel
1111
{
12-
/**
13-
* @var \NotificationChannels\Discord\Discord;
14-
*/
12+
/** @var \NotificationChannels\Discord\Discord */
1513
protected $discord;
1614

1715
/**
@@ -27,6 +25,7 @@ public function __construct(Discord $discord)
2725
*
2826
* @param mixed $notifiable
2927
* @param \Illuminate\Notifications\Notification $notification
28+
*
3029
* @throws \NotificationChannels\Discord\Exceptions\CouldNotSendNotification
3130
*/
3231
public function send($notifiable, Notification $notification)

src/DiscordMessage.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace NotificationChannels\Discord;
44

5-
use Illuminate\Support\Arr;
65

76
class DiscordMessage
87
{
@@ -13,6 +12,16 @@ class DiscordMessage
1312
*/
1413
public $body;
1514

15+
/**
16+
* @param string $body
17+
*
18+
* @return static
19+
*/
20+
public static function create($body = '')
21+
{
22+
return new static($body);
23+
}
24+
1625
/**
1726
* @param string $body
1827
*/

src/Exceptions/CouldNotSendNotification.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ public static function serviceRespondedWithAnApiError($response)
3333
}
3434

3535
/**
36-
* @param \Exception $e
36+
* @param \Exception $exception
3737
* @return static
3838
*/
39-
public static function serviceCommunicationError(Exception $e)
39+
public static function serviceCommunicationError(Exception $exception)
4040
{
41-
return new static("Communication with Discord failed: {$e->getCode()}: {$e->getMessage()}");
41+
return new static("Communication with Discord failed: {$exception->getCode()}: {$exception->getMessage()}");
4242
}
4343
}

0 commit comments

Comments
 (0)