Skip to content

Commit b1af90a

Browse files
brianstoopmarcella-galambos-move
authored andcommitted
JPush: Add phpstan array shapes
1 parent 2649ab0 commit b1af90a

File tree

5 files changed

+48
-17
lines changed

5 files changed

+48
-17
lines changed

src/Lunr/Vortex/JPush/JPushBatchResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class JPushBatchResponse
3535

3636
/**
3737
* The statuses per endpoint.
38-
* @var array
38+
* @var array<string, PushNotificationStatus>
3939
*/
4040
private array $statuses;
4141

@@ -53,7 +53,7 @@ class JPushBatchResponse
5353

5454
/**
5555
* Notification endpoints.
56-
* @var array
56+
* @var string[]
5757
*/
5858
protected array $endpoints;
5959

src/Lunr/Vortex/JPush/JPushMessagePayload.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212

1313
/**
1414
* JPush Message Payload Generator.
15+
*
16+
* @phpstan-type JPushMessagePayloadElements array{
17+
* platform: string[],
18+
* audience: array<string, mixed>,
19+
* message?: array<string, mixed>,
20+
* options?: array<string, string|int|float|bool>
21+
* }
1522
*/
1623
class JPushMessagePayload extends JPushPayload
1724
{
@@ -35,7 +42,7 @@ public function __destruct()
3542
/**
3643
* Construct the payload for the push notification.
3744
*
38-
* @return array JPushPayload
45+
* @return JPushMessagePayloadElements JPushPayload
3946
*/
4047
public function get_payload(): array
4148
{

src/Lunr/Vortex/JPush/JPushNotification3rdPayload.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111

1212
/**
1313
* JPush Notification_3rd Payload Generator.
14+
*
15+
* @phpstan-type JPushNotification3rdPayloadElements array{
16+
* platform: string[],
17+
* audience: array<string, mixed>,
18+
* notification_3rd?: array<string, mixed>,
19+
* message?: array<string, mixed>,
20+
* options?: array<string, string|int|float|bool>
21+
* }
1422
*/
1523
class JPushNotification3rdPayload extends JPushPayload
1624
{
@@ -34,7 +42,7 @@ public function __destruct()
3442
/**
3543
* Construct the payload for the push notification.
3644
*
37-
* @return array JPushPayload
45+
* @return JPushNotification3rdPayloadElements JPushPayload
3846
*/
3947
public function get_payload(): array
4048
{

src/Lunr/Vortex/JPush/JPushNotificationPayload.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414

1515
/**
1616
* JPush Notification Payload Generator.
17+
*
18+
* @phpstan-type JPushNotificationPayloadElements array{
19+
* platform: string[],
20+
* audience: array<string, mixed>,
21+
* notification?: array<string, mixed>,
22+
* options?: array<string, string|int|float|bool>
23+
* }
1724
*/
1825
class JPushNotificationPayload extends JPushPayload
1926
{
@@ -39,7 +46,7 @@ public function __destruct()
3946
/**
4047
* Construct the payload for the push notification.
4148
*
42-
* @return array JPushPayload
49+
* @return JPushNotificationPayloadElements JPushPayload
4350
*/
4451
public function get_payload(): array
4552
{

src/Lunr/Vortex/JPush/JPushPayload.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,28 @@
1414

1515
/**
1616
* JPush Payload Generator.
17+
*
18+
* @phpstan-type JPushPayloadElements array{
19+
* platform: string[],
20+
* audience: array<string, mixed>,
21+
* notification?: array<string, mixed>,
22+
* notification_3rd?: array<string, mixed>,
23+
* message?: array<string, mixed>,
24+
* options?: array<string, string|int|float|bool>
25+
* }
1726
*/
1827
abstract class JPushPayload implements PushNotificationPayloadInterface
1928
{
2029

2130
/**
2231
* Array of Push Notification elements.
23-
* @var array
32+
* @var JPushPayloadElements
2433
*/
2534
protected array $elements;
2635

2736
/**
2837
* Supported push platforms
29-
* @var array
38+
* @var string[]
3039
*/
3140
private const PLATFORMS = [ 'ios', 'android' ];
3241

@@ -35,13 +44,13 @@ abstract class JPushPayload implements PushNotificationPayloadInterface
3544
*/
3645
public function __construct()
3746
{
38-
$this->elements = [];
39-
40-
$this->elements['platform'] = self::PLATFORMS;
41-
$this->elements['audience'] = [];
42-
$this->elements['notification'] = [];
43-
$this->elements['notification_3rd'] = [];
44-
$this->elements['message'] = [];
47+
$this->elements = [
48+
'platform' => self::PLATFORMS,
49+
'audience' => [],
50+
'notification' => [],
51+
'notification_3rd' => [],
52+
'message' => [],
53+
];
4554
}
4655

4756
/**
@@ -65,7 +74,7 @@ public function is_broadcast(): bool
6574
/**
6675
* Construct the payload for the push notification.
6776
*
68-
* @return array JPushPayload
77+
* @return JPushPayloadElements JPushPayload
6978
*/
7079
abstract public function get_payload(): array;
7180

@@ -116,7 +125,7 @@ public function set_title(string $message): static
116125
*
117126
* The fields of data represent the key-value pairs of the message's payload data.
118127
*
119-
* @param array $data The actual notification information
128+
* @param array<string,mixed> $data The actual notification information
120129
*
121130
* @return $this Self Reference
122131
*/
@@ -182,7 +191,7 @@ public function set_collapse_key(string $key): static
182191
*
183192
* @return $this Self Reference
184193
*/
185-
public function set_options(string $key, $value): static
194+
public function set_options(string $key, string|int|float|bool $value): static
186195
{
187196
if (!isset($this->elements['options']))
188197
{

0 commit comments

Comments
 (0)