Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| LCP_Storage | |
0.00% |
0 / 12 |
|
0.00% |
0 / 5 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| store_lcp | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| clear | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_lcp | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_current_request_lcp | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\Jetpack_Boost\Modules\Optimizations\Lcp; |
| 4 | |
| 5 | use Automattic\Jetpack_Boost\Lib\Critical_CSS\Source_Providers\Providers\Cornerstone_Provider; |
| 6 | use Automattic\Jetpack_Boost\Lib\Storage_Post_Type; |
| 7 | /** |
| 8 | * LCP Storage class |
| 9 | */ |
| 10 | class LCP_Storage { |
| 11 | /** |
| 12 | * Storage post type. |
| 13 | * |
| 14 | * @var Storage_Post_Type |
| 15 | */ |
| 16 | protected $storage; |
| 17 | |
| 18 | /** |
| 19 | * LCP_Storage constructor. |
| 20 | */ |
| 21 | public function __construct() { |
| 22 | $this->storage = new Storage_Post_Type( 'lcp' ); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Store LCP data for a specific page. |
| 27 | * |
| 28 | * @param string $key Page key. |
| 29 | * @param array $data LCP data. |
| 30 | */ |
| 31 | public function store_lcp( $key, $data ) { |
| 32 | $this->storage->set( |
| 33 | $key, |
| 34 | $data |
| 35 | ); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Clear the whole LCP storage. |
| 40 | */ |
| 41 | public function clear() { |
| 42 | $this->storage->clear(); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Get LCP data for a specific page key. |
| 47 | * |
| 48 | * @param string $page_key Page key. |
| 49 | * |
| 50 | * @return array|false |
| 51 | */ |
| 52 | public function get_lcp( $page_key ) { |
| 53 | return $this->storage->get( $page_key, false ); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Get LCP data for the current request. |
| 58 | * |
| 59 | * @return array|false LCP data for the current request, or false if not found. |
| 60 | */ |
| 61 | public function get_current_request_lcp() { |
| 62 | // @TODO: this is a temporary solution to get the LCP data for the current request. Cornerstone Provider should be decoupled from the CSS storage. |
| 63 | $current_url = Cornerstone_Provider::get_request_url(); |
| 64 | $key = Cornerstone_Provider::get_provider_key( $current_url ); |
| 65 | if ( empty( $key ) ) { |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | return $this->get_lcp( $key ); |
| 70 | } |
| 71 | } |