Passed
Push — master ( ac4e16...62cea4 )
by Paul
04:17
created
plugin/Modules/Html/Partials/SiteReviews.php 1 patch
Spacing   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -45,13 +45,13 @@  discard block
 block discarded – undo
45 45
      * @param Reviews|null $reviews
46 46
      * @return ReviewsHtml
47 47
      */
48
-    public function build(array $args = [], $reviews = null)
48
+    public function build( array $args = [], $reviews = null )
49 49
     {
50
-        $this->args = glsr(SiteReviewsDefaults::class)->merge($args);
51
-        $this->options = Arr::flattenArray(glsr(OptionManager::class)->all());
50
+        $this->args = glsr( SiteReviewsDefaults::class )->merge( $args );
51
+        $this->options = Arr::flattenArray( glsr( OptionManager::class )->all() );
52 52
         $this->reviews = $reviews instanceof Reviews
53 53
             ? $reviews
54
-            : glsr(ReviewManager::class)->get($this->args);
54
+            : glsr( ReviewManager::class )->get( $this->args );
55 55
         $this->generateSchema();
56 56
         return $this->buildReviews();
57 57
     }
@@ -59,26 +59,26 @@  discard block
 block discarded – undo
59 59
     /**
60 60
      * @return ReviewHtml
61 61
      */
62
-    public function buildReview(Review $review)
62
+    public function buildReview( Review $review )
63 63
     {
64
-        $review = apply_filters('site-reviews/review/build/before', $review);
64
+        $review = apply_filters( 'site-reviews/review/build/before', $review );
65 65
         $this->current = $review;
66 66
         $renderedFields = [];
67
-        foreach ($review as $key => $value) {
68
-            $method = Helper::buildMethodName($key, 'buildOption');
69
-            $field = method_exists($this, $method)
70
-                ? $this->$method($key, $value)
67
+        foreach( $review as $key => $value ) {
68
+            $method = Helper::buildMethodName( $key, 'buildOption' );
69
+            $field = method_exists( $this, $method )
70
+                ? $this->$method( $key, $value )
71 71
                 : false;
72
-            $field = apply_filters('site-reviews/review/build/'.$key, $field, $value, $review, $this);
73
-            if (false === $field) {
72
+            $field = apply_filters( 'site-reviews/review/build/'.$key, $field, $value, $review, $this );
73
+            if( false === $field ) {
74 74
                 continue;
75 75
             }
76 76
             $renderedFields[$key] = $field;
77 77
         }
78
-        $this->wrap($renderedFields, $review);
79
-        $renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review, $this);
78
+        $this->wrap( $renderedFields, $review );
79
+        $renderedFields = apply_filters( 'site-reviews/review/build/after', $renderedFields, $review, $this );
80 80
         $this->current = null;
81
-        return new ReviewHtml($review, (array) $renderedFields);
81
+        return new ReviewHtml( $review, (array)$renderedFields );
82 82
     }
83 83
 
84 84
     /**
@@ -87,10 +87,10 @@  discard block
 block discarded – undo
87 87
     public function buildReviews()
88 88
     {
89 89
         $renderedReviews = [];
90
-        foreach ($this->reviews as $index => $review) {
91
-            $renderedReviews[] = $this->buildReview($review);
90
+        foreach( $this->reviews as $index => $review ) {
91
+            $renderedReviews[] = $this->buildReview( $review );
92 92
         }
93
-        return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args);
93
+        return new ReviewsHtml( $renderedReviews, $this->reviews->max_num_pages, $this->args );
94 94
     }
95 95
 
96 96
     /**
@@ -98,11 +98,11 @@  discard block
 block discarded – undo
98 98
      */
99 99
     public function generateSchema()
100 100
     {
101
-        if (!wp_validate_boolean($this->args['schema'])) {
101
+        if( !wp_validate_boolean( $this->args['schema'] ) ) {
102 102
             return;
103 103
         }
104
-        glsr(Schema::class)->store(
105
-            glsr(Schema::class)->build($this->args)
104
+        glsr( Schema::class )->store(
105
+            glsr( Schema::class )->build( $this->args )
106 106
         );
107 107
     }
108 108
 
@@ -110,20 +110,20 @@  discard block
 block discarded – undo
110 110
      * @param string $text
111 111
      * @return string
112 112
      */
113
-    public function getExcerpt($text)
113
+    public function getExcerpt( $text )
114 114
     {
115
-        $limit = intval($this->getOption('settings.reviews.excerpts_length', 55));
116
-        $split = extension_loaded('intl')
117
-            ? $this->getExcerptIntlSplit($text, $limit)
118
-            : $this->getExcerptSplit($text, $limit);
119
-        $hiddenText = substr($text, $split);
120
-        if (!empty($hiddenText)) {
121
-            $showMore = glsr(Builder::class)->span($hiddenText, [
115
+        $limit = intval( $this->getOption( 'settings.reviews.excerpts_length', 55 ) );
116
+        $split = extension_loaded( 'intl' )
117
+            ? $this->getExcerptIntlSplit( $text, $limit )
118
+            : $this->getExcerptSplit( $text, $limit );
119
+        $hiddenText = substr( $text, $split );
120
+        if( !empty($hiddenText) ) {
121
+            $showMore = glsr( Builder::class )->span( $hiddenText, [
122 122
                 'class' => 'glsr-hidden glsr-hidden-text',
123
-                'data-show-less' => __('Show less', 'site-reviews'),
124
-                'data-show-more' => __('Show more', 'site-reviews'),
125
-            ]);
126
-            $text = ltrim(substr($text, 0, $split)).$showMore;
123
+                'data-show-less' => __( 'Show less', 'site-reviews' ),
124
+                'data-show-more' => __( 'Show more', 'site-reviews' ),
125
+            ] );
126
+            $text = ltrim( substr( $text, 0, $split ) ).$showMore;
127 127
         }
128 128
         return $text;
129 129
     }
@@ -133,12 +133,12 @@  discard block
 block discarded – undo
133 133
      * @param string $path
134 134
      * @return bool
135 135
      */
136
-    public function isHidden($key, $path = '')
136
+    public function isHidden( $key, $path = '' )
137 137
     {
138 138
         $isOptionEnabled = !empty($path)
139
-            ? $this->isOptionEnabled($path)
139
+            ? $this->isOptionEnabled( $path )
140 140
             : true;
141
-        return in_array($key, $this->args['hide']) || !$isOptionEnabled;
141
+        return in_array( $key, $this->args['hide'] ) || !$isOptionEnabled;
142 142
     }
143 143
 
144 144
     /**
@@ -146,25 +146,25 @@  discard block
 block discarded – undo
146 146
      * @param string $value
147 147
      * @return bool
148 148
      */
149
-    public function isHiddenOrEmpty($key, $value)
149
+    public function isHiddenOrEmpty( $key, $value )
150 150
     {
151
-        return $this->isHidden($key) || empty($value);
151
+        return $this->isHidden( $key ) || empty($value);
152 152
     }
153 153
 
154 154
     /**
155 155
      * @param string $text
156 156
      * @return string
157 157
      */
158
-    public function normalizeText($text)
158
+    public function normalizeText( $text )
159 159
     {
160
-        $text = wp_kses($text, wp_kses_allowed_html());
161
-        $text = convert_smilies(strip_shortcodes($text));
162
-        $text = str_replace(']]>', ']]>', $text);
163
-        $text = preg_replace('/(\R){2,}/', '$1', $text);
164
-        if ($this->isOptionEnabled('settings.reviews.excerpts')) {
165
-            $text = $this->getExcerpt($text);
160
+        $text = wp_kses( $text, wp_kses_allowed_html() );
161
+        $text = convert_smilies( strip_shortcodes( $text ) );
162
+        $text = str_replace( ']]>', ']]>', $text );
163
+        $text = preg_replace( '/(\R){2,}/', '$1', $text );
164
+        if( $this->isOptionEnabled( 'settings.reviews.excerpts' ) ) {
165
+            $text = $this->getExcerpt( $text );
166 166
         }
167
-        return wptexturize(nl2br($text));
167
+        return wptexturize( nl2br( $text ) );
168 168
     }
169 169
 
170 170
     /**
@@ -172,19 +172,19 @@  discard block
 block discarded – undo
172 172
      * @param string $value
173 173
      * @return void|string
174 174
      */
175
-    protected function buildOptionAssignedTo($key, $value)
175
+    protected function buildOptionAssignedTo( $key, $value )
176 176
     {
177
-        if ($this->isHidden($key, 'settings.reviews.assigned_links')) {
177
+        if( $this->isHidden( $key, 'settings.reviews.assigned_links' ) ) {
178 178
             return;
179 179
         }
180
-        $post = glsr(Multilingual::class)->getPost($value);
181
-        if (!($post instanceof WP_Post)) {
180
+        $post = glsr( Multilingual::class )->getPost( $value );
181
+        if( !($post instanceof WP_Post) ) {
182 182
             return;
183 183
         }
184
-        $permalink = glsr(Builder::class)->a(get_the_title($post->ID), [
185
-            'href' => get_the_permalink($post->ID),
186
-        ]);
187
-        $assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink);
184
+        $permalink = glsr( Builder::class )->a( get_the_title( $post->ID ), [
185
+            'href' => get_the_permalink( $post->ID ),
186
+        ] );
187
+        $assignedTo = sprintf( __( 'Review of %s', 'site-reviews' ), $permalink );
188 188
         return '<span>'.$assignedTo.'</span>';
189 189
     }
190 190
 
@@ -193,13 +193,13 @@  discard block
 block discarded – undo
193 193
      * @param string $value
194 194
      * @return void|string
195 195
      */
196
-    protected function buildOptionAuthor($key, $value)
196
+    protected function buildOptionAuthor( $key, $value )
197 197
     {
198
-        if (!$this->isHidden($key)) {
198
+        if( !$this->isHidden( $key ) ) {
199 199
             $name = Str::convertName(
200 200
                 $value,
201
-                glsr_get_option('reviews.name.format'),
202
-                glsr_get_option('reviews.name.initial')
201
+                glsr_get_option( 'reviews.name.format' ),
202
+                glsr_get_option( 'reviews.name.initial' )
203 203
             );
204 204
             return '<span>'.$name.'</span>';
205 205
         }
@@ -210,18 +210,18 @@  discard block
 block discarded – undo
210 210
      * @param string $value
211 211
      * @return void|string
212 212
      */
213
-    protected function buildOptionAvatar($key, $value)
213
+    protected function buildOptionAvatar( $key, $value )
214 214
     {
215
-        if ($this->isHidden($key, 'settings.reviews.avatars')) {
215
+        if( $this->isHidden( $key, 'settings.reviews.avatars' ) ) {
216 216
             return;
217 217
         }
218
-        $size = $this->getOption('settings.reviews.avatars_size', 40);
219
-        return glsr(Builder::class)->img([
218
+        $size = $this->getOption( 'settings.reviews.avatars_size', 40 );
219
+        return glsr( Builder::class )->img( [
220 220
             'height' => $size,
221
-            'src' => $this->generateAvatar($value),
222
-            'style' => sprintf('width:%1$spx; height:%1$spx;', $size),
221
+            'src' => $this->generateAvatar( $value ),
222
+            'style' => sprintf( 'width:%1$spx; height:%1$spx;', $size ),
223 223
             'width' => $size,
224
-        ]);
224
+        ] );
225 225
     }
226 226
 
227 227
     /**
@@ -229,10 +229,10 @@  discard block
 block discarded – undo
229 229
      * @param string $value
230 230
      * @return void|string
231 231
      */
232
-    protected function buildOptionContent($key, $value)
232
+    protected function buildOptionContent( $key, $value )
233 233
     {
234
-        $text = $this->normalizeText($value);
235
-        if (!$this->isHiddenOrEmpty($key, $text)) {
234
+        $text = $this->normalizeText( $value );
235
+        if( !$this->isHiddenOrEmpty( $key, $text ) ) {
236 236
             return '<p>'.$text.'</p>';
237 237
         }
238 238
     }
@@ -242,19 +242,19 @@  discard block
 block discarded – undo
242 242
      * @param string $value
243 243
      * @return void|string
244 244
      */
245
-    protected function buildOptionDate($key, $value)
245
+    protected function buildOptionDate( $key, $value )
246 246
     {
247
-        if ($this->isHidden($key)) {
247
+        if( $this->isHidden( $key ) ) {
248 248
             return;
249 249
         }
250
-        $dateFormat = $this->getOption('settings.reviews.date.format', 'default');
251
-        if ('relative' == $dateFormat) {
252
-            $date = glsr(Date::class)->relative($value);
250
+        $dateFormat = $this->getOption( 'settings.reviews.date.format', 'default' );
251
+        if( 'relative' == $dateFormat ) {
252
+            $date = glsr( Date::class )->relative( $value );
253 253
         } else {
254 254
             $format = 'custom' == $dateFormat
255
-                ? $this->getOption('settings.reviews.date.custom', 'M j, Y')
256
-                : glsr(OptionManager::class)->getWP('date_format', 'F j, Y');
257
-            $date = date_i18n($format, strtotime($value));
255
+                ? $this->getOption( 'settings.reviews.date.custom', 'M j, Y' )
256
+                : glsr( OptionManager::class )->getWP( 'date_format', 'F j, Y' );
257
+            $date = date_i18n( $format, strtotime( $value ) );
258 258
         }
259 259
         return '<span>'.$date.'</span>';
260 260
     }
@@ -264,10 +264,10 @@  discard block
 block discarded – undo
264 264
      * @param string $value
265 265
      * @return void|string
266 266
      */
267
-    protected function buildOptionRating($key, $value)
267
+    protected function buildOptionRating( $key, $value )
268 268
     {
269
-        if (!$this->isHiddenOrEmpty($key, $value)) {
270
-            return glsr_star_rating($value);
269
+        if( !$this->isHiddenOrEmpty( $key, $value ) ) {
270
+            return glsr_star_rating( $value );
271 271
         }
272 272
     }
273 273
 
@@ -276,16 +276,16 @@  discard block
 block discarded – undo
276 276
      * @param string $value
277 277
      * @return void|string
278 278
      */
279
-    protected function buildOptionResponse($key, $value)
279
+    protected function buildOptionResponse( $key, $value )
280 280
     {
281
-        if ($this->isHiddenOrEmpty($key, $value)) {
281
+        if( $this->isHiddenOrEmpty( $key, $value ) ) {
282 282
             return;
283 283
         }
284
-        $title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name'));
285
-        $text = $this->normalizeText($value);
284
+        $title = sprintf( __( 'Response from %s', 'site-reviews' ), get_bloginfo( 'name' ) );
285
+        $text = $this->normalizeText( $value );
286 286
         $text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>';
287
-        $response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']);
288
-        $background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']);
287
+        $response = glsr( Builder::class )->div( $text, ['class' => 'glsr-review-response-inner'] );
288
+        $background = glsr( Builder::class )->div( ['class' => 'glsr-review-response-background'] );
289 289
         return $response.$background;
290 290
     }
291 291
 
@@ -294,13 +294,13 @@  discard block
 block discarded – undo
294 294
      * @param string $value
295 295
      * @return void|string
296 296
      */
297
-    protected function buildOptionTitle($key, $value)
297
+    protected function buildOptionTitle( $key, $value )
298 298
     {
299
-        if ($this->isHidden($key)) {
299
+        if( $this->isHidden( $key ) ) {
300 300
             return;
301 301
         }
302
-        if (empty($value)) {
303
-            $value = __('No Title', 'site-reviews');
302
+        if( empty($value) ) {
303
+            $value = __( 'No Title', 'site-reviews' );
304 304
         }
305 305
         return '<h3>'.$value.'</h3>';
306 306
     }
@@ -309,16 +309,16 @@  discard block
 block discarded – undo
309 309
      * @param string $avatarUrl
310 310
      * @return string
311 311
      */
312
-    protected function generateAvatar($avatarUrl)
312
+    protected function generateAvatar( $avatarUrl )
313 313
     {
314
-        if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) {
314
+        if( !$this->isOptionEnabled( 'settings.reviews.avatars_regenerate' ) || 'local' != $this->current->review_type ) {
315 315
             return $avatarUrl;
316 316
         }
317
-        $authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id);
318
-        if (empty($authorIdOrEmail)) {
317
+        $authorIdOrEmail = get_the_author_meta( 'ID', $this->current->user_id );
318
+        if( empty($authorIdOrEmail) ) {
319 319
             $authorIdOrEmail = $this->current->email;
320 320
         }
321
-        if ($newAvatar = get_avatar_url($authorIdOrEmail)) {
321
+        if( $newAvatar = get_avatar_url( $authorIdOrEmail ) ) {
322 322
             return $newAvatar;
323 323
         }
324 324
         return $avatarUrl;
@@ -329,22 +329,22 @@  discard block
 block discarded – undo
329 329
      * @param int $limit
330 330
      * @return int
331 331
      */
332
-    protected function getExcerptIntlSplit($text, $limit)
332
+    protected function getExcerptIntlSplit( $text, $limit )
333 333
     {
334
-        $words = IntlRuleBasedBreakIterator::createWordInstance('');
335
-        $words->setText($text);
334
+        $words = IntlRuleBasedBreakIterator::createWordInstance( '' );
335
+        $words->setText( $text );
336 336
         $count = 0;
337
-        foreach ($words as $offset) {
338
-            if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) {
337
+        foreach( $words as $offset ) {
338
+            if( IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus() ) {
339 339
                 continue;
340 340
             }
341 341
             ++$count;
342
-            if ($count != $limit) {
342
+            if( $count != $limit ) {
343 343
                 continue;
344 344
             }
345 345
             return $offset;
346 346
         }
347
-        return strlen($text);
347
+        return strlen( $text );
348 348
     }
349 349
 
350 350
     /**
@@ -352,13 +352,13 @@  discard block
 block discarded – undo
352 352
      * @param int $limit
353 353
      * @return int
354 354
      */
355
-    protected function getExcerptSplit($text, $limit)
355
+    protected function getExcerptSplit( $text, $limit )
356 356
     {
357
-        if (str_word_count($text, 0) > $limit) {
358
-            $words = array_keys(str_word_count($text, 2));
357
+        if( str_word_count( $text, 0 ) > $limit ) {
358
+            $words = array_keys( str_word_count( $text, 2 ) );
359 359
             return $words[$limit];
360 360
         }
361
-        return strlen($text);
361
+        return strlen( $text );
362 362
     }
363 363
 
364 364
     /**
@@ -366,9 +366,9 @@  discard block
 block discarded – undo
366 366
      * @param mixed $fallback
367 367
      * @return mixed
368 368
      */
369
-    protected function getOption($path, $fallback = '')
369
+    protected function getOption( $path, $fallback = '' )
370 370
     {
371
-        if (array_key_exists($path, $this->options)) {
371
+        if( array_key_exists( $path, $this->options ) ) {
372 372
             return $this->options[$path];
373 373
         }
374 374
         return $fallback;
@@ -378,25 +378,25 @@  discard block
 block discarded – undo
378 378
      * @param string $path
379 379
      * @return bool
380 380
      */
381
-    protected function isOptionEnabled($path)
381
+    protected function isOptionEnabled( $path )
382 382
     {
383
-        return 'yes' == $this->getOption($path);
383
+        return 'yes' == $this->getOption( $path );
384 384
     }
385 385
 
386 386
     /**
387 387
      * @return void
388 388
      */
389
-    protected function wrap(array &$renderedFields, Review $review)
389
+    protected function wrap( array &$renderedFields, Review $review )
390 390
     {
391
-        $renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review, $this);
392
-        array_walk($renderedFields, function (&$value, $key) use ($review) {
393
-            $value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review);
394
-            if (empty($value)) {
391
+        $renderedFields = apply_filters( 'site-reviews/review/wrap', $renderedFields, $review, $this );
392
+        array_walk( $renderedFields, function( &$value, $key ) use ($review) {
393
+            $value = apply_filters( 'site-reviews/review/wrap/'.$key, $value, $review );
394
+            if( empty($value) ) {
395 395
                 return;
396 396
             }
397
-            $value = glsr(Builder::class)->div($value, [
397
+            $value = glsr( Builder::class )->div( $value, [
398 398
                 'class' => 'glsr-review-'.$key,
399
-            ]);
399
+            ] );
400 400
         });
401 401
     }
402 402
 }
Please login to merge, or discard this patch.
plugin/Database/QueryBuilder.php 1 patch
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -16,19 +16,19 @@  discard block
 block discarded – undo
16 16
      * Build a WP_Query meta_query/tax_query.
17 17
      * @return array
18 18
      */
19
-    public function buildQuery(array $keys = [], array $values = [])
19
+    public function buildQuery( array $keys = [], array $values = [] )
20 20
     {
21 21
         $queries = [];
22
-        foreach ($keys as $key) {
23
-            if (!array_key_exists($key, $values)) {
22
+        foreach( $keys as $key ) {
23
+            if( !array_key_exists( $key, $values ) ) {
24 24
                 continue;
25 25
             }
26
-            $methodName = Helper::buildMethodName($key, __FUNCTION__);
27
-            if (!method_exists($this, $methodName)) {
26
+            $methodName = Helper::buildMethodName( $key, __FUNCTION__ );
27
+            if( !method_exists( $this, $methodName ) ) {
28 28
                 continue;
29 29
             }
30
-            $query = call_user_func([$this, $methodName], $values[$key]);
31
-            if (is_array($query)) {
30
+            $query = call_user_func( [$this, $methodName], $values[$key] );
31
+            if( is_array( $query ) ) {
32 32
                 $queries[] = $query;
33 33
             }
34 34
         }
@@ -38,17 +38,17 @@  discard block
 block discarded – undo
38 38
     /**
39 39
      * @return string
40 40
      */
41
-    public function buildSqlLines(array $values, array $conditions)
41
+    public function buildSqlLines( array $values, array $conditions )
42 42
     {
43 43
         $string = '';
44
-        $values = array_filter($values);
45
-        foreach ($conditions as $key => $value) {
46
-            if (!isset($values[$key])) {
44
+        $values = array_filter( $values );
45
+        foreach( $conditions as $key => $value ) {
46
+            if( !isset($values[$key]) ) {
47 47
                 continue;
48 48
             }
49
-            $values[$key] = implode(',', (array) $values[$key]);
50
-            $string.= Str::contains($value, '%s')
51
-                ? sprintf($value, strval($values[$key]))
49
+            $values[$key] = implode( ',', (array)$values[$key] );
50
+            $string .= Str::contains( $value, '%s' )
51
+                ? sprintf( $value, strval( $values[$key] ) )
52 52
                 : $value;
53 53
         }
54 54
         return $string;
@@ -60,16 +60,16 @@  discard block
 block discarded – undo
60 60
      * @param string $sprintfFormat
61 61
      * @return string
62 62
      */
63
-    public function buildSqlOr($values, $sprintfFormat)
63
+    public function buildSqlOr( $values, $sprintfFormat )
64 64
     {
65
-        if (!is_array($values)) {
66
-            $values = explode(',', $values);
65
+        if( !is_array( $values ) ) {
66
+            $values = explode( ',', $values );
67 67
         }
68
-        $values = array_filter(array_map('trim', (array) $values));
69
-        $values = array_map(function ($value) use ($sprintfFormat) {
70
-            return sprintf($sprintfFormat, $value);
71
-        }, $values);
72
-        return implode(' OR ', $values);
68
+        $values = array_filter( array_map( 'trim', (array)$values ) );
69
+        $values = array_map( function( $value ) use ($sprintfFormat) {
70
+            return sprintf( $sprintfFormat, $value );
71
+        }, $values );
72
+        return implode( ' OR ', $values );
73 73
     }
74 74
 
75 75
     /**
@@ -79,23 +79,23 @@  discard block
 block discarded – undo
79 79
      * @return string
80 80
      * @filter posts_search
81 81
      */
82
-    public function filterSearchByTitle($search, WP_Query $query)
82
+    public function filterSearchByTitle( $search, WP_Query $query )
83 83
     {
84
-        if (empty($search) || empty($query->get('search_terms'))) {
84
+        if( empty($search) || empty($query->get( 'search_terms' )) ) {
85 85
             return $search;
86 86
         }
87 87
         global $wpdb;
88
-        $n = empty($query->get('exact'))
88
+        $n = empty($query->get( 'exact' ))
89 89
             ? '%'
90 90
             : '';
91 91
         $search = [];
92
-        foreach ((array) $query->get('search_terms') as $term) {
93
-            $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n);
92
+        foreach( (array)$query->get( 'search_terms' ) as $term ) {
93
+            $search[] = $wpdb->prepare( "{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like( $term ).$n );
94 94
         }
95
-        if (!is_user_logged_in()) {
95
+        if( !is_user_logged_in() ) {
96 96
             $search[] = "{$wpdb->posts}.post_password = ''";
97 97
         }
98
-        return ' AND '.implode(' AND ', $search);
98
+        return ' AND '.implode( ' AND ', $search );
99 99
     }
100 100
 
101 101
     /**
@@ -103,10 +103,10 @@  discard block
 block discarded – undo
103 103
      * @param bool $isEnabled
104 104
      * @return int
105 105
      */
106
-    public function getPaged($isEnabled = true)
106
+    public function getPaged( $isEnabled = true )
107 107
     {
108 108
         return $isEnabled
109
-            ? max(1, intval(filter_input(INPUT_GET, glsr()->constant('PAGED_QUERY_VAR'))))
109
+            ? max( 1, intval( filter_input( INPUT_GET, glsr()->constant( 'PAGED_QUERY_VAR' ) ) ) )
110 110
             : 1;
111 111
     }
112 112
 
@@ -114,14 +114,14 @@  discard block
 block discarded – undo
114 114
      * @param string $value
115 115
      * @return void|array
116 116
      */
117
-    protected function buildQueryAssignedTo($value)
117
+    protected function buildQueryAssignedTo( $value )
118 118
     {
119
-        if (!empty($value)) {
120
-            $postIds = Arr::convertStringToArray($value, 'is_numeric');
119
+        if( !empty($value) ) {
120
+            $postIds = Arr::convertStringToArray( $value, 'is_numeric' );
121 121
             return [
122 122
                 'compare' => 'IN',
123 123
                 'key' => '_assigned_to',
124
-                'value' => glsr(Multilingual::class)->getPostIds($postIds),
124
+                'value' => glsr( Multilingual::class )->getPostIds( $postIds ),
125 125
             ];
126 126
         }
127 127
     }
@@ -130,9 +130,9 @@  discard block
 block discarded – undo
130 130
      * @param array $value
131 131
      * @return void|array
132 132
      */
133
-    protected function buildQueryCategory($value)
133
+    protected function buildQueryCategory( $value )
134 134
     {
135
-        if (!empty($value)) {
135
+        if( !empty($value) ) {
136 136
             return [
137 137
                 'field' => 'term_id',
138 138
                 'taxonomy' => Application::TAXONOMY,
@@ -145,9 +145,9 @@  discard block
 block discarded – undo
145 145
      * @param string $value
146 146
      * @return void|array
147 147
      */
148
-    protected function buildQueryEmail($value)
148
+    protected function buildQueryEmail( $value )
149 149
     {
150
-        if (!empty($value)) {
150
+        if( !empty($value) ) {
151 151
             return [
152 152
                 'key' => '_email',
153 153
                 'value' => $value,
@@ -159,9 +159,9 @@  discard block
 block discarded – undo
159 159
      * @param string $value
160 160
      * @return void|array
161 161
      */
162
-    protected function buildQueryIpAddress($value)
162
+    protected function buildQueryIpAddress( $value )
163 163
     {
164
-        if (!empty($value)) {
164
+        if( !empty($value) ) {
165 165
             return [
166 166
                 'key' => '_ip_address',
167 167
                 'value' => $value,
@@ -173,10 +173,10 @@  discard block
 block discarded – undo
173 173
      * @param string $value
174 174
      * @return void|array
175 175
      */
176
-    protected function buildQueryRating($value)
176
+    protected function buildQueryRating( $value )
177 177
     {
178
-        if (is_numeric($value)
179
-            && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) {
178
+        if( is_numeric( $value )
179
+            && in_array( intval( $value ), range( 1, glsr()->constant( 'MAX_RATING', Rating::class ) ) ) ) {
180 180
             return [
181 181
                 'compare' => '>=',
182 182
                 'key' => '_rating',
@@ -189,9 +189,9 @@  discard block
 block discarded – undo
189 189
      * @param string $value
190 190
      * @return void|array
191 191
      */
192
-    protected function buildQueryType($value)
192
+    protected function buildQueryType( $value )
193 193
     {
194
-        if (!in_array($value, ['', 'all'])) {
194
+        if( !in_array( $value, ['', 'all'] ) ) {
195 195
             return [
196 196
                 'key' => '_review_type',
197 197
                 'value' => $value,
Please login to merge, or discard this patch.
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(Multilingual::class)->getPostIds($args['post_ids']);
366
-        $args['type'] = $this->normalizeType($args['type']);
364
+        ] );
365
+        $args['post_ids'] = glsr( Multilingual::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/Modules/Multilingual/Wpml.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -13,44 +13,44 @@  discard block
 block discarded – undo
13 13
     /**
14 14
      * {@inheritdoc}
15 15
      */
16
-    public function getPost($postId)
16
+    public function getPost( $postId )
17 17
     {
18
-        $postId = trim($postId);
19
-        if (!is_numeric($postId)) {
18
+        $postId = trim( $postId );
19
+        if( !is_numeric( $postId ) ) {
20 20
             return;
21 21
         }
22
-        if ($this->isEnabled()) {
23
-            $postId = apply_filters('wpml_object_id', $postId, 'any', true);
22
+        if( $this->isEnabled() ) {
23
+            $postId = apply_filters( 'wpml_object_id', $postId, 'any', true );
24 24
         }
25
-        return get_post(intval($postId));
25
+        return get_post( intval( $postId ) );
26 26
     }
27 27
 
28 28
     /**
29 29
      * {@inheritdoc}
30 30
      */
31
-    public function getPostIds(array $postIds)
31
+    public function getPostIds( array $postIds )
32 32
     {
33
-        if (!$this->isEnabled()) {
33
+        if( !$this->isEnabled() ) {
34 34
             return $postIds;
35 35
         }
36 36
         $newPostIds = [];
37
-        foreach ($this->cleanIds($postIds) as $postId) {
38
-            $postType = get_post_type($postId);
39
-            if (!$postType) {
37
+        foreach( $this->cleanIds( $postIds ) as $postId ) {
38
+            $postType = get_post_type( $postId );
39
+            if( !$postType ) {
40 40
                 continue;
41 41
             }
42 42
             $elementType = 'post_'.$postType;
43
-            $trid = apply_filters('wpml_element_trid', null, $postId, $elementType);
44
-            $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType);
45
-            if (!is_array($translations)) {
43
+            $trid = apply_filters( 'wpml_element_trid', null, $postId, $elementType );
44
+            $translations = apply_filters( 'wpml_get_element_translations', null, $trid, $elementType );
45
+            if( !is_array( $translations ) ) {
46 46
                 $translations = [];
47 47
             }
48 48
             $newPostIds = array_merge(
49 49
                 $newPostIds,
50
-                array_column($translations, 'element_id')
50
+                array_column( $translations, 'element_id' )
51 51
             );
52 52
         }
53
-        return $this->cleanIds($newPostIds);
53
+        return $this->cleanIds( $newPostIds );
54 54
     }
55 55
 
56 56
     /**
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
      */
59 59
     public function isActive()
60 60
     {
61
-        return defined('ICL_SITEPRESS_VERSION');
61
+        return defined( 'ICL_SITEPRESS_VERSION' );
62 62
     }
63 63
 
64 64
     /**
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
     public function isEnabled()
68 68
     {
69 69
         return $this->isActive()
70
-            && 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual');
70
+            && 'wpml' == glsr( OptionManager::class )->get( 'settings.general.multilingual' );
71 71
     }
72 72
 
73 73
     /**
@@ -76,14 +76,14 @@  discard block
 block discarded – undo
76 76
     public function isSupported()
77 77
     {
78 78
         return $this->isActive()
79
-            && version_compare(ICL_SITEPRESS_VERSION, $this->supportedVersion, '>=');
79
+            && version_compare( ICL_SITEPRESS_VERSION, $this->supportedVersion, '>=' );
80 80
     }
81 81
 
82 82
     /**
83 83
      * @return array
84 84
      */
85
-    protected function cleanIds(array $postIds)
85
+    protected function cleanIds( array $postIds )
86 86
     {
87
-        return array_filter(array_unique($postIds));
87
+        return array_filter( array_unique( $postIds ) );
88 88
     }
89 89
 }
Please login to merge, or discard this patch.
plugin/Modules/Multilingual/Polylang.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -13,37 +13,37 @@  discard block
 block discarded – undo
13 13
     /**
14 14
      * {@inheritdoc}
15 15
      */
16
-    public function getPost($postId)
16
+    public function getPost( $postId )
17 17
     {
18
-        $postId = trim($postId);
19
-        if (!is_numeric($postId)) {
18
+        $postId = trim( $postId );
19
+        if( !is_numeric( $postId ) ) {
20 20
             return;
21 21
         }
22
-        if ($this->isEnabled()) {
23
-            $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID()));
22
+        if( $this->isEnabled() ) {
23
+            $polylangPostId = pll_get_post( $postId, pll_get_post_language( get_the_ID() ) );
24 24
         }
25
-        if (!empty($polylangPostId)) {
25
+        if( !empty($polylangPostId) ) {
26 26
             $postId = $polylangPostId;
27 27
         }
28
-        return get_post(intval($postId));
28
+        return get_post( intval( $postId ) );
29 29
     }
30 30
 
31 31
     /**
32 32
      * {@inheritdoc}
33 33
      */
34
-    public function getPostIds(array $postIds)
34
+    public function getPostIds( array $postIds )
35 35
     {
36
-        if (!$this->isEnabled()) {
36
+        if( !$this->isEnabled() ) {
37 37
             return $postIds;
38 38
         }
39 39
         $newPostIds = [];
40
-        foreach ($this->cleanIds($postIds) as $postId) {
40
+        foreach( $this->cleanIds( $postIds ) as $postId ) {
41 41
             $newPostIds = array_merge(
42 42
                 $newPostIds,
43
-                array_values(pll_get_post_translations($postId))
43
+                array_values( pll_get_post_translations( $postId ) )
44 44
             );
45 45
         }
46
-        return $this->cleanIds($newPostIds);
46
+        return $this->cleanIds( $newPostIds );
47 47
     }
48 48
 
49 49
     /**
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
      */
52 52
     public function isActive()
53 53
     {
54
-        return function_exists('PLL')
55
-            && function_exists('pll_get_post')
56
-            && function_exists('pll_get_post_language')
57
-            && function_exists('pll_get_post_translations');
54
+        return function_exists( 'PLL' )
55
+            && function_exists( 'pll_get_post' )
56
+            && function_exists( 'pll_get_post_language' )
57
+            && function_exists( 'pll_get_post_translations' );
58 58
     }
59 59
 
60 60
     /**
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
     public function isEnabled()
64 64
     {
65 65
         return $this->isActive()
66
-            && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual');
66
+            && 'polylang' == glsr( OptionManager::class )->get( 'settings.general.multilingual' );
67 67
     }
68 68
 
69 69
     /**
@@ -71,15 +71,15 @@  discard block
 block discarded – undo
71 71
      */
72 72
     public function isSupported()
73 73
     {
74
-        return defined('POLYLANG_VERSION')
75
-            && version_compare(POLYLANG_VERSION, $this->supportedVersion, '>=');
74
+        return defined( 'POLYLANG_VERSION' )
75
+            && version_compare( POLYLANG_VERSION, $this->supportedVersion, '>=' );
76 76
     }
77 77
 
78 78
     /**
79 79
      * @return array
80 80
      */
81
-    protected function cleanIds(array $postIds)
81
+    protected function cleanIds( array $postIds )
82 82
     {
83
-        return array_filter(array_unique($postIds));
83
+        return array_filter( array_unique( $postIds ) );
84 84
     }
85 85
 }
Please login to merge, or discard this patch.
plugin/Controllers/SettingsController.php 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -14,17 +14,17 @@  discard block
 block discarded – undo
14 14
      * @return array
15 15
      * @callback register_setting
16 16
      */
17
-    public function callbackRegisterSettings($input)
17
+    public function callbackRegisterSettings( $input )
18 18
     {
19
-        $settings = Arr::consolidateArray($input);
20
-        if (1 === count($settings) && array_key_exists('settings', $settings)) {
21
-            $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input);
22
-            $options = $this->sanitizeGeneral($input, $options);
23
-            $options = $this->sanitizeSubmissions($input, $options);
24
-            $options = $this->sanitizeTranslations($input, $options);
25
-            $options = apply_filters('site-reviews/settings/callback', $options, $settings);
26
-            if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') {
27
-                glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews'));
19
+        $settings = Arr::consolidateArray( $input );
20
+        if( 1 === count( $settings ) && array_key_exists( 'settings', $settings ) ) {
21
+            $options = array_replace_recursive( glsr( OptionManager::class )->all(), $input );
22
+            $options = $this->sanitizeGeneral( $input, $options );
23
+            $options = $this->sanitizeSubmissions( $input, $options );
24
+            $options = $this->sanitizeTranslations( $input, $options );
25
+            $options = apply_filters( 'site-reviews/settings/callback', $options, $settings );
26
+            if( filter_input( INPUT_POST, 'option_page' ) == Application::ID.'-settings' ) {
27
+                glsr( Notice::class )->addSuccess( __( 'Settings updated.', 'site-reviews' ) );
28 28
             }
29 29
             return $options;
30 30
         }
@@ -37,63 +37,63 @@  discard block
 block discarded – undo
37 37
      */
38 38
     public function registerSettings()
39 39
     {
40
-        register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [
40
+        register_setting( Application::ID.'-settings', OptionManager::databaseKey(), [
41 41
             'sanitize_callback' => [$this, 'callbackRegisterSettings'],
42
-        ]);
42
+        ] );
43 43
     }
44 44
 
45 45
     /**
46 46
      * @return array
47 47
      */
48
-    protected function sanitizeGeneral(array $input, array $options)
48
+    protected function sanitizeGeneral( array $input, array $options )
49 49
     {
50 50
         $key = 'settings.general';
51
-        $inputForm = Arr::get($input, $key);
52
-        if (!$this->hasMultilingualIntegration(Arr::get($inputForm, 'multilingual'))) {
53
-            $options = Arr::set($options, $key.'.multilingual', '');
51
+        $inputForm = Arr::get( $input, $key );
52
+        if( !$this->hasMultilingualIntegration( Arr::get( $inputForm, 'multilingual' ) ) ) {
53
+            $options = Arr::set( $options, $key.'.multilingual', '' );
54 54
         }
55
-        if ('' == trim(Arr::get($inputForm, 'notification_message'))) {
56
-            $defaultValue = Arr::get(glsr()->defaults, $key.'.notification_message');
57
-            $options = Arr::set($options, $key.'.notification_message', $defaultValue);
55
+        if( '' == trim( Arr::get( $inputForm, 'notification_message' ) ) ) {
56
+            $defaultValue = Arr::get( glsr()->defaults, $key.'.notification_message' );
57
+            $options = Arr::set( $options, $key.'.notification_message', $defaultValue );
58 58
         }
59
-        $defaultValue = Arr::get($inputForm, 'notifications', []);
60
-        $options = Arr::set($options, $key.'.notifications', $defaultValue);
59
+        $defaultValue = Arr::get( $inputForm, 'notifications', [] );
60
+        $options = Arr::set( $options, $key.'.notifications', $defaultValue );
61 61
         return $options;
62 62
     }
63 63
 
64 64
     /**
65 65
      * @return array
66 66
      */
67
-    protected function sanitizeSubmissions(array $input, array $options)
67
+    protected function sanitizeSubmissions( array $input, array $options )
68 68
     {
69 69
         $key = 'settings.submissions';
70
-        $inputForm = Arr::get($input, $key);
70
+        $inputForm = Arr::get( $input, $key );
71 71
         $defaultValue = isset($inputForm['required'])
72 72
             ? $inputForm['required']
73 73
             : [];
74
-        $options = Arr::set($options, $key.'.required', $defaultValue);
74
+        $options = Arr::set( $options, $key.'.required', $defaultValue );
75 75
         return $options;
76 76
     }
77 77
 
78 78
     /**
79 79
      * @return array
80 80
      */
81
-    protected function sanitizeTranslations(array $input, array $options)
81
+    protected function sanitizeTranslations( array $input, array $options )
82 82
     {
83 83
         $key = 'settings.strings';
84
-        $inputForm = Arr::consolidateArray(Arr::get($input, $key));
85
-        if (!empty($inputForm)) {
86
-            $options = Arr::set($options, $key, array_values(array_filter($inputForm)));
84
+        $inputForm = Arr::consolidateArray( Arr::get( $input, $key ) );
85
+        if( !empty($inputForm) ) {
86
+            $options = Arr::set( $options, $key, array_values( array_filter( $inputForm ) ) );
87 87
             $allowedTags = [
88 88
                 'a' => ['class' => [], 'href' => [], 'target' => []],
89 89
                 'span' => ['class' => []],
90 90
             ];
91
-            array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) {
92
-                if (isset($string['s2'])) {
93
-                    $string['s2'] = wp_kses($string['s2'], $allowedTags);
91
+            array_walk( $options['settings']['strings'], function( &$string ) use ($allowedTags) {
92
+                if( isset($string['s2']) ) {
93
+                    $string['s2'] = wp_kses( $string['s2'], $allowedTags );
94 94
                 }
95
-                if (isset($string['p2'])) {
96
-                    $string['p2'] = wp_kses($string['p2'], $allowedTags);
95
+                if( isset($string['p2']) ) {
96
+                    $string['p2'] = wp_kses( $string['p2'], $allowedTags );
97 97
                 }
98 98
             });
99 99
         }
@@ -104,24 +104,24 @@  discard block
 block discarded – undo
104 104
      * @param string $integrationSlug
105 105
      * @return bool
106 106
      */
107
-    protected function hasMultilingualIntegration($integrationSlug)
107
+    protected function hasMultilingualIntegration( $integrationSlug )
108 108
     {
109
-        $integration = glsr(Multilingual::class)->getIntegration($integrationSlug);
110
-        if (!$integration) {
109
+        $integration = glsr( Multilingual::class )->getIntegration( $integrationSlug );
110
+        if( !$integration ) {
111 111
             return false;
112 112
         }
113
-        if (!$integration->isActive()) {
114
-            glsr(Notice::class)->addError(sprintf(
115
-                __('Please install/activate the %s plugin to enable integration.', 'site-reviews'),
113
+        if( !$integration->isActive() ) {
114
+            glsr( Notice::class )->addError( sprintf(
115
+                __( 'Please install/activate the %s plugin to enable integration.', 'site-reviews' ),
116 116
                 $integration->pluginName
117
-            ));
117
+            ) );
118 118
             return false;
119
-        } elseif (!$integration->isSupported()) {
120
-            glsr(Notice::class)->addError(sprintf(
121
-                __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'),
119
+        } elseif( !$integration->isSupported() ) {
120
+            glsr( Notice::class )->addError( sprintf(
121
+                __( 'Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews' ),
122 122
                 $integration->pluginName,
123 123
                 $integration->supportedVersion
124
-            ));
124
+            ) );
125 125
             return false;
126 126
         }
127 127
         return true;
Please login to merge, or discard this patch.
plugin/Modules/Multilingual.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -13,36 +13,36 @@  discard block
 block discarded – undo
13 13
      * @param string $integration
14 14
      * @return false|\GeminiLabs\SiteReviews\Modules\Multilingual\Polylang|\GeminiLabs\SiteReviews\Modules\Multilingual\Wpml
15 15
      */
16
-    public function getIntegration($integration = '')
16
+    public function getIntegration( $integration = '' )
17 17
     {
18
-        if (empty($integration)) {
19
-            $integration = ucfirst(glsr(OptionManager::class)->get('settings.general.multilingual'));
18
+        if( empty($integration) ) {
19
+            $integration = ucfirst( glsr( OptionManager::class )->get( 'settings.general.multilingual' ) );
20 20
         }
21 21
         $integrationClass = 'GeminiLabs\SiteReviews\Modules\Multilingual\\'.$integration;
22
-        if (class_exists($integrationClass)) {
23
-            return glsr($integrationClass);
22
+        if( class_exists( $integrationClass ) ) {
23
+            return glsr( $integrationClass );
24 24
         }
25
-        glsr_log()->error($integrationClass.' does not exist');
25
+        glsr_log()->error( $integrationClass.' does not exist' );
26 26
         return false;
27 27
     }
28 28
 
29 29
     /**
30 30
      * {@inheritdoc}
31 31
      */
32
-    public function getPost($postId)
32
+    public function getPost( $postId )
33 33
     {
34 34
         return $this->isIntegrated()
35
-            ? $this->integration->getPostIds($postId)
35
+            ? $this->integration->getPostIds( $postId )
36 36
             : $postId;
37 37
     }
38 38
 
39 39
     /**
40 40
      * {@inheritdoc}
41 41
      */
42
-    public function getPostIds(array $postIds)
42
+    public function getPostIds( array $postIds )
43 43
     {
44 44
         return $this->isIntegrated()
45
-            ? $this->integration->getPostIds($postIds)
45
+            ? $this->integration->getPostIds( $postIds )
46 46
             : $postIds;
47 47
     }
48 48
 
@@ -81,10 +81,10 @@  discard block
 block discarded – undo
81 81
      */
82 82
     protected function isIntegrated()
83 83
     {
84
-        if (!empty($this->integration)) {
84
+        if( !empty($this->integration) ) {
85 85
             return true;
86 86
         }
87
-        if ($integration = $this->getIntegration()) {
87
+        if( $integration = $this->getIntegration() ) {
88 88
             $this->integration = $integration;
89 89
             return true;
90 90
         }
Please login to merge, or discard this patch.