Completed
Push — master ( 159d3b...c30b21 )
by David
02:37
created

Wordlift_Configuration_Service::is_skip_wizard()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 22 and the first side effect is on line 14.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Wordlift_Configuration_Service class.
4
 *
5
 * The {@link Wordlift_Configuration_Service} class provides helper functions to get configuration parameter values.
6
 *
7
 * @link       https://wordlift.io
8
 *
9
 * @package    Wordlift
10
 * @since      3.6.0
11
 */
12
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * Get WordLift's configuration settings stored in WordPress database.
19
 *
20
 * @since 3.6.0
21
 */
22
class Wordlift_Configuration_Service {
23
24
	/**
25
	 * The entity base path option name.
26
	 *
27
	 * @since 3.6.0
28
	 */
29
	const ENTITY_BASE_PATH_KEY = 'wl_entity_base_path';
30
31
	/**
32
	 * The skip wizard (admin installation wizard) option name.
33
	 *
34
	 * @since 3.9.0
35
	 */
36
	const SKIP_WIZARD = 'wl_skip_wizard';
37
38
	/**
39
	 * WordLift's key option name.
40
	 *
41
	 * @since 3.9.0
42
	 */
43
	const KEY = 'key';
44
45
	/**
46
	 * WordLift's configured language option name.
47
	 *
48
	 * @since 3.9.0
49
	 */
50
	const LANGUAGE = 'site_language';
51
52
	/**
53
	 * The publisher entity post ID option name.
54
	 *
55
	 * @since 3.9.0
56
	 */
57
	const PUBLISHER_ID = 'publisher_id';
58
59
	/**
60
	 * The Wordlift_Configuration_Service's singleton instance.
61
	 *
62
	 * @since  3.6.0
63
	 *
64
	 * @access private
65
	 * @var \Wordlift_Configuration_Service $instance Wordlift_Configuration_Service's singleton instance.
66
	 */
67
	private static $instance;
68
69
	/**
70
	 * Create a Wordlift_Configuration_Service's instance.
71
	 *
72
	 * @since 3.6.0
73
	 */
74
	public function __construct() {
75
76
		self::$instance = $this;
77
78
	}
79
80
	/**
81
	 * Get the singleton instance.
82
	 *
83
	 * @since 3.6.0
84
	 *
85
	 * @return \Wordlift_Configuration_Service
86
	 */
87
	public static function get_instance() {
88
89
		return self::$instance;
90
	}
91
92
	/**
93
	 * Get a configuration given the option name and a key. The option value is
94
	 * expected to be an array.
95
	 *
96
	 * @since 3.6.0
97
	 *
98
	 * @param string $option  The option name.
99
	 * @param string $key     A key in the option value array.
100
	 * @param string $default The default value in case the key is not found (by default an empty string).
101
	 *
102
	 * @return mixed The configuration value or the default value if not found.
103
	 */
104
	private function get( $option, $key, $default = '' ) {
105
106
		$options = get_option( $option, array() );
107
108
		return isset( $options[ $key ] ) ? $options[ $key ] : $default;
109
	}
110
111
	/**
112
	 * Set a configuration parameter.
113
	 *
114
	 * @since 3.9.0
115
	 *
116
	 * @param string $option Name of option to retrieve. Expected to not be SQL-escaped.
117
	 * @param string $key    The value key.
118
	 * @param mixed  $value  The value.
119
	 */
120 View Code Duplication
	private function set( $option, $key, $value ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
121
122
		$values         = get_option( $option );
123
		$values         = isset( $values ) ? $values : array();
124
		$values[ $key ] = $value;
125
		update_option( $option, $values );
126
127
	}
128
129
	/**
130
	 * Get the entity base path, by default 'entity'.
131
	 *
132
	 * @since 3.6.0
133
	 *
134
	 * @return string The entity base path.
135
	 */
136
	public function get_entity_base_path() {
137
138
		return $this->get( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity' );
139
	}
140
141
	/**
142
	 * Get the entity base path.
143
	 *
144
	 * @since 3.9.0
145
	 *
146
	 * @param string $value The entity base path.
147
	 */
148
	public function set_entity_base_path( $value ) {
149
150
		$this->set( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value );
151
	}
152
153
	/**
154
	 * Whether the installation skip wizard should be skipped.
155
	 *
156
	 * @since 3.9.0
157
	 *
158
	 * @return bool True if it should be skipped otherwise false.
159
	 */
160
	public function is_skip_wizard() {
161
162
		return $this->get( 'wl_general_settings', self::SKIP_WIZARD, FALSE );
0 ignored issues
show
Documentation introduced by
FALSE is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
163
	}
164
165
	/**
166
	 * Set the skip wizard parameter.
167
	 *
168
	 * @since 3.9.0
169
	 *
170
	 * @param bool $value True to skip the wizard. We expect a boolean value.
171
	 */
172
	public function set_skip_wizard( $value ) {
173
174
		$this->set( 'wl_general_settings', self::SKIP_WIZARD, $value === TRUE );
175
176
	}
177
178
	/**
179
	 * Get WordLift's key.
180
	 *
181
	 * @since 3.9.0
182
	 *
183
	 * @return WordLift's key or an empty string if not set.
0 ignored issues
show
Documentation introduced by
The doc-type WordLift's could not be parsed: Unknown type name "WordLift's" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
184
	 */
185
	public function get_key() {
186
187
		return $this->get( 'wl_general_settings', self::KEY, '' );
188
	}
189
190
	/**
191
	 * Set WordLift's key.
192
	 *
193
	 * @since 3.9.0
194
	 *
195
	 * @param string $value WordLift's key.
196
	 */
197
	public function set_key( $value ) {
198
199
		$this->set( 'wl_general_settings', self::KEY, $value );
200
	}
201
202
	/**
203
	 * Get WordLift's configured language, by default 'en'.
204
	 *
205
	 * Note that WordLift's language is used when writing strings to the Linked Data dataset, not for the analysis.
206
	 *
207
	 * @since 3.9.0
208
	 *
209
	 * @return string WordLift's configured language code ('en' by default).
210
	 */
211
	public function get_language_code() {
212
213
		return $this->get( 'wl_general_settings', self::LANGUAGE, 'en' );
214
	}
215
216
	/**
217
	 * Set WordLift's language code, used when storing strings to the Linked Data dataset.
218
	 *
219
	 * @since 3.9.0
220
	 *
221
	 * @param string $value WordLift's language code.
222
	 */
223
	public function set_language_code( $value ) {
224
225
		$this->set( 'wl_general_settings', self::LANGUAGE, $value );
226
227
	}
228
229
	/**
230
	 * Get the publisher entity post id.
231
	 *
232
	 * The publisher entity post id points to an entity post which contains the data for the publisher used in schema.org
233
	 * Article markup.
234
	 *
235
	 * @since 3.9.0
236
	 *
237
	 * @return int|NULL The publisher entity post id or NULL if not set.
238
	 */
239
	public function get_publisher_id() {
240
241
		return $this->get( 'wl_general_settings', self::PUBLISHER_ID, NULL );
242
	}
243
244
	/**
245
	 * Set the publisher entity post id.
246
	 *
247
	 * @since 3.9.0
248
	 *
249
	 * @param int $value The publisher entity post id.
250
	 */
251
	public function set_publisher_id( $value ) {
252
253
		$this->set( 'wl_general_settings', self::PUBLISHER_ID, $value );
254
255
	}
256
257
}
258