Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Default_Filter_Settings
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
5
100.00% covered (success)
100.00%
1 / 1
 get_default_settings
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 get_all_filters_default_settings
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * The Default Filter Settings class.
4 *
5 * This class provides the default whitelist values for the Sync data filters.
6 * See the DATA_FILTER_DEFAULTS constant for the list of filters.
7 *
8 * @package automattic/jetpack-sync
9 */
10
11namespace Automattic\Jetpack\Sync;
12
13/**
14 * The Default_Filter_Settings class
15 */
16class Default_Filter_Settings {
17
18    /**
19     * The class that contains the default values of the filters.
20     */
21    const DEFAULT_FILTER_CLASS = 'Automattic\Jetpack\Sync\Defaults';
22
23    /**
24     * A map of each Sync filter name to the associated property name in the Defaults class.
25     */
26    const DATA_FILTER_DEFAULTS = array(
27        'jetpack_sync_options_whitelist'            => 'default_options_whitelist',
28        'jetpack_sync_options_contentless'          => 'default_options_contentless',
29        'jetpack_sync_constants_whitelist'          => 'default_constants_whitelist',
30        'jetpack_sync_callable_whitelist'           => 'default_callable_whitelist',
31        'jetpack_sync_multisite_callable_whitelist' => 'default_multisite_callable_whitelist',
32        'jetpack_sync_post_meta_whitelist'          => 'post_meta_whitelist',
33        'jetpack_sync_comment_meta_whitelist'       => 'comment_meta_whitelist',
34        'jetpack_sync_capabilities_whitelist'       => 'default_capabilities_whitelist',
35        'jetpack_sync_known_importers'              => 'default_known_importers',
36    );
37
38    /**
39     * The data associated with these filters are stored as associative arrays.
40     * (All other filters store data as indexed arrays.)
41     */
42    const ASSOCIATIVE_FILTERS = array(
43        'jetpack_sync_callable_whitelist',
44        'jetpack_sync_multisite_callable_whitelist',
45        'jetpack_sync_known_importers',
46    );
47
48    /**
49     * Returns the default data settings list for the provided filter.
50     *
51     * @param string $filter The filter name.
52     *
53     * @return array|false The default list of data settings. Returns false if the provided
54     *                     filter doesn't not have an array of default settings.
55     */
56    public function get_default_settings( $filter ) {
57        if ( ! is_string( $filter ) || ! array_key_exists( $filter, self::DATA_FILTER_DEFAULTS ) ) {
58            return false;
59        }
60
61        $property = self::DATA_FILTER_DEFAULTS[ $filter ];
62        $class    = self::DEFAULT_FILTER_CLASS;
63        return $class::$$property;
64    }
65
66    /**
67     * Returns an array containing the default values for all of the filters shown
68     * in DATA_FILTER_DEFAULTS.
69     *
70     * @return array The array containing all sync data filters and their default values.
71     */
72    public function get_all_filters_default_settings() {
73        $defaults = array();
74
75        foreach ( self::DATA_FILTER_DEFAULTS as $filter => $default_location ) {
76            $defaults[ $filter ] = $this->get_default_settings( $filter );
77        }
78        return $defaults;
79    }
80}