Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
81 / 81 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
| Data_Sync_Schema | |
100.00% |
81 / 81 |
|
100.00% |
7 / 7 |
7 | |
100.00% |
1 / 1 |
| critical_css_provider_error | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
1 | |||
| critical_css_state | |
100.00% |
28 / 28 |
|
100.00% |
1 / 1 |
1 | |||
| critical_css_meta | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| critical_css_suggest_regenerate | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| critical_css_set_provider | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| critical_css_set_provider_errors | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| critical_css_set_provider_errors_dismissed | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\Jetpack_Boost\Lib\Critical_CSS\Data_Sync; |
| 4 | |
| 5 | use Automattic\Jetpack\Schema\Schema; |
| 6 | |
| 7 | /** |
| 8 | * Registers data sync for both the Critical CSS module and the Cloud CSS module. Both of these modules cannot be available at the same time. |
| 9 | */ |
| 10 | class Data_Sync_Schema { |
| 11 | /** |
| 12 | * Represents a set of errors that can be stored for a single Provider Key in a Critical CSS state block. |
| 13 | */ |
| 14 | public static function critical_css_provider_error() { |
| 15 | return Schema::as_array( |
| 16 | Schema::as_assoc_array( |
| 17 | array( |
| 18 | 'url' => Schema::as_string(), |
| 19 | 'message' => Schema::as_string(), |
| 20 | 'type' => Schema::as_string(), |
| 21 | 'meta' => Schema::any_json_data()->nullable(), |
| 22 | ) |
| 23 | )->fallback( |
| 24 | array( |
| 25 | 'url' => '', |
| 26 | 'message' => '', |
| 27 | 'type' => '', |
| 28 | ) |
| 29 | ) |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | public static function critical_css_state() { |
| 34 | return Schema::as_assoc_array( |
| 35 | array( |
| 36 | 'providers' => Schema::as_array( |
| 37 | Schema::as_assoc_array( |
| 38 | array( |
| 39 | 'key' => Schema::as_string(), |
| 40 | 'label' => Schema::as_string(), |
| 41 | 'urls' => Schema::as_array( Schema::as_string() ), |
| 42 | 'success_ratio' => Schema::as_float(), |
| 43 | 'status' => Schema::enum( array( 'success', 'pending', 'error', 'validation-error' ) )->fallback( 'validation-error' ), |
| 44 | 'dismissed_errors' => Schema::as_array( Schema::as_string() )->nullable(), |
| 45 | 'errors' => self::critical_css_provider_error()->nullable(), |
| 46 | ) |
| 47 | ) |
| 48 | )->nullable(), |
| 49 | 'status' => Schema::enum( array( 'not_generated', 'generated', 'pending', 'error' ) )->fallback( 'not_generated' ), |
| 50 | 'created' => Schema::as_float()->nullable(), |
| 51 | 'updated' => Schema::as_float()->nullable(), |
| 52 | 'status_error' => Schema::as_string()->nullable(), |
| 53 | ) |
| 54 | )->fallback( |
| 55 | array( |
| 56 | 'providers' => array(), |
| 57 | 'status' => 'not_generated', |
| 58 | 'created' => null, |
| 59 | 'updated' => null, |
| 60 | ) |
| 61 | ); |
| 62 | } |
| 63 | |
| 64 | public static function critical_css_meta() { |
| 65 | return Schema::as_assoc_array( |
| 66 | array( |
| 67 | 'proxy_nonce' => Schema::as_string()->nullable(), |
| 68 | ) |
| 69 | ); |
| 70 | } |
| 71 | |
| 72 | public static function critical_css_suggest_regenerate() { |
| 73 | return Schema::enum( |
| 74 | array( |
| 75 | '1', // Old versions of Boost stored a boolean in the DB. |
| 76 | 'page_saved', |
| 77 | 'post_saved', |
| 78 | 'switched_theme', |
| 79 | 'plugin_change', |
| 80 | 'cornerstone_page_saved', |
| 81 | 'cornerstone_pages_list_updated', |
| 82 | ) |
| 83 | )->nullable(); |
| 84 | } |
| 85 | |
| 86 | public static function critical_css_set_provider() { |
| 87 | return Schema::as_assoc_array( |
| 88 | array( |
| 89 | 'key' => Schema::as_string(), |
| 90 | 'css' => Schema::as_string(), |
| 91 | ) |
| 92 | ); |
| 93 | } |
| 94 | |
| 95 | public static function critical_css_set_provider_errors() { |
| 96 | return Schema::as_assoc_array( |
| 97 | array( |
| 98 | 'key' => Schema::as_string(), |
| 99 | 'errors' => self::critical_css_provider_error(), |
| 100 | ) |
| 101 | ); |
| 102 | } |
| 103 | |
| 104 | public static function critical_css_set_provider_errors_dismissed() { |
| 105 | return Schema::as_array( |
| 106 | Schema::as_assoc_array( |
| 107 | array( |
| 108 | 'provider' => Schema::as_string(), |
| 109 | 'error_type' => Schema::as_string(), |
| 110 | 'dismissed' => Schema::as_boolean(), |
| 111 | ) |
| 112 | ) |
| 113 | ); |
| 114 | } |
| 115 | } |