1 | <?php |
||
7 | class OneSignalPayloadFactory |
||
8 | { |
||
9 | /** |
||
10 | * Make a one signal notification payload. |
||
11 | * |
||
12 | * @param mixed $notifiable |
||
13 | * @param \Illuminate\Notifications\Notification $notification |
||
14 | * @param mixed $targeting |
||
15 | * |
||
16 | * @return array |
||
17 | */ |
||
18 | 9 | public static function make($notifiable, Notification $notification, $targeting): array |
|
19 | { |
||
20 | 9 | $payload = $notification->toOneSignal($notifiable)->toArray(); |
|
|
|||
21 | |||
22 | 9 | if (static::isTargetingEmail($targeting)) { |
|
23 | 1 | $payload['filters'] = collect([['field' => 'email', 'value' => $targeting['email']]]); |
|
24 | 8 | } elseif (static::isTargetingTags($targeting)) { |
|
25 | 2 | $array = $targeting['tags']; |
|
26 | 2 | $res = count($array) == count($array, COUNT_RECURSIVE); |
|
27 | 2 | if ($res) { |
|
28 | 1 | $payload['tags'] = collect([$targeting['tags']]); |
|
29 | } else { |
||
30 | 2 | $payload['tags'] = collect($targeting['tags']); |
|
31 | } |
||
32 | 6 | } elseif (static::isTargetingIncludedSegments($targeting)) { |
|
33 | 1 | $payload['included_segments'] = collect($targeting['included_segments']); |
|
34 | 5 | } elseif (static::isTargetingExcludedSegments($targeting)) { |
|
35 | 1 | $payload['excluded_segments'] = collect($targeting['excluded_segments']); |
|
36 | 4 | } elseif (static::isTargetingExternalUserIds($targeting)) { |
|
37 | 1 | $payload['include_external_user_ids'] = collect($targeting['include_external_user_ids']); |
|
38 | } else { |
||
39 | 3 | $payload['include_player_ids'] = collect($targeting); |
|
40 | } |
||
41 | |||
42 | 9 | return $payload; |
|
43 | } |
||
44 | |||
45 | /** |
||
46 | * @param mixed $targeting |
||
47 | * |
||
48 | * @return bool |
||
49 | */ |
||
50 | 6 | protected static function isTargetingIncludedSegments($targeting) |
|
54 | |||
55 | /** |
||
56 | * @param mixed $targeting |
||
57 | * |
||
58 | * @return bool |
||
59 | */ |
||
60 | 4 | protected static function isTargetingExternalUserIds($targeting) |
|
64 | |||
65 | /** |
||
66 | * @param mixed $targeting |
||
67 | * |
||
68 | * @return bool |
||
69 | */ |
||
70 | 5 | protected static function isTargetingExcludedSegments($targeting) |
|
74 | |||
75 | /** |
||
76 | * @param mixed $targeting |
||
77 | * |
||
78 | * @return bool |
||
79 | */ |
||
80 | 9 | protected static function isTargetingEmail($targeting) |
|
84 | |||
85 | /** |
||
86 | * @param mixed $targeting |
||
87 | * |
||
88 | * @return bool |
||
89 | */ |
||
90 | 8 | protected static function isTargetingTags($targeting) |
|
94 | } |
||
95 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.