Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Observer_Settings | |
0.00% |
0 / 10 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
| sanitize | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| validate | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| parse | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\Jetpack_Inspect\Options; |
| 4 | |
| 5 | use Automattic\Jetpack\Packages\Async_Option\Async_Option_Template; |
| 6 | |
| 7 | class Observer_Settings extends Async_Option_Template { |
| 8 | |
| 9 | // phpcs:ignore WordPress.NamingConventions.ValidVariableName.PropertyNotSnakeCase |
| 10 | public static $DEFAULT_VALUE = array( |
| 11 | 'enabled' => true, |
| 12 | 'filter' => '', |
| 13 | ); |
| 14 | |
| 15 | public function sanitize( $value ) { |
| 16 | return array( |
| 17 | 'enabled' => filter_var( $value['enabled'], FILTER_VALIDATE_BOOLEAN ), |
| 18 | 'filter' => sanitize_text_field( $value['filter'] ), |
| 19 | ); |
| 20 | } |
| 21 | |
| 22 | public function validate( $value ) { |
| 23 | |
| 24 | if ( ! isset( $value['enabled'] ) ) { |
| 25 | $this->add_error( "Missing required key 'enabled'" ); |
| 26 | } |
| 27 | if ( ! isset( $value['filter'] ) ) { |
| 28 | $this->add_error( "Missing required key 'filters'" ); |
| 29 | } |
| 30 | |
| 31 | return ! $this->has_errors(); |
| 32 | } |
| 33 | |
| 34 | public function parse( $value ) { |
| 35 | return json_decode( $value, true ); |
| 36 | } |
| 37 | } |