Completed
Pull Request — master (#1641)
by Naveen
01:35
created
src/wordlift/jsonld/class-term-reference.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
 
14 14
 class Term_Reference extends Abstract_Reference {
15 15
 
16
-	public function get_type() {
17
-		return Object_Type_Enum::TERM;
18
-	}
16
+    public function get_type() {
17
+        return Object_Type_Enum::TERM;
18
+    }
19 19
 }
Please login to merge, or discard this patch.
src/wordlift/jsonld/class-jsonld-endpoint.php 2 patches
Indentation   +215 added lines, -215 removed lines patch added patch discarded remove patch
@@ -21,215 +21,215 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class Jsonld_Endpoint {
23 23
 
24
-	/**
25
-	 * The {@link Wordlift_Jsonld_Service} instance.
26
-	 *
27
-	 * @var Wordlift_Jsonld_Service The {@link Wordlift_Jsonld_Service} instance.
28
-	 */
29
-	private $jsonld_service;
30
-	/**
31
-	 * @var \Wordlift_Entity_Uri_Service
32
-	 */
33
-	private $entity_uri_service;
34
-
35
-	/**
36
-	 * Jsonld_Endpoint constructor.
37
-	 *
38
-	 * @param Jsonld_Service               $jsonld_service
39
-	 * @param \Wordlift_Entity_Uri_Service $entity_uri_service
40
-	 */
41
-	public function __construct( $jsonld_service, $entity_uri_service ) {
42
-
43
-		$this->jsonld_service     = $jsonld_service;
44
-		$this->entity_uri_service = $entity_uri_service;
45
-
46
-		// PHP 5.3 compatibility.
47
-		$that = $this;
48
-		add_action(
49
-			'rest_api_init',
50
-			function () use ( $that ) {
51
-				register_rest_route(
52
-					WL_REST_ROUTE_DEFAULT_NAMESPACE,
53
-					'/jsonld/(?P<id>\d+)',
54
-					array(
55
-						'methods'             => WP_REST_Server::READABLE,
56
-						'callback'            => array( $that, 'jsonld_using_post_id' ),
57
-						'permission_callback' => '__return_true',
58
-						'args'                => array(
59
-							'id' => array(
60
-								// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
61
-								'validate_callback' => function ( $param, $request, $key ) {
62
-									return is_numeric( $param );
63
-								},
64
-								'sanitize_callback' => 'absint',
65
-							),
66
-						),
67
-					)
68
-				);
69
-
70
-				register_rest_route(
71
-					WL_REST_ROUTE_DEFAULT_NAMESPACE,
72
-					'/jsonld/http/(?P<item_id>.*)',
73
-					array(
74
-						'methods'             => 'GET',
75
-						'callback'            => array( $that, 'jsonld_using_item_id' ),
76
-						'permission_callback' => '__return_true',
77
-					)
78
-				);
79
-
80
-				register_rest_route(
81
-					WL_REST_ROUTE_DEFAULT_NAMESPACE,
82
-					'/jsonld/post-meta/(?P<meta_key>[^/]+)',
83
-					array(
84
-						'methods'             => 'GET',
85
-						'callback'            => array( $that, 'jsonld_using_post_meta' ),
86
-						'permission_callback' => '__return_true',
87
-					)
88
-				);
89
-
90
-				register_rest_route(
91
-					WL_REST_ROUTE_DEFAULT_NAMESPACE,
92
-					'/jsonld/meta/(?P<meta_key>[^/]+)',
93
-					array(
94
-						'methods'             => 'GET',
95
-						'callback'            => array( $that, 'jsonld_using_meta' ),
96
-						'permission_callback' => '__return_true',
97
-					)
98
-				);
99
-
100
-				register_rest_route(
101
-					WL_REST_ROUTE_DEFAULT_NAMESPACE,
102
-					'/jsonld/(?P<post_type>.*)/(?P<post_name>.*)',
103
-					array(
104
-						'methods'             => 'GET',
105
-						'callback'            => array( $that, 'jsonld_using_get_page_by_path' ),
106
-						'permission_callback' => '__return_true',
107
-					)
108
-				);
109
-
110
-			}
111
-		);
112
-
113
-	}
114
-
115
-	/**
116
-	 * Callback for the JSON-LD request.
117
-	 *
118
-	 * @param array $request {
119
-	 *  The request array.
120
-	 *
121
-	 * @type int $id The post id.
122
-	 * }
123
-	 *
124
-	 * @return WP_REST_Response
125
-	 * @throws \Exception when an error occurs.
126
-	 */
127
-	public function jsonld_using_post_id( $request ) {
128
-
129
-		$post_id = $request['id'];
130
-		$type    = ( 0 === $post_id ? Object_Type_Enum::HOMEPAGE : Object_Type_Enum::POST );
131
-
132
-		// Send the generated JSON-LD.
133
-		$data = $this->jsonld_service->get( $type, $post_id, Jsonld_Context_Enum::REST );
134
-
135
-		return Jsonld_Response_Helper::to_response( $data );
136
-	}
137
-
138
-	/**
139
-	 * Provide a JSON-LD given the itemId.
140
-	 *
141
-	 * @param array $request {
142
-	 *  The request array.
143
-	 *
144
-	 * @type string $item_id The entity item id.
145
-	 * }
146
-	 *
147
-	 * @return WP_REST_Response
148
-	 * @throws \Exception when an error occurs.
149
-	 */
150
-	public function jsonld_using_item_id( $request ) {
151
-
152
-		$item_id = 'http://' . $request['item_id'];
153
-		$post    = $this->entity_uri_service->get_entity( $item_id );
154
-
155
-		if ( ! is_a( $post, 'WP_Post' ) ) {
156
-			return new WP_REST_Response( esc_html( "$item_id not found." ), 404, array( 'Content-Type' => 'text/html' ) );
157
-		}
158
-
159
-		return $this->jsonld_using_post_id( array( 'id' => $post->ID ) );
160
-	}
161
-
162
-	public function jsonld_using_get_page_by_path( $request ) {
163
-
164
-		$post_name = $request['post_name'];
165
-		$post_type = $request['post_type'];
166
-
167
-		global $wpdb;
168
-
169
-		$post_id = $wpdb->get_var(
170
-			$wpdb->prepare(
171
-				"
24
+    /**
25
+     * The {@link Wordlift_Jsonld_Service} instance.
26
+     *
27
+     * @var Wordlift_Jsonld_Service The {@link Wordlift_Jsonld_Service} instance.
28
+     */
29
+    private $jsonld_service;
30
+    /**
31
+     * @var \Wordlift_Entity_Uri_Service
32
+     */
33
+    private $entity_uri_service;
34
+
35
+    /**
36
+     * Jsonld_Endpoint constructor.
37
+     *
38
+     * @param Jsonld_Service               $jsonld_service
39
+     * @param \Wordlift_Entity_Uri_Service $entity_uri_service
40
+     */
41
+    public function __construct( $jsonld_service, $entity_uri_service ) {
42
+
43
+        $this->jsonld_service     = $jsonld_service;
44
+        $this->entity_uri_service = $entity_uri_service;
45
+
46
+        // PHP 5.3 compatibility.
47
+        $that = $this;
48
+        add_action(
49
+            'rest_api_init',
50
+            function () use ( $that ) {
51
+                register_rest_route(
52
+                    WL_REST_ROUTE_DEFAULT_NAMESPACE,
53
+                    '/jsonld/(?P<id>\d+)',
54
+                    array(
55
+                        'methods'             => WP_REST_Server::READABLE,
56
+                        'callback'            => array( $that, 'jsonld_using_post_id' ),
57
+                        'permission_callback' => '__return_true',
58
+                        'args'                => array(
59
+                            'id' => array(
60
+                                // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
61
+                                'validate_callback' => function ( $param, $request, $key ) {
62
+                                    return is_numeric( $param );
63
+                                },
64
+                                'sanitize_callback' => 'absint',
65
+                            ),
66
+                        ),
67
+                    )
68
+                );
69
+
70
+                register_rest_route(
71
+                    WL_REST_ROUTE_DEFAULT_NAMESPACE,
72
+                    '/jsonld/http/(?P<item_id>.*)',
73
+                    array(
74
+                        'methods'             => 'GET',
75
+                        'callback'            => array( $that, 'jsonld_using_item_id' ),
76
+                        'permission_callback' => '__return_true',
77
+                    )
78
+                );
79
+
80
+                register_rest_route(
81
+                    WL_REST_ROUTE_DEFAULT_NAMESPACE,
82
+                    '/jsonld/post-meta/(?P<meta_key>[^/]+)',
83
+                    array(
84
+                        'methods'             => 'GET',
85
+                        'callback'            => array( $that, 'jsonld_using_post_meta' ),
86
+                        'permission_callback' => '__return_true',
87
+                    )
88
+                );
89
+
90
+                register_rest_route(
91
+                    WL_REST_ROUTE_DEFAULT_NAMESPACE,
92
+                    '/jsonld/meta/(?P<meta_key>[^/]+)',
93
+                    array(
94
+                        'methods'             => 'GET',
95
+                        'callback'            => array( $that, 'jsonld_using_meta' ),
96
+                        'permission_callback' => '__return_true',
97
+                    )
98
+                );
99
+
100
+                register_rest_route(
101
+                    WL_REST_ROUTE_DEFAULT_NAMESPACE,
102
+                    '/jsonld/(?P<post_type>.*)/(?P<post_name>.*)',
103
+                    array(
104
+                        'methods'             => 'GET',
105
+                        'callback'            => array( $that, 'jsonld_using_get_page_by_path' ),
106
+                        'permission_callback' => '__return_true',
107
+                    )
108
+                );
109
+
110
+            }
111
+        );
112
+
113
+    }
114
+
115
+    /**
116
+     * Callback for the JSON-LD request.
117
+     *
118
+     * @param array $request {
119
+     *  The request array.
120
+     *
121
+     * @type int $id The post id.
122
+     * }
123
+     *
124
+     * @return WP_REST_Response
125
+     * @throws \Exception when an error occurs.
126
+     */
127
+    public function jsonld_using_post_id( $request ) {
128
+
129
+        $post_id = $request['id'];
130
+        $type    = ( 0 === $post_id ? Object_Type_Enum::HOMEPAGE : Object_Type_Enum::POST );
131
+
132
+        // Send the generated JSON-LD.
133
+        $data = $this->jsonld_service->get( $type, $post_id, Jsonld_Context_Enum::REST );
134
+
135
+        return Jsonld_Response_Helper::to_response( $data );
136
+    }
137
+
138
+    /**
139
+     * Provide a JSON-LD given the itemId.
140
+     *
141
+     * @param array $request {
142
+     *  The request array.
143
+     *
144
+     * @type string $item_id The entity item id.
145
+     * }
146
+     *
147
+     * @return WP_REST_Response
148
+     * @throws \Exception when an error occurs.
149
+     */
150
+    public function jsonld_using_item_id( $request ) {
151
+
152
+        $item_id = 'http://' . $request['item_id'];
153
+        $post    = $this->entity_uri_service->get_entity( $item_id );
154
+
155
+        if ( ! is_a( $post, 'WP_Post' ) ) {
156
+            return new WP_REST_Response( esc_html( "$item_id not found." ), 404, array( 'Content-Type' => 'text/html' ) );
157
+        }
158
+
159
+        return $this->jsonld_using_post_id( array( 'id' => $post->ID ) );
160
+    }
161
+
162
+    public function jsonld_using_get_page_by_path( $request ) {
163
+
164
+        $post_name = $request['post_name'];
165
+        $post_type = $request['post_type'];
166
+
167
+        global $wpdb;
168
+
169
+        $post_id = $wpdb->get_var(
170
+            $wpdb->prepare(
171
+                "
172 172
 			SELECT ID
173 173
 			FROM $wpdb->posts
174 174
 			WHERE post_name = %s
175 175
 			 AND post_type = %s
176 176
 		",
177
-				$post_name,
178
-				$post_type
179
-			)
180
-		);
181
-
182
-		if ( $post_id === null ) {
183
-			return new WP_REST_Response( esc_html( "$post_name of type $post_type not found." ), 404, array( 'Content-Type' => 'text/html' ) );
184
-		}
185
-
186
-		return $this->jsonld_using_post_id( array( 'id' => $post_id ) );
187
-	}
188
-
189
-	/**
190
-	 * @param WP_REST_Request $request
191
-	 *
192
-	 * @return WP_REST_Response
193
-	 * @throws \Exception when an error occurs.
194
-	 */
195
-	public function jsonld_using_post_meta( $request ) {
196
-
197
-		$meta_key   = $request['meta_key'];
198
-		$meta_value = urldecode( current( $request->get_query_params( 'meta_value' ) ) );
199
-
200
-		global $wpdb;
201
-
202
-		$post_id = $wpdb->get_var(
203
-			$wpdb->prepare(
204
-				"
177
+                $post_name,
178
+                $post_type
179
+            )
180
+        );
181
+
182
+        if ( $post_id === null ) {
183
+            return new WP_REST_Response( esc_html( "$post_name of type $post_type not found." ), 404, array( 'Content-Type' => 'text/html' ) );
184
+        }
185
+
186
+        return $this->jsonld_using_post_id( array( 'id' => $post_id ) );
187
+    }
188
+
189
+    /**
190
+     * @param WP_REST_Request $request
191
+     *
192
+     * @return WP_REST_Response
193
+     * @throws \Exception when an error occurs.
194
+     */
195
+    public function jsonld_using_post_meta( $request ) {
196
+
197
+        $meta_key   = $request['meta_key'];
198
+        $meta_value = urldecode( current( $request->get_query_params( 'meta_value' ) ) );
199
+
200
+        global $wpdb;
201
+
202
+        $post_id = $wpdb->get_var(
203
+            $wpdb->prepare(
204
+                "
205 205
 			SELECT post_id AS ID
206 206
 			FROM $wpdb->postmeta
207 207
 			WHERE meta_key = %s
208 208
 			 AND meta_value = %s
209 209
 			LIMIT 1
210 210
 		",
211
-				$meta_key,
212
-				$meta_value
213
-			)
214
-		);
211
+                $meta_key,
212
+                $meta_value
213
+            )
214
+        );
215 215
 
216
-		if ( $post_id === null ) {
217
-			return new WP_REST_Response( esc_html( "Post with meta key $meta_key and value $meta_value not found." ), 404, array( 'Content-Type' => 'text/html' ) );
218
-		}
216
+        if ( $post_id === null ) {
217
+            return new WP_REST_Response( esc_html( "Post with meta key $meta_key and value $meta_value not found." ), 404, array( 'Content-Type' => 'text/html' ) );
218
+        }
219 219
 
220
-		return $this->jsonld_using_post_id( array( 'id' => $post_id ) );
221
-	}
220
+        return $this->jsonld_using_post_id( array( 'id' => $post_id ) );
221
+    }
222 222
 
223
-	public function jsonld_using_meta( $request ) {
223
+    public function jsonld_using_meta( $request ) {
224 224
 
225
-		global $wpdb;
225
+        global $wpdb;
226 226
 
227
-		$meta_key   = $request['meta_key'];
228
-		$meta_value = urldecode( current( $request->get_query_params( 'meta_value' ) ) );
227
+        $meta_key   = $request['meta_key'];
228
+        $meta_value = urldecode( current( $request->get_query_params( 'meta_value' ) ) );
229 229
 
230
-		$results = $wpdb->get_results(
231
-			$wpdb->prepare(
232
-				"
230
+        $results = $wpdb->get_results(
231
+            $wpdb->prepare(
232
+                "
233 233
 			SELECT pm.post_id AS id, %s AS type
234 234
 			 FROM {$wpdb->postmeta} pm
235 235
 			 	INNER JOIN {$wpdb->posts} p
@@ -240,28 +240,28 @@  discard block
 block discarded – undo
240 240
 			 FROM {$wpdb->termmeta}
241 241
 			 WHERE meta_key = %s AND meta_value = %s
242 242
 			",
243
-				Object_Type_Enum::POST,
244
-				$meta_key,
245
-				$meta_value,
246
-				Object_Type_Enum::TERM,
247
-				$meta_key,
248
-				$meta_value
249
-			)
250
-		);
251
-
252
-		$jsonld_service = $this->jsonld_service;
253
-
254
-		$data = array_reduce(
255
-			$results,
256
-			function ( $carry, $result ) use ( $jsonld_service ) {
257
-				$jsonld = $jsonld_service->get( $result->type, $result->id, Jsonld_Context_Enum::REST );
258
-
259
-				return array_merge( $carry, $jsonld );
260
-			},
261
-			array()
262
-		);
263
-
264
-		return Jsonld_Response_Helper::to_response( $data );
265
-	}
243
+                Object_Type_Enum::POST,
244
+                $meta_key,
245
+                $meta_value,
246
+                Object_Type_Enum::TERM,
247
+                $meta_key,
248
+                $meta_value
249
+            )
250
+        );
251
+
252
+        $jsonld_service = $this->jsonld_service;
253
+
254
+        $data = array_reduce(
255
+            $results,
256
+            function ( $carry, $result ) use ( $jsonld_service ) {
257
+                $jsonld = $jsonld_service->get( $result->type, $result->id, Jsonld_Context_Enum::REST );
258
+
259
+                return array_merge( $carry, $jsonld );
260
+            },
261
+            array()
262
+        );
263
+
264
+        return Jsonld_Response_Helper::to_response( $data );
265
+    }
266 266
 
267 267
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	 * @param Jsonld_Service               $jsonld_service
39 39
 	 * @param \Wordlift_Entity_Uri_Service $entity_uri_service
40 40
 	 */
41
-	public function __construct( $jsonld_service, $entity_uri_service ) {
41
+	public function __construct($jsonld_service, $entity_uri_service) {
42 42
 
43 43
 		$this->jsonld_service     = $jsonld_service;
44 44
 		$this->entity_uri_service = $entity_uri_service;
@@ -47,19 +47,19 @@  discard block
 block discarded – undo
47 47
 		$that = $this;
48 48
 		add_action(
49 49
 			'rest_api_init',
50
-			function () use ( $that ) {
50
+			function() use ($that) {
51 51
 				register_rest_route(
52 52
 					WL_REST_ROUTE_DEFAULT_NAMESPACE,
53 53
 					'/jsonld/(?P<id>\d+)',
54 54
 					array(
55 55
 						'methods'             => WP_REST_Server::READABLE,
56
-						'callback'            => array( $that, 'jsonld_using_post_id' ),
56
+						'callback'            => array($that, 'jsonld_using_post_id'),
57 57
 						'permission_callback' => '__return_true',
58 58
 						'args'                => array(
59 59
 							'id' => array(
60 60
 								// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
61
-								'validate_callback' => function ( $param, $request, $key ) {
62
-									return is_numeric( $param );
61
+								'validate_callback' => function($param, $request, $key) {
62
+									return is_numeric($param);
63 63
 								},
64 64
 								'sanitize_callback' => 'absint',
65 65
 							),
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 					'/jsonld/http/(?P<item_id>.*)',
73 73
 					array(
74 74
 						'methods'             => 'GET',
75
-						'callback'            => array( $that, 'jsonld_using_item_id' ),
75
+						'callback'            => array($that, 'jsonld_using_item_id'),
76 76
 						'permission_callback' => '__return_true',
77 77
 					)
78 78
 				);
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 					'/jsonld/post-meta/(?P<meta_key>[^/]+)',
83 83
 					array(
84 84
 						'methods'             => 'GET',
85
-						'callback'            => array( $that, 'jsonld_using_post_meta' ),
85
+						'callback'            => array($that, 'jsonld_using_post_meta'),
86 86
 						'permission_callback' => '__return_true',
87 87
 					)
88 88
 				);
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 					'/jsonld/meta/(?P<meta_key>[^/]+)',
93 93
 					array(
94 94
 						'methods'             => 'GET',
95
-						'callback'            => array( $that, 'jsonld_using_meta' ),
95
+						'callback'            => array($that, 'jsonld_using_meta'),
96 96
 						'permission_callback' => '__return_true',
97 97
 					)
98 98
 				);
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 					'/jsonld/(?P<post_type>.*)/(?P<post_name>.*)',
103 103
 					array(
104 104
 						'methods'             => 'GET',
105
-						'callback'            => array( $that, 'jsonld_using_get_page_by_path' ),
105
+						'callback'            => array($that, 'jsonld_using_get_page_by_path'),
106 106
 						'permission_callback' => '__return_true',
107 107
 					)
108 108
 				);
@@ -124,15 +124,15 @@  discard block
 block discarded – undo
124 124
 	 * @return WP_REST_Response
125 125
 	 * @throws \Exception when an error occurs.
126 126
 	 */
127
-	public function jsonld_using_post_id( $request ) {
127
+	public function jsonld_using_post_id($request) {
128 128
 
129 129
 		$post_id = $request['id'];
130
-		$type    = ( 0 === $post_id ? Object_Type_Enum::HOMEPAGE : Object_Type_Enum::POST );
130
+		$type    = (0 === $post_id ? Object_Type_Enum::HOMEPAGE : Object_Type_Enum::POST);
131 131
 
132 132
 		// Send the generated JSON-LD.
133
-		$data = $this->jsonld_service->get( $type, $post_id, Jsonld_Context_Enum::REST );
133
+		$data = $this->jsonld_service->get($type, $post_id, Jsonld_Context_Enum::REST);
134 134
 
135
-		return Jsonld_Response_Helper::to_response( $data );
135
+		return Jsonld_Response_Helper::to_response($data);
136 136
 	}
137 137
 
138 138
 	/**
@@ -147,19 +147,19 @@  discard block
 block discarded – undo
147 147
 	 * @return WP_REST_Response
148 148
 	 * @throws \Exception when an error occurs.
149 149
 	 */
150
-	public function jsonld_using_item_id( $request ) {
150
+	public function jsonld_using_item_id($request) {
151 151
 
152
-		$item_id = 'http://' . $request['item_id'];
153
-		$post    = $this->entity_uri_service->get_entity( $item_id );
152
+		$item_id = 'http://'.$request['item_id'];
153
+		$post    = $this->entity_uri_service->get_entity($item_id);
154 154
 
155
-		if ( ! is_a( $post, 'WP_Post' ) ) {
156
-			return new WP_REST_Response( esc_html( "$item_id not found." ), 404, array( 'Content-Type' => 'text/html' ) );
155
+		if ( ! is_a($post, 'WP_Post')) {
156
+			return new WP_REST_Response(esc_html("$item_id not found."), 404, array('Content-Type' => 'text/html'));
157 157
 		}
158 158
 
159
-		return $this->jsonld_using_post_id( array( 'id' => $post->ID ) );
159
+		return $this->jsonld_using_post_id(array('id' => $post->ID));
160 160
 	}
161 161
 
162
-	public function jsonld_using_get_page_by_path( $request ) {
162
+	public function jsonld_using_get_page_by_path($request) {
163 163
 
164 164
 		$post_name = $request['post_name'];
165 165
 		$post_type = $request['post_type'];
@@ -179,11 +179,11 @@  discard block
 block discarded – undo
179 179
 			)
180 180
 		);
181 181
 
182
-		if ( $post_id === null ) {
183
-			return new WP_REST_Response( esc_html( "$post_name of type $post_type not found." ), 404, array( 'Content-Type' => 'text/html' ) );
182
+		if ($post_id === null) {
183
+			return new WP_REST_Response(esc_html("$post_name of type $post_type not found."), 404, array('Content-Type' => 'text/html'));
184 184
 		}
185 185
 
186
-		return $this->jsonld_using_post_id( array( 'id' => $post_id ) );
186
+		return $this->jsonld_using_post_id(array('id' => $post_id));
187 187
 	}
188 188
 
189 189
 	/**
@@ -192,10 +192,10 @@  discard block
 block discarded – undo
192 192
 	 * @return WP_REST_Response
193 193
 	 * @throws \Exception when an error occurs.
194 194
 	 */
195
-	public function jsonld_using_post_meta( $request ) {
195
+	public function jsonld_using_post_meta($request) {
196 196
 
197 197
 		$meta_key   = $request['meta_key'];
198
-		$meta_value = urldecode( current( $request->get_query_params( 'meta_value' ) ) );
198
+		$meta_value = urldecode(current($request->get_query_params('meta_value')));
199 199
 
200 200
 		global $wpdb;
201 201
 
@@ -213,19 +213,19 @@  discard block
 block discarded – undo
213 213
 			)
214 214
 		);
215 215
 
216
-		if ( $post_id === null ) {
217
-			return new WP_REST_Response( esc_html( "Post with meta key $meta_key and value $meta_value not found." ), 404, array( 'Content-Type' => 'text/html' ) );
216
+		if ($post_id === null) {
217
+			return new WP_REST_Response(esc_html("Post with meta key $meta_key and value $meta_value not found."), 404, array('Content-Type' => 'text/html'));
218 218
 		}
219 219
 
220
-		return $this->jsonld_using_post_id( array( 'id' => $post_id ) );
220
+		return $this->jsonld_using_post_id(array('id' => $post_id));
221 221
 	}
222 222
 
223
-	public function jsonld_using_meta( $request ) {
223
+	public function jsonld_using_meta($request) {
224 224
 
225 225
 		global $wpdb;
226 226
 
227 227
 		$meta_key   = $request['meta_key'];
228
-		$meta_value = urldecode( current( $request->get_query_params( 'meta_value' ) ) );
228
+		$meta_value = urldecode(current($request->get_query_params('meta_value')));
229 229
 
230 230
 		$results = $wpdb->get_results(
231 231
 			$wpdb->prepare(
@@ -253,15 +253,15 @@  discard block
 block discarded – undo
253 253
 
254 254
 		$data = array_reduce(
255 255
 			$results,
256
-			function ( $carry, $result ) use ( $jsonld_service ) {
257
-				$jsonld = $jsonld_service->get( $result->type, $result->id, Jsonld_Context_Enum::REST );
256
+			function($carry, $result) use ($jsonld_service) {
257
+				$jsonld = $jsonld_service->get($result->type, $result->id, Jsonld_Context_Enum::REST);
258 258
 
259
-				return array_merge( $carry, $jsonld );
259
+				return array_merge($carry, $jsonld);
260 260
 			},
261 261
 			array()
262 262
 		);
263 263
 
264
-		return Jsonld_Response_Helper::to_response( $data );
264
+		return Jsonld_Response_Helper::to_response($data);
265 265
 	}
266 266
 
267 267
 }
Please login to merge, or discard this patch.
src/wordlift/jsonld/class-post-reference.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
 
14 14
 class Post_Reference extends Abstract_Reference {
15 15
 
16
-	public function get_type() {
17
-		return Object_Type_Enum::POST;
18
-	}
16
+    public function get_type() {
17
+        return Object_Type_Enum::POST;
18
+    }
19 19
 }
Please login to merge, or discard this patch.
src/wordlift/jsonld/class-jsonld-user-service.php 2 patches
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -6,76 +6,76 @@
 block discarded – undo
6 6
 
7 7
 class Jsonld_User_Service {
8 8
 
9
-	/**
10
-	 * @var \Wordlift_User_Service $user_service
11
-	 */
12
-	private $user_service;
13
-
14
-	/**
15
-	 * @var Jsonld_Service
16
-	 */
17
-	private $jsonld_service;
18
-
19
-	/**
20
-	 * Jsonld_User_Service constructor.
21
-	 *
22
-	 * @param \Wordlift_User_Service $user_service
23
-	 */
24
-	public function __construct( $user_service ) {
25
-		$this->user_service = $user_service;
26
-	}
27
-
28
-	/**
29
-	 * @param Jsonld_Service $jsonld_service
30
-	 */
31
-	public function set_jsonld_service( $jsonld_service ) {
32
-		$this->jsonld_service = $jsonld_service;
33
-	}
34
-
35
-	public function get( $user_id ) {
36
-		$userdata = get_userdata( $user_id );
37
-
38
-		// Bail out if user not found.
39
-		if ( ! ( $userdata instanceof \WP_User ) ) {
40
-			return array();
41
-		}
42
-
43
-		// Return the post JSON-LD if a post has been bound to this user.
44
-		$post_id = $this->user_service->get_entity( $user_id );
45
-		if ( ! empty( $post_id ) && isset( $this->jsonld_service ) ) {
46
-			return $this->jsonld_service->get( Object_Type_Enum::POST, $post_id );
47
-		}
48
-
49
-		// Bail out if the user doesn't have a valid URI.
50
-		$uri = $this->user_service->get_uri( $user_id );
51
-		if ( empty( $uri ) ) {
52
-			return array();
53
-		}
54
-
55
-		// Finally return the user's JSON-LD.
56
-		$data = array(
57
-			'@context' => 'http://schema.org',
58
-			'@id'      => $uri,
59
-			'@type'    => 'Person',
60
-		);
61
-
62
-		if ( ! empty( $userdata->display_name ) ) {
63
-			$data['name'] = $userdata->display_name;
64
-		}
65
-
66
-		if ( ! empty( $userdata->first_name ) ) {
67
-			$data['givenName'] = $userdata->first_name;
68
-		}
69
-
70
-		if ( ! empty( $userdata->last_name ) ) {
71
-			$data['familyName'] = $userdata->last_name;
72
-		}
73
-
74
-		if ( ! empty( $userdata->user_url ) ) {
75
-			$data['url'] = $userdata->user_url;
76
-		}
77
-
78
-		return array( $data );
79
-	}
9
+    /**
10
+     * @var \Wordlift_User_Service $user_service
11
+     */
12
+    private $user_service;
13
+
14
+    /**
15
+     * @var Jsonld_Service
16
+     */
17
+    private $jsonld_service;
18
+
19
+    /**
20
+     * Jsonld_User_Service constructor.
21
+     *
22
+     * @param \Wordlift_User_Service $user_service
23
+     */
24
+    public function __construct( $user_service ) {
25
+        $this->user_service = $user_service;
26
+    }
27
+
28
+    /**
29
+     * @param Jsonld_Service $jsonld_service
30
+     */
31
+    public function set_jsonld_service( $jsonld_service ) {
32
+        $this->jsonld_service = $jsonld_service;
33
+    }
34
+
35
+    public function get( $user_id ) {
36
+        $userdata = get_userdata( $user_id );
37
+
38
+        // Bail out if user not found.
39
+        if ( ! ( $userdata instanceof \WP_User ) ) {
40
+            return array();
41
+        }
42
+
43
+        // Return the post JSON-LD if a post has been bound to this user.
44
+        $post_id = $this->user_service->get_entity( $user_id );
45
+        if ( ! empty( $post_id ) && isset( $this->jsonld_service ) ) {
46
+            return $this->jsonld_service->get( Object_Type_Enum::POST, $post_id );
47
+        }
48
+
49
+        // Bail out if the user doesn't have a valid URI.
50
+        $uri = $this->user_service->get_uri( $user_id );
51
+        if ( empty( $uri ) ) {
52
+            return array();
53
+        }
54
+
55
+        // Finally return the user's JSON-LD.
56
+        $data = array(
57
+            '@context' => 'http://schema.org',
58
+            '@id'      => $uri,
59
+            '@type'    => 'Person',
60
+        );
61
+
62
+        if ( ! empty( $userdata->display_name ) ) {
63
+            $data['name'] = $userdata->display_name;
64
+        }
65
+
66
+        if ( ! empty( $userdata->first_name ) ) {
67
+            $data['givenName'] = $userdata->first_name;
68
+        }
69
+
70
+        if ( ! empty( $userdata->last_name ) ) {
71
+            $data['familyName'] = $userdata->last_name;
72
+        }
73
+
74
+        if ( ! empty( $userdata->user_url ) ) {
75
+            $data['url'] = $userdata->user_url;
76
+        }
77
+
78
+        return array( $data );
79
+    }
80 80
 
81 81
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -21,34 +21,34 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @param \Wordlift_User_Service $user_service
23 23
 	 */
24
-	public function __construct( $user_service ) {
24
+	public function __construct($user_service) {
25 25
 		$this->user_service = $user_service;
26 26
 	}
27 27
 
28 28
 	/**
29 29
 	 * @param Jsonld_Service $jsonld_service
30 30
 	 */
31
-	public function set_jsonld_service( $jsonld_service ) {
31
+	public function set_jsonld_service($jsonld_service) {
32 32
 		$this->jsonld_service = $jsonld_service;
33 33
 	}
34 34
 
35
-	public function get( $user_id ) {
36
-		$userdata = get_userdata( $user_id );
35
+	public function get($user_id) {
36
+		$userdata = get_userdata($user_id);
37 37
 
38 38
 		// Bail out if user not found.
39
-		if ( ! ( $userdata instanceof \WP_User ) ) {
39
+		if ( ! ($userdata instanceof \WP_User)) {
40 40
 			return array();
41 41
 		}
42 42
 
43 43
 		// Return the post JSON-LD if a post has been bound to this user.
44
-		$post_id = $this->user_service->get_entity( $user_id );
45
-		if ( ! empty( $post_id ) && isset( $this->jsonld_service ) ) {
46
-			return $this->jsonld_service->get( Object_Type_Enum::POST, $post_id );
44
+		$post_id = $this->user_service->get_entity($user_id);
45
+		if ( ! empty($post_id) && isset($this->jsonld_service)) {
46
+			return $this->jsonld_service->get(Object_Type_Enum::POST, $post_id);
47 47
 		}
48 48
 
49 49
 		// Bail out if the user doesn't have a valid URI.
50
-		$uri = $this->user_service->get_uri( $user_id );
51
-		if ( empty( $uri ) ) {
50
+		$uri = $this->user_service->get_uri($user_id);
51
+		if (empty($uri)) {
52 52
 			return array();
53 53
 		}
54 54
 
@@ -59,23 +59,23 @@  discard block
 block discarded – undo
59 59
 			'@type'    => 'Person',
60 60
 		);
61 61
 
62
-		if ( ! empty( $userdata->display_name ) ) {
62
+		if ( ! empty($userdata->display_name)) {
63 63
 			$data['name'] = $userdata->display_name;
64 64
 		}
65 65
 
66
-		if ( ! empty( $userdata->first_name ) ) {
66
+		if ( ! empty($userdata->first_name)) {
67 67
 			$data['givenName'] = $userdata->first_name;
68 68
 		}
69 69
 
70
-		if ( ! empty( $userdata->last_name ) ) {
70
+		if ( ! empty($userdata->last_name)) {
71 71
 			$data['familyName'] = $userdata->last_name;
72 72
 		}
73 73
 
74
-		if ( ! empty( $userdata->user_url ) ) {
74
+		if ( ! empty($userdata->user_url)) {
75 75
 			$data['url'] = $userdata->user_url;
76 76
 		}
77 77
 
78
-		return array( $data );
78
+		return array($data);
79 79
 	}
80 80
 
81 81
 }
Please login to merge, or discard this patch.
src/wordlift/analysis/entity-provider/class-term-entity-provider.php 2 patches
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -15,41 +15,41 @@
 block discarded – undo
15 15
 
16 16
 class Term_Entity_Provider implements Entity_Provider {
17 17
 
18
-	/**
19
-	 * @var Type_Service
20
-	 */
21
-	private $term_type_service;
22
-
23
-	public function __construct() {
24
-		$this->term_type_service = Type_Service::get_instance();
25
-	}
26
-
27
-	public function get_entity( $uri ) {
28
-
29
-		$content = Wordpress_Term_Content_Legacy_Service::get_instance()->get_by_entity_id_or_same_as( $uri );
30
-
31
-		if ( ! isset( $content ) ) {
32
-			return false;
33
-		}
34
-
35
-		$term    = $content->get_bag();
36
-		$term_id = $term->term_id;
37
-
38
-		$schema = $this->term_type_service->get_schema( $term_id );
39
-		// @todo: For now we dont support images
40
-		// $images = $this->post_image_storage->get( $term_entity->ID );
41
-		$same_as = get_term_meta( $term_id, 'entity_same_as' );
42
-		$same_as = $same_as ? $same_as : array();
43
-
44
-		return (object) array(
45
-			'id'          => $uri,
46
-			'label'       => $term->name,
47
-			'description' => '',
48
-			'sameAs'      => $same_as,
49
-			'mainType'    => str_replace( 'wl-', '', $schema['css_class'] ),
50
-			'types'       => $this->term_type_service->get_entity_types_labels( $term_id ),
51
-			'images'      => array(),
52
-		);
53
-	}
18
+    /**
19
+     * @var Type_Service
20
+     */
21
+    private $term_type_service;
22
+
23
+    public function __construct() {
24
+        $this->term_type_service = Type_Service::get_instance();
25
+    }
26
+
27
+    public function get_entity( $uri ) {
28
+
29
+        $content = Wordpress_Term_Content_Legacy_Service::get_instance()->get_by_entity_id_or_same_as( $uri );
30
+
31
+        if ( ! isset( $content ) ) {
32
+            return false;
33
+        }
34
+
35
+        $term    = $content->get_bag();
36
+        $term_id = $term->term_id;
37
+
38
+        $schema = $this->term_type_service->get_schema( $term_id );
39
+        // @todo: For now we dont support images
40
+        // $images = $this->post_image_storage->get( $term_entity->ID );
41
+        $same_as = get_term_meta( $term_id, 'entity_same_as' );
42
+        $same_as = $same_as ? $same_as : array();
43
+
44
+        return (object) array(
45
+            'id'          => $uri,
46
+            'label'       => $term->name,
47
+            'description' => '',
48
+            'sameAs'      => $same_as,
49
+            'mainType'    => str_replace( 'wl-', '', $schema['css_class'] ),
50
+            'types'       => $this->term_type_service->get_entity_types_labels( $term_id ),
51
+            'images'      => array(),
52
+        );
53
+    }
54 54
 
55 55
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -24,21 +24,21 @@  discard block
 block discarded – undo
24 24
 		$this->term_type_service = Type_Service::get_instance();
25 25
 	}
26 26
 
27
-	public function get_entity( $uri ) {
27
+	public function get_entity($uri) {
28 28
 
29
-		$content = Wordpress_Term_Content_Legacy_Service::get_instance()->get_by_entity_id_or_same_as( $uri );
29
+		$content = Wordpress_Term_Content_Legacy_Service::get_instance()->get_by_entity_id_or_same_as($uri);
30 30
 
31
-		if ( ! isset( $content ) ) {
31
+		if ( ! isset($content)) {
32 32
 			return false;
33 33
 		}
34 34
 
35 35
 		$term    = $content->get_bag();
36 36
 		$term_id = $term->term_id;
37 37
 
38
-		$schema = $this->term_type_service->get_schema( $term_id );
38
+		$schema = $this->term_type_service->get_schema($term_id);
39 39
 		// @todo: For now we dont support images
40 40
 		// $images = $this->post_image_storage->get( $term_entity->ID );
41
-		$same_as = get_term_meta( $term_id, 'entity_same_as' );
41
+		$same_as = get_term_meta($term_id, 'entity_same_as');
42 42
 		$same_as = $same_as ? $same_as : array();
43 43
 
44 44
 		return (object) array(
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
 			'label'       => $term->name,
47 47
 			'description' => '',
48 48
 			'sameAs'      => $same_as,
49
-			'mainType'    => str_replace( 'wl-', '', $schema['css_class'] ),
50
-			'types'       => $this->term_type_service->get_entity_types_labels( $term_id ),
49
+			'mainType'    => str_replace('wl-', '', $schema['css_class']),
50
+			'types'       => $this->term_type_service->get_entity_types_labels($term_id),
51 51
 			'images'      => array(),
52 52
 		);
53 53
 	}
Please login to merge, or discard this patch.
src/wordlift/analysis/entity-provider/class-entity-provider.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,6 +4,6 @@
 block discarded – undo
4 4
 
5 5
 interface Entity_Provider {
6 6
 
7
-	public function get_entity( $uri );
7
+    public function get_entity( $uri );
8 8
 
9 9
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,6 +4,6 @@
 block discarded – undo
4 4
 
5 5
 interface Entity_Provider {
6 6
 
7
-	public function get_entity( $uri );
7
+	public function get_entity($uri);
8 8
 
9 9
 }
Please login to merge, or discard this patch.
src/wordlift/analysis/class-no-editor-analysis-service.php 2 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -13,12 +13,12 @@
 block discarded – undo
13 13
  */
14 14
 class No_Editor_Analysis_Service extends Abstract_Analysis_Service {
15 15
 
16
-	public function get_analysis_response( $data, $content_type, $post_id ) {
16
+    public function get_analysis_response( $data, $content_type, $post_id ) {
17 17
 
18
-		$v2_analysis_request = new No_Editor_Analysis_Request( $post_id );
18
+        $v2_analysis_request = new No_Editor_Analysis_Request( $post_id );
19 19
 
20
-		$json_encoded_body = wp_json_encode( $v2_analysis_request->get_data() );
20
+        $json_encoded_body = wp_json_encode( $v2_analysis_request->get_data() );
21 21
 
22
-		return $this->api_service->post_custom_content_type( 'analysis/v2/analyze', $json_encoded_body, $content_type );
23
-	}
22
+        return $this->api_service->post_custom_content_type( 'analysis/v2/analyze', $json_encoded_body, $content_type );
23
+    }
24 24
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -13,12 +13,12 @@
 block discarded – undo
13 13
  */
14 14
 class No_Editor_Analysis_Service extends Abstract_Analysis_Service {
15 15
 
16
-	public function get_analysis_response( $data, $content_type, $post_id ) {
16
+	public function get_analysis_response($data, $content_type, $post_id) {
17 17
 
18
-		$v2_analysis_request = new No_Editor_Analysis_Request( $post_id );
18
+		$v2_analysis_request = new No_Editor_Analysis_Request($post_id);
19 19
 
20
-		$json_encoded_body = wp_json_encode( $v2_analysis_request->get_data() );
20
+		$json_encoded_body = wp_json_encode($v2_analysis_request->get_data());
21 21
 
22
-		return $this->api_service->post_custom_content_type( 'analysis/v2/analyze', $json_encoded_body, $content_type );
22
+		return $this->api_service->post_custom_content_type('analysis/v2/analyze', $json_encoded_body, $content_type);
23 23
 	}
24 24
 }
Please login to merge, or discard this patch.
src/wordlift/analysis/class-no-editor-analysis-request.php 2 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -10,36 +10,36 @@
 block discarded – undo
10 10
 
11 11
 class No_Editor_Analysis_Request {
12 12
 
13
-	private $post_id;
13
+    private $post_id;
14 14
 
15
-	public function __construct( $post_id ) {
16
-		$this->post_id = $post_id;
17
-	}
15
+    public function __construct( $post_id ) {
16
+        $this->post_id = $post_id;
17
+    }
18 18
 
19
-	/**
20
-	 * @return array
21
-	 */
22
-	public function get_data() {
19
+    /**
20
+     * @return array
21
+     */
22
+    public function get_data() {
23 23
 
24
-		$permalink = get_permalink( $this->post_id );
24
+        $permalink = get_permalink( $this->post_id );
25 25
 
26
-		$post_content_response = wp_remote_get(
27
-			$permalink,
28
-			array(
29
-				'timeout' => 30,
30
-			)
31
-		);
26
+        $post_content_response = wp_remote_get(
27
+            $permalink,
28
+            array(
29
+                'timeout' => 30,
30
+            )
31
+        );
32 32
 
33
-		$page_body = wp_remote_retrieve_body( $post_content_response );
33
+        $page_body = wp_remote_retrieve_body( $post_content_response );
34 34
 
35
-		return array(
36
-			'html'     => array( 'page' => $page_body ),
37
-			'language' => \Wordlift_Configuration_Service::get_instance()->get_language_code(),
38
-			'scope'    => 'all',
39
-			'matches'  => 1,
40
-			'links'    => 'no',
41
-		);
35
+        return array(
36
+            'html'     => array( 'page' => $page_body ),
37
+            'language' => \Wordlift_Configuration_Service::get_instance()->get_language_code(),
38
+            'scope'    => 'all',
39
+            'matches'  => 1,
40
+            'links'    => 'no',
41
+        );
42 42
 
43
-	}
43
+    }
44 44
 
45 45
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 
13 13
 	private $post_id;
14 14
 
15
-	public function __construct( $post_id ) {
15
+	public function __construct($post_id) {
16 16
 		$this->post_id = $post_id;
17 17
 	}
18 18
 
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	 */
22 22
 	public function get_data() {
23 23
 
24
-		$permalink = get_permalink( $this->post_id );
24
+		$permalink = get_permalink($this->post_id);
25 25
 
26 26
 		$post_content_response = wp_remote_get(
27 27
 			$permalink,
@@ -30,10 +30,10 @@  discard block
 block discarded – undo
30 30
 			)
31 31
 		);
32 32
 
33
-		$page_body = wp_remote_retrieve_body( $post_content_response );
33
+		$page_body = wp_remote_retrieve_body($post_content_response);
34 34
 
35 35
 		return array(
36
-			'html'     => array( 'page' => $page_body ),
36
+			'html'     => array('page' => $page_body),
37 37
 			'language' => \Wordlift_Configuration_Service::get_instance()->get_language_code(),
38 38
 			'scope'    => 'all',
39 39
 			'matches'  => 1,
Please login to merge, or discard this patch.
src/wordlift/analysis/class-v1-analysis-service.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@
 block discarded – undo
12 12
  */
13 13
 class V1_Analysis_Service extends Abstract_Analysis_Service {
14 14
 
15
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
16
-	public function get_analysis_response( $data, $content_type, $post_id ) {
17
-		return $this->api_service->post_custom_content_type( 'analysis/single', $data, $content_type );
18
-	}
15
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
16
+    public function get_analysis_response( $data, $content_type, $post_id ) {
17
+        return $this->api_service->post_custom_content_type( 'analysis/single', $data, $content_type );
18
+    }
19 19
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
 class V1_Analysis_Service extends Abstract_Analysis_Service {
14 14
 
15 15
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
16
-	public function get_analysis_response( $data, $content_type, $post_id ) {
17
-		return $this->api_service->post_custom_content_type( 'analysis/single', $data, $content_type );
16
+	public function get_analysis_response($data, $content_type, $post_id) {
17
+		return $this->api_service->post_custom_content_type('analysis/single', $data, $content_type);
18 18
 	}
19 19
 }
Please login to merge, or discard this patch.