Skip to content

Commit ab8e311

Browse files
committed
refactor: added strict types tests
1 parent 268e96e commit ab8e311

File tree

8 files changed

+27
-21
lines changed

8 files changed

+27
-21
lines changed
Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace NotificationChannels\Pushbullet\Exceptions;
46

5-
use GuzzleHttp\Exception\ClientException;
7+
use Psr\Http\Message\ResponseInterface;
68
use RuntimeException;
79

810
class CouldNotSendNotification extends RuntimeException
911
{
10-
public static function pushbulletRespondedWithAnError(ClientException $exception)
12+
public static function pushbulletRespondedWithAnError(ResponseInterface $response): self
1113
{
12-
$code = $exception->getResponse()->getStatusCode();
13-
14-
$message = $exception->getResponse()->getBody();
14+
$code = $response->getStatusCode();
1515

16-
return new static("Pushbullet responded with an error `{$code} - {$message}`");
17-
}
16+
$message = $response->getBody();
1817

19-
public static function providedEmailIsInvalid($email)
20-
{
21-
return new static("Provided email `{$email}` of `notifiable` is not valid");
18+
return new self("Pushbullet responded with error: `{$code} - {$message}`.");
2219
}
2320

24-
public static function couldNotSendNotificationWithoutRecipient()
21+
public static function providedEmailIsInvalid(string $email): self
2522
{
26-
return new static('Neither device id nor email of recipient was not specified');
23+
return new self("Provided email `{$email}` of `notifiable` is not valid.");
2724
}
2825

29-
public static function couldNotCommunicateWithPushbullet()
26+
public static function couldNotCommunicateWithPushbullet(): self
3027
{
31-
return new static("Couldn't connect to Pushbullet API.");
28+
return new self('Could not connect to Pushbullet API.');
3229
}
3330
}

src/Pushbullet.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<?php
22

3-
declare(strict_types=1);
3+
declare(strict_types=1);
44

55
namespace NotificationChannels\Pushbullet;
66

77
use Exception;
88
use GuzzleHttp\Client as HttpClient;
99
use GuzzleHttp\Exception\ClientException;
1010
use NotificationChannels\Pushbullet\Exceptions\CouldNotSendNotification;
11+
use Psr\Http\Message\ResponseInterface;
1112

1213
class Pushbullet
1314
{
@@ -23,7 +24,7 @@ class Pushbullet
2324
* @param string $token
2425
* @param \GuzzleHttp\Client $httpClient
2526
*/
26-
public function __construct($token, HttpClient $httpClient)
27+
public function __construct(string $token, HttpClient $httpClient)
2728
{
2829
$this->token = $token;
2930
$this->httpClient = $httpClient;
@@ -55,9 +56,10 @@ private function getHeaders(): array
5556
* Send request to Pushbullet API.
5657
*
5758
* @param array $params
59+
*
5860
* @return \Psr\Http\Message\ResponseInterface
5961
*/
60-
public function send($params)
62+
public function send($params): ResponseInterface
6163
{
6264
$url = $this->getPushbulletUrl();
6365

@@ -67,7 +69,7 @@ public function send($params)
6769
'headers' => $this->getHeaders(),
6870
]);
6971
} catch (ClientException $exception) {
70-
throw CouldNotSendNotification::pushbulletRespondedWithAnError($exception);
72+
throw CouldNotSendNotification::pushbulletRespondedWithAnError($exception->getResponse());
7173
} catch (Exception $exception) {
7274
throw CouldNotSendNotification::couldNotCommunicateWithPushbullet();
7375
}

src/PushbulletChannel.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class PushbulletChannel
1515
private $pushbullet;
1616

1717
/**
18-
* Create pushbullet notification channel.
1918
* @param \NotificationChannels\Pushbullet\Pushbullet $pushbullet
2019
*/
2120
public function __construct(Pushbullet $pushbullet)

src/PushbulletServiceProvider.php

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

1010
class PushbulletServiceProvider extends ServiceProvider
1111
{
12-
public function boot()
12+
public function boot(): void
1313
{
1414
$this->app->when(PushbulletChannel::class)
1515
->needs(Pushbullet::class)
16-
->give(function () {
16+
->give(static function (): Pushbullet {
1717
$config = config('services.pushbullet');
1818

1919
return new Pushbullet($config['access_token'], new HttpClient());

src/Targets/Channel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace NotificationChannels\Pushbullet\Targets;
46

57
class Channel implements Targetable

src/Targets/Device.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace NotificationChannels\Pushbullet\Targets;
46

57
class Device implements Targetable

src/Targets/Email.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace NotificationChannels\Pushbullet\Targets;
46

57
use NotificationChannels\Pushbullet\Exceptions\CouldNotSendNotification;

src/Targets/Targetable.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace NotificationChannels\Pushbullet\Targets;
46

57
interface Targetable

0 commit comments

Comments
 (0)