Skip to content

Commit dff96e5

Browse files
committed
fix: Made code stricter
1 parent 318e534 commit dff96e5

File tree

5 files changed

+47
-35
lines changed

5 files changed

+47
-35
lines changed

src/Pushbullet.php

Lines changed: 6 additions & 5 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;
46

57
use Exception;
@@ -10,10 +12,10 @@
1012
class Pushbullet
1113
{
1214
/** @var string */
13-
protected $token;
15+
private $token;
1416

1517
/** @var \GuzzleHttp\Client */
16-
protected $httpClient;
18+
private $httpClient;
1719

1820
/**
1921
* Create small Pushbullet client.
@@ -24,7 +26,6 @@ class Pushbullet
2426
public function __construct($token, HttpClient $httpClient)
2527
{
2628
$this->token = $token;
27-
2829
$this->httpClient = $httpClient;
2930
}
3031

@@ -33,7 +34,7 @@ public function __construct($token, HttpClient $httpClient)
3334
*
3435
* @return string
3536
*/
36-
protected function getPushbulletUrl()
37+
private function getPushbulletUrl(): string
3738
{
3839
return 'https://api.pushbullet.com/v2/pushes';
3940
}
@@ -43,7 +44,7 @@ protected function getPushbulletUrl()
4344
*
4445
* @return array
4546
*/
46-
protected function getHeaders()
47+
private function getHeaders(): array
4748
{
4849
return [
4950
'Access-Token' => $this->token,

src/PushbulletChannel.php

Lines changed: 8 additions & 7 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;
46

57
use Illuminate\Notifications\Notification;
@@ -9,10 +11,8 @@
911

1012
class PushbulletChannel
1113
{
12-
/**
13-
* @var \NotificationChannels\Pushbullet\Pushbullet
14-
*/
15-
protected $pushbullet;
14+
/** @var \NotificationChannels\Pushbullet\Pushbullet */
15+
private $pushbullet;
1616

1717
/**
1818
* Create pushbullet notification channel.
@@ -31,7 +31,7 @@ public function __construct(Pushbullet $pushbullet)
3131
*
3232
* @throws \NotificationChannels\Pushbullet\Exceptions\CouldNotSendNotification
3333
*/
34-
public function send($notifiable, Notification $notification)
34+
public function send($notifiable, Notification $notification): void
3535
{
3636
if (! $target = $this->getTarget($notifiable)) {
3737
return;
@@ -45,12 +45,13 @@ public function send($notifiable, Notification $notification)
4545

4646
/**
4747
* @param $notifiable
48+
*
4849
* @return \NotificationChannels\Pushbullet\Targets\Targetable|void
4950
*/
50-
protected function getTarget($notifiable)
51+
private function getTarget($notifiable): ?Targetable
5152
{
5253
if (! $target = $notifiable->routeNotificationFor('pushbullet')) {
53-
return;
54+
return null;
5455
}
5556

5657
if ($target instanceof Targetable) {

src/PushbulletMessage.php

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

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

57
use NotificationChannels\Pushbullet\Targets\Targetable;
68

79
class PushbulletMessage
810
{
9-
const TYPE_NOTE = 'note';
10-
const TYPE_LINK = 'link';
11+
private const TYPE_NOTE = 'note';
12+
private const TYPE_LINK = 'link';
1113

1214
/**
1315
* Type of message (currently: note or link).
@@ -45,7 +47,7 @@ class PushbulletMessage
4547
*
4648
* @return static
4749
*/
48-
public static function create($message)
50+
public static function create($message): self
4951
{
5052
return new static($message);
5153
}
@@ -63,7 +65,7 @@ public function __construct($message)
6365
*
6466
* @return $this
6567
*/
66-
public function target(Targetable $targetable)
68+
public function target(Targetable $targetable): self
6769
{
6870
$this->target = $targetable;
6971

@@ -75,9 +77,9 @@ public function target(Targetable $targetable)
7577
*
7678
* @return $this
7779
*/
78-
public function note()
80+
public function note(): self
7981
{
80-
$this->type = static::TYPE_NOTE;
82+
$this->type = self::TYPE_NOTE;
8183

8284
return $this;
8385
}
@@ -87,9 +89,9 @@ public function note()
8789
*
8890
* @return $this
8991
*/
90-
public function link()
92+
public function link(): self
9193
{
92-
$this->type = static::TYPE_LINK;
94+
$this->type = self::TYPE_LINK;
9395

9496
return $this;
9597
}
@@ -101,7 +103,7 @@ public function link()
101103
*
102104
* @return $this
103105
*/
104-
public function title($title)
106+
public function title($title): self
105107
{
106108
$this->title = $title;
107109

@@ -115,7 +117,7 @@ public function title($title)
115117
*
116118
* @return $this
117119
*/
118-
public function message($message)
120+
public function message($message): self
119121
{
120122
$this->message = $message;
121123

@@ -129,7 +131,7 @@ public function message($message)
129131
*
130132
* @return $this
131133
*/
132-
public function url($url)
134+
public function url($url): self
133135
{
134136
$this->url = $url;
135137

@@ -141,7 +143,7 @@ public function url($url)
141143
*
142144
* @return array
143145
*/
144-
public function toArray()
146+
public function toArray(): array
145147
{
146148
$payload = [
147149
'type' => $this->type,
@@ -159,15 +161,15 @@ public function toArray()
159161
/**
160162
* @return bool
161163
*/
162-
private function isLink()
164+
private function isLink(): bool
163165
{
164-
return $this->type === static::TYPE_LINK;
166+
return $this->type === self::TYPE_LINK;
165167
}
166168

167169
/**
168170
* @return array
169171
*/
170-
private function getUrlParameter()
172+
private function getUrlParameter(): array
171173
{
172174
return $this->isLink() ? ['url' => $this->url] : [];
173175
}

src/PushbulletServiceProvider.php

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

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

57
use GuzzleHttp\Client as HttpClient;
68
use Illuminate\Support\ServiceProvider;
79

810
class PushbulletServiceProvider extends ServiceProvider
911
{
10-
/**
11-
* Bootstrap the application services.
12-
*/
1312
public function boot()
1413
{
15-
// Bootstrap code here.
1614
$this->app->when(PushbulletChannel::class)
1715
->needs(Pushbullet::class)
1816
->give(function () {
1917
$config = config('services.pushbullet');
2018

21-
return new Pushbullet($config['access_token'], new HttpClient);
19+
return new Pushbullet($config['access_token'], new HttpClient());
2220
});
2321
}
2422
}

tests/PushbulletMessageTest.php

Lines changed: 13 additions & 3 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\Test;
46

57
use NotificationChannels\Pushbullet\PushbulletMessage;
@@ -12,6 +14,14 @@
1214
*/
1315
class PushbulletMessageTest extends TestCase
1416
{
17+
/** @test */
18+
public function message_can_be_created_by_static_function()
19+
{
20+
$message = PushbulletMessage::create('Hello');
21+
22+
$this->assertEquals('Hello', $message->message);
23+
}
24+
1525
/** @test */
1626
public function message_can_be_instantiated_with_text()
1727
{
@@ -25,7 +35,7 @@ public function new_message_is_of_note_type()
2535
{
2636
$message = new PushbulletMessage('Hello');
2737

28-
$this->assertEquals(PushbulletMessage::TYPE_NOTE, $message->type);
38+
$this->assertEquals('note', $message->type);
2939
}
3040

3141
/** @test */
@@ -35,7 +45,7 @@ public function message_can_be_set_to_link_type()
3545

3646
$message->link();
3747

38-
$this->assertEquals(PushbulletMessage::TYPE_LINK, $message->type);
48+
$this->assertEquals('link', $message->type);
3949
}
4050

4151
/** @test */
@@ -47,7 +57,7 @@ public function message_can_be_set_to_note_type()
4757

4858
$message->note();
4959

50-
$this->assertEquals(PushbulletMessage::TYPE_NOTE, $message->type);
60+
$this->assertEquals('note', $message->type);
5161
}
5262

5363
/** @test */

0 commit comments

Comments
 (0)