7676 * Nearly all the methods in this class allow setting additional HTML attributes for the HTML tags they generate.
7777 * You can specify, for example, `class`, `style` or `id` for an HTML element using the `$options` parameter. See the
7878 * documentation of the {@see tag()} method for more details.
79- *
80- * @psalm-type HtmlAttributes = array<string, mixed>&array{
81- * id?: string|null,
82- * class?: string[]|string|null,
83- * style?: array<string, string>|string|null,
84- * data?: array<array-key, array|string|null>|string|null,
85- * data-ng?: array<array-key, array|string|null>|string|null,
86- * ng?: array<array-key, array|string|null>|string|null,
87- * aria?: array<array-key, array|string|null>|string|null,
88- * }
8979 */
9080final class Html
9181{
@@ -363,8 +353,6 @@ public static function closeTag(string $name): string
363353 *
364354 * @param string $content The style content.
365355 * @param array $attributes The tag attributes in terms of name-value pairs.
366- *
367- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
368356 */
369357 public static function style (string $ content = '' , array $ attributes = []): Style
370358 {
@@ -383,8 +371,6 @@ public static function style(string $content = '', array $attributes = []): Styl
383371 *
384372 * @param string $content The script content.
385373 * @param array $attributes The tag attributes in terms of name-value pairs.
386- *
387- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
388374 */
389375 public static function script (string $ content = '' , array $ attributes = []): Script
390376 {
@@ -414,8 +400,6 @@ public static function noscript($content = ''): Noscript
414400 *
415401 * @param string|Stringable $content Tag content.
416402 * @param array $attributes The tag attributes in terms of name-value pairs.
417- *
418- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
419403 */
420404 public static function title ($ content = '' , array $ attributes = []): Title
421405 {
@@ -430,8 +414,6 @@ public static function title($content = '', array $attributes = []): Title
430414 * Generates a {@see Meta} tag.
431415 *
432416 * @param array $attributes The tag attributes in terms of name-value pairs.
433- *
434- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
435417 */
436418 public static function meta (array $ attributes = []): Meta
437419 {
@@ -447,8 +429,6 @@ public static function meta(array $attributes = []): Meta
447429 *
448430 * @param string|null $url The destination of the link.
449431 * @param array $attributes The tag attributes in terms of name-value pairs.
450- *
451- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
452432 */
453433 public static function link (?string $ url = null , array $ attributes = []): Link
454434 {
@@ -467,8 +447,6 @@ public static function link(?string $url = null, array $attributes = []): Link
467447 *
468448 * @param string $url The URL of the CSS file.
469449 * @param array $attributes The tag attributes in terms of name-value pairs.
470- *
471- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
472450 */
473451 public static function cssFile (string $ url , array $ attributes = []): Link
474452 {
@@ -484,8 +462,6 @@ public static function cssFile(string $url, array $attributes = []): Link
484462 *
485463 * @param string $url The URL of the JavaScript file.
486464 * @param array $attributes The tag attributes in terms of name-value pairs.
487- *
488- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
489465 */
490466 public static function javaScriptFile (string $ url , array $ attributes = []): Script
491467 {
@@ -502,8 +478,6 @@ public static function javaScriptFile(string $url, array $attributes = []): Scri
502478 * @param string|Stringable $content The tag content.
503479 * @param array $attributes The tag attributes in terms of name-value pairs.
504480 *
505- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
506- *
507481 * @see A
508482 */
509483 public static function a ($ content = '' , ?string $ url = null , array $ attributes = []): A
@@ -526,8 +500,6 @@ public static function a($content = '', ?string $url = null, array $attributes =
526500 *
527501 * @param array $attributes The tag attributes in terms of name-value pairs.
528502 *
529- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
530- *
531503 * @see A
532504 */
533505 public static function mailto (string $ content , ?string $ mail = null , array $ attributes = []): A
@@ -607,8 +579,6 @@ public static function label($content = '', ?string $for = null): Label
607579 *
608580 * @param string $content The content enclosed within the button tag.
609581 * @param array $attributes The tag attributes in terms of name-value pairs.
610- *
611- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
612582 */
613583 public static function button (string $ content = 'Button ' , array $ attributes = []): Button
614584 {
@@ -626,8 +596,6 @@ public static function button(string $content = 'Button', array $attributes = []
626596 *
627597 * @param string $content The content enclosed within the button tag.
628598 * @param array $attributes The tag attributes in terms of name-value pairs.
629- *
630- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
631599 */
632600 public static function submitButton (string $ content = 'Submit ' , array $ attributes = []): Button
633601 {
@@ -645,8 +613,6 @@ public static function submitButton(string $content = 'Submit', array $attribute
645613 *
646614 * @param string $content The content enclosed within the button tag.
647615 * @param array $attributes The tag attributes in terms of name-value pairs.
648- *
649- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
650616 */
651617 public static function resetButton (string $ content = 'Reset ' , array $ attributes = []): Button
652618 {
@@ -719,8 +685,6 @@ public static function resetInput(?string $label = 'Reset'): Input
719685 * @param string|null $name The name attribute.
720686 * @param bool|float|int|string|Stringable|null $value The value attribute.
721687 * @param array $attributes The tag attributes in terms of name-value pairs.
722- *
723- * @psalm-param HtmlAttributes $attributes
724688 */
725689 public static function textInput (?string $ name = null , $ value = null , array $ attributes = []): Input
726690 {
@@ -736,8 +700,6 @@ public static function textInput(?string $name = null, $value = null, array $att
736700 * @param string|null $name The name attribute.
737701 * @param bool|float|int|string|Stringable|null $value The value attribute.
738702 * @param array $attributes The tag attributes in terms of name-value pairs.
739- *
740- * @psalm-param HtmlAttributes $attributes
741703 */
742704 public static function hiddenInput (?string $ name = null , $ value = null , array $ attributes = []): Input
743705 {
@@ -753,8 +715,6 @@ public static function hiddenInput(?string $name = null, $value = null, array $a
753715 * @param string|null $name The name attribute.
754716 * @param bool|float|int|string|Stringable|null $value The value attribute.
755717 * @param array $attributes The tag attributes in terms of name-value pairs.
756- *
757- * @psalm-param HtmlAttributes $attributes
758718 */
759719 public static function passwordInput (?string $ name = null , $ value = null , array $ attributes = []): Input
760720 {
@@ -774,8 +734,6 @@ public static function passwordInput(?string $name = null, $value = null, array
774734 * @param string|null $name The name attribute.
775735 * @param bool|float|int|string|Stringable|null $value The value attribute.
776736 * @param array $attributes The tag attributes in terms of name-value pairs.
777- *
778- * @psalm-param HtmlAttributes $attributes
779737 */
780738 public static function fileInput (?string $ name = null , $ value = null , array $ attributes = []): Input
781739 {
@@ -791,8 +749,6 @@ public static function fileInput(?string $name = null, $value = null, array $att
791749 * @param string|null $name The name attribute.
792750 * @param bool|float|int|string|Stringable|null $value The value attribute.
793751 * @param array $attributes The tag attributes in terms of name-value pairs.
794- *
795- * @psalm-param HtmlAttributes $attributes
796752 */
797753 public static function radio (?string $ name = null , $ value = null , array $ attributes = []): Radio
798754 {
@@ -808,8 +764,6 @@ public static function radio(?string $name = null, $value = null, array $attribu
808764 * @param string|null $name The name attribute.
809765 * @param bool|float|int|string|Stringable|null $value The value attribute.
810766 * @param array $attributes The tag attributes in terms of name-value pairs.
811- *
812- * @psalm-param HtmlAttributes $attributes
813767 */
814768 public static function checkbox (?string $ name = null , $ value = null , array $ attributes = []): Checkbox
815769 {
@@ -823,8 +777,6 @@ public static function checkbox(?string $name = null, $value = null, array $attr
823777 * @param string|null $name The input name.
824778 * @param string|null $value The input value.
825779 * @param array $attributes The tag attributes in terms of name-value pairs.
826- *
827- * @psalm-param HtmlAttributes $attributes
828780 */
829781 public static function textarea (?string $ name = null , ?string $ value = null , array $ attributes = []): Textarea
830782 {
@@ -903,8 +855,6 @@ public static function radioList(string $name): RadioList
903855 *
904856 * @param string|Stringable $content Tag content.
905857 * @param array $attributes The tag attributes in terms of name-value pairs.
906- *
907- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
908858 */
909859 public static function div ($ content = '' , array $ attributes = []): Div
910860 {
@@ -920,8 +870,6 @@ public static function div($content = '', array $attributes = []): Div
920870 *
921871 * @param string|Stringable $content Tag content.
922872 * @param array $attributes The tag attributes in terms of name-value pairs.
923- *
924- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
925873 */
926874 public static function span ($ content = '' , array $ attributes = []): Span
927875 {
@@ -937,8 +885,6 @@ public static function span($content = '', array $attributes = []): Span
937885 *
938886 * @param string|Stringable $content Tag content.
939887 * @param array $attributes The tag attributes in terms of name-value pairs.
940- *
941- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
942888 */
943889 public static function em ($ content = '' , array $ attributes = []): Em
944890 {
@@ -954,8 +900,6 @@ public static function em($content = '', array $attributes = []): Em
954900 *
955901 * @param string|Stringable $content Tag content.
956902 * @param array $attributes The tag attributes in terms of name-value pairs.
957- *
958- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
959903 */
960904 public static function strong ($ content = '' , array $ attributes = []): Strong
961905 {
@@ -971,8 +915,6 @@ public static function strong($content = '', array $attributes = []): Strong
971915 *
972916 * @param string|Stringable $content Tag content.
973917 * @param array $attributes The tag attributes in terms of name-value pairs.
974- *
975- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
976918 */
977919 public static function b ($ content = '' , array $ attributes = []): B
978920 {
@@ -988,8 +930,6 @@ public static function b($content = '', array $attributes = []): B
988930 *
989931 * @param string|Stringable $content Tag content.
990932 * @param array $attributes The tag attributes in terms of name-value pairs.
991- *
992- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
993933 */
994934 public static function i ($ content = '' , array $ attributes = []): I
995935 {
@@ -1005,8 +945,6 @@ public static function i($content = '', array $attributes = []): I
1005945 *
1006946 * @param string|Stringable $content Tag content.
1007947 * @param array $attributes The tag attributes in terms of name-value pairs.
1008- *
1009- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
1010948 */
1011949 public static function h1 ($ content = '' , array $ attributes = []): H1
1012950 {
@@ -1022,8 +960,6 @@ public static function h1($content = '', array $attributes = []): H1
1022960 *
1023961 * @param string|Stringable $content Tag content.
1024962 * @param array $attributes The tag attributes in terms of name-value pairs.
1025- *
1026- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
1027963 */
1028964 public static function h2 ($ content = '' , array $ attributes = []): H2
1029965 {
@@ -1039,8 +975,6 @@ public static function h2($content = '', array $attributes = []): H2
1039975 *
1040976 * @param string|Stringable $content Tag content.
1041977 * @param array $attributes The tag attributes in terms of name-value pairs.
1042- *
1043- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
1044978 */
1045979 public static function h3 ($ content = '' , array $ attributes = []): H3
1046980 {
@@ -1056,8 +990,6 @@ public static function h3($content = '', array $attributes = []): H3
1056990 *
1057991 * @param string|Stringable $content Tag content.
1058992 * @param array $attributes The tag attributes in terms of name-value pairs.
1059- *
1060- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
1061993 */
1062994 public static function h4 ($ content = '' , array $ attributes = []): H4
1063995 {
@@ -1073,8 +1005,6 @@ public static function h4($content = '', array $attributes = []): H4
10731005 *
10741006 * @param string|Stringable $content Tag content.
10751007 * @param array $attributes The tag attributes in terms of name-value pairs.
1076- *
1077- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
10781008 */
10791009 public static function h5 ($ content = '' , array $ attributes = []): H5
10801010 {
@@ -1090,8 +1020,6 @@ public static function h5($content = '', array $attributes = []): H5
10901020 *
10911021 * @param string|Stringable $content Tag content.
10921022 * @param array $attributes The tag attributes in terms of name-value pairs.
1093- *
1094- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
10951023 */
10961024 public static function h6 ($ content = '' , array $ attributes = []): H6
10971025 {
@@ -1107,8 +1035,6 @@ public static function h6($content = '', array $attributes = []): H6
11071035 *
11081036 * @param string|Stringable $content Tag content.
11091037 * @param array $attributes The tag attributes in terms of name-value pairs.
1110- *
1111- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
11121038 */
11131039 public static function p ($ content = '' , array $ attributes = []): P
11141040 {
@@ -1345,8 +1271,6 @@ public static function source(): Source
13451271 * @param array $attributes Attributes to be rendered. The attribute values will be HTML-encoded using
13461272 * {@see encodeAttribute()}.
13471273 *
1348- * @psalm-param HtmlAttributes|array<empty, empty> $attributes
1349- *
13501274 * @throws JsonException
13511275 *
13521276 * @return string The rendering result. If the attributes are not empty, they will be rendered into a string
@@ -1425,16 +1349,15 @@ public static function renderTagAttributes(array $attributes): string
14251349 *
14261350 * @param array $options The options to be modified.
14271351 * @param string|string[] $class The CSS class(es) to be added.
1428- *
1429- * @psalm-param HtmlAttributes|array<empty, empty> $options
14301352 */
14311353 public static function addCssClass (array &$ options , $ class ): void
14321354 {
1433- /** @psalm-var HtmlAttributes $options */
14341355 if (isset ($ options ['class ' ])) {
14351356 if (is_array ($ options ['class ' ])) {
1357+ /** @psalm-var string[] $options['class'] */
14361358 $ options ['class ' ] = self ::mergeCssClasses ($ options ['class ' ], (array )$ class );
14371359 } else {
1360+ /** @psalm-var string $options['class'] */
14381361 $ classes = preg_split ('/\s+/ ' , $ options ['class ' ], -1 , PREG_SPLIT_NO_EMPTY );
14391362 $ options ['class ' ] = implode (' ' , self ::mergeCssClasses ($ classes , (array )$ class ));
14401363 }
@@ -1450,8 +1373,6 @@ public static function addCssClass(array &$options, $class): void
14501373 *
14511374 * @param array $options The options to be modified.
14521375 * @param string|string[] $class The CSS class(es) to be removed.
1453- *
1454- * @psalm-param HtmlAttributes|array<empty, empty> $options
14551376 */
14561377 public static function removeCssClass (array &$ options , $ class ): void
14571378 {
@@ -1518,13 +1439,11 @@ private static function mergeCssClasses(array $existingClasses, array $additiona
15181439 * @param array<string, string>|string $style The new style string (e.g. `'width: 100px; height: 200px'`) or array
15191440 * (e.g. `['width' => '100px', 'height' => '200px']`).
15201441 * @param bool $overwrite Whether to overwrite existing CSS properties if the new style contain them too.
1521- *
1522- * @psalm-param HtmlAttributes|array<empty, empty> $options
15231442 */
15241443 public static function addCssStyle (array &$ options , $ style , bool $ overwrite = true ): void
15251444 {
1526- /** @psalm-var HtmlAttributes $options */
15271445 if (!empty ($ options ['style ' ])) {
1446+ /** @psalm-var array<string,string>|string $options['style'] */
15281447 $ oldStyle = is_array ($ options ['style ' ]) ? $ options ['style ' ] : self ::cssStyleToArray ($ options ['style ' ]);
15291448 $ newStyle = is_array ($ style ) ? $ style : self ::cssStyleToArray ($ style );
15301449 if (!$ overwrite ) {
@@ -1553,13 +1472,11 @@ public static function addCssStyle(array &$options, $style, bool $overwrite = tr
15531472 * @param array $options The HTML options to be modified.
15541473 * @param string|string[] $properties The CSS properties to be removed. You may use a string if you are removing a
15551474 * single property.
1556- *
1557- * @psalm-param HtmlAttributes|array<empty, empty> $options
15581475 */
15591476 public static function removeCssStyle (array &$ options , $ properties ): void
15601477 {
1561- /** @psalm-var HtmlAttributes $options */
15621478 if (!empty ($ options ['style ' ])) {
1479+ /** @psalm-var array<string,string>|string $options['style'] */
15631480 $ style = is_array ($ options ['style ' ]) ? $ options ['style ' ] : self ::cssStyleToArray ($ options ['style ' ]);
15641481 foreach ((array )$ properties as $ property ) {
15651482 unset($ style [$ property ]);
0 commit comments