Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
6.25% |
1 / 16 |
|
25.00% |
1 / 4 |
CRAP | |
0.00% |
0 / 1 |
| Critical_CSS_Storage | |
6.25% |
1 / 16 |
|
25.00% |
1 / 4 |
47.37 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| store_css | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| clear | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_css | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Critical CSS storage. |
| 4 | * |
| 5 | * @link https://automattic.com |
| 6 | * @since 1.0.0 |
| 7 | * @package automattic/jetpack-boost |
| 8 | */ |
| 9 | |
| 10 | namespace Automattic\Jetpack_Boost\Lib\Critical_CSS; |
| 11 | |
| 12 | use Automattic\Jetpack_Boost\Lib\Storage_Post_Type; |
| 13 | |
| 14 | /** |
| 15 | * Critical CSS Storage class |
| 16 | */ |
| 17 | class Critical_CSS_Storage { |
| 18 | |
| 19 | /** |
| 20 | * Storage post type. |
| 21 | * |
| 22 | * @var Storage_Post_Type |
| 23 | */ |
| 24 | protected $storage; |
| 25 | |
| 26 | /** |
| 27 | * Critical_CSS_Storage constructor. |
| 28 | */ |
| 29 | public function __construct() { |
| 30 | $this->storage = new Storage_Post_Type( 'css' ); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Store Critical CSS for a specific provider. |
| 35 | * |
| 36 | * @param string $key Provider key. |
| 37 | * @param string $value Critical CSS. |
| 38 | */ |
| 39 | public function store_css( $key, $value ) { |
| 40 | $this->storage->set( |
| 41 | $key, |
| 42 | array( |
| 43 | 'css' => $value, |
| 44 | ) |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Clear the whole Critical CSS storage. |
| 50 | */ |
| 51 | public function clear() { |
| 52 | $this->storage->clear(); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Get Critical CSS for specific provider keys. |
| 57 | * |
| 58 | * @param array $provider_keys Provider keys. |
| 59 | * |
| 60 | * @return array|false |
| 61 | */ |
| 62 | public function get_css( $provider_keys ) { |
| 63 | foreach ( $provider_keys as $key ) { |
| 64 | $data = $this->storage->get( $key, false ); |
| 65 | if ( $data && $data['css'] ) { |
| 66 | return array( |
| 67 | 'key' => $key, |
| 68 | 'css' => $data['css'], |
| 69 | ); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | return false; |
| 74 | } |
| 75 | } |