Completed
Push — develop ( 986ace...13b240 )
by David
01:33 queued 13s
created
src/includes/class-wordlift-relation-service.php 1 patch
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 	protected function __construct() {
45 45
 		global $wpdb;
46 46
 
47
-		self::$log = Wordlift_Log_Service::get_logger( get_class() );
47
+		self::$log = Wordlift_Log_Service::get_logger(get_class());
48 48
 
49 49
 		// The relations table.
50 50
 		$this->relation_table = "{$wpdb->prefix}wl_relation_instances";
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 */
70 70
 	public static function get_instance() {
71 71
 
72
-		if ( ! isset( self::$instance ) ) {
72
+		if ( ! isset(self::$instance)) {
73 73
 			self::$instance = new self();
74 74
 		}
75 75
 
@@ -96,24 +96,24 @@  discard block
 block discarded – undo
96 96
 	 * @return array|object|null Database query results
97 97
 	 * @since 3.15.0
98 98
 	 */
99
-	public function get_article_subjects( $object_id, $fields = '*', $predicate = null, $status = null, $excludes = array(), $limit = null, $include = null, $order_by = null, $post_types = array(), $offset = null ) {
99
+	public function get_article_subjects($object_id, $fields = '*', $predicate = null, $status = null, $excludes = array(), $limit = null, $include = null, $order_by = null, $post_types = array(), $offset = null) {
100 100
 		global $wpdb;
101 101
 
102 102
 		// The output fields.
103
-		$actual_fields = self::fields( $fields );
103
+		$actual_fields = self::fields($fields);
104 104
 
105
-		self::$log->trace( 'Getting article subjects for object ' . implode( ', ', (array) $object_id ) . '...' );
105
+		self::$log->trace('Getting article subjects for object '.implode(', ', (array) $object_id).'...');
106 106
 
107
-		$objects = $this->article_id_to_entity_id( $object_id );
107
+		$objects = $this->article_id_to_entity_id($object_id);
108 108
 
109 109
 		// If there are no related objects, return an empty array.
110
-		if ( empty( $objects ) ) {
111
-			self::$log->debug( 'No entities found for object ' . implode( ', ', (array) $object_id ) . '.' );
110
+		if (empty($objects)) {
111
+			self::$log->debug('No entities found for object '.implode(', ', (array) $object_id).'.');
112 112
 
113 113
 			return array();
114 114
 		}
115 115
 
116
-		self::$log->debug( count( $objects ) . ' entity id(s) found for object ' . implode( ', ', (array) $object_id ) . '.' );
116
+		self::$log->debug(count($objects).' entity id(s) found for object '.implode(', ', (array) $object_id).'.');
117 117
 
118 118
 		$sql =
119 119
 			"
@@ -123,20 +123,20 @@  discard block
 block discarded – undo
123 123
 				ON p.id = r.subject_id
124 124
 			"
125 125
 			// Add the status clause.
126
-			. self::and_status( $status )
126
+			. self::and_status($status)
127 127
 			. self::inner_join_is_article()
128
-			. self::where_object_id( $objects )
128
+			. self::where_object_id($objects)
129 129
 			// Since `object_id` can be an article ID we need to exclude it from
130 130
 			// the results.
131
-			. self::and_article_not_in( array_merge( $excludes, (array) $object_id ) )
132
-			. self::and_article_in( $include )
133
-			. self::and_post_type_in( $post_types )
134
-			. self::and_predicate( $predicate )
135
-			. self::order_by( $order_by )
136
-			. self::limit( $limit )
137
-			. self::offset( $offset );
138
-
139
-		return '*' === $actual_fields ? $wpdb->get_results( $sql ) : $wpdb->get_col( $sql );  // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
131
+			. self::and_article_not_in(array_merge($excludes, (array) $object_id))
132
+			. self::and_article_in($include)
133
+			. self::and_post_type_in($post_types)
134
+			. self::and_predicate($predicate)
135
+			. self::order_by($order_by)
136
+			. self::limit($limit)
137
+			. self::offset($offset);
138
+
139
+		return '*' === $actual_fields ? $wpdb->get_results($sql) : $wpdb->get_col($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
140 140
 	}
141 141
 
142 142
 	/**
@@ -148,16 +148,16 @@  discard block
 block discarded – undo
148 148
 	 * @return string The `post_type IN` clause.
149 149
 	 * @since 3.15.3
150 150
 	 */
151
-	private static function and_post_type_in( $post_types = array() ) {
151
+	private static function and_post_type_in($post_types = array()) {
152 152
 
153
-		if ( array() === $post_types ) {
153
+		if (array() === $post_types) {
154 154
 			$post_types = Wordlift_Entity_Service::valid_entity_post_types();
155 155
 		}
156 156
 
157 157
 		return " AND p.post_type IN ( '"
158 158
 			. implode(
159 159
 				"','",
160
-				array_map( 'esc_sql', $post_types )
160
+				array_map('esc_sql', $post_types)
161 161
 			)
162 162
 			   . "' )";
163 163
 	}
@@ -170,9 +170,9 @@  discard block
 block discarded – undo
170 170
 	 * @return string The limit clause (empty if no limit has been specified).
171 171
 	 * @since 3.15.0
172 172
 	 */
173
-	private static function limit( $limit = null ) {
173
+	private static function limit($limit = null) {
174 174
 
175
-		if ( null === $limit ) {
175
+		if (null === $limit) {
176 176
 			return '';
177 177
 		}
178 178
 
@@ -187,9 +187,9 @@  discard block
 block discarded – undo
187 187
 	 * @return string The offset clause (empty if no offset has been specified).
188 188
 	 * @since 3.35.11
189 189
 	 */
190
-	private static function offset( $offset = null ) {
190
+	private static function offset($offset = null) {
191 191
 
192
-		if ( null === $offset || ! is_numeric( $offset ) ) {
192
+		if (null === $offset || ! is_numeric($offset)) {
193 193
 			return '';
194 194
 		}
195 195
 
@@ -201,14 +201,14 @@  discard block
 block discarded – undo
201 201
 	 *
202 202
 	 * @return string
203 203
 	 */
204
-	private static function order_by( $order_by ) {
205
-		if ( ! $order_by ) {
204
+	private static function order_by($order_by) {
205
+		if ( ! $order_by) {
206 206
 			return '';
207 207
 		}
208 208
 		$order_by         = (string) $order_by;
209
-		$order_by_clauses = array( 'DESC', 'ASC' );
209
+		$order_by_clauses = array('DESC', 'ASC');
210 210
 
211
-		if ( in_array( $order_by, $order_by_clauses, true ) ) {
211
+		if (in_array($order_by, $order_by_clauses, true)) {
212 212
 			return " ORDER BY p.post_modified {$order_by} ";
213 213
 		} else {
214 214
 			return ' ORDER BY p.post_modified DESC ';
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 	 * @return array An array of entities' ids.
225 225
 	 * @since 3.15.0
226 226
 	 */
227
-	private function article_id_to_entity_id( $object_id ) {
227
+	private function article_id_to_entity_id($object_id) {
228 228
 
229 229
 		$entity_service = Wordlift_Entity_Service::get_instance();
230 230
 
@@ -232,12 +232,12 @@  discard block
 block discarded – undo
232 232
 
233 233
 		return array_reduce(
234 234
 			(array) $object_id,
235
-			function ( $carry, $item ) use ( $entity_service, $relation_service ) {
236
-				if ( $entity_service->is_entity( $item ) ) {
237
-					return array_merge( $carry, (array) $item );
235
+			function($carry, $item) use ($entity_service, $relation_service) {
236
+				if ($entity_service->is_entity($item)) {
237
+					return array_merge($carry, (array) $item);
238 238
 				}
239 239
 
240
-				return array_merge( $carry, $relation_service->get_objects( $item, 'ids' ) );
240
+				return array_merge($carry, $relation_service->get_objects($item, 'ids'));
241 241
 			},
242 242
 			array()
243 243
 		);
@@ -252,15 +252,15 @@  discard block
 block discarded – undo
252 252
 	 * @return string The WHERE clause.
253 253
 	 * @since 3.15.0
254 254
 	 */
255
-	private static function where_object_id( $object_id ) {
255
+	private static function where_object_id($object_id) {
256 256
 
257
-		if ( empty( $object_id ) ) {
257
+		if (empty($object_id)) {
258 258
 			// self::$log->warn( sprintf( "%s `where_object_id` called with empty `object_id`.", var_export( debug_backtrace( false, 3 ), true ) ) );
259 259
 
260 260
 			return ' WHERE 1 = 1';
261 261
 		}
262 262
 
263
-		return ' WHERE r.object_id IN ( ' . implode( ',', wp_parse_id_list( (array) $object_id ) ) . ' )';
263
+		return ' WHERE r.object_id IN ( '.implode(',', wp_parse_id_list((array) $object_id)).' )';
264 264
 	}
265 265
 
266 266
 	/**
@@ -271,9 +271,9 @@  discard block
 block discarded – undo
271 271
 	 * @return string The exclude clause.
272 272
 	 * @since 3.15.0
273 273
 	 */
274
-	private static function and_article_not_in( $exclude ) {
274
+	private static function and_article_not_in($exclude) {
275 275
 
276
-		return ' AND NOT p.ID IN ( ' . implode( ',', wp_parse_id_list( (array) $exclude ) ) . ' )';
276
+		return ' AND NOT p.ID IN ( '.implode(',', wp_parse_id_list((array) $exclude)).' )';
277 277
 	}
278 278
 
279 279
 	/**
@@ -285,13 +285,13 @@  discard block
 block discarded – undo
285 285
 	 *                clause.
286 286
 	 * @since 3.15.0
287 287
 	 */
288
-	private static function and_article_in( $include = null ) {
288
+	private static function and_article_in($include = null) {
289 289
 
290
-		if ( null === $include ) {
290
+		if (null === $include) {
291 291
 			return '';
292 292
 		}
293 293
 
294
-		return ' AND p.ID IN ( ' . implode( ',', wp_parse_id_list( (array) $include ) ) . ' )';
294
+		return ' AND p.ID IN ( '.implode(',', wp_parse_id_list((array) $include)).' )';
295 295
 	}
296 296
 
297 297
 	/**
@@ -305,23 +305,23 @@  discard block
 block discarded – undo
305 305
 	 * @return array|object|null Database query results
306 306
 	 * @since 3.15.0
307 307
 	 */
308
-	public function get_non_article_subjects( $object_id, $fields = '*', $status = null ) {
308
+	public function get_non_article_subjects($object_id, $fields = '*', $status = null) {
309 309
 		global $wpdb;
310 310
 
311 311
 		// The output fields.
312
-		$actual_fields = self::fields( $fields );
312
+		$actual_fields = self::fields($fields);
313 313
 
314 314
 		$sql = $wpdb->prepare(
315 315
 			"SELECT p.$actual_fields FROM {$wpdb->prefix}wl_relation_instances r INNER JOIN $wpdb->posts p ON p.id = r.subject_id" // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
316 316
 			// Add the status clause.
317
-			. self::and_status( $status ) // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
317
+			. self::and_status($status) // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
318 318
 			. self::inner_join_is_not_article() // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
319 319
 			. ' WHERE r.object_id = %d '
320 320
 			. self::and_post_type_in(), // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
321 321
 			$object_id
322 322
 		);
323 323
 
324
-		return '*' === $actual_fields ? $wpdb->get_results( $sql ) : $wpdb->get_col( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
324
+		return '*' === $actual_fields ? $wpdb->get_results($sql) : $wpdb->get_col($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
325 325
 	}
326 326
 
327 327
 	/**
@@ -338,24 +338,24 @@  discard block
 block discarded – undo
338 338
 	 * @deprecated since it doesn't handle the subject_type nor the object_type
339 339
 	 * @since 3.15.0
340 340
 	 */
341
-	public function get_objects( $subject_id, $fields = '*', $predicate = null, $status = null ) {
341
+	public function get_objects($subject_id, $fields = '*', $predicate = null, $status = null) {
342 342
 		global $wpdb;
343 343
 
344 344
 		// The output fields.
345
-		$actual_fields = self::fields( $fields );
345
+		$actual_fields = self::fields($fields);
346 346
 
347 347
 		$sql = $wpdb->prepare(
348 348
 			"SELECT p.$actual_fields FROM {$this->relation_table} r INNER JOIN $wpdb->posts p ON p.id = r.object_id" // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
349 349
 			// Add the status clause.
350
-			. self::and_status( $status ) // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
350
+			. self::and_status($status) // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
351 351
 			. self::inner_join_is_not_article() // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
352 352
 			. ' WHERE r.subject_id = %d '
353 353
 			. self::and_post_type_in() // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
354
-			. self::and_predicate( $predicate ), // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
354
+			. self::and_predicate($predicate), // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
355 355
 			$subject_id
356 356
 		);
357 357
 
358
-		return '*' === $actual_fields ? $wpdb->get_results( $sql ) : $wpdb->get_col( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
358
+		return '*' === $actual_fields ? $wpdb->get_results($sql) : $wpdb->get_col($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
359 359
 	}
360 360
 
361 361
 	/**
@@ -366,13 +366,13 @@  discard block
 block discarded – undo
366 366
 	 * @return string An empty string if $status is null, otherwise the status clause.
367 367
 	 * @since 3.15.0
368 368
 	 */
369
-	private static function and_status( $status = null ) {
369
+	private static function and_status($status = null) {
370 370
 
371
-		if ( null === $status ) {
371
+		if (null === $status) {
372 372
 			return '';
373 373
 		}
374 374
 
375
-		return " AND p.post_status IN ('" . implode( "', '", array_map( 'esc_sql', (array) $status ) ) . "')";
375
+		return " AND p.post_status IN ('".implode("', '", array_map('esc_sql', (array) $status))."')";
376 376
 	}
377 377
 
378 378
 	/**
@@ -384,13 +384,13 @@  discard block
 block discarded – undo
384 384
 	 *                clause.
385 385
 	 * @since 3.15.0
386 386
 	 */
387
-	private static function and_predicate( $predicate = null ) {
387
+	private static function and_predicate($predicate = null) {
388 388
 
389
-		if ( null === $predicate ) {
389
+		if (null === $predicate) {
390 390
 			return '';
391 391
 		}
392 392
 
393
-		return " AND r.predicate IN ('" . implode( "', '", array_map( 'esc_sql', (array) $predicate ) ) . "')";
393
+		return " AND r.predicate IN ('".implode("', '", array_map('esc_sql', (array) $predicate))."')";
394 394
 	}
395 395
 
396 396
 	/**
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
 	 * @return string The `id` field if `ids` otherwise `*`.
402 402
 	 * @since 3.15.0
403 403
 	 */
404
-	private static function fields( $fields = '*' ) {
404
+	private static function fields($fields = '*') {
405 405
 
406 406
 		// The output fields.
407 407
 		return 'ids' === $fields ? 'id' : '*';
Please login to merge, or discard this patch.
src/shortcodes/class-wordlift-shortcode-rest.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	 */
26 26
 	private $args;
27 27
 
28
-	public function __construct( $endpoint, $args ) {
28
+	public function __construct($endpoint, $args) {
29 29
 
30 30
 		$scope          = $this;
31 31
 		$this->endpoint = $endpoint;
@@ -34,14 +34,14 @@  discard block
 block discarded – undo
34 34
 		// Register rest route with callback
35 35
 		add_action(
36 36
 			'rest_api_init',
37
-			function () use ( $scope ) {
37
+			function() use ($scope) {
38 38
 				register_rest_route(
39 39
 					WL_REST_ROUTE_DEFAULT_NAMESPACE,
40 40
 					$scope->endpoint,
41 41
 					array(
42 42
 						'methods'             => WP_REST_Server::READABLE,
43 43
 						'permission_callback' => '__return_true',
44
-						'callback'            => array( $scope, 'rest_callback' ),
44
+						'callback'            => array($scope, 'rest_callback'),
45 45
 						'args'                => $scope->args,
46 46
 					)
47 47
 				);
@@ -51,96 +51,96 @@  discard block
 block discarded – undo
51 51
 		// Optimizations: disable unneeded plugins on this specific REST call. WPSeo is slowing down the responses quite a bit.
52 52
 		add_action(
53 53
 			'plugins_loaded',
54
-			function () use ( $scope ) {
54
+			function() use ($scope) {
55 55
 
56
-				if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST || ! $scope->is_endpoint() ) {
56
+				if ( ! defined('REST_REQUEST') || ! REST_REQUEST || ! $scope->is_endpoint()) {
57 57
 					return;
58 58
 				}
59 59
 
60
-				remove_action( 'plugins_loaded', 'rocket_init' );
61
-				remove_action( 'plugins_loaded', 'wpseo_premium_init', 14 );
62
-				remove_action( 'plugins_loaded', 'wpseo_init', 14 );
60
+				remove_action('plugins_loaded', 'rocket_init');
61
+				remove_action('plugins_loaded', 'wpseo_premium_init', 14);
62
+				remove_action('plugins_loaded', 'wpseo_init', 14);
63 63
 			},
64 64
 			0
65 65
 		);
66 66
 
67 67
 		add_action(
68 68
 			'init',
69
-			function () use ( $scope ) {
69
+			function() use ($scope) {
70 70
 
71
-				if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST || ! $scope->is_endpoint() ) {
71
+				if ( ! defined('REST_REQUEST') || ! REST_REQUEST || ! $scope->is_endpoint()) {
72 72
 					return;
73 73
 				}
74 74
 
75
-				remove_action( 'init', 'wp_widgets_init', 1 );
76
-				remove_action( 'init', 'gglcptch_init' );
75
+				remove_action('init', 'wp_widgets_init', 1);
76
+				remove_action('init', 'gglcptch_init');
77 77
 			},
78 78
 			0
79 79
 		);
80 80
 
81 81
 	}
82 82
 
83
-	abstract public function get_data( $request );
83
+	abstract public function get_data($request);
84 84
 
85
-	public function rest_callback( WP_REST_Request $request ) {
85
+	public function rest_callback(WP_REST_Request $request) {
86 86
 
87 87
 		// Respond from origin if TTL is 0
88
-		if ( static::CACHE_TTL === 0 ) {
88
+		if (static::CACHE_TTL === 0) {
89 89
 
90
-			$data     = $this->get_data( $request );
91
-			$response = rest_ensure_response( $data );
92
-			if ( is_wp_error( $data ) ) {
90
+			$data     = $this->get_data($request);
91
+			$response = rest_ensure_response($data);
92
+			if (is_wp_error($data)) {
93 93
 				return $response;
94 94
 			}
95
-			$response->header( 'Access-Control-Allow-Origin', '*' );
96
-			$response->header( 'X-WordLift-Cache', 'MISS' );
95
+			$response->header('Access-Control-Allow-Origin', '*');
96
+			$response->header('X-WordLift-Cache', 'MISS');
97 97
 
98 98
 			return $response;
99 99
 		}
100 100
 
101 101
 		// Create the cache key.
102 102
 		$cache_key_params = $request->get_params();
103
-		unset( $cache_key_params['uniqid'] );
104
-		unset( $cache_key_params['rest_route'] );
105
-		$cache_key = array( 'request_params' => $cache_key_params );
103
+		unset($cache_key_params['uniqid']);
104
+		unset($cache_key_params['rest_route']);
105
+		$cache_key = array('request_params' => $cache_key_params);
106 106
 
107 107
 		// Create the TTL cache and try to get the results.
108
-		$cache         = new Ttl_Cache( $this->endpoint, static::CACHE_TTL );
109
-		$cache_results = $cache->get( $cache_key );
108
+		$cache         = new Ttl_Cache($this->endpoint, static::CACHE_TTL);
109
+		$cache_results = $cache->get($cache_key);
110 110
 
111
-		if ( isset( $cache_results ) ) {
111
+		if (isset($cache_results)) {
112 112
 
113
-			$response = rest_ensure_response( $cache_results );
114
-			$response->header( 'Access-Control-Allow-Origin', '*' );
115
-			$response->header( 'X-WordLift-Cache', 'HIT' );
113
+			$response = rest_ensure_response($cache_results);
114
+			$response->header('Access-Control-Allow-Origin', '*');
115
+			$response->header('X-WordLift-Cache', 'HIT');
116 116
 
117 117
 			return $response;
118 118
 		}
119 119
 
120
-		$data     = $this->get_data( $request );
121
-		$response = rest_ensure_response( $data );
122
-		if ( is_wp_error( $data ) ) {
120
+		$data     = $this->get_data($request);
121
+		$response = rest_ensure_response($data);
122
+		if (is_wp_error($data)) {
123 123
 			return $response;
124 124
 		}
125
-		$response->header( 'Access-Control-Allow-Origin', '*' );
126
-		$response->header( 'X-WordLift-Cache', 'MISS' );
125
+		$response->header('Access-Control-Allow-Origin', '*');
126
+		$response->header('X-WordLift-Cache', 'MISS');
127 127
 
128 128
 		// Put the result before sending the json to the client, since sending the json will terminate us.
129
-		$cache->put( $cache_key, $data );
129
+		$cache->put($cache_key, $data);
130 130
 
131 131
 		return $response;
132 132
 
133 133
 	}
134 134
 
135 135
 	private function is_endpoint() {
136
-		$compare_route = WL_REST_ROUTE_DEFAULT_NAMESPACE . $this->endpoint;
136
+		$compare_route = WL_REST_ROUTE_DEFAULT_NAMESPACE.$this->endpoint;
137 137
 
138 138
 		// Directly accessing $_SERVER['REQUEST_URI'] or $_GET['rest_route'] here as it's too early to use global $wp reliably
139 139
 
140
-		if ( isset( $_SERVER['REQUEST_URI'] ) && strpos( esc_url_raw( wp_unslash( (string) $_SERVER['REQUEST_URI'] ) ), $compare_route ) ) {
140
+		if (isset($_SERVER['REQUEST_URI']) && strpos(esc_url_raw(wp_unslash((string) $_SERVER['REQUEST_URI'])), $compare_route)) {
141 141
 			return true;
142 142
 		}
143
-		if ( ! empty( $_GET['rest_route'] ) && strpos( esc_url_raw( wp_unslash( (string) $_GET['rest_route'] ) ), $compare_route ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
143
+		if ( ! empty($_GET['rest_route']) && strpos(esc_url_raw(wp_unslash((string) $_GET['rest_route'])), $compare_route)) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
144 144
 			return true;
145 145
 		}
146 146
 
Please login to merge, or discard this patch.
src/classes/features/class-features-registry.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 	private static $instance = null;
13 13
 
14 14
 	public static function get_instance() {
15
-		if ( null === self::$instance ) {
15
+		if (null === self::$instance) {
16 16
 			self::$instance = new Features_Registry();
17 17
 		}
18 18
 
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	/**
23 23
 	 * @param $feature Feature
24 24
 	 */
25
-	public function register_feature( $feature ) {
25
+	public function register_feature($feature) {
26 26
 		$this->features[] = $feature;
27 27
 	}
28 28
 
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 	 * @param $default_value bool
32 32
 	 * @param $callback callable
33 33
 	 */
34
-	public function register_feature_from_slug( $feature_slug, $default_value, $callback ) {
34
+	public function register_feature_from_slug($feature_slug, $default_value, $callback) {
35 35
 		$this->features[] = new Feature(
36 36
 			$feature_slug,
37 37
 			$default_value,
@@ -40,13 +40,13 @@  discard block
 block discarded – undo
40 40
 	}
41 41
 
42 42
 	public function initialize_all_features() {
43
-		foreach ( $this->features as $feature ) {
43
+		foreach ($this->features as $feature) {
44 44
 			/**
45 45
 			 * @var $feature Feature
46 46
 			 */
47 47
 			$feature_slug = $feature->feature_slug;
48
-			if ( apply_filters( "wl_feature__enable__{$feature_slug}", $feature->default_value ) ) {
49
-				call_user_func( $feature->callback );
48
+			if (apply_filters("wl_feature__enable__{$feature_slug}", $feature->default_value)) {
49
+				call_user_func($feature->callback);
50 50
 			}
51 51
 		}
52 52
 	}
Please login to merge, or discard this patch.
src/classes/features/class-response-adapter.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 	public function __construct() {
10 10
 
11 11
 		// Filter responses from the API calls to update the enabled features.
12
-		add_filter( 'wl_api_service__response', array( $this, 'response' ), 10, 1 );
12
+		add_filter('wl_api_service__response', array($this, 'response'), 10, 1);
13 13
 
14 14
 		// Initialize from `$_ENV`: this is currently required for Unit Tests, since `tests/bootstrap.php` loads WordLift
15 15
 		// before it can actually query the enabled features via HTTP (mock), which would prevent files from being included.
@@ -19,34 +19,34 @@  discard block
 block discarded – undo
19 19
 		$this->register_filters();
20 20
 
21 21
 		// Hook to the updates to the features setting to refresh the features' filters.
22
-		add_action( 'update_option_' . self::WL_FEATURES, array( $this, 'register_filters' ), 10, 0 );
22
+		add_action('update_option_'.self::WL_FEATURES, array($this, 'register_filters'), 10, 0);
23 23
 
24 24
 	}
25 25
 
26
-	public function response( $response ) {
26
+	public function response($response) {
27 27
 
28
-		$headers = wp_remote_retrieve_headers( $response );
28
+		$headers = wp_remote_retrieve_headers($response);
29 29
 
30 30
 		// Bail out if the `wl1` header isn't defined.
31
-		if ( ! isset( $headers[ self::WL_1 ] ) ) {
31
+		if ( ! isset($headers[self::WL_1])) {
32 32
 			return $response;
33 33
 		}
34
-		$wl1_as_base64_string = $headers[ self::WL_1 ];
34
+		$wl1_as_base64_string = $headers[self::WL_1];
35 35
 		// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode
36
-		$wl1 = json_decode( base64_decode( $wl1_as_base64_string ), true );
36
+		$wl1 = json_decode(base64_decode($wl1_as_base64_string), true);
37 37
 
38 38
 		$updated_features = $wl1['features'];
39 39
 
40
-		$existing_features = get_option( self::WL_FEATURES, array() );
40
+		$existing_features = get_option(self::WL_FEATURES, array());
41 41
 
42 42
 		// Loop through updated features.
43
-		foreach ( $updated_features as $feature_slug => $new_value ) {
43
+		foreach ($updated_features as $feature_slug => $new_value) {
44 44
 
45 45
 			// We cant pass false because that indicates if the feature is active or not, null is used to represent the features which are
46 46
 			// not set before.
47
-			$old_value = array_key_exists( $feature_slug, $existing_features ) ? $existing_features[ $feature_slug ] : null;
47
+			$old_value = array_key_exists($feature_slug, $existing_features) ? $existing_features[$feature_slug] : null;
48 48
 
49
-			if ( $old_value !== $new_value ) {
49
+			if ($old_value !== $new_value) {
50 50
 				/**
51 51
 				 * @param $feature_slug string The feature slug.
52 52
 				 * @param $old_value null | boolean Null represents the feature flag was not set before.
@@ -56,13 +56,13 @@  discard block
 block discarded – undo
56 56
 				 * Hook : `wl_feature__change__{feature_slug}`
57 57
 				 * Action hook to be fired when there is a change in feature state.
58 58
 				 */
59
-				do_action( "wl_feature__change__$feature_slug", $new_value, $old_value, $feature_slug );
59
+				do_action("wl_feature__change__$feature_slug", $new_value, $old_value, $feature_slug);
60 60
 			}
61 61
 		}
62 62
 
63
-		if ( isset( $updated_features ) ) {
63
+		if (isset($updated_features)) {
64 64
 
65
-			if ( update_option( self::WL_FEATURES, (array) $updated_features, true ) ) {
65
+			if (update_option(self::WL_FEATURES, (array) $updated_features, true)) {
66 66
 				$this->register_filters();
67 67
 			}
68 68
 		}
@@ -75,13 +75,13 @@  discard block
 block discarded – undo
75 75
 	 */
76 76
 	public function register_filters() {
77 77
 
78
-		foreach ( (array) get_option( self::WL_FEATURES, array() ) as $name => $enabled ) {
78
+		foreach ((array) get_option(self::WL_FEATURES, array()) as $name => $enabled) {
79 79
 			// Remove previous filters.
80
-			remove_filter( "wl_feature__enable__{$name}", '__return_true' );
81
-			remove_filter( "wl_feature__enable__{$name}", '__return_false' );
80
+			remove_filter("wl_feature__enable__{$name}", '__return_true');
81
+			remove_filter("wl_feature__enable__{$name}", '__return_false');
82 82
 
83
-			$callback = ( $enabled ? '__return_true' : '__return_false' );
84
-			add_filter( "wl_feature__enable__{$name}", $callback );
83
+			$callback = ($enabled ? '__return_true' : '__return_false');
84
+			add_filter("wl_feature__enable__{$name}", $callback);
85 85
 		}
86 86
 
87 87
 	}
@@ -89,22 +89,22 @@  discard block
 block discarded – undo
89 89
 	private function init_from_env() {
90 90
 		$features = array_reduce(
91 91
 			array_filter(
92
-				array_keys( $_ENV ),
93
-				function ( $key ) {
94
-					return preg_match( '~^WL_FEATURES__.*~', $key );
92
+				array_keys($_ENV),
93
+				function($key) {
94
+					return preg_match('~^WL_FEATURES__.*~', $key);
95 95
 				}
96 96
 			),
97
-			function ( $features, $env ) {
98
-				$name              = strtolower( str_replace( '_', '-', substr( $env, strlen( 'WL_FEATURES__' ) ) ) );
99
-				$value             = wp_validate_boolean( getenv( $env ) );
100
-				$features[ $name ] = $value;
97
+			function($features, $env) {
98
+				$name              = strtolower(str_replace('_', '-', substr($env, strlen('WL_FEATURES__'))));
99
+				$value             = wp_validate_boolean(getenv($env));
100
+				$features[$name] = $value;
101 101
 
102 102
 				return $features;
103 103
 			},
104 104
 			array()
105 105
 		);
106 106
 
107
-		update_option( self::WL_FEATURES, (array) $features, true );
107
+		update_option(self::WL_FEATURES, (array) $features, true);
108 108
 	}
109 109
 
110 110
 }
Please login to merge, or discard this patch.
src/modules/include-exclude/includes/Configuration.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -10,8 +10,8 @@  discard block
 block discarded – undo
10 10
 	private $urls;
11 11
 
12 12
 	protected function __construct() {
13
-		$include_exclude_data = get_option( 'wl_exclude_include_urls_settings', array() );
14
-		$include_exclude      = isset( $include_exclude_data['include_exclude'] ) ? $include_exclude_data['include_exclude'] : 'exclude';
13
+		$include_exclude_data = get_option('wl_exclude_include_urls_settings', array());
14
+		$include_exclude      = isset($include_exclude_data['include_exclude']) ? $include_exclude_data['include_exclude'] : 'exclude';
15 15
 
16 16
 		$this->type = in_array(
17 17
 			$include_exclude,
@@ -22,11 +22,11 @@  discard block
 block discarded – undo
22 22
 			true
23 23
 		)
24 24
 			? $include_exclude : 'exclude';
25
-		$this->urls = isset( $include_exclude_data['urls'] ) ? $include_exclude_data['urls'] : '';
25
+		$this->urls = isset($include_exclude_data['urls']) ? $include_exclude_data['urls'] : '';
26 26
 	}
27 27
 
28 28
 	public static function get_instance() {
29
-		if ( ! isset( self::$instance ) ) {
29
+		if ( ! isset(self::$instance)) {
30 30
 			self::$instance = new self();
31 31
 		}
32 32
 
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	 * @return string
44 44
 	 */
45 45
 	public function get_default() {
46
-		return ( $this->type === 'exclude' ? 'include' : 'exclude' );
46
+		return ($this->type === 'exclude' ? 'include' : 'exclude');
47 47
 	}
48 48
 
49 49
 	public function get_urls() {
Please login to merge, or discard this patch.
src/modules/include-exclude/includes/Jsonld_Interceptor.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -7,39 +7,39 @@
 block discarded – undo
7 7
 	/** @var Plugin_Enabled $plugin_enabled */
8 8
 	private $plugin_enabled;
9 9
 
10
-	public function __construct( $plugin_enabled ) {
10
+	public function __construct($plugin_enabled) {
11 11
 		$this->plugin_enabled = $plugin_enabled;
12 12
 	}
13 13
 
14 14
 	public function register_hooks() {
15
-		add_filter( 'wl_after_get_jsonld', array( $this, 'after_get_jsonld' ) );
15
+		add_filter('wl_after_get_jsonld', array($this, 'after_get_jsonld'));
16 16
 	}
17 17
 
18
-	public function after_get_jsonld( $jsonld_arr ) {
18
+	public function after_get_jsonld($jsonld_arr) {
19 19
 		// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
20
-		@header( 'X-Wordlift-IncludeExclude-Stage-0: Filter Called with default ' . $this->plugin_enabled->get_configuration()->get_default() );
21
-		if ( ! is_array( $jsonld_arr ) || empty( $jsonld_arr ) || ! isset( $jsonld_arr[0]['url'] ) || null !== filter_input( INPUT_SERVER, 'HTTP_X_WORDLIFT_BYPASS_INCLUDE_EXCLUDE' ) ) {
20
+		@header('X-Wordlift-IncludeExclude-Stage-0: Filter Called with default '.$this->plugin_enabled->get_configuration()->get_default());
21
+		if ( ! is_array($jsonld_arr) || empty($jsonld_arr) || ! isset($jsonld_arr[0]['url']) || null !== filter_input(INPUT_SERVER, 'HTTP_X_WORDLIFT_BYPASS_INCLUDE_EXCLUDE')) {
22 22
 			// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
23
-			@header( 'X-Wordlift-IncludeExclude-Stage-1: Condition Not Matched' );
23
+			@header('X-Wordlift-IncludeExclude-Stage-1: Condition Not Matched');
24 24
 
25 25
 			return $jsonld_arr;
26 26
 		}
27 27
 
28 28
 		// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
29
-		@header( 'X-Wordlift-IncludeExclude-Stage-1: Condition Matched for ' . $jsonld_arr[0]['url'] );
29
+		@header('X-Wordlift-IncludeExclude-Stage-1: Condition Matched for '.$jsonld_arr[0]['url']);
30 30
 		// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
31
-		@header( 'X-Wordlift-IncludeExclude-Note: To bypass the Include/Exclude filter add a `x-wordlift-bypass-include-exclude` HTTP request header with any value.' );
31
+		@header('X-Wordlift-IncludeExclude-Note: To bypass the Include/Exclude filter add a `x-wordlift-bypass-include-exclude` HTTP request header with any value.');
32 32
 
33 33
 		// If the URLs are included then publish them.
34
-		if ( $this->plugin_enabled->are_urls_included( $jsonld_arr[0]['url'] ) ) {
34
+		if ($this->plugin_enabled->are_urls_included($jsonld_arr[0]['url'])) {
35 35
 			// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
36
-			@header( 'X-Wordlift-IncludeExclude-Stage-2: URL Included' );
36
+			@header('X-Wordlift-IncludeExclude-Stage-2: URL Included');
37 37
 
38 38
 			return $jsonld_arr;
39 39
 		}
40 40
 
41 41
 		// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
42
-		@header( 'X-Wordlift-IncludeExclude-Stage-2: URL Excluded' );
42
+		@header('X-Wordlift-IncludeExclude-Stage-2: URL Excluded');
43 43
 
44 44
 		return array();
45 45
 	}
Please login to merge, or discard this patch.