Completed
Pull Request — develop (#1698)
by David
01:23
created
src/modules/dashboard/includes/Post_Entity_Match/Query_Builder.php 2 patches
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -16,25 +16,25 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class Query_Builder extends Match_Query_Builder {
18 18
 
19
-	public function build() {
20
-
21
-		global $wpdb;
22
-		/**
23
-		 * Why not use JSON_EXTRACT() to extract the match_name ?
24
-		 * As of now the min wp compatibility is 5.3 which requires min mysql version
25
-		 * 5.6, The JSON_* functions are introduced on 5.7 which will break the
26
-		 * compatibility.
27
-		 *
28
-		 *  Returns an array of rows where each row contains
29
-		 * 'post_title' => The title of the post
30
-		 * 'id'   => The id of the post
31
-		 * 'parent_post_title' => The title of the post linked to this post via wprm_parent_post_id property
32
-		 * ( this is only applicable when the post is wprm_recipe, returns null if not present )
33
-		 * 'parent_post_id'  => The id of the linked parent post.
34
-		 * 'match_jsonld' => The matched `about_jsonld` column from wl_entities.
35
-		 * 'match_id' => This id points to id column of wl_entities table.
36
-		 */
37
-		$this->sql = "
19
+    public function build() {
20
+
21
+        global $wpdb;
22
+        /**
23
+         * Why not use JSON_EXTRACT() to extract the match_name ?
24
+         * As of now the min wp compatibility is 5.3 which requires min mysql version
25
+         * 5.6, The JSON_* functions are introduced on 5.7 which will break the
26
+         * compatibility.
27
+         *
28
+         *  Returns an array of rows where each row contains
29
+         * 'post_title' => The title of the post
30
+         * 'id'   => The id of the post
31
+         * 'parent_post_title' => The title of the post linked to this post via wprm_parent_post_id property
32
+         * ( this is only applicable when the post is wprm_recipe, returns null if not present )
33
+         * 'parent_post_id'  => The id of the linked parent post.
34
+         * 'match_jsonld' => The matched `about_jsonld` column from wl_entities.
35
+         * 'match_id' => This id points to id column of wl_entities table.
36
+         */
37
+        $this->sql = "
38 38
 		SELECT p.ID as id,
39 39
 		       p.post_title as post_title,
40 40
 		       p.post_status as post_status,
@@ -49,48 +49,48 @@  discard block
 block discarded – undo
49 49
 			WHERE 1=1 
50 50
 		";
51 51
 
52
-		$this->cursor()
53
-			 ->post_type()
54
-			 ->post_status()
55
-			 ->has_match()
56
-			 ->order_by()
57
-			 ->limit();
58
-	}
59
-
60
-	private function post_status() {
61
-		global $wpdb;
62
-
63
-		// If a value has been provided and it's either 'draft' or 'publish', we add the related filter.
64
-		if ( is_string( $this->params['post_status'] ) && in_array(
65
-			$this->params['post_status'],
66
-			array(
67
-				'publish',
68
-				'draft',
69
-			),
70
-			true
71
-		) ) {
72
-
73
-			$this->sql .= $wpdb->prepare( ' AND p.post_status = %s', $this->params['post_status'] );
74
-
75
-			return $this;
76
-		}
77
-
78
-		// By default we filter on 'draft' and 'publish'.
79
-		$this->sql .= " AND p.post_status IN ( 'draft', 'publish' )";
80
-
81
-		return $this;
82
-	}
83
-
84
-	public function post_type() {
85
-		$post_types = $this->params['post_types'];
86
-
87
-		if ( ! isset( $post_types ) ) {
88
-			return $this;
89
-		}
90
-		$post_types_sql = Escape::sql_array( $post_types );
91
-		$this->sql     .= " AND p.post_type IN ({$post_types_sql}) ";
92
-
93
-		return $this;
94
-	}
52
+        $this->cursor()
53
+                ->post_type()
54
+                ->post_status()
55
+                ->has_match()
56
+                ->order_by()
57
+                ->limit();
58
+    }
59
+
60
+    private function post_status() {
61
+        global $wpdb;
62
+
63
+        // If a value has been provided and it's either 'draft' or 'publish', we add the related filter.
64
+        if ( is_string( $this->params['post_status'] ) && in_array(
65
+            $this->params['post_status'],
66
+            array(
67
+                'publish',
68
+                'draft',
69
+            ),
70
+            true
71
+        ) ) {
72
+
73
+            $this->sql .= $wpdb->prepare( ' AND p.post_status = %s', $this->params['post_status'] );
74
+
75
+            return $this;
76
+        }
77
+
78
+        // By default we filter on 'draft' and 'publish'.
79
+        $this->sql .= " AND p.post_status IN ( 'draft', 'publish' )";
80
+
81
+        return $this;
82
+    }
83
+
84
+    public function post_type() {
85
+        $post_types = $this->params['post_types'];
86
+
87
+        if ( ! isset( $post_types ) ) {
88
+            return $this;
89
+        }
90
+        $post_types_sql = Escape::sql_array( $post_types );
91
+        $this->sql     .= " AND p.post_type IN ({$post_types_sql}) ";
92
+
93
+        return $this;
94
+    }
95 95
 
96 96
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -61,16 +61,16 @@  discard block
 block discarded – undo
61 61
 		global $wpdb;
62 62
 
63 63
 		// If a value has been provided and it's either 'draft' or 'publish', we add the related filter.
64
-		if ( is_string( $this->params['post_status'] ) && in_array(
64
+		if (is_string($this->params['post_status']) && in_array(
65 65
 			$this->params['post_status'],
66 66
 			array(
67 67
 				'publish',
68 68
 				'draft',
69 69
 			),
70 70
 			true
71
-		) ) {
71
+		)) {
72 72
 
73
-			$this->sql .= $wpdb->prepare( ' AND p.post_status = %s', $this->params['post_status'] );
73
+			$this->sql .= $wpdb->prepare(' AND p.post_status = %s', $this->params['post_status']);
74 74
 
75 75
 			return $this;
76 76
 		}
@@ -84,10 +84,10 @@  discard block
 block discarded – undo
84 84
 	public function post_type() {
85 85
 		$post_types = $this->params['post_types'];
86 86
 
87
-		if ( ! isset( $post_types ) ) {
87
+		if ( ! isset($post_types)) {
88 88
 			return $this;
89 89
 		}
90
-		$post_types_sql = Escape::sql_array( $post_types );
90
+		$post_types_sql = Escape::sql_array($post_types);
91 91
 		$this->sql     .= " AND p.post_type IN ({$post_types_sql}) ";
92 92
 
93 93
 		return $this;
Please login to merge, or discard this patch.
src/modules/dashboard/includes/Post_Entity_Match/Sort.php 2 patches
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -11,20 +11,20 @@
 block discarded – undo
11 11
  */
12 12
 class Sort extends Match_Sort {
13 13
 
14
-	/**
15
-	 * Get field name.
16
-	 *
17
-	 * @return string
18
-	 */
19
-	public function get_field_name() {
20
-		$tmp_sort_field_name = substr( $this->sort, 1 );
21
-		if ( 'id' === $tmp_sort_field_name ) {
22
-			return 'p.ID';
23
-		} elseif ( 'date_modified_gmt' === $tmp_sort_field_name ) {
24
-			return 'p.post_modified_gmt';
25
-		} else {
26
-			return 'p.post_title';
27
-		}
28
-	}
14
+    /**
15
+     * Get field name.
16
+     *
17
+     * @return string
18
+     */
19
+    public function get_field_name() {
20
+        $tmp_sort_field_name = substr( $this->sort, 1 );
21
+        if ( 'id' === $tmp_sort_field_name ) {
22
+            return 'p.ID';
23
+        } elseif ( 'date_modified_gmt' === $tmp_sort_field_name ) {
24
+            return 'p.post_modified_gmt';
25
+        } else {
26
+            return 'p.post_title';
27
+        }
28
+    }
29 29
 
30 30
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -17,10 +17,10 @@
 block discarded – undo
17 17
 	 * @return string
18 18
 	 */
19 19
 	public function get_field_name() {
20
-		$tmp_sort_field_name = substr( $this->sort, 1 );
21
-		if ( 'id' === $tmp_sort_field_name ) {
20
+		$tmp_sort_field_name = substr($this->sort, 1);
21
+		if ('id' === $tmp_sort_field_name) {
22 22
 			return 'p.ID';
23
-		} elseif ( 'date_modified_gmt' === $tmp_sort_field_name ) {
23
+		} elseif ('date_modified_gmt' === $tmp_sort_field_name) {
24 24
 			return 'p.post_modified_gmt';
25 25
 		} else {
26 26
 			return 'p.post_title';
Please login to merge, or discard this patch.
dashboard/includes/Term_Entity_Match/Term_Entity_Match_Rest_Controller.php 2 patches
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -28,12 +28,12 @@  discard block
 block discarded – undo
28 28
 	 *
29 29
 	 * @param $match_service
30 30
 	 */
31
-	public function __construct( $match_service ) {
31
+	public function __construct($match_service) {
32 32
 		$this->match_service = $match_service;
33 33
 	}
34 34
 
35 35
 	public function register_hooks() {
36
-		add_action( 'rest_api_init', array( $this, 'register_routes' ) );
36
+		add_action('rest_api_init', array($this, 'register_routes'));
37 37
 	}
38 38
 
39 39
 	/**
@@ -46,13 +46,13 @@  discard block
 block discarded – undo
46 46
 			'/term-matches',
47 47
 			array(
48 48
 				'methods'             => 'GET',
49
-				'callback'            => array( $this, 'get_term_matches' ),
49
+				'callback'            => array($this, 'get_term_matches'),
50 50
 				'args'                => array(
51 51
 					'cursor'                   => array(
52 52
 						'type'              => 'string',
53 53
 						'default'           => Cursor::EMPTY_CURSOR_AS_BASE64_STRING,
54 54
 						'validate_callback' => 'rest_validate_request_arg',
55
-						'sanitize_callback' => array( Cursor::class, 'rest_sanitize_request_arg' ),
55
+						'sanitize_callback' => array(Cursor::class, 'rest_sanitize_request_arg'),
56 56
 					),
57 57
 					'limit'                    => array(
58 58
 						'type'              => 'integer',
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
 						'validate_callback' => 'rest_validate_request_arg',
91 91
 					),
92 92
 				),
93
-				'permission_callback' => function () {
94
-					return current_user_can( 'manage_options' );
93
+				'permission_callback' => function() {
94
+					return current_user_can('manage_options');
95 95
 				},
96 96
 			)
97 97
 		);
@@ -102,15 +102,15 @@  discard block
 block discarded – undo
102 102
 			'/term-matches/(?P<term_id>\d+)/matches',
103 103
 			array(
104 104
 				'methods'             => 'POST',
105
-				'callback'            => array( $this, 'create_term_match' ),
105
+				'callback'            => array($this, 'create_term_match'),
106 106
 				'args'                => array(
107 107
 					'term_id' => array(
108 108
 						'required'          => true,
109 109
 						'validate_callback' => 'rest_validate_request_arg',
110 110
 					),
111 111
 				),
112
-				'permission_callback' => function () {
113
-					return current_user_can( 'manage_options' );
112
+				'permission_callback' => function() {
113
+					return current_user_can('manage_options');
114 114
 				},
115 115
 			)
116 116
 		);
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 			'/term-matches/(?P<term_id>\d+)/matches/(?P<match_id>\d+)',
122 122
 			array(
123 123
 				'methods'             => 'PUT',
124
-				'callback'            => array( $this, 'update_term_match' ),
124
+				'callback'            => array($this, 'update_term_match'),
125 125
 				'args'                => array(
126 126
 					'term_id'  => array(
127 127
 						'required'          => true,
@@ -132,8 +132,8 @@  discard block
 block discarded – undo
132 132
 						'validate_callback' => 'rest_validate_request_arg',
133 133
 					),
134 134
 				),
135
-				'permission_callback' => function () {
136
-					return current_user_can( 'manage_options' );
135
+				'permission_callback' => function() {
136
+					return current_user_can('manage_options');
137 137
 				},
138 138
 			)
139 139
 		);
@@ -146,27 +146,27 @@  discard block
 block discarded – undo
146 146
 	 *
147 147
 	 * @throws \Exception If there was a problem getting the match.
148 148
 	 */
149
-	public function get_term_matches( $request ) {
149
+	public function get_term_matches($request) {
150 150
 
151
-		$cursor = $request->get_param( 'cursor' );
152
-		if ( $request->has_param( 'limit' ) ) {
153
-			$cursor['limit'] = $request->get_param( 'limit' );
151
+		$cursor = $request->get_param('cursor');
152
+		if ($request->has_param('limit')) {
153
+			$cursor['limit'] = $request->get_param('limit');
154 154
 		}
155
-		if ( $request->has_param( 'sort' ) ) {
156
-			$cursor['sort'] = $request->get_param( 'sort' );
155
+		if ($request->has_param('sort')) {
156
+			$cursor['sort'] = $request->get_param('sort');
157 157
 		}
158
-		if ( $request->has_param( 'taxonomies' ) ) {
159
-			$cursor['query']['taxonomies'] = $request->get_param( 'taxonomies' );
158
+		if ($request->has_param('taxonomies')) {
159
+			$cursor['query']['taxonomies'] = $request->get_param('taxonomies');
160 160
 		}
161
-		if ( $request->has_param( 'has_match' ) ) {
162
-			$cursor['query']['has_match'] = $request->get_param( 'has_match' );
161
+		if ($request->has_param('has_match')) {
162
+			$cursor['query']['has_match'] = $request->get_param('has_match');
163 163
 		}
164
-		if ( $request->has_param( 'ingredient_name_contains' ) ) {
165
-			$cursor['query']['ingredient_name_contains'] = $request->get_param( 'ingredient_name_contains' );
164
+		if ($request->has_param('ingredient_name_contains')) {
165
+			$cursor['query']['ingredient_name_contains'] = $request->get_param('ingredient_name_contains');
166 166
 		}
167 167
 
168 168
 		// Query.
169
-		$taxonomies = isset( $cursor['query']['taxonomies'] ) ? $cursor['query']['taxonomies'] : apply_filters(
169
+		$taxonomies = isset($cursor['query']['taxonomies']) ? $cursor['query']['taxonomies'] : apply_filters(
170 170
 			'wl_dashboard__post_entity_match__taxonomies',
171 171
 			array(
172 172
 				'post_tag',
@@ -174,8 +174,8 @@  discard block
 block discarded – undo
174 174
 			)
175 175
 		);
176 176
 
177
-		$has_match                = isset( $cursor['query']['has_match'] ) ? $cursor['query']['has_match'] : null;
178
-		$ingredient_name_contains = isset( $cursor['query']['ingredient_name_contains'] ) ? $cursor['query']['ingredient_name_contains'] : null;
177
+		$has_match                = isset($cursor['query']['has_match']) ? $cursor['query']['has_match'] : null;
178
+		$ingredient_name_contains = isset($cursor['query']['ingredient_name_contains']) ? $cursor['query']['ingredient_name_contains'] : null;
179 179
 
180 180
 		$items = $this->match_service->list_items(
181 181
 			array(
@@ -211,15 +211,15 @@  discard block
 block discarded – undo
211 211
 	 *
212 212
 	 * @throws \Exception If there was a problem creating the match.
213 213
 	 */
214
-	public function create_term_match( $request ) {
214
+	public function create_term_match($request) {
215 215
 
216
-		$term_id = $request->get_param( 'term_id' );
216
+		$term_id = $request->get_param('term_id');
217 217
 
218 218
 		// If we dont have a entry on the match table, then add one.
219
-		$content_id = Wordpress_Content_Id::create_term( $term_id );
220
-		if ( ! Wordpress_Content_Service::get_instance()->get_entity_id( $content_id ) ) {
221
-			$uri = Entity_Uri_Generator::create_uri( $content_id->get_type(), $content_id->get_id() );
222
-			Wordpress_Content_Service::get_instance()->set_entity_id( $content_id, $uri );
219
+		$content_id = Wordpress_Content_Id::create_term($term_id);
220
+		if ( ! Wordpress_Content_Service::get_instance()->get_entity_id($content_id)) {
221
+			$uri = Entity_Uri_Generator::create_uri($content_id->get_type(), $content_id->get_id());
222
+			Wordpress_Content_Service::get_instance()->set_entity_id($content_id, $uri);
223 223
 		}
224 224
 
225 225
 		$match_id = $this->match_service->get_id(
@@ -244,11 +244,11 @@  discard block
 block discarded – undo
244 244
 	 *
245 245
 	 * @throws \Exception If there was a problem updating the match.
246 246
 	 */
247
-	public function update_term_match( $request ) {
247
+	public function update_term_match($request) {
248 248
 		return $this->match_service->set_jsonld(
249
-			$request->get_param( 'term_id' ),
249
+			$request->get_param('term_id'),
250 250
 			Object_Type_Enum::TERM,
251
-			$request->get_param( 'match_id' ),
251
+			$request->get_param('match_id'),
252 252
 			$request->get_json_params()
253 253
 		);
254 254
 	}
Please login to merge, or discard this patch.
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -18,243 +18,243 @@
 block discarded – undo
18 18
  */
19 19
 class Term_Entity_Match_Rest_Controller extends \WP_REST_Controller {
20 20
 
21
-	/**
22
-	 * @var Post_Entity_Match_Service
23
-	 */
24
-	private $match_service;
21
+    /**
22
+     * @var Post_Entity_Match_Service
23
+     */
24
+    private $match_service;
25 25
 
26
-	/**
27
-	 * Construct
28
-	 *
29
-	 * @param $match_service
30
-	 */
31
-	public function __construct( $match_service ) {
32
-		$this->match_service = $match_service;
33
-	}
26
+    /**
27
+     * Construct
28
+     *
29
+     * @param $match_service
30
+     */
31
+    public function __construct( $match_service ) {
32
+        $this->match_service = $match_service;
33
+    }
34 34
 
35
-	public function register_hooks() {
36
-		add_action( 'rest_api_init', array( $this, 'register_routes' ) );
37
-	}
35
+    public function register_hooks() {
36
+        add_action( 'rest_api_init', array( $this, 'register_routes' ) );
37
+    }
38 38
 
39
-	/**
40
-	 * Register the routes for the objects of the controller.
41
-	 */
42
-	public function register_routes() {
43
-		// Get term matches by taxonomy name
44
-		register_rest_route(
45
-			WL_REST_ROUTE_DEFAULT_NAMESPACE,
46
-			'/term-matches',
47
-			array(
48
-				'methods'             => 'GET',
49
-				'callback'            => array( $this, 'get_term_matches' ),
50
-				'args'                => array(
51
-					'cursor'                   => array(
52
-						'type'              => 'string',
53
-						'default'           => Cursor::EMPTY_CURSOR_AS_BASE64_STRING,
54
-						'validate_callback' => 'rest_validate_request_arg',
55
-						'sanitize_callback' => array( Cursor::class, 'rest_sanitize_request_arg' ),
56
-					),
57
-					'limit'                    => array(
58
-						'type'              => 'integer',
59
-						'validate_callback' => 'rest_validate_request_arg',
60
-						'default'           => 10,
61
-						'minimum'           => 1,
62
-						'maximum'           => 100,
63
-						'sanitize_callback' => 'absint',
64
-					),
65
-					'taxonomies'               => array(
66
-						'type'              => 'array',
67
-						'validate_callback' => 'rest_validate_request_arg',
68
-					),
69
-					'has_match'                => array(
70
-						'type'              => 'boolean',
71
-						'required'          => false,
72
-						'validate_callback' => 'rest_validate_request_arg',
73
-					),
74
-					'ingredient_name_contains' => array(
75
-						'type'              => 'string',
76
-						'required'          => false,
77
-						'validate_callback' => 'rest_validate_request_arg',
78
-					),
79
-					'sort'                     => array(
80
-						'type'              => 'string',
81
-						'required'          => 'false',
82
-						'enum'              => array(
83
-							'+term_name',
84
-							'-term_name',
85
-							'+entity_name',
86
-							'-entity_name',
87
-							'+ingredient_term',
88
-							'-ingredient_term',
89
-							'+matched_ingredient',
90
-							'-matched_ingredient',
91
-							'+occurrences',
92
-							'-occurrences',
93
-						),
94
-						'validate_callback' => 'rest_validate_request_arg',
95
-					),
96
-				),
97
-				'permission_callback' => function () {
98
-					return current_user_can( 'manage_options' );
99
-				},
100
-			)
101
-		);
39
+    /**
40
+     * Register the routes for the objects of the controller.
41
+     */
42
+    public function register_routes() {
43
+        // Get term matches by taxonomy name
44
+        register_rest_route(
45
+            WL_REST_ROUTE_DEFAULT_NAMESPACE,
46
+            '/term-matches',
47
+            array(
48
+                'methods'             => 'GET',
49
+                'callback'            => array( $this, 'get_term_matches' ),
50
+                'args'                => array(
51
+                    'cursor'                   => array(
52
+                        'type'              => 'string',
53
+                        'default'           => Cursor::EMPTY_CURSOR_AS_BASE64_STRING,
54
+                        'validate_callback' => 'rest_validate_request_arg',
55
+                        'sanitize_callback' => array( Cursor::class, 'rest_sanitize_request_arg' ),
56
+                    ),
57
+                    'limit'                    => array(
58
+                        'type'              => 'integer',
59
+                        'validate_callback' => 'rest_validate_request_arg',
60
+                        'default'           => 10,
61
+                        'minimum'           => 1,
62
+                        'maximum'           => 100,
63
+                        'sanitize_callback' => 'absint',
64
+                    ),
65
+                    'taxonomies'               => array(
66
+                        'type'              => 'array',
67
+                        'validate_callback' => 'rest_validate_request_arg',
68
+                    ),
69
+                    'has_match'                => array(
70
+                        'type'              => 'boolean',
71
+                        'required'          => false,
72
+                        'validate_callback' => 'rest_validate_request_arg',
73
+                    ),
74
+                    'ingredient_name_contains' => array(
75
+                        'type'              => 'string',
76
+                        'required'          => false,
77
+                        'validate_callback' => 'rest_validate_request_arg',
78
+                    ),
79
+                    'sort'                     => array(
80
+                        'type'              => 'string',
81
+                        'required'          => 'false',
82
+                        'enum'              => array(
83
+                            '+term_name',
84
+                            '-term_name',
85
+                            '+entity_name',
86
+                            '-entity_name',
87
+                            '+ingredient_term',
88
+                            '-ingredient_term',
89
+                            '+matched_ingredient',
90
+                            '-matched_ingredient',
91
+                            '+occurrences',
92
+                            '-occurrences',
93
+                        ),
94
+                        'validate_callback' => 'rest_validate_request_arg',
95
+                    ),
96
+                ),
97
+                'permission_callback' => function () {
98
+                    return current_user_can( 'manage_options' );
99
+                },
100
+            )
101
+        );
102 102
 
103
-		// Create a new match for a term
104
-		register_rest_route(
105
-			WL_REST_ROUTE_DEFAULT_NAMESPACE,
106
-			'/term-matches/(?P<term_id>\d+)/matches',
107
-			array(
108
-				'methods'             => 'POST',
109
-				'callback'            => array( $this, 'create_term_match' ),
110
-				'args'                => array(
111
-					'term_id' => array(
112
-						'required'          => true,
113
-						'validate_callback' => 'rest_validate_request_arg',
114
-					),
115
-				),
116
-				'permission_callback' => function () {
117
-					return current_user_can( 'manage_options' );
118
-				},
119
-			)
120
-		);
103
+        // Create a new match for a term
104
+        register_rest_route(
105
+            WL_REST_ROUTE_DEFAULT_NAMESPACE,
106
+            '/term-matches/(?P<term_id>\d+)/matches',
107
+            array(
108
+                'methods'             => 'POST',
109
+                'callback'            => array( $this, 'create_term_match' ),
110
+                'args'                => array(
111
+                    'term_id' => array(
112
+                        'required'          => true,
113
+                        'validate_callback' => 'rest_validate_request_arg',
114
+                    ),
115
+                ),
116
+                'permission_callback' => function () {
117
+                    return current_user_can( 'manage_options' );
118
+                },
119
+            )
120
+        );
121 121
 
122
-		// Update an existing term match
123
-		register_rest_route(
124
-			WL_REST_ROUTE_DEFAULT_NAMESPACE,
125
-			'/term-matches/(?P<term_id>\d+)/matches/(?P<match_id>\d+)',
126
-			array(
127
-				'methods'             => 'PUT',
128
-				'callback'            => array( $this, 'update_term_match' ),
129
-				'args'                => array(
130
-					'term_id'  => array(
131
-						'required'          => true,
132
-						'validate_callback' => 'rest_validate_request_arg',
133
-					),
134
-					'match_id' => array(
135
-						'required'          => true,
136
-						'validate_callback' => 'rest_validate_request_arg',
137
-					),
138
-				),
139
-				'permission_callback' => function () {
140
-					return current_user_can( 'manage_options' );
141
-				},
142
-			)
143
-		);
144
-	}
122
+        // Update an existing term match
123
+        register_rest_route(
124
+            WL_REST_ROUTE_DEFAULT_NAMESPACE,
125
+            '/term-matches/(?P<term_id>\d+)/matches/(?P<match_id>\d+)',
126
+            array(
127
+                'methods'             => 'PUT',
128
+                'callback'            => array( $this, 'update_term_match' ),
129
+                'args'                => array(
130
+                    'term_id'  => array(
131
+                        'required'          => true,
132
+                        'validate_callback' => 'rest_validate_request_arg',
133
+                    ),
134
+                    'match_id' => array(
135
+                        'required'          => true,
136
+                        'validate_callback' => 'rest_validate_request_arg',
137
+                    ),
138
+                ),
139
+                'permission_callback' => function () {
140
+                    return current_user_can( 'manage_options' );
141
+                },
142
+            )
143
+        );
144
+    }
145 145
 
146
-	/**
147
-	 * Get the term matches by taxonomy name.
148
-	 *
149
-	 * @param  $request \WP_REST_Request
150
-	 *
151
-	 * @throws \Exception If there was a problem getting the match.
152
-	 */
153
-	public function get_term_matches( $request ) {
146
+    /**
147
+     * Get the term matches by taxonomy name.
148
+     *
149
+     * @param  $request \WP_REST_Request
150
+     *
151
+     * @throws \Exception If there was a problem getting the match.
152
+     */
153
+    public function get_term_matches( $request ) {
154 154
 
155
-		$cursor = $request->get_param( 'cursor' );
156
-		if ( $request->has_param( 'limit' ) ) {
157
-			$cursor['limit'] = $request->get_param( 'limit' );
158
-		}
159
-		if ( $request->has_param( 'sort' ) ) {
160
-			$cursor['sort'] = $request->get_param( 'sort' );
161
-		}
162
-		if ( $request->has_param( 'taxonomies' ) ) {
163
-			$cursor['query']['taxonomies'] = $request->get_param( 'taxonomies' );
164
-		}
165
-		if ( $request->has_param( 'has_match' ) ) {
166
-			$cursor['query']['has_match'] = $request->get_param( 'has_match' );
167
-		}
168
-		if ( $request->has_param( 'ingredient_name_contains' ) ) {
169
-			$cursor['query']['ingredient_name_contains'] = $request->get_param( 'ingredient_name_contains' );
170
-		}
155
+        $cursor = $request->get_param( 'cursor' );
156
+        if ( $request->has_param( 'limit' ) ) {
157
+            $cursor['limit'] = $request->get_param( 'limit' );
158
+        }
159
+        if ( $request->has_param( 'sort' ) ) {
160
+            $cursor['sort'] = $request->get_param( 'sort' );
161
+        }
162
+        if ( $request->has_param( 'taxonomies' ) ) {
163
+            $cursor['query']['taxonomies'] = $request->get_param( 'taxonomies' );
164
+        }
165
+        if ( $request->has_param( 'has_match' ) ) {
166
+            $cursor['query']['has_match'] = $request->get_param( 'has_match' );
167
+        }
168
+        if ( $request->has_param( 'ingredient_name_contains' ) ) {
169
+            $cursor['query']['ingredient_name_contains'] = $request->get_param( 'ingredient_name_contains' );
170
+        }
171 171
 
172
-		// Query.
173
-		$taxonomies = isset( $cursor['query']['taxonomies'] ) ? $cursor['query']['taxonomies'] : apply_filters(
174
-			'wl_dashboard__post_entity_match__taxonomies',
175
-			array(
176
-				'post_tag',
177
-				'category',
178
-			)
179
-		);
172
+        // Query.
173
+        $taxonomies = isset( $cursor['query']['taxonomies'] ) ? $cursor['query']['taxonomies'] : apply_filters(
174
+            'wl_dashboard__post_entity_match__taxonomies',
175
+            array(
176
+                'post_tag',
177
+                'category',
178
+            )
179
+        );
180 180
 
181
-		$has_match                = isset( $cursor['query']['has_match'] ) ? $cursor['query']['has_match'] : null;
182
-		$ingredient_name_contains = isset( $cursor['query']['ingredient_name_contains'] ) ? $cursor['query']['ingredient_name_contains'] : null;
181
+        $has_match                = isset( $cursor['query']['has_match'] ) ? $cursor['query']['has_match'] : null;
182
+        $ingredient_name_contains = isset( $cursor['query']['ingredient_name_contains'] ) ? $cursor['query']['ingredient_name_contains'] : null;
183 183
 
184
-		$items = $this->match_service->list_items(
185
-			array(
186
-				// Query
187
-				'taxonomies'               => $taxonomies,
188
-				'has_match'                => $has_match,
189
-				'ingredient_name_contains' => $ingredient_name_contains,
190
-				// Cursor-Pagination
191
-				'position'                 => $cursor['position'],
192
-				'element'                  => $cursor['element'],
193
-				'direction'                => $cursor['direction'],
194
-				// `+1` to check if we have other results.
195
-				'limit'                    => $cursor['limit'] + 1,
196
-				'sort'                     => $cursor['sort'],
197
-			)
198
-		);
184
+        $items = $this->match_service->list_items(
185
+            array(
186
+                // Query
187
+                'taxonomies'               => $taxonomies,
188
+                'has_match'                => $has_match,
189
+                'ingredient_name_contains' => $ingredient_name_contains,
190
+                // Cursor-Pagination
191
+                'position'                 => $cursor['position'],
192
+                'element'                  => $cursor['element'],
193
+                'direction'                => $cursor['direction'],
194
+                // `+1` to check if we have other results.
195
+                'limit'                    => $cursor['limit'] + 1,
196
+                'sort'                     => $cursor['sort'],
197
+            )
198
+        );
199 199
 
200
-		return new Cursor_Page(
201
-			$items,
202
-			$cursor['position'],
203
-			$cursor['element'],
204
-			$cursor['direction'],
205
-			$cursor['sort'],
206
-			$cursor['limit'],
207
-			$cursor['query']
208
-		);
209
-	}
200
+        return new Cursor_Page(
201
+            $items,
202
+            $cursor['position'],
203
+            $cursor['element'],
204
+            $cursor['direction'],
205
+            $cursor['sort'],
206
+            $cursor['limit'],
207
+            $cursor['query']
208
+        );
209
+    }
210 210
 
211
-	/**
212
-	 * Create a new match for a term.
213
-	 *
214
-	 * @param  $request \WP_REST_Request
215
-	 *
216
-	 * @throws \Exception If there was a problem creating the match.
217
-	 */
218
-	public function create_term_match( $request ) {
211
+    /**
212
+     * Create a new match for a term.
213
+     *
214
+     * @param  $request \WP_REST_Request
215
+     *
216
+     * @throws \Exception If there was a problem creating the match.
217
+     */
218
+    public function create_term_match( $request ) {
219 219
 
220
-		$term_id = $request->get_param( 'term_id' );
220
+        $term_id = $request->get_param( 'term_id' );
221 221
 
222
-		// If we dont have a entry on the match table, then add one.
223
-		$content_id = Wordpress_Content_Id::create_term( $term_id );
224
-		if ( ! Wordpress_Content_Service::get_instance()->get_entity_id( $content_id ) ) {
225
-			$uri = Entity_Uri_Generator::create_uri( $content_id->get_type(), $content_id->get_id() );
226
-			Wordpress_Content_Service::get_instance()->set_entity_id( $content_id, $uri );
227
-		}
222
+        // If we dont have a entry on the match table, then add one.
223
+        $content_id = Wordpress_Content_Id::create_term( $term_id );
224
+        if ( ! Wordpress_Content_Service::get_instance()->get_entity_id( $content_id ) ) {
225
+            $uri = Entity_Uri_Generator::create_uri( $content_id->get_type(), $content_id->get_id() );
226
+            Wordpress_Content_Service::get_instance()->set_entity_id( $content_id, $uri );
227
+        }
228 228
 
229
-		$match_id = $this->match_service->get_id(
230
-			$term_id,
231
-			Object_Type_Enum::TERM
232
-		);
229
+        $match_id = $this->match_service->get_id(
230
+            $term_id,
231
+            Object_Type_Enum::TERM
232
+        );
233 233
 
234
-		return $this->match_service->set_jsonld(
235
-			$term_id,
236
-			Object_Type_Enum::TERM,
237
-			$match_id,
238
-			$request->get_json_params()
239
-		);
240
-	}
234
+        return $this->match_service->set_jsonld(
235
+            $term_id,
236
+            Object_Type_Enum::TERM,
237
+            $match_id,
238
+            $request->get_json_params()
239
+        );
240
+    }
241 241
 
242
-	/**
243
-	 * Update term match.
244
-	 *
245
-	 * @param \WP_REST_Request $request
246
-	 *
247
-	 * @return Match_Entry
248
-	 *
249
-	 * @throws \Exception If there was a problem updating the match.
250
-	 */
251
-	public function update_term_match( $request ) {
252
-		return $this->match_service->set_jsonld(
253
-			$request->get_param( 'term_id' ),
254
-			Object_Type_Enum::TERM,
255
-			$request->get_param( 'match_id' ),
256
-			$request->get_json_params()
257
-		);
258
-	}
242
+    /**
243
+     * Update term match.
244
+     *
245
+     * @param \WP_REST_Request $request
246
+     *
247
+     * @return Match_Entry
248
+     *
249
+     * @throws \Exception If there was a problem updating the match.
250
+     */
251
+    public function update_term_match( $request ) {
252
+        return $this->match_service->set_jsonld(
253
+            $request->get_param( 'term_id' ),
254
+            Object_Type_Enum::TERM,
255
+            $request->get_param( 'match_id' ),
256
+            $request->get_json_params()
257
+        );
258
+    }
259 259
 
260 260
 }
Please login to merge, or discard this patch.
modules/dashboard/includes/Term_Entity_Match/Term_Entity_Match_Service.php 2 patches
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -12,90 +12,90 @@
 block discarded – undo
12 12
  */
13 13
 class Term_Entity_Match_Service extends Match_Service {
14 14
 
15
-	/**
16
-	 * List items.
17
-	 *
18
-	 * @param $args
19
-	 *
20
-	 * @return array
21
-	 *
22
-	 * @throws \Exception If there was a problem generating the list items.
23
-	 */
24
-	public function list_items( $args ) {
25
-		global $wpdb;
15
+    /**
16
+     * List items.
17
+     *
18
+     * @param $args
19
+     *
20
+     * @return array
21
+     *
22
+     * @throws \Exception If there was a problem generating the list items.
23
+     */
24
+    public function list_items( $args ) {
25
+        global $wpdb;
26 26
 
27
-		$params = wp_parse_args(
28
-			$args,
29
-			array(
30
-				'position'                 => null,
31
-				'element'                  => 'INCLUDED',
32
-				'direction'                => 'ASCENDING',
33
-				'limit'                    => 10,
34
-				'sort'                     => '+id',
35
-				// Query.
36
-				'taxonomy'                 => null,
37
-				'has_match'                => null,
38
-				'ingredient_name_contains' => null,
39
-			)
40
-		);
27
+        $params = wp_parse_args(
28
+            $args,
29
+            array(
30
+                'position'                 => null,
31
+                'element'                  => 'INCLUDED',
32
+                'direction'                => 'ASCENDING',
33
+                'limit'                    => 10,
34
+                'sort'                     => '+id',
35
+                // Query.
36
+                'taxonomy'                 => null,
37
+                'has_match'                => null,
38
+                'ingredient_name_contains' => null,
39
+            )
40
+        );
41 41
 
42
-		/**
43
-		 * @var $sort Sort
44
-		 */
45
-		$sort = new Sort( $params['sort'] );
42
+        /**
43
+         * @var $sort Sort
44
+         */
45
+        $sort = new Sort( $params['sort'] );
46 46
 
47
-		$query_builder = new Query_Builder(
48
-			$params,
49
-			$sort
50
-		);
51
-		$query         = $query_builder
52
-			->get();
47
+        $query_builder = new Query_Builder(
48
+            $params,
49
+            $sort
50
+        );
51
+        $query         = $query_builder
52
+            ->get();
53 53
 
54
-		$items = $wpdb->get_results(
55
-		// Each function above is preparing `$sql` by using `$wpdb->prepare`.
56
-		// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
57
-			$wpdb->prepare( $query, Object_Type_Enum::TERM )
58
-		);
54
+        $items = $wpdb->get_results(
55
+        // Each function above is preparing `$sql` by using `$wpdb->prepare`.
56
+        // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
57
+            $wpdb->prepare( $query, Object_Type_Enum::TERM )
58
+        );
59 59
 
60
-		$sort->apply( $items );
60
+        $sort->apply( $items );
61 61
 
62
-		return $this->map( $items );
63
-	}
62
+        return $this->map( $items );
63
+    }
64 64
 
65
-	/**
66
-	 * Map.
67
-	 *
68
-	 * @param array $items
69
-	 *
70
-	 * @return array
71
-	 */
72
-	private function map( array $items ) {
73
-		return array_map(
74
-			function ( $item ) {
75
-				$data              = json_decode( $item->match_jsonld, true );
76
-				$item->match_name  = $data && is_array( $data ) && array_key_exists( 'name', $data ) ? $data['name'] : null;
77
-				$item->occurrences = $this->get_term_occurrences( $item->id );
65
+    /**
66
+     * Map.
67
+     *
68
+     * @param array $items
69
+     *
70
+     * @return array
71
+     */
72
+    private function map( array $items ) {
73
+        return array_map(
74
+            function ( $item ) {
75
+                $data              = json_decode( $item->match_jsonld, true );
76
+                $item->match_name  = $data && is_array( $data ) && array_key_exists( 'name', $data ) ? $data['name'] : null;
77
+                $item->occurrences = $this->get_term_occurrences( $item->id );
78 78
 
79
-				return $item;
80
-			},
81
-			$items
82
-		);
83
-	}
79
+                return $item;
80
+            },
81
+            $items
82
+        );
83
+    }
84 84
 
85
-	/**
86
-	 * Get term occurrences.
87
-	 *
88
-	 * @param $term_id
89
-	 *
90
-	 * @return int
91
-	 */
92
-	private function get_term_occurrences( $term_id ) {
93
-		$term = get_term( $term_id );
85
+    /**
86
+     * Get term occurrences.
87
+     *
88
+     * @param $term_id
89
+     *
90
+     * @return int
91
+     */
92
+    private function get_term_occurrences( $term_id ) {
93
+        $term = get_term( $term_id );
94 94
 
95
-		if ( ! is_wp_error( $term ) ) {
96
-			return $term->count;
97
-		}
95
+        if ( ! is_wp_error( $term ) ) {
96
+            return $term->count;
97
+        }
98 98
 
99
-		return 0;
100
-	}
99
+        return 0;
100
+    }
101 101
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @throws \Exception If there was a problem generating the list items.
23 23
 	 */
24
-	public function list_items( $args ) {
24
+	public function list_items($args) {
25 25
 		global $wpdb;
26 26
 
27 27
 		$params = wp_parse_args(
@@ -42,24 +42,24 @@  discard block
 block discarded – undo
42 42
 		/**
43 43
 		 * @var $sort Sort
44 44
 		 */
45
-		$sort = new Sort( $params['sort'] );
45
+		$sort = new Sort($params['sort']);
46 46
 
47 47
 		$query_builder = new Query_Builder(
48 48
 			$params,
49 49
 			$sort
50 50
 		);
51
-		$query         = $query_builder
51
+		$query = $query_builder
52 52
 			->get();
53 53
 
54 54
 		$items = $wpdb->get_results(
55 55
 		// Each function above is preparing `$sql` by using `$wpdb->prepare`.
56 56
 		// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
57
-			$wpdb->prepare( $query, Object_Type_Enum::TERM )
57
+			$wpdb->prepare($query, Object_Type_Enum::TERM)
58 58
 		);
59 59
 
60
-		$sort->apply( $items );
60
+		$sort->apply($items);
61 61
 
62
-		return $this->map( $items );
62
+		return $this->map($items);
63 63
 	}
64 64
 
65 65
 	/**
@@ -69,12 +69,12 @@  discard block
 block discarded – undo
69 69
 	 *
70 70
 	 * @return array
71 71
 	 */
72
-	private function map( array $items ) {
72
+	private function map(array $items) {
73 73
 		return array_map(
74
-			function ( $item ) {
75
-				$data              = json_decode( $item->match_jsonld, true );
76
-				$item->match_name  = $data && is_array( $data ) && array_key_exists( 'name', $data ) ? $data['name'] : null;
77
-				$item->occurrences = $this->get_term_occurrences( $item->id );
74
+			function($item) {
75
+				$data              = json_decode($item->match_jsonld, true);
76
+				$item->match_name  = $data && is_array($data) && array_key_exists('name', $data) ? $data['name'] : null;
77
+				$item->occurrences = $this->get_term_occurrences($item->id);
78 78
 
79 79
 				return $item;
80 80
 			},
@@ -89,10 +89,10 @@  discard block
 block discarded – undo
89 89
 	 *
90 90
 	 * @return int
91 91
 	 */
92
-	private function get_term_occurrences( $term_id ) {
93
-		$term = get_term( $term_id );
92
+	private function get_term_occurrences($term_id) {
93
+		$term = get_term($term_id);
94 94
 
95
-		if ( ! is_wp_error( $term ) ) {
95
+		if ( ! is_wp_error($term)) {
96 96
 			return $term->count;
97 97
 		}
98 98
 
Please login to merge, or discard this patch.
src/modules/dashboard/includes/Term_Entity_Match/Query_Builder.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -53,10 +53,10 @@  discard block
 block discarded – undo
53 53
 	public function taxonomy() {
54 54
 		$taxonomies = $this->params['taxonomies'];
55 55
 
56
-		if ( ! isset( $taxonomies ) ) {
56
+		if ( ! isset($taxonomies)) {
57 57
 			return $this;
58 58
 		}
59
-		$sql        = Escape::sql_array( $taxonomies );
59
+		$sql        = Escape::sql_array($taxonomies);
60 60
 		$this->sql .= " AND tt.taxonomy IN ($sql)";
61 61
 
62 62
 		return $this;
@@ -71,9 +71,9 @@  discard block
 block discarded – undo
71 71
 		global $wpdb;
72 72
 
73 73
 		// If the ingredient_name_contains value is a non-empty string, add the filter
74
-		if ( is_string( $this->params['ingredient_name_contains'] ) && ! empty( $this->params['ingredient_name_contains'] ) ) {
74
+		if (is_string($this->params['ingredient_name_contains']) && ! empty($this->params['ingredient_name_contains'])) {
75 75
 			$ingredient_name_contains = $this->params['ingredient_name_contains'];
76
-			$this->sql               .= $wpdb->prepare( ' AND t.name LIKE %s', '%' . $ingredient_name_contains . '%' );
76
+			$this->sql               .= $wpdb->prepare(' AND t.name LIKE %s', '%'.$ingredient_name_contains.'%');
77 77
 		}
78 78
 
79 79
 		return $this;
Please login to merge, or discard this patch.
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -12,21 +12,21 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class Query_Builder extends Match_Query_Builder {
14 14
 
15
-	/**
16
-	 * Build.
17
-	 *
18
-	 * @throws \Exception If there was a problem with SQL query.
19
-	 */
20
-	public function build() {
15
+    /**
16
+     * Build.
17
+     *
18
+     * @throws \Exception If there was a problem with SQL query.
19
+     */
20
+    public function build() {
21 21
 
22
-		global $wpdb;
23
-		/**
24
-		 * Why not use JSON_EXTRACT() to extract the match_name ?
25
-		 * As of now the min wp compatibility is 5.3 which requires min mysql version
26
-		 * 5.6, The JSON_* functions are introduced on 5.7 which will break the
27
-		 * compatibility.
28
-		 */
29
-		$this->sql = "
22
+        global $wpdb;
23
+        /**
24
+         * Why not use JSON_EXTRACT() to extract the match_name ?
25
+         * As of now the min wp compatibility is 5.3 which requires min mysql version
26
+         * 5.6, The JSON_* functions are introduced on 5.7 which will break the
27
+         * compatibility.
28
+         */
29
+        $this->sql = "
30 30
 		SELECT t.term_id as id, e.about_jsonld as match_jsonld,
31 31
 		       t.name, e.id AS match_id FROM {$wpdb->prefix}terms t
32 32
 			INNER JOIN {$wpdb->prefix}term_taxonomy tt ON t.term_id = tt.term_id
@@ -34,48 +34,48 @@  discard block
 block discarded – undo
34 34
 			AND e.content_type = %d WHERE 1=1
35 35
 		";
36 36
 
37
-		$this->cursor()
38
-			 ->ingredient_name_contains()
39
-			 ->taxonomy()
40
-			 ->has_match()
41
-			 ->order_by()
42
-			 ->limit();
37
+        $this->cursor()
38
+                ->ingredient_name_contains()
39
+                ->taxonomy()
40
+                ->has_match()
41
+                ->order_by()
42
+                ->limit();
43 43
 
44
-	}
44
+    }
45 45
 
46
-	/**
47
-	 * Taxonomy.
48
-	 *
49
-	 * @return $this
50
-	 *
51
-	 * @throws \Exception When supplied argument is not an array, throw exception.
52
-	 */
53
-	public function taxonomy() {
54
-		$taxonomies = $this->params['taxonomies'];
46
+    /**
47
+     * Taxonomy.
48
+     *
49
+     * @return $this
50
+     *
51
+     * @throws \Exception When supplied argument is not an array, throw exception.
52
+     */
53
+    public function taxonomy() {
54
+        $taxonomies = $this->params['taxonomies'];
55 55
 
56
-		if ( ! isset( $taxonomies ) ) {
57
-			return $this;
58
-		}
59
-		$sql        = Escape::sql_array( $taxonomies );
60
-		$this->sql .= " AND tt.taxonomy IN ($sql)";
56
+        if ( ! isset( $taxonomies ) ) {
57
+            return $this;
58
+        }
59
+        $sql        = Escape::sql_array( $taxonomies );
60
+        $this->sql .= " AND tt.taxonomy IN ($sql)";
61 61
 
62
-		return $this;
63
-	}
62
+        return $this;
63
+    }
64 64
 
65
-	/**
66
-	 * Ingredient name contains.
67
-	 *
68
-	 * @return $this
69
-	 */
70
-	public function ingredient_name_contains() {
71
-		global $wpdb;
65
+    /**
66
+     * Ingredient name contains.
67
+     *
68
+     * @return $this
69
+     */
70
+    public function ingredient_name_contains() {
71
+        global $wpdb;
72 72
 
73
-		// If the ingredient_name_contains value is a non-empty string, add the filter
74
-		if ( is_string( $this->params['ingredient_name_contains'] ) && ! empty( $this->params['ingredient_name_contains'] ) ) {
75
-			$ingredient_name_contains = $this->params['ingredient_name_contains'];
76
-			$this->sql               .= $wpdb->prepare( ' AND t.name LIKE %s', '%' . $ingredient_name_contains . '%' );
77
-		}
73
+        // If the ingredient_name_contains value is a non-empty string, add the filter
74
+        if ( is_string( $this->params['ingredient_name_contains'] ) && ! empty( $this->params['ingredient_name_contains'] ) ) {
75
+            $ingredient_name_contains = $this->params['ingredient_name_contains'];
76
+            $this->sql               .= $wpdb->prepare( ' AND t.name LIKE %s', '%' . $ingredient_name_contains . '%' );
77
+        }
78 78
 
79
-		return $this;
80
-	}
79
+        return $this;
80
+    }
81 81
 }
Please login to merge, or discard this patch.
modules/dashboard/includes/Post_Entity_Match/Post_Entity_Match_Service.php 2 patches
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -12,91 +12,91 @@
 block discarded – undo
12 12
  */
13 13
 class Post_Entity_Match_Service extends Match_Service {
14 14
 
15
-	/**
16
-	 * List items.
17
-	 *
18
-	 * @param $args
19
-	 *
20
-	 * @return array
21
-	 *
22
-	 * @throws \Exception If there was a problem generating the list items.
23
-	 */
24
-	public function list_items( $args ) {
25
-		global $wpdb;
15
+    /**
16
+     * List items.
17
+     *
18
+     * @param $args
19
+     *
20
+     * @return array
21
+     *
22
+     * @throws \Exception If there was a problem generating the list items.
23
+     */
24
+    public function list_items( $args ) {
25
+        global $wpdb;
26 26
 
27
-		$params = wp_parse_args(
28
-			$args,
29
-			array(
30
-				'position'    => null,
31
-				'element'     => 'INCLUDED',
32
-				'direction'   => 'ASCENDING',
33
-				'limit'       => 10,
34
-				'sort'        => '+id',
35
-				'post_type'   => null,
36
-				'has_match'   => null,
37
-				'post_status' => null,
38
-			)
39
-		);
40
-		/**
41
-		 * @var $sort Sort
42
-		 */
43
-		$sort = new Sort( $params['sort'] );
27
+        $params = wp_parse_args(
28
+            $args,
29
+            array(
30
+                'position'    => null,
31
+                'element'     => 'INCLUDED',
32
+                'direction'   => 'ASCENDING',
33
+                'limit'       => 10,
34
+                'sort'        => '+id',
35
+                'post_type'   => null,
36
+                'has_match'   => null,
37
+                'post_status' => null,
38
+            )
39
+        );
40
+        /**
41
+         * @var $sort Sort
42
+         */
43
+        $sort = new Sort( $params['sort'] );
44 44
 
45
-		$query_builder = new Query_Builder(
46
-			$params,
47
-			$sort
48
-		);
45
+        $query_builder = new Query_Builder(
46
+            $params,
47
+            $sort
48
+        );
49 49
 
50
-		$items = $wpdb->get_results(
51
-		// Each function above is preparing `$sql` by using `$wpdb->prepare`.
52
-		// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
53
-			$wpdb->prepare( $query_builder->get(), Object_Type_Enum::POST )
54
-		);
50
+        $items = $wpdb->get_results(
51
+        // Each function above is preparing `$sql` by using `$wpdb->prepare`.
52
+        // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
53
+            $wpdb->prepare( $query_builder->get(), Object_Type_Enum::POST )
54
+        );
55 55
 
56
-		$sort->apply( $items );
56
+        $sort->apply( $items );
57 57
 
58
-		return $this->map( $items );
59
-	}
58
+        return $this->map( $items );
59
+    }
60 60
 
61
-	/**
62
-	 * Returns an array of rows where each row contains:
63
-	 *
64
-	 * 'post_title' => The title of the post
65
-	 * 'id'   => The id of the post
66
-	 * 'post_link' => The edit post link
67
-	 * 'post_status' => The status of the post.
68
-	 * 'parent_post_title' => The title of the post linked to this post via wprm_parent_post_id property
69
-	 * ( this is only applicable when the post is wprm_recipe, returns null if not present )
70
-	 * 'parent_post_id'  => The id of the linked parent post.
71
-	 * 'parent_post_link' => The link to parent post.
72
-	 * 'view link'  => The permalink to the post.
73
-	 * 'preview link' => The preview link to the post.
74
-	 * 'match_jsonld' => The matched `about_jsonld` column from wl_entities.
75
-	 * 'match_id' => This id points to id column of wl_entities table.
76
-	 *
77
-	 * @param array $items
78
-	 *
79
-	 * @return array
80
-	 */
81
-	private function map( array $items ) {
82
-		return array_map(
83
-			function ( $item ) {
84
-				$data             = json_decode( $item->match_jsonld, true );
85
-				$item->match_name = $data && is_array( $data ) && array_key_exists( 'name', $data ) ? $data['name'] : null;
61
+    /**
62
+     * Returns an array of rows where each row contains:
63
+     *
64
+     * 'post_title' => The title of the post
65
+     * 'id'   => The id of the post
66
+     * 'post_link' => The edit post link
67
+     * 'post_status' => The status of the post.
68
+     * 'parent_post_title' => The title of the post linked to this post via wprm_parent_post_id property
69
+     * ( this is only applicable when the post is wprm_recipe, returns null if not present )
70
+     * 'parent_post_id'  => The id of the linked parent post.
71
+     * 'parent_post_link' => The link to parent post.
72
+     * 'view link'  => The permalink to the post.
73
+     * 'preview link' => The preview link to the post.
74
+     * 'match_jsonld' => The matched `about_jsonld` column from wl_entities.
75
+     * 'match_id' => This id points to id column of wl_entities table.
76
+     *
77
+     * @param array $items
78
+     *
79
+     * @return array
80
+     */
81
+    private function map( array $items ) {
82
+        return array_map(
83
+            function ( $item ) {
84
+                $data             = json_decode( $item->match_jsonld, true );
85
+                $item->match_name = $data && is_array( $data ) && array_key_exists( 'name', $data ) ? $data['name'] : null;
86 86
 
87
-				if ( $item->id ) {
88
-					$item->post_link    = get_edit_post_link( $item->id, 'ui' );
89
-					$item->view_link    = get_permalink( $item->id );
90
-					$item->preview_link = get_preview_post_link( $item->id );
91
-				}
87
+                if ( $item->id ) {
88
+                    $item->post_link    = get_edit_post_link( $item->id, 'ui' );
89
+                    $item->view_link    = get_permalink( $item->id );
90
+                    $item->preview_link = get_preview_post_link( $item->id );
91
+                }
92 92
 
93
-				if ( $item->parent_post_id ) {
94
-					$item->parent_post_link = get_edit_post_link( $item->parent_post_id, 'ui' );
95
-				}
93
+                if ( $item->parent_post_id ) {
94
+                    $item->parent_post_link = get_edit_post_link( $item->parent_post_id, 'ui' );
95
+                }
96 96
 
97
-				return $item;
98
-			},
99
-			$items
100
-		);
101
-	}
97
+                return $item;
98
+            },
99
+            $items
100
+        );
101
+    }
102 102
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @throws \Exception If there was a problem generating the list items.
23 23
 	 */
24
-	public function list_items( $args ) {
24
+	public function list_items($args) {
25 25
 		global $wpdb;
26 26
 
27 27
 		$params = wp_parse_args(
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 		/**
41 41
 		 * @var $sort Sort
42 42
 		 */
43
-		$sort = new Sort( $params['sort'] );
43
+		$sort = new Sort($params['sort']);
44 44
 
45 45
 		$query_builder = new Query_Builder(
46 46
 			$params,
@@ -50,12 +50,12 @@  discard block
 block discarded – undo
50 50
 		$items = $wpdb->get_results(
51 51
 		// Each function above is preparing `$sql` by using `$wpdb->prepare`.
52 52
 		// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
53
-			$wpdb->prepare( $query_builder->get(), Object_Type_Enum::POST )
53
+			$wpdb->prepare($query_builder->get(), Object_Type_Enum::POST)
54 54
 		);
55 55
 
56
-		$sort->apply( $items );
56
+		$sort->apply($items);
57 57
 
58
-		return $this->map( $items );
58
+		return $this->map($items);
59 59
 	}
60 60
 
61 61
 	/**
@@ -78,20 +78,20 @@  discard block
 block discarded – undo
78 78
 	 *
79 79
 	 * @return array
80 80
 	 */
81
-	private function map( array $items ) {
81
+	private function map(array $items) {
82 82
 		return array_map(
83
-			function ( $item ) {
84
-				$data             = json_decode( $item->match_jsonld, true );
85
-				$item->match_name = $data && is_array( $data ) && array_key_exists( 'name', $data ) ? $data['name'] : null;
83
+			function($item) {
84
+				$data             = json_decode($item->match_jsonld, true);
85
+				$item->match_name = $data && is_array($data) && array_key_exists('name', $data) ? $data['name'] : null;
86 86
 
87
-				if ( $item->id ) {
88
-					$item->post_link    = get_edit_post_link( $item->id, 'ui' );
89
-					$item->view_link    = get_permalink( $item->id );
90
-					$item->preview_link = get_preview_post_link( $item->id );
87
+				if ($item->id) {
88
+					$item->post_link    = get_edit_post_link($item->id, 'ui');
89
+					$item->view_link    = get_permalink($item->id);
90
+					$item->preview_link = get_preview_post_link($item->id);
91 91
 				}
92 92
 
93
-				if ( $item->parent_post_id ) {
94
-					$item->parent_post_link = get_edit_post_link( $item->parent_post_id, 'ui' );
93
+				if ($item->parent_post_id) {
94
+					$item->parent_post_link = get_edit_post_link($item->parent_post_id, 'ui');
95 95
 				}
96 96
 
97 97
 				return $item;
Please login to merge, or discard this patch.
src/modules/dashboard/includes/Term_Entity_Match/Sort.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -11,24 +11,24 @@
 block discarded – undo
11 11
  */
12 12
 class Sort extends Match_Sort {
13 13
 
14
-	/**
15
-	 * Get field name.
16
-	 *
17
-	 * @return string|null
18
-	 */
19
-	public function get_field_name() {
20
-		$tmp_sort_field_name = substr( $this->sort, 1 );
21
-		if ( 'id' === $tmp_sort_field_name ) {
22
-			return 't.term_id';
23
-		} elseif ( 'ingredient_term' === $tmp_sort_field_name ) {
24
-			return 't.name';
25
-		} elseif ( 'matched_ingredient' === $tmp_sort_field_name ) {
26
-			return 't.match_name';
27
-		} elseif ( 'occurrences' === $tmp_sort_field_name ) {
28
-			// @todo This block will be filled in the future when occurrences handling is implemented
29
-			return null;
30
-		}
14
+    /**
15
+     * Get field name.
16
+     *
17
+     * @return string|null
18
+     */
19
+    public function get_field_name() {
20
+        $tmp_sort_field_name = substr( $this->sort, 1 );
21
+        if ( 'id' === $tmp_sort_field_name ) {
22
+            return 't.term_id';
23
+        } elseif ( 'ingredient_term' === $tmp_sort_field_name ) {
24
+            return 't.name';
25
+        } elseif ( 'matched_ingredient' === $tmp_sort_field_name ) {
26
+            return 't.match_name';
27
+        } elseif ( 'occurrences' === $tmp_sort_field_name ) {
28
+            // @todo This block will be filled in the future when occurrences handling is implemented
29
+            return null;
30
+        }
31 31
 
32
-		return 't.name';
33
-	}
32
+        return 't.name';
33
+    }
34 34
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -17,14 +17,14 @@
 block discarded – undo
17 17
 	 * @return string|null
18 18
 	 */
19 19
 	public function get_field_name() {
20
-		$tmp_sort_field_name = substr( $this->sort, 1 );
21
-		if ( 'id' === $tmp_sort_field_name ) {
20
+		$tmp_sort_field_name = substr($this->sort, 1);
21
+		if ('id' === $tmp_sort_field_name) {
22 22
 			return 't.term_id';
23
-		} elseif ( 'ingredient_term' === $tmp_sort_field_name ) {
23
+		} elseif ('ingredient_term' === $tmp_sort_field_name) {
24 24
 			return 't.name';
25
-		} elseif ( 'matched_ingredient' === $tmp_sort_field_name ) {
25
+		} elseif ('matched_ingredient' === $tmp_sort_field_name) {
26 26
 			return 't.match_name';
27
-		} elseif ( 'occurrences' === $tmp_sort_field_name ) {
27
+		} elseif ('occurrences' === $tmp_sort_field_name) {
28 28
 			// @todo This block will be filled in the future when occurrences handling is implemented
29 29
 			return null;
30 30
 		}
Please login to merge, or discard this patch.
src/modules/dashboard/includes/Synchronization/Rest_Controller.php 2 patches
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -7,89 +7,89 @@
 block discarded – undo
7 7
 
8 8
 class Rest_Controller {
9 9
 
10
-	/**
11
-	 * @var Synchronization_Service $synchronization_service
12
-	 */
13
-	private $synchronization_service;
10
+    /**
11
+     * @var Synchronization_Service $synchronization_service
12
+     */
13
+    private $synchronization_service;
14 14
 
15
-	/**
16
-	 * @param Synchronization_Service $synchronization_service
17
-	 */
18
-	public function __construct( $synchronization_service ) {
19
-		$this->synchronization_service = $synchronization_service;
20
-	}
15
+    /**
16
+     * @param Synchronization_Service $synchronization_service
17
+     */
18
+    public function __construct( $synchronization_service ) {
19
+        $this->synchronization_service = $synchronization_service;
20
+    }
21 21
 
22
-	public function register_hooks() {
23
-		add_action( 'rest_api_init', array( $this, 'rest_api_init' ) );
24
-	}
22
+    public function register_hooks() {
23
+        add_action( 'rest_api_init', array( $this, 'rest_api_init' ) );
24
+    }
25 25
 
26
-	public function rest_api_init() {
27
-		register_rest_route(
28
-			'wl-dashboard/v1',
29
-			'/synchronizations',
30
-			array(
31
-				'methods'             => 'POST',
32
-				'callback'            => array( $this, 'create_sync' ),
33
-				'permission_callback' => '__return_true',
34
-			)
35
-		);
26
+    public function rest_api_init() {
27
+        register_rest_route(
28
+            'wl-dashboard/v1',
29
+            '/synchronizations',
30
+            array(
31
+                'methods'             => 'POST',
32
+                'callback'            => array( $this, 'create_sync' ),
33
+                'permission_callback' => '__return_true',
34
+            )
35
+        );
36 36
 
37
-		register_rest_route(
38
-			'wl-dashboard/v1',
39
-			'/synchronizations',
40
-			array(
41
-				'methods'             => 'GET',
42
-				'callback'            => array( $this, 'list_syncs' ),
43
-				'permission_callback' => '__return_true',
44
-				'args'                => array(
45
-					'is_running' => array(
46
-						'description' => esc_html__( 'Filter the is_running', 'wordlift' ),
47
-						'type'        => 'boolean',
48
-					),
49
-				),
50
-			)
51
-		);
37
+        register_rest_route(
38
+            'wl-dashboard/v1',
39
+            '/synchronizations',
40
+            array(
41
+                'methods'             => 'GET',
42
+                'callback'            => array( $this, 'list_syncs' ),
43
+                'permission_callback' => '__return_true',
44
+                'args'                => array(
45
+                    'is_running' => array(
46
+                        'description' => esc_html__( 'Filter the is_running', 'wordlift' ),
47
+                        'type'        => 'boolean',
48
+                    ),
49
+                ),
50
+            )
51
+        );
52 52
 
53
-		register_rest_route(
54
-			'wl-dashboard/v1',
55
-			'/synchronizations',
56
-			array(
57
-				'methods'             => 'DELETE',
58
-				'callback'            => array( $this, 'delete_syncs' ),
59
-				'permission_callback' => '__return_true',
60
-			)
61
-		);
62
-	}
53
+        register_rest_route(
54
+            'wl-dashboard/v1',
55
+            '/synchronizations',
56
+            array(
57
+                'methods'             => 'DELETE',
58
+                'callback'            => array( $this, 'delete_syncs' ),
59
+                'permission_callback' => '__return_true',
60
+            )
61
+        );
62
+    }
63 63
 
64
-	public function create_sync() {
65
-		try {
66
-			return rest_ensure_response( $this->synchronization_service->create() );
67
-		} catch ( \Exception $e ) {
68
-			return new \WP_Error(
69
-				'wl_error_synchronization_running',
70
-				esc_html__( 'Another synchronization is already running.', 'wordlift' ),
71
-				array( 'status' => 409 )
72
-			);
73
-		}
74
-	}
64
+    public function create_sync() {
65
+        try {
66
+            return rest_ensure_response( $this->synchronization_service->create() );
67
+        } catch ( \Exception $e ) {
68
+            return new \WP_Error(
69
+                'wl_error_synchronization_running',
70
+                esc_html__( 'Another synchronization is already running.', 'wordlift' ),
71
+                array( 'status' => 409 )
72
+            );
73
+        }
74
+    }
75 75
 
76
-	public function list_syncs( WP_REST_Request $request ) {
77
-		$last_synchronization = $this->synchronization_service->load();
78
-		$is_running_all       = ! $request->has_param( 'is_running' );
79
-		if ( is_a( $last_synchronization, 'Wordlift\Modules\Dashboard\Synchronization\Synchronization' )
80
-			&& ( $is_running_all || $request->get_param( 'is_running' ) === $last_synchronization->is_running() ) ) {
81
-			$data = array( $last_synchronization );
82
-		} else {
83
-			$data = array();
84
-		}
76
+    public function list_syncs( WP_REST_Request $request ) {
77
+        $last_synchronization = $this->synchronization_service->load();
78
+        $is_running_all       = ! $request->has_param( 'is_running' );
79
+        if ( is_a( $last_synchronization, 'Wordlift\Modules\Dashboard\Synchronization\Synchronization' )
80
+            && ( $is_running_all || $request->get_param( 'is_running' ) === $last_synchronization->is_running() ) ) {
81
+            $data = array( $last_synchronization );
82
+        } else {
83
+            $data = array();
84
+        }
85 85
 
86
-		return rest_ensure_response( array( 'items' => $data ) );
87
-	}
86
+        return rest_ensure_response( array( 'items' => $data ) );
87
+    }
88 88
 
89
-	public function delete_syncs() {
90
-		$this->synchronization_service->delete_syncs();
89
+    public function delete_syncs() {
90
+        $this->synchronization_service->delete_syncs();
91 91
 
92
-		return new WP_REST_Response();
93
-	}
92
+        return new WP_REST_Response();
93
+    }
94 94
 
95 95
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -15,12 +15,12 @@  discard block
 block discarded – undo
15 15
 	/**
16 16
 	 * @param Synchronization_Service $synchronization_service
17 17
 	 */
18
-	public function __construct( $synchronization_service ) {
18
+	public function __construct($synchronization_service) {
19 19
 		$this->synchronization_service = $synchronization_service;
20 20
 	}
21 21
 
22 22
 	public function register_hooks() {
23
-		add_action( 'rest_api_init', array( $this, 'rest_api_init' ) );
23
+		add_action('rest_api_init', array($this, 'rest_api_init'));
24 24
 	}
25 25
 
26 26
 	public function rest_api_init() {
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 			'/synchronizations',
30 30
 			array(
31 31
 				'methods'             => 'POST',
32
-				'callback'            => array( $this, 'create_sync' ),
32
+				'callback'            => array($this, 'create_sync'),
33 33
 				'permission_callback' => '__return_true',
34 34
 			)
35 35
 		);
@@ -39,11 +39,11 @@  discard block
 block discarded – undo
39 39
 			'/synchronizations',
40 40
 			array(
41 41
 				'methods'             => 'GET',
42
-				'callback'            => array( $this, 'list_syncs' ),
42
+				'callback'            => array($this, 'list_syncs'),
43 43
 				'permission_callback' => '__return_true',
44 44
 				'args'                => array(
45 45
 					'is_running' => array(
46
-						'description' => esc_html__( 'Filter the is_running', 'wordlift' ),
46
+						'description' => esc_html__('Filter the is_running', 'wordlift'),
47 47
 						'type'        => 'boolean',
48 48
 					),
49 49
 				),
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 			'/synchronizations',
56 56
 			array(
57 57
 				'methods'             => 'DELETE',
58
-				'callback'            => array( $this, 'delete_syncs' ),
58
+				'callback'            => array($this, 'delete_syncs'),
59 59
 				'permission_callback' => '__return_true',
60 60
 			)
61 61
 		);
@@ -63,27 +63,27 @@  discard block
 block discarded – undo
63 63
 
64 64
 	public function create_sync() {
65 65
 		try {
66
-			return rest_ensure_response( $this->synchronization_service->create() );
67
-		} catch ( \Exception $e ) {
66
+			return rest_ensure_response($this->synchronization_service->create());
67
+		} catch (\Exception $e) {
68 68
 			return new \WP_Error(
69 69
 				'wl_error_synchronization_running',
70
-				esc_html__( 'Another synchronization is already running.', 'wordlift' ),
71
-				array( 'status' => 409 )
70
+				esc_html__('Another synchronization is already running.', 'wordlift'),
71
+				array('status' => 409)
72 72
 			);
73 73
 		}
74 74
 	}
75 75
 
76
-	public function list_syncs( WP_REST_Request $request ) {
76
+	public function list_syncs(WP_REST_Request $request) {
77 77
 		$last_synchronization = $this->synchronization_service->load();
78
-		$is_running_all       = ! $request->has_param( 'is_running' );
79
-		if ( is_a( $last_synchronization, 'Wordlift\Modules\Dashboard\Synchronization\Synchronization' )
80
-			&& ( $is_running_all || $request->get_param( 'is_running' ) === $last_synchronization->is_running() ) ) {
81
-			$data = array( $last_synchronization );
78
+		$is_running_all       = ! $request->has_param('is_running');
79
+		if (is_a($last_synchronization, 'Wordlift\Modules\Dashboard\Synchronization\Synchronization')
80
+			&& ($is_running_all || $request->get_param('is_running') === $last_synchronization->is_running())) {
81
+			$data = array($last_synchronization);
82 82
 		} else {
83 83
 			$data = array();
84 84
 		}
85 85
 
86
-		return rest_ensure_response( array( 'items' => $data ) );
86
+		return rest_ensure_response(array('items' => $data));
87 87
 	}
88 88
 
89 89
 	public function delete_syncs() {
Please login to merge, or discard this patch.
src/modules/dashboard/includes/Match/Match_Sort.php 2 patches
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -4,75 +4,75 @@
 block discarded – undo
4 4
 
5 5
 abstract class Match_Sort {
6 6
 
7
-	/**
8
-	 * The sort string, example: +name,-name,-id,+id
9
-	 *
10
-	 * @var string
11
-	 */
12
-	protected $sort;
7
+    /**
8
+     * The sort string, example: +name,-name,-id,+id
9
+     *
10
+     * @var string
11
+     */
12
+    protected $sort;
13 13
 
14
-	public function __construct( $sort ) {
15
-		$this->sort = $sort;
16
-	}
17
-	abstract public function get_field_name();
14
+    public function __construct( $sort ) {
15
+        $this->sort = $sort;
16
+    }
17
+    abstract public function get_field_name();
18 18
 
19
-	public function property_name() {
20
-		$tmp_sort_field_name = substr( $this->sort, 1 );
21
-		// @todo: Need to discuss this code due to unit tests error - Undefined property: stdClass::$name.
22
-		if ( 'id' === $tmp_sort_field_name || str_contains( $tmp_sort_field_name, 'date_modified_gmt' ) ) {
23
-			return 'id';
24
-		} else {
25
-			return 'name';
26
-		}
27
-	}
19
+    public function property_name() {
20
+        $tmp_sort_field_name = substr( $this->sort, 1 );
21
+        // @todo: Need to discuss this code due to unit tests error - Undefined property: stdClass::$name.
22
+        if ( 'id' === $tmp_sort_field_name || str_contains( $tmp_sort_field_name, 'date_modified_gmt' ) ) {
23
+            return 'id';
24
+        } else {
25
+            return 'name';
26
+        }
27
+    }
28 28
 
29
-	public function is_ascending() {
30
-		return strpos( $this->sort, '-' ) !== 0;
31
-	}
29
+    public function is_ascending() {
30
+        return strpos( $this->sort, '-' ) !== 0;
31
+    }
32 32
 
33
-	private function get_sort_order( $direction, $sort_ascending ) {
34
-		switch ( array( $sort_ascending, $direction ) ) {
35
-			case array( true, 'ASCENDING' ):
36
-			case array( false, 'DESCENDING' ):
37
-				return 'ASC';
38
-			case array( true, 'DESCENDING' ):
39
-			case array( false, 'ASCENDING' ):
40
-				return 'DESC';
41
-		}
33
+    private function get_sort_order( $direction, $sort_ascending ) {
34
+        switch ( array( $sort_ascending, $direction ) ) {
35
+            case array( true, 'ASCENDING' ):
36
+            case array( false, 'DESCENDING' ):
37
+                return 'ASC';
38
+            case array( true, 'DESCENDING' ):
39
+            case array( false, 'ASCENDING' ):
40
+                return 'DESC';
41
+        }
42 42
 
43
-		return 'ASC';
44
-	}
43
+        return 'ASC';
44
+    }
45 45
 
46
-	public function get_orderby_clause( $direction ) {
47
-		$sort_order = $this->get_sort_order( $direction, $this->is_ascending() );
48
-		return " ORDER BY {$this->get_field_name()} $sort_order";
49
-	}
46
+    public function get_orderby_clause( $direction ) {
47
+        $sort_order = $this->get_sort_order( $direction, $this->is_ascending() );
48
+        return " ORDER BY {$this->get_field_name()} $sort_order";
49
+    }
50 50
 
51
-	public function apply( &$items ) {
52
-		$sort_ascending     = $this->is_ascending();
53
-		$sort_property_name = $this->property_name();
54
-		usort(
55
-			$items,
56
-			function ( $a, $b ) use ( $sort_ascending, $sort_property_name ) {
57
-				if ( $a->{$sort_property_name} === $b->{$sort_property_name} ) {
58
-					return 0;
59
-				}
51
+    public function apply( &$items ) {
52
+        $sort_ascending     = $this->is_ascending();
53
+        $sort_property_name = $this->property_name();
54
+        usort(
55
+            $items,
56
+            function ( $a, $b ) use ( $sort_ascending, $sort_property_name ) {
57
+                if ( $a->{$sort_property_name} === $b->{$sort_property_name} ) {
58
+                    return 0;
59
+                }
60 60
 
61
-				switch ( array(
62
-					$sort_ascending,
63
-					$a->{$sort_property_name} > $b->{$sort_property_name},
64
-				) ) {
65
-					case array( true, true ):
66
-					case array( false, false ):
67
-						return 1;
68
-					case array( true, false ):
69
-					case array( false, true ):
70
-						return - 1;
71
-				}
61
+                switch ( array(
62
+                    $sort_ascending,
63
+                    $a->{$sort_property_name} > $b->{$sort_property_name},
64
+                ) ) {
65
+                    case array( true, true ):
66
+                    case array( false, false ):
67
+                        return 1;
68
+                    case array( true, false ):
69
+                    case array( false, true ):
70
+                        return - 1;
71
+                }
72 72
 
73
-				return 0;
74
-			}
75
-		);
76
-	}
73
+                return 0;
74
+            }
75
+        );
76
+    }
77 77
 
78 78
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -11,15 +11,15 @@  discard block
 block discarded – undo
11 11
 	 */
12 12
 	protected $sort;
13 13
 
14
-	public function __construct( $sort ) {
14
+	public function __construct($sort) {
15 15
 		$this->sort = $sort;
16 16
 	}
17 17
 	abstract public function get_field_name();
18 18
 
19 19
 	public function property_name() {
20
-		$tmp_sort_field_name = substr( $this->sort, 1 );
20
+		$tmp_sort_field_name = substr($this->sort, 1);
21 21
 		// @todo: Need to discuss this code due to unit tests error - Undefined property: stdClass::$name.
22
-		if ( 'id' === $tmp_sort_field_name || str_contains( $tmp_sort_field_name, 'date_modified_gmt' ) ) {
22
+		if ('id' === $tmp_sort_field_name || str_contains($tmp_sort_field_name, 'date_modified_gmt')) {
23 23
 			return 'id';
24 24
 		} else {
25 25
 			return 'name';
@@ -27,47 +27,47 @@  discard block
 block discarded – undo
27 27
 	}
28 28
 
29 29
 	public function is_ascending() {
30
-		return strpos( $this->sort, '-' ) !== 0;
30
+		return strpos($this->sort, '-') !== 0;
31 31
 	}
32 32
 
33
-	private function get_sort_order( $direction, $sort_ascending ) {
34
-		switch ( array( $sort_ascending, $direction ) ) {
35
-			case array( true, 'ASCENDING' ):
36
-			case array( false, 'DESCENDING' ):
33
+	private function get_sort_order($direction, $sort_ascending) {
34
+		switch (array($sort_ascending, $direction)) {
35
+			case array(true, 'ASCENDING'):
36
+			case array(false, 'DESCENDING'):
37 37
 				return 'ASC';
38
-			case array( true, 'DESCENDING' ):
39
-			case array( false, 'ASCENDING' ):
38
+			case array(true, 'DESCENDING'):
39
+			case array(false, 'ASCENDING'):
40 40
 				return 'DESC';
41 41
 		}
42 42
 
43 43
 		return 'ASC';
44 44
 	}
45 45
 
46
-	public function get_orderby_clause( $direction ) {
47
-		$sort_order = $this->get_sort_order( $direction, $this->is_ascending() );
46
+	public function get_orderby_clause($direction) {
47
+		$sort_order = $this->get_sort_order($direction, $this->is_ascending());
48 48
 		return " ORDER BY {$this->get_field_name()} $sort_order";
49 49
 	}
50 50
 
51
-	public function apply( &$items ) {
51
+	public function apply(&$items) {
52 52
 		$sort_ascending     = $this->is_ascending();
53 53
 		$sort_property_name = $this->property_name();
54 54
 		usort(
55 55
 			$items,
56
-			function ( $a, $b ) use ( $sort_ascending, $sort_property_name ) {
57
-				if ( $a->{$sort_property_name} === $b->{$sort_property_name} ) {
56
+			function($a, $b) use ($sort_ascending, $sort_property_name) {
57
+				if ($a->{$sort_property_name} === $b->{$sort_property_name} ) {
58 58
 					return 0;
59 59
 				}
60 60
 
61
-				switch ( array(
61
+				switch (array(
62 62
 					$sort_ascending,
63 63
 					$a->{$sort_property_name} > $b->{$sort_property_name},
64
-				) ) {
65
-					case array( true, true ):
66
-					case array( false, false ):
64
+				)) {
65
+					case array(true, true):
66
+					case array(false, false):
67 67
 						return 1;
68
-					case array( true, false ):
69
-					case array( false, true ):
70
-						return - 1;
68
+					case array(true, false):
69
+					case array(false, true):
70
+						return -1;
71 71
 				}
72 72
 
73 73
 				return 0;
Please login to merge, or discard this patch.