2
2
3
3
namespace NotificationChannels \HipChat ;
4
4
5
+ use Closure ;
6
+ use InvalidArgumentException ;
7
+
5
8
class Card
6
9
{
7
10
/**
@@ -134,11 +137,8 @@ class Card
134
137
*/
135
138
public function __construct ($ title = '' , $ id = '' )
136
139
{
137
- if (! empty ($ title )) {
138
- $ this ->title = $ title ;
139
- }
140
-
141
- $ this ->id = $ id ?: str_random ();
140
+ $ this ->title ($ title );
141
+ $ this ->id (str_empty ($ id ) ? str_random () : $ id );
142
142
}
143
143
144
144
/**
@@ -215,7 +215,7 @@ public function text($content = '')
215
215
{
216
216
$ this ->format = 'text ' ;
217
217
218
- if (! empty ($ content )) {
218
+ if (! str_empty ($ content )) {
219
219
$ this ->content ($ content );
220
220
}
221
221
@@ -232,7 +232,7 @@ public function html($content = '')
232
232
{
233
233
$ this ->format = 'html ' ;
234
234
235
- if (! empty ($ content )) {
235
+ if (! str_empty ($ content )) {
236
236
$ this ->content ($ content );
237
237
}
238
238
@@ -278,15 +278,15 @@ public function thumbnail($icon, $icon2 = null, $width = null, $height = null)
278
278
{
279
279
$ this ->thumbnail = trim ($ icon );
280
280
281
- if (! empty ($ icon2 )) {
281
+ if (! str_empty ($ icon2 )) {
282
282
$ this ->thumbnail2 = trim ($ icon2 );
283
283
}
284
284
285
- if (! empty ($ width )) {
285
+ if (! is_null ($ width )) {
286
286
$ this ->thumbnailWidth = $ width ;
287
287
}
288
288
289
- if (! empty ($ height )) {
289
+ if (! is_null ($ height )) {
290
290
$ this ->thumbnailHeight = $ height ;
291
291
}
292
292
@@ -305,11 +305,11 @@ public function activity($html, $icon = null, $icon2 = null)
305
305
{
306
306
$ this ->activity = trim ($ html );
307
307
308
- if (! empty ($ icon )) {
308
+ if (! str_empty ($ icon )) {
309
309
$ this ->activityIcon = trim ($ icon );
310
310
}
311
311
312
- if (! empty ($ icon2 )) {
312
+ if (! str_empty ($ icon2 )) {
313
313
$ this ->activityIcon2 = trim ($ icon2 );
314
314
}
315
315
@@ -327,7 +327,7 @@ public function icon($icon, $icon2 = null)
327
327
{
328
328
$ this ->icon = trim ($ icon );
329
329
330
- if (! empty ($ icon2 )) {
330
+ if (! str_empty ($ icon2 )) {
331
331
$ this ->icon2 = trim ($ icon2 );
332
332
}
333
333
@@ -337,7 +337,7 @@ public function icon($icon, $icon2 = null)
337
337
/**
338
338
* Adds a CardAttribute to the card.
339
339
*
340
- * @param CardAttribute|\ Closure $attribute
340
+ * @param CardAttribute|Closure $attribute
341
341
* @return $this
342
342
*/
343
343
public function addAttribute ($ attribute )
@@ -348,14 +348,16 @@ public function addAttribute($attribute)
348
348
return $ this ;
349
349
}
350
350
351
- if ($ attribute instanceof \ Closure) {
351
+ if ($ attribute instanceof Closure) {
352
352
$ attribute ($ new = new CardAttribute ());
353
353
$ this ->attributes [] = $ new ;
354
354
355
355
return $ this ;
356
356
}
357
357
358
- throw new \InvalidArgumentException ('Invalid attribute type. Expected ' .CardAttribute::class.' or ' .\Closure::class.'. ' );
358
+ throw new InvalidArgumentException (
359
+ 'Invalid attribute type. Expected ' .CardAttribute::class.' or ' . Closure::class.'. '
360
+ );
359
361
}
360
362
361
363
/**
@@ -365,42 +367,42 @@ public function addAttribute($attribute)
365
367
*/
366
368
public function toArray ()
367
369
{
368
- $ card = array_filter ([
370
+ $ card = str_array_filter ([
369
371
'id ' => $ this ->id ,
370
372
'style ' => $ this ->style ,
371
373
'format ' => $ this ->cardFormat ,
372
374
'title ' => $ this ->title ,
373
375
'url ' => $ this ->url ,
374
376
]);
375
377
376
- if (! empty ($ this ->content )) {
378
+ if (! str_empty ($ this ->content )) {
377
379
$ card ['description ' ] = [
378
380
'value ' => $ this ->content ,
379
381
'format ' => $ this ->format ,
380
382
];
381
383
}
382
384
383
- if (! empty ($ this ->thumbnail )) {
384
- $ card ['thumbnail ' ] = array_filter ([
385
+ if (! str_empty ($ this ->thumbnail )) {
386
+ $ card ['thumbnail ' ] = str_array_filter ([
385
387
'url ' => $ this ->thumbnail ,
386
388
'url@2x ' => $ this ->thumbnail2 ,
387
389
'width ' => $ this ->thumbnailWidth ,
388
390
'height ' => $ this ->thumbnailHeight ,
389
391
]);
390
392
}
391
393
392
- if (! empty ($ this ->activity )) {
393
- $ card ['activity ' ] = array_filter ([
394
+ if (! str_empty ($ this ->activity )) {
395
+ $ card ['activity ' ] = str_array_filter ([
394
396
'html ' => $ this ->activity ,
395
- 'icon ' => array_filter ([
397
+ 'icon ' => str_array_filter ([
396
398
'url ' => $ this ->activityIcon ,
397
399
'url@2x ' => $ this ->activityIcon2 ,
398
400
]),
399
401
]);
400
402
}
401
403
402
- if (! empty ($ this ->icon )) {
403
- $ card ['icon ' ] = array_filter ([
404
+ if (! str_empty ($ this ->icon )) {
405
+ $ card ['icon ' ] = str_array_filter ([
404
406
'url ' => $ this ->icon ,
405
407
'url@2x ' => $ this ->icon2 ,
406
408
]);
0 commit comments