17
17
*
18
18
* @since n.e.x.t
19
19
*
20
- * @return array<string,mixed> Returns an array containing response and blocking assets.
20
+ * @return array{
21
+ * response: WP_Error|array{
22
+ * headers: WpOrg\Requests\Utility\CaseInsensitiveDictionary,
23
+ * body: string,
24
+ * response: array{
25
+ * code: int|false,
26
+ * message: string|false,
27
+ * },
28
+ * },
29
+ * assets: array{
30
+ * scripts: array<array{ src: string, size: int|null, error: WP_Error|null }>,
31
+ * styles: array<array{ src: string, size: int|null, error: WP_Error|null }>,
32
+ * }
33
+ * } An array containing response and blocking assets.
21
34
*/
22
35
function perflab_aea_audit_blocking_assets (): array {
23
36
$ response = wp_remote_get (
@@ -150,11 +163,10 @@ function perflab_aea_enqueued_blocking_assets_test(): array {
150
163
);
151
164
152
165
$ audit_result = perflab_aea_audit_blocking_assets ();
153
- if ( is_wp_error ( $ audit_result ['response ' ] ) || is_array ( $ audit_result ['response ' ] ) ) {
154
- $ retrieval_failure_result = perflab_aea_blocking_assets_retrieval_failure ( $ audit_result ['response ' ] );
155
- if ( null !== $ retrieval_failure_result ) {
156
- return array_merge ( $ result , $ retrieval_failure_result );
157
- }
166
+
167
+ $ retrieval_failure_result = perflab_aea_blocking_assets_retrieval_failure ( $ audit_result ['response ' ] );
168
+ if ( null !== $ retrieval_failure_result ) {
169
+ return array_merge ( $ result , $ retrieval_failure_result );
158
170
}
159
171
160
172
$ scripts_result = perflab_aea_enqueued_blocking_scripts ( $ audit_result ['assets ' ] );
@@ -199,6 +211,11 @@ function perflab_aea_enqueued_ajax_blocking_assets_test(): void {
199
211
*
200
212
* @since n.e.x.t
201
213
*
214
+ * @phpstan-param array{
215
+ * scripts: array<array{ src: string, size: int|null, error: WP_Error|null }>,
216
+ * styles: array<array{ src: string, size: int|null, error: WP_Error|null }>,
217
+ * } $blocking_assets
218
+ *
202
219
* @param array<string, mixed> $blocking_assets Array of blocking assets.
203
220
* @return array{status: 'good'|'recommended', description: string}|null Result.
204
221
*/
@@ -287,6 +304,11 @@ function perflab_aea_enqueued_blocking_scripts( array $blocking_assets ): ?array
287
304
*
288
305
* @since n.e.x.t
289
306
*
307
+ * @phpstan-param array{
308
+ * scripts: array<array{ src: string, size: int|null, error: WP_Error|null }>,
309
+ * styles: array<array{ src: string, size: int|null, error: WP_Error|null }>,
310
+ * } $blocking_assets
311
+ *
290
312
* @param array<string, mixed> $blocking_assets Array of blocking assets.
291
313
* @return array{status: string, description: string}|null Result.
292
314
*/
@@ -376,6 +398,15 @@ function perflab_aea_enqueued_blocking_styles( array $blocking_assets ): ?array
376
398
*
377
399
* @since n.e.x.t
378
400
*
401
+ * @phpstan-param WP_Error|array{
402
+ * headers: WpOrg\Requests\Utility\CaseInsensitiveDictionary,
403
+ * body: string,
404
+ * response: array{
405
+ * code: int|false,
406
+ * message: string|false,
407
+ * },
408
+ * } $response
409
+ *
379
410
* @param WP_Error|array<string, mixed> $response The response from the home page retrieval.
380
411
* @return array{status: 'recommended', description: string}|null Result, or null if there was no failure.
381
412
*/
@@ -445,6 +476,11 @@ function perflab_aea_blocking_assets_retrieval_failure( $response ): ?array {
445
476
*
446
477
* @since n.e.x.t
447
478
*
479
+ * @phpstan-param array{
480
+ * scripts: array<array{ src: string, size: int|null, error: WP_Error|null }>,
481
+ * styles: array<array{ src: string, size: int|null, error: WP_Error|null }>,
482
+ * } $blocking_assets
483
+ *
448
484
* @param array<string, mixed> $blocking_assets Array of blocking assets.
449
485
* @param 'scripts'|'styles' $type Type of assets.
450
486
* @return array<array{ src: string, size: int|null, error: WP_Error|null }>|null Blocking assets, or null if transient not set.
@@ -486,6 +522,11 @@ function perflab_aea_get_blocking_assets( array $blocking_assets, string $type )
486
522
*
487
523
* @since n.e.x.t
488
524
*
525
+ * @phpstan-param array{
526
+ * scripts: array<array{ src: string, size: int|null, error: WP_Error|null }>,
527
+ * styles: array<array{ src: string, size: int|null, error: WP_Error|null }>,
528
+ * } $blocking_assets
529
+ *
489
530
* @param array<string, mixed> $blocking_assets Array of blocking assets.
490
531
* @param 'scripts'|'styles' $type Type.
491
532
* @return int|null Number of total scripts or null if transient hasn't been set.
@@ -503,6 +544,11 @@ function perflab_aea_get_total_enqueued_assets( array $blocking_assets, string $
503
544
*
504
545
* @since n.e.x.t
505
546
*
547
+ * @phpstan-param array{
548
+ * scripts: array<array{ src: string, size: int|null, error: WP_Error|null }>,
549
+ * styles: array<array{ src: string, size: int|null, error: WP_Error|null }>,
550
+ * } $blocking_assets
551
+ *
506
552
* @param array<string, mixed> $blocking_assets Array of blocking assets.
507
553
* @param 'scripts'|'styles' $type Type.
508
554
* @return int|null Byte Total size or null if transient hasn't been set.
@@ -583,11 +629,16 @@ function perflab_get_http_basic_authorization_headers(): array {
583
629
*
584
630
* @since n.e.x.t
585
631
*
586
- * @param array{scripts: array<string, mixed>, styles: array<string, mixed>} $blocking_assets Array of blocking assets.
632
+ * @phpstan-param array{
633
+ * scripts: array<array{ src: string, size: int|null, error: WP_Error|null }>,
634
+ * styles: array<array{ src: string, size: int|null, error: WP_Error|null }>,
635
+ * } $blocking_assets
636
+ *
637
+ * @param array<string, mixed> $blocking_assets Array of blocking assets.
587
638
* @return string HTML table of blocking assets.
588
639
*/
589
640
function perflab_aea_generate_blocking_assets_table ( array $ blocking_assets ): string {
590
- if ( 0 === count ( $ blocking_assets ) || ( isset ( $ blocking_assets ['scripts ' ] ) && 0 === count ( $ blocking_assets ['scripts ' ] ) && 0 === count ( $ blocking_assets [ ' styles ' ] ) ) ) {
641
+ if ( 0 === count ( $ blocking_assets ['scripts ' ] ) && 0 === count ( $ blocking_assets ['styles ' ] ) ) {
591
642
return '' ;
592
643
}
593
644
@@ -605,12 +656,10 @@ function perflab_aea_generate_blocking_assets_table( array $blocking_assets ): s
605
656
foreach ( $ asset_types as $ type => $ label ) {
606
657
if ( isset ( $ blocking_assets [ $ type ] ) && is_array ( $ blocking_assets [ $ type ] ) ) {
607
658
foreach ( $ blocking_assets [ $ type ] as $ asset ) {
608
- $ has_error = is_wp_error ( $ asset ['error ' ] );
609
-
610
- $ table .= $ has_error ? '<tr style="background-color: #ffecec;"> ' : '<tr> ' ;
659
+ $ table .= is_wp_error ( $ asset ['error ' ] ) ? '<tr style="background-color: #ffecec;"> ' : '<tr> ' ;
611
660
$ table .= '<td> ' . esc_html ( $ label ) . '</td> ' ;
612
661
$ table .= '<td> ' . esc_url ( $ asset ['src ' ] );
613
- if ( $ has_error ) {
662
+ if ( is_wp_error ( $ asset [ ' error ' ] ) ) {
614
663
$ table .= '<p> ' . wp_kses ( $ asset ['error ' ]->get_error_message (), array ( 'code ' => array () ) ) . '</p> ' ;
615
664
}
616
665
$ table .= '</td> ' ;
@@ -622,7 +671,7 @@ function perflab_aea_generate_blocking_assets_table( array $blocking_assets ): s
622
671
}
623
672
$ table .= '</td> ' ;
624
673
$ table .= '<td> ' ;
625
- if ( $ has_error ) {
674
+ if ( is_wp_error ( $ asset [ ' error ' ] ) ) {
626
675
$ table .= esc_html__ ( 'Error ' , 'performance-lab ' );
627
676
} else {
628
677
$ table .= esc_html__ ( 'OK ' , 'performance-lab ' );
0 commit comments