Completed
Pull Request — develop (#900)
by William
04:03
created
src/includes/class-wordlift-rating-service.php 3 patches
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -173,7 +173,6 @@  discard block
 block discarded – undo
173 173
 	 * @since 3.3.0
174 174
 	 *
175 175
 	 * @param int $post_id      The entity post id.
176
-	 * @param     $force_reload $warnings_needed If true, detailed warnings collection is provided with the rating obj.
177 176
 	 *
178 177
 	 * @return array An array representing the rating obj.
179 178
 	 */
@@ -332,7 +331,7 @@  discard block
 block discarded – undo
332 331
 	 *
333 332
 	 * @param int $score The rating score for a given entity.
334 333
 	 *
335
-	 * @return string The input HTML code.
334
+	 * @return double The input HTML code.
336 335
 	 */
337 336
 	public function convert_raw_score_to_percentage( $score ) {
338 337
 
Please login to merge, or discard this patch.
Indentation   +369 added lines, -369 removed lines patch added patch discarded remove patch
@@ -14,374 +14,374 @@
 block discarded – undo
14 14
  */
15 15
 class Wordlift_Rating_Service {
16 16
 
17
-	/**
18
-	 * Entity rating max.
19
-	 *
20
-	 * @since 3.3.0
21
-	 */
22
-	const RATING_MAX = 7;
23
-
24
-	/**
25
-	 * Entity rating score meta key.
26
-	 *
27
-	 * @since 3.3.0
28
-	 */
29
-	const RATING_RAW_SCORE_META_KEY = '_wl_entity_rating_raw_score';
30
-
31
-	/**
32
-	 * Entity rating warnings meta key.
33
-	 *
34
-	 * @since 3.3.0
35
-	 */
36
-	const RATING_WARNINGS_META_KEY = '_wl_entity_rating_warnings';
37
-
38
-	/**
39
-	 * Entity warning has related post identifier.
40
-	 *
41
-	 * @since 3.3.0
42
-	 */
43
-	const RATING_WARNING_HAS_RELATED_POSTS = 'There are no related posts for the current entity.';
44
-
45
-	/**
46
-	 * Entity warning has content post identifier.
47
-	 *
48
-	 * @since 3.3.0
49
-	 */
50
-	const RATING_WARNING_HAS_CONTENT_POST = 'This entity has not description.';
51
-
52
-	/**
53
-	 * Entity warning has related entities identifier.
54
-	 *
55
-	 * @since 3.3.0
56
-	 */
57
-	const RATING_WARNING_HAS_RELATED_ENTITIES = 'There are no related entities for the current entity.';
58
-
59
-	/**
60
-	 * Entity warning is published identifier.
61
-	 *
62
-	 * @since 3.3.0
63
-	 */
64
-	const RATING_WARNING_IS_PUBLISHED = 'This entity is not published. It will not appear within analysis results.';
65
-
66
-	/**
67
-	 * Entity warning has thumbnail identifier.
68
-	 *
69
-	 * @since 3.3.0
70
-	 */
71
-	const RATING_WARNING_HAS_THUMBNAIL = 'This entity has no featured image yet.';
72
-
73
-	/**
74
-	 * Entity warning has same as identifier.
75
-	 *
76
-	 * @since 3.3.0
77
-	 */
78
-	const RATING_WARNING_HAS_SAME_AS = 'There are no sameAs configured for this entity.';
79
-
80
-	/**
81
-	 * Entity warning has completed metadata identifier.
82
-	 *
83
-	 * @since 3.3.0
84
-	 */
85
-	const RATING_WARNING_HAS_COMPLETED_METADATA = 'Schema.org metadata for this entity are not completed.';
86
-
87
-	/**
88
-	 * A {@link Wordlift_Entity_Service} instance.
89
-	 *
90
-	 * @since  3.10.0
91
-	 * @access private
92
-	 * @var Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
93
-	 */
94
-	private $entity_service;
95
-
96
-	/**
97
-	 *  A {@link Wordlift_Entity_Type_Service} instance.
98
-	 *
99
-	 * @since  3.10.0
100
-	 * @access private
101
-	 * @var Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance.
102
-	 */
103
-	private $entity_type_service;
104
-
105
-	/**
106
-	 * The Notice service.
107
-	 *
108
-	 * @since  3.3.0
109
-	 * @access private
110
-	 * @var \Wordlift_Notice_Service $notice_service The Notice service.
111
-	 */
112
-	private $notice_service;
113
-
114
-	/**
115
-	 * A {@link Wordlift_Log_Service} instance.
116
-	 *
117
-	 * @since  3.10.0
118
-	 * @access private
119
-	 * @var Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
120
-	 */
121
-	private $log;
122
-
123
-	/**
124
-	 * Create a {@link Wordlift_Rating_Service} instance.
125
-	 *
126
-	 * @since 3.10.0
127
-	 *
128
-	 * @param \Wordlift_Entity_Service      $entity_service      A {@link Wordlift_Entity_Service} instance.
129
-	 * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance.
130
-	 * @param \Wordlift_Notice_Service      $notice_service      A {@link Wordlift_Notice_Service} instance.
131
-	 */
132
-	public function __construct( $entity_service, $entity_type_service, $notice_service ) {
133
-
134
-		$this->entity_service      = $entity_service;
135
-		$this->entity_type_service = $entity_type_service;
136
-		$this->notice_service      = $notice_service;
137
-
138
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Rating_Service' );
139
-
140
-	}
141
-
142
-	/**
143
-	 * Set rating for a given entity.
144
-	 *
145
-	 * @since 3.3.0
146
-	 *
147
-	 * @param int $post_id The entity post id.
148
-	 *
149
-	 * @return array An array representing the rating obj.
150
-	 */
151
-	public function set_rating_for( $post_id ) {
152
-
153
-		if ( ! $this->entity_service->is_entity( $post_id ) ) {
154
-			return;
155
-		}
156
-
157
-		// Calculate rating for the given post.
158
-		$rating = $this->calculate_rating_for( $post_id );
159
-
160
-		// Store the rating on db as post meta. Please notice that RATING_RAW_SCORE_META_KEY
161
-		// is saved on a different meta to allow score sorting. Both meta are managed as unique.
162
-		//
163
-		// See https://codex.wordpress.org/Function_Reference/update_post_meta
164
-		update_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, $rating['raw_score'] );
165
-		update_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, $rating['warnings'] );
166
-
167
-		$this->log->trace( sprintf( "Rating set for [ post_id :: $post_id ] [ rating :: %s ]", $rating['raw_score'] ) );
168
-
169
-		// Finally returns the rating
170
-		return $rating;
171
-	}
172
-
173
-
174
-	/**
175
-	 * Get or calculate rating for a given entity
176
-	 *
177
-	 * @since 3.3.0
178
-	 *
179
-	 * @param int $post_id      The entity post id.
180
-	 * @param     $force_reload $warnings_needed If true, detailed warnings collection is provided with the rating obj.
181
-	 *
182
-	 * @return array An array representing the rating obj.
183
-	 */
184
-	public function get_rating_for( $post_id, $force_reload = false ) {
185
-
186
-		// If forced reload is required or rating is missing.
187
-		if ( $force_reload ) {
188
-			$this->log->trace( "Force rating reload [ post_id :: $post_id ]" );
189
-
190
-			return $this->set_rating_for( $post_id );
191
-		}
192
-
193
-		$current_raw_score = get_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, true );
194
-
195
-		if ( ! is_numeric( $current_raw_score ) ) {
196
-			$this->log->trace( "Rating missing for [ post_id :: $post_id ] [ current_raw_score :: $current_raw_score ]" );
197
-
198
-			return $this->set_rating_for( $post_id );
199
-		}
200
-
201
-		$current_warnings = get_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, true );
202
-
203
-		// Finally return score and warnings
204
-		return array(
205
-			'raw_score'           => $current_raw_score,
206
-			'traffic_light_score' => $this->convert_raw_score_to_traffic_light( $current_raw_score ),
207
-			'percentage_score'    => $this->convert_raw_score_to_percentage( $current_raw_score ),
208
-			'warnings'            => $current_warnings,
209
-		);
210
-
211
-	}
212
-
213
-	/**
214
-	 * Calculate rating for a given entity.
215
-	 *
216
-	 * Rating depends from following criteria:
217
-	 *
218
-	 * 1. Is the current entity related to at least 1 post?
219
-	 * 2. Is the current entity content post not empty?
220
-	 * 3. Is the current entity related to at least 1 entity?
221
-	 * 4. Is the entity published?
222
-	 * 5. There is a a thumbnail associated to the entity?
223
-	 * 6. Has the entity a sameas defined?
224
-	 * 7. Are all schema.org required metadata compiled?
225
-	 *
226
-	 * Each positive check means +1 in terms of rating score.
227
-	 *
228
-	 * @since 3.3.0
229
-	 *
230
-	 * @param int $post_id The entity post id.
231
-	 *
232
-	 * @return array An array representing the rating obj.
233
-	 */
234
-	private function calculate_rating_for( $post_id ) {
235
-
236
-		// If it's not an entity, return.
237
-		if ( ! $this->entity_service->is_entity( $post_id ) ) {
238
-			return array();
239
-		}
240
-		// Retrieve the post object.
241
-		$post = get_post( $post_id );
242
-
243
-		// Rating value.
244
-		$score = 0;
245
-
246
-		// Store warning messages.
247
-		$warnings = array();
248
-
249
-		// Is the current entity related to at least 1 post?
250
-		( 0 < count( wl_core_get_related_post_ids( $post->ID ) ) ) ?
251
-			$score ++ :
252
-			array_push( $warnings, __( 'There are no related posts for the current entity.', 'wordlift' ) );
253
-
254
-		// Is the post content not empty?
255
-		( ! empty( $post->post_content ) ) ?
256
-			$score ++ :
257
-			array_push( $warnings, __( 'This entity has not description.', 'wordlift' ) );
258
-
259
-		// Is the current entity related to at least 1 entity?
260
-		// Was the current entity already disambiguated?
261
-		( 0 < count( wl_core_get_related_entity_ids( $post->ID ) ) ) ?
262
-			$score ++ :
263
-			array_push( $warnings, __( 'There are no related entities for the current entity.', 'wordlift' ) );
264
-
265
-		// Is the entity published?
266
-		( 'publish' === get_post_status( $post->ID ) ) ?
267
-			$score ++ :
268
-			array_push( $warnings, __( 'This entity is not published. It will not appear within analysis results.', 'wordlift' ) );
269
-
270
-		// Has a thumbnail?
271
-		( has_post_thumbnail( $post->ID ) ) ?
272
-			$score ++ :
273
-			array_push( $warnings, __( 'This entity has no featured image yet.', 'wordlift' ) );
274
-
275
-		// Get all post meta keys for the current post
276
-		global $wpdb;
277
-
278
-		$query = $wpdb->prepare(
279
-			"SELECT DISTINCT (meta_key) FROM $wpdb->postmeta  WHERE post_id = %d", $post->ID
280
-		);
281
-
282
-		// Check intersection between available meta keys and expected ones
283
-		// arrays to detect missing values.
284
-		$available_meta_keys = $wpdb->get_col( $query );
285
-
286
-		// If each expected key is contained in available keys array ...
287
-		( in_array( Wordlift_Schema_Service::FIELD_SAME_AS, $available_meta_keys ) ) ?
288
-			$score ++ :
289
-			array_push( $warnings, __( 'There are no sameAs configured for this entity.', 'wordlift' ) );
290
-
291
-		$schema = $this->entity_type_service->get( $post_id );
292
-
293
-		$expected_meta_keys = ( null === $schema['custom_fields'] ) ?
294
-			array() :
295
-			array_keys( $schema['custom_fields'] );
296
-
297
-		$intersection = array_intersect( $expected_meta_keys, $available_meta_keys );
298
-		// If each expected key is contained in available keys array ...
299
-		( count( $intersection ) === count( $expected_meta_keys ) ) ?
300
-			$score ++ :
301
-			array_push( $warnings, __( 'Schema.org metadata for this entity are not completed.', 'wordlift' ) );
302
-
303
-		// Finally return score and warnings
304
-		return array(
305
-			'raw_score'           => $score,
306
-			'traffic_light_score' => $this->convert_raw_score_to_traffic_light( $score ),
307
-			'percentage_score'    => $this->convert_raw_score_to_percentage( $score ),
308
-			'warnings'            => $warnings,
309
-		);
310
-
311
-	}
312
-
313
-	/**
314
-	 * Get as rating as input and convert in a traffic-light rating
315
-	 *
316
-	 * @since 3.3.0
317
-	 *
318
-	 * @param int $score The rating score for a given entity.
319
-	 *
320
-	 * @return string The input HTML code.
321
-	 */
322
-	private function convert_raw_score_to_traffic_light( $score ) {
323
-		// RATING_MAX : $score = 3 : x
324
-		// See http://php.net/manual/en/function.round.php
325
-		$rating = round( ( $score * 3 ) / self::RATING_MAX, 0, PHP_ROUND_HALF_UP );
326
-
327
-		// If rating is 0, return 1, otherwise return rating
328
-		return ( 0 == $rating ) ? 1 : $rating;
329
-
330
-	}
331
-
332
-	/**
333
-	 * Get as rating as input and convert in a traffic-light rating
334
-	 *
335
-	 * @since 3.3.0
336
-	 *
337
-	 * @param int $score The rating score for a given entity.
338
-	 *
339
-	 * @return string The input HTML code.
340
-	 */
341
-	public function convert_raw_score_to_percentage( $score ) {
342
-
343
-		// RATING_MAX : $score = 100 : x
344
-		return round( ( $score * 100 ) / self::RATING_MAX, 0, PHP_ROUND_HALF_UP );
345
-	}
346
-
347
-
348
-	/**
349
-	 * Add admin notices for the current entity depending on the current rating.
350
-	 *
351
-	 * @since 3.3.0
352
-	 */
353
-	public function in_admin_header() {
354
-
355
-		// Return safely if get_current_screen() is not defined (yet)
356
-		if ( false === function_exists( 'get_current_screen' ) ) {
357
-			return;
358
-		}
359
-
360
-		$screen = get_current_screen();
361
-		// If there is any valid screen nothing to do
362
-		if ( null === $screen ) {
363
-			return;
364
-		}
365
-
366
-		// If you're not in the entity post edit page, return.
367
-		if ( Wordlift_Entity_Service::TYPE_NAME !== $screen->id ) {
368
-			return;
369
-		}
370
-		// Retrieve the current global post
371
-		global $post;
372
-		// If it's not an entity, return.
373
-		if ( ! $this->entity_service->is_entity( $post->ID ) ) {
374
-			return;
375
-		}
376
-		// Retrieve an updated rating for the current entity
377
-		$rating = $this->get_rating_for( $post->ID, true );
378
-
379
-		// If there is at least 1 warning
380
-		if ( isset( $rating['warnings'] ) && 0 < count( $rating['warnings'] ) ) {
381
-			// TODO - Pass Wordlift_Notice_Service trough the service constructor
382
-			$this->notice_service->add_suggestion( $rating['warnings'] );
383
-		}
384
-
385
-	}
17
+    /**
18
+     * Entity rating max.
19
+     *
20
+     * @since 3.3.0
21
+     */
22
+    const RATING_MAX = 7;
23
+
24
+    /**
25
+     * Entity rating score meta key.
26
+     *
27
+     * @since 3.3.0
28
+     */
29
+    const RATING_RAW_SCORE_META_KEY = '_wl_entity_rating_raw_score';
30
+
31
+    /**
32
+     * Entity rating warnings meta key.
33
+     *
34
+     * @since 3.3.0
35
+     */
36
+    const RATING_WARNINGS_META_KEY = '_wl_entity_rating_warnings';
37
+
38
+    /**
39
+     * Entity warning has related post identifier.
40
+     *
41
+     * @since 3.3.0
42
+     */
43
+    const RATING_WARNING_HAS_RELATED_POSTS = 'There are no related posts for the current entity.';
44
+
45
+    /**
46
+     * Entity warning has content post identifier.
47
+     *
48
+     * @since 3.3.0
49
+     */
50
+    const RATING_WARNING_HAS_CONTENT_POST = 'This entity has not description.';
51
+
52
+    /**
53
+     * Entity warning has related entities identifier.
54
+     *
55
+     * @since 3.3.0
56
+     */
57
+    const RATING_WARNING_HAS_RELATED_ENTITIES = 'There are no related entities for the current entity.';
58
+
59
+    /**
60
+     * Entity warning is published identifier.
61
+     *
62
+     * @since 3.3.0
63
+     */
64
+    const RATING_WARNING_IS_PUBLISHED = 'This entity is not published. It will not appear within analysis results.';
65
+
66
+    /**
67
+     * Entity warning has thumbnail identifier.
68
+     *
69
+     * @since 3.3.0
70
+     */
71
+    const RATING_WARNING_HAS_THUMBNAIL = 'This entity has no featured image yet.';
72
+
73
+    /**
74
+     * Entity warning has same as identifier.
75
+     *
76
+     * @since 3.3.0
77
+     */
78
+    const RATING_WARNING_HAS_SAME_AS = 'There are no sameAs configured for this entity.';
79
+
80
+    /**
81
+     * Entity warning has completed metadata identifier.
82
+     *
83
+     * @since 3.3.0
84
+     */
85
+    const RATING_WARNING_HAS_COMPLETED_METADATA = 'Schema.org metadata for this entity are not completed.';
86
+
87
+    /**
88
+     * A {@link Wordlift_Entity_Service} instance.
89
+     *
90
+     * @since  3.10.0
91
+     * @access private
92
+     * @var Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
93
+     */
94
+    private $entity_service;
95
+
96
+    /**
97
+     *  A {@link Wordlift_Entity_Type_Service} instance.
98
+     *
99
+     * @since  3.10.0
100
+     * @access private
101
+     * @var Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance.
102
+     */
103
+    private $entity_type_service;
104
+
105
+    /**
106
+     * The Notice service.
107
+     *
108
+     * @since  3.3.0
109
+     * @access private
110
+     * @var \Wordlift_Notice_Service $notice_service The Notice service.
111
+     */
112
+    private $notice_service;
113
+
114
+    /**
115
+     * A {@link Wordlift_Log_Service} instance.
116
+     *
117
+     * @since  3.10.0
118
+     * @access private
119
+     * @var Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
120
+     */
121
+    private $log;
122
+
123
+    /**
124
+     * Create a {@link Wordlift_Rating_Service} instance.
125
+     *
126
+     * @since 3.10.0
127
+     *
128
+     * @param \Wordlift_Entity_Service      $entity_service      A {@link Wordlift_Entity_Service} instance.
129
+     * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance.
130
+     * @param \Wordlift_Notice_Service      $notice_service      A {@link Wordlift_Notice_Service} instance.
131
+     */
132
+    public function __construct( $entity_service, $entity_type_service, $notice_service ) {
133
+
134
+        $this->entity_service      = $entity_service;
135
+        $this->entity_type_service = $entity_type_service;
136
+        $this->notice_service      = $notice_service;
137
+
138
+        $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Rating_Service' );
139
+
140
+    }
141
+
142
+    /**
143
+     * Set rating for a given entity.
144
+     *
145
+     * @since 3.3.0
146
+     *
147
+     * @param int $post_id The entity post id.
148
+     *
149
+     * @return array An array representing the rating obj.
150
+     */
151
+    public function set_rating_for( $post_id ) {
152
+
153
+        if ( ! $this->entity_service->is_entity( $post_id ) ) {
154
+            return;
155
+        }
156
+
157
+        // Calculate rating for the given post.
158
+        $rating = $this->calculate_rating_for( $post_id );
159
+
160
+        // Store the rating on db as post meta. Please notice that RATING_RAW_SCORE_META_KEY
161
+        // is saved on a different meta to allow score sorting. Both meta are managed as unique.
162
+        //
163
+        // See https://codex.wordpress.org/Function_Reference/update_post_meta
164
+        update_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, $rating['raw_score'] );
165
+        update_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, $rating['warnings'] );
166
+
167
+        $this->log->trace( sprintf( "Rating set for [ post_id :: $post_id ] [ rating :: %s ]", $rating['raw_score'] ) );
168
+
169
+        // Finally returns the rating
170
+        return $rating;
171
+    }
172
+
173
+
174
+    /**
175
+     * Get or calculate rating for a given entity
176
+     *
177
+     * @since 3.3.0
178
+     *
179
+     * @param int $post_id      The entity post id.
180
+     * @param     $force_reload $warnings_needed If true, detailed warnings collection is provided with the rating obj.
181
+     *
182
+     * @return array An array representing the rating obj.
183
+     */
184
+    public function get_rating_for( $post_id, $force_reload = false ) {
185
+
186
+        // If forced reload is required or rating is missing.
187
+        if ( $force_reload ) {
188
+            $this->log->trace( "Force rating reload [ post_id :: $post_id ]" );
189
+
190
+            return $this->set_rating_for( $post_id );
191
+        }
192
+
193
+        $current_raw_score = get_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, true );
194
+
195
+        if ( ! is_numeric( $current_raw_score ) ) {
196
+            $this->log->trace( "Rating missing for [ post_id :: $post_id ] [ current_raw_score :: $current_raw_score ]" );
197
+
198
+            return $this->set_rating_for( $post_id );
199
+        }
200
+
201
+        $current_warnings = get_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, true );
202
+
203
+        // Finally return score and warnings
204
+        return array(
205
+            'raw_score'           => $current_raw_score,
206
+            'traffic_light_score' => $this->convert_raw_score_to_traffic_light( $current_raw_score ),
207
+            'percentage_score'    => $this->convert_raw_score_to_percentage( $current_raw_score ),
208
+            'warnings'            => $current_warnings,
209
+        );
210
+
211
+    }
212
+
213
+    /**
214
+     * Calculate rating for a given entity.
215
+     *
216
+     * Rating depends from following criteria:
217
+     *
218
+     * 1. Is the current entity related to at least 1 post?
219
+     * 2. Is the current entity content post not empty?
220
+     * 3. Is the current entity related to at least 1 entity?
221
+     * 4. Is the entity published?
222
+     * 5. There is a a thumbnail associated to the entity?
223
+     * 6. Has the entity a sameas defined?
224
+     * 7. Are all schema.org required metadata compiled?
225
+     *
226
+     * Each positive check means +1 in terms of rating score.
227
+     *
228
+     * @since 3.3.0
229
+     *
230
+     * @param int $post_id The entity post id.
231
+     *
232
+     * @return array An array representing the rating obj.
233
+     */
234
+    private function calculate_rating_for( $post_id ) {
235
+
236
+        // If it's not an entity, return.
237
+        if ( ! $this->entity_service->is_entity( $post_id ) ) {
238
+            return array();
239
+        }
240
+        // Retrieve the post object.
241
+        $post = get_post( $post_id );
242
+
243
+        // Rating value.
244
+        $score = 0;
245
+
246
+        // Store warning messages.
247
+        $warnings = array();
248
+
249
+        // Is the current entity related to at least 1 post?
250
+        ( 0 < count( wl_core_get_related_post_ids( $post->ID ) ) ) ?
251
+            $score ++ :
252
+            array_push( $warnings, __( 'There are no related posts for the current entity.', 'wordlift' ) );
253
+
254
+        // Is the post content not empty?
255
+        ( ! empty( $post->post_content ) ) ?
256
+            $score ++ :
257
+            array_push( $warnings, __( 'This entity has not description.', 'wordlift' ) );
258
+
259
+        // Is the current entity related to at least 1 entity?
260
+        // Was the current entity already disambiguated?
261
+        ( 0 < count( wl_core_get_related_entity_ids( $post->ID ) ) ) ?
262
+            $score ++ :
263
+            array_push( $warnings, __( 'There are no related entities for the current entity.', 'wordlift' ) );
264
+
265
+        // Is the entity published?
266
+        ( 'publish' === get_post_status( $post->ID ) ) ?
267
+            $score ++ :
268
+            array_push( $warnings, __( 'This entity is not published. It will not appear within analysis results.', 'wordlift' ) );
269
+
270
+        // Has a thumbnail?
271
+        ( has_post_thumbnail( $post->ID ) ) ?
272
+            $score ++ :
273
+            array_push( $warnings, __( 'This entity has no featured image yet.', 'wordlift' ) );
274
+
275
+        // Get all post meta keys for the current post
276
+        global $wpdb;
277
+
278
+        $query = $wpdb->prepare(
279
+            "SELECT DISTINCT (meta_key) FROM $wpdb->postmeta  WHERE post_id = %d", $post->ID
280
+        );
281
+
282
+        // Check intersection between available meta keys and expected ones
283
+        // arrays to detect missing values.
284
+        $available_meta_keys = $wpdb->get_col( $query );
285
+
286
+        // If each expected key is contained in available keys array ...
287
+        ( in_array( Wordlift_Schema_Service::FIELD_SAME_AS, $available_meta_keys ) ) ?
288
+            $score ++ :
289
+            array_push( $warnings, __( 'There are no sameAs configured for this entity.', 'wordlift' ) );
290
+
291
+        $schema = $this->entity_type_service->get( $post_id );
292
+
293
+        $expected_meta_keys = ( null === $schema['custom_fields'] ) ?
294
+            array() :
295
+            array_keys( $schema['custom_fields'] );
296
+
297
+        $intersection = array_intersect( $expected_meta_keys, $available_meta_keys );
298
+        // If each expected key is contained in available keys array ...
299
+        ( count( $intersection ) === count( $expected_meta_keys ) ) ?
300
+            $score ++ :
301
+            array_push( $warnings, __( 'Schema.org metadata for this entity are not completed.', 'wordlift' ) );
302
+
303
+        // Finally return score and warnings
304
+        return array(
305
+            'raw_score'           => $score,
306
+            'traffic_light_score' => $this->convert_raw_score_to_traffic_light( $score ),
307
+            'percentage_score'    => $this->convert_raw_score_to_percentage( $score ),
308
+            'warnings'            => $warnings,
309
+        );
310
+
311
+    }
312
+
313
+    /**
314
+     * Get as rating as input and convert in a traffic-light rating
315
+     *
316
+     * @since 3.3.0
317
+     *
318
+     * @param int $score The rating score for a given entity.
319
+     *
320
+     * @return string The input HTML code.
321
+     */
322
+    private function convert_raw_score_to_traffic_light( $score ) {
323
+        // RATING_MAX : $score = 3 : x
324
+        // See http://php.net/manual/en/function.round.php
325
+        $rating = round( ( $score * 3 ) / self::RATING_MAX, 0, PHP_ROUND_HALF_UP );
326
+
327
+        // If rating is 0, return 1, otherwise return rating
328
+        return ( 0 == $rating ) ? 1 : $rating;
329
+
330
+    }
331
+
332
+    /**
333
+     * Get as rating as input and convert in a traffic-light rating
334
+     *
335
+     * @since 3.3.0
336
+     *
337
+     * @param int $score The rating score for a given entity.
338
+     *
339
+     * @return string The input HTML code.
340
+     */
341
+    public function convert_raw_score_to_percentage( $score ) {
342
+
343
+        // RATING_MAX : $score = 100 : x
344
+        return round( ( $score * 100 ) / self::RATING_MAX, 0, PHP_ROUND_HALF_UP );
345
+    }
346
+
347
+
348
+    /**
349
+     * Add admin notices for the current entity depending on the current rating.
350
+     *
351
+     * @since 3.3.0
352
+     */
353
+    public function in_admin_header() {
354
+
355
+        // Return safely if get_current_screen() is not defined (yet)
356
+        if ( false === function_exists( 'get_current_screen' ) ) {
357
+            return;
358
+        }
359
+
360
+        $screen = get_current_screen();
361
+        // If there is any valid screen nothing to do
362
+        if ( null === $screen ) {
363
+            return;
364
+        }
365
+
366
+        // If you're not in the entity post edit page, return.
367
+        if ( Wordlift_Entity_Service::TYPE_NAME !== $screen->id ) {
368
+            return;
369
+        }
370
+        // Retrieve the current global post
371
+        global $post;
372
+        // If it's not an entity, return.
373
+        if ( ! $this->entity_service->is_entity( $post->ID ) ) {
374
+            return;
375
+        }
376
+        // Retrieve an updated rating for the current entity
377
+        $rating = $this->get_rating_for( $post->ID, true );
378
+
379
+        // If there is at least 1 warning
380
+        if ( isset( $rating['warnings'] ) && 0 < count( $rating['warnings'] ) ) {
381
+            // TODO - Pass Wordlift_Notice_Service trough the service constructor
382
+            $this->notice_service->add_suggestion( $rating['warnings'] );
383
+        }
384
+
385
+    }
386 386
 
387 387
 }
Please login to merge, or discard this patch.
Spacing   +55 added lines, -63 removed lines patch added patch discarded remove patch
@@ -129,13 +129,13 @@  discard block
 block discarded – undo
129 129
 	 * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance.
130 130
 	 * @param \Wordlift_Notice_Service      $notice_service      A {@link Wordlift_Notice_Service} instance.
131 131
 	 */
132
-	public function __construct( $entity_service, $entity_type_service, $notice_service ) {
132
+	public function __construct($entity_service, $entity_type_service, $notice_service) {
133 133
 
134 134
 		$this->entity_service      = $entity_service;
135 135
 		$this->entity_type_service = $entity_type_service;
136 136
 		$this->notice_service      = $notice_service;
137 137
 
138
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Rating_Service' );
138
+		$this->log = Wordlift_Log_Service::get_logger('Wordlift_Rating_Service');
139 139
 
140 140
 	}
141 141
 
@@ -148,23 +148,23 @@  discard block
 block discarded – undo
148 148
 	 *
149 149
 	 * @return array An array representing the rating obj.
150 150
 	 */
151
-	public function set_rating_for( $post_id ) {
151
+	public function set_rating_for($post_id) {
152 152
 
153
-		if ( ! $this->entity_service->is_entity( $post_id ) ) {
153
+		if ( ! $this->entity_service->is_entity($post_id)) {
154 154
 			return;
155 155
 		}
156 156
 
157 157
 		// Calculate rating for the given post.
158
-		$rating = $this->calculate_rating_for( $post_id );
158
+		$rating = $this->calculate_rating_for($post_id);
159 159
 
160 160
 		// Store the rating on db as post meta. Please notice that RATING_RAW_SCORE_META_KEY
161 161
 		// is saved on a different meta to allow score sorting. Both meta are managed as unique.
162 162
 		//
163 163
 		// See https://codex.wordpress.org/Function_Reference/update_post_meta
164
-		update_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, $rating['raw_score'] );
165
-		update_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, $rating['warnings'] );
164
+		update_post_meta($post_id, self::RATING_RAW_SCORE_META_KEY, $rating['raw_score']);
165
+		update_post_meta($post_id, self::RATING_WARNINGS_META_KEY, $rating['warnings']);
166 166
 
167
-		$this->log->trace( sprintf( "Rating set for [ post_id :: $post_id ] [ rating :: %s ]", $rating['raw_score'] ) );
167
+		$this->log->trace(sprintf("Rating set for [ post_id :: $post_id ] [ rating :: %s ]", $rating['raw_score']));
168 168
 
169 169
 		// Finally returns the rating
170 170
 		return $rating;
@@ -181,30 +181,30 @@  discard block
 block discarded – undo
181 181
 	 *
182 182
 	 * @return array An array representing the rating obj.
183 183
 	 */
184
-	public function get_rating_for( $post_id, $force_reload = false ) {
184
+	public function get_rating_for($post_id, $force_reload = false) {
185 185
 
186 186
 		// If forced reload is required or rating is missing.
187
-		if ( $force_reload ) {
188
-			$this->log->trace( "Force rating reload [ post_id :: $post_id ]" );
187
+		if ($force_reload) {
188
+			$this->log->trace("Force rating reload [ post_id :: $post_id ]");
189 189
 
190
-			return $this->set_rating_for( $post_id );
190
+			return $this->set_rating_for($post_id);
191 191
 		}
192 192
 
193
-		$current_raw_score = get_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, true );
193
+		$current_raw_score = get_post_meta($post_id, self::RATING_RAW_SCORE_META_KEY, true);
194 194
 
195
-		if ( ! is_numeric( $current_raw_score ) ) {
196
-			$this->log->trace( "Rating missing for [ post_id :: $post_id ] [ current_raw_score :: $current_raw_score ]" );
195
+		if ( ! is_numeric($current_raw_score)) {
196
+			$this->log->trace("Rating missing for [ post_id :: $post_id ] [ current_raw_score :: $current_raw_score ]");
197 197
 
198
-			return $this->set_rating_for( $post_id );
198
+			return $this->set_rating_for($post_id);
199 199
 		}
200 200
 
201
-		$current_warnings = get_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, true );
201
+		$current_warnings = get_post_meta($post_id, self::RATING_WARNINGS_META_KEY, true);
202 202
 
203 203
 		// Finally return score and warnings
204 204
 		return array(
205 205
 			'raw_score'           => $current_raw_score,
206
-			'traffic_light_score' => $this->convert_raw_score_to_traffic_light( $current_raw_score ),
207
-			'percentage_score'    => $this->convert_raw_score_to_percentage( $current_raw_score ),
206
+			'traffic_light_score' => $this->convert_raw_score_to_traffic_light($current_raw_score),
207
+			'percentage_score'    => $this->convert_raw_score_to_percentage($current_raw_score),
208 208
 			'warnings'            => $current_warnings,
209 209
 		);
210 210
 
@@ -231,14 +231,14 @@  discard block
 block discarded – undo
231 231
 	 *
232 232
 	 * @return array An array representing the rating obj.
233 233
 	 */
234
-	private function calculate_rating_for( $post_id ) {
234
+	private function calculate_rating_for($post_id) {
235 235
 
236 236
 		// If it's not an entity, return.
237
-		if ( ! $this->entity_service->is_entity( $post_id ) ) {
237
+		if ( ! $this->entity_service->is_entity($post_id)) {
238 238
 			return array();
239 239
 		}
240 240
 		// Retrieve the post object.
241
-		$post = get_post( $post_id );
241
+		$post = get_post($post_id);
242 242
 
243 243
 		// Rating value.
244 244
 		$score = 0;
@@ -247,30 +247,25 @@  discard block
 block discarded – undo
247 247
 		$warnings = array();
248 248
 
249 249
 		// Is the current entity related to at least 1 post?
250
-		( 0 < count( wl_core_get_related_post_ids( $post->ID ) ) ) ?
251
-			$score ++ :
252
-			array_push( $warnings, __( 'There are no related posts for the current entity.', 'wordlift' ) );
250
+		(0 < count(wl_core_get_related_post_ids($post->ID))) ?
251
+			$score++ : array_push($warnings, __('There are no related posts for the current entity.', 'wordlift'));
253 252
 
254 253
 		// Is the post content not empty?
255
-		( ! empty( $post->post_content ) ) ?
256
-			$score ++ :
257
-			array_push( $warnings, __( 'This entity has not description.', 'wordlift' ) );
254
+		( ! empty($post->post_content)) ?
255
+			$score++ : array_push($warnings, __('This entity has not description.', 'wordlift'));
258 256
 
259 257
 		// Is the current entity related to at least 1 entity?
260 258
 		// Was the current entity already disambiguated?
261
-		( 0 < count( wl_core_get_related_entity_ids( $post->ID ) ) ) ?
262
-			$score ++ :
263
-			array_push( $warnings, __( 'There are no related entities for the current entity.', 'wordlift' ) );
259
+		(0 < count(wl_core_get_related_entity_ids($post->ID))) ?
260
+			$score++ : array_push($warnings, __('There are no related entities for the current entity.', 'wordlift'));
264 261
 
265 262
 		// Is the entity published?
266
-		( 'publish' === get_post_status( $post->ID ) ) ?
267
-			$score ++ :
268
-			array_push( $warnings, __( 'This entity is not published. It will not appear within analysis results.', 'wordlift' ) );
263
+		('publish' === get_post_status($post->ID)) ?
264
+			$score++ : array_push($warnings, __('This entity is not published. It will not appear within analysis results.', 'wordlift'));
269 265
 
270 266
 		// Has a thumbnail?
271
-		( has_post_thumbnail( $post->ID ) ) ?
272
-			$score ++ :
273
-			array_push( $warnings, __( 'This entity has no featured image yet.', 'wordlift' ) );
267
+		(has_post_thumbnail($post->ID)) ?
268
+			$score++ : array_push($warnings, __('This entity has no featured image yet.', 'wordlift'));
274 269
 
275 270
 		// Get all post meta keys for the current post
276 271
 		global $wpdb;
@@ -281,30 +276,27 @@  discard block
 block discarded – undo
281 276
 
282 277
 		// Check intersection between available meta keys and expected ones
283 278
 		// arrays to detect missing values.
284
-		$available_meta_keys = $wpdb->get_col( $query );
279
+		$available_meta_keys = $wpdb->get_col($query);
285 280
 
286 281
 		// If each expected key is contained in available keys array ...
287
-		( in_array( Wordlift_Schema_Service::FIELD_SAME_AS, $available_meta_keys ) ) ?
288
-			$score ++ :
289
-			array_push( $warnings, __( 'There are no sameAs configured for this entity.', 'wordlift' ) );
282
+		(in_array(Wordlift_Schema_Service::FIELD_SAME_AS, $available_meta_keys)) ?
283
+			$score++ : array_push($warnings, __('There are no sameAs configured for this entity.', 'wordlift'));
290 284
 
291
-		$schema = $this->entity_type_service->get( $post_id );
285
+		$schema = $this->entity_type_service->get($post_id);
292 286
 
293
-		$expected_meta_keys = ( null === $schema['custom_fields'] ) ?
294
-			array() :
295
-			array_keys( $schema['custom_fields'] );
287
+		$expected_meta_keys = (null === $schema['custom_fields']) ?
288
+			array() : array_keys($schema['custom_fields']);
296 289
 
297
-		$intersection = array_intersect( $expected_meta_keys, $available_meta_keys );
290
+		$intersection = array_intersect($expected_meta_keys, $available_meta_keys);
298 291
 		// If each expected key is contained in available keys array ...
299
-		( count( $intersection ) === count( $expected_meta_keys ) ) ?
300
-			$score ++ :
301
-			array_push( $warnings, __( 'Schema.org metadata for this entity are not completed.', 'wordlift' ) );
292
+		(count($intersection) === count($expected_meta_keys)) ?
293
+			$score++ : array_push($warnings, __('Schema.org metadata for this entity are not completed.', 'wordlift'));
302 294
 
303 295
 		// Finally return score and warnings
304 296
 		return array(
305 297
 			'raw_score'           => $score,
306
-			'traffic_light_score' => $this->convert_raw_score_to_traffic_light( $score ),
307
-			'percentage_score'    => $this->convert_raw_score_to_percentage( $score ),
298
+			'traffic_light_score' => $this->convert_raw_score_to_traffic_light($score),
299
+			'percentage_score'    => $this->convert_raw_score_to_percentage($score),
308 300
 			'warnings'            => $warnings,
309 301
 		);
310 302
 
@@ -319,13 +311,13 @@  discard block
 block discarded – undo
319 311
 	 *
320 312
 	 * @return string The input HTML code.
321 313
 	 */
322
-	private function convert_raw_score_to_traffic_light( $score ) {
314
+	private function convert_raw_score_to_traffic_light($score) {
323 315
 		// RATING_MAX : $score = 3 : x
324 316
 		// See http://php.net/manual/en/function.round.php
325
-		$rating = round( ( $score * 3 ) / self::RATING_MAX, 0, PHP_ROUND_HALF_UP );
317
+		$rating = round(($score * 3) / self::RATING_MAX, 0, PHP_ROUND_HALF_UP);
326 318
 
327 319
 		// If rating is 0, return 1, otherwise return rating
328
-		return ( 0 == $rating ) ? 1 : $rating;
320
+		return (0 == $rating) ? 1 : $rating;
329 321
 
330 322
 	}
331 323
 
@@ -338,10 +330,10 @@  discard block
 block discarded – undo
338 330
 	 *
339 331
 	 * @return string The input HTML code.
340 332
 	 */
341
-	public function convert_raw_score_to_percentage( $score ) {
333
+	public function convert_raw_score_to_percentage($score) {
342 334
 
343 335
 		// RATING_MAX : $score = 100 : x
344
-		return round( ( $score * 100 ) / self::RATING_MAX, 0, PHP_ROUND_HALF_UP );
336
+		return round(($score * 100) / self::RATING_MAX, 0, PHP_ROUND_HALF_UP);
345 337
 	}
346 338
 
347 339
 
@@ -353,33 +345,33 @@  discard block
 block discarded – undo
353 345
 	public function in_admin_header() {
354 346
 
355 347
 		// Return safely if get_current_screen() is not defined (yet)
356
-		if ( false === function_exists( 'get_current_screen' ) ) {
348
+		if (false === function_exists('get_current_screen')) {
357 349
 			return;
358 350
 		}
359 351
 
360 352
 		$screen = get_current_screen();
361 353
 		// If there is any valid screen nothing to do
362
-		if ( null === $screen ) {
354
+		if (null === $screen) {
363 355
 			return;
364 356
 		}
365 357
 
366 358
 		// If you're not in the entity post edit page, return.
367
-		if ( Wordlift_Entity_Service::TYPE_NAME !== $screen->id ) {
359
+		if (Wordlift_Entity_Service::TYPE_NAME !== $screen->id) {
368 360
 			return;
369 361
 		}
370 362
 		// Retrieve the current global post
371 363
 		global $post;
372 364
 		// If it's not an entity, return.
373
-		if ( ! $this->entity_service->is_entity( $post->ID ) ) {
365
+		if ( ! $this->entity_service->is_entity($post->ID)) {
374 366
 			return;
375 367
 		}
376 368
 		// Retrieve an updated rating for the current entity
377
-		$rating = $this->get_rating_for( $post->ID, true );
369
+		$rating = $this->get_rating_for($post->ID, true);
378 370
 
379 371
 		// If there is at least 1 warning
380
-		if ( isset( $rating['warnings'] ) && 0 < count( $rating['warnings'] ) ) {
372
+		if (isset($rating['warnings']) && 0 < count($rating['warnings'])) {
381 373
 			// TODO - Pass Wordlift_Notice_Service trough the service constructor
382
-			$this->notice_service->add_suggestion( $rating['warnings'] );
374
+			$this->notice_service->add_suggestion($rating['warnings']);
383 375
 		}
384 376
 
385 377
 	}
Please login to merge, or discard this patch.
src/includes/properties/class-wordlift-property-entity-reference.php 2 patches
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -16,61 +16,61 @@
 block discarded – undo
16 16
  */
17 17
 class Wordlift_Property_Entity_Reference {
18 18
 
19
-	/**
20
-	 * The URL associated with this entity reference.
21
-	 *
22
-	 * @since  3.8.0
23
-	 * @access private
24
-	 * @var string $url The URL associated with the entity reference.
25
-	 */
26
-	private $url;
19
+    /**
20
+     * The URL associated with this entity reference.
21
+     *
22
+     * @since  3.8.0
23
+     * @access private
24
+     * @var string $url The URL associated with the entity reference.
25
+     */
26
+    private $url;
27 27
 
28
-	/**
29
-	 * The entity post id.
30
-	 *
31
-	 * @since  3.10.0
32
-	 * @access private
33
-	 * @var int $id The entity post id.
34
-	 */
35
-	private $id;
28
+    /**
29
+     * The entity post id.
30
+     *
31
+     * @since  3.10.0
32
+     * @access private
33
+     * @var int $id The entity post id.
34
+     */
35
+    private $id;
36 36
 
37
-	/**
38
-	 * Create a Wordlift_Property_Entity_Reference instance with the provided URL.
39
-	 *
40
-	 * @since 3.8.0
41
-	 *
42
-	 * @param string $url The URL.
43
-	 * @param int    $id  The entity post id.
44
-	 */
45
-	public function __construct( $url, $id ) {
37
+    /**
38
+     * Create a Wordlift_Property_Entity_Reference instance with the provided URL.
39
+     *
40
+     * @since 3.8.0
41
+     *
42
+     * @param string $url The URL.
43
+     * @param int    $id  The entity post id.
44
+     */
45
+    public function __construct( $url, $id ) {
46 46
 
47
-		$this->url = $url;
48
-		$this->id  = $id;
47
+        $this->url = $url;
48
+        $this->id  = $id;
49 49
 
50
-	}
50
+    }
51 51
 
52
-	/**
53
-	 * Get the URL associated with this entity reference.
54
-	 *
55
-	 * @since 3.8.0
56
-	 *
57
-	 * @return string The URL associated with the entity reference.
58
-	 */
59
-	public function getURL() {
52
+    /**
53
+     * Get the URL associated with this entity reference.
54
+     *
55
+     * @since 3.8.0
56
+     *
57
+     * @return string The URL associated with the entity reference.
58
+     */
59
+    public function getURL() {
60 60
 
61
-		return $this->url;
62
-	}
61
+        return $this->url;
62
+    }
63 63
 
64
-	/**
65
-	 * Get the entity id.
66
-	 *
67
-	 * @since 3.10.0
68
-	 *
69
-	 * @return int The entity id.
70
-	 */
71
-	public function getID() {
64
+    /**
65
+     * Get the entity id.
66
+     *
67
+     * @since 3.10.0
68
+     *
69
+     * @return int The entity id.
70
+     */
71
+    public function getID() {
72 72
 
73
-		return $this->id;
74
-	}
73
+        return $this->id;
74
+    }
75 75
 
76 76
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@
 block discarded – undo
42 42
 	 * @param string $url The URL.
43 43
 	 * @param int    $id  The entity post id.
44 44
 	 */
45
-	public function __construct( $url, $id ) {
45
+	public function __construct($url, $id) {
46 46
 
47 47
 		$this->url = $url;
48 48
 		$this->id  = $id;
Please login to merge, or discard this patch.
src/includes/properties/class-wordlift-entity-property-service.php 2 patches
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -7,38 +7,38 @@
 block discarded – undo
7 7
  * @since 3.8.0
8 8
  */
9 9
 class Wordlift_Entity_Property_Service extends Wordlift_Simple_Property_Service {
10
-	/**
11
-	 * @var \Wordlift_Entity_Service $entity_service
12
-	 */
13
-	private $entity_service;
14
-
15
-	/**
16
-	 * Wordlift_Entity_Property_Service constructor.
17
-	 *
18
-	 * @param \Wordlift_Entity_Service $entity_service
19
-	 */
20
-	public function __construct( $entity_service ) {
21
-
22
-		$this->entity_service = $entity_service;
23
-
24
-	}
25
-
26
-	/**
27
-	 * {@inheritdoc}
28
-	 */
29
-	public function get( $post_id, $meta_key ) {
30
-
31
-		$entity_service = $this->entity_service;
32
-
33
-		// Map each returned value to a Wordlift_Property_Entity_Reference.
34
-		return array_map( function ( $item ) use ( $entity_service ) {
35
-
36
-			// If the $item is a number and it's an existing post, return the
37
-			// URI of the referenced entity. Otherwise return the value.
38
-			return is_numeric( $item ) && null !== get_post( $item )
39
-				? new Wordlift_Property_Entity_Reference( $entity_service->get_uri( $item ), $item )
40
-				: $item;
41
-		}, get_post_meta( $post_id, $meta_key ) );
42
-	}
10
+    /**
11
+     * @var \Wordlift_Entity_Service $entity_service
12
+     */
13
+    private $entity_service;
14
+
15
+    /**
16
+     * Wordlift_Entity_Property_Service constructor.
17
+     *
18
+     * @param \Wordlift_Entity_Service $entity_service
19
+     */
20
+    public function __construct( $entity_service ) {
21
+
22
+        $this->entity_service = $entity_service;
23
+
24
+    }
25
+
26
+    /**
27
+     * {@inheritdoc}
28
+     */
29
+    public function get( $post_id, $meta_key ) {
30
+
31
+        $entity_service = $this->entity_service;
32
+
33
+        // Map each returned value to a Wordlift_Property_Entity_Reference.
34
+        return array_map( function ( $item ) use ( $entity_service ) {
35
+
36
+            // If the $item is a number and it's an existing post, return the
37
+            // URI of the referenced entity. Otherwise return the value.
38
+            return is_numeric( $item ) && null !== get_post( $item )
39
+                ? new Wordlift_Property_Entity_Reference( $entity_service->get_uri( $item ), $item )
40
+                : $item;
41
+        }, get_post_meta( $post_id, $meta_key ) );
42
+    }
43 43
 
44 44
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 	 *
18 18
 	 * @param \Wordlift_Entity_Service $entity_service
19 19
 	 */
20
-	public function __construct( $entity_service ) {
20
+	public function __construct($entity_service) {
21 21
 
22 22
 		$this->entity_service = $entity_service;
23 23
 
@@ -26,19 +26,19 @@  discard block
 block discarded – undo
26 26
 	/**
27 27
 	 * {@inheritdoc}
28 28
 	 */
29
-	public function get( $post_id, $meta_key ) {
29
+	public function get($post_id, $meta_key) {
30 30
 
31 31
 		$entity_service = $this->entity_service;
32 32
 
33 33
 		// Map each returned value to a Wordlift_Property_Entity_Reference.
34
-		return array_map( function ( $item ) use ( $entity_service ) {
34
+		return array_map(function($item) use ($entity_service) {
35 35
 
36 36
 			// If the $item is a number and it's an existing post, return the
37 37
 			// URI of the referenced entity. Otherwise return the value.
38
-			return is_numeric( $item ) && null !== get_post( $item )
39
-				? new Wordlift_Property_Entity_Reference( $entity_service->get_uri( $item ), $item )
38
+			return is_numeric($item) && null !== get_post($item)
39
+				? new Wordlift_Property_Entity_Reference($entity_service->get_uri($item), $item)
40 40
 				: $item;
41
-		}, get_post_meta( $post_id, $meta_key ) );
41
+		}, get_post_meta($post_id, $meta_key));
42 42
 	}
43 43
 
44 44
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-debug-service.php 2 patches
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -13,66 +13,66 @@
 block discarded – undo
13 13
  */
14 14
 class Wordlift_Debug_Service {
15 15
 
16
-	/**
17
-	 * The {@link Wordlift_Entity_Service} instance.
18
-	 *
19
-	 * @since  3.7.2
20
-	 * @access private
21
-	 * @var Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
22
-	 */
23
-	private $entity_service;
24
-
25
-	/**
26
-	 * A {@link Wordlift_Uri_Service} instance.
27
-	 *
28
-	 * @since  3.10.0
29
-	 * @access private
30
-	 * @var \Wordlift_Uri_Service $uri_service A {@link Wordlift_Uri_Service} instance.
31
-	 */
32
-	private $uri_service;
33
-
34
-	/**
35
-	 * Wordlift_Debug_Service constructor.
36
-	 *
37
-	 * @since 3.7.2
38
-	 *
39
-	 * @param Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
40
-	 * @param \Wordlift_Uri_Service   $uri_service    A {@link Wordlift_Uri_Service} instance.
41
-	 */
42
-	public function __construct( $entity_service, $uri_service ) {
43
-
44
-		$this->entity_service = $entity_service;
45
-		$this->uri_service    = $uri_service;
46
-
47
-		add_action( 'wp_ajax_wl_dump_uri', array( $this, 'dump_uri' ) );
48
-
49
-	}
50
-
51
-	public function dump_uri() {
52
-
53
-		if ( ! isset( $_GET['id'] ) ) {
54
-			wp_send_json_error( 'id not set' );
55
-		}
56
-
57
-		$post_id = $_GET['id'];
58
-
59
-		$post = get_post( $post_id );
60
-
61
-		$uri       = $this->entity_service->get_uri( $post_id );
62
-		$encoding  = mb_detect_encoding( $uri );
63
-		$build_uri = $this->uri_service->build_uri( $post->post_title, $post->post_type );
64
-
65
-
66
-		var_dump( $uri );
67
-
68
-		wp_send_json_success( array(
69
-			'uri'               => $uri,
70
-			'post_title'        => sprintf( '%s (%s)', $post->post_title, mb_detect_encoding( $post->post_title ) ),
71
-			'post_title_ascii'  => mb_convert_encoding( $post->post_title, 'ASCII' ),
72
-			'build_uri'         => $build_uri,
73
-			'build_uri_convert' => mb_convert_encoding( $build_uri, 'ASCII' ),
74
-		) );
75
-
76
-	}
16
+    /**
17
+     * The {@link Wordlift_Entity_Service} instance.
18
+     *
19
+     * @since  3.7.2
20
+     * @access private
21
+     * @var Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
22
+     */
23
+    private $entity_service;
24
+
25
+    /**
26
+     * A {@link Wordlift_Uri_Service} instance.
27
+     *
28
+     * @since  3.10.0
29
+     * @access private
30
+     * @var \Wordlift_Uri_Service $uri_service A {@link Wordlift_Uri_Service} instance.
31
+     */
32
+    private $uri_service;
33
+
34
+    /**
35
+     * Wordlift_Debug_Service constructor.
36
+     *
37
+     * @since 3.7.2
38
+     *
39
+     * @param Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
40
+     * @param \Wordlift_Uri_Service   $uri_service    A {@link Wordlift_Uri_Service} instance.
41
+     */
42
+    public function __construct( $entity_service, $uri_service ) {
43
+
44
+        $this->entity_service = $entity_service;
45
+        $this->uri_service    = $uri_service;
46
+
47
+        add_action( 'wp_ajax_wl_dump_uri', array( $this, 'dump_uri' ) );
48
+
49
+    }
50
+
51
+    public function dump_uri() {
52
+
53
+        if ( ! isset( $_GET['id'] ) ) {
54
+            wp_send_json_error( 'id not set' );
55
+        }
56
+
57
+        $post_id = $_GET['id'];
58
+
59
+        $post = get_post( $post_id );
60
+
61
+        $uri       = $this->entity_service->get_uri( $post_id );
62
+        $encoding  = mb_detect_encoding( $uri );
63
+        $build_uri = $this->uri_service->build_uri( $post->post_title, $post->post_type );
64
+
65
+
66
+        var_dump( $uri );
67
+
68
+        wp_send_json_success( array(
69
+            'uri'               => $uri,
70
+            'post_title'        => sprintf( '%s (%s)', $post->post_title, mb_detect_encoding( $post->post_title ) ),
71
+            'post_title_ascii'  => mb_convert_encoding( $post->post_title, 'ASCII' ),
72
+            'build_uri'         => $build_uri,
73
+            'build_uri_convert' => mb_convert_encoding( $build_uri, 'ASCII' ),
74
+        ) );
75
+
76
+    }
77 77
 
78 78
 }
79 79
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -39,39 +39,39 @@
 block discarded – undo
39 39
 	 * @param Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
40 40
 	 * @param \Wordlift_Uri_Service   $uri_service    A {@link Wordlift_Uri_Service} instance.
41 41
 	 */
42
-	public function __construct( $entity_service, $uri_service ) {
42
+	public function __construct($entity_service, $uri_service) {
43 43
 
44 44
 		$this->entity_service = $entity_service;
45 45
 		$this->uri_service    = $uri_service;
46 46
 
47
-		add_action( 'wp_ajax_wl_dump_uri', array( $this, 'dump_uri' ) );
47
+		add_action('wp_ajax_wl_dump_uri', array($this, 'dump_uri'));
48 48
 
49 49
 	}
50 50
 
51 51
 	public function dump_uri() {
52 52
 
53
-		if ( ! isset( $_GET['id'] ) ) {
54
-			wp_send_json_error( 'id not set' );
53
+		if ( ! isset($_GET['id'])) {
54
+			wp_send_json_error('id not set');
55 55
 		}
56 56
 
57 57
 		$post_id = $_GET['id'];
58 58
 
59
-		$post = get_post( $post_id );
59
+		$post = get_post($post_id);
60 60
 
61
-		$uri       = $this->entity_service->get_uri( $post_id );
62
-		$encoding  = mb_detect_encoding( $uri );
63
-		$build_uri = $this->uri_service->build_uri( $post->post_title, $post->post_type );
61
+		$uri       = $this->entity_service->get_uri($post_id);
62
+		$encoding  = mb_detect_encoding($uri);
63
+		$build_uri = $this->uri_service->build_uri($post->post_title, $post->post_type);
64 64
 
65 65
 
66
-		var_dump( $uri );
66
+		var_dump($uri);
67 67
 
68
-		wp_send_json_success( array(
68
+		wp_send_json_success(array(
69 69
 			'uri'               => $uri,
70
-			'post_title'        => sprintf( '%s (%s)', $post->post_title, mb_detect_encoding( $post->post_title ) ),
71
-			'post_title_ascii'  => mb_convert_encoding( $post->post_title, 'ASCII' ),
70
+			'post_title'        => sprintf('%s (%s)', $post->post_title, mb_detect_encoding($post->post_title)),
71
+			'post_title_ascii'  => mb_convert_encoding($post->post_title, 'ASCII'),
72 72
 			'build_uri'         => $build_uri,
73
-			'build_uri_convert' => mb_convert_encoding( $build_uri, 'ASCII' ),
74
-		) );
73
+			'build_uri_convert' => mb_convert_encoding($build_uri, 'ASCII'),
74
+		));
75 75
 
76 76
 	}
77 77
 
Please login to merge, or discard this patch.
src/public/class-wordlift-seo-service.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -21,66 +21,66 @@
 block discarded – undo
21 21
  */
22 22
 class Wordlift_Seo_Service {
23 23
 
24
-	/**
25
-	 * @inheritdoc
26
-	 */
27
-	function __construct() {
24
+    /**
25
+     * @inheritdoc
26
+     */
27
+    function __construct() {
28 28
 
29
-		// If we are not on the admin, run the get_term filter for entity type terms.
30
-		add_filter( 'get_wl_entity_type', array(
31
-			$this,
32
-			'get_wl_entity_type',
33
-		), 10, 2 );
29
+        // If we are not on the admin, run the get_term filter for entity type terms.
30
+        add_filter( 'get_wl_entity_type', array(
31
+            $this,
32
+            'get_wl_entity_type',
33
+        ), 10, 2 );
34 34
 
35
-	}
35
+    }
36 36
 
37
-	/**
38
-	 * Filter the entity term object, and when not in admin context replace title
39
-	 * and description with whatever was set in the entity settings page.
40
-	 *
41
-	 * @since    3.11
42
-	 *
43
-	 * @param WP_Term $term     The term to filters.
44
-	 * @param string  $taxonomy The taxonomy name.
45
-	 *
46
-	 * @return WP_Term The {@link WP_Term} with fields changed.
47
-	 */
48
-	function get_wl_entity_type( $term, $taxonomy ) {
37
+    /**
38
+     * Filter the entity term object, and when not in admin context replace title
39
+     * and description with whatever was set in the entity settings page.
40
+     *
41
+     * @since    3.11
42
+     *
43
+     * @param WP_Term $term     The term to filters.
44
+     * @param string  $taxonomy The taxonomy name.
45
+     *
46
+     * @return WP_Term The {@link WP_Term} with fields changed.
47
+     */
48
+    function get_wl_entity_type( $term, $taxonomy ) {
49 49
 
50
-		// Do nothing when in admin.
51
-		if ( is_admin() ) {
52
-			return $term;
53
-		}
50
+        // Do nothing when in admin.
51
+        if ( is_admin() ) {
52
+            return $term;
53
+        }
54 54
 
55
-		// Get the terms' settings.
56
-		$entity_settings = get_option( 'wl_entity_type_settings', array() );
55
+        // Get the terms' settings.
56
+        $entity_settings = get_option( 'wl_entity_type_settings', array() );
57 57
 
58
-		// If we have no settings for the specified term, then return the original
59
-		// term.
60
-		if ( ! isset( $entity_settings[ $term->term_id ] ) ) {
58
+        // If we have no settings for the specified term, then return the original
59
+        // term.
60
+        if ( ! isset( $entity_settings[ $term->term_id ] ) ) {
61 61
 
62
-			return $term;
63
-		}
62
+            return $term;
63
+        }
64 64
 
65
-		// Get the settings for the specified term.
66
-		$settings = $entity_settings[ $term->term_id ];
65
+        // Get the settings for the specified term.
66
+        $settings = $entity_settings[ $term->term_id ];
67 67
 
68
-		// Update the name.
69
-		if ( ! empty( $settings['title'] ) ) {
68
+        // Update the name.
69
+        if ( ! empty( $settings['title'] ) ) {
70 70
 
71
-			$term->name = $settings['title'];
71
+            $term->name = $settings['title'];
72 72
 
73
-		}
73
+        }
74 74
 
75
-		// Update the description.
76
-		if ( ! empty( $settings['description'] ) ) {
75
+        // Update the description.
76
+        if ( ! empty( $settings['description'] ) ) {
77 77
 
78
-			$term->description = $settings['description'];
78
+            $term->description = $settings['description'];
79 79
 
80
-		}
80
+        }
81 81
 
82
-		// Return the updated term.
83
-		return $term;
84
-	}
82
+        // Return the updated term.
83
+        return $term;
84
+    }
85 85
 
86 86
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -27,10 +27,10 @@  discard block
 block discarded – undo
27 27
 	function __construct() {
28 28
 
29 29
 		// If we are not on the admin, run the get_term filter for entity type terms.
30
-		add_filter( 'get_wl_entity_type', array(
30
+		add_filter('get_wl_entity_type', array(
31 31
 			$this,
32 32
 			'get_wl_entity_type',
33
-		), 10, 2 );
33
+		), 10, 2);
34 34
 
35 35
 	}
36 36
 
@@ -45,35 +45,35 @@  discard block
 block discarded – undo
45 45
 	 *
46 46
 	 * @return WP_Term The {@link WP_Term} with fields changed.
47 47
 	 */
48
-	function get_wl_entity_type( $term, $taxonomy ) {
48
+	function get_wl_entity_type($term, $taxonomy) {
49 49
 
50 50
 		// Do nothing when in admin.
51
-		if ( is_admin() ) {
51
+		if (is_admin()) {
52 52
 			return $term;
53 53
 		}
54 54
 
55 55
 		// Get the terms' settings.
56
-		$entity_settings = get_option( 'wl_entity_type_settings', array() );
56
+		$entity_settings = get_option('wl_entity_type_settings', array());
57 57
 
58 58
 		// If we have no settings for the specified term, then return the original
59 59
 		// term.
60
-		if ( ! isset( $entity_settings[ $term->term_id ] ) ) {
60
+		if ( ! isset($entity_settings[$term->term_id])) {
61 61
 
62 62
 			return $term;
63 63
 		}
64 64
 
65 65
 		// Get the settings for the specified term.
66
-		$settings = $entity_settings[ $term->term_id ];
66
+		$settings = $entity_settings[$term->term_id];
67 67
 
68 68
 		// Update the name.
69
-		if ( ! empty( $settings['title'] ) ) {
69
+		if ( ! empty($settings['title'])) {
70 70
 
71 71
 			$term->name = $settings['title'];
72 72
 
73 73
 		}
74 74
 
75 75
 		// Update the description.
76
-		if ( ! empty( $settings['description'] ) ) {
76
+		if ( ! empty($settings['description'])) {
77 77
 
78 78
 			$term->description = $settings['description'];
79 79
 
Please login to merge, or discard this patch.
src/public/class-wordlift-widget.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -16,26 +16,26 @@
 block discarded – undo
16 16
  */
17 17
 abstract class Wordlift_Widget extends WP_Widget {
18 18
 
19
-	/**
20
-	 * @inheritdoc
21
-	 */
22
-	public function __construct( $id_base, $name, array $widget_options = array(), array $control_options = array() ) {
23
-		parent::__construct( $id_base, $name, $widget_options, $control_options );
19
+    /**
20
+     * @inheritdoc
21
+     */
22
+    public function __construct( $id_base, $name, array $widget_options = array(), array $control_options = array() ) {
23
+        parent::__construct( $id_base, $name, $widget_options, $control_options );
24 24
 
25
-		// Initialize the Related Entities Cloud Widget.
26
-		add_action( 'widgets_init', array( $this, 'widget_init' ) );
25
+        // Initialize the Related Entities Cloud Widget.
26
+        add_action( 'widgets_init', array( $this, 'widget_init' ) );
27 27
 
28
-	}
28
+    }
29 29
 
30
-	/**
31
-	 * Register the related entities cloud widget
32
-	 *
33
-	 * @since 3.11.0
34
-	 */
35
-	public function widget_init() {
30
+    /**
31
+     * Register the related entities cloud widget
32
+     *
33
+     * @since 3.11.0
34
+     */
35
+    public function widget_init() {
36 36
 
37
-		register_widget( get_class( $this ) );
37
+        register_widget( get_class( $this ) );
38 38
 
39
-	}
39
+    }
40 40
 
41 41
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,11 +19,11 @@  discard block
 block discarded – undo
19 19
 	/**
20 20
 	 * @inheritdoc
21 21
 	 */
22
-	public function __construct( $id_base, $name, array $widget_options = array(), array $control_options = array() ) {
23
-		parent::__construct( $id_base, $name, $widget_options, $control_options );
22
+	public function __construct($id_base, $name, array $widget_options = array(), array $control_options = array()) {
23
+		parent::__construct($id_base, $name, $widget_options, $control_options);
24 24
 
25 25
 		// Initialize the Related Entities Cloud Widget.
26
-		add_action( 'widgets_init', array( $this, 'widget_init' ) );
26
+		add_action('widgets_init', array($this, 'widget_init'));
27 27
 
28 28
 	}
29 29
 
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	 */
35 35
 	public function widget_init() {
36 36
 
37
-		register_widget( get_class( $this ) );
37
+		register_widget(get_class($this));
38 38
 
39 39
 	}
40 40
 
Please login to merge, or discard this patch.
src/includes/class-wordlift-publisher-ajax-adapter.php 2 patches
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -16,55 +16,55 @@
 block discarded – undo
16 16
  */
17 17
 class Wordlift_Publisher_Ajax_Adapter {
18 18
 
19
-	/**
20
-	 * The {@link Wordlift_Publisher_Service} instance.
21
-	 *
22
-	 * @since  3.11.0
23
-	 * @access private
24
-	 * @var Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance.
25
-	 */
26
-	private $publisher_service;
19
+    /**
20
+     * The {@link Wordlift_Publisher_Service} instance.
21
+     *
22
+     * @since  3.11.0
23
+     * @access private
24
+     * @var Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance.
25
+     */
26
+    private $publisher_service;
27 27
 
28
-	/**
29
-	 * Create a {@link Wordlift_Publisher_Ajax_Adapter} instance.
30
-	 *
31
-	 * @since 3.11.0
32
-	 *
33
-	 * @param \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance.
34
-	 */
35
-	function __construct( $publisher_service ) {
28
+    /**
29
+     * Create a {@link Wordlift_Publisher_Ajax_Adapter} instance.
30
+     *
31
+     * @since 3.11.0
32
+     *
33
+     * @param \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance.
34
+     */
35
+    function __construct( $publisher_service ) {
36 36
 
37
-		$this->publisher_service = $publisher_service;
37
+        $this->publisher_service = $publisher_service;
38 38
 
39
-	}
39
+    }
40 40
 
41
-	/**
42
-	 * The publisher AJAX action. This function is hook to the `wl_publisher`
43
-	 * action.
44
-	 *
45
-	 * @since 3.11.0
46
-	 */
47
-	public function publisher() {
41
+    /**
42
+     * The publisher AJAX action. This function is hook to the `wl_publisher`
43
+     * action.
44
+     *
45
+     * @since 3.11.0
46
+     */
47
+    public function publisher() {
48 48
 
49
-		// Ensure we don't have garbage before us.
50
-		ob_clean();
49
+        // Ensure we don't have garbage before us.
50
+        ob_clean();
51 51
 
52
-		// Check if the current user can `manage_options`.
53
-		if ( ! current_user_can( 'manage_options' ) ) {
54
-			wp_send_json_error( 'Access denied.' );
55
-		}
52
+        // Check if the current user can `manage_options`.
53
+        if ( ! current_user_can( 'manage_options' ) ) {
54
+            wp_send_json_error( 'Access denied.' );
55
+        }
56 56
 
57
-		// No actual search parameter was passed, bail out.
58
-		if ( ! isset( $_POST['q'] ) || empty( $_POST['q'] ) ) {
59
-			wp_send_json_error( 'The q parameter is required.' );
60
-		}
57
+        // No actual search parameter was passed, bail out.
58
+        if ( ! isset( $_POST['q'] ) || empty( $_POST['q'] ) ) {
59
+            wp_send_json_error( 'The q parameter is required.' );
60
+        }
61 61
 
62
-		// Get the response.
63
-		$response = $this->publisher_service->query( $_POST['q'] );
62
+        // Get the response.
63
+        $response = $this->publisher_service->query( $_POST['q'] );
64 64
 
65
-		// Finally output the response.
66
-		wp_send_json_success( $response );
65
+        // Finally output the response.
66
+        wp_send_json_success( $response );
67 67
 
68
-	}
68
+    }
69 69
 
70 70
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 *
33 33
 	 * @param \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance.
34 34
 	 */
35
-	function __construct( $publisher_service ) {
35
+	function __construct($publisher_service) {
36 36
 
37 37
 		$this->publisher_service = $publisher_service;
38 38
 
@@ -50,20 +50,20 @@  discard block
 block discarded – undo
50 50
 		ob_clean();
51 51
 
52 52
 		// Check if the current user can `manage_options`.
53
-		if ( ! current_user_can( 'manage_options' ) ) {
54
-			wp_send_json_error( 'Access denied.' );
53
+		if ( ! current_user_can('manage_options')) {
54
+			wp_send_json_error('Access denied.');
55 55
 		}
56 56
 
57 57
 		// No actual search parameter was passed, bail out.
58
-		if ( ! isset( $_POST['q'] ) || empty( $_POST['q'] ) ) {
59
-			wp_send_json_error( 'The q parameter is required.' );
58
+		if ( ! isset($_POST['q']) || empty($_POST['q'])) {
59
+			wp_send_json_error('The q parameter is required.');
60 60
 		}
61 61
 
62 62
 		// Get the response.
63
-		$response = $this->publisher_service->query( $_POST['q'] );
63
+		$response = $this->publisher_service->query($_POST['q']);
64 64
 
65 65
 		// Finally output the response.
66
-		wp_send_json_success( $response );
66
+		wp_send_json_success($response);
67 67
 
68 68
 	}
69 69
 
Please login to merge, or discard this patch.
src/includes/class-wordlift-category-taxonomy-service.php 2 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -18,74 +18,74 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Category_Taxonomy_Service {
20 20
 
21
-	/**
22
-	 * The {@link Wordlift_Entity_Post_Type_Service} instance.
23
-	 *
24
-	 * @since  3.11.0
25
-	 * @access private
26
-	 * @var \Wordlift_Entity_Post_Type_Service $entity_post_type_service The {@link Wordlift_Entity_Post_Type_Service} instance.
27
-	 */
28
-	private $entity_post_type_service;
21
+    /**
22
+     * The {@link Wordlift_Entity_Post_Type_Service} instance.
23
+     *
24
+     * @since  3.11.0
25
+     * @access private
26
+     * @var \Wordlift_Entity_Post_Type_Service $entity_post_type_service The {@link Wordlift_Entity_Post_Type_Service} instance.
27
+     */
28
+    private $entity_post_type_service;
29 29
 
30
-	/**
31
-	 * Create a {@link Wordlift_Category_Taxonomy_Service} instance.
32
-	 *
33
-	 * @since 3.11.0
34
-	 *
35
-	 * @param \Wordlift_Entity_Post_Type_Service $entity_post_type_service The {@link Wordlift_Entity_Post_Type_Service} instance.
36
-	 */
37
-	function __construct( $entity_post_type_service ) {
30
+    /**
31
+     * Create a {@link Wordlift_Category_Taxonomy_Service} instance.
32
+     *
33
+     * @since 3.11.0
34
+     *
35
+     * @param \Wordlift_Entity_Post_Type_Service $entity_post_type_service The {@link Wordlift_Entity_Post_Type_Service} instance.
36
+     */
37
+    function __construct( $entity_post_type_service ) {
38 38
 
39
-		$this->entity_post_type_service = $entity_post_type_service;
39
+        $this->entity_post_type_service = $entity_post_type_service;
40 40
 
41
-	}
41
+    }
42 42
 
43
-	/**
44
-	 * Set the entity post types as one to be included in archive pages.
45
-	 *
46
-	 * In order to have entities show up in standard WP categories (Posts categories)
47
-	 * we configure the `entity` post type, but we also need to alter the main
48
-	 * WP query (which by default queries posts only) to include the `entities`.
49
-	 *
50
-	 * @since 3.11.0
51
-	 *
52
-	 * @param WP_Query $query WP's {@link WP_Query} instance.
53
-	 */
54
-	public function pre_get_posts( $query ) {
43
+    /**
44
+     * Set the entity post types as one to be included in archive pages.
45
+     *
46
+     * In order to have entities show up in standard WP categories (Posts categories)
47
+     * we configure the `entity` post type, but we also need to alter the main
48
+     * WP query (which by default queries posts only) to include the `entities`.
49
+     *
50
+     * @since 3.11.0
51
+     *
52
+     * @param WP_Query $query WP's {@link WP_Query} instance.
53
+     */
54
+    public function pre_get_posts( $query ) {
55 55
 
56
-		// Only for the main query, avoid problems with widgets and what not.
57
-		if ( ! $query->is_main_query() ) {
58
-			return;
59
-		}
56
+        // Only for the main query, avoid problems with widgets and what not.
57
+        if ( ! $query->is_main_query() ) {
58
+            return;
59
+        }
60 60
 
61
-		// We don't want to alter the query if we're in the admin UI, if this is
62
-		// not a category query, or if the `suppress_filters` is set.
63
-		//
64
-		// Note that it is unlikely for `suppress_filter` to be set on the front
65
-		// end, but let's be safe if it is set the calling code assumes no
66
-		// modifications of queries.
67
-		//
68
-		// is_admin is needed, otherwise category based post filters will show
69
-		// both types and at the current release (4.7) it causes PHP errors.
70
-		if ( is_admin() || ! is_category() || ! empty( $query->query_vars['suppress_filters'] ) ) {
71
-			return;
72
-		}
61
+        // We don't want to alter the query if we're in the admin UI, if this is
62
+        // not a category query, or if the `suppress_filters` is set.
63
+        //
64
+        // Note that it is unlikely for `suppress_filter` to be set on the front
65
+        // end, but let's be safe if it is set the calling code assumes no
66
+        // modifications of queries.
67
+        //
68
+        // is_admin is needed, otherwise category based post filters will show
69
+        // both types and at the current release (4.7) it causes PHP errors.
70
+        if ( is_admin() || ! is_category() || ! empty( $query->query_vars['suppress_filters'] ) ) {
71
+            return;
72
+        }
73 73
 
74
-		// Check the current post types, maybe the category archive pages
75
-		// are already associated with other post types.
76
-		//
77
-		// If `post_type` isn't set, WP assumes `post` by default.
78
-		$post_types = (array) ( $query->get( 'post_type' ) ?: 'post' );
74
+        // Check the current post types, maybe the category archive pages
75
+        // are already associated with other post types.
76
+        //
77
+        // If `post_type` isn't set, WP assumes `post` by default.
78
+        $post_types = (array) ( $query->get( 'post_type' ) ?: 'post' );
79 79
 
80
-		// Add the entities post type only if the post post type is used in the query
81
-		// since we only want `entities` to appear alongside posts.
82
-		if ( in_array( 'post', $post_types ) ) {
83
-			$post_types[] = $this->entity_post_type_service->get_post_type();
84
-		}
80
+        // Add the entities post type only if the post post type is used in the query
81
+        // since we only want `entities` to appear alongside posts.
82
+        if ( in_array( 'post', $post_types ) ) {
83
+            $post_types[] = $this->entity_post_type_service->get_post_type();
84
+        }
85 85
 
86
-		// Update the query post types.
87
-		$query->set( 'post_type', $post_types );
86
+        // Update the query post types.
87
+        $query->set( 'post_type', $post_types );
88 88
 
89
-	}
89
+    }
90 90
 
91 91
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	 *
35 35
 	 * @param \Wordlift_Entity_Post_Type_Service $entity_post_type_service The {@link Wordlift_Entity_Post_Type_Service} instance.
36 36
 	 */
37
-	function __construct( $entity_post_type_service ) {
37
+	function __construct($entity_post_type_service) {
38 38
 
39 39
 		$this->entity_post_type_service = $entity_post_type_service;
40 40
 
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
 	 *
52 52
 	 * @param WP_Query $query WP's {@link WP_Query} instance.
53 53
 	 */
54
-	public function pre_get_posts( $query ) {
54
+	public function pre_get_posts($query) {
55 55
 
56 56
 		// Only for the main query, avoid problems with widgets and what not.
57
-		if ( ! $query->is_main_query() ) {
57
+		if ( ! $query->is_main_query()) {
58 58
 			return;
59 59
 		}
60 60
 
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 		//
68 68
 		// is_admin is needed, otherwise category based post filters will show
69 69
 		// both types and at the current release (4.7) it causes PHP errors.
70
-		if ( is_admin() || ! is_category() || ! empty( $query->query_vars['suppress_filters'] ) ) {
70
+		if (is_admin() || ! is_category() || ! empty($query->query_vars['suppress_filters'])) {
71 71
 			return;
72 72
 		}
73 73
 
@@ -75,16 +75,16 @@  discard block
 block discarded – undo
75 75
 		// are already associated with other post types.
76 76
 		//
77 77
 		// If `post_type` isn't set, WP assumes `post` by default.
78
-		$post_types = (array) ( $query->get( 'post_type' ) ?: 'post' );
78
+		$post_types = (array) ($query->get('post_type') ?: 'post');
79 79
 
80 80
 		// Add the entities post type only if the post post type is used in the query
81 81
 		// since we only want `entities` to appear alongside posts.
82
-		if ( in_array( 'post', $post_types ) ) {
82
+		if (in_array('post', $post_types)) {
83 83
 			$post_types[] = $this->entity_post_type_service->get_post_type();
84 84
 		}
85 85
 
86 86
 		// Update the query post types.
87
-		$query->set( 'post_type', $post_types );
87
+		$query->set('post_type', $post_types);
88 88
 
89 89
 	}
90 90
 
Please login to merge, or discard this patch.
src/widgets/wordlift_widget_timeline.php 2 patches
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -2,52 +2,52 @@
 block discarded – undo
2 2
 
3 3
 class Wordlift_Timeline_Widget extends WP_Widget {
4 4
 
5
-	/**
6
-	 * Sets up the widgets name etc
7
-	 */
8
-	public function __construct() {
9
-		// widget actual processes
10
-		parent::__construct(
11
-			'wl_timeline_widget', // Base ID
12
-			__( 'WordLift Timeline Widget', 'wordlift' ), // Name
13
-			array( 'description' => __( 'Displays entities of type event using an interactive timeline.', 'wordlift' ), ) // Args
14
-		);
15
-	}
16
-
17
-	/**
18
-	 * Outputs the content of the widget
19
-	 *
20
-	 * @param array $args
21
-	 * @param array $instance
22
-	 */
23
-	public function widget( $args, $instance ) {
24
-		// outputs the content of the widget	
25
-		echo do_shortcode( '[wl_timeline global=true]' );
26
-	}
27
-
28
-	/**
29
-	 * Outputs the options form on admin
30
-	 *
31
-	 * @param array $instance The widget options
32
-	 */
33
-	public function form( $instance ) {
34
-		// outputs the options form on admin
35
-	}
36
-
37
-	/**
38
-	 * Processing widget options on save
39
-	 *
40
-	 * @param array $new_instance The new options
41
-	 * @param array $old_instance The previous options
42
-	 */
43
-	public function update( $new_instance, $old_instance ) {
44
-		// processes widget options to be saved
45
-	}
5
+    /**
6
+     * Sets up the widgets name etc
7
+     */
8
+    public function __construct() {
9
+        // widget actual processes
10
+        parent::__construct(
11
+            'wl_timeline_widget', // Base ID
12
+            __( 'WordLift Timeline Widget', 'wordlift' ), // Name
13
+            array( 'description' => __( 'Displays entities of type event using an interactive timeline.', 'wordlift' ), ) // Args
14
+        );
15
+    }
16
+
17
+    /**
18
+     * Outputs the content of the widget
19
+     *
20
+     * @param array $args
21
+     * @param array $instance
22
+     */
23
+    public function widget( $args, $instance ) {
24
+        // outputs the content of the widget	
25
+        echo do_shortcode( '[wl_timeline global=true]' );
26
+    }
27
+
28
+    /**
29
+     * Outputs the options form on admin
30
+     *
31
+     * @param array $instance The widget options
32
+     */
33
+    public function form( $instance ) {
34
+        // outputs the options form on admin
35
+    }
36
+
37
+    /**
38
+     * Processing widget options on save
39
+     *
40
+     * @param array $new_instance The new options
41
+     * @param array $old_instance The previous options
42
+     */
43
+    public function update( $new_instance, $old_instance ) {
44
+        // processes widget options to be saved
45
+    }
46 46
 }
47 47
 
48 48
 function wl_register_timeline_widget() {
49 49
 
50
-	register_widget( 'WordLift_Timeline_Widget' );
50
+    register_widget( 'WordLift_Timeline_Widget' );
51 51
 }
52 52
 
53 53
 add_action( 'widgets_init', 'wl_register_timeline_widget' );
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -9,8 +9,8 @@  discard block
 block discarded – undo
9 9
 		// widget actual processes
10 10
 		parent::__construct(
11 11
 			'wl_timeline_widget', // Base ID
12
-			__( 'WordLift Timeline Widget', 'wordlift' ), // Name
13
-			array( 'description' => __( 'Displays entities of type event using an interactive timeline.', 'wordlift' ), ) // Args
12
+			__('WordLift Timeline Widget', 'wordlift'), // Name
13
+			array('description' => __('Displays entities of type event using an interactive timeline.', 'wordlift'),) // Args
14 14
 		);
15 15
 	}
16 16
 
@@ -20,9 +20,9 @@  discard block
 block discarded – undo
20 20
 	 * @param array $args
21 21
 	 * @param array $instance
22 22
 	 */
23
-	public function widget( $args, $instance ) {
23
+	public function widget($args, $instance) {
24 24
 		// outputs the content of the widget	
25
-		echo do_shortcode( '[wl_timeline global=true]' );
25
+		echo do_shortcode('[wl_timeline global=true]');
26 26
 	}
27 27
 
28 28
 	/**
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 	 *
31 31
 	 * @param array $instance The widget options
32 32
 	 */
33
-	public function form( $instance ) {
33
+	public function form($instance) {
34 34
 		// outputs the options form on admin
35 35
 	}
36 36
 
@@ -40,15 +40,15 @@  discard block
 block discarded – undo
40 40
 	 * @param array $new_instance The new options
41 41
 	 * @param array $old_instance The previous options
42 42
 	 */
43
-	public function update( $new_instance, $old_instance ) {
43
+	public function update($new_instance, $old_instance) {
44 44
 		// processes widget options to be saved
45 45
 	}
46 46
 }
47 47
 
48 48
 function wl_register_timeline_widget() {
49 49
 
50
-	register_widget( 'WordLift_Timeline_Widget' );
50
+	register_widget('WordLift_Timeline_Widget');
51 51
 }
52 52
 
53
-add_action( 'widgets_init', 'wl_register_timeline_widget' );
54
-add_filter( 'widget_text', 'do_shortcode' );
53
+add_action('widgets_init', 'wl_register_timeline_widget');
54
+add_filter('widget_text', 'do_shortcode');
Please login to merge, or discard this patch.