@@ -89,7 +89,7 @@ public function attributes(array $attributes): string
8989 }
9090 }
9191
92- return count ($ html ) > 0 ? ' ' .implode (' ' , $ html ) : '' ;
92+ return ! empty ($ html ) ? ' ' .implode (' ' , $ html ) : '' ;
9393 }
9494
9595 /**
@@ -119,7 +119,7 @@ protected function attributeElement(string $key, mixed $value): mixed
119119 return 'class=" ' .implode (' ' , $ value ).'" ' ;
120120 }
121121
122- if (! is_null ($ value )) {
122+ if (is_bool ( $ value ) || is_float ( $ value ) || is_int ( $ value ) || is_resource ( $ value ) || is_string ($ value )) {
123123 return $ key .'=" ' .e (strval ($ value ), false ).'" ' ;
124124 }
125125
@@ -226,7 +226,9 @@ public function link(
226226 $ title = $ this ->entities ($ title );
227227 }
228228
229- return $ this ->toHtmlString ('<a href=" ' .$ this ->entities ($ url ).'" ' .$ this ->attributes ($ attributes ).'> ' .$ title .'</a> ' );
229+ return $ this ->toHtmlString (
230+ '<a href=" ' .$ this ->entities ($ url ).'" ' .$ this ->attributes ($ attributes ).'> ' .$ title .'</a> '
231+ );
230232 }
231233
232234 /**
@@ -430,7 +432,7 @@ protected function listing(string $type, array $list, array $attributes = []): H
430432 {
431433 $ html = '' ;
432434
433- if (count ($ list ) === 0 ) {
435+ if (empty ($ list )) {
434436 return $ html ;
435437 }
436438
@@ -459,8 +461,18 @@ protected function listingElement(mixed $key, string $type, mixed $value): HtmlS
459461 if (is_array ($ value )) {
460462 return $ this ->nestedListing ($ key , $ type , $ value );
461463 } else {
462- return '<li> ' .e (strval ($ value ), false ).'</li> ' ;
464+ if (is_bool ($ value )
465+ || is_float ($ value )
466+ || is_int ($ value )
467+ || is_resource ($ value )
468+ || is_string ($ value )
469+ || is_null ($ value )
470+ ) {
471+ return '<li> ' .e (strval ($ value ), false ).'</li> ' ;
472+ }
463473 }
474+
475+ return '<li> ' .$ value .'</li> ' ;
464476 }
465477
466478 /**
@@ -510,7 +522,7 @@ public function dl(array $list, array $attributes = []): HtmlString
510522
511523 $ html .= "<dt> $ key</dt> " ;
512524
513- foreach ($ value as $ v_key => $ v_value ) {
525+ foreach ($ value as $ v_value ) {
514526 $ html .= "<dd> $ v_value</dd> " ;
515527 }
516528 }
@@ -549,6 +561,18 @@ public function tag(string $tag, mixed $content, array $attributes = []): HtmlSt
549561 {
550562 $ content = is_array ($ content ) ? implode ('' , $ content ) : $ content ;
551563
552- return $ this ->toHtmlString ('< ' .$ tag .$ this ->attributes ($ attributes ).'> ' .$ this ->toHtmlString (strval ($ content )).'</ ' .$ tag .'> ' );
564+ if (is_bool ($ content )
565+ || is_float ($ content )
566+ || is_int ($ content )
567+ || is_resource ($ content )
568+ || is_string ($ content )
569+ || is_null ($ content )
570+ ) {
571+ return $ this ->toHtmlString (
572+ '< ' .$ tag .$ this ->attributes ($ attributes ).'> ' .$ this ->toHtmlString (strval ($ content )).'</ ' .$ tag .'> '
573+ );
574+ }
575+
576+ return $ this ->toHtmlString ('< ' .$ tag .$ this ->attributes ($ attributes ).'> ' .$ content .'</ ' .$ tag .'> ' );
553577 }
554578}
0 commit comments