Completed
Push — develop ( ea7315...985324 )
by David
01:53 queued 15s
created
src/modules/dashboard/includes/Post_Entity_Match/Recipe_Query.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	 * @param WP_REST_Request $request
39 39
 	 * @param Cursor          $cursor
40 40
 	 */
41
-	public function __construct( $request, $cursor, $cursor_sort, $limit ) {
41
+	public function __construct($request, $cursor, $cursor_sort, $limit) {
42 42
 		global $wpdb;
43 43
 
44 44
 		$this->request     = $request;
@@ -88,34 +88,34 @@  discard block
 block discarded – undo
88 88
 
89 89
 		// The `sql` is prepared in each delegated function in this class.
90 90
 		// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
91
-		$items = $wpdb->get_results( $this->sql );
91
+		$items = $wpdb->get_results($this->sql);
92 92
 
93
-		$sort = ( $this->sort === 'ASC' ? SORT_ASC : SORT_DESC );
94
-		array_multisort( array_column( $items, $this->cursor_sort->get_sort_property() ), $sort, $items );
95
-		$items = array_map( array( $this, 'map_item' ), $items );
93
+		$sort = ($this->sort === 'ASC' ? SORT_ASC : SORT_DESC);
94
+		array_multisort(array_column($items, $this->cursor_sort->get_sort_property()), $sort, $items);
95
+		$items = array_map(array($this, 'map_item'), $items);
96 96
 
97 97
 		return $items;
98 98
 	}
99 99
 
100
-	public function map_item( $item ) {
101
-		if ( $item->id ) {
102
-			$item->post_link    = get_edit_post_link( $item->id, 'ui' );
103
-			$item->view_link    = get_permalink( $item->id );
104
-			$item->preview_link = get_preview_post_link( $item->id );
100
+	public function map_item($item) {
101
+		if ($item->id) {
102
+			$item->post_link    = get_edit_post_link($item->id, 'ui');
103
+			$item->view_link    = get_permalink($item->id);
104
+			$item->preview_link = get_preview_post_link($item->id);
105 105
 		}
106 106
 
107
-		if ( $item->parent_post_id ) {
108
-			$item->parent_post_link = get_edit_post_link( $item->parent_post_id, 'ui' );
107
+		if ($item->parent_post_id) {
108
+			$item->parent_post_link = get_edit_post_link($item->parent_post_id, 'ui');
109 109
 		}
110 110
 
111
-		$item->match_name = $this->get_match_name( $item->match_jsonld );
111
+		$item->match_name = $this->get_match_name($item->match_jsonld);
112 112
 
113 113
 		return $item;
114 114
 	}
115 115
 
116
-	private function get_match_name( $jsonld ) {
117
-		$data = json_decode( $jsonld, true );
118
-		if ( ! $data || ! array_key_exists( 'name', $data ) ) {
116
+	private function get_match_name($jsonld) {
117
+		$data = json_decode($jsonld, true);
118
+		if ( ! $data || ! array_key_exists('name', $data)) {
119 119
 			return null;
120 120
 		}
121 121
 
@@ -123,26 +123,26 @@  discard block
 block discarded – undo
123 123
 	}
124 124
 
125 125
 	private function post_types() {
126
-		$post_types = $this->request->has_param( 'post_types' )
127
-			? (array) $this->request->get_param( 'post_types' )
128
-			: array( 'post', 'page' );
129
-		$value      = array_map( 'esc_sql', $post_types );
130
-		$this->sql .= " AND p.post_type IN ( '" . implode( "', '", $value ) . "' )";
126
+		$post_types = $this->request->has_param('post_types')
127
+			? (array) $this->request->get_param('post_types')
128
+			: array('post', 'page');
129
+		$value      = array_map('esc_sql', $post_types);
130
+		$this->sql .= " AND p.post_type IN ( '".implode("', '", $value)."' )";
131 131
 	}
132 132
 
133 133
 	private function limit() {
134
-		$value      = is_numeric( $this->limit ) ? $this->limit : 10;
135
-		$this->sql .= ' LIMIT ' . esc_sql( $value );
134
+		$value      = is_numeric($this->limit) ? $this->limit : 10;
135
+		$this->sql .= ' LIMIT '.esc_sql($value);
136 136
 	}
137 137
 
138 138
 	private function has_match() {
139
-		if ( ! $this->request->has_param( 'has_match' ) ) {
139
+		if ( ! $this->request->has_param('has_match')) {
140 140
 			return;
141 141
 		}
142 142
 
143
-		$value = (bool) $this->request->get_param( 'has_match' );
143
+		$value = (bool) $this->request->get_param('has_match');
144 144
 
145
-		if ( $value ) {
145
+		if ($value) {
146 146
 			$this->sql .= ' AND e.about_jsonld IS NOT NULL';
147 147
 		} else {
148 148
 			$this->sql .= ' AND e.about_jsonld IS NULL';
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	}
151 151
 
152 152
 	private function sort() {
153
-		switch ( $this->direction . '$' . $this->sort ) {
153
+		switch ($this->direction.'$'.$this->sort) {
154 154
 			case 'ASCENDING$ASC':
155 155
 			case 'DESCENDING$DESC':
156 156
 				$sort = 'ASC';
@@ -161,27 +161,27 @@  discard block
 block discarded – undo
161 161
 				break;
162 162
 		}
163 163
 
164
-		$this->sql .= ' ORDER BY p.' . $this->sortby . ' ' . $sort;
164
+		$this->sql .= ' ORDER BY p.'.$this->sortby.' '.$sort;
165 165
 	}
166 166
 
167 167
 	private function post_status() {
168
-		if ( ! $this->request->has_param( 'post_status' ) ) {
168
+		if ( ! $this->request->has_param('post_status')) {
169 169
 			$this->sql .= " AND p.post_status IN ( 'draft', 'publish' ) ";
170 170
 
171 171
 			return;
172 172
 		}
173 173
 
174 174
 		global $wpdb;
175
-		$value      = $this->request->get_param( 'post_status' );
176
-		$this->sql .= $wpdb->prepare( ' AND p.post_status = %s', $value );
175
+		$value      = $this->request->get_param('post_status');
176
+		$this->sql .= $wpdb->prepare(' AND p.post_status = %s', $value);
177 177
 	}
178 178
 
179 179
 	private function cursor() {
180
-		if ( ! isset( $this->position ) ) {
180
+		if ( ! isset($this->position)) {
181 181
 			return;
182 182
 		}
183 183
 
184
-		switch ( $this->direction . '$' . $this->sort ) {
184
+		switch ($this->direction.'$'.$this->sort) {
185 185
 			case 'ASCENDING$ASC':
186 186
 			case 'DESCENDING$DESC':
187 187
 				$condition = '>';
@@ -192,11 +192,11 @@  discard block
 block discarded – undo
192 192
 				break;
193 193
 		}
194 194
 
195
-		$condition .= ( $this->element === 'INCLUDED' ? '=' : '' );
195
+		$condition .= ($this->element === 'INCLUDED' ? '=' : '');
196 196
 		global $wpdb;
197 197
 		// We control the vars in this method.
198 198
 		// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
199
-		$this->sql .= $wpdb->prepare( ' AND p.' . esc_sql( $this->sortby ) . ' ' . $condition . ' %s', $this->position );
199
+		$this->sql .= $wpdb->prepare(' AND p.'.esc_sql($this->sortby).' '.$condition.' %s', $this->position);
200 200
 	}
201 201
 
202 202
 	private function set_sort() {
@@ -204,13 +204,13 @@  discard block
 block discarded – undo
204 204
 			'date_modified_gmt' => 'post_modified_gmt',
205 205
 		);
206 206
 
207
-		$value = $this->request->has_param( 'sort' )
208
-			? $this->request->get_param( 'sort' )
207
+		$value = $this->request->has_param('sort')
208
+			? $this->request->get_param('sort')
209 209
 			: '-date_modified_gmt';
210 210
 
211
-		$sortby       = substr( $value, 1 );
212
-		$this->sortby = isset( $sortby_to_col[ $sortby ] ) ? $sortby_to_col[ $sortby ] : $sortby;
213
-		$this->sort   = substr( $value, 0, 1 ) === '+' ? 'ASC' : 'DESC';
211
+		$sortby       = substr($value, 1);
212
+		$this->sortby = isset($sortby_to_col[$sortby]) ? $sortby_to_col[$sortby] : $sortby;
213
+		$this->sort   = substr($value, 0, 1) === '+' ? 'ASC' : 'DESC';
214 214
 	}
215 215
 
216 216
 	public static function get_data() {
Please login to merge, or discard this patch.
src/modules/dashboard/includes/Post_Entity_Match/Post_Query.php 1 patch
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	 * @param WP_REST_Request $request
38 38
 	 * @param Cursor          $cursor
39 39
 	 */
40
-	public function __construct( $request, $cursor, $cursor_sort, $limit ) {
40
+	public function __construct($request, $cursor, $cursor_sort, $limit) {
41 41
 		global $wpdb;
42 42
 
43 43
 		$this->request     = $request;
@@ -81,27 +81,27 @@  discard block
 block discarded – undo
81 81
 
82 82
 		// The `sql` is prepared in each delegated function in this class.
83 83
 		// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
84
-		$items = $wpdb->get_results( $this->sql );
84
+		$items = $wpdb->get_results($this->sql);
85 85
 
86
-		$sort = ( $this->sort === 'ASC' ? SORT_ASC : SORT_DESC );
87
-		array_multisort( array_column( $items, $this->cursor_sort->get_sort_property() ), $sort, $items );
88
-		$items = array_map( array( $this, 'map_item' ), $items );
86
+		$sort = ($this->sort === 'ASC' ? SORT_ASC : SORT_DESC);
87
+		array_multisort(array_column($items, $this->cursor_sort->get_sort_property()), $sort, $items);
88
+		$items = array_map(array($this, 'map_item'), $items);
89 89
 
90 90
 		return $items;
91 91
 	}
92 92
 
93
-	public function map_item( $item ) {
94
-		$item->post_link    = get_edit_post_link( $item->id, 'ui' );
95
-		$item->view_link    = get_permalink( $item->id );
96
-		$item->preview_link = get_preview_post_link( $item->id );
97
-		$item->match_name   = $this->get_match_name( $item->match_jsonld );
93
+	public function map_item($item) {
94
+		$item->post_link    = get_edit_post_link($item->id, 'ui');
95
+		$item->view_link    = get_permalink($item->id);
96
+		$item->preview_link = get_preview_post_link($item->id);
97
+		$item->match_name   = $this->get_match_name($item->match_jsonld);
98 98
 
99 99
 		return $item;
100 100
 	}
101 101
 
102
-	private function get_match_name( $jsonld ) {
103
-		$data = json_decode( $jsonld, true );
104
-		if ( ! $data || ! array_key_exists( 'name', $data ) ) {
102
+	private function get_match_name($jsonld) {
103
+		$data = json_decode($jsonld, true);
104
+		if ( ! $data || ! array_key_exists('name', $data)) {
105 105
 			return null;
106 106
 		}
107 107
 
@@ -109,26 +109,26 @@  discard block
 block discarded – undo
109 109
 	}
110 110
 
111 111
 	private function post_types() {
112
-		$post_types = $this->request->has_param( 'post_types' )
113
-			? (array) $this->request->get_param( 'post_types' )
114
-			: array( 'post', 'page' );
115
-		$value      = array_map( 'esc_sql', $post_types );
116
-		$this->sql .= " AND p.post_type IN ( '" . implode( "', '", $value ) . "' )";
112
+		$post_types = $this->request->has_param('post_types')
113
+			? (array) $this->request->get_param('post_types')
114
+			: array('post', 'page');
115
+		$value      = array_map('esc_sql', $post_types);
116
+		$this->sql .= " AND p.post_type IN ( '".implode("', '", $value)."' )";
117 117
 	}
118 118
 
119 119
 	private function limit() {
120
-		$value      = is_numeric( $this->limit ) ? $this->limit : 10;
121
-		$this->sql .= ' LIMIT ' . esc_sql( $value );
120
+		$value      = is_numeric($this->limit) ? $this->limit : 10;
121
+		$this->sql .= ' LIMIT '.esc_sql($value);
122 122
 	}
123 123
 
124 124
 	private function has_match() {
125
-		if ( ! $this->request->has_param( 'has_match' ) ) {
125
+		if ( ! $this->request->has_param('has_match')) {
126 126
 			return;
127 127
 		}
128 128
 
129
-		$value = (bool) $this->request->get_param( 'has_match' );
129
+		$value = (bool) $this->request->get_param('has_match');
130 130
 
131
-		if ( $value ) {
131
+		if ($value) {
132 132
 			$this->sql .= ' AND e.about_jsonld IS NOT NULL';
133 133
 		} else {
134 134
 			$this->sql .= ' AND e.about_jsonld IS NULL';
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 	}
137 137
 
138 138
 	private function sort() {
139
-		switch ( $this->direction . '$' . $this->sort ) {
139
+		switch ($this->direction.'$'.$this->sort) {
140 140
 			case 'ASCENDING$ASC':
141 141
 			case 'DESCENDING$DESC':
142 142
 				$sort = 'ASC';
@@ -147,27 +147,27 @@  discard block
 block discarded – undo
147 147
 				break;
148 148
 		}
149 149
 
150
-		$this->sql .= ' ORDER BY p.' . $this->sortby . ' ' . $sort;
150
+		$this->sql .= ' ORDER BY p.'.$this->sortby.' '.$sort;
151 151
 	}
152 152
 
153 153
 	private function post_status() {
154
-		if ( ! $this->request->has_param( 'post_status' ) ) {
154
+		if ( ! $this->request->has_param('post_status')) {
155 155
 			$this->sql .= " AND p.post_status IN ( 'draft', 'publish' ) ";
156 156
 
157 157
 			return;
158 158
 		}
159 159
 
160 160
 		global $wpdb;
161
-		$value      = $this->request->get_param( 'post_status' );
162
-		$this->sql .= $wpdb->prepare( ' AND p.post_status = %s', $value );
161
+		$value      = $this->request->get_param('post_status');
162
+		$this->sql .= $wpdb->prepare(' AND p.post_status = %s', $value);
163 163
 	}
164 164
 
165 165
 	private function cursor() {
166
-		if ( ! isset( $this->position ) ) {
166
+		if ( ! isset($this->position)) {
167 167
 			return;
168 168
 		}
169 169
 
170
-		switch ( $this->direction . '$' . $this->sort ) {
170
+		switch ($this->direction.'$'.$this->sort) {
171 171
 			case 'ASCENDING$ASC':
172 172
 			case 'DESCENDING$DESC':
173 173
 				$condition = '>';
@@ -178,11 +178,11 @@  discard block
 block discarded – undo
178 178
 				break;
179 179
 		}
180 180
 
181
-		$condition .= ( $this->element === 'INCLUDED' ? '=' : '' );
181
+		$condition .= ($this->element === 'INCLUDED' ? '=' : '');
182 182
 		global $wpdb;
183 183
 		// We control the vars in this method.
184 184
 		// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
185
-		$this->sql .= $wpdb->prepare( ' AND p.' . esc_sql( $this->sortby ) . ' ' . $condition . ' %s', $this->position );
185
+		$this->sql .= $wpdb->prepare(' AND p.'.esc_sql($this->sortby).' '.$condition.' %s', $this->position);
186 186
 	}
187 187
 
188 188
 	private function set_sort() {
@@ -190,13 +190,13 @@  discard block
 block discarded – undo
190 190
 			'date_modified_gmt' => 'post_modified_gmt',
191 191
 		);
192 192
 
193
-		$value = $this->request->has_param( 'sort' )
194
-			? $this->request->get_param( 'sort' )
193
+		$value = $this->request->has_param('sort')
194
+			? $this->request->get_param('sort')
195 195
 			: '-date_modified_gmt';
196 196
 
197
-		$sortby       = substr( $value, 1 );
198
-		$this->sortby = isset( $sortby_to_col[ $sortby ] ) ? $sortby_to_col[ $sortby ] : $sortby;
199
-		$this->sort   = substr( $value, 0, 1 ) === '+' ? 'ASC' : 'DESC';
197
+		$sortby       = substr($value, 1);
198
+		$this->sortby = isset($sortby_to_col[$sortby]) ? $sortby_to_col[$sortby] : $sortby;
199
+		$this->sort   = substr($value, 0, 1) === '+' ? 'ASC' : 'DESC';
200 200
 	}
201 201
 
202 202
 }
Please login to merge, or discard this patch.