Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
50.00% covered (danger)
50.00%
3 / 6
25.00% covered (danger)
25.00%
1 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
Mergeable_Array_Entry
50.00% covered (danger)
50.00%
3 / 6
25.00% covered (danger)
25.00%
1 / 4
8.12
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
 set
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 merge
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Automattic\Jetpack_Boost\Data_Sync;
4
5use Automattic\Jetpack\WP_JS_Data_Sync\Contracts\Entry_Can_Get;
6use Automattic\Jetpack\WP_JS_Data_Sync\Contracts\Entry_Can_Merge;
7
8class Mergeable_Array_Entry implements Entry_Can_Get, Entry_Can_Merge {
9    private $option_key;
10
11    public function __construct( $option_key ) {
12        $this->option_key = $option_key;
13    }
14
15    public function get( $fallback_value = false ) {
16        // WordPress looks at argument count to figure out if a fallback value was used.
17        // Only provide the fallback value if it's not the default ( false ).
18        if ( $fallback_value !== false ) {
19            return get_option( $this->option_key, $fallback_value );
20        }
21        return get_option( $this->option_key );
22    }
23
24    public function set( $value ) {
25        update_option( $this->option_key, $value, false );
26    }
27
28    public function merge( $value, $partial_value ) {
29        return array_merge( $value, $partial_value );
30    }
31}