Passed
Push — master ( 054ae2...bf35ce )
by Paul
04:22
created
plugin/Database/CountsManager.php 1 patch
Spacing   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -21,26 +21,26 @@  discard block
 block discarded – undo
21 21
      * @return array
22 22
      * @todo verify the additional type checks are needed
23 23
      */
24
-    public function buildCounts(array $args = [])
24
+    public function buildCounts( array $args = [] )
25 25
     {
26 26
         $counts = [];
27
-        $query = $this->queryReviews($args);
28
-        while ($query) {
29
-            $types = array_keys(array_flip(glsr_array_column($query->reviews, 'type')));
30
-            $types = array_unique(array_merge(['local'], $types));
31
-            foreach ($types as $type) {
32
-                $type = $this->normalizeType($type);
33
-                if (isset($counts[$type])) {
27
+        $query = $this->queryReviews( $args );
28
+        while( $query ) {
29
+            $types = array_keys( array_flip( glsr_array_column( $query->reviews, 'type' ) ) );
30
+            $types = array_unique( array_merge( ['local'], $types ) );
31
+            foreach( $types as $type ) {
32
+                $type = $this->normalizeType( $type );
33
+                if( isset($counts[$type]) ) {
34 34
                     continue;
35 35
             }
36
-                $counts[$type] = array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0);
36
+                $counts[$type] = array_fill_keys( range( 0, glsr()->constant( 'MAX_RATING', Rating::class ) ), 0 );
37 37
             }
38
-            foreach ($query->reviews as $review) {
39
-                $type = $this->normalizeType($review->type);
38
+            foreach( $query->reviews as $review ) {
39
+                $type = $this->normalizeType( $review->type );
40 40
                 ++$counts[$type][$review->rating];
41 41
             }
42 42
             $query = $query->has_more
43
-                ? $this->queryReviews($args, end($query->reviews)->ID)
43
+                ? $this->queryReviews( $args, end( $query->reviews )->ID )
44 44
                 : false;
45 45
         }
46 46
         return $counts;
@@ -50,18 +50,18 @@  discard block
 block discarded – undo
50 50
      * @param int $postId
51 51
      * @return array
52 52
      */
53
-    public function buildPostCounts($postId)
53
+    public function buildPostCounts( $postId )
54 54
     {
55
-        return $this->buildCounts(['post_ids' => [$postId]]);
55
+        return $this->buildCounts( ['post_ids' => [$postId]] );
56 56
     }
57 57
 
58 58
     /**
59 59
      * @param int $termTaxonomyId
60 60
      * @return array
61 61
      */
62
-    public function buildTermCounts($termTaxonomyId)
62
+    public function buildTermCounts( $termTaxonomyId )
63 63
     {
64
-        return $this->buildCounts(['term_ids' => [$termTaxonomyId]]);
64
+        return $this->buildCounts( ['term_ids' => [$termTaxonomyId]] );
65 65
     }
66 66
 
67 67
     /**
@@ -69,80 +69,80 @@  discard block
 block discarded – undo
69 69
      */
70 70
     public function countAll()
71 71
     {
72
-        $terms = glsr(Database::class)->getTerms(['fields' => 'all']);
73
-        foreach ($terms as $term) {
74
-            $this->setTermCounts($term->term_id, $this->buildTermCounts($term->term_taxonomy_id));
72
+        $terms = glsr( Database::class )->getTerms( ['fields' => 'all'] );
73
+        foreach( $terms as $term ) {
74
+            $this->setTermCounts( $term->term_id, $this->buildTermCounts( $term->term_taxonomy_id ) );
75 75
         }
76
-        $postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to');
77
-        foreach ($postIds as $postId) {
78
-            $this->setPostCounts($postId, $this->buildPostCounts($postId));
76
+        $postIds = glsr( SqlQueries::class )->getReviewsMeta( 'assigned_to' );
77
+        foreach( $postIds as $postId ) {
78
+            $this->setPostCounts( $postId, $this->buildPostCounts( $postId ) );
79 79
         }
80
-        $this->setCounts($this->buildCounts());
80
+        $this->setCounts( $this->buildCounts() );
81 81
     }
82 82
 
83 83
     /**
84 84
      * @return void
85 85
      */
86
-    public function decrease(Review $review)
86
+    public function decrease( Review $review )
87 87
     {
88
-        $this->decreaseCounts($review);
89
-        $this->decreasePostCounts($review);
90
-        $this->decreaseTermCounts($review);
88
+        $this->decreaseCounts( $review );
89
+        $this->decreasePostCounts( $review );
90
+        $this->decreaseTermCounts( $review );
91 91
     }
92 92
 
93 93
     /**
94 94
      * @return void
95 95
      */
96
-    public function decreaseCounts(Review $review)
96
+    public function decreaseCounts( Review $review )
97 97
     {
98
-        $this->setCounts($this->decreaseRating(
98
+        $this->setCounts( $this->decreaseRating(
99 99
             $this->getCounts(),
100 100
             $review->review_type,
101 101
             $review->rating
102
-        ));
102
+        ) );
103 103
     }
104 104
 
105 105
     /**
106 106
      * @return void
107 107
      */
108
-    public function decreasePostCounts(Review $review)
108
+    public function decreasePostCounts( Review $review )
109 109
     {
110
-        if (empty($counts = $this->getPostCounts($review->assigned_to))) {
110
+        if( empty($counts = $this->getPostCounts( $review->assigned_to )) ) {
111 111
             return;
112 112
         }
113
-        $counts = $this->decreaseRating($counts, $review->review_type, $review->rating);
114
-        $this->setPostCounts($review->assigned_to, $counts);
113
+        $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating );
114
+        $this->setPostCounts( $review->assigned_to, $counts );
115 115
     }
116 116
 
117 117
     /**
118 118
      * @return void
119 119
      */
120
-    public function decreaseTermCounts(Review $review)
120
+    public function decreaseTermCounts( Review $review )
121 121
     {
122
-        foreach ($review->term_ids as $termId) {
123
-            if (empty($counts = $this->getTermCounts($termId))) {
122
+        foreach( $review->term_ids as $termId ) {
123
+            if( empty($counts = $this->getTermCounts( $termId )) ) {
124 124
                 continue;
125 125
             }
126
-            $counts = $this->decreaseRating($counts, $review->review_type, $review->rating);
127
-            $this->setTermCounts($termId, $counts);
126
+            $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating );
127
+            $this->setTermCounts( $termId, $counts );
128 128
         }
129 129
     }
130 130
 
131 131
     /**
132 132
      * @return array
133 133
      */
134
-    public function flatten(array $reviewCounts, array $args = [])
134
+    public function flatten( array $reviewCounts, array $args = [] )
135 135
     {
136 136
         $counts = [];
137
-        array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) {
138
-            $counts[$index] = $num + intval(Arr::get($counts, $index, 0));
137
+        array_walk_recursive( $reviewCounts, function( $num, $index ) use (&$counts) {
138
+            $counts[$index] = $num + intval( Arr::get( $counts, $index, 0 ) );
139 139
         });
140
-        $args = wp_parse_args($args, [
141
-            'max' => glsr()->constant('MAX_RATING', Rating::class),
142
-            'min' => glsr()->constant('MIN_RATING', Rating::class),
143
-        ]);
144
-        foreach ($counts as $index => &$num) {
145
-            if ($index >= intval($args['min']) && $index <= intval($args['max'])) {
140
+        $args = wp_parse_args( $args, [
141
+            'max' => glsr()->constant( 'MAX_RATING', Rating::class ),
142
+            'min' => glsr()->constant( 'MIN_RATING', Rating::class ),
143
+        ] );
144
+        foreach( $counts as $index => &$num ) {
145
+            if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ) ) {
146 146
                 continue;
147 147
             }
148 148
             $num = 0;
@@ -153,26 +153,26 @@  discard block
 block discarded – undo
153 153
     /**
154 154
      * @return array
155 155
      */
156
-    public function get(array $args = [])
156
+    public function get( array $args = [] )
157 157
     {
158
-        $args = $this->normalizeArgs($args);
158
+        $args = $this->normalizeArgs( $args );
159 159
         $counts = [];
160
-        if ($this->isMixedCount($args)) {
161
-            $counts = [$this->buildCounts($args)]; // force query the database
160
+        if( $this->isMixedCount( $args ) ) {
161
+            $counts = [$this->buildCounts( $args )]; // force query the database
162 162
         } else {
163
-            foreach ($args['post_ids'] as $postId) {
164
-                $counts[] = $this->getPostCounts($postId);
163
+            foreach( $args['post_ids'] as $postId ) {
164
+                $counts[] = $this->getPostCounts( $postId );
165 165
         }
166
-            foreach ($args['term_ids'] as $termId) {
167
-                $counts[] = $this->getTermCounts($termId);
166
+            foreach( $args['term_ids'] as $termId ) {
167
+                $counts[] = $this->getTermCounts( $termId );
168 168
             }
169
-            if (empty($counts)) {
169
+            if( empty($counts) ) {
170 170
                 $counts[] = $this->getCounts();
171 171
             }
172 172
         }
173
-        return in_array($args['type'], ['', 'all'])
174
-            ? $this->normalize([$this->flatten($counts)])
175
-            : $this->normalize(glsr_array_column($counts, $args['type']));
173
+        return in_array( $args['type'], ['', 'all'] )
174
+            ? $this->normalize( [$this->flatten( $counts )] )
175
+            : $this->normalize( glsr_array_column( $counts, $args['type'] ) );
176 176
     }
177 177
 
178 178
     /**
@@ -180,9 +180,9 @@  discard block
 block discarded – undo
180 180
      */
181 181
     public function getCounts()
182 182
     {
183
-        $counts = glsr(OptionManager::class)->get('counts', []);
184
-        if (!is_array($counts)) {
185
-            glsr_log()->error('Review counts is not an array; possibly due to incorrectly imported reviews.')->debug($counts);
183
+        $counts = glsr( OptionManager::class )->get( 'counts', [] );
184
+        if( !is_array( $counts ) ) {
185
+            glsr_log()->error( 'Review counts is not an array; possibly due to incorrectly imported reviews.' )->debug( $counts );
186 186
             return [];
187 187
         }
188 188
         return $counts;
@@ -192,105 +192,105 @@  discard block
 block discarded – undo
192 192
      * @param int $postId
193 193
      * @return array
194 194
      */
195
-    public function getPostCounts($postId)
195
+    public function getPostCounts( $postId )
196 196
     {
197
-        return array_filter((array) get_post_meta($postId, static::META_COUNT, true));
197
+        return array_filter( (array)get_post_meta( $postId, static::META_COUNT, true ) );
198 198
     }
199 199
 
200 200
     /**
201 201
      * @param int $termId
202 202
      * @return array
203 203
      */
204
-    public function getTermCounts($termId)
204
+    public function getTermCounts( $termId )
205 205
     {
206
-        return array_filter((array) get_term_meta($termId, static::META_COUNT, true));
206
+        return array_filter( (array)get_term_meta( $termId, static::META_COUNT, true ) );
207 207
     }
208 208
 
209 209
     /**
210 210
      * @return void
211 211
      */
212
-    public function increase(Review $review)
212
+    public function increase( Review $review )
213 213
     {
214
-        $this->increaseCounts($review);
215
-        $this->increasePostCounts($review);
216
-        $this->increaseTermCounts($review);
214
+        $this->increaseCounts( $review );
215
+        $this->increasePostCounts( $review );
216
+        $this->increaseTermCounts( $review );
217 217
     }
218 218
 
219 219
     /**
220 220
      * @return void
221 221
      */
222
-    public function increaseCounts(Review $review)
222
+    public function increaseCounts( Review $review )
223 223
     {
224
-        if (empty($counts = $this->getCounts())) {
224
+        if( empty($counts = $this->getCounts()) ) {
225 225
             $counts = $this->buildCounts();
226 226
         }
227
-        $this->setCounts($this->increaseRating($counts, $review->review_type, $review->rating));
227
+        $this->setCounts( $this->increaseRating( $counts, $review->review_type, $review->rating ) );
228 228
     }
229 229
 
230 230
     /**
231 231
      * @return void
232 232
      */
233
-    public function increasePostCounts(Review $review)
233
+    public function increasePostCounts( Review $review )
234 234
     {
235
-        if (!(get_post($review->assigned_to) instanceof WP_Post)) {
235
+        if( !(get_post( $review->assigned_to ) instanceof WP_Post) ) {
236 236
             return;
237 237
         }
238
-        $counts = $this->getPostCounts($review->assigned_to);
238
+        $counts = $this->getPostCounts( $review->assigned_to );
239 239
         $counts = empty($counts)
240
-            ? $this->buildPostCounts($review->assigned_to)
241
-            : $this->increaseRating($counts, $review->review_type, $review->rating);
242
-        $this->setPostCounts($review->assigned_to, $counts);
240
+            ? $this->buildPostCounts( $review->assigned_to )
241
+            : $this->increaseRating( $counts, $review->review_type, $review->rating );
242
+        $this->setPostCounts( $review->assigned_to, $counts );
243 243
     }
244 244
 
245 245
     /**
246 246
      * @return void
247 247
      */
248
-    public function increaseTermCounts(Review $review)
248
+    public function increaseTermCounts( Review $review )
249 249
     {
250
-        $terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids));
251
-        foreach ($terms as $term) {
252
-            $counts = $this->getTermCounts($term['term_id']);
250
+        $terms = glsr( ReviewManager::class )->normalizeTerms( implode( ',', $review->term_ids ) );
251
+        foreach( $terms as $term ) {
252
+            $counts = $this->getTermCounts( $term['term_id'] );
253 253
             $counts = empty($counts)
254
-                ? $this->buildTermCounts($term['term_taxonomy_id'])
255
-                : $this->increaseRating($counts, $review->review_type, $review->rating);
256
-            $this->setTermCounts($term['term_id'], $counts);
254
+                ? $this->buildTermCounts( $term['term_taxonomy_id'] )
255
+                : $this->increaseRating( $counts, $review->review_type, $review->rating );
256
+            $this->setTermCounts( $term['term_id'], $counts );
257 257
         }
258 258
     }
259 259
 
260 260
     /**
261 261
      * @return void
262 262
      */
263
-    public function setCounts(array $reviewCounts)
263
+    public function setCounts( array $reviewCounts )
264 264
     {
265
-        glsr(OptionManager::class)->set('counts', $reviewCounts);
265
+        glsr( OptionManager::class )->set( 'counts', $reviewCounts );
266 266
     }
267 267
 
268 268
     /**
269 269
      * @param int $postId
270 270
      * @return void
271 271
      */
272
-    public function setPostCounts($postId, array $reviewCounts)
272
+    public function setPostCounts( $postId, array $reviewCounts )
273 273
     {
274
-        $ratingCounts = $this->flatten($reviewCounts);
275
-        update_post_meta($postId, static::META_COUNT, $reviewCounts);
276
-        update_post_meta($postId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
277
-        update_post_meta($postId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
274
+        $ratingCounts = $this->flatten( $reviewCounts );
275
+        update_post_meta( $postId, static::META_COUNT, $reviewCounts );
276
+        update_post_meta( $postId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) );
277
+        update_post_meta( $postId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) );
278 278
     }
279 279
 
280 280
     /**
281 281
      * @param int $termId
282 282
      * @return void
283 283
      */
284
-    public function setTermCounts($termId, array $reviewCounts)
284
+    public function setTermCounts( $termId, array $reviewCounts )
285 285
     {
286
-        $term = get_term($termId, Application::TAXONOMY);
287
-        if (!isset($term->term_id)) {
286
+        $term = get_term( $termId, Application::TAXONOMY );
287
+        if( !isset($term->term_id) ) {
288 288
             return;
289 289
         }
290
-        $ratingCounts = $this->flatten($reviewCounts);
291
-        update_term_meta($termId, static::META_COUNT, $reviewCounts);
292
-        update_term_meta($termId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
293
-        update_term_meta($termId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
290
+        $ratingCounts = $this->flatten( $reviewCounts );
291
+        update_term_meta( $termId, static::META_COUNT, $reviewCounts );
292
+        update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) );
293
+        update_term_meta( $termId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) );
294 294
     }
295 295
 
296 296
     /**
@@ -298,10 +298,10 @@  discard block
 block discarded – undo
298 298
      * @param int $rating
299 299
      * @return array
300 300
      */
301
-    protected function decreaseRating(array $reviewCounts, $type, $rating)
301
+    protected function decreaseRating( array $reviewCounts, $type, $rating )
302 302
     {
303
-        if (isset($reviewCounts[$type][$rating])) {
304
-            $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1);
303
+        if( isset($reviewCounts[$type][$rating]) ) {
304
+            $reviewCounts[$type][$rating] = max( 0, $reviewCounts[$type][$rating] - 1 );
305 305
         }
306 306
         return $reviewCounts;
307 307
     }
@@ -311,23 +311,23 @@  discard block
 block discarded – undo
311 311
      * @param int $rating
312 312
      * @return array
313 313
      */
314
-    protected function increaseRating(array $reviewCounts, $type, $rating)
314
+    protected function increaseRating( array $reviewCounts, $type, $rating )
315 315
     {
316
-        if (!array_key_exists($type, glsr()->reviewTypes)) {
316
+        if( !array_key_exists( $type, glsr()->reviewTypes ) ) {
317 317
             return $reviewCounts;
318 318
         }
319
-        if (!array_key_exists($type, $reviewCounts)) {
319
+        if( !array_key_exists( $type, $reviewCounts ) ) {
320 320
             $reviewCounts[$type] = [];
321 321
         }
322
-        $reviewCounts = $this->normalize($reviewCounts);
323
-        $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1;
322
+        $reviewCounts = $this->normalize( $reviewCounts );
323
+        $reviewCounts[$type][$rating] = intval( $reviewCounts[$type][$rating] ) + 1;
324 324
         return $reviewCounts;
325 325
     }
326 326
 
327 327
     /**
328 328
      * @return bool
329 329
      */
330
-    protected function isMixedCount(array $args)
330
+    protected function isMixedCount( array $args )
331 331
     {
332 332
         return !empty($args['post_ids']) && !empty($args['term_ids']);
333 333
     }
@@ -335,19 +335,19 @@  discard block
 block discarded – undo
335 335
     /**
336 336
      * @return array
337 337
      */
338
-    protected function normalize(array $reviewCounts)
338
+    protected function normalize( array $reviewCounts )
339 339
     {
340
-        if (empty($reviewCounts)) {
340
+        if( empty($reviewCounts) ) {
341 341
             $reviewCounts = [[]];
342 342
         }
343
-        foreach ($reviewCounts as &$counts) {
344
-            foreach (range(0, glsr()->constant('MAX_RATING', Rating::class)) as $index) {
345
-                if (isset($counts[$index])) {
343
+        foreach( $reviewCounts as &$counts ) {
344
+            foreach( range( 0, glsr()->constant( 'MAX_RATING', Rating::class ) ) as $index ) {
345
+                if( isset($counts[$index]) ) {
346 346
                     continue;
347 347
                 }
348 348
                 $counts[$index] = 0;
349 349
             }
350
-            ksort($counts);
350
+            ksort( $counts );
351 351
         }
352 352
         return $reviewCounts;
353 353
     }
@@ -355,15 +355,15 @@  discard block
 block discarded – undo
355 355
     /**
356 356
      * @return array
357 357
      */
358
-    protected function normalizeArgs(array $args)
358
+    protected function normalizeArgs( array $args )
359 359
     {
360
-        $args = wp_parse_args(array_filter($args), [
360
+        $args = wp_parse_args( array_filter( $args ), [
361 361
             'post_ids' => [],
362 362
             'term_ids' => [],
363 363
             'type' => 'local',
364
-        ]);
365
-        $args['post_ids'] = glsr(Polylang::class)->getPostIds($args['post_ids']);
366
-        $args['type'] = $this->normalizeType($args['type']);
364
+        ] );
365
+        $args['post_ids'] = glsr( Polylang::class )->getPostIds( $args['post_ids'] );
366
+        $args['type'] = $this->normalizeType( $args['type'] );
367 367
         return $args;
368 368
     }
369 369
 
@@ -371,9 +371,9 @@  discard block
 block discarded – undo
371 371
      * @param string $type
372 372
      * @return string
373 373
      */
374
-    protected function normalizeType($type)
374
+    protected function normalizeType( $type )
375 375
     {
376
-        return empty($type) || !is_string($type)
376
+        return empty($type) || !is_string( $type )
377 377
             ? 'local'
378 378
             : $type;
379 379
     }
@@ -382,13 +382,13 @@  discard block
 block discarded – undo
382 382
      * @param int $lastPostId
383 383
      * @return object
384 384
      */
385
-    protected function queryReviews(array $args = [], $lastPostId = 0)
385
+    protected function queryReviews( array $args = [], $lastPostId = 0 )
386 386
     {
387
-        $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT);
388
-        $hasMore = is_array($reviews)
389
-            ? count($reviews) == static::LIMIT
387
+        $reviews = glsr( SqlQueries::class )->getReviewCounts( $args, $lastPostId, static::LIMIT );
388
+        $hasMore = is_array( $reviews )
389
+            ? count( $reviews ) == static::LIMIT
390 390
             : false;
391
-        return (object) [
391
+        return (object)[
392 392
             'has_more' => $hasMore,
393 393
             'reviews' => $reviews,
394 394
         ];
Please login to merge, or discard this patch.
plugin/Database/SqlQueries.php 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -22,17 +22,17 @@  discard block
 block discarded – undo
22 22
      * @param string $metaReviewId
23 23
      * @return int
24 24
      */
25
-    public function getPostIdFromReviewId($metaReviewId)
25
+    public function getPostIdFromReviewId( $metaReviewId )
26 26
     {
27
-        $postId = $this->db->get_var("
27
+        $postId = $this->db->get_var( "
28 28
             SELECT p.ID
29 29
             FROM {$this->db->posts} AS p
30 30
             INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
31 31
             WHERE p.post_type = '{$this->postType}'
32 32
             AND m.meta_key = '_review_id'
33 33
             AND m.meta_value = '{$metaReviewId}'
34
-        ");
35
-        return intval($postId);
34
+        " );
35
+        return intval( $postId );
36 36
     }
37 37
 
38 38
     /**
@@ -40,23 +40,23 @@  discard block
 block discarded – undo
40 40
      * @param int $limit
41 41
      * @return array
42 42
      */
43
-    public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500)
43
+    public function getReviewCounts( array $args, $lastPostId = 0, $limit = 500 )
44 44
     {
45
-        return (array) $this->db->get_results("
45
+        return (array)$this->db->get_results( "
46 46
             SELECT DISTINCT p.ID, m1.meta_value AS rating, m2.meta_value AS type
47 47
             FROM {$this->db->posts} AS p
48 48
             INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id
49 49
             INNER JOIN {$this->db->postmeta} AS m2 ON p.ID = m2.post_id
50
-            {$this->getInnerJoinForCounts($args)}
50
+            {$this->getInnerJoinForCounts( $args )}
51 51
             WHERE p.ID > {$lastPostId}
52 52
             AND p.post_status = 'publish'
53 53
             AND p.post_type = '{$this->postType}'
54 54
             AND m1.meta_key = '_rating'
55 55
             AND m2.meta_key = '_review_type'
56
-            {$this->getAndForCounts($args)}
56
+            {$this->getAndForCounts( $args )}
57 57
             ORDER By p.ID ASC
58 58
             LIMIT {$limit}
59
-        ");
59
+        " );
60 60
     }
61 61
 
62 62
     /**
@@ -64,17 +64,17 @@  discard block
 block discarded – undo
64 64
      * @param string $metaKey
65 65
      * @return array
66 66
      */
67
-    public function getReviewCountsFor($metaKey)
67
+    public function getReviewCountsFor( $metaKey )
68 68
     {
69
-        $metaKey = Str::prefix('_', $metaKey);
70
-        return (array) $this->db->get_results("
69
+        $metaKey = Str::prefix( '_', $metaKey );
70
+        return (array)$this->db->get_results( "
71 71
             SELECT DISTINCT m.meta_value AS name, COUNT(*) num_posts
72 72
             FROM {$this->db->posts} AS p
73 73
             INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
74 74
             WHERE p.post_type = '{$this->postType}'
75 75
             AND m.meta_key = '{$metaKey}'
76 76
             GROUP BY name
77
-        ");
77
+        " );
78 78
     }
79 79
 
80 80
     /**
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
      * @param string $reviewType
83 83
      * @return array
84 84
      */
85
-    public function getReviewIdsByType($reviewType)
85
+    public function getReviewIdsByType( $reviewType )
86 86
     {
87
-        $results = $this->db->get_col("
87
+        $results = $this->db->get_col( "
88 88
             SELECT DISTINCT m1.meta_value AS review_id
89 89
             FROM {$this->db->posts} AS p
90 90
             INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
             AND m1.meta_key = '_review_id'
94 94
             AND m2.meta_key = '_review_type'
95 95
             AND m2.meta_value = '{$reviewType}'
96
-        ");
97
-        return array_keys(array_flip($results));
96
+        " );
97
+        return array_keys( array_flip( $results ) );
98 98
     }
99 99
 
100 100
     /**
@@ -102,12 +102,12 @@  discard block
 block discarded – undo
102 102
      * @param int $limit
103 103
      * @return array
104 104
      */
105
-    public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100)
105
+    public function getReviewRatingsFromIds( array $postIds, $greaterThanId = 0, $limit = 100 )
106 106
     {
107
-        sort($postIds);
108
-        $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit);
109
-        $postIds = implode(',', $postIds);
110
-        return (array) $this->db->get_results("
107
+        sort( $postIds );
108
+        $postIds = array_slice( $postIds, intval( array_search( $greaterThanId, $postIds ) ), $limit );
109
+        $postIds = implode( ',', $postIds );
110
+        return (array)$this->db->get_results( "
111 111
             SELECT p.ID, m.meta_value AS rating
112 112
             FROM {$this->db->posts} AS p
113 113
             INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
             GROUP BY p.ID
120 120
             ORDER By p.ID ASC
121 121
             LIMIT {$limit}
122
-        ");
122
+        " );
123 123
     }
124 124
 
125 125
     /**
@@ -127,10 +127,10 @@  discard block
 block discarded – undo
127 127
      * @param string $status
128 128
      * @return array
129 129
      */
130
-    public function getReviewsMeta($key, $status = 'publish')
130
+    public function getReviewsMeta( $key, $status = 'publish' )
131 131
     {
132
-        $key = Str::prefix('_', $key);
133
-        $values = $this->db->get_col("
132
+        $key = Str::prefix( '_', $key );
133
+        $values = $this->db->get_col( "
134 134
             SELECT DISTINCT m.meta_value
135 135
             FROM {$this->db->postmeta} m
136 136
             LEFT JOIN {$this->db->posts} p ON p.ID = m.post_id
@@ -140,8 +140,8 @@  discard block
 block discarded – undo
140 140
             AND p.post_status = '{$status}'
141 141
             GROUP BY p.ID -- remove duplicate meta_value entries
142 142
             ORDER BY m.meta_id ASC -- sort by oldest meta_value
143
-        ");
144
-        sort($values);
143
+        " );
144
+        sort( $values );
145 145
         return $values;
146 146
     }
147 147
 
@@ -149,34 +149,34 @@  discard block
 block discarded – undo
149 149
      * @param string $and
150 150
      * @return string
151 151
      */
152
-    protected function getAndForCounts(array $args, $and = '')
152
+    protected function getAndForCounts( array $args, $and = '' )
153 153
     {
154
-        $postIds = implode(',', array_filter(Arr::get($args, 'post_ids', [])));
155
-        $termIds = implode(',', array_filter(Arr::get($args, 'term_ids', [])));
156
-        if (!empty($args['type'])) {
157
-            $and.= "AND m2.meta_value = '{$args['type']}' ";
154
+        $postIds = implode( ',', array_filter( Arr::get( $args, 'post_ids', [] ) ) );
155
+        $termIds = implode( ',', array_filter( Arr::get( $args, 'term_ids', [] ) ) );
156
+        if( !empty($args['type']) ) {
157
+            $and .= "AND m2.meta_value = '{$args['type']}' ";
158 158
         }
159
-        if ($postIds) {
160
-            $and.= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) ";
159
+        if( $postIds ) {
160
+            $and .= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) ";
161 161
         }
162
-        if ($termIds) {
163
-            $and.= "AND tr.term_taxonomy_id IN ({$termIds}) ";
162
+        if( $termIds ) {
163
+            $and .= "AND tr.term_taxonomy_id IN ({$termIds}) ";
164 164
         }
165
-        return apply_filters('site-reviews/query/and-for-counts', $and);
165
+        return apply_filters( 'site-reviews/query/and-for-counts', $and );
166 166
     }
167 167
 
168 168
     /**
169 169
      * @param string $innerJoin
170 170
      * @return string
171 171
      */
172
-    protected function getInnerJoinForCounts(array $args, $innerJoin = '')
172
+    protected function getInnerJoinForCounts( array $args, $innerJoin = '' )
173 173
     {
174
-        if (!empty(Arr::get($args, 'post_ids'))) {
175
-            $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id ";
174
+        if( !empty(Arr::get( $args, 'post_ids' )) ) {
175
+            $innerJoin .= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id ";
176 176
         }
177
-        if (!empty(Arr::get($args, 'term_ids'))) {
178
-            $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id ";
177
+        if( !empty(Arr::get( $args, 'term_ids' )) ) {
178
+            $innerJoin .= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id ";
179 179
         }
180
-        return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin);
180
+        return apply_filters( 'site-reviews/query/inner-join-for-counts', $innerJoin );
181 181
     }
182 182
 }
Please login to merge, or discard this patch.
plugin/Controllers/TaxonomyController.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -36,14 +36,14 @@  discard block
 block discarded – undo
36 36
      */
37 37
     public function renderTaxonomyFilter()
38 38
     {
39
-        if (!is_object_in_taxonomy(glsr_current_screen()->post_type, Application::TAXONOMY)) {
39
+        if( !is_object_in_taxonomy( glsr_current_screen()->post_type, Application::TAXONOMY ) ) {
40 40
             return;
41 41
         }
42
-        echo glsr(Builder::class)->label(__('Filter by category', 'site-reviews'), [
42
+        echo glsr( Builder::class )->label( __( 'Filter by category', 'site-reviews' ), [
43 43
             'class' => 'screen-reader-text',
44 44
             'for' => Application::TAXONOMY,
45
-        ]);
46
-        wp_dropdown_categories([
45
+        ] );
46
+        wp_dropdown_categories( [
47 47
             'depth' => 3,
48 48
             'hide_empty' => true,
49 49
             'hide_if_empty' => true,
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
             'show_option_all' => $this->getShowOptionAll(),
56 56
             'taxonomy' => Application::TAXONOMY,
57 57
             'value_field' => 'slug',
58
-        ]);
58
+        ] );
59 59
     }
60 60
 
61 61
     /**
@@ -68,17 +68,17 @@  discard block
 block discarded – undo
68 68
      * @return void
69 69
      * @action set_object_terms
70 70
      */
71
-    public function restrictTermSelection($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds)
71
+    public function restrictTermSelection( $postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds )
72 72
     {
73
-        if (Application::TAXONOMY != $taxonomy || count($newTTIds) <= 1) {
73
+        if( Application::TAXONOMY != $taxonomy || count( $newTTIds ) <= 1 ) {
74 74
             return;
75 75
         }
76
-        $diff = array_diff($newTTIds, $oldTTIds);
77
-        if (empty($newTerm = array_shift($diff))) {
78
-            $newTerm = array_shift($newTTIds);
76
+        $diff = array_diff( $newTTIds, $oldTTIds );
77
+        if( empty($newTerm = array_shift( $diff )) ) {
78
+            $newTerm = array_shift( $newTTIds );
79 79
         }
80
-        if ($newTerm) {
81
-            wp_set_object_terms($postId, intval($newTerm), $taxonomy);
80
+        if( $newTerm ) {
81
+            wp_set_object_terms( $postId, intval( $newTerm ), $taxonomy );
82 82
         }
83 83
     }
84 84
 
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
     protected function getSelected()
89 89
     {
90 90
         global $wp_query;
91
-        return Arr::get($wp_query->query, Application::TAXONOMY);
91
+        return Arr::get( $wp_query->query, Application::TAXONOMY );
92 92
     }
93 93
 
94 94
     /**
@@ -96,9 +96,9 @@  discard block
 block discarded – undo
96 96
      */
97 97
     protected function getShowOptionAll()
98 98
     {
99
-        $taxonomy = get_taxonomy(Application::TAXONOMY);
99
+        $taxonomy = get_taxonomy( Application::TAXONOMY );
100 100
         return $taxonomy
101
-            ? ucfirst(strtolower($taxonomy->labels->all_items))
101
+            ? ucfirst( strtolower( $taxonomy->labels->all_items ) )
102 102
             : '';
103 103
     }
104 104
 }
Please login to merge, or discard this patch.
plugin/Controllers/ReviewController.php 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -23,22 +23,22 @@  discard block
 block discarded – undo
23 23
      * @return void
24 24
      * @action set_object_terms
25 25
      */
26
-    public function onAfterChangeCategory($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds)
26
+    public function onAfterChangeCategory( $postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds )
27 27
     {
28
-        sort($newTTIds);
29
-        sort($oldTTIds);
30
-        if ($newTTIds === $oldTTIds || !$this->isReviewPostId($postId)) {
28
+        sort( $newTTIds );
29
+        sort( $oldTTIds );
30
+        if( $newTTIds === $oldTTIds || !$this->isReviewPostId( $postId ) ) {
31 31
             return;
32 32
         }
33
-        $review = glsr_get_review($postId);
34
-        $ignoredIds = array_intersect($oldTTIds, $newTTIds);
35
-        $decreasedIds = array_diff($oldTTIds, $ignoredIds);
36
-        $increasedIds = array_diff($newTTIds, $ignoredIds);
37
-        if ($review->term_ids = glsr(Database::class)->getTermIds($decreasedIds, 'term_taxonomy_id')) {
38
-            glsr(CountsManager::class)->decreaseTermCounts($review);
33
+        $review = glsr_get_review( $postId );
34
+        $ignoredIds = array_intersect( $oldTTIds, $newTTIds );
35
+        $decreasedIds = array_diff( $oldTTIds, $ignoredIds );
36
+        $increasedIds = array_diff( $newTTIds, $ignoredIds );
37
+        if( $review->term_ids = glsr( Database::class )->getTermIds( $decreasedIds, 'term_taxonomy_id' ) ) {
38
+            glsr( CountsManager::class )->decreaseTermCounts( $review );
39 39
         }
40
-        if ($review->term_ids = glsr(Database::class)->getTermIds($increasedIds, 'term_taxonomy_id')) {
41
-            glsr(CountsManager::class)->increaseTermCounts($review);
40
+        if( $review->term_ids = glsr( Database::class )->getTermIds( $increasedIds, 'term_taxonomy_id' ) ) {
41
+            glsr( CountsManager::class )->increaseTermCounts( $review );
42 42
         }
43 43
     }
44 44
 
@@ -49,16 +49,16 @@  discard block
 block discarded – undo
49 49
      * @return void
50 50
      * @action transition_post_status
51 51
      */
52
-    public function onAfterChangeStatus($newStatus, $oldStatus, $post)
52
+    public function onAfterChangeStatus( $newStatus, $oldStatus, $post )
53 53
     {
54
-        if (Application::POST_TYPE != Arr::get($post, 'post_type') || in_array($oldStatus, ['new', $newStatus])) {
54
+        if( Application::POST_TYPE != Arr::get( $post, 'post_type' ) || in_array( $oldStatus, ['new', $newStatus] ) ) {
55 55
             return;
56 56
         }
57
-        $review = glsr_get_review($post);
58
-        if ('publish' == $post->post_status) {
59
-            glsr(CountsManager::class)->increase($review);
57
+        $review = glsr_get_review( $post );
58
+        if( 'publish' == $post->post_status ) {
59
+            glsr( CountsManager::class )->increase( $review );
60 60
         } else {
61
-            glsr(CountsManager::class)->decrease($review);
61
+            glsr( CountsManager::class )->decrease( $review );
62 62
         }
63 63
     }
64 64
 
@@ -66,13 +66,13 @@  discard block
 block discarded – undo
66 66
      * @return void
67 67
      * @action site-reviews/review/created
68 68
      */
69
-    public function onAfterCreate(Review $review)
69
+    public function onAfterCreate( Review $review )
70 70
     {
71
-        if ('publish' !== $review->status) {
71
+        if( 'publish' !== $review->status ) {
72 72
             return;
73 73
         }
74
-        glsr(CountsManager::class)->increaseCounts($review);
75
-        glsr(CountsManager::class)->increasePostCounts($review);
74
+        glsr( CountsManager::class )->increaseCounts( $review );
75
+        glsr( CountsManager::class )->increasePostCounts( $review );
76 76
     }
77 77
 
78 78
     /**
@@ -80,14 +80,14 @@  discard block
 block discarded – undo
80 80
      * @return void
81 81
      * @action before_delete_post
82 82
      */
83
-    public function onBeforeDelete($postId)
83
+    public function onBeforeDelete( $postId )
84 84
     {
85
-        if (!$this->isReviewPostId($postId)) {
85
+        if( !$this->isReviewPostId( $postId ) ) {
86 86
             return;
87 87
         }
88
-        $review = glsr_get_review($postId);
89
-        if ('trash' !== $review->status) { // do not run for trashed posts
90
-            glsr(CountsManager::class)->decrease($review);
88
+        $review = glsr_get_review( $postId );
89
+        if( 'trash' !== $review->status ) { // do not run for trashed posts
90
+            glsr( CountsManager::class )->decrease( $review );
91 91
         }
92 92
     }
93 93
 
@@ -99,53 +99,53 @@  discard block
 block discarded – undo
99 99
      * @return void
100 100
      * @action update_postmeta
101 101
      */
102
-    public function onBeforeUpdate($metaId, $postId, $metaKey, $metaValue)
102
+    public function onBeforeUpdate( $metaId, $postId, $metaKey, $metaValue )
103 103
     {
104
-        if (!$this->isReviewPostId($postId)) {
104
+        if( !$this->isReviewPostId( $postId ) ) {
105 105
             return;
106 106
         }
107
-        $metaKey = Str::removePrefix('_', $metaKey);
108
-        if (!in_array($metaKey, ['assigned_to', 'rating', 'review_type'])) {
107
+        $metaKey = Str::removePrefix( '_', $metaKey );
108
+        if( !in_array( $metaKey, ['assigned_to', 'rating', 'review_type'] ) ) {
109 109
             return;
110 110
         }
111
-        $review = glsr_get_review($postId);
112
-        if ($review->$metaKey == $metaValue) {
111
+        $review = glsr_get_review( $postId );
112
+        if( $review->$metaKey == $metaValue ) {
113 113
             return;
114 114
         }
115
-        $method = Helper::buildMethodName($metaKey, 'onBeforeChange');
116
-        call_user_func([$this, $method], $review, $metaValue);
115
+        $method = Helper::buildMethodName( $metaKey, 'onBeforeChange' );
116
+        call_user_func( [$this, $method], $review, $metaValue );
117 117
     }
118 118
 
119 119
     /**
120 120
      * @param string|int $assignedTo
121 121
      * @return void
122 122
      */
123
-    public function onBeforeChangeAssignedTo(Review $review, $assignedTo)
123
+    public function onBeforeChangeAssignedTo( Review $review, $assignedTo )
124 124
     {
125
-        glsr(CountsManager::class)->decreasePostCounts($review);
125
+        glsr( CountsManager::class )->decreasePostCounts( $review );
126 126
         $review->assigned_to = $assignedTo;
127
-        glsr(CountsManager::class)->increasePostCounts($review);
127
+        glsr( CountsManager::class )->increasePostCounts( $review );
128 128
     }
129 129
 
130 130
     /**
131 131
      * @param string|int $rating
132 132
      * @return void
133 133
      */
134
-    public function onBeforeChangeRating(Review $review, $rating)
134
+    public function onBeforeChangeRating( Review $review, $rating )
135 135
     {
136
-        glsr(CountsManager::class)->decrease($review);
136
+        glsr( CountsManager::class )->decrease( $review );
137 137
         $review->rating = $rating;
138
-        glsr(CountsManager::class)->increase($review);
138
+        glsr( CountsManager::class )->increase( $review );
139 139
     }
140 140
 
141 141
     /**
142 142
      * @param string $reviewType
143 143
      * @return void
144 144
      */
145
-    public function onBeforeChangeReviewType(Review $review, $reviewType)
145
+    public function onBeforeChangeReviewType( Review $review, $reviewType )
146 146
     {
147
-        glsr(CountsManager::class)->decrease($review);
147
+        glsr( CountsManager::class )->decrease( $review );
148 148
         $review->review_type = $reviewType;
149
-        glsr(CountsManager::class)->increase($review);
149
+        glsr( CountsManager::class )->increase( $review );
150 150
     }
151 151
 }
Please login to merge, or discard this patch.
plugin/Controllers/AdminController.php 1 patch
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -22,9 +22,9 @@  discard block
 block discarded – undo
22 22
      */
23 23
     public function enqueueAssets()
24 24
     {
25
-        $command = new EnqueueAdminAssets([
25
+        $command = new EnqueueAdminAssets( [
26 26
             'pointers' => [[
27
-                'content' => __('You can pin exceptional reviews so that they are always shown first.', 'site-reviews'),
27
+                'content' => __( 'You can pin exceptional reviews so that they are always shown first.', 'site-reviews' ),
28 28
                 'id' => 'glsr-pointer-pinned',
29 29
                 'position' => [
30 30
                     'edge' => 'right',
@@ -32,24 +32,24 @@  discard block
 block discarded – undo
32 32
                 ],
33 33
                 'screen' => Application::POST_TYPE,
34 34
                 'target' => '#misc-pub-pinned',
35
-                'title' => __('Pin Your Reviews', 'site-reviews'),
35
+                'title' => __( 'Pin Your Reviews', 'site-reviews' ),
36 36
             ]],
37
-        ]);
38
-        $this->execute($command);
37
+        ] );
38
+        $this->execute( $command );
39 39
     }
40 40
 
41 41
     /**
42 42
      * @return array
43 43
      * @filter plugin_action_links_site-reviews/site-reviews.php
44 44
      */
45
-    public function filterActionLinks(array $links)
45
+    public function filterActionLinks( array $links )
46 46
     {
47
-        $links['documentation'] = glsr(Builder::class)->a(__('Help', 'site-reviews'), [
48
-            'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=documentation'),
49
-        ]);
50
-        $links['settings'] = glsr(Builder::class)->a(__('Settings', 'site-reviews'), [
51
-            'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=settings'),
52
-        ]);
47
+        $links['documentation'] = glsr( Builder::class )->a( __( 'Help', 'site-reviews' ), [
48
+            'href' => admin_url( 'edit.php?post_type='.Application::POST_TYPE.'&page=documentation' ),
49
+        ] );
50
+        $links['settings'] = glsr( Builder::class )->a( __( 'Settings', 'site-reviews' ), [
51
+            'href' => admin_url( 'edit.php?post_type='.Application::POST_TYPE.'&page=settings' ),
52
+        ] );
53 53
         return $links;
54 54
     }
55 55
 
@@ -59,9 +59,9 @@  discard block
 block discarded – undo
59 59
      * @return array
60 60
      * @filter map_meta_cap
61 61
      */
62
-    public function filterCreateCapability($capabilities, $capability)
62
+    public function filterCreateCapability( $capabilities, $capability )
63 63
     {
64
-        if ($capability == 'create_'.Application::POST_TYPE) {
64
+        if( $capability == 'create_'.Application::POST_TYPE ) {
65 65
             $capabilities[] = 'do_not_allow';
66 66
         }
67 67
         return $capabilities;
@@ -72,23 +72,23 @@  discard block
 block discarded – undo
72 72
      * @return array
73 73
      * @filter dashboard_glance_items
74 74
      */
75
-    public function filterDashboardGlanceItems($items)
75
+    public function filterDashboardGlanceItems( $items )
76 76
     {
77
-        $postCount = wp_count_posts(Application::POST_TYPE);
78
-        if (empty($postCount->publish)) {
77
+        $postCount = wp_count_posts( Application::POST_TYPE );
78
+        if( empty($postCount->publish) ) {
79 79
             return $items;
80 80
         }
81
-        $text = _n('%s Review', '%s Reviews', $postCount->publish, 'site-reviews');
82
-        $text = sprintf($text, number_format_i18n($postCount->publish));
83
-        $items = Arr::consolidateArray($items);
84
-        $items[] = current_user_can(get_post_type_object(Application::POST_TYPE)->cap->edit_posts)
85
-            ? glsr(Builder::class)->a($text, [
81
+        $text = _n( '%s Review', '%s Reviews', $postCount->publish, 'site-reviews' );
82
+        $text = sprintf( $text, number_format_i18n( $postCount->publish ) );
83
+        $items = Arr::consolidateArray( $items );
84
+        $items[] = current_user_can( get_post_type_object( Application::POST_TYPE )->cap->edit_posts )
85
+            ? glsr( Builder::class )->a( $text, [
86 86
                 'class' => 'glsr-review-count',
87 87
                 'href' => 'edit.php?post_type='.Application::POST_TYPE,
88
-            ])
89
-            : glsr(Builder::class)->span($text, [
88
+            ] )
89
+            : glsr( Builder::class )->span( $text, [
90 90
                 'class' => 'glsr-review-count',
91
-            ]);
91
+            ] );
92 92
         return $items;
93 93
     }
94 94
 
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
      * @return array
98 98
      * @filter mce_external_plugins
99 99
      */
100
-    public function filterTinymcePlugins($plugins)
100
+    public function filterTinymcePlugins( $plugins )
101 101
     {
102
-        if (current_user_can('edit_posts') || current_user_can('edit_pages')) {
103
-            $plugins = Arr::consolidateArray($plugins);
104
-            $plugins['glsr_shortcode'] = glsr()->url('assets/scripts/mce-plugin.js');
102
+        if( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) {
103
+            $plugins = Arr::consolidateArray( $plugins );
104
+            $plugins['glsr_shortcode'] = glsr()->url( 'assets/scripts/mce-plugin.js' );
105 105
         }
106 106
         return $plugins;
107 107
     }
@@ -112,12 +112,12 @@  discard block
 block discarded – undo
112 112
      */
113 113
     public function registerTinymcePopups()
114 114
     {
115
-        $command = new RegisterTinymcePopups([
116
-            'site_reviews' => esc_html__('Recent Reviews', 'site-reviews'),
117
-            'site_reviews_form' => esc_html__('Submit a Review', 'site-reviews'),
118
-            'site_reviews_summary' => esc_html__('Summary of Reviews', 'site-reviews'),
119
-        ]);
120
-        $this->execute($command);
115
+        $command = new RegisterTinymcePopups( [
116
+            'site_reviews' => esc_html__( 'Recent Reviews', 'site-reviews' ),
117
+            'site_reviews_form' => esc_html__( 'Submit a Review', 'site-reviews' ),
118
+            'site_reviews_summary' => esc_html__( 'Summary of Reviews', 'site-reviews' ),
119
+        ] );
120
+        $this->execute( $command );
121 121
     }
122 122
 
123 123
     /**
@@ -125,22 +125,22 @@  discard block
 block discarded – undo
125 125
      * @return void|null
126 126
      * @action media_buttons
127 127
      */
128
-    public function renderTinymceButton($editorId)
128
+    public function renderTinymceButton( $editorId )
129 129
     {
130
-        $allowedEditors = apply_filters('site-reviews/tinymce/editor-ids', ['content'], $editorId);
131
-        if ('post' != glsr_current_screen()->base || !in_array($editorId, $allowedEditors)) {
130
+        $allowedEditors = apply_filters( 'site-reviews/tinymce/editor-ids', ['content'], $editorId );
131
+        if( 'post' != glsr_current_screen()->base || !in_array( $editorId, $allowedEditors ) ) {
132 132
             return;
133 133
         }
134 134
         $shortcodes = [];
135
-        foreach (glsr()->mceShortcodes as $shortcode => $values) {
135
+        foreach( glsr()->mceShortcodes as $shortcode => $values ) {
136 136
             $shortcodes[$shortcode] = $values;
137 137
         }
138
-        if (empty($shortcodes)) {
138
+        if( empty($shortcodes) ) {
139 139
             return;
140 140
         }
141
-        glsr()->render('partials/editor/tinymce', [
141
+        glsr()->render( 'partials/editor/tinymce', [
142 142
             'shortcodes' => $shortcodes,
143
-        ]);
143
+        ] );
144 144
     }
145 145
 
146 146
     /**
@@ -148,8 +148,8 @@  discard block
 block discarded – undo
148 148
      */
149 149
     public function routerClearConsole()
150 150
     {
151
-        glsr(Console::class)->clear();
152
-        glsr(Notice::class)->addSuccess(__('Console cleared.', 'site-reviews'));
151
+        glsr( Console::class )->clear();
152
+        glsr( Notice::class )->addSuccess( __( 'Console cleared.', 'site-reviews' ) );
153 153
     }
154 154
 
155 155
     /**
@@ -157,19 +157,19 @@  discard block
 block discarded – undo
157 157
      */
158 158
     public function routerFetchConsole()
159 159
     {
160
-        glsr(Notice::class)->addSuccess(__('Console reloaded.', 'site-reviews'));
160
+        glsr( Notice::class )->addSuccess( __( 'Console reloaded.', 'site-reviews' ) );
161 161
     }
162 162
 
163 163
     /**
164 164
      * @param bool $showNotice
165 165
      * @return void
166 166
      */
167
-    public function routerCountReviews($showNotice = true)
167
+    public function routerCountReviews( $showNotice = true )
168 168
     {
169
-        glsr(CountsManager::class)->countAll();
170
-        glsr(OptionManager::class)->set('last_review_count', current_time('timestamp'));
171
-        if ($showNotice) {
172
-            glsr(Notice::class)->clear()->addSuccess(__('Recalculated rating counts.', 'site-reviews'));
169
+        glsr( CountsManager::class )->countAll();
170
+        glsr( OptionManager::class )->set( 'last_review_count', current_time( 'timestamp' ) );
171
+        if( $showNotice ) {
172
+            glsr( Notice::class )->clear()->addSuccess( __( 'Recalculated rating counts.', 'site-reviews' ) );
173 173
         }
174 174
     }
175 175
 
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
      */
179 179
     public function routerDownloadConsole()
180 180
     {
181
-        $this->download(Application::ID.'-console.txt', glsr(Console::class)->get());
181
+        $this->download( Application::ID.'-console.txt', glsr( Console::class )->get() );
182 182
     }
183 183
 
184 184
     /**
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
      */
187 187
     public function routerDownloadSystemInfo()
188 188
     {
189
-        $this->download(Application::ID.'-system-info.txt', glsr(System::class)->get());
189
+        $this->download( Application::ID.'-system-info.txt', glsr( System::class )->get() );
190 190
     }
191 191
 
192 192
     /**
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
      */
195 195
     public function routerExportSettings()
196 196
     {
197
-        $this->download(Application::ID.'-settings.json', glsr(OptionManager::class)->json());
197
+        $this->download( Application::ID.'-settings.json', glsr( OptionManager::class )->json() );
198 198
     }
199 199
 
200 200
     /**
@@ -203,35 +203,35 @@  discard block
 block discarded – undo
203 203
     public function routerImportSettings()
204 204
     {
205 205
         $file = $_FILES['import-file'];
206
-        if (UPLOAD_ERR_OK !== $file['error']) {
207
-            return glsr(Notice::class)->addError($this->getUploadError($file['error']));
206
+        if( UPLOAD_ERR_OK !== $file['error'] ) {
207
+            return glsr( Notice::class )->addError( $this->getUploadError( $file['error'] ) );
208 208
         }
209
-        if ('application/json' !== $file['type'] || !Str::endsWith('.json', $file['name'])) {
210
-            return glsr(Notice::class)->addError(__('Please use a valid Site Reviews settings file.', 'site-reviews'));
209
+        if( 'application/json' !== $file['type'] || !Str::endsWith( '.json', $file['name'] ) ) {
210
+            return glsr( Notice::class )->addError( __( 'Please use a valid Site Reviews settings file.', 'site-reviews' ) );
211 211
         }
212
-        $settings = json_decode(file_get_contents($file['tmp_name']), true);
213
-        if (empty($settings)) {
214
-            return glsr(Notice::class)->addWarning(__('There were no settings found to import.', 'site-reviews'));
212
+        $settings = json_decode( file_get_contents( $file['tmp_name'] ), true );
213
+        if( empty($settings) ) {
214
+            return glsr( Notice::class )->addWarning( __( 'There were no settings found to import.', 'site-reviews' ) );
215 215
         }
216
-        glsr(OptionManager::class)->set(glsr(OptionManager::class)->normalize($settings));
217
-        glsr(Notice::class)->addSuccess(__('Settings imported.', 'site-reviews'));
216
+        glsr( OptionManager::class )->set( glsr( OptionManager::class )->normalize( $settings ) );
217
+        glsr( Notice::class )->addSuccess( __( 'Settings imported.', 'site-reviews' ) );
218 218
     }
219 219
 
220 220
     /**
221 221
      * @param int $errorCode
222 222
      * @return string
223 223
      */
224
-    protected function getUploadError($errorCode)
224
+    protected function getUploadError( $errorCode )
225 225
     {
226 226
         $errors = [
227
-            UPLOAD_ERR_INI_SIZE => __('The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'site-reviews'),
228
-            UPLOAD_ERR_FORM_SIZE => __('The uploaded file is too big.', 'site-reviews'),
229
-            UPLOAD_ERR_PARTIAL => __('The uploaded file was only partially uploaded.', 'site-reviews'),
230
-            UPLOAD_ERR_NO_FILE => __('No file was uploaded.', 'site-reviews'),
231
-            UPLOAD_ERR_NO_TMP_DIR => __('Missing a temporary folder.', 'site-reviews'),
232
-            UPLOAD_ERR_CANT_WRITE => __('Failed to write file to disk.', 'site-reviews'),
233
-            UPLOAD_ERR_EXTENSION => __('A PHP extension stopped the file upload.', 'site-reviews'),
227
+            UPLOAD_ERR_INI_SIZE => __( 'The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'site-reviews' ),
228
+            UPLOAD_ERR_FORM_SIZE => __( 'The uploaded file is too big.', 'site-reviews' ),
229
+            UPLOAD_ERR_PARTIAL => __( 'The uploaded file was only partially uploaded.', 'site-reviews' ),
230
+            UPLOAD_ERR_NO_FILE => __( 'No file was uploaded.', 'site-reviews' ),
231
+            UPLOAD_ERR_NO_TMP_DIR => __( 'Missing a temporary folder.', 'site-reviews' ),
232
+            UPLOAD_ERR_CANT_WRITE => __( 'Failed to write file to disk.', 'site-reviews' ),
233
+            UPLOAD_ERR_EXTENSION => __( 'A PHP extension stopped the file upload.', 'site-reviews' ),
234 234
         ];
235
-        return Arr::get($errors, $errorCode, __('Unknown upload error.', 'site-reviews'));
235
+        return Arr::get( $errors, $errorCode, __( 'Unknown upload error.', 'site-reviews' ) );
236 236
     }
237 237
 }
Please login to merge, or discard this patch.
plugin/Modules/ReviewLimits.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -14,26 +14,26 @@  discard block
 block discarded – undo
14 14
      * @return array
15 15
      * @filter site-reviews/get/reviews/query
16 16
      */
17
-    public function filterReviewsQuery(array $parameters, array $args)
17
+    public function filterReviewsQuery( array $parameters, array $args )
18 18
     {
19
-        if ($authorId = get_current_user_id()) {
19
+        if( $authorId = get_current_user_id() ) {
20 20
             $parameters['author'] = $authorId;
21 21
         }
22 22
         $parameters['post_status'] = ['pending', 'publish'];
23
-        return apply_filters('site-reviews/reviews-limits/query', $parameters, $args);
23
+        return apply_filters( 'site-reviews/reviews-limits/query', $parameters, $args );
24 24
     }
25 25
 
26 26
     /**
27 27
      * @return bool
28 28
      */
29
-    public function hasReachedLimit(array $request = [])
29
+    public function hasReachedLimit( array $request = [] )
30 30
     {
31 31
         $this->request = $request;
32 32
         $method = Helper::buildMethodName(
33
-            glsr(OptionManager::class)->get('settings.submissions.limit'), 'validateBy'
33
+            glsr( OptionManager::class )->get( 'settings.submissions.limit' ), 'validateBy'
34 34
         );
35
-        return method_exists($this, $method)
36
-            ? !call_user_func([$this, $method])
35
+        return method_exists( $this, $method )
36
+            ? !call_user_func( [$this, $method] )
37 37
             : false;
38 38
     }
39 39
 
@@ -42,39 +42,39 @@  discard block
 block discarded – undo
42 42
      * @param string $whitelist
43 43
      * @return bool
44 44
      */
45
-    public function isWhitelisted($value, $whitelist)
45
+    public function isWhitelisted( $value, $whitelist )
46 46
     {
47
-        if (empty($whitelist)) {
47
+        if( empty($whitelist) ) {
48 48
             return false;
49 49
         }
50
-        return in_array($value, array_filter(explode("\n", $whitelist), 'trim'));
50
+        return in_array( $value, array_filter( explode( "\n", $whitelist ), 'trim' ) );
51 51
     }
52 52
 
53 53
     /**
54 54
      * @param string $whitelistName
55 55
      * @return string
56 56
      */
57
-    protected function getWhitelist($whitelistName)
57
+    protected function getWhitelist( $whitelistName )
58 58
     {
59
-        return glsr(OptionManager::class)->get('settings.submissions.limit_whitelist.'.$whitelistName);
59
+        return glsr( OptionManager::class )->get( 'settings.submissions.limit_whitelist.'.$whitelistName );
60 60
     }
61 61
 
62 62
     /**
63 63
      * @return bool
64 64
      */
65
-    protected function validate($key, $value, $addMetaQuery = true)
65
+    protected function validate( $key, $value, $addMetaQuery = true )
66 66
     {
67
-        if ($this->isWhitelisted($value, $this->getWhitelist($key))) {
67
+        if( $this->isWhitelisted( $value, $this->getWhitelist( $key ) ) ) {
68 68
             return true;
69 69
         }
70
-        add_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5, 2);
71
-        $args = ['assigned_to' => Arr::get($this->request, 'assign_to')];
72
-        if ($addMetaQuery) {
70
+        add_filter( 'site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5, 2 );
71
+        $args = ['assigned_to' => Arr::get( $this->request, 'assign_to' )];
72
+        if( $addMetaQuery ) {
73 73
             $args[$key] = $value;
74 74
         }
75
-        $reviews = glsr_get_reviews($args);
76
-        remove_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5);
77
-        return 0 === count($reviews);
75
+        $reviews = glsr_get_reviews( $args );
76
+        remove_filter( 'site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5 );
77
+        return 0 === count( $reviews );
78 78
     }
79 79
 
80 80
     /**
@@ -82,8 +82,8 @@  discard block
 block discarded – undo
82 82
      */
83 83
     protected function validateByEmail()
84 84
     {
85
-        glsr_log()->debug('Email is: '.Arr::get($this->request, 'email'));
86
-        return $this->validate('email', Arr::get($this->request, 'email'));
85
+        glsr_log()->debug( 'Email is: '.Arr::get( $this->request, 'email' ) );
86
+        return $this->validate( 'email', Arr::get( $this->request, 'email' ) );
87 87
     }
88 88
 
89 89
     /**
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
      */
92 92
     protected function validateByIpAddress()
93 93
     {
94
-        glsr_log()->debug('IP Address is: '.Arr::get($this->request, 'ip_address'));
95
-        return $this->validate('ip_address', Arr::get($this->request, 'ip_address'));
94
+        glsr_log()->debug( 'IP Address is: '.Arr::get( $this->request, 'ip_address' ) );
95
+        return $this->validate( 'ip_address', Arr::get( $this->request, 'ip_address' ) );
96 96
     }
97 97
 
98 98
     /**
@@ -101,10 +101,10 @@  discard block
 block discarded – undo
101 101
     protected function validateByUsername()
102 102
     {
103 103
         $user = wp_get_current_user();
104
-        if (!$user->exists()) {
104
+        if( !$user->exists() ) {
105 105
             return true;
106 106
         }
107
-        glsr_log()->debug('Username is: '.$user->user_login);
108
-        return $this->validate('username', $user->user_login, false);
107
+        glsr_log()->debug( 'Username is: '.$user->user_login );
108
+        return $this->validate( 'username', $user->user_login, false );
109 109
     }
110 110
 }
Please login to merge, or discard this patch.
plugin/Modules/Rebusify.php 1 patch
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -20,25 +20,25 @@  discard block
 block discarded – undo
20 20
     /**
21 21
      * @return mixed
22 22
      */
23
-    public function __get($key)
23
+    public function __get( $key )
24 24
     {
25
-        return property_exists($this, $key)
25
+        return property_exists( $this, $key )
26 26
             ? $this->$key
27
-            : Arr::get($this->response, $key, null);
27
+            : Arr::get( $this->response, $key, null );
28 28
     }
29 29
 
30 30
     /**
31 31
      * @return self
32 32
      */
33
-    public function activateKey($apiKey = '', $email = '')
33
+    public function activateKey( $apiKey = '', $email = '' )
34 34
     {
35
-        $this->send('api_key_activation.php', [
35
+        $this->send( 'api_key_activation.php', [
36 36
             'body' => [
37 37
                 'apikey' => $apiKey ?: 0,
38 38
                 'domain' => get_home_url(),
39 39
                 'email' => $email ?: 0,
40 40
             ],
41
-        ]);
41
+        ] );
42 42
         return $this;
43 43
     }
44 44
 
@@ -56,77 +56,77 @@  discard block
 block discarded – undo
56 56
     /**
57 57
      * @return self
58 58
      */
59
-    public function sendReview(Review $review)
59
+    public function sendReview( Review $review )
60 60
     {
61
-        $this->send('index.php', [
62
-            'body' => $this->getBodyForReview($review),
61
+        $this->send( 'index.php', [
62
+            'body' => $this->getBodyForReview( $review ),
63 63
             'timeout' => 120,
64
-        ]);
64
+        ] );
65 65
         return $this;
66 66
     }
67 67
 
68 68
     /**
69 69
      * @return self
70 70
      */
71
-    public function sendReviewResponse(Review $review)
71
+    public function sendReviewResponse( Review $review )
72 72
     {
73
-        $this->send('fetch_customer_reply.php', [
74
-            'body' => $this->getBodyForResponse($review),
75
-        ]);
73
+        $this->send( 'fetch_customer_reply.php', [
74
+            'body' => $this->getBodyForResponse( $review ),
75
+        ] );
76 76
         return $this;
77 77
     }
78 78
 
79 79
     /**
80 80
      * @return array
81 81
      */
82
-    protected function getBodyForResponse(Review $review)
82
+    protected function getBodyForResponse( Review $review )
83 83
     {
84 84
         $rebusifyResponse = [
85
-            'reply' => Str::truncate($review->response, 300),
86
-            'review_id' => glsr(Database::class)->get($review->ID, 'rebusify'), // this is the rebusify review ID
85
+            'reply' => Str::truncate( $review->response, 300 ),
86
+            'review_id' => glsr( Database::class )->get( $review->ID, 'rebusify' ), // this is the rebusify review ID
87 87
             'review_transaction_id' => $review->review_id,
88 88
             'type' => 'M',
89 89
         ];
90
-        return apply_filters('site-reviews/rebusify/response', $rebusifyResponse, $review);
90
+        return apply_filters( 'site-reviews/rebusify/response', $rebusifyResponse, $review );
91 91
     }
92 92
 
93 93
     /**
94 94
      * @return array
95 95
      */
96
-    protected function getBodyForReview(Review $review)
96
+    protected function getBodyForReview( Review $review )
97 97
     {
98 98
         $rebusifyReview = [
99 99
             'domain' => get_home_url(),
100
-            'firstname' => Str::truncate(Str::convertName($review->author, 'first'), 25),
100
+            'firstname' => Str::truncate( Str::convertName( $review->author, 'first' ), 25 ),
101 101
             'rate' => $review->rating,
102 102
             'review_transaction_id' => $review->review_id,
103
-            'reviews' => Str::truncate($review->content, 280),
104
-            'title' => Str::truncate($review->title, 35),
103
+            'reviews' => Str::truncate( $review->content, 280 ),
104
+            'title' => Str::truncate( $review->title, 35 ),
105 105
             'transaction' => Application::ID, // woocommerce field, not needed for Site Reviews
106 106
         ];
107
-        return apply_filters('site-reviews/rebusify/review', $rebusifyReview, $review);
107
+        return apply_filters( 'site-reviews/rebusify/review', $rebusifyReview, $review );
108 108
     }
109 109
 
110 110
     /**
111 111
      * @param \WP_Error|array $response
112 112
      * @return void
113 113
      */
114
-    protected function handleResponse($response)
114
+    protected function handleResponse( $response )
115 115
     {
116
-        if (is_wp_error($response)) {
116
+        if( is_wp_error( $response ) ) {
117 117
             $this->message = $response->get_error_message();
118 118
         } else {
119
-            $responseBody = wp_remote_retrieve_body($response);
120
-            $responseCode = wp_remote_retrieve_response_code($response);
121
-            $responseData = (array) json_decode($responseBody, true);
122
-            $this->response = array_shift($responseData);
123
-            $this->message = Arr::get($this->response, 'msg');
124
-            $this->success = 'success' === Arr::get($this->response, 'result') || 'yes' === Arr::get($this->response, 'success'); // @todo remove this ugly hack!
125
-            if (200 !== $responseCode) {
126
-                glsr_log()->error('Bad response code ['.$responseCode.']');
119
+            $responseBody = wp_remote_retrieve_body( $response );
120
+            $responseCode = wp_remote_retrieve_response_code( $response );
121
+            $responseData = (array)json_decode( $responseBody, true );
122
+            $this->response = array_shift( $responseData );
123
+            $this->message = Arr::get( $this->response, 'msg' );
124
+            $this->success = 'success' === Arr::get( $this->response, 'result' ) || 'yes' === Arr::get( $this->response, 'success' ); // @todo remove this ugly hack!
125
+            if( 200 !== $responseCode ) {
126
+                glsr_log()->error( 'Bad response code ['.$responseCode.']' );
127 127
             }
128
-            if (!$this->success) {
129
-                glsr_log()->error($this->message);
128
+            if( !$this->success ) {
129
+                glsr_log()->error( $this->message );
130 130
             }
131 131
         }
132 132
     }
@@ -135,18 +135,18 @@  discard block
 block discarded – undo
135 135
      * @param string $endpoint
136 136
      * @return void
137 137
      */
138
-    protected function send($endpoint, array $args = [])
138
+    protected function send( $endpoint, array $args = [] )
139 139
     {
140
-        $args = wp_parse_args($args, [
140
+        $args = wp_parse_args( $args, [
141 141
             'body' => null,
142 142
             'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'],
143 143
             'redirection' => 5,
144 144
             'sslverify' => false,
145 145
             'timeout' => 5,
146
-        ]);
146
+        ] );
147 147
         $this->reset();
148 148
         $this->handleResponse(
149
-            wp_remote_post(trailingslashit(static::API_URL).$endpoint, $args)
149
+            wp_remote_post( trailingslashit( static::API_URL ).$endpoint, $args )
150 150
         );
151 151
     }
152 152
 }
Please login to merge, or discard this patch.
plugin/Modules/Schema/BaseType.php 1 patch
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -37,18 +37,18 @@  discard block
 block discarded – undo
37 37
      * @param string $method
38 38
      * @return static
39 39
      */
40
-    public function __call($method, array $arguments)
40
+    public function __call( $method, array $arguments )
41 41
     {
42
-        return $this->setProperty($method, Arr::get($arguments, 0));
42
+        return $this->setProperty( $method, Arr::get( $arguments, 0 ) );
43 43
     }
44 44
 
45 45
     /**
46 46
      * @param string $type
47 47
      */
48
-    public function __construct($type = null)
48
+    public function __construct( $type = null )
49 49
     {
50
-        $this->type = !is_string($type)
51
-            ? (new ReflectionClass($this))->getShortName()
50
+        $this->type = !is_string( $type )
51
+            ? (new ReflectionClass( $this ))->getShortName()
52 52
             : $type;
53 53
         $this->setAllowedProperties();
54 54
     }
@@ -64,10 +64,10 @@  discard block
 block discarded – undo
64 64
     /**
65 65
      * @return static
66 66
      */
67
-    public function addProperties(array $properties)
67
+    public function addProperties( array $properties )
68 68
     {
69
-        foreach ($properties as $property => $value) {
70
-            $this->setProperty($property, $value);
69
+        foreach( $properties as $property => $value ) {
70
+            $this->setProperty( $property, $value );
71 71
         }
72 72
         return $this;
73 73
     }
@@ -93,9 +93,9 @@  discard block
 block discarded – undo
93 93
      * @param mixed $default
94 94
      * @return mixed
95 95
      */
96
-    public function getProperty($property, $default = null)
96
+    public function getProperty( $property, $default = null )
97 97
     {
98
-        return Arr::get($this->properties, $property, $default);
98
+        return Arr::get( $this->properties, $property, $default );
99 99
     }
100 100
 
101 101
     /**
@@ -111,10 +111,10 @@  discard block
 block discarded – undo
111 111
      * @param mixed $callback
112 112
      * @return static
113 113
      */
114
-    public function doIf($condition, $callback)
114
+    public function doIf( $condition, $callback )
115 115
     {
116
-        if ($condition) {
117
-            $callback($this);
116
+        if( $condition ) {
117
+            $callback( $this );
118 118
         }
119 119
         return $this;
120 120
     }
@@ -131,18 +131,18 @@  discard block
 block discarded – undo
131 131
      * @param mixed $offset
132 132
      * @return bool
133 133
      */
134
-    public function offsetExists($offset)
134
+    public function offsetExists( $offset )
135 135
     {
136
-        return array_key_exists($offset, $this->properties);
136
+        return array_key_exists( $offset, $this->properties );
137 137
     }
138 138
 
139 139
     /**
140 140
      * @param string $offset
141 141
      * @return mixed
142 142
      */
143
-    public function offsetGet($offset)
143
+    public function offsetGet( $offset )
144 144
     {
145
-        return $this->getProperty($offset);
145
+        return $this->getProperty( $offset );
146 146
     }
147 147
 
148 148
     /**
@@ -150,16 +150,16 @@  discard block
 block discarded – undo
150 150
      * @param mixed $value
151 151
      * @return void
152 152
      */
153
-    public function offsetSet($offset, $value)
153
+    public function offsetSet( $offset, $value )
154 154
     {
155
-        $this->setProperty($offset, $value);
155
+        $this->setProperty( $offset, $value );
156 156
     }
157 157
 
158 158
     /**
159 159
      * @param string $offset
160 160
      * @return void
161 161
      */
162
-    public function offsetUnset($offset)
162
+    public function offsetUnset( $offset )
163 163
     {
164 164
         unset($this->properties[$offset]);
165 165
     }
@@ -169,11 +169,11 @@  discard block
 block discarded – undo
169 169
      * @param mixed $value
170 170
      * @return static
171 171
      */
172
-    public function setProperty($property, $value)
172
+    public function setProperty( $property, $value )
173 173
     {
174
-        if (!in_array($property, $this->allowed)
175
-            && 'UnknownType' != (new ReflectionClass($this))->getShortName()) {
176
-            glsr_log()->warning($this->getType().' does not allow the "'.$property.'" property');
174
+        if( !in_array( $property, $this->allowed )
175
+            && 'UnknownType' != (new ReflectionClass( $this ))->getShortName() ) {
176
+            glsr_log()->warning( $this->getType().' does not allow the "'.$property.'" property' );
177 177
             return $this;
178 178
         }
179 179
         $this->properties[$property] = $value;
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
         return [
189 189
             '@context' => $this->getContext(),
190 190
             '@type' => $this->getType(),
191
-        ] + $this->serializeProperty($this->getProperties());
191
+        ] + $this->serializeProperty( $this->getProperties() );
192 192
     }
193 193
 
194 194
     /**
@@ -196,8 +196,8 @@  discard block
 block discarded – undo
196 196
      */
197 197
     public function toScript()
198 198
     {
199
-        return sprintf('<script type="application/ld+json">%s</script>',
200
-            json_encode($this->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)
199
+        return sprintf( '<script type="application/ld+json">%s</script>',
200
+            json_encode( $this->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES )
201 201
         );
202 202
     }
203 203
 
@@ -205,20 +205,20 @@  discard block
 block discarded – undo
205 205
      * @param array|null $parents
206 206
      * @return array
207 207
      */
208
-    protected function getParents($parents = null)
208
+    protected function getParents( $parents = null )
209 209
     {
210
-        if (!isset($parents)) {
210
+        if( !isset($parents) ) {
211 211
             $parents = $this->parents;
212 212
         }
213 213
         $newParents = $parents;
214
-        foreach ($parents as $parent) {
215
-            $parentClass = Helper::buildClassName($parent, __NAMESPACE__);
216
-            if (!class_exists($parentClass)) {
214
+        foreach( $parents as $parent ) {
215
+            $parentClass = Helper::buildClassName( $parent, __NAMESPACE__ );
216
+            if( !class_exists( $parentClass ) ) {
217 217
                 continue;
218 218
             }
219
-            $newParents = array_merge($newParents, $this->getParents((new $parentClass())->parents));
219
+            $newParents = array_merge( $newParents, $this->getParents( (new $parentClass())->parents ) );
220 220
         }
221
-        return array_values(array_unique($newParents));
221
+        return array_values( array_unique( $newParents ) );
222 222
     }
223 223
 
224 224
     /**
@@ -227,12 +227,12 @@  discard block
 block discarded – undo
227 227
     protected function setAllowedProperties()
228 228
     {
229 229
         $parents = $this->getParents();
230
-        foreach ($parents as $parent) {
231
-            $parentClass = Helper::buildClassName($parent, __NAMESPACE__);
232
-            if (!class_exists($parentClass)) {
230
+        foreach( $parents as $parent ) {
231
+            $parentClass = Helper::buildClassName( $parent, __NAMESPACE__ );
232
+            if( !class_exists( $parentClass ) ) {
233 233
                 continue;
234 234
             }
235
-            $this->allowed = array_values(array_unique(array_merge((new $parentClass())->allowed, $this->allowed)));
235
+            $this->allowed = array_values( array_unique( array_merge( (new $parentClass())->allowed, $this->allowed ) ) );
236 236
         }
237 237
     }
238 238
 
@@ -240,19 +240,19 @@  discard block
 block discarded – undo
240 240
      * @param mixed $property
241 241
      * @return array|string
242 242
      */
243
-    protected function serializeProperty($property)
243
+    protected function serializeProperty( $property )
244 244
     {
245
-        if (is_array($property)) {
246
-            return array_map([$this, 'serializeProperty'], $property);
245
+        if( is_array( $property ) ) {
246
+            return array_map( [$this, 'serializeProperty'], $property );
247 247
         }
248
-        if ($property instanceof Type) {
248
+        if( $property instanceof Type ) {
249 249
             $property = $property->toArray();
250 250
             unset($property['@context']);
251 251
         }
252
-        if ($property instanceof DateTimeInterface) {
253
-            $property = $property->format(DateTime::ATOM);
252
+        if( $property instanceof DateTimeInterface ) {
253
+            $property = $property->format( DateTime::ATOM );
254 254
         }
255
-        if (is_object($property)) {
255
+        if( is_object( $property ) ) {
256 256
             throw new InvalidProperty();
257 257
         }
258 258
         return $property;
Please login to merge, or discard this patch.
plugin/Modules/Html/Settings.php 1 patch
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -20,31 +20,31 @@  discard block
 block discarded – undo
20 20
      * @param string $id
21 21
      * @return string
22 22
      */
23
-    public function buildFields($id)
23
+    public function buildFields( $id )
24 24
     {
25
-        $this->settings = glsr(DefaultsManager::class)->settings();
26
-        $method = Helper::buildMethodName($id, 'getTemplateDataFor');
27
-        $data = !method_exists($this, $method)
28
-            ? $this->getTemplateData($id)
29
-            : $this->$method($id);
30
-        return glsr(Template::class)->build('pages/settings/'.$id, $data);
25
+        $this->settings = glsr( DefaultsManager::class )->settings();
26
+        $method = Helper::buildMethodName( $id, 'getTemplateDataFor' );
27
+        $data = !method_exists( $this, $method )
28
+            ? $this->getTemplateData( $id )
29
+            : $this->$method( $id );
30
+        return glsr( Template::class )->build( 'pages/settings/'.$id, $data );
31 31
     }
32 32
 
33 33
     /**
34 34
      * @return string
35 35
      */
36
-    protected function getFieldDefault(array $field)
36
+    protected function getFieldDefault( array $field )
37 37
     {
38
-        return Arr::get($field, 'default');
38
+        return Arr::get( $field, 'default' );
39 39
     }
40 40
 
41 41
     /**
42 42
      * @return string
43 43
      */
44
-    protected function getFieldNameForDependsOn($path)
44
+    protected function getFieldNameForDependsOn( $path )
45 45
     {
46
-        $fieldName = Str::convertPathToName($path, OptionManager::databaseKey());
47
-        return $this->isMultiDependency($path)
46
+        $fieldName = Str::convertPathToName( $path, OptionManager::databaseKey() );
47
+        return $this->isMultiDependency( $path )
48 48
             ? $fieldName.'[]'
49 49
             : $fieldName;
50 50
     }
@@ -52,25 +52,25 @@  discard block
 block discarded – undo
52 52
     /**
53 53
      * @return array
54 54
      */
55
-    protected function getSettingFields($path)
55
+    protected function getSettingFields( $path )
56 56
     {
57
-        return array_filter($this->settings, function ($key) use ($path) {
58
-            return Str::startsWith($path, $key);
59
-        }, ARRAY_FILTER_USE_KEY);
57
+        return array_filter( $this->settings, function( $key ) use ($path) {
58
+            return Str::startsWith( $path, $key );
59
+        }, ARRAY_FILTER_USE_KEY );
60 60
     }
61 61
 
62 62
     /**
63 63
      * @return string
64 64
      */
65
-    protected function getSettingRows(array $fields)
65
+    protected function getSettingRows( array $fields )
66 66
     {
67 67
         $rows = '';
68
-        foreach ($fields as $name => $field) {
69
-            $field = wp_parse_args($field, [
68
+        foreach( $fields as $name => $field ) {
69
+            $field = wp_parse_args( $field, [
70 70
                 'is_setting' => true,
71 71
                 'name' => $name,
72
-            ]);
73
-            $rows.= new Field($this->normalize($field));
72
+            ] );
73
+            $rows .= new Field( $this->normalize( $field ) );
74 74
         }
75 75
         return $rows;
76 76
     }
@@ -79,12 +79,12 @@  discard block
 block discarded – undo
79 79
      * @param string $id
80 80
      * @return array
81 81
      */
82
-    protected function getTemplateData($id)
82
+    protected function getTemplateData( $id )
83 83
     {
84
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
84
+        $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) );
85 85
         return [
86 86
             'context' => [
87
-                'rows' => $this->getSettingRows($fields),
87
+                'rows' => $this->getSettingRows( $fields ),
88 88
             ],
89 89
         ];
90 90
     }
@@ -93,19 +93,19 @@  discard block
 block discarded – undo
93 93
      * @param string $id
94 94
      * @return array
95 95
      */
96
-    protected function getTemplateDataForAddons($id)
96
+    protected function getTemplateDataForAddons( $id )
97 97
     {
98
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
99
-        $settings = Arr::convertDotNotationArray($fields);
100
-        $settingKeys = array_keys($settings['settings']['addons']);
98
+        $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) );
99
+        $settings = Arr::convertDotNotationArray( $fields );
100
+        $settingKeys = array_keys( $settings['settings']['addons'] );
101 101
         $results = [];
102
-        foreach ($settingKeys as $key) {
103
-            $addonFields = array_filter($fields, function ($path) use ($key) {
104
-                return Str::startsWith('settings.addons.'.$key, $path);
105
-            }, ARRAY_FILTER_USE_KEY);
106
-            $results[$key] = $this->getSettingRows($addonFields);
102
+        foreach( $settingKeys as $key ) {
103
+            $addonFields = array_filter( $fields, function( $path ) use ($key) {
104
+                return Str::startsWith( 'settings.addons.'.$key, $path );
105
+            }, ARRAY_FILTER_USE_KEY );
106
+            $results[$key] = $this->getSettingRows( $addonFields );
107 107
         }
108
-        ksort($results);
108
+        ksort( $results );
109 109
         return [
110 110
             'settings' => $results,
111 111
         ];
@@ -115,13 +115,13 @@  discard block
 block discarded – undo
115 115
      * @param string $id
116 116
      * @return array
117 117
      */
118
-    protected function getTemplateDataForLicenses($id)
118
+    protected function getTemplateDataForLicenses( $id )
119 119
     {
120
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
121
-        ksort($fields);
120
+        $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) );
121
+        ksort( $fields );
122 122
         return [
123 123
             'context' => [
124
-                'rows' => $this->getSettingRows($fields),
124
+                'rows' => $this->getSettingRows( $fields ),
125 125
             ],
126 126
         ];
127 127
     }
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      */
132 132
     protected function getTemplateDataForTranslations()
133 133
     {
134
-        $translations = glsr(Translation::class)->renderAll();
134
+        $translations = glsr( Translation::class )->renderAll();
135 135
         $class = empty($translations)
136 136
             ? 'glsr-hidden'
137 137
             : '';
@@ -149,16 +149,16 @@  discard block
 block discarded – undo
149 149
      * @param string|array $expectedValue
150 150
      * @return bool
151 151
      */
152
-    protected function isFieldHidden($path, $expectedValue)
152
+    protected function isFieldHidden( $path, $expectedValue )
153 153
     {
154
-        $optionValue = glsr(OptionManager::class)->get(
154
+        $optionValue = glsr( OptionManager::class )->get(
155 155
             $path,
156
-            Arr::get(glsr()->defaults, $path)
156
+            Arr::get( glsr()->defaults, $path )
157 157
         );
158
-        if (is_array($expectedValue)) {
159
-            return is_array($optionValue)
160
-                ? 0 === count(array_intersect($optionValue, $expectedValue))
161
-                : !in_array($optionValue, $expectedValue);
158
+        if( is_array( $expectedValue ) ) {
159
+            return is_array( $optionValue )
160
+                ? 0 === count( array_intersect( $optionValue, $expectedValue ) )
161
+                : !in_array( $optionValue, $expectedValue );
162 162
         }
163 163
         return $optionValue != $expectedValue;
164 164
     }
@@ -166,9 +166,9 @@  discard block
 block discarded – undo
166 166
     /**
167 167
      * @return bool
168 168
      */
169
-    protected function isMultiDependency($path)
169
+    protected function isMultiDependency( $path )
170 170
     {
171
-        if (isset($this->settings[$path])) {
171
+        if( isset($this->settings[$path]) ) {
172 172
             $field = $this->settings[$path];
173 173
             return ('checkbox' == $field['type'] && !empty($field['options']))
174 174
                 || !empty($field['multiple']);
@@ -179,32 +179,32 @@  discard block
 block discarded – undo
179 179
     /**
180 180
      * @return array
181 181
      */
182
-    protected function normalize(array $field)
182
+    protected function normalize( array $field )
183 183
     {
184
-        $field = $this->normalizeDependsOn($field);
185
-        $field = $this->normalizeLabelAndLegend($field);
186
-        $field = $this->normalizeValue($field);
184
+        $field = $this->normalizeDependsOn( $field );
185
+        $field = $this->normalizeLabelAndLegend( $field );
186
+        $field = $this->normalizeValue( $field );
187 187
         return $field;
188 188
     }
189 189
 
190 190
     /**
191 191
      * @return array
192 192
      */
193
-    protected function normalizeDependsOn(array $field)
193
+    protected function normalizeDependsOn( array $field )
194 194
     {
195
-        if (!empty($field['depends_on']) && is_array($field['depends_on'])) {
195
+        if( !empty($field['depends_on']) && is_array( $field['depends_on'] ) ) {
196 196
             $isFieldHidden = false;
197 197
             $conditions = [];
198
-            foreach ($field['depends_on'] as $path => $value) {
198
+            foreach( $field['depends_on'] as $path => $value ) {
199 199
                 $conditions[] = [
200
-                    'name' => $this->getFieldNameForDependsOn($path),
200
+                    'name' => $this->getFieldNameForDependsOn( $path ),
201 201
                     'value' => $value,
202 202
                 ];
203
-                if ($this->isFieldHidden($path, $value)) {
203
+                if( $this->isFieldHidden( $path, $value ) ) {
204 204
                     $isFieldHidden = true;
205 205
                 }
206 206
             }
207
-            $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT);
207
+            $field['data-depends'] = json_encode( $conditions, JSON_HEX_APOS | JSON_HEX_QUOT );
208 208
             $field['is_hidden'] = $isFieldHidden;
209 209
         }
210 210
         return $field;
@@ -213,14 +213,14 @@  discard block
 block discarded – undo
213 213
     /**
214 214
      * @return array
215 215
      */
216
-    protected function normalizeLabelAndLegend(array $field)
216
+    protected function normalizeLabelAndLegend( array $field )
217 217
     {
218
-        if (!empty($field['label'])) {
218
+        if( !empty($field['label']) ) {
219 219
             $field['legend'] = $field['label'];
220 220
             unset($field['label']);
221 221
         } else {
222 222
             $field['is_valid'] = false;
223
-            glsr_log()->warning('Setting field is missing a label')->debug($field);
223
+            glsr_log()->warning( 'Setting field is missing a label' )->debug( $field );
224 224
         }
225 225
         return $field;
226 226
     }
@@ -228,12 +228,12 @@  discard block
 block discarded – undo
228 228
     /**
229 229
      * @return array
230 230
      */
231
-    protected function normalizeValue(array $field)
231
+    protected function normalizeValue( array $field )
232 232
     {
233
-        if (!isset($field['value'])) {
234
-            $field['value'] = glsr(OptionManager::class)->get(
233
+        if( !isset($field['value']) ) {
234
+            $field['value'] = glsr( OptionManager::class )->get(
235 235
                 $field['name'],
236
-                $this->getFieldDefault($field)
236
+                $this->getFieldDefault( $field )
237 237
             );
238 238
         }
239 239
         return $field;
@@ -242,8 +242,8 @@  discard block
 block discarded – undo
242 242
     /**
243 243
      * @return string
244 244
      */
245
-    protected function normalizeSettingPath($path)
245
+    protected function normalizeSettingPath( $path )
246 246
     {
247
-        return Str::prefix('settings.', rtrim($path, '.'));
247
+        return Str::prefix( 'settings.', rtrim( $path, '.' ) );
248 248
     }
249 249
 }
Please login to merge, or discard this patch.