Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
Set_Provider_Error_Dismissed
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 1
 handle
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace Automattic\Jetpack_Boost\Lib\Critical_CSS\Data_Sync_Actions;
4
5use Automattic\Jetpack\WP_JS_Data_Sync\Contracts\Data_Sync_Action;
6use Automattic\Jetpack_Boost\Lib\Critical_CSS\Critical_CSS_State;
7
8/**
9 * Critical CSS Action: Update whether or not to show a provider which is in an error state.
10 */
11class Set_Provider_Error_Dismissed implements Data_Sync_Action {
12    /**
13     * Handles the action logic.
14     *
15     * @param mixed            $data     JSON Data passed to the action.
16     * @param \WP_REST_Request $_request The request object.
17     */
18    public function handle( $data, $_request ) {
19        $state = new Critical_CSS_State();
20
21        foreach ( $data as $item ) {
22            if ( empty( $item['provider'] ) ) {
23                return array(
24                    'success' => false,
25                    'state'   => $state->get(),
26                    'error'   => 'Invalid data',
27                );
28            }
29
30            $provider_key = sanitize_key( $item['provider'] );
31            $dismissed    = ! empty( $item['dismissed'] );
32
33            $state->set_provider_error_dismissed( $provider_key, $item['error_type'], $dismissed );
34        }
35
36        $state->save();
37
38        return array(
39            'success' => true,
40            'state'   => $state->get(),
41        );
42    }
43}