These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace NotificationChannels\Apn; |
||
4 | |||
5 | class ApnMessage |
||
6 | { |
||
7 | /** |
||
8 | * The title of the notification. |
||
9 | * |
||
10 | * @var string |
||
11 | */ |
||
12 | public $title; |
||
13 | |||
14 | /** |
||
15 | * The body of the notification. |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | public $body; |
||
20 | |||
21 | /** |
||
22 | * The badge of the notification. |
||
23 | * |
||
24 | * @var int |
||
25 | */ |
||
26 | public $badge; |
||
27 | |||
28 | /** |
||
29 | * The sound for the notification. |
||
30 | * |
||
31 | * @var string|null |
||
32 | */ |
||
33 | public $sound; |
||
34 | |||
35 | /** |
||
36 | * Additional data of the notification. |
||
37 | * |
||
38 | * @var array |
||
39 | */ |
||
40 | public $custom = []; |
||
41 | |||
42 | /** |
||
43 | * @param string|null $title |
||
44 | * @param string|null $body |
||
45 | * @param array $custom |
||
46 | * @param null|int $badge |
||
47 | * |
||
48 | * @return static |
||
49 | */ |
||
50 | public static function create($title = null, $body = null, $custom = [], $badge = null) |
||
51 | { |
||
52 | return new static($title, $body, $custom, $badge); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param string|null $title |
||
57 | * @param string|null $body |
||
58 | * @param array $custom |
||
59 | * @param null|int $badge |
||
60 | * |
||
61 | * @return static |
||
0 ignored issues
–
show
|
|||
62 | */ |
||
63 | 1 | public function __construct($title = null, $body = null, $custom = [], $badge = null) |
|
64 | { |
||
65 | 1 | $this->title = $title; |
|
66 | 1 | $this->body = $body; |
|
67 | 1 | $this->custom = $custom; |
|
68 | 1 | $this->badge = $badge; |
|
69 | 1 | } |
|
70 | |||
71 | /** |
||
72 | * Set the alert title of the notification. |
||
73 | * |
||
74 | * @param string $title |
||
75 | * |
||
76 | * @return $this |
||
77 | */ |
||
78 | public function title($title) |
||
79 | { |
||
80 | $this->title = $title; |
||
81 | |||
82 | return $this; |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * Set the alert message of the notification. |
||
87 | * |
||
88 | * @param string $body |
||
89 | * |
||
90 | * @return $this |
||
91 | */ |
||
92 | public function body($body) |
||
93 | { |
||
94 | $this->body = $body; |
||
95 | |||
96 | return $this; |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * Set the badge of the notification. |
||
101 | * |
||
102 | * @param int $badge |
||
103 | * |
||
104 | * @return $this |
||
105 | */ |
||
106 | public function badge($badge) |
||
107 | { |
||
108 | $this->badge = $badge; |
||
109 | |||
110 | return $this; |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * Set the sound for the notification. |
||
115 | * |
||
116 | * @param string|null $sound |
||
117 | * |
||
118 | * @return $this |
||
119 | */ |
||
120 | public function sound($sound) |
||
121 | { |
||
122 | $this->sound = $sound; |
||
123 | |||
124 | return $this; |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * Add custom data to the notification. |
||
129 | * |
||
130 | * @param string $key |
||
131 | * @param mixed $value |
||
132 | * |
||
133 | * @return $this |
||
134 | */ |
||
135 | public function custom($key, $value) |
||
136 | { |
||
137 | $this->custom[$key] = $value; |
||
138 | |||
139 | return $this; |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * Override the data of the notification. |
||
144 | * |
||
145 | * @param array $custom |
||
146 | * |
||
147 | * @return $this |
||
148 | */ |
||
149 | public function setCustom($custom) |
||
150 | { |
||
151 | $this->custom = $custom; |
||
152 | |||
153 | return $this; |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * Add an action to the notification. |
||
158 | * |
||
159 | * @param string $action |
||
160 | * @param mixed $params |
||
161 | * |
||
162 | * @return $this |
||
163 | */ |
||
164 | public function action($action, $params = null) |
||
165 | { |
||
166 | return $this->custom('action', [ |
||
167 | 'action' => $action, |
||
168 | 'params' => $params, |
||
169 | ]); |
||
170 | } |
||
171 | } |
||
172 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.