Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
50.00% covered (danger)
50.00%
5 / 10
60.00% covered (warning)
60.00%
3 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
Liar
50.00% covered (danger)
50.00%
5 / 10
60.00% covered (warning)
60.00%
3 / 5
10.50
0.00% covered (danger)
0.00%
0 / 1
 setup
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_slug
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 is_available
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 inject_image_cdn_liar_script
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 get_parent_features
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Automattic\Jetpack_Boost\Modules\Optimizations\Image_CDN;
4
5use Automattic\Jetpack_Boost\Contracts\Changes_Output_On_Activation;
6use Automattic\Jetpack_Boost\Contracts\Sub_Feature;
7use Automattic\Jetpack_Boost\Lib\Premium_Features;
8
9class Liar implements Sub_Feature, Changes_Output_On_Activation {
10
11    public function setup() {
12        add_action( 'wp_footer', array( $this, 'inject_image_cdn_liar_script' ) );
13    }
14
15    public static function get_slug() {
16        return 'image_cdn_liar';
17    }
18
19    public static function is_available() {
20        return Premium_Features::has_feature( Premium_Features::IMAGE_CDN_LIAR );
21    }
22
23    /**
24     * Injects the image-cdn-liar.js script as an inline script in the footer.
25     */
26    public function inject_image_cdn_liar_script() {
27        $file = __DIR__ . '/dist/inline-liar.js';
28        if ( file_exists( $file ) ) {
29            // Include the JavaScript directly inline.
30            // phpcs:ignore
31            $data = file_get_contents( $file );
32            // There's no meaningful way to escape JavaScript in this context.
33            // phpcs:ignore
34            echo wp_get_inline_script_tag( $data, array( 'async' => true ) );
35        }
36    }
37
38    public static function get_parent_features(): array {
39        return array(
40            Image_CDN::class,
41        );
42    }
43}