Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Data_Point_Theme
0.00% covered (danger)
0.00%
0 / 23
0.00% covered (danger)
0.00%
0 / 2
210
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
 get_value
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 1
132
1<?php
2/**
3 * Class Data Point Theme.
4 *
5 * @package automattic/jetpack-mu-wpcom
6 */
7
8namespace Automattic\Jetpack\Jetpack_Mu_Wpcom\Global_Styles;
9
10require_once __DIR__ . '/interface-data-point.php';
11
12/**
13 * Theme Data Point.
14 */
15class Data_Point_Theme implements Data_Point {
16
17    /**
18     * Feature name.
19     *
20     * @var string
21     */
22    private $feature_name;
23
24    /**
25     * Option property to access, if exists.
26     *
27     * @var string
28     */
29    private $feature_property;
30
31    /**
32     * Default value to return if no found.
33     *
34     * @var string
35     */
36    private $default_value;
37
38    /**
39     * Constructor.
40     *
41     * @param array $meta Data point description.
42     */
43    public function __construct( $meta ) {
44        if ( is_array( $meta['name'] ) ) {
45            $this->feature_name     = $meta['name'][0];
46            $this->feature_property = $meta['name'][1];
47        } else {
48            $this->feature_name = $meta['name'];
49        }
50
51        if ( array_key_exists( 'default', $meta ) ) {
52            $this->default_value = $meta['default'];
53        }
54    }
55
56    /**
57     * Implements the \Automattic\Jetpack\Jetpack_Mu_Wpcom\Global_Styles\Data_Point interface.
58     *
59     * @return mixed The theme value.
60     */
61    public function get_value() {
62        $theme_support = get_theme_support( $this->feature_name );
63        if ( is_array( $theme_support ) ) {
64            $theme_support = $theme_support[0];
65        }
66
67        if ( is_bool( $theme_support ) ) {
68            return $this->default_value;
69        }
70
71        if (
72            is_array( $theme_support ) &&
73            ! isset( $this->feature_property )
74        ) {
75            return $theme_support;
76        }
77
78        if (
79            is_array( $theme_support ) &&
80            isset( $this->feature_property ) &&
81            array_key_exists( $this->feature_property, $theme_support )
82        ) {
83            return $theme_support[ $this->feature_property ];
84        }
85
86        if (
87            is_array( $theme_support ) &&
88            isset( $this->feature_property ) &&
89            ! array_key_exists( $this->feature_property, $theme_support )
90        ) {
91            return $this->default_value;
92        }
93
94        return $this->default_value;
95    }
96}