Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Provider
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 2
6
0.00% covered (danger)
0.00%
0 / 1
 get_critical_source_urls
n/a
0 / 0
n/a
0 / 0
0
 get_current_storage_keys
n/a
0 / 0
n/a
0 / 0
0
 get_keys
n/a
0 / 0
n/a
0 / 0
0
 describe_key
n/a
0 / 0
n/a
0 / 0
0
 get_edit_url
n/a
0 / 0
n/a
0 / 0
0
 owns_key
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_provider_name
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_success_ratio
n/a
0 / 0
n/a
0 / 0
0
1<?php
2/**
3 * Abstract Critical CSS provider class.
4 *
5 * @package automattic/jetpack-boost
6 */
7
8namespace Automattic\Jetpack_Boost\Lib\Critical_CSS\Source_Providers\Providers;
9
10/**
11 * Class Provider
12 *
13 * @package Automattic\Jetpack_Boost\Modules\Critical_CSS\Providers
14 */
15abstract class Provider {
16
17    /**
18     * The name of the provider.
19     *
20     * @since    1.0.0
21     * @access   protected
22     * @var      string $name The name of the provider
23     */
24    protected static $name;
25
26    /**
27     * Each provider must return a list of URLs to generate CSS from.
28     *
29     * @param \WP_Post[] $context_posts The posts to generate CSS from.
30     * @return array
31     */
32    abstract public static function get_critical_source_urls( $context_posts = array() );
33
34    /**
35     * What key should this provider look for during the current request?
36     * Used in the front-end to determine where the CSS
37     * might be stored for the current request.
38     *
39     * @return array
40     */
41    abstract public static function get_current_storage_keys();
42
43    /**
44     * Returns a list of all keys that this provider can provide, regardless
45     * of the current URL.
46     */
47    abstract public static function get_keys();
48
49    /**
50     * Get a human-displayable string describing the given provider key.
51     *
52     * @param string $provider_key the key to describe.
53     */
54    abstract public static function describe_key( $provider_key );
55
56    /**
57     * Get the URL of the edit page for the given provider key.
58     *
59     * @param string $provider_key the key to edit.
60     */
61    abstract public static function get_edit_url( $provider_key );
62
63    /**
64     * Returns true if the key looks like it belongs to this provider.
65     *
66     * @param string $key The key.
67     */
68    public static function owns_key( $key ) {
69        return strncmp( static::$name, $key, strlen( static::$name ) ) === 0;
70    }
71
72    /**
73     * Get the name of the provider.
74     *
75     * @return string
76     */
77    public static function get_provider_name() {
78        return static::$name;
79    }
80
81    /**
82     * Returns the ratio of valid urls from the provider source urls
83     * for the Critical CSS generation to be considered successful.
84     *
85     * @return float|int
86     */
87    abstract public static function get_success_ratio();
88}