@@ -41,7 +41,7 @@ final class WebViewState
4141
4242 /**
4343 * @var array The registered link tags.
44- * @psalm-var array<int, Link[] >
44+ * @psalm-var array<int, non-empty-array<array-key, Link> >
4545 *
4646 * @see registerLink()
4747 * @see registerLinkTag()
@@ -50,31 +50,31 @@ final class WebViewState
5050
5151 /**
5252 * @var array The registered CSS code blocks.
53- * @psalm-var array<int, string[] |Style[] >
53+ * @psalm-var array<int, non-empty-array<array-key, string|Style> >
5454 *
5555 * {@see registerCss()}
5656 */
5757 private array $ css = [];
5858
5959 /**
6060 * @var array The registered CSS files.
61- * @psalm-var array<int, string[] >
61+ * @psalm-var array<int, non-empty-array<array-key, string> >
6262 *
6363 * {@see registerCssFile()}
6464 */
6565 private array $ cssFiles = [];
6666
6767 /**
6868 * @var array The registered JS code blocks
69- * @psalm-var array<int, string[] |Script[] >
69+ * @psalm-var array<int, non-empty-array<array-key, string|Script> >
7070 *
7171 * {@see registerJs()}
7272 */
7373 private array $ js = [];
7474
7575 /**
7676 * @var array The registered JS files.
77- * @psalm-var array<int, string[] >
77+ * @psalm-var array<int, non-empty-array<array-key, string> >
7878 *
7979 * {@see registerJsFile()}
8080 */
@@ -98,7 +98,7 @@ public function getMetaTags(): array
9898
9999 /**
100100 * @return array The registered link tags.
101- * @psalm-return array<int, Link[] >
101+ * @psalm-return array<int, non-empty-array<array-key, Link> >
102102 */
103103 public function getLinkTags (): array
104104 {
@@ -107,7 +107,7 @@ public function getLinkTags(): array
107107
108108 /**
109109 * @return array The registered CSS code blocks.
110- * @psalm-return array<int, string[] |Style[] >
110+ * @psalm-return array<int, non-empty-array<array-key, string|Style> >
111111 */
112112 public function getCss (): array
113113 {
@@ -116,7 +116,7 @@ public function getCss(): array
116116
117117 /**
118118 * @return array The registered CSS files.
119- * @psalm-return array<int, string[] >
119+ * @psalm-return array<int, non-empty-array<array-key, string> >
120120 */
121121 public function getCssFiles (): array
122122 {
@@ -125,7 +125,7 @@ public function getCssFiles(): array
125125
126126 /**
127127 * @return array The registered JS code blocks
128- * @psalm-return array<int, string[] |Script[] >
128+ * @psalm-return array<int, non-empty-array<array-key, string|Script> >
129129 */
130130 public function getJs (): array
131131 {
@@ -134,7 +134,7 @@ public function getJs(): array
134134
135135 /**
136136 * @return array The registered JS files.
137- * @psalm-return array<int, string[] >
137+ * @psalm-return array<int, non-empty-array<array-key, string> >
138138 */
139139 public function getJsFiles (): array
140140 {
@@ -224,18 +224,17 @@ public function registerLinkTag(Link $link, int $position = WebView::POSITION_HE
224224 * Registers a CSS code block.
225225 *
226226 * @param string $css The content of the CSS code block to be registered.
227- * @param string|null $key The key that identifies the CSS code block. If null, it will use $css as the key.
228- * If two CSS code blocks are registered with the same key, the latter will overwrite the former.
229227 * @param array $attributes The HTML attributes for the {@see Style} tag.
228+ * @param string|null $key The key that identifies the CSS code block. If `null`, it will use `$css` as the key.
229+ * If two CSS code blocks are registered with the same key, the latter will overwrite the former.
230230 */
231231 public function registerCss (
232232 string $ css ,
233233 int $ position = WebView::POSITION_HEAD ,
234234 array $ attributes = [],
235235 ?string $ key = null
236236 ): void {
237- $ key = $ key ?: md5 ($ css );
238- $ this ->css [$ position ][$ key ] = $ attributes === [] ? $ css : Html::style ($ css , $ attributes );
237+ $ this ->css [$ position ][$ key ?? md5 ($ css )] = $ attributes === [] ? $ css : Html::style ($ css , $ attributes );
239238 }
240239
241240 /**
@@ -266,8 +265,7 @@ public function registerCssFromFile(
266265 */
267266 public function registerStyleTag (Style $ style , int $ position = WebView::POSITION_HEAD , ?string $ key = null ): void
268267 {
269- $ key = $ key ?: md5 ($ style ->render ());
270- $ this ->css [$ position ][$ key ] = $ style ;
268+ $ this ->css [$ position ][$ key ?? md5 ($ style ->render ())] = $ style ;
271269 }
272270
273271 /**
@@ -280,20 +278,20 @@ public function registerStyleTag(Style $style, int $position = WebView::POSITION
280278 * @param string $url The CSS file to be registered.
281279 * @param array $options the HTML attributes for the link tag. Please refer to {@see \Yiisoft\Html\Html::cssFile()}
282280 * for the supported options.
283- * @param string|null $key The key that identifies the CSS script file. If null, it will use $url as the key.
281+ * @param string|null $key The key that identifies the CSS script file. If ` null` , it will use ` $url` as the key.
284282 * If two CSS files are registered with the same key, the latter will overwrite the former.
285283 */
286284 public function registerCssFile (
287285 string $ url ,
288286 int $ position = WebView::POSITION_HEAD ,
289287 array $ options = [],
290- string $ key = null
288+ ? string $ key = null
291289 ): void {
292290 if (!$ this ->isValidCssPosition ($ position )) {
293291 throw new InvalidArgumentException ('Invalid position of CSS file. ' );
294292 }
295293
296- $ this ->cssFiles [$ position ][$ key ?: $ url ] = Html::cssFile ($ url , $ options )->render ();
294+ $ this ->cssFiles [$ position ][$ key ?? $ url ] = Html::cssFile ($ url , $ options )->render ();
297295 }
298296
299297 /**
@@ -337,13 +335,12 @@ public function addCssStrings(array $cssStrings): void
337335 * - {@see WebView::POSITION_END}: at the end of the body section. This is the default value.
338336 * - {@see WebView::POSITION_LOAD}: executed when HTML page is completely loaded.
339337 * - {@see WebView::POSITION_READY}: executed when HTML document composition is ready.
340- * @param string|null $key The key that identifies the JS code block. If null, it will use $js as the key.
338+ * @param string|null $key The key that identifies the JS code block. If ` null` , it will use ` $js` as the key.
341339 * If two JS code blocks are registered with the same key, the latter will overwrite the former.
342340 */
343341 public function registerJs (string $ js , int $ position = WebView::POSITION_END , ?string $ key = null ): void
344342 {
345- $ key = $ key ?: md5 ($ js );
346- $ this ->js [$ position ][$ key ] = $ js ;
343+ $ this ->js [$ position ][$ key ?? md5 ($ js )] = $ js ;
347344 }
348345
349346 /**
@@ -353,8 +350,7 @@ public function registerJs(string $js, int $position = WebView::POSITION_END, ?s
353350 */
354351 public function registerScriptTag (Script $ script , int $ position = WebView::POSITION_END , ?string $ key = null ): void
355352 {
356- $ key = $ key ?: md5 ($ script ->render ());
357- $ this ->js [$ position ][$ key ] = $ script ;
353+ $ this ->js [$ position ][$ key ?? md5 ($ script ->render ())] = $ script ;
358354 }
359355
360356 /**
@@ -389,7 +385,7 @@ public function registerJsFile(
389385 throw new InvalidArgumentException ('Invalid position of JS file. ' );
390386 }
391387
392- $ this ->jsFiles [$ position ][$ key ?: $ url ] = Html::javaScriptFile ($ url , $ options )->render ();
388+ $ this ->jsFiles [$ position ][$ key ?? $ url ] = Html::javaScriptFile ($ url , $ options )->render ();
393389 }
394390
395391 /**
0 commit comments