Skip to content

Commit 3347e87

Browse files
committed
Minor cleanup
1 parent af9d67b commit 3347e87

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

src/FcmMessage.php

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ class FcmMessage implements Message
1212
{
1313
use Macroable;
1414

15-
1615
/**
1716
* Create a new message instance.
1817
*/
@@ -29,7 +28,6 @@ public function __construct(
2928
//
3029
}
3130

32-
3331
/**
3432
* Create a new message instance.
3533
*/
@@ -38,7 +36,6 @@ public static function create(...$args): static
3836
return new static(...$args);
3937
}
4038

41-
4239
/**
4340
* Set the message name.
4441
*/
@@ -49,7 +46,9 @@ public function name(?string $name): self
4946
return $this;
5047
}
5148

52-
49+
/**
50+
* Set the message token.
51+
*/
5352
public function token(?string $token): self
5453
{
5554
$this->token = $token;
@@ -58,7 +57,7 @@ public function token(?string $token): self
5857
}
5958

6059
/**
61-
* Set the message topic.s
60+
* Set the message topic.
6261
*/
6362
public function topic(?string $topic): self
6463
{
@@ -67,14 +66,19 @@ public function topic(?string $topic): self
6766
return $this;
6867
}
6968

70-
69+
/**
70+
* Set the message condition.
71+
*/
7172
public function condition(?string $condition): self
7273
{
7374
$this->condition = $condition;
7475

7576
return $this;
7677
}
7778

79+
/**
80+
* Set the message data.
81+
*/
7882
public function data(?array $data): self
7983
{
8084
if (! empty(array_filter($data, fn($value) => ! is_string($value)))) {
@@ -86,21 +90,21 @@ public function data(?array $data): self
8690
return $this;
8791
}
8892

89-
93+
/**
94+
* Set the message custom options.
95+
*/
9096
public function custom(?array $custom = []): self
9197
{
9298
$this->custom = $custom;
9399

94100
return $this;
95101
}
96102

97-
98103
/**
99-
* Set "android" specific custom options.
104+
* Set Aandroid specific custom options.
100105
*/
101106
public function android(array $options = []): self
102107
{
103-
104108
$this->custom([
105109
...$this->custom,
106110
'android' => $options,
@@ -109,11 +113,8 @@ public function android(array $options = []): self
109113
return $this;
110114
}
111115

112-
113-
114116
/**
115-
* Set APNs-specific custom options for iOS.
116-
* Set APNs-specific custom options for iOS.
117+
* Set APNs-specific custom options.
117118
*/
118119
public function ios(array $options = []): self
119120
{
@@ -126,22 +127,29 @@ public function ios(array $options = []): self
126127
return $this;
127128
}
128129

129-
130+
/**
131+
* Set the message notification.
132+
*/
130133
public function notification(Notification $notification): self
131134
{
132135
$this->notification = $notification;
133136

134137
return $this;
135138
}
136139

140+
/**
141+
* Set the client to use for the message.
142+
*/
137143
public function usingClient(Messaging $client): self
138144
{
139145
$this->client = $client;
140146

141147
return $this;
142148
}
143149

144-
150+
/**
151+
* Get the array represenation of the message.
152+
*/
145153
public function toArray()
146154
{
147155
return array_filter([
@@ -155,7 +163,6 @@ public function toArray()
155163
]);
156164
}
157165

158-
159166
/**
160167
* @return mixed
161168
*/

tests/FcmMessageTest.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,37 +112,36 @@ public function test_it_can_set_client()
112112

113113
public function test_appends_android_options_into_custom()
114114
{
115-
$msg = FcmMessage::create()
116-
->notification(new Notification(title: 'T', body: 'B'))
117-
->android(['notification' => ['channel_id' => 'ops', 'sound' => 'default']]);
115+
$message = FcmMessage::create()
116+
->notification(new Notification(title: 'title', body: 'body'))
117+
->android(['notification' => ['channel_id' => 'channel_id']]);
118118

119-
$payload = $msg->toArray();
119+
$payload = $message->toArray();
120120

121121
$this->assertArrayHasKey('android', $payload);
122122
$this->assertArrayHasKey('notification', $payload['android']);
123-
$this->assertEquals('ops', $payload['android']['notification']['channel_id']);
124-
$this->assertEquals('default', $payload['android']['notification']['sound']);
123+
$this->assertEquals('channel_id', $payload['android']['notification']['channel_id']);
125124
}
126125

127126
public function test_appends_ios_options_into_custom()
128127
{
129-
$msg = FcmMessage::create()
130-
->ios(['payload' => ['aps' => ['sound' => 'default']]]);
128+
$message = FcmMessage::create()
129+
->ios(['payload' => ['aps' => ['sound' => 'sound']]]);
131130

132-
$payload = $msg->toArray();
131+
$payload = $message->toArray();
133132

134133
$this->assertArrayHasKey('apns', $payload);
135134
$this->assertArrayHasKey('payload', $payload['apns']);
136-
$this->assertEquals('default', $payload['apns']['payload']['aps']['sound']);
135+
$this->assertEquals('sound', $payload['apns']['payload']['aps']['sound']);
137136
}
138137

139138
public function test_preserves_existing_custom_keys_when_using_helpers()
140139
{
141-
$msg = FcmMessage::create()
140+
$message = FcmMessage::create()
142141
->custom(['meta' => ['a' => 1]])
143142
->android(['notification' => ['color' => '#000']]);
144143

145-
$payload = $msg->toArray();
144+
$payload = $message->toArray();
146145

147146
$this->assertArrayHasKey('meta', $payload);
148147
$this->assertEquals(1, $payload['meta']['a']);

0 commit comments

Comments
 (0)