Completed
Push — develop ( cf0659...0af133 )
by David
01:28 queued 12s
created
src/install/class-wordlift-install-service.php 1 patch
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -49,37 +49,37 @@  discard block
 block discarded – undo
49 49
 	public function __construct() {
50 50
 
51 51
 		/** Installs. */
52
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install.php';
53
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-1-0-0.php';
54
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-10-0.php';
55
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-12-0.php';
56
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-14-0.php';
57
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-15-0.php';
58
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-18-0.php';
59
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-18-3.php';
60
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-19-5.php';
61
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-20-0.php';
62
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-23-4.php';
63
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-24-2.php';
64
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-all-entity-types.php';
65
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-package-type.php';
66
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-25-0.php';
67
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-27-0.php';
68
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-27-1.php';
69
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-28-0.php';
70
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-32-0.php';
71
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-33-9.php';
72
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-36-0.php';
73
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-38-5.php';
74
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-39-1.php';
75
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-40-1.php';
76
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-40-2.php';
77
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-41-0.php';
78
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-42-0.php';
79
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-44-1.php';
80
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-44-4.php';
81
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-45-0.php';
82
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-45-1.php';
52
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install.php';
53
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-1-0-0.php';
54
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-10-0.php';
55
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-12-0.php';
56
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-14-0.php';
57
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-15-0.php';
58
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-18-0.php';
59
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-18-3.php';
60
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-19-5.php';
61
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-20-0.php';
62
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-23-4.php';
63
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-24-2.php';
64
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-all-entity-types.php';
65
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-package-type.php';
66
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-25-0.php';
67
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-27-0.php';
68
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-27-1.php';
69
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-28-0.php';
70
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-32-0.php';
71
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-33-9.php';
72
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-36-0.php';
73
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-38-5.php';
74
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-39-1.php';
75
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-40-1.php';
76
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-40-2.php';
77
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-41-0.php';
78
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-42-0.php';
79
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-44-1.php';
80
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-44-4.php';
81
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-45-0.php';
82
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-45-1.php';
83 83
 
84 84
 		// Get the install services.
85 85
 		$this->installs = array(
@@ -130,9 +130,9 @@  discard block
 block discarded – undo
130 130
 		);
131 131
 		self::$instance = $this;
132 132
 
133
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
133
+		$this->log = Wordlift_Log_Service::get_logger(get_class());
134 134
 
135
-		add_action( 'init', array( $this, 'install' ) );
135
+		add_action('init', array($this, 'install'));
136 136
 
137 137
 	}
138 138
 
@@ -158,30 +158,30 @@  discard block
 block discarded – undo
158 158
 
159 159
 		$version = null;
160 160
 
161
-		if ( $this->install_required() && false === get_transient( '_wl_installing' ) ) {
162
-			set_transient( '_wl_installing', true, 5 * MINUTE_IN_SECONDS );
161
+		if ($this->install_required() && false === get_transient('_wl_installing')) {
162
+			set_transient('_wl_installing', true, 5 * MINUTE_IN_SECONDS);
163 163
 			/** @var Wordlift_Install $install */
164
-			foreach ( $this->installs as $install ) {
164
+			foreach ($this->installs as $install) {
165 165
 				// Get the install version.
166 166
 				$version = $install->get_version();
167 167
 
168
-				if ( version_compare( $version, $this->get_current_version(), '>' )
169
-					 || $install->must_install() ) {
170
-					$class_name = get_class( $install );
168
+				if (version_compare($version, $this->get_current_version(), '>')
169
+					 || $install->must_install()) {
170
+					$class_name = get_class($install);
171 171
 
172
-					$this->log->info( "Current version is {$this->get_current_version()}, installing $class_name..." );
172
+					$this->log->info("Current version is {$this->get_current_version()}, installing $class_name...");
173 173
 					// Install version.
174 174
 					$install->install();
175 175
 
176
-					$this->log->info( "$class_name installed." );
176
+					$this->log->info("$class_name installed.");
177 177
 
178 178
 					// Bump the version.
179
-					update_option( 'wl_db_version', $version );
179
+					update_option('wl_db_version', $version);
180 180
 				}
181 181
 			}
182 182
 
183 183
 			// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
184
-			@delete_transient( '_wl_installing' );
184
+			@delete_transient('_wl_installing');
185 185
 
186 186
 		}
187 187
 
@@ -190,12 +190,12 @@  discard block
 block discarded – undo
190 190
 	private function install_required() {
191 191
 
192 192
 		/** @var Wordlift_Install $install */
193
-		foreach ( $this->installs as $install ) {
193
+		foreach ($this->installs as $install) {
194 194
 			// Get the install version.
195 195
 			$version = $install->get_version();
196 196
 
197
-			if ( version_compare( $version, $this->get_current_version(), '>' )
198
-				 || $install->must_install() ) {
197
+			if (version_compare($version, $this->get_current_version(), '>')
198
+				 || $install->must_install()) {
199 199
 				return true;
200 200
 			}
201 201
 		}
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 	 * @return type
210 210
 	 */
211 211
 	private function get_current_version() {
212
-		return get_option( 'wl_db_version', '0.0.0' );
212
+		return get_option('wl_db_version', '0.0.0');
213 213
 	}
214 214
 
215 215
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-abstract-post-to-jsonld-converter.php 1 patch
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 	 *
74 74
 	 * @since 3.10.0
75 75
 	 */
76
-	public function __construct( $entity_type_service, $user_service, $attachment_service, $property_getter ) {
76
+	public function __construct($entity_type_service, $user_service, $attachment_service, $property_getter) {
77 77
 		$this->entity_type_service = $entity_type_service;
78 78
 		$this->user_service        = $user_service;
79 79
 		$this->attachment_service  = $attachment_service;
@@ -92,19 +92,19 @@  discard block
 block discarded – undo
92 92
 	 * @since 3.10.0
93 93
 	 */
94 94
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
95
-	public function convert( $post_id, &$references = array(), &$references_infos = array(), $relations = null ) {
95
+	public function convert($post_id, &$references = array(), &$references_infos = array(), $relations = null) {
96 96
 
97 97
 		// Get the post instance.
98
-		$post = get_post( $post_id );
99
-		if ( null === $post ) {
98
+		$post = get_post($post_id);
99
+		if (null === $post) {
100 100
 			// Post not found.
101 101
 			return null;
102 102
 		}
103 103
 
104 104
 		// Get the post URI @id.
105
-		$id = Wordlift_Entity_Service::get_instance()->get_uri( $post->ID );
106
-		if ( $id === null ) {
107
-			$id = 'get_uri returned null, dataset is ' . wl_configuration_get_redlink_dataset_uri();
105
+		$id = Wordlift_Entity_Service::get_instance()->get_uri($post->ID);
106
+		if ($id === null) {
107
+			$id = 'get_uri returned null, dataset is '.wl_configuration_get_redlink_dataset_uri();
108 108
 		}
109 109
 
110 110
 		/*
@@ -116,8 +116,8 @@  discard block
 block discarded – undo
116 116
 		 */
117 117
 		// Get the entity @type. We consider `post` BlogPostings.
118 118
 		// $type = $this->entity_type_service->get( $post_id );
119
-		$types = $this->entity_type_service->get_names( $post_id );
120
-		$type  = self::make_one( $types );
119
+		$types = $this->entity_type_service->get_names($post_id);
120
+		$type  = self::make_one($types);
121 121
 
122 122
 		// Prepare the response.
123 123
 		$jsonld = array(
@@ -126,8 +126,8 @@  discard block
 block discarded – undo
126 126
 			'@type'    => $type,
127 127
 		);
128 128
 
129
-		if ( post_type_supports( $post->post_type, 'excerpt' ) ) {
130
-			$jsonld['description'] = Wordlift_Post_Excerpt_Helper::get_text_excerpt( $post );
129
+		if (post_type_supports($post->post_type, 'excerpt')) {
130
+			$jsonld['description'] = Wordlift_Post_Excerpt_Helper::get_text_excerpt($post);
131 131
 		}
132 132
 
133 133
 		// Set the `mainEntityOfPage` property if the post has some contents.
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
 		 *
140 140
 		 * @since 3.20.0
141 141
 		 */
142
-		$post_content = apply_filters( 'wl_post_content', $post->post_content, $post );
143
-		if ( ! empty( $post_content ) || in_array( 'Product', (array) $type, true ) ) {
142
+		$post_content = apply_filters('wl_post_content', $post->post_content, $post);
143
+		if ( ! empty($post_content) || in_array('Product', (array) $type, true)) {
144 144
 			// We're setting the `mainEntityOfPage` to signal which one is the
145 145
 			// main entity for the specified URL. It might be however that the
146 146
 			// post/page is actually about another specific entity. How WL deals
@@ -151,29 +151,29 @@  discard block
 block discarded – undo
151 151
 			// No need to specify `'@type' => 'WebPage'.
152 152
 			//
153 153
 			// See https://github.com/insideout10/wordlift-plugin/issues/451.
154
-			$jsonld['mainEntityOfPage'] = get_the_permalink( $post->ID );
154
+			$jsonld['mainEntityOfPage'] = get_the_permalink($post->ID);
155 155
 
156 156
 			/**
157 157
 			 * @see https://github.com/insideout10/wordlift-plugin/issues/1207
158 158
 			 *
159 159
 			 * @since 3.27.7
160 160
 			 */
161
-			if ( in_array(
161
+			if (in_array(
162 162
 				$type,
163 163
 				array(
164 164
 					'Occupation',
165 165
 					'OccupationAggregationByEmployer',
166 166
 				),
167 167
 				true
168
-			) ) {
168
+			)) {
169 169
 				$jsonld['mainEntityOfPage'] = array(
170 170
 					'@type'        => 'WebPage',
171
-					'lastReviewed' => get_post_time( 'Y-m-d\TH:i:sP', true, $post, false ),
171
+					'lastReviewed' => get_post_time('Y-m-d\TH:i:sP', true, $post, false),
172 172
 				);
173 173
 			}
174 174
 		};
175 175
 
176
-		$this->set_images( $this->attachment_service, $post, $jsonld );
176
+		$this->set_images($this->attachment_service, $post, $jsonld);
177 177
 
178 178
 		// Naveen: Get the entities referenced by this post and set it to the `references`
179 179
 		// array so that the caller can do further processing, such as printing out
@@ -187,18 +187,18 @@  discard block
 block discarded – undo
187 187
 		// $references_without_locations = $object_relation_service->get_references( $post_id, Object_Type_Enum::POST );
188 188
 
189 189
 		$relation_service = Relation_Service::get_instance();
190
-		$content_id       = Wordpress_Content_Id::create_post( $post_id );
191
-		$relation_service->add_relations( $content_id, $relations );
192
-		$this->add_relations_to_references( $relations, $references );
190
+		$content_id       = Wordpress_Content_Id::create_post($post_id);
191
+		$relation_service->add_relations($content_id, $relations);
192
+		$this->add_relations_to_references($relations, $references);
193 193
 
194
-		$this->expand_references_with_location( $references );
194
+		$this->expand_references_with_location($references);
195 195
 
196 196
 		return $jsonld;
197 197
 	}
198 198
 
199
-	public function expand_references_with_location( &$references ) {
199
+	public function expand_references_with_location(&$references) {
200 200
 		// Bail out if ACF isn't available.
201
-		if ( ! function_exists( 'get_field' ) ) {
201
+		if ( ! function_exists('get_field')) {
202 202
 			return;
203 203
 		}
204 204
 		$entity_type_service = Wordlift_Entity_Type_Service::get_instance();
@@ -206,30 +206,30 @@  discard block
 block discarded – undo
206 206
 		// check if any of the references has the entity type set to Action, Event or organisation.
207 207
 		$references_with_location = array_filter(
208 208
 			$references,
209
-			function ( $post_id ) use ( $entity_type_service ) {
210
-				return ( $entity_type_service->has_entity_type( $post_id, 'http://schema.org/Action' )
211
-						 || $entity_type_service->has_entity_type( $post_id, 'http://schema.org/Event' )
212
-						 || $entity_type_service->has_entity_type( $post_id, 'http://schema.org/Organization' ) );
209
+			function($post_id) use ($entity_type_service) {
210
+				return ($entity_type_service->has_entity_type($post_id, 'http://schema.org/Action')
211
+						 || $entity_type_service->has_entity_type($post_id, 'http://schema.org/Event')
212
+						 || $entity_type_service->has_entity_type($post_id, 'http://schema.org/Organization'));
213 213
 			}
214 214
 		);
215 215
 
216 216
 		// If set, then get all the location ids and push them to references.
217
-		foreach ( $references_with_location as $post_id ) {
217
+		foreach ($references_with_location as $post_id) {
218 218
 			// We need to know whether the user chose a `Place` or smtg else (we're not interested in smtg else).
219
-			$target_field = get_field( 'field_wl_18117ac085e38f4fc3b077340a9548ee7c9fb9f5_radio', $post_id );
220
-			if ( 1 !== preg_match( '@^.*_as_place$@', $target_field ) ) {
219
+			$target_field = get_field('field_wl_18117ac085e38f4fc3b077340a9548ee7c9fb9f5_radio', $post_id);
220
+			if (1 !== preg_match('@^.*_as_place$@', $target_field)) {
221 221
 				continue;
222 222
 			}
223 223
 
224 224
 			// Get the target posts
225
-			$target_posts = get_field( $target_field, $post_id );
226
-			if ( ! is_array( $target_posts ) || empty( $target_posts ) ) {
225
+			$target_posts = get_field($target_field, $post_id);
226
+			if ( ! is_array($target_posts) || empty($target_posts)) {
227 227
 				continue;
228 228
 			}
229 229
 
230 230
 			// Add the target posts to the references
231
-			foreach ( $target_posts as $target_post ) {
232
-				if ( ! is_a( $target_post, '\WP_Post' ) ) {
231
+			foreach ($target_posts as $target_post) {
232
+				if ( ! is_a($target_post, '\WP_Post')) {
233 233
 					continue;
234 234
 				}
235 235
 
@@ -238,12 +238,12 @@  discard block
 block discarded – undo
238 238
 		}
239 239
 
240 240
 		// Location as WP custom meta
241
-		foreach ( $references_with_location as $post_id ) {
242
-			$post_location_ids = get_post_meta( $post_id, Wordlift_Schema_Service::FIELD_LOCATION );
243
-			$post_location_ids = is_array( $post_location_ids ) ? $post_location_ids : array();
241
+		foreach ($references_with_location as $post_id) {
242
+			$post_location_ids = get_post_meta($post_id, Wordlift_Schema_Service::FIELD_LOCATION);
243
+			$post_location_ids = is_array($post_location_ids) ? $post_location_ids : array();
244 244
 			// Only numeric values here pls
245
-			$post_location_ids = array_filter( $post_location_ids, 'is_numeric' );
246
-			$references        = array_merge( $post_location_ids, $references );
245
+			$post_location_ids = array_filter($post_location_ids, 'is_numeric');
246
+			$references        = array_merge($post_location_ids, $references);
247 247
 		}
248 248
 
249 249
 	}
@@ -253,12 +253,12 @@  discard block
 block discarded – undo
253 253
 	 *
254 254
 	 * @param Relations $relations
255 255
 	 */
256
-	private function add_relations_to_references( $relations, &$references ) {
256
+	private function add_relations_to_references($relations, &$references) {
257 257
 		/** @var Relation $relation */
258
-		foreach ( $relations->toArray() as $relation ) {
258
+		foreach ($relations->toArray() as $relation) {
259 259
 			$object    = $relation->get_object();
260 260
 			$object_id = $object->get_id();
261
-			if ( $object->get_type() === Object_Type_Enum::POST && ! in_array( $object_id, $references, true ) ) {
261
+			if ($object->get_type() === Object_Type_Enum::POST && ! in_array($object_id, $references, true)) {
262 262
 				$references[] = $object_id;
263 263
 			}
264 264
 		}
@@ -301,8 +301,8 @@  discard block
 block discarded – undo
301 301
 	 * @return string The property value without the context.
302 302
 	 * @since 3.10.0
303 303
 	 */
304
-	public function relative_to_context( $value ) {
305
-		return ! is_array( $value ) && 0 === strpos( $value, self::CONTEXT . '/' ) ? substr( $value, strlen( self::CONTEXT ) + 1 ) : $value;
304
+	public function relative_to_context($value) {
305
+		return ! is_array($value) && 0 === strpos($value, self::CONTEXT.'/') ? substr($value, strlen(self::CONTEXT) + 1) : $value;
306 306
 	}
307 307
 
308 308
 	/**
@@ -317,14 +317,14 @@  discard block
 block discarded – undo
317 317
 	 *
318 318
 	 * @since 3.10.0
319 319
 	 */
320
-	public static function set_images( $attachment_service, $post, &$jsonld ) {
320
+	public static function set_images($attachment_service, $post, &$jsonld) {
321 321
 
322 322
 		// Prepare the attachment ids array.
323 323
 		$ids = array();
324 324
 
325 325
 		// Set the thumbnail id as first attachment id, if any.
326
-		$thumbnail_id = get_post_thumbnail_id( $post->ID );
327
-		if ( '' !== $thumbnail_id && 0 !== $thumbnail_id ) {
326
+		$thumbnail_id = get_post_thumbnail_id($post->ID);
327
+		if ('' !== $thumbnail_id && 0 !== $thumbnail_id) {
328 328
 			$ids[] = $thumbnail_id;
329 329
 		}
330 330
 
@@ -335,34 +335,34 @@  discard block
 block discarded – undo
335 335
 		//
336 336
 		// Get the embeds, removing existing ids.
337 337
 		// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
338
-		if ( apply_filters( 'wl_feature__enable__image-embeds', false ) ) {
339
-			$embeds = array_diff( $attachment_service->get_image_embeds( $post->post_content ), $ids );
338
+		if (apply_filters('wl_feature__enable__image-embeds', false)) {
339
+			$embeds = array_diff($attachment_service->get_image_embeds($post->post_content), $ids);
340 340
 		} else {
341 341
 			$embeds = array();
342 342
 		}
343 343
 
344 344
 		// Get the gallery, removing existing ids.
345
-		$gallery = array_diff( $attachment_service->get_gallery( $post ), $ids, $embeds );
345
+		$gallery = array_diff($attachment_service->get_gallery($post), $ids, $embeds);
346 346
 
347 347
 		// Map the attachment ids to images' data structured for schema.org use.
348 348
 		$images_with_sizes = array_filter(
349 349
 			array_reduce(
350
-				array_merge( $ids, $embeds, $gallery ),
351
-				function ( $carry, $item ) {
350
+				array_merge($ids, $embeds, $gallery),
351
+				function($carry, $item) {
352 352
 					/*
353 353
 					* @todo: we're not sure that we're getting attachment data here, we
354 354
 					* should filter `false`s.
355 355
 					*/
356 356
 
357 357
 					$sources = array_merge(
358
-						Wordlift_Image_Service::get_sources( $item ),
359
-						array( wp_get_attachment_image_src( $item, 'full' ) )
358
+						Wordlift_Image_Service::get_sources($item),
359
+						array(wp_get_attachment_image_src($item, 'full'))
360 360
 					);
361 361
 
362 362
 					$sources_with_image = array_filter(
363 363
 						$sources,
364
-						function ( $source ) {
365
-							return ! empty( $source[0] );
364
+						function($source) {
365
+							return ! empty($source[0]);
366 366
 						}
367 367
 					);
368 368
 
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
 					// or from uploads dir, but the image id still exists as featured image
377 377
 					// or in [gallery] shortcode.
378 378
 					// if ( empty( $attachment[0] ) ) {
379
-					if ( empty( $sources_with_image ) ) {
379
+					if (empty($sources_with_image)) {
380 380
 						return $carry;
381 381
 					}
382 382
 
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
 
395 395
 		// Refactor data as per schema.org specifications.
396 396
 		$images = array_map(
397
-			function ( $attachment ) {
397
+			function($attachment) {
398 398
 				return Wordlift_Abstract_Post_To_Jsonld_Converter::set_image_size(
399 399
 					array(
400 400
 						'@type' => 'ImageObject',
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 		);
408 408
 
409 409
 		// Add images if present.
410
-		if ( 0 < count( $images ) ) {
410
+		if (0 < count($images)) {
411 411
 			$jsonld['image'] = $images;
412 412
 		}
413 413
 
@@ -425,9 +425,9 @@  discard block
 block discarded – undo
425 425
 	 * @since  3.8.0
426 426
 	 * @access private
427 427
 	 */
428
-	protected static function make_one( $value ) {
428
+	protected static function make_one($value) {
429 429
 
430
-		return 1 === count( $value ) ? $value[0] : $value;
430
+		return 1 === count($value) ? $value[0] : $value;
431 431
 	}
432 432
 
433 433
 	/**
@@ -440,17 +440,17 @@  discard block
 block discarded – undo
440 440
 	 * @return array The enriched `ImageObject` array.
441 441
 	 * @since 3.14.0
442 442
 	 */
443
-	public static function set_image_size( $image, $attachment ) {
443
+	public static function set_image_size($image, $attachment) {
444 444
 
445 445
 		// If you specify a "width" or "height" value you should leave out
446 446
 		// 'px'. For example: "width":"4608px" should be "width":"4608".
447 447
 		//
448 448
 		// See https://github.com/insideout10/wordlift-plugin/issues/451.
449
-		if ( isset( $attachment[1] ) && is_numeric( $attachment[1] ) && 0 < $attachment[1] ) {
449
+		if (isset($attachment[1]) && is_numeric($attachment[1]) && 0 < $attachment[1]) {
450 450
 			$image['width'] = $attachment[1];
451 451
 		}
452 452
 
453
-		if ( isset( $attachment[2] ) && is_numeric( $attachment[2] ) && 0 < $attachment[2] ) {
453
+		if (isset($attachment[2]) && is_numeric($attachment[2]) && 0 < $attachment[2]) {
454 454
 			$image['height'] = $attachment[2];
455 455
 		}
456 456
 
@@ -469,33 +469,33 @@  discard block
 block discarded – undo
469 469
 	 * @since 3.20.0 This code moved from the above function `convert`, used for entity types defined in
470 470
 	 *  the {@link Wordlift_Schema_Service} class.
471 471
 	 */
472
-	protected function process_type_custom_fields( &$jsonld, $fields, $post, &$references, &$references_infos ) {
472
+	protected function process_type_custom_fields(&$jsonld, $fields, $post, &$references, &$references_infos) {
473 473
 
474 474
 		// Set a reference to use in closures.
475 475
 		$converter = $this;
476 476
 
477 477
 		// Try each field on the entity.
478
-		foreach ( $fields as $key => $value ) {
478
+		foreach ($fields as $key => $value) {
479 479
 
480 480
 			// Get the predicate.
481
-			$name = $this->relative_to_context( $value['predicate'] );
481
+			$name = $this->relative_to_context($value['predicate']);
482 482
 
483 483
 			// Get the value, the property service will get the right extractor
484 484
 			// for that property.
485
-			$value = $this->property_getter->get( $post->ID, $key, Object_Type_Enum::POST );
485
+			$value = $this->property_getter->get($post->ID, $key, Object_Type_Enum::POST);
486 486
 
487
-			if ( empty( $value ) ) {
487
+			if (empty($value)) {
488 488
 				continue;
489 489
 			}
490 490
 
491 491
 			// Map the value to the property name.
492 492
 			// If we got an array with just one value, we return that one value.
493 493
 			// If we got a Wordlift_Property_Entity_Reference we get the URL.
494
-			$jsonld[ $name ] = self::make_one(
494
+			$jsonld[$name] = self::make_one(
495 495
 				array_map(
496
-					function ( $item ) use ( $converter, &$references, &$references_infos ) {
496
+					function($item) use ($converter, &$references, &$references_infos) {
497 497
 
498
-						if ( $item instanceof Wordlift_Property_Entity_Reference ) {
498
+						if ($item instanceof Wordlift_Property_Entity_Reference) {
499 499
 
500 500
 							$url = $item->get_url();
501 501
 
@@ -504,12 +504,12 @@  discard block
 block discarded – undo
504 504
 							$references[] = $item->get_id();
505 505
 
506 506
 							// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
507
-							$references_infos[] = array( 'reference' => $item );
507
+							$references_infos[] = array('reference' => $item);
508 508
 
509
-							return array( '@id' => $url );
509
+							return array('@id' => $url);
510 510
 						}
511 511
 
512
-						return $converter->relative_to_context( $item );
512
+						return $converter->relative_to_context($item);
513 513
 					},
514 514
 					$value
515 515
 				)
Please login to merge, or discard this patch.
src/includes/class-wordlift-entity-uri-service.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -45,11 +45,11 @@  discard block
 block discarded – undo
45 45
 	 */
46 46
 	protected function __construct() {
47 47
 
48
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
48
+		$this->log = Wordlift_Log_Service::get_logger(get_class());
49 49
 
50 50
 		// Add a filter to the `rest_post_dispatch` filter to add the wl_entity_url meta as `wl:entity_url`.
51
-		add_filter( 'rest_post_dispatch', array( $this, 'rest_post_dispatch' ) );
52
-		add_filter( 'wl_content_service__post__not_found', array( $this, 'content_service__post__not_found' ), 10, 2 );
51
+		add_filter('rest_post_dispatch', array($this, 'rest_post_dispatch'));
52
+		add_filter('wl_content_service__post__not_found', array($this, 'content_service__post__not_found'), 10, 2);
53 53
 
54 54
 	}
55 55
 
@@ -70,9 +70,9 @@  discard block
 block discarded – undo
70 70
 	 */
71 71
 	public static function get_instance() {
72 72
 
73
-		if ( ! isset( self::$instance ) ) {
74
-			$entity_uri_cache_service = new Wordlift_File_Cache_Service( WL_TEMP_DIR . 'entity_uri/' );
75
-			self::$instance           = new Wordlift_Cached_Entity_Uri_Service( $entity_uri_cache_service );
73
+		if ( ! isset(self::$instance)) {
74
+			$entity_uri_cache_service = new Wordlift_File_Cache_Service(WL_TEMP_DIR.'entity_uri/');
75
+			self::$instance           = new Wordlift_Cached_Entity_Uri_Service($entity_uri_cache_service);
76 76
 
77 77
 		}
78 78
 
@@ -87,8 +87,8 @@  discard block
 block discarded – undo
87 87
 	 *
88 88
 	 * @return false|int
89 89
 	 */
90
-	public function content_service__post__not_found( $post, $uri ) {
91
-		return $this->get_post_id_from_url( $uri );
90
+	public function content_service__post__not_found($post, $uri) {
91
+		return $this->get_post_id_from_url($uri);
92 92
 	}
93 93
 
94 94
 	/**
@@ -101,18 +101,18 @@  discard block
 block discarded – undo
101 101
 	 *
102 102
 	 * @since 3.16.3
103 103
 	 */
104
-	public function preload_uris( $uris ) {
104
+	public function preload_uris($uris) {
105 105
 
106 106
 		// Bail out if there are no URIs.
107
-		if ( 0 === count( $uris ) ) {
107
+		if (0 === count($uris)) {
108 108
 			return;
109 109
 		}
110 110
 
111
-		$this->log->trace( 'Preloading ' . count( $uris ) . ' URI(s)...' );
111
+		$this->log->trace('Preloading '.count($uris).' URI(s)...');
112 112
 
113 113
 		global $wpdb;
114
-		$in_post_types  = implode( "','", array_map( 'esc_sql', Wordlift_Entity_Service::valid_entity_post_types() ) );
115
-		$in_entity_uris = implode( "','", array_map( 'esc_sql', $uris ) );
114
+		$in_post_types  = implode("','", array_map('esc_sql', Wordlift_Entity_Service::valid_entity_post_types()));
115
+		$in_entity_uris = implode("','", array_map('esc_sql', $uris));
116 116
 		$sql            = "
117 117
 			SELECT ID FROM $wpdb->posts p
118 118
 			INNER JOIN $wpdb->postmeta pm
@@ -124,33 +124,33 @@  discard block
 block discarded – undo
124 124
   		";
125 125
 
126 126
 		// Get the posts.
127
-		$posts = $wpdb->get_col( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
127
+		$posts = $wpdb->get_col($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
128 128
 
129 129
 		// Populate the array. We reinitialize the array on purpose because
130 130
 		// we don't want these data to long live.
131 131
 		$this->uri_to_post = array_reduce(
132 132
 			$posts,
133
-			function ( $carry, $item ) {
134
-				$uris = get_post_meta( $item, Wordlift_Schema_Service::FIELD_SAME_AS );
133
+			function($carry, $item) {
134
+				$uris = get_post_meta($item, Wordlift_Schema_Service::FIELD_SAME_AS);
135 135
 
136 136
 				$uri = Wordpress_Content_Service::get_instance()
137
-												->get_entity_id( Wordpress_Content_Id::create_post( $item ) );
137
+												->get_entity_id(Wordpress_Content_Id::create_post($item));
138 138
 
139
-				if ( isset( $uri ) ) {
139
+				if (isset($uri)) {
140 140
 					$uris[] = $uri;
141 141
 				}
142 142
 
143 143
 				return $carry
144 144
 					   // Get the URI related to the post and fill them with the item id.
145
-					   + array_fill_keys( $uris, $item );
145
+					   + array_fill_keys($uris, $item);
146 146
 			},
147 147
 			array()
148 148
 		);
149 149
 
150 150
 		// Add the not found URIs.
151
-		$this->uri_to_post += array_fill_keys( $uris, null );
151
+		$this->uri_to_post += array_fill_keys($uris, null);
152 152
 
153
-		$this->log->debug( count( $this->uri_to_post ) . ' URI(s) preloaded.' );
153
+		$this->log->debug(count($this->uri_to_post).' URI(s) preloaded.');
154 154
 
155 155
 	}
156 156
 
@@ -173,17 +173,17 @@  discard block
 block discarded – undo
173 173
 	 * @return WP_Post|null A WP_Post instance or null if not found.
174 174
 	 * @since 3.2.0
175 175
 	 */
176
-	public function get_entity( $uri ) {
177
-		if ( ! isset( $uri ) ) {
176
+	public function get_entity($uri) {
177
+		if ( ! isset($uri)) {
178 178
 			return null;
179 179
 		}
180 180
 
181
-		$this->log->trace( "Getting an entity post for URI $uri..." );
181
+		$this->log->trace("Getting an entity post for URI $uri...");
182 182
 
183
-		$content = Wordpress_Content_Service::get_instance()->get_by_entity_id_or_same_as( $uri );
183
+		$content = Wordpress_Content_Service::get_instance()->get_by_entity_id_or_same_as($uri);
184 184
 
185 185
 		// Return null if the content isn't found or isn't a post.
186
-		if ( ! isset( $content ) || ! is_a( $content->get_bag(), '\WP_Post' ) ) {
186
+		if ( ! isset($content) || ! is_a($content->get_bag(), '\WP_Post')) {
187 187
 			return null;
188 188
 		}
189 189
 
@@ -198,9 +198,9 @@  discard block
 block discarded – undo
198 198
 	 * @return true if the uri internal to the current dataset otherwise false.
199 199
 	 * @since 3.16.3
200 200
 	 */
201
-	public function is_internal( $uri ) {
201
+	public function is_internal($uri) {
202 202
 
203
-		return ( 0 === strrpos( $uri, (string) Wordlift_Configuration_Service::get_instance()->get_dataset_uri() ) );
203
+		return (0 === strrpos($uri, (string) Wordlift_Configuration_Service::get_instance()->get_dataset_uri()));
204 204
 	}
205 205
 
206 206
 	/**
@@ -215,19 +215,19 @@  discard block
 block discarded – undo
215 215
 	 *
216 216
 	 * @since 3.23.0
217 217
 	 */
218
-	public function rest_post_dispatch( $result ) {
218
+	public function rest_post_dispatch($result) {
219 219
 
220 220
 		// Get a reference to the actual data.
221 221
 		$data = &$result->data;
222 222
 
223 223
 		// Bail out if we don't have the required parameters, or if the type is not a valid entity.
224
-		if ( ! is_array( $data ) || ! isset( $data['id'] ) || ! isset( $data['type'] )
225
-			 || ! Wordlift_Entity_Type_Service::is_valid_entity_post_type( $data['type'] ) ) {
224
+		if ( ! is_array($data) || ! isset($data['id']) || ! isset($data['type'])
225
+			 || ! Wordlift_Entity_Type_Service::is_valid_entity_post_type($data['type'])) {
226 226
 			return $result;
227 227
 		}
228 228
 
229 229
 		// Add the `wl:entity_url`.
230
-		$data['wl:entity_url'] = Wordlift_Entity_Service::get_instance()->get_uri( $data['id'] );
230
+		$data['wl:entity_url'] = Wordlift_Entity_Service::get_instance()->get_uri($data['id']);
231 231
 
232 232
 		return $result;
233 233
 	}
@@ -240,31 +240,31 @@  discard block
 block discarded – undo
240 240
 	 *
241 241
 	 * @return int Post ID | bool false
242 242
 	 */
243
-	public function get_post_id_from_url( $url ) {
243
+	public function get_post_id_from_url($url) {
244 244
 
245 245
 		// Try url_to_postid
246
-		$post_id = url_to_postid( htmlspecialchars_decode( $url ) );
247
-		if ( 0 !== $post_id ) {
246
+		$post_id = url_to_postid(htmlspecialchars_decode($url));
247
+		if (0 !== $post_id) {
248 248
 			return $post_id;
249 249
 		}
250 250
 
251
-		$parsed_url = wp_parse_url( $url );
251
+		$parsed_url = wp_parse_url($url);
252 252
 
253
-		if ( ! isset( $parsed_url['query'] ) ) {
253
+		if ( ! isset($parsed_url['query'])) {
254 254
 			return false;
255 255
 		}
256 256
 
257
-		parse_str( $parsed_url['query'], $parsed_query );
257
+		parse_str($parsed_url['query'], $parsed_query);
258 258
 
259 259
 		// Try to parse WooCommerce non-pretty product URL
260
-		if ( $parsed_query['product'] ) {
260
+		if ($parsed_query['product']) {
261 261
 			$posts = get_posts(
262 262
 				array(
263 263
 					'name'      => $parsed_query['product'],
264 264
 					'post_type' => 'product',
265 265
 				)
266 266
 			);
267
-			if ( count( $posts ) > 0 ) {
267
+			if (count($posts) > 0) {
268 268
 				return $posts[0]->ID;
269 269
 			}
270 270
 		}
Please login to merge, or discard this patch.