Completed
Push — develop ( a9eff4...17e8c5 )
by David
02:06 queued 14s
created
src/modules/dashboard/includes/Term_Entity_Match/Term_Query.php 1 patch
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 	 * @param WP_REST_Request $request
40 40
 	 * @param Cursor          $cursor
41 41
 	 */
42
-	public function __construct( $request, $cursor, $cursor_sort, $limit ) {
42
+	public function __construct($request, $cursor, $cursor_sort, $limit) {
43 43
 		global $wpdb;
44 44
 
45 45
 		$this->request     = $request;
@@ -80,24 +80,24 @@  discard block
 block discarded – undo
80 80
 
81 81
 		// The `sql` is prepared in each delegated function in this class.
82 82
 		// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
83
-		$items = $wpdb->get_results( $this->sql );
83
+		$items = $wpdb->get_results($this->sql);
84 84
 
85
-		$sort = ( $this->sort === 'ASC' ? SORT_ASC : SORT_DESC );
86
-		array_multisort( array_column( $items, $this->cursor_sort->get_sort_property() ), $sort, $items );
87
-		$items = array_map( array( $this, 'map_item' ), $items );
85
+		$sort = ($this->sort === 'ASC' ? SORT_ASC : SORT_DESC);
86
+		array_multisort(array_column($items, $this->cursor_sort->get_sort_property()), $sort, $items);
87
+		$items = array_map(array($this, 'map_item'), $items);
88 88
 
89 89
 		return $items;
90 90
 	}
91 91
 
92
-	public function map_item( $item ) {
93
-		$item->match_name = $this->get_match_name( $item->match_jsonld );
92
+	public function map_item($item) {
93
+		$item->match_name = $this->get_match_name($item->match_jsonld);
94 94
 
95 95
 		return $item;
96 96
 	}
97 97
 
98
-	private function get_match_name( $jsonld ) {
99
-		$data = json_decode( $jsonld, true );
100
-		if ( ! $data || ! array_key_exists( 'name', $data ) ) {
98
+	private function get_match_name($jsonld) {
99
+		$data = json_decode($jsonld, true);
100
+		if ( ! $data || ! array_key_exists('name', $data)) {
101 101
 			return null;
102 102
 		}
103 103
 
@@ -105,26 +105,26 @@  discard block
 block discarded – undo
105 105
 	}
106 106
 
107 107
 	private function post_types() {
108
-		$post_types = $this->request->has_param( 'post_types' )
109
-			? (array) $this->request->get_param( 'post_types' )
110
-			: array( 'post', 'page' );
111
-		$value      = array_map( 'esc_sql', $post_types );
112
-		$this->sql .= " AND p.post_type IN ( '" . implode( "', '", $value ) . "' )";
108
+		$post_types = $this->request->has_param('post_types')
109
+			? (array) $this->request->get_param('post_types')
110
+			: array('post', 'page');
111
+		$value      = array_map('esc_sql', $post_types);
112
+		$this->sql .= " AND p.post_type IN ( '".implode("', '", $value)."' )";
113 113
 	}
114 114
 
115 115
 	private function limit() {
116
-		$value      = is_numeric( $this->limit ) ? $this->limit : 10;
117
-		$this->sql .= ' LIMIT ' . esc_sql( $value );
116
+		$value      = is_numeric($this->limit) ? $this->limit : 10;
117
+		$this->sql .= ' LIMIT '.esc_sql($value);
118 118
 	}
119 119
 
120 120
 	private function has_match() {
121
-		if ( ! $this->request->has_param( 'has_match' ) ) {
121
+		if ( ! $this->request->has_param('has_match')) {
122 122
 			return;
123 123
 		}
124 124
 
125
-		$value = (bool) $this->request->get_param( 'has_match' );
125
+		$value = (bool) $this->request->get_param('has_match');
126 126
 
127
-		if ( $value ) {
127
+		if ($value) {
128 128
 			$this->sql .= ' AND e.about_jsonld IS NOT NULL';
129 129
 		} else {
130 130
 			$this->sql .= ' AND e.about_jsonld IS NULL';
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 	}
133 133
 
134 134
 	private function sort() {
135
-		switch ( $this->direction . '$' . $this->sort ) {
135
+		switch ($this->direction.'$'.$this->sort) {
136 136
 			case 'ASCENDING$ASC':
137 137
 			case 'DESCENDING$DESC':
138 138
 				$sort = 'ASC';
@@ -143,15 +143,15 @@  discard block
 block discarded – undo
143 143
 				break;
144 144
 		}
145 145
 
146
-		$this->sql .= ' ORDER BY t.' . $this->sortby . ' ' . $sort;
146
+		$this->sql .= ' ORDER BY t.'.$this->sortby.' '.$sort;
147 147
 	}
148 148
 
149 149
 	private function cursor() {
150
-		if ( ! isset( $this->position ) ) {
150
+		if ( ! isset($this->position)) {
151 151
 			return;
152 152
 		}
153 153
 
154
-		switch ( $this->direction . '$' . $this->sort ) {
154
+		switch ($this->direction.'$'.$this->sort) {
155 155
 			case 'ASCENDING$ASC':
156 156
 			case 'DESCENDING$DESC':
157 157
 				$condition = '>';
@@ -162,11 +162,11 @@  discard block
 block discarded – undo
162 162
 				break;
163 163
 		}
164 164
 
165
-		$condition .= ( $this->element === 'INCLUDED' ? '=' : '' );
165
+		$condition .= ($this->element === 'INCLUDED' ? '=' : '');
166 166
 		global $wpdb;
167 167
 		// We control the vars in this method.
168 168
 		// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
169
-		$this->sql .= $wpdb->prepare( ' AND t.' . esc_sql( $this->sortby ) . ' ' . $condition . ' %s', $this->position );
169
+		$this->sql .= $wpdb->prepare(' AND t.'.esc_sql($this->sortby).' '.$condition.' %s', $this->position);
170 170
 	}
171 171
 
172 172
 	private function set_sort() {
@@ -175,31 +175,31 @@  discard block
 block discarded – undo
175 175
 			'term_name' => 'name',
176 176
 		);
177 177
 
178
-		$value = $this->request->has_param( 'sort' )
179
-			? $this->request->get_param( 'sort' )
178
+		$value = $this->request->has_param('sort')
179
+			? $this->request->get_param('sort')
180 180
 			: '+term_name';
181 181
 
182
-		$sortby       = substr( $value, 1 );
183
-		$this->sortby = isset( $sortby_to_col[ $sortby ] ) ? $sortby_to_col[ $sortby ] : $sortby;
184
-		$this->sort   = substr( $value, 0, 1 ) === '+' ? 'ASC' : 'DESC';
182
+		$sortby       = substr($value, 1);
183
+		$this->sortby = isset($sortby_to_col[$sortby]) ? $sortby_to_col[$sortby] : $sortby;
184
+		$this->sort   = substr($value, 0, 1) === '+' ? 'ASC' : 'DESC';
185 185
 	}
186 186
 
187 187
 	private function term_contains() {
188
-		if ( ! $this->request->has_param( 'term_contains' ) ) {
188
+		if ( ! $this->request->has_param('term_contains')) {
189 189
 			return;
190 190
 		}
191 191
 
192 192
 		global $wpdb;
193
-		$value      = $this->request->get_param( 'term_contains' );
194
-		$this->sql .= $wpdb->prepare( ' and t.name LIKE %s', '%' . esc_sql( $value ) . '%' );
193
+		$value      = $this->request->get_param('term_contains');
194
+		$this->sql .= $wpdb->prepare(' and t.name LIKE %s', '%'.esc_sql($value).'%');
195 195
 	}
196 196
 
197 197
 	private function taxonomies() {
198
-		$taxonomies = $this->request->has_param( 'taxonomies' )
199
-			? (array) $this->request->get_param( 'taxonomies' )
200
-			: array( 'post_tag', 'category' );
201
-		$value      = array_map( 'esc_sql', $taxonomies );
202
-		$this->sql .= " AND tt.taxonomy IN ( '" . implode( "', '", $value ) . "' )";
198
+		$taxonomies = $this->request->has_param('taxonomies')
199
+			? (array) $this->request->get_param('taxonomies')
200
+			: array('post_tag', 'category');
201
+		$value      = array_map('esc_sql', $taxonomies);
202
+		$this->sql .= " AND tt.taxonomy IN ( '".implode("', '", $value)."' )";
203 203
 	}
204 204
 
205 205
 }
Please login to merge, or discard this patch.