Test Failed
Push — tmp ( 15f615...89cc97 )
by Paul
10:31 queued 04:40
created
plugin/Database/QuerySql.php 1 patch
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -10,28 +10,28 @@  discard block
 block discarded – undo
10 10
     public $args;
11 11
     public $db;
12 12
 
13
-    public function escFieldsForInsert(array $fields)
13
+    public function escFieldsForInsert( array $fields )
14 14
     {
15
-        return sprintf('(`%s`)', implode('`,`', $fields));
15
+        return sprintf( '(`%s`)', implode( '`,`', $fields ) );
16 16
     }
17 17
 
18
-    public function escValuesForInsert(array $values)
18
+    public function escValuesForInsert( array $values )
19 19
     {
20
-        $values = array_map('esc_sql', $values);
21
-        return sprintf("('%s')", implode("','", array_values($values)));
20
+        $values = array_map( 'esc_sql', $values );
21
+        return sprintf( "('%s')", implode( "','", array_values( $values ) ) );
22 22
     }
23 23
 
24 24
     /**
25 25
      * @param string $clause
26 26
      * @return array
27 27
      */
28
-    public function sqlClauses(array $values, $clause)
28
+    public function sqlClauses( array $values, $clause )
29 29
     {
30
-        $prefix = Str::restrictTo('and, join', $clause);
31
-        foreach (array_keys($this->args) as $key) {
32
-            $method = Helper::buildMethodName($key, 'clause-'.$prefix);
33
-            if (method_exists($this, $method)) {
34
-                $values[] = call_user_func([$this, $method]);
30
+        $prefix = Str::restrictTo( 'and, join', $clause );
31
+        foreach( array_keys( $this->args ) as $key ) {
32
+            $method = Helper::buildMethodName( $key, 'clause-'.$prefix );
33
+            if( method_exists( $this, $method ) ) {
34
+                $values[] = call_user_func( [$this, $method] );
35 35
             }
36 36
         }
37 37
         return $values;
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public function sqlFrom()
44 44
     {
45
-        $from = "FROM {$this->table('ratings')} r";
46
-        $from = glsr()->filterString('query/sql/from', $from, $this);
45
+        $from = "FROM {$this->table( 'ratings' )} r";
46
+        $from = glsr()->filterString( 'query/sql/from', $from, $this );
47 47
         return $from;
48 48
     }
49 49
 
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
     public function sqlGroupBy()
54 54
     {
55 55
         $groupBy = 'GROUP BY p.ID';
56
-        return glsr()->filterString('query/sql/group-by', $groupBy, $this);
56
+        return glsr()->filterString( 'query/sql/group-by', $groupBy, $this );
57 57
     }
58 58
 
59 59
     /**
@@ -64,8 +64,8 @@  discard block
 block discarded – undo
64 64
         $join = [
65 65
             "INNER JOIN {$this->db->posts} AS p ON r.review_id = p.ID",
66 66
         ];
67
-        $join = glsr()->filterArray('query/sql/join', $join, $this);
68
-        return implode(' ', $join);
67
+        $join = glsr()->filterArray( 'query/sql/join', $join, $this );
68
+        return implode( ' ', $join );
69 69
     }
70 70
 
71 71
     /**
@@ -73,9 +73,9 @@  discard block
 block discarded – undo
73 73
      */
74 74
     public function sqlJoinClauses()
75 75
     {
76
-        $join = $this->sqlClauses([], 'join');
77
-        $join = glsr()->filterArray('query/sql/join-clauses', $join, $this);
78
-        return trim($this->sqlJoin().' '.implode(' ', $join));
76
+        $join = $this->sqlClauses( [], 'join' );
77
+        $join = glsr()->filterArray( 'query/sql/join-clauses', $join, $this );
78
+        return trim( $this->sqlJoin().' '.implode( ' ', $join ) );
79 79
     }
80 80
 
81 81
     /**
@@ -84,12 +84,12 @@  discard block
 block discarded – undo
84 84
     public function sqlJoinPivots()
85 85
     {
86 86
         $join = [
87
-            "LEFT JOIN {$this->table('assigned_posts')} apt on r.ID = apt.rating_id",
88
-            "LEFT JOIN {$this->table('assigned_terms')} att on r.ID = att.rating_id",
89
-            "LEFT JOIN {$this->table('assigned_users')} aut on r.ID = aut.rating_id",
87
+            "LEFT JOIN {$this->table( 'assigned_posts' )} apt on r.ID = apt.rating_id",
88
+            "LEFT JOIN {$this->table( 'assigned_terms' )} att on r.ID = att.rating_id",
89
+            "LEFT JOIN {$this->table( 'assigned_users' )} aut on r.ID = aut.rating_id",
90 90
         ];
91
-        $join = glsr()->filterArray('query/sql/join-pivots', $join, $this);
92
-        return implode(' ', $join);
91
+        $join = glsr()->filterArray( 'query/sql/join-pivots', $join, $this );
92
+        return implode( ' ', $join );
93 93
     }
94 94
 
95 95
     /**
@@ -98,9 +98,9 @@  discard block
 block discarded – undo
98 98
     public function sqlLimit()
99 99
     {
100 100
         $limit = $this->args['per_page'] > 0
101
-            ? $this->db->prepare('LIMIT %d', $this->args['per_page'])
101
+            ? $this->db->prepare( 'LIMIT %d', $this->args['per_page'] )
102 102
             : '';
103
-        return glsr()->filterString('query/sql/limit', $limit, $this);
103
+        return glsr()->filterString( 'query/sql/limit', $limit, $this );
104 104
     }
105 105
 
106 106
     /**
@@ -110,9 +110,9 @@  discard block
 block discarded – undo
110 110
     {
111 111
         $offsetBy = (($this->args['page'] - 1) * $this->args['per_page']) + $this->args['offset'];
112 112
         $offset = ($offsetBy > 0)
113
-            ? $this->db->prepare('OFFSET %d', $offsetBy)
113
+            ? $this->db->prepare( 'OFFSET %d', $offsetBy )
114 114
             : '';
115
-        return glsr()->filterString('query/sql/offset', $offset, $this);
115
+        return glsr()->filterString( 'query/sql/offset', $offset, $this );
116 116
     }
117 117
 
118 118
     /**
@@ -127,14 +127,14 @@  discard block
 block discarded – undo
127 127
         ];
128 128
         $order = $this->args['order'];
129 129
         $orderby = $this->args['orderby'];
130
-        if (Str::startsWith('p.', $orderby)) {
130
+        if( Str::startsWith( 'p.', $orderby ) ) {
131 131
             $orderBy = "ORDER BY r.is_pinned {$order}, {$orderby} {$order}";
132
-        } elseif (array_key_exists($orderby, $values)) {
132
+        } elseif( array_key_exists( $orderby, $values ) ) {
133 133
             $orderBy = $orderby;
134 134
         } else {
135 135
             $orderBy = '';
136 136
         }
137
-        return glsr()->filterString('query/sql/order-by', $orderBy, $this);
137
+        return glsr()->filterString( 'query/sql/order-by', $orderBy, $this );
138 138
     }
139 139
 
140 140
     /**
@@ -153,8 +153,8 @@  discard block
 block discarded – undo
153 153
             'GROUP_CONCAT(DISTINCT att.term_id) as term_ids',
154 154
             'GROUP_CONCAT(DISTINCT aut.user_id) as user_ids',
155 155
         ];
156
-        $select = glsr()->filterArray('query/sql/select', $select, $this);
157
-        $select = implode(', ', $select);
156
+        $select = glsr()->filterArray( 'query/sql/select', $select, $this );
157
+        $select = implode( ', ', $select );
158 158
         return "SELECT {$select}";
159 159
     }
160 160
 
@@ -164,21 +164,21 @@  discard block
 block discarded – undo
164 164
     public function sqlWhere()
165 165
     {
166 166
         $where = [
167
-            $this->db->prepare('AND p.post_type = %s', glsr()->post_type),
167
+            $this->db->prepare( 'AND p.post_type = %s', glsr()->post_type ),
168 168
             "AND p.post_status = 'publish'",
169 169
         ];
170
-        $where = $this->sqlClauses($where, 'and');
171
-        $where = glsr()->filterArray('query/sql/where', $where, $this);
172
-        $where = implode(' ', $where);
170
+        $where = $this->sqlClauses( $where, 'and' );
171
+        $where = glsr()->filterArray( 'query/sql/where', $where, $this );
172
+        $where = implode( ' ', $where );
173 173
         return "WHERE 1=1 {$where}";
174 174
     }
175 175
 
176 176
     /**
177 177
      * @return string
178 178
      */
179
-    public function table($table)
179
+    public function table( $table )
180 180
     {
181
-        return glsr(SqlSchema::class)->table($table);
181
+        return glsr( SqlSchema::class )->table( $table );
182 182
     }
183 183
 
184 184
     /**
@@ -188,16 +188,16 @@  discard block
 block discarded – undo
188 188
     protected function clauseAndAssignedTo()
189 189
     {
190 190
         $clauses = [];
191
-        if ($postIds = $this->args['assigned_to']) {
192
-            $clauses[] = $this->db->prepare('(apt.post_id IN (%s) AND apt.is_published = 1)', implode(',', $postIds));
191
+        if( $postIds = $this->args['assigned_to'] ) {
192
+            $clauses[] = $this->db->prepare( '(apt.post_id IN (%s) AND apt.is_published = 1)', implode( ',', $postIds ) );
193 193
         }
194
-        if ($termIds = $this->args['category']) {
195
-            $clauses[] = $this->db->prepare('(att.term_id IN (%s))', implode(',', $termIds));
194
+        if( $termIds = $this->args['category'] ) {
195
+            $clauses[] = $this->db->prepare( '(att.term_id IN (%s))', implode( ',', $termIds ) );
196 196
         }
197
-        if ($userIds = $this->args['user']) {
198
-            $clauses[] = $this->db->prepare('(aut.user_id IN (%s))', implode(',', $userIds));
197
+        if( $userIds = $this->args['user'] ) {
198
+            $clauses[] = $this->db->prepare( '(aut.user_id IN (%s))', implode( ',', $userIds ) );
199 199
         }
200
-        if ($clauses = implode(' OR ', $clauses)) {
200
+        if( $clauses = implode( ' OR ', $clauses ) ) {
201 201
             return "AND ($clauses)";
202 202
         }
203 203
         return '';
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
     protected function clauseAndRating()
210 210
     {
211 211
         return $this->args['rating']
212
-            ? $this->db->prepare('AND r.rating > %d', --$this->args['rating'])
212
+            ? $this->db->prepare( 'AND r.rating > %d', --$this->args['rating'] )
213 213
             : '';
214 214
     }
215 215
 
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
     protected function clauseAndType()
220 220
     {
221 221
         return $this->args['type']
222
-            ? $this->db->prepare('AND r.type = %s', $this->args['type'])
222
+            ? $this->db->prepare( 'AND r.type = %s', $this->args['type'] )
223 223
             : '';
224 224
     }
225 225
 
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
     protected function clauseJoinAssignedTo()
230 230
     {
231 231
         return !empty($this->args['assigned_to'])
232
-            ? "INNER JOIN {$this->table('assigned_posts')} AS apt ON r.ID = apt.rating_id"
232
+            ? "INNER JOIN {$this->table( 'assigned_posts' )} AS apt ON r.ID = apt.rating_id"
233 233
             : '';
234 234
     }
235 235
 
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
     protected function clauseJoinCategory()
240 240
     {
241 241
         return !empty($this->args['category'])
242
-            ? "INNER JOIN {$this->table('assigned_terms')} AS att ON r.ID = att.rating_id"
242
+            ? "INNER JOIN {$this->table( 'assigned_terms' )} AS att ON r.ID = att.rating_id"
243 243
             : '';
244 244
     }
245 245
 
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
     protected function clauseJoinUser()
250 250
     {
251 251
         return !empty($this->args['user'])
252
-            ? "INNER JOIN {$this->table('assigned_users')} AS aut ON r.ID = aut.rating_id"
252
+            ? "INNER JOIN {$this->table( 'assigned_users' )} AS aut ON r.ID = aut.rating_id"
253 253
             : '';
254 254
     }
255 255
 }
Please login to merge, or discard this patch.
plugin/Database/SqlQueries.php 1 patch
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -25,11 +25,11 @@  discard block
 block discarded – undo
25 25
      */
26 26
     public function deletePostCountMetaKeys()
27 27
     {
28
-        return $this->db->query("
28
+        return $this->db->query( "
29 29
             DELETE
30 30
             FROM {$this->db->postmeta}
31 31
             WHERE meta_key LIKE '_glsr_%'
32
-        ");
32
+        " );
33 33
     }
34 34
 
35 35
     /**
@@ -37,46 +37,46 @@  discard block
 block discarded – undo
37 37
      */
38 38
     public function deleteTermCountMetaKeys()
39 39
     {
40
-        return $this->db->query("
40
+        return $this->db->query( "
41 41
             DELETE
42 42
             FROM {$this->db->termmeta}
43 43
             WHERE meta_key LIKE '_glsr_%'
44
-        ");
44
+        " );
45 45
     }
46 46
 
47 47
     /**
48 48
      * @param string $metaReviewId
49 49
      * @return int
50 50
      */
51
-    public function getPostIdFromReviewId($metaReviewId)
51
+    public function getPostIdFromReviewId( $metaReviewId )
52 52
     {
53
-        $postId = $this->db->get_var("
53
+        $postId = $this->db->get_var( "
54 54
             SELECT p.ID
55 55
             FROM {$this->db->posts} AS p
56 56
             INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
57 57
             WHERE p.post_type = '{$this->postType}'
58 58
             AND m.meta_key = '_review_id'
59 59
             AND m.meta_value = '{$metaReviewId}'
60
-        ");
61
-        return intval($postId);
60
+        " );
61
+        return intval( $postId );
62 62
     }
63 63
 
64 64
     /**
65 65
      * @return array
66 66
      */
67
-    public function getRatings(array $args)
67
+    public function getRatings( array $args )
68 68
     {
69 69
         // get types
70 70
         // get for each type
71
-        $table = glsr(SqlSchema::class)->table('ratings');
72
-        return (array) $this->db->get_results("
71
+        $table = glsr( SqlSchema::class )->table( 'ratings' );
72
+        return (array)$this->db->get_results( "
73 73
             SELECT r.rating AS rating, COUNT(r.rating) AS count
74 74
             FROM {$table} AS r
75
-            {$this->getInnerJoinForRatings($args)}
75
+            {$this->getInnerJoinForRatings( $args )}
76 76
             WHERE r.is_approved = 1
77
-            {$this->getAndForRatings($args)}
77
+            {$this->getAndForRatings( $args )}
78 78
             GROUP BY rating
79
-        ");
79
+        " );
80 80
     }
81 81
 
82 82
     /**
@@ -84,23 +84,23 @@  discard block
 block discarded – undo
84 84
      * @param int $limit
85 85
      * @return array
86 86
      */
87
-    public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500)
87
+    public function getReviewCounts( array $args, $lastPostId = 0, $limit = 500 )
88 88
     {
89
-        return (array) $this->db->get_results("
89
+        return (array)$this->db->get_results( "
90 90
             SELECT DISTINCT p.ID, m1.meta_value AS rating, m2.meta_value AS type
91 91
             FROM {$this->db->posts} AS p
92 92
             INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id
93 93
             INNER JOIN {$this->db->postmeta} AS m2 ON p.ID = m2.post_id
94
-            {$this->getInnerJoinForCounts($args)}
94
+            {$this->getInnerJoinForCounts( $args )}
95 95
             WHERE p.ID > {$lastPostId}
96 96
             AND p.post_status = 'publish'
97 97
             AND p.post_type = '{$this->postType}'
98 98
             AND m1.meta_key = '_rating'
99 99
             AND m2.meta_key = '_review_type'
100
-            {$this->getAndForCounts($args)}
100
+            {$this->getAndForCounts( $args )}
101 101
             ORDER By p.ID ASC
102 102
             LIMIT {$limit}
103
-        ");
103
+        " );
104 104
     }
105 105
 
106 106
     /**
@@ -108,17 +108,17 @@  discard block
 block discarded – undo
108 108
      * @param string $metaKey
109 109
      * @return array
110 110
      */
111
-    public function getReviewCountsFor($metaKey)
111
+    public function getReviewCountsFor( $metaKey )
112 112
     {
113
-        $metaKey = Str::prefix('_', $metaKey);
114
-        return (array) $this->db->get_results("
113
+        $metaKey = Str::prefix( '_', $metaKey );
114
+        return (array)$this->db->get_results( "
115 115
             SELECT DISTINCT m.meta_value AS name, COUNT(*) num_posts
116 116
             FROM {$this->db->posts} AS p
117 117
             INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
118 118
             WHERE p.post_type = '{$this->postType}'
119 119
             AND m.meta_key = '{$metaKey}'
120 120
             GROUP BY name
121
-        ");
121
+        " );
122 122
     }
123 123
 
124 124
     /**
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
      * @param string $reviewType
127 127
      * @return array
128 128
      */
129
-    public function getReviewIdsByType($reviewType)
129
+    public function getReviewIdsByType( $reviewType )
130 130
     {
131
-        $results = $this->db->get_col("
131
+        $results = $this->db->get_col( "
132 132
             SELECT DISTINCT m1.meta_value AS review_id
133 133
             FROM {$this->db->posts} AS p
134 134
             INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id
@@ -137,8 +137,8 @@  discard block
 block discarded – undo
137 137
             AND m1.meta_key = '_review_id'
138 138
             AND m2.meta_key = '_review_type'
139 139
             AND m2.meta_value = '{$reviewType}'
140
-        ");
141
-        return array_keys(array_flip($results));
140
+        " );
141
+        return array_keys( array_flip( $results ) );
142 142
     }
143 143
 
144 144
     /**
@@ -146,12 +146,12 @@  discard block
 block discarded – undo
146 146
      * @param int $limit
147 147
      * @return array
148 148
      */
149
-    public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100)
149
+    public function getReviewRatingsFromIds( array $postIds, $greaterThanId = 0, $limit = 100 )
150 150
     {
151
-        sort($postIds);
152
-        $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit);
153
-        $postIds = implode(',', $postIds);
154
-        return (array) $this->db->get_results("
151
+        sort( $postIds );
152
+        $postIds = array_slice( $postIds, intval( array_search( $greaterThanId, $postIds ) ), $limit );
153
+        $postIds = implode( ',', $postIds );
154
+        return (array)$this->db->get_results( "
155 155
             SELECT p.ID, m.meta_value AS rating
156 156
             FROM {$this->db->posts} AS p
157 157
             INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
             GROUP BY p.ID
164 164
             ORDER By p.ID ASC
165 165
             LIMIT {$limit}
166
-        ");
166
+        " );
167 167
     }
168 168
 
169 169
     /**
@@ -171,13 +171,13 @@  discard block
 block discarded – undo
171 171
      * @param string $status
172 172
      * @return array
173 173
      */
174
-    public function getReviewsMeta($key, $status = 'publish')
174
+    public function getReviewsMeta( $key, $status = 'publish' )
175 175
     {
176 176
         $postStatusQuery = 'all' != $status && !empty($status)
177 177
             ? "AND p.post_status = '{$status}'"
178 178
             : '';
179
-        $key = Str::prefix('_', $key);
180
-        $values = $this->db->get_col("
179
+        $key = Str::prefix( '_', $key );
180
+        $values = $this->db->get_col( "
181 181
             SELECT DISTINCT m.meta_value
182 182
             FROM {$this->db->postmeta} m
183 183
             LEFT JOIN {$this->db->posts} p ON p.ID = m.post_id
@@ -187,8 +187,8 @@  discard block
 block discarded – undo
187 187
             $postStatusQuery
188 188
             GROUP BY p.ID -- remove duplicate meta_value entries
189 189
             ORDER BY m.meta_id ASC -- sort by oldest meta_value
190
-        ");
191
-        sort($values);
190
+        " );
191
+        sort( $values );
192 192
         return $values;
193 193
     }
194 194
 
@@ -196,79 +196,79 @@  discard block
 block discarded – undo
196 196
      * @param string $and
197 197
      * @return string
198 198
      */
199
-    protected function getAndForCounts(array $args, $and = '')
199
+    protected function getAndForCounts( array $args, $and = '' )
200 200
     {
201
-        $postIds = implode(',', array_filter(Arr::get($args, 'post_ids', [])));
202
-        $termIds = implode(',', array_filter(Arr::get($args, 'term_ids', [])));
203
-        if (!empty($args['type'])) {
201
+        $postIds = implode( ',', array_filter( Arr::get( $args, 'post_ids', [] ) ) );
202
+        $termIds = implode( ',', array_filter( Arr::get( $args, 'term_ids', [] ) ) );
203
+        if( !empty($args['type']) ) {
204 204
             $and .= "AND m2.meta_value = '{$args['type']}' ";
205 205
         }
206
-        if ($postIds) {
206
+        if( $postIds ) {
207 207
             $and .= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) ";
208 208
         }
209
-        if ($termIds) {
209
+        if( $termIds ) {
210 210
             $and .= "AND tr.term_taxonomy_id IN ({$termIds}) ";
211 211
         }
212
-        return glsr()->filter('query/and-for-counts', $and);
212
+        return glsr()->filter( 'query/and-for-counts', $and );
213 213
     }
214 214
 
215 215
     /**
216 216
      * @param string $and
217 217
      * @return string
218 218
      */
219
-    protected function getAndForRatings(array $args, $and = '')
219
+    protected function getAndForRatings( array $args, $and = '' )
220 220
     {
221 221
         $assignedQueries = [];
222
-        if ($postIds = Arr::consolidate(Arr::get($args, 'post_ids', []))) {
223
-            $postIds = implode(',', array_filter($postIds));
222
+        if( $postIds = Arr::consolidate( Arr::get( $args, 'post_ids', [] ) ) ) {
223
+            $postIds = implode( ',', array_filter( $postIds ) );
224 224
             $assignedQueries[] = "(ap.post_id IN ({$postIds}) AND ap.is_published = 1)";
225 225
         }
226
-        if ($termIds = Arr::consolidate(Arr::get($args, 'term_ids', []))) {
227
-            $termIds = implode(',', array_filter($termIds));
226
+        if( $termIds = Arr::consolidate( Arr::get( $args, 'term_ids', [] ) ) ) {
227
+            $termIds = implode( ',', array_filter( $termIds ) );
228 228
             $assignedQueries[] = "at.term_id IN ({$termIds})";
229 229
         }
230
-        if ($rating = Helper::castToInt(Arr::get($args, 'rating'))) {
230
+        if( $rating = Helper::castToInt( Arr::get( $args, 'rating' ) ) ) {
231 231
             ++$rating;
232 232
             $and .= "AND r.rating < {$rating} ";
233 233
         }
234
-        if ($type = Arr::get($args, 'type')) {
234
+        if( $type = Arr::get( $args, 'type' ) ) {
235 235
             $and .= "AND r.type = '{$type}' ";
236 236
         }
237
-        if ($assignedQuery = implode(' OR ', $assignedQueries)) {
237
+        if( $assignedQuery = implode( ' OR ', $assignedQueries ) ) {
238 238
             $and .= "AND ($assignedQuery) ";
239 239
         }
240
-        return glsr()->filter('query/and-for-ratings', $and);
240
+        return glsr()->filter( 'query/and-for-ratings', $and );
241 241
     }
242 242
 
243 243
     /**
244 244
      * @param string $innerJoin
245 245
      * @return string
246 246
      */
247
-    protected function getInnerJoinForCounts(array $args, $innerJoin = '')
247
+    protected function getInnerJoinForCounts( array $args, $innerJoin = '' )
248 248
     {
249
-        if (!empty(Arr::get($args, 'post_ids'))) {
249
+        if( !empty(Arr::get( $args, 'post_ids' )) ) {
250 250
             $innerJoin .= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id ";
251 251
         }
252
-        if (!empty(Arr::get($args, 'term_ids'))) {
252
+        if( !empty(Arr::get( $args, 'term_ids' )) ) {
253 253
             $innerJoin .= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id ";
254 254
         }
255
-        return glsr()->filter('query/inner-join-for-counts', $innerJoin);
255
+        return glsr()->filter( 'query/inner-join-for-counts', $innerJoin );
256 256
     }
257 257
 
258 258
     /**
259 259
      * @param string $innerJoin
260 260
      * @return string
261 261
      */
262
-    protected function getInnerJoinForRatings(array $args, $innerJoin = '')
262
+    protected function getInnerJoinForRatings( array $args, $innerJoin = '' )
263 263
     {
264
-        if (Arr::consolidate(Arr::get($args, 'post_ids', []))) {
265
-            $table = glsr(SqlSchema::class)->table('assigned_posts');
264
+        if( Arr::consolidate( Arr::get( $args, 'post_ids', [] ) ) ) {
265
+            $table = glsr( SqlSchema::class )->table( 'assigned_posts' );
266 266
             $innerJoin .= "INNER JOIN {$table} AS ap ON r.ID = ap.rating_id ";
267 267
         }
268
-        if (Arr::consolidate(Arr::get($args, 'term_ids', []))) {
269
-            $table = glsr(SqlSchema::class)->table('assigned_terms');
268
+        if( Arr::consolidate( Arr::get( $args, 'term_ids', [] ) ) ) {
269
+            $table = glsr( SqlSchema::class )->table( 'assigned_terms' );
270 270
             $innerJoin .= "INNER JOIN {$table} AS at ON r.ID = at.rating_id ";
271 271
         }
272
-        return glsr()->filter('query/inner-join-for-ratings', $innerJoin);
272
+        return glsr()->filter( 'query/inner-join-for-ratings', $innerJoin );
273 273
     }
274 274
 }
Please login to merge, or discard this patch.
plugin/Database/TermCountsManager.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -16,31 +16,31 @@  discard block
 block discarded – undo
16 16
 
17 17
     public function __construct()
18 18
     {
19
-        $this->manager = glsr(CountsManager::class);
19
+        $this->manager = glsr( CountsManager::class );
20 20
     }
21 21
 
22 22
     /**
23 23
      * @param int $termTaxonomyId
24 24
      * @return array
25 25
      */
26
-    public function build($termTaxonomyId)
26
+    public function build( $termTaxonomyId )
27 27
     {
28
-        return $this->manager->buildCounts([
28
+        return $this->manager->buildCounts( [
29 29
             'term_ids' => [$termTaxonomyId],
30
-        ]);
30
+        ] );
31 31
     }
32 32
 
33 33
     /**
34 34
      * @return void
35 35
      */
36
-    public function decrease(Review $review)
36
+    public function decrease( Review $review )
37 37
     {
38
-        foreach ($review->term_ids as $termId) {
39
-            if (empty($counts = $this->get($termId))) {
38
+        foreach( $review->term_ids as $termId ) {
39
+            if( empty($counts = $this->get( $termId )) ) {
40 40
                 continue;
41 41
             }
42
-            $this->update($termId,
43
-                $this->manager->decreaseRating($counts, $review->review_type, $review->rating)
42
+            $this->update( $termId,
43
+                $this->manager->decreaseRating( $counts, $review->review_type, $review->rating )
44 44
             );
45 45
         }
46 46
     }
@@ -49,23 +49,23 @@  discard block
 block discarded – undo
49 49
      * @param int $termId
50 50
      * @return array
51 51
      */
52
-    public function get($termId)
52
+    public function get( $termId )
53 53
     {
54
-        return array_filter((array) get_term_meta($termId, CountsManager::META_COUNT, true));
54
+        return array_filter( (array)get_term_meta( $termId, CountsManager::META_COUNT, true ) );
55 55
     }
56 56
 
57 57
     /**
58 58
      * @return void
59 59
      */
60
-    public function increase(Review $review)
60
+    public function increase( Review $review )
61 61
     {
62
-        $terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids));
63
-        foreach ($terms as $term) {
64
-            $counts = $this->get($term['term_id']);
62
+        $terms = glsr( ReviewManager::class )->normalizeTerms( implode( ',', $review->term_ids ) );
63
+        foreach( $terms as $term ) {
64
+            $counts = $this->get( $term['term_id'] );
65 65
             $counts = empty($counts)
66
-                ? $this->build($term['term_taxonomy_id'])
67
-                : $this->manager->increaseRating($counts, $review->review_type, $review->rating);
68
-            $this->update($term['term_id'], $counts);
66
+                ? $this->build( $term['term_taxonomy_id'] )
67
+                : $this->manager->increaseRating( $counts, $review->review_type, $review->rating );
68
+            $this->update( $term['term_id'], $counts );
69 69
         }
70 70
     }
71 71
 
@@ -73,16 +73,16 @@  discard block
 block discarded – undo
73 73
      * @param int $termId
74 74
      * @return void
75 75
      */
76
-    public function update($termId, array $reviewCounts)
76
+    public function update( $termId, array $reviewCounts )
77 77
     {
78
-        $term = get_term($termId, Application::TAXONOMY);
79
-        if (!isset($term->term_id)) {
78
+        $term = get_term( $termId, Application::TAXONOMY );
79
+        if( !isset($term->term_id) ) {
80 80
             return;
81 81
         }
82
-        $ratingCounts = $this->manager->flatten($reviewCounts);
83
-        update_term_meta($termId, CountsManager::META_COUNT, $reviewCounts);
84
-        update_term_meta($termId, CountsManager::META_AVERAGE, glsr(Rating::class)->average($ratingCounts));
85
-        update_term_meta($termId, CountsManager::META_RANKING, glsr(Rating::class)->ranking($ratingCounts));
82
+        $ratingCounts = $this->manager->flatten( $reviewCounts );
83
+        update_term_meta( $termId, CountsManager::META_COUNT, $reviewCounts );
84
+        update_term_meta( $termId, CountsManager::META_AVERAGE, glsr( Rating::class )->average( $ratingCounts ) );
85
+        update_term_meta( $termId, CountsManager::META_RANKING, glsr( Rating::class )->ranking( $ratingCounts ) );
86 86
     }
87 87
 
88 88
     /**
@@ -91,11 +91,11 @@  discard block
 block discarded – undo
91 91
     public function updateAll()
92 92
     {
93 93
         // glsr(SqlQueries::class)->deleteTermCountMetaKeys(); // @todo test this with SiteGround for race conditions
94
-        $terms = glsr(Database::class)->getTerms([
94
+        $terms = glsr( Database::class )->getTerms( [
95 95
             'fields' => 'all',
96
-        ]);
97
-        foreach ($terms as $term) {
98
-            $this->update($term->term_id, $this->build($term->term_taxonomy_id));
96
+        ] );
97
+        foreach( $terms as $term ) {
98
+            $this->update( $term->term_id, $this->build( $term->term_taxonomy_id ) );
99 99
         }
100 100
     }
101 101
 }
Please login to merge, or discard this patch.
plugin/Database/PostCountsManager.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -14,30 +14,30 @@  discard block
 block discarded – undo
14 14
 
15 15
     public function __construct()
16 16
     {
17
-        $this->manager = glsr(CountsManager::class);
17
+        $this->manager = glsr( CountsManager::class );
18 18
     }
19 19
 
20 20
     /**
21 21
      * @param int $postId
22 22
      * @return array
23 23
      */
24
-    public function build($postId)
24
+    public function build( $postId )
25 25
     {
26
-        return $this->manager->buildCounts([
26
+        return $this->manager->buildCounts( [
27 27
             'post_ids' => [$postId],
28
-        ]);
28
+        ] );
29 29
     }
30 30
 
31 31
     /**
32 32
      * @return void
33 33
      */
34
-    public function decrease(Review $review)
34
+    public function decrease( Review $review )
35 35
     {
36
-        if (empty($counts = $this->get($review->assigned_to))) {
36
+        if( empty($counts = $this->get( $review->assigned_to )) ) {
37 37
             return;
38 38
         }
39
-        $this->update($review->assigned_to,
40
-            $this->manager->decreaseRating($counts, $review->review_type, $review->rating)
39
+        $this->update( $review->assigned_to,
40
+            $this->manager->decreaseRating( $counts, $review->review_type, $review->rating )
41 41
         );
42 42
     }
43 43
 
@@ -45,36 +45,36 @@  discard block
 block discarded – undo
45 45
      * @param int $postId
46 46
      * @return array
47 47
      */
48
-    public function get($postId)
48
+    public function get( $postId )
49 49
     {
50
-        return array_filter((array) get_post_meta($postId, CountsManager::META_COUNT, true));
50
+        return array_filter( (array)get_post_meta( $postId, CountsManager::META_COUNT, true ) );
51 51
     }
52 52
 
53 53
     /**
54 54
      * @return void
55 55
      */
56
-    public function increase(Review $review)
56
+    public function increase( Review $review )
57 57
     {
58
-        if (!get_post($review->assigned_to) instanceof \WP_Post) {
58
+        if( !get_post( $review->assigned_to ) instanceof \WP_Post ) {
59 59
             return;
60 60
         }
61
-        $counts = $this->get($review->assigned_to);
61
+        $counts = $this->get( $review->assigned_to );
62 62
         $counts = empty($counts)
63
-            ? $this->build($review->assigned_to)
64
-            : $this->manager->increaseRating($counts, $review->review_type, $review->rating);
65
-        $this->update($review->assigned_to, $counts);
63
+            ? $this->build( $review->assigned_to )
64
+            : $this->manager->increaseRating( $counts, $review->review_type, $review->rating );
65
+        $this->update( $review->assigned_to, $counts );
66 66
     }
67 67
 
68 68
     /**
69 69
      * @param int $postId
70 70
      * @return void
71 71
      */
72
-    public function update($postId, array $reviewCounts)
72
+    public function update( $postId, array $reviewCounts )
73 73
     {
74
-        $ratingCounts = $this->manager->flatten($reviewCounts);
75
-        update_post_meta($postId, CountsManager::META_COUNT, $reviewCounts);
76
-        update_post_meta($postId, CountsManager::META_AVERAGE, glsr(Rating::class)->average($ratingCounts));
77
-        update_post_meta($postId, CountsManager::META_RANKING, glsr(Rating::class)->ranking($ratingCounts));
74
+        $ratingCounts = $this->manager->flatten( $reviewCounts );
75
+        update_post_meta( $postId, CountsManager::META_COUNT, $reviewCounts );
76
+        update_post_meta( $postId, CountsManager::META_AVERAGE, glsr( Rating::class )->average( $ratingCounts ) );
77
+        update_post_meta( $postId, CountsManager::META_RANKING, glsr( Rating::class )->ranking( $ratingCounts ) );
78 78
     }
79 79
 
80 80
     /**
@@ -82,10 +82,10 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public function updateAll()
84 84
     {
85
-        glsr(SqlQueries::class)->deletePostCountMetaKeys(); // @todo test this with SiteGround for race conditions
86
-        $postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to');
87
-        foreach ($postIds as $postId) {
88
-            $this->update($postId, $this->build($postId));
85
+        glsr( SqlQueries::class )->deletePostCountMetaKeys(); // @todo test this with SiteGround for race conditions
86
+        $postIds = glsr( SqlQueries::class )->getReviewsMeta( 'assigned_to' );
87
+        foreach( $postIds as $postId ) {
88
+            $this->update( $postId, $this->build( $postId ) );
89 89
         }
90 90
     }
91 91
 }
Please login to merge, or discard this patch.
plugin/Database/DefaultsManager.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -12,11 +12,11 @@  discard block
 block discarded – undo
12 12
     public function defaults()
13 13
     {
14 14
         $settings = $this->settings();
15
-        $defaults = (array) array_combine(array_keys($settings), wp_list_pluck($settings, 'default'));
16
-        return wp_parse_args($defaults, [
15
+        $defaults = (array)array_combine( array_keys( $settings ), wp_list_pluck( $settings, 'default' ) );
16
+        return wp_parse_args( $defaults, [
17 17
             'version' => '',
18 18
             'version_upgraded_from' => '',
19
-        ]);
19
+        ] );
20 20
     }
21 21
 
22 22
     /**
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
      */
25 25
     public function get()
26 26
     {
27
-        return Arr::convertFromDotNotation($this->defaults());
27
+        return Arr::convertFromDotNotation( $this->defaults() );
28 28
     }
29 29
 
30 30
     /**
@@ -32,11 +32,11 @@  discard block
 block discarded – undo
32 32
      */
33 33
     public function set()
34 34
     {
35
-        $settings = glsr(OptionManager::class)->all();
36
-        $currentSettings = Arr::removeEmptyValues($settings);
37
-        $defaultSettings = array_replace_recursive($this->get(), $currentSettings);
38
-        $updatedSettings = array_replace_recursive($settings, $defaultSettings);
39
-        update_option(OptionManager::databaseKey(), $updatedSettings);
35
+        $settings = glsr( OptionManager::class )->all();
36
+        $currentSettings = Arr::removeEmptyValues( $settings );
37
+        $defaultSettings = array_replace_recursive( $this->get(), $currentSettings );
38
+        $updatedSettings = array_replace_recursive( $settings, $defaultSettings );
39
+        update_option( OptionManager::databaseKey(), $updatedSettings );
40 40
         return $defaultSettings;
41 41
     }
42 42
 
@@ -45,17 +45,17 @@  discard block
 block discarded – undo
45 45
      */
46 46
     public function settings()
47 47
     {
48
-        $settings = glsr()->filterArray('addon/settings', glsr()->config('settings'));
49
-        return $this->normalize($settings);
48
+        $settings = glsr()->filterArray( 'addon/settings', glsr()->config( 'settings' ) );
49
+        return $this->normalize( $settings );
50 50
     }
51 51
 
52 52
     /**
53 53
      * @return array
54 54
      */
55
-    protected function normalize(array $settings)
55
+    protected function normalize( array $settings )
56 56
     {
57
-        array_walk($settings, function (&$setting) {
58
-            if (isset($setting['default'])) {
57
+        array_walk( $settings, function( &$setting ) {
58
+            if( isset($setting['default']) ) {
59 59
                 return;
60 60
             }
61 61
             $setting['default'] = '';
Please login to merge, or discard this patch.
plugin/Database/NormalizeQueryArgs.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -23,35 +23,35 @@  discard block
 block discarded – undo
23 23
     public $type;
24 24
     public $user;
25 25
 
26
-    public function __construct(array $args = [])
26
+    public function __construct( array $args = [] )
27 27
     {
28
-        $args = glsr(ReviewsDefaults::class)->merge($args);
29
-        $args['assigned_to'] = Arr::uniqueInt(Arr::consolidate($args['assigned_to']));
30
-        $args['category'] = $this->normalizeTermIds($args['category']);
31
-        $args['offset'] = absint(filter_var($args['offset'], FILTER_SANITIZE_NUMBER_INT));
32
-        $args['order'] = Str::restrictTo('ASC,DESC,', sanitize_key($args['order']), 'DESC'); // include an empty value
33
-        $args['orderby'] = $this->normalizeOrderBy($args['orderby']);
34
-        $args['page'] = absint($args['page']);
35
-        $args['per_page'] = absint($args['per_page']); // "0" and "-1" = all
36
-        $args['post__in'] = Arr::uniqueInt(Arr::consolidate($args['post__in']));
37
-        $args['post__not_in'] = Arr::uniqueInt(Arr::consolidate($args['post__not_in']));
38
-        $args['rating'] = absint(filter_var($args['rating'], FILTER_SANITIZE_NUMBER_INT));
39
-        $args['type'] = sanitize_key($args['type']);
40
-        $args['user'] = $this->normalizeUserIds(Arr::consolidate($args['user']));
41
-        parent::__construct($args);
28
+        $args = glsr( ReviewsDefaults::class )->merge( $args );
29
+        $args['assigned_to'] = Arr::uniqueInt( Arr::consolidate( $args['assigned_to'] ) );
30
+        $args['category'] = $this->normalizeTermIds( $args['category'] );
31
+        $args['offset'] = absint( filter_var( $args['offset'], FILTER_SANITIZE_NUMBER_INT ) );
32
+        $args['order'] = Str::restrictTo( 'ASC,DESC,', sanitize_key( $args['order'] ), 'DESC' ); // include an empty value
33
+        $args['orderby'] = $this->normalizeOrderBy( $args['orderby'] );
34
+        $args['page'] = absint( $args['page'] );
35
+        $args['per_page'] = absint( $args['per_page'] ); // "0" and "-1" = all
36
+        $args['post__in'] = Arr::uniqueInt( Arr::consolidate( $args['post__in'] ) );
37
+        $args['post__not_in'] = Arr::uniqueInt( Arr::consolidate( $args['post__not_in'] ) );
38
+        $args['rating'] = absint( filter_var( $args['rating'], FILTER_SANITIZE_NUMBER_INT ) );
39
+        $args['type'] = sanitize_key( $args['type'] );
40
+        $args['user'] = $this->normalizeUserIds( Arr::consolidate( $args['user'] ) );
41
+        parent::__construct( $args );
42 42
     }
43 43
 
44 44
     /**
45 45
      * @return string
46 46
      */
47
-    protected function normalizeOrderBy($orderBy)
47
+    protected function normalizeOrderBy( $orderBy )
48 48
     {
49
-        $orderBy = Str::restrictTo('author,comment_count,date,ID,menu_order,none,rand,relevance', $orderBy, 'date');
50
-        if (in_array($orderBy, ['comment_count', 'ID', 'menu_order'])) {
51
-            return Str::prefix('p.', $orderBy);
49
+        $orderBy = Str::restrictTo( 'author,comment_count,date,ID,menu_order,none,rand,relevance', $orderBy, 'date' );
50
+        if( in_array( $orderBy, ['comment_count', 'ID', 'menu_order'] ) ) {
51
+            return Str::prefix( 'p.', $orderBy );
52 52
         }
53
-        if (in_array($orderBy, ['author', 'date'])) {
54
-            return Str::prefix('p.post_', $orderBy);
53
+        if( in_array( $orderBy, ['author', 'date'] ) ) {
54
+            return Str::prefix( 'p.post_', $orderBy );
55 55
         }
56 56
         return $orderBy;
57 57
     }
@@ -60,23 +60,23 @@  discard block
 block discarded – undo
60 60
      * @param array[]|string $termIds
61 61
      * @return array
62 62
      */
63
-    public function normalizeTermIds($termIds)
63
+    public function normalizeTermIds( $termIds )
64 64
     {
65
-        return glsr(ReviewManager::class)->normalizeTermIds($termIds);
65
+        return glsr( ReviewManager::class )->normalizeTermIds( $termIds );
66 66
     }
67 67
 
68 68
     /**
69 69
      * @return array
70 70
      */
71
-    protected function normalizeUserIds(array $users)
71
+    protected function normalizeUserIds( array $users )
72 72
     {
73 73
         $userIds = [];
74
-        foreach ($users as $userId) {
75
-            if (!is_numeric($userId)) {
76
-                $userId = Helper::castToInt(username_exists($userId));
74
+        foreach( $users as $userId ) {
75
+            if( !is_numeric( $userId ) ) {
76
+                $userId = Helper::castToInt( username_exists( $userId ) );
77 77
             }
78 78
             $userIds[] = $userId;
79 79
         }
80
-        return Arr::uniqueInt($userIds);
80
+        return Arr::uniqueInt( $userIds );
81 81
     }
82 82
 }
Please login to merge, or discard this patch.
plugin/Database/QueryBuilder.php 1 patch
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -16,19 +16,19 @@  discard block
 block discarded – undo
16 16
      * Build a WP_Query meta_query/tax_query.
17 17
      * @return array
18 18
      */
19
-    public function buildQuery(array $keys = [], array $values = [])
19
+    public function buildQuery( array $keys = [], array $values = [] )
20 20
     {
21 21
         $queries = [];
22
-        foreach ($keys as $key) {
23
-            if (!array_key_exists($key, $values)) {
22
+        foreach( $keys as $key ) {
23
+            if( !array_key_exists( $key, $values ) ) {
24 24
                 continue;
25 25
             }
26
-            $methodName = Helper::buildMethodName($key, __FUNCTION__);
27
-            if (!method_exists($this, $methodName)) {
26
+            $methodName = Helper::buildMethodName( $key, __FUNCTION__ );
27
+            if( !method_exists( $this, $methodName ) ) {
28 28
                 continue;
29 29
             }
30
-            $query = call_user_func([$this, $methodName], $values[$key]);
31
-            if (is_array($query)) {
30
+            $query = call_user_func( [$this, $methodName], $values[$key] );
31
+            if( is_array( $query ) ) {
32 32
                 $queries[] = $query;
33 33
             }
34 34
         }
@@ -38,17 +38,17 @@  discard block
 block discarded – undo
38 38
     /**
39 39
      * @return string
40 40
      */
41
-    public function buildSqlLines(array $values, array $conditions)
41
+    public function buildSqlLines( array $values, array $conditions )
42 42
     {
43 43
         $string = '';
44
-        $values = array_filter($values);
45
-        foreach ($conditions as $key => $value) {
46
-            if (!isset($values[$key])) {
44
+        $values = array_filter( $values );
45
+        foreach( $conditions as $key => $value ) {
46
+            if( !isset($values[$key]) ) {
47 47
                 continue;
48 48
             }
49
-            $values[$key] = implode(',', (array) $values[$key]);
50
-            $string.= Str::contains($value, '%s')
51
-                ? sprintf($value, strval($values[$key]))
49
+            $values[$key] = implode( ',', (array)$values[$key] );
50
+            $string .= Str::contains( $value, '%s' )
51
+                ? sprintf( $value, strval( $values[$key] ) )
52 52
                 : $value;
53 53
         }
54 54
         return $string;
@@ -60,16 +60,16 @@  discard block
 block discarded – undo
60 60
      * @param string $sprintfFormat
61 61
      * @return string
62 62
      */
63
-    public function buildSqlOr($values, $sprintfFormat)
63
+    public function buildSqlOr( $values, $sprintfFormat )
64 64
     {
65
-        if (!is_array($values)) {
66
-            $values = explode(',', $values);
65
+        if( !is_array( $values ) ) {
66
+            $values = explode( ',', $values );
67 67
         }
68
-        $values = array_filter(array_map('trim', (array) $values));
69
-        $values = array_map(function ($value) use ($sprintfFormat) {
70
-            return sprintf($sprintfFormat, $value);
71
-        }, $values);
72
-        return implode(' OR ', $values);
68
+        $values = array_filter( array_map( 'trim', (array)$values ) );
69
+        $values = array_map( function( $value ) use ($sprintfFormat) {
70
+            return sprintf( $sprintfFormat, $value );
71
+        }, $values );
72
+        return implode( ' OR ', $values );
73 73
     }
74 74
 
75 75
     /**
@@ -77,10 +77,10 @@  discard block
 block discarded – undo
77 77
      * @param bool $isEnabled
78 78
      * @return int
79 79
      */
80
-    public function getPaged($isEnabled = true)
80
+    public function getPaged( $isEnabled = true )
81 81
     {
82 82
         return $isEnabled
83
-            ? max(1, intval(filter_input(INPUT_GET, glsr()->constant('PAGED_QUERY_VAR'))))
83
+            ? max( 1, intval( filter_input( INPUT_GET, glsr()->constant( 'PAGED_QUERY_VAR' ) ) ) )
84 84
             : 1;
85 85
     }
86 86
 
@@ -88,14 +88,14 @@  discard block
 block discarded – undo
88 88
      * @param string $value
89 89
      * @return void|array
90 90
      */
91
-    protected function buildQueryAssignedTo($value)
91
+    protected function buildQueryAssignedTo( $value )
92 92
     {
93
-        if (!empty($value)) {
94
-            $postIds = Arr::convertFromString($value, 'is_numeric');
93
+        if( !empty($value) ) {
94
+            $postIds = Arr::convertFromString( $value, 'is_numeric' );
95 95
             return [
96 96
                 'compare' => 'IN',
97 97
                 'key' => '_assigned_to',
98
-                'value' => glsr(Multilingual::class)->getPostIds($postIds),
98
+                'value' => glsr( Multilingual::class )->getPostIds( $postIds ),
99 99
             ];
100 100
         }
101 101
     }
@@ -104,9 +104,9 @@  discard block
 block discarded – undo
104 104
      * @param array $value
105 105
      * @return void|array
106 106
      */
107
-    protected function buildQueryCategory($value)
107
+    protected function buildQueryCategory( $value )
108 108
     {
109
-        if (!empty($value)) {
109
+        if( !empty($value) ) {
110 110
             return [
111 111
                 'field' => 'term_id',
112 112
                 'taxonomy' => Application::TAXONOMY,
@@ -119,9 +119,9 @@  discard block
 block discarded – undo
119 119
      * @param string $value
120 120
      * @return void|array
121 121
      */
122
-    protected function buildQueryEmail($value)
122
+    protected function buildQueryEmail( $value )
123 123
     {
124
-        if (!empty($value)) {
124
+        if( !empty($value) ) {
125 125
             return [
126 126
                 'key' => '_email',
127 127
                 'value' => $value,
@@ -133,9 +133,9 @@  discard block
 block discarded – undo
133 133
      * @param string $value
134 134
      * @return void|array
135 135
      */
136
-    protected function buildQueryIpAddress($value)
136
+    protected function buildQueryIpAddress( $value )
137 137
     {
138
-        if (!empty($value)) {
138
+        if( !empty($value) ) {
139 139
             return [
140 140
                 'key' => '_ip_address',
141 141
                 'value' => $value,
@@ -147,10 +147,10 @@  discard block
 block discarded – undo
147 147
      * @param string $value
148 148
      * @return void|array
149 149
      */
150
-    protected function buildQueryRating($value)
150
+    protected function buildQueryRating( $value )
151 151
     {
152
-        if (is_numeric($value)
153
-            && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) {
152
+        if( is_numeric( $value )
153
+            && in_array( intval( $value ), range( 1, glsr()->constant( 'MAX_RATING', Rating::class ) ) ) ) {
154 154
             return [
155 155
                 'compare' => '>=',
156 156
                 'key' => '_rating',
@@ -163,9 +163,9 @@  discard block
 block discarded – undo
163 163
      * @param string $value
164 164
      * @return void|array
165 165
      */
166
-    protected function buildQueryType($value)
166
+    protected function buildQueryType( $value )
167 167
     {
168
-        if (!in_array($value, ['', 'all'])) {
168
+        if( !in_array( $value, ['', 'all'] ) ) {
169 169
             return [
170 170
                 'key' => '_review_type',
171 171
                 'value' => $value,
Please login to merge, or discard this patch.
plugin/Database/RatingManager.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -12,19 +12,19 @@
 block discarded – undo
12 12
      * @param bool $flatten
13 13
      * @return array
14 14
      */
15
-    public function ratings(array $args = [])
15
+    public function ratings( array $args = [] )
16 16
     {
17
-        $args = wp_parse_args($args, [
18
-            'max' => glsr()->constant('MAX_RATING', Rating::class),
19
-            'min' => glsr()->constant('MIN_RATING', Rating::class),
20
-        ]);
17
+        $args = wp_parse_args( $args, [
18
+            'max' => glsr()->constant( 'MAX_RATING', Rating::class ),
19
+            'min' => glsr()->constant( 'MIN_RATING', Rating::class ),
20
+        ] );
21 21
         $ratings = [];
22
-        $results = glsr(Query::class)->ratings($args);
23
-        array_walk_recursive($results, function ($rating, $index) use (&$ratings) {
24
-            $ratings[$index] = $rating + intval(Arr::get($ratings, $index, 0));
22
+        $results = glsr( Query::class )->ratings( $args );
23
+        array_walk_recursive( $results, function( $rating, $index ) use (&$ratings) {
24
+            $ratings[$index] = $rating + intval( Arr::get( $ratings, $index, 0 ) );
25 25
         });
26
-        foreach ($ratings as $index => &$rating) {
27
-            if (!Helper::inRange($index, $args['min'], $args['max'])) {
26
+        foreach( $ratings as $index => &$rating ) {
27
+            if( !Helper::inRange( $index, $args['min'], $args['max'] ) ) {
28 28
                 $rating = 0;
29 29
             }
30 30
         }
Please login to merge, or discard this patch.
plugin/Database/Query.php 1 patch
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -23,18 +23,18 @@  discard block
 block discarded – undo
23 23
     /**
24 24
      * @return array
25 25
      */
26
-    public function ratings(array $args)
26
+    public function ratings( array $args )
27 27
     {
28
-        $this->setArgs($args);
29
-        $join = implode(' ', $this->sqlClauses([], 'join'));
30
-        $and = implode(' ', $this->sqlClauses([], 'and'));
31
-        $results = $this->db->get_results("
28
+        $this->setArgs( $args );
29
+        $join = implode( ' ', $this->sqlClauses( [], 'join' ) );
30
+        $and = implode( ' ', $this->sqlClauses( [], 'and' ) );
31
+        $results = $this->db->get_results( "
32 32
             SELECT r.rating, r.type, COUNT(r.rating) AS count
33
-            FROM {$this->table('ratings')} AS r {$join}
33
+            FROM {$this->table( 'ratings' )} AS r {$join}
34 34
             WHERE r.is_approved = 1 {$and}
35 35
             GROUP BY r.type, r.rating
36
-        ", ARRAY_A);
37
-        return $this->normalizeRatings($results);
36
+        ", ARRAY_A );
37
+        return $this->normalizeRatings( $results );
38 38
     }
39 39
 
40 40
     /**
@@ -42,23 +42,23 @@  discard block
 block discarded – undo
42 42
      * @param int $postId
43 43
      * @return Review
44 44
      */
45
-    public function review($postId)
45
+    public function review( $postId )
46 46
     {
47
-        $reviewId = Helper::castToInt($postId);
48
-        if (($review = glsr(Cache::class)->get($reviewId, 'reviews')) instanceof Review) {
47
+        $reviewId = Helper::castToInt( $postId );
48
+        if( ($review = glsr( Cache::class )->get( $reviewId, 'reviews' )) instanceof Review ) {
49 49
             return $review;
50 50
         }
51
-        $result = $this->db->get_row("
51
+        $result = $this->db->get_row( "
52 52
             {$this->sqlSelect()}
53 53
             {$this->sqlFrom()}
54 54
             {$this->sqlJoin()}
55 55
             {$this->sqlJoinPivots()}
56 56
             WHERE r.review_id = {$reviewId}
57 57
             GROUP BY r.ID
58
-        ");
59
-        $review = new Review($result);
60
-        if (!empty($result)) {
61
-            glsr(Cache::class)->store($reviewId, 'reviews', $review);
58
+        " );
59
+        $review = new Review( $result );
60
+        if( !empty($result) ) {
61
+            glsr( Cache::class )->store( $reviewId, 'reviews', $review );
62 62
         }
63 63
         return $review;
64 64
     }
@@ -66,11 +66,11 @@  discard block
 block discarded – undo
66 66
     /**
67 67
      * @return array
68 68
      */
69
-    public function reviews(array $args = [], array $postIds = [])
69
+    public function reviews( array $args = [], array $postIds = [] )
70 70
     {
71
-        $this->setArgs($args);
72
-        if (!empty($postIds)) {
73
-            $postIds = implode(',', Arr::uniqueInt($postIds));
71
+        $this->setArgs( $args );
72
+        if( !empty($postIds) ) {
73
+            $postIds = implode( ',', Arr::uniqueInt( $postIds ) );
74 74
         } else {
75 75
             $postIds = "SELECT ids.* FROM (
76 76
                 SELECT r.review_id
@@ -82,17 +82,17 @@  discard block
 block discarded – undo
82 82
                 {$this->sqlOffset()}
83 83
             ) as ids";
84 84
         }
85
-        $results = $this->db->get_results("
85
+        $results = $this->db->get_results( "
86 86
             {$this->sqlSelect()}
87 87
             {$this->sqlFrom()}
88 88
             {$this->sqlJoin()}
89 89
             {$this->sqlJoinPivots()}
90 90
             WHERE r.review_id in ({$postIds})
91 91
             GROUP BY r.ID 
92
-        ");
93
-        foreach ($results as &$result) {
94
-            $result = new Review($result);
95
-            glsr(Cache::class)->store($result->ID, 'reviews', $result);
92
+        " );
93
+        foreach( $results as &$result ) {
94
+            $result = new Review( $result );
95
+            glsr( Cache::class )->store( $result->ID, 'reviews', $result );
96 96
         }
97 97
         return $results;
98 98
     }
@@ -100,46 +100,46 @@  discard block
 block discarded – undo
100 100
     /**
101 101
      * @return int
102 102
      */
103
-    public function totalReviews(array $args = [], array $reviews = [])
103
+    public function totalReviews( array $args = [], array $reviews = [] )
104 104
     {
105
-        $this->setArgs($args);
106
-        if (empty($this->sqlLimit()) && !empty($reviews)) {
107
-            return count($reviews);
105
+        $this->setArgs( $args );
106
+        if( empty($this->sqlLimit()) && !empty($reviews) ) {
107
+            return count( $reviews );
108 108
         }
109
-        return (int) $this->db->get_var("
109
+        return (int)$this->db->get_var( "
110 110
             SELECT COUNT(*)
111 111
             {$this->sqlFrom()}
112 112
             {$this->sqlJoin()}
113 113
             {$this->sqlWhere()}
114
-        ");
114
+        " );
115 115
     }
116 116
 
117 117
     /**
118 118
      * @param int $postId
119 119
      * @return bool
120 120
      */
121
-    public function hasRevisions($postId)
121
+    public function hasRevisions( $postId )
122 122
     {
123
-        $revisions = (int) $this->db->get_var("
123
+        $revisions = (int)$this->db->get_var( "
124 124
             SELECT COUNT(*) 
125 125
             FROM {$this->db->posts}
126 126
             WHERE post_type = 'revision' AND post_parent = {$postId}
127
-        ");
127
+        " );
128 128
         return $revisions > 0;
129 129
     }
130 130
 
131 131
     /**
132 132
      * @return array
133 133
      */
134
-    protected function normalizeRatings(array $ratings = [])
134
+    protected function normalizeRatings( array $ratings = [] )
135 135
     {
136 136
         $normalized = [];
137
-        foreach ($ratings as $result) {
137
+        foreach( $ratings as $result ) {
138 138
             $type = $result['type'];
139
-            if (!array_key_exists($type, $normalized)) {
140
-                $normalized[$type] = glsr(Rating::class)->emptyArray();
139
+            if( !array_key_exists( $type, $normalized ) ) {
140
+                $normalized[$type] = glsr( Rating::class )->emptyArray();
141 141
             }
142
-            $normalized[$type] = Arr::set($normalized[$type], $result['rating'], $result['count']);
142
+            $normalized[$type] = Arr::set( $normalized[$type], $result['rating'], $result['count'] );
143 143
         }
144 144
         return $normalized;
145 145
     }
@@ -147,8 +147,8 @@  discard block
 block discarded – undo
147 147
     /**
148 148
      * @return void
149 149
      */
150
-    public function setArgs(array $args = [])
150
+    public function setArgs( array $args = [] )
151 151
     {
152
-        $this->args = (new NormalizeQueryArgs($args))->toArray();
152
+        $this->args = (new NormalizeQueryArgs( $args ))->toArray();
153 153
     }
154 154
 }
Please login to merge, or discard this patch.