| @@ -254,9 +254,12 @@ | ||
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | $started = Scan::start( |
| 257 | 257 | (string) ( $request->get_param( 'url' ) ?? '' ), |
| 258 | - (bool) $request->get_param( 'fresh' ) | |
| 258 | + (bool) $request->get_param( 'fresh' ), | |
| 259 | + // `both` (default), `desktop` or `mobile` — which Lighthouse runs | |
| 260 | + // the engine spends and therefore which device is the headline. | |
| 261 | + (string) ( $request->get_param( 'strategy' ) ?? 'both' ) | |
| 259 | 262 | ); |
| 260 | 263 | if ( is_wp_error( $started ) ) { |
| 261 | 264 | return $started; |
| 262 | 265 | } |
| @@ -811,8 +814,15 @@ | ||
| 811 | 814 | 'description' => 'Force a new scan instead of reusing a recent cached report.', |
| 812 | 815 | 'optional' => true, |
| 813 | 816 | ), |
| 814 | 817 | array( |
| 818 | + 'type' => 'assoc', | |
| 819 | + 'name' => 'strategy', | |
| 820 | + 'description' => 'Which Lighthouse runs to spend: both (default; desktop graded as the headline, mobile graded alongside), desktop, or mobile. One device costs half the engine quota and becomes the headline.', | |
| 821 | + 'optional' => true, | |
| 822 | + 'options' => array( 'both', 'desktop', 'mobile' ), | |
| 823 | + ), | |
| 824 | + array( | |
| 815 | 825 | 'type' => 'flag', |
| 816 | 826 | 'name' => 'wait', |
| 817 | 827 | 'description' => 'Poll until the scan finishes instead of returning immediately.', |
| 818 | 828 | 'optional' => true, |
| @@ -863,9 +873,10 @@ | ||
| 863 | 873 | } |
| 864 | 874 | |
| 865 | 875 | $started = Scan::start( |
| 866 | 876 | (string) ( $assoc_args['target'] ?? '' ), |
| 867 | - ! empty( $assoc_args['fresh'] ) | |
| 877 | + ! empty( $assoc_args['fresh'] ), | |
| 878 | + (string) ( $assoc_args['strategy'] ?? 'both' ) | |
| 868 | 879 | ); |
| 869 | 880 | if ( is_wp_error( $started ) ) { |
| 870 | 881 | \WP_CLI::error( $started->get_error_message() ); |
| 871 | 882 | return; |
| @@ -935,20 +946,30 @@ | ||
| 935 | 946 | ); |
| 936 | 947 | foreach ( (array) ( $r['dimensions'] ?? array() ) as $key => $d ) { |
| 937 | 948 | \WP_CLI::log( sprintf( ' %-9s %3s/100 (%s of %s pts)', $key, $d['score'] ?? '-', $d['earned'] ?? '-', $d['weight'] ?? '-' ) ); |
| 938 | 949 | } |
| 939 | - $lh = $r['measured']['lighthouse'] ?? null; | |
| 950 | + // Read the PER-DEVICE fields, never `measured.lighthouse`: that one is | |
| 951 | + // the graded run's score, which is desktop on a default scan, so | |
| 952 | + // printing it as "mobile" reported desktop under a mobile label. | |
| 953 | + $lhm = $r['measured']['lighthouse_mobile'] ?? null; | |
| 940 | 954 | $lhd = $r['measured']['lighthouse_desktop'] ?? null; |
| 941 | - if ( null !== $lh || null !== $lhd ) { | |
| 942 | - // Both strategies: the engine measures both and they diverge | |
| 943 | - // widely, so reporting only mobile states the harsher number as | |
| 944 | - // though it were the whole picture. Labelled, and never as "the | |
| 945 | - // score": different scale. | |
| 955 | + if ( null !== $lhm || null !== $lhd ) { | |
| 956 | + // Name only the devices actually measured. A desktop-only scan | |
| 957 | + // never ran mobile, and a dash there reads as "scored zero" | |
| 958 | + // rather than "not run". | |
| 959 | + $parts = array(); | |
| 960 | + if ( null !== $lhd ) { | |
| 961 | + $parts[] = 'desktop ' . $lhd . '/100'; | |
| 962 | + } | |
| 963 | + if ( null !== $lhm ) { | |
| 964 | + $parts[] = 'mobile ' . $lhm . '/100'; | |
| 965 | + } | |
| 966 | + $graded = (string) ( $r['device'] ?? '' ); | |
| 946 | 967 | \WP_CLI::log( |
| 947 | 968 | sprintf( |
| 948 | - 'Lighthouse: mobile %s, desktop %s - a different scale, one check inside the score above.', | |
| 949 | - null === $lh ? '-' : $lh . '/100', | |
| 950 | - null === $lhd ? '-' : $lhd . '/100' | |
| 969 | + 'Lighthouse: %s - a different scale, one check inside the score above.%s', | |
| 970 | + implode( ', ', $parts ), | |
| 971 | + '' !== $graded ? ' Graded on ' . $graded . '.' : '' | |
| 951 | 972 | ) |
| 952 | 973 | ); |
| 953 | 974 | } |
| 954 | 975 | \WP_CLI::log( 'Report: ' . ( $r['report_url'] ?? '' ) ); |