Skip to content

Commit 5648987

Browse files
committed
code review
1 parent 5fc8b5b commit 5648987

File tree

10 files changed

+63
-44
lines changed

10 files changed

+63
-44
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Pushbullet notification channel for Laravel 5.3
22

3+
[![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-notification-channels/pushbullet.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/pushbullet)
4+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
5+
[![Build Status](https://img.shields.io/travis/laravel-notification-channels/pushbullet/master.svg?style=flat-square)](https://travis-ci.org/laravel-notification-channels/pushbullet)
6+
[![StyleCI](https://styleci.io/repos/xxx/shield)](https://styleci.io/repos/xxx)
7+
[![SensioLabsInsight](https://img.shields.io/sensiolabs/i/xxx.svg?style=flat-square)](https://insight.sensiolabs.com/projects/xxx)
8+
[![Quality Score](https://img.shields.io/scrutinizer/g/laravel-notification-channels/pushbullet.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/pushbullet)
9+
[![Total Downloads](https://img.shields.io/packagist/dt/laravel-notification-channels/pushbullet.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/pushbullet)
10+
311
This package makes it easy to send notifications using [Pushbullet](http://pushbullet.com) with Laravel 5.3.
412

513
## Contents
@@ -98,10 +106,9 @@ public function toPushbullet($notifiable)
98106
{
99107
$url = url('/invoice/' . $this->invoice->id);
100108

101-
return (new PushbulletMessage)
109+
return PushbulletMessage::create('Thank you for using our application!')
102110
->link()
103111
->title('One of your invoices has been paid!')
104-
->message('Thank you for using our application!')
105112
->url($url);
106113
}
107114
```

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
],
1414
"require": {
1515
"php": ">=5.6.4",
16+
"guzzlehttp/guzzle": "^6.2",
17+
"illuminate/events": "^5.3@dev",
1618
"illuminate/notifications": "^5.3@dev",
17-
"illuminate/support": "^5.3@dev",
18-
"illuminate/events": "^5.3@dev"
19+
"illuminate/support": "^5.3@dev"
1920
},
2021
"require-dev": {
2122
"mockery/mockery": "^0.9.5",

src/Exceptions/CouldNotSendNotification.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public static function pushbulletRespondedWithAnError(ClientException $exception
1616
return new static("Pushbullet responded with an error `{$code} - {$message}`");
1717
}
1818

19-
public static function providedEmailIsInvalid()
19+
public static function providedEmailIsInvalid($email)
2020
{
21-
return new static('Provided email of `notifiable` is not valid');
21+
return new static("Provided email `{$email}` of `notifiable` is not valid");
2222
}
2323

2424
public static function couldNotSendNotificationWithoutRecipient()
@@ -28,6 +28,6 @@ public static function couldNotSendNotificationWithoutRecipient()
2828

2929
public static function couldNotCommunicateWithPushbullet()
3030
{
31-
return new static('Couldn\'t connect to Pushbullet API.');
31+
return new static("Couldn't connect to Pushbullet API.");
3232
}
3333
}

src/Pushbullet.php

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

33
namespace NotificationChannels\Pushbullet;
44

5+
use Exception;
56
use GuzzleHttp\Client as HttpClient;
67
use GuzzleHttp\Exception\ClientException;
78
use NotificationChannels\Pushbullet\Exceptions\CouldNotSendNotification;
89

910
class Pushbullet
1011
{
11-
/**
12-
* @var string
13-
*/
12+
/** @var string */
1413
protected $token;
1514

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

2118
/**
2219
* Create small Pushbullet client.
@@ -27,11 +24,12 @@ class Pushbullet
2724
public function __construct($token, HttpClient $httpClient)
2825
{
2926
$this->token = $token;
30-
$this->http = $httpClient;
27+
28+
$this->httpClient = $httpClient;
3129
}
3230

3331
/**
34-
* Get url to send to pushbullet API
32+
* Get url to send to Pushbullet API?
3533
*
3634
* @return string
3735
*/
@@ -41,7 +39,7 @@ protected function getPushbulletUrl()
4139
}
4240

4341
/**
44-
* Get headers for API callse
42+
* Get headers for API calls.
4543
*
4644
* @return array
4745
*/
@@ -53,7 +51,7 @@ protected function getHeaders()
5351
}
5452

5553
/**
56-
* Send request to Pushbullet API
54+
* Send request to Pushbullet API.
5755
*
5856
* @param array $params
5957
* @return \Psr\Http\Message\ResponseInterface
@@ -63,13 +61,13 @@ public function send($params)
6361
$url = $this->getPushbulletUrl();
6462

6563
try {
66-
return $this->http->post($url, [
64+
return $this->httpClient->post($url, [
6765
'json' => $params,
6866
'headers' => $this->getHeaders()
6967
]);
7068
} catch (ClientException $exception) {
7169
throw CouldNotSendNotification::pushbulletRespondedWithAnError($exception);
72-
} catch (\Exception $exception) {
70+
} catch (Exception $exception) {
7371
throw CouldNotSendNotification::couldNotCommunicateWithPushbullet();
7472
}
7573
}

src/PushbulletChannel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class PushbulletChannel
1313
{
1414
/**
15-
* @var \NotificationChannels\Pushbullet\Pushbullet
15+
* @var \NotificationChannels\Pushbullet\Pushbullet
1616
*/
1717
protected $pushbullet;
1818

src/PushbulletMessage.php

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ class PushbulletMessage
1717
*/
1818
public $type = 'note';
1919

20-
/**
21-
* @var \NotificationChannels\Pushbullet\Targets\Targetable
22-
*/
20+
/** @var \NotificationChannels\Pushbullet\Targets\Targetable */
2321
protected $target;
2422

2523
/**
@@ -37,14 +35,33 @@ class PushbulletMessage
3735
public $message;
3836

3937
/**
40-
* URL if notification is of link type
38+
* Url if notification is of link type
4139
*
4240
* @var string
4341
*/
4442
public $url;
4543

44+
/**
45+
* @param string $message
46+
*
47+
* @return static
48+
*/
49+
public static function create($message)
50+
{
51+
return new static($message);
52+
}
53+
54+
/**
55+
* @param string $message
56+
*/
57+
public function __construct($message)
58+
{
59+
$this->message = $message;
60+
}
61+
4662
/**
4763
* @param \NotificationChannels\Pushbullet\Targets\Targetable $targetable
64+
*
4865
* @return $this
4966
*/
5067
public function target(Targetable $targetable)
@@ -55,7 +72,7 @@ public function target(Targetable $targetable)
5572
}
5673

5774
/**
58-
* Specify that notification is of `note` type
75+
* Specify that notification is of `note` type.
5976
*
6077
* @return $this
6178
*/
@@ -67,7 +84,7 @@ public function note()
6784
}
6885

6986
/**
70-
* Specify that notification is of `link` type
87+
* Specify that notification is of `link` type.
7188
*
7289
* @return $this
7390
*/
@@ -79,9 +96,10 @@ public function link()
7996
}
8097

8198
/**
82-
* Set notification title
99+
* Set notification title.
83100
*
84101
* @param string $title
102+
*
85103
* @return $this
86104
*/
87105
public function title($title)
@@ -92,9 +110,10 @@ public function title($title)
92110
}
93111

94112
/**
95-
* Set notification message
113+
* Set notification message.
96114
*
97115
* @param string $message
116+
*
98117
* @return $this
99118
*/
100119
public function message($message)
@@ -105,9 +124,10 @@ public function message($message)
105124
}
106125

107126
/**
108-
* Set notification url (if notification is of `link` type)
127+
* Set notification url (if notification is of `link` type).
109128
*
110129
* @param string $url
130+
*
111131
* @return $this
112132
*/
113133
public function url($url)
@@ -118,7 +138,7 @@ public function url($url)
118138
}
119139

120140
/**
121-
* Get array representation of message for pushbullet client
141+
* Get array representation of message for Pushbullet client.
122142
*
123143
* @return array
124144
*/

src/PushbulletServiceProvider.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@ public function boot()
1616
$this->app->when(PushbulletChannel::class)
1717
->needs(Pushbullet::class)
1818
->give(function () {
19-
return new Pushbullet($this->app['config']['services.pushbullet.access_token'], new HttpClient);
20-
});
21-
}
19+
$config = config('services.pushbullet');
2220

23-
/**
24-
* Register the application services.
25-
*/
26-
public function register()
27-
{
21+
return new Pushbullet($config['access_token'], new HttpClient);
22+
});
2823
}
2924
}

src/Targets/Device.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace NotificationChannels\Pushbullet\Targets;
44

5-
use NotificationChannels\Pushbullet\Exceptions\CouldNotSendNotification;
6-
75
class Device implements Targetable
86
{
97
/**
@@ -24,7 +22,7 @@ public function __construct($device)
2422
}
2523

2624
/**
27-
* @inheritdoc
25+
* @return array
2826
*/
2927
public function getTarget()
3028
{

src/Targets/Email.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Email implements Targetable
2121
public function __construct($email)
2222
{
2323
if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
24-
throw CouldNotSendNotification::providedEmailIsInvalid();
24+
throw CouldNotSendNotification::providedEmailIsInvalid($email);
2525
}
2626

2727
$this->email = $email;

src/Targets/Targetable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
interface Targetable
66
{
77
/**
8-
* Get proper target object for pushbullet client
8+
* Get proper target object for Pushbullet client
99
*
1010
* @return array
1111
*/

0 commit comments

Comments
 (0)