Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
Types | |
0.00% |
0 / 13 |
|
0.00% |
0 / 5 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
set_refers | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
set_value | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
save | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
to_array | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
validate | n/a |
0 / 0 |
n/a |
0 / 0 |
0 |
1 | <?php |
2 | |
3 | namespace NewfoldLabs\WP\Module\Data\SiteClassification; |
4 | |
5 | /** |
6 | * Base class with common functionality across different site classification types. |
7 | */ |
8 | abstract class Types { |
9 | /** |
10 | * The option name to store the data. |
11 | * |
12 | * @var string |
13 | */ |
14 | public $option_name; |
15 | |
16 | /** |
17 | * Indicates what the value refers to, slug(from default slugs)|custom(from a custom input field). |
18 | * |
19 | * @var string |
20 | */ |
21 | public $refers; |
22 | |
23 | /** |
24 | * The actual value of the site classification type. |
25 | * |
26 | * @var string |
27 | */ |
28 | public $value; |
29 | |
30 | /** |
31 | * Constructor for the Type class. |
32 | * |
33 | * @param string $option_name The option name to store the data. |
34 | * @param string $refers Indicates what the value refers to, slug(from default slugs)|custom(from a custom input field). |
35 | * @param string $value The actual value of the site classification type. |
36 | */ |
37 | public function __construct( $option_name, $refers, $value ) { |
38 | $this->option_name = $option_name; |
39 | $this->refers = $refers; |
40 | $this->value = $value; |
41 | } |
42 | |
43 | /** |
44 | * Sets the refers property. |
45 | * |
46 | * @param string $refers Indicates what the value refers to, slug(from default slugs)|custom(from a custom input field). |
47 | * @return void |
48 | */ |
49 | public function set_refers( $refers ) { |
50 | $this->refers = $refers; |
51 | } |
52 | |
53 | /** |
54 | * Sets the value property. |
55 | * |
56 | * @param string $value The actual value of the site classification type. |
57 | * @return void |
58 | */ |
59 | public function set_value( $value ) { |
60 | $this->value = $value; |
61 | } |
62 | |
63 | /** |
64 | * Saves data to the option after validation. |
65 | * |
66 | * @return boolean |
67 | */ |
68 | public function save() { |
69 | if ( ! $this->validate() ) { |
70 | return false; |
71 | } |
72 | update_option( $this->option_name, $this->to_array() ); |
73 | return true; |
74 | } |
75 | |
76 | /** |
77 | * Converts the object to an array. |
78 | * |
79 | * @return array |
80 | */ |
81 | public function to_array() { |
82 | return array( |
83 | 'refers' => $this->refers, |
84 | 'value' => $this->value, |
85 | ); |
86 | } |
87 | |
88 | /** |
89 | * Validates the site classification type data. |
90 | * |
91 | * @return boolean |
92 | */ |
93 | abstract public function validate(); |
94 | } |