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\HipChat; |
||
4 | |||
5 | class HipChatMessage |
||
6 | { |
||
7 | /** |
||
8 | * HipChat room. |
||
9 | * |
||
10 | * @var string |
||
11 | */ |
||
12 | public $room = ''; |
||
13 | |||
14 | /** |
||
15 | * A label to be shown in addition to the sender's name. |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | public $from = ''; |
||
20 | |||
21 | /** |
||
22 | * The format of the notification (text, html). |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | public $format = 'text'; |
||
27 | |||
28 | /** |
||
29 | * Should a message trigger a user notification in a HipChat client. |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | public $notify = false; |
||
34 | |||
35 | /** |
||
36 | * The "level" of the notification (info, success, error). |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | public $level = 'info'; |
||
41 | |||
42 | /** |
||
43 | * The color of the notification (yellow, green, red, purple, gray, random). |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | public $color = 'gray'; |
||
48 | |||
49 | /** |
||
50 | * The text content of the message. |
||
51 | * |
||
52 | * @var string |
||
53 | */ |
||
54 | public $content = ''; |
||
55 | |||
56 | /** |
||
57 | * Create a new instance of HipChatMessage. |
||
58 | * |
||
59 | * @param string $content |
||
60 | * @return static |
||
61 | */ |
||
62 | public static function create($content = '') |
||
63 | { |
||
64 | return new static($content); |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * Create a new instance of HipChatMessage. |
||
69 | * |
||
70 | * @param $content |
||
71 | */ |
||
72 | public function __construct($content = '') |
||
73 | { |
||
74 | if (! empty($content)) { |
||
75 | $this->content($content); |
||
76 | } |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * Set the HipChat room to send message to. |
||
81 | * |
||
82 | * @param $room |
||
83 | * @return $this |
||
84 | */ |
||
85 | public function room($room) |
||
86 | { |
||
87 | $this->room = $room; |
||
88 | |||
89 | return $this; |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Indicate that the notification gives general information. |
||
94 | * |
||
95 | * @return $this |
||
96 | */ |
||
97 | public function info() |
||
98 | { |
||
99 | $this->level = 'info'; |
||
100 | $this->color = 'gray'; |
||
101 | |||
102 | return $this; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * Indicate that the notification gives information about a successful operation. |
||
107 | * |
||
108 | * @return $this |
||
109 | */ |
||
110 | public function success() |
||
111 | { |
||
112 | $this->level = 'success'; |
||
113 | $this->color = 'green'; |
||
114 | |||
115 | return $this; |
||
116 | } |
||
117 | |||
118 | /** |
||
119 | * Indicate that the notification gives information about an error. |
||
120 | * |
||
121 | * @return $this |
||
122 | */ |
||
123 | public function error() |
||
124 | { |
||
125 | $this->level = 'error'; |
||
126 | $this->color = 'red'; |
||
127 | |||
128 | return $this; |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * Set the from label of the HipChat message. |
||
133 | * |
||
134 | * @param string $from |
||
135 | * @return $this |
||
136 | */ |
||
137 | public function from($from) |
||
138 | { |
||
139 | $this->from = $from; |
||
140 | |||
141 | return $this; |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * Set HTML format of the HipChat message. |
||
146 | * |
||
147 | * @return $this |
||
148 | */ |
||
149 | public function html() |
||
150 | { |
||
151 | $this->format = 'html'; |
||
152 | |||
153 | return $this; |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * Set text format of the HipChat message. |
||
158 | * |
||
159 | * @return $this |
||
160 | */ |
||
161 | public function text() |
||
162 | { |
||
163 | $this->format = 'text'; |
||
164 | |||
165 | return $this; |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * Should a message trigger a user notification in a HipChat client. |
||
170 | * |
||
171 | * @param bool $notify |
||
172 | * @return $this |
||
173 | */ |
||
174 | public function notify($notify = true) |
||
175 | { |
||
176 | $this->notify = $notify; |
||
0 ignored issues
–
show
|
|||
177 | |||
178 | return $this; |
||
179 | } |
||
180 | |||
181 | /** |
||
182 | * Set the content of the message. |
||
183 | * Allowed HTML tags: a, b, i, strong, em, br, img, pre, code, lists, tables. |
||
184 | * |
||
185 | * @param string $content |
||
186 | * @return $this |
||
187 | */ |
||
188 | public function content($content) |
||
189 | { |
||
190 | $this->content = $content; |
||
191 | |||
192 | return $this; |
||
193 | } |
||
194 | |||
195 | /** |
||
196 | * Set the color for the message. |
||
197 | * |
||
198 | * @return string |
||
199 | */ |
||
200 | public function color($color) |
||
201 | { |
||
202 | $this->color = $color; |
||
203 | |||
204 | return $this; |
||
205 | } |
||
206 | |||
207 | public function toArray() |
||
208 | { |
||
209 | return [ |
||
210 | 'from' => $this->from, |
||
211 | 'message_format' => $this->format, |
||
212 | 'color' => $this->color, |
||
213 | 'notify' => $this->notify, |
||
214 | 'message' => $this->content, |
||
215 | ]; |
||
216 | } |
||
217 | } |
||
218 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.