Passed
Push — master ( ffa8d9...6a6a4c )
by Paul
03:54
created
plugin/Modules/Html/Partials/SiteReviews.php 2 patches
Indentation   +353 added lines, -353 removed lines patch added patch discarded remove patch
@@ -21,382 +21,382 @@
 block discarded – undo
21 21
 
22 22
 class SiteReviews
23 23
 {
24
-    /**
25
-     * @var array
26
-     */
27
-    public $args;
24
+	/**
25
+	 * @var array
26
+	 */
27
+	public $args;
28 28
 
29
-    /**
30
-     * @var Review
31
-     */
32
-    public $current;
29
+	/**
30
+	 * @var Review
31
+	 */
32
+	public $current;
33 33
 
34
-    /**
35
-     * @var array
36
-     */
37
-    public $options;
34
+	/**
35
+	 * @var array
36
+	 */
37
+	public $options;
38 38
 
39
-    /**
40
-     * @var Reviews
41
-     */
42
-    protected $reviews;
39
+	/**
40
+	 * @var Reviews
41
+	 */
42
+	protected $reviews;
43 43
 
44
-    /**
45
-     * @param Reviews|null $reviews
46
-     * @return ReviewsHtml
47
-     */
48
-    public function build(array $args = [], $reviews = null)
49
-    {
50
-        $this->args = glsr(SiteReviewsDefaults::class)->merge($args);
51
-        $this->options = Arr::flattenArray(glsr(OptionManager::class)->all());
52
-        $this->reviews = $reviews instanceof Reviews
53
-            ? $reviews
54
-            : glsr(ReviewManager::class)->get($this->args);
55
-        $this->generateSchema();
56
-        return $this->buildReviews();
57
-    }
44
+	/**
45
+	 * @param Reviews|null $reviews
46
+	 * @return ReviewsHtml
47
+	 */
48
+	public function build(array $args = [], $reviews = null)
49
+	{
50
+		$this->args = glsr(SiteReviewsDefaults::class)->merge($args);
51
+		$this->options = Arr::flattenArray(glsr(OptionManager::class)->all());
52
+		$this->reviews = $reviews instanceof Reviews
53
+			? $reviews
54
+			: glsr(ReviewManager::class)->get($this->args);
55
+		$this->generateSchema();
56
+		return $this->buildReviews();
57
+	}
58 58
 
59
-    /**
60
-     * @return ReviewHtml
61
-     */
62
-    public function buildReview(Review $review)
63
-    {
64
-        $review = apply_filters('site-reviews/review/build/before', $review);
65
-        $this->current = $review;
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)
71
-                : false;
72
-            $field = apply_filters('site-reviews/review/build/'.$key, $field, $value, $review, $this);
73
-            if (false === $field) {
74
-                continue;
75
-            }
76
-            $renderedFields[$key] = $field;
77
-        }
78
-        $this->wrap($renderedFields, $review);
79
-        $renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review, $this);
80
-        $this->current = null;
81
-        return new ReviewHtml($review, (array) $renderedFields);
82
-    }
59
+	/**
60
+	 * @return ReviewHtml
61
+	 */
62
+	public function buildReview(Review $review)
63
+	{
64
+		$review = apply_filters('site-reviews/review/build/before', $review);
65
+		$this->current = $review;
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)
71
+				: false;
72
+			$field = apply_filters('site-reviews/review/build/'.$key, $field, $value, $review, $this);
73
+			if (false === $field) {
74
+				continue;
75
+			}
76
+			$renderedFields[$key] = $field;
77
+		}
78
+		$this->wrap($renderedFields, $review);
79
+		$renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review, $this);
80
+		$this->current = null;
81
+		return new ReviewHtml($review, (array) $renderedFields);
82
+	}
83 83
 
84
-    /**
85
-     * @return ReviewsHtml
86
-     */
87
-    public function buildReviews()
88
-    {
89
-        $renderedReviews = [];
90
-        foreach ($this->reviews as $index => $review) {
91
-            $renderedReviews[] = $this->buildReview($review);
92
-        }
93
-        return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args);
94
-    }
84
+	/**
85
+	 * @return ReviewsHtml
86
+	 */
87
+	public function buildReviews()
88
+	{
89
+		$renderedReviews = [];
90
+		foreach ($this->reviews as $index => $review) {
91
+			$renderedReviews[] = $this->buildReview($review);
92
+		}
93
+		return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args);
94
+	}
95 95
 
96
-    /**
97
-     * @return void
98
-     */
99
-    public function generateSchema()
100
-    {
101
-        if (!wp_validate_boolean($this->args['schema'])) {
102
-            return;
103
-        }
104
-        glsr(Schema::class)->store(
105
-            glsr(Schema::class)->build($this->args)
106
-        );
107
-    }
96
+	/**
97
+	 * @return void
98
+	 */
99
+	public function generateSchema()
100
+	{
101
+		if (!wp_validate_boolean($this->args['schema'])) {
102
+			return;
103
+		}
104
+		glsr(Schema::class)->store(
105
+			glsr(Schema::class)->build($this->args)
106
+		);
107
+	}
108 108
 
109
-    /**
110
-     * @param string $text
111
-     * @return string
112
-     */
113
-    public function getExcerpt($text)
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, [
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;
127
-        }
128
-        return $text;
129
-    }
109
+	/**
110
+	 * @param string $text
111
+	 * @return string
112
+	 */
113
+	public function getExcerpt($text)
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, [
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;
127
+		}
128
+		return $text;
129
+	}
130 130
 
131
-    /**
132
-     * @param string $key
133
-     * @param string $path
134
-     * @return bool
135
-     */
136
-    public function isHidden($key, $path = '')
137
-    {
138
-        $isOptionEnabled = !empty($path)
139
-            ? $this->isOptionEnabled($path)
140
-            : true;
141
-        return in_array($key, $this->args['hide']) || !$isOptionEnabled;
142
-    }
131
+	/**
132
+	 * @param string $key
133
+	 * @param string $path
134
+	 * @return bool
135
+	 */
136
+	public function isHidden($key, $path = '')
137
+	{
138
+		$isOptionEnabled = !empty($path)
139
+			? $this->isOptionEnabled($path)
140
+			: true;
141
+		return in_array($key, $this->args['hide']) || !$isOptionEnabled;
142
+	}
143 143
 
144
-    /**
145
-     * @param string $key
146
-     * @param string $value
147
-     * @return bool
148
-     */
149
-    public function isHiddenOrEmpty($key, $value)
150
-    {
151
-        return $this->isHidden($key) || empty($value);
152
-    }
144
+	/**
145
+	 * @param string $key
146
+	 * @param string $value
147
+	 * @return bool
148
+	 */
149
+	public function isHiddenOrEmpty($key, $value)
150
+	{
151
+		return $this->isHidden($key) || empty($value);
152
+	}
153 153
 
154
-    /**
155
-     * @param string $text
156
-     * @return string
157
-     */
158
-    public function normalizeText($text)
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);
166
-        }
167
-        return wptexturize(nl2br($text));
168
-    }
154
+	/**
155
+	 * @param string $text
156
+	 * @return string
157
+	 */
158
+	public function normalizeText($text)
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);
166
+		}
167
+		return wptexturize(nl2br($text));
168
+	}
169 169
 
170
-    /**
171
-     * @param string $key
172
-     * @param string $value
173
-     * @return void|string
174
-     */
175
-    protected function buildOptionAssignedTo($key, $value)
176
-    {
177
-        if ($this->isHidden($key, 'settings.reviews.assigned_links')) {
178
-            return;
179
-        }
180
-        $post = glsr(Multilingual::class)->getPost($value);
181
-        if (!($post instanceof WP_Post)) {
182
-            return;
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);
188
-        return '<span>'.$assignedTo.'</span>';
189
-    }
170
+	/**
171
+	 * @param string $key
172
+	 * @param string $value
173
+	 * @return void|string
174
+	 */
175
+	protected function buildOptionAssignedTo($key, $value)
176
+	{
177
+		if ($this->isHidden($key, 'settings.reviews.assigned_links')) {
178
+			return;
179
+		}
180
+		$post = glsr(Multilingual::class)->getPost($value);
181
+		if (!($post instanceof WP_Post)) {
182
+			return;
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);
188
+		return '<span>'.$assignedTo.'</span>';
189
+	}
190 190
 
191
-    /**
192
-     * @param string $key
193
-     * @param string $value
194
-     * @return void|string
195
-     */
196
-    protected function buildOptionAuthor($key, $value)
197
-    {
198
-        if (!$this->isHidden($key)) {
199
-            $name = Str::convertName(
200
-                $value,
201
-                glsr_get_option('reviews.name.format'),
202
-                glsr_get_option('reviews.name.initial')
203
-            );
204
-            return '<span>'.$name.'</span>';
205
-        }
206
-    }
191
+	/**
192
+	 * @param string $key
193
+	 * @param string $value
194
+	 * @return void|string
195
+	 */
196
+	protected function buildOptionAuthor($key, $value)
197
+	{
198
+		if (!$this->isHidden($key)) {
199
+			$name = Str::convertName(
200
+				$value,
201
+				glsr_get_option('reviews.name.format'),
202
+				glsr_get_option('reviews.name.initial')
203
+			);
204
+			return '<span>'.$name.'</span>';
205
+		}
206
+	}
207 207
 
208
-    /**
209
-     * @param string $key
210
-     * @param string $value
211
-     * @return void|string
212
-     */
213
-    protected function buildOptionAvatar($key, $value)
214
-    {
215
-        if ($this->isHidden($key, 'settings.reviews.avatars')) {
216
-            return;
217
-        }
218
-        $size = $this->getOption('settings.reviews.avatars_size', 40);
219
-        return glsr(Builder::class)->img([
220
-            'height' => $size,
221
-            'src' => $this->generateAvatar($value),
222
-            'style' => sprintf('width:%1$spx; height:%1$spx;', $size),
223
-            'width' => $size,
224
-        ]);
225
-    }
208
+	/**
209
+	 * @param string $key
210
+	 * @param string $value
211
+	 * @return void|string
212
+	 */
213
+	protected function buildOptionAvatar($key, $value)
214
+	{
215
+		if ($this->isHidden($key, 'settings.reviews.avatars')) {
216
+			return;
217
+		}
218
+		$size = $this->getOption('settings.reviews.avatars_size', 40);
219
+		return glsr(Builder::class)->img([
220
+			'height' => $size,
221
+			'src' => $this->generateAvatar($value),
222
+			'style' => sprintf('width:%1$spx; height:%1$spx;', $size),
223
+			'width' => $size,
224
+		]);
225
+	}
226 226
 
227
-    /**
228
-     * @param string $key
229
-     * @param string $value
230
-     * @return void|string
231
-     */
232
-    protected function buildOptionContent($key, $value)
233
-    {
234
-        $text = $this->normalizeText($value);
235
-        if (!$this->isHiddenOrEmpty($key, $text)) {
236
-            return '<p>'.$text.'</p>';
237
-        }
238
-    }
227
+	/**
228
+	 * @param string $key
229
+	 * @param string $value
230
+	 * @return void|string
231
+	 */
232
+	protected function buildOptionContent($key, $value)
233
+	{
234
+		$text = $this->normalizeText($value);
235
+		if (!$this->isHiddenOrEmpty($key, $text)) {
236
+			return '<p>'.$text.'</p>';
237
+		}
238
+	}
239 239
 
240
-    /**
241
-     * @param string $key
242
-     * @param string $value
243
-     * @return void|string
244
-     */
245
-    protected function buildOptionDate($key, $value)
246
-    {
247
-        if ($this->isHidden($key)) {
248
-            return;
249
-        }
250
-        $dateFormat = $this->getOption('settings.reviews.date.format', 'default');
251
-        if ('relative' == $dateFormat) {
252
-            $date = glsr(Date::class)->relative($value);
253
-        } else {
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));
258
-        }
259
-        return '<span>'.$date.'</span>';
260
-    }
240
+	/**
241
+	 * @param string $key
242
+	 * @param string $value
243
+	 * @return void|string
244
+	 */
245
+	protected function buildOptionDate($key, $value)
246
+	{
247
+		if ($this->isHidden($key)) {
248
+			return;
249
+		}
250
+		$dateFormat = $this->getOption('settings.reviews.date.format', 'default');
251
+		if ('relative' == $dateFormat) {
252
+			$date = glsr(Date::class)->relative($value);
253
+		} else {
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));
258
+		}
259
+		return '<span>'.$date.'</span>';
260
+	}
261 261
 
262
-    /**
263
-     * @param string $key
264
-     * @param string $value
265
-     * @return void|string
266
-     */
267
-    protected function buildOptionRating($key, $value)
268
-    {
269
-        if (!$this->isHiddenOrEmpty($key, $value)) {
270
-            return glsr_star_rating($value);
271
-        }
272
-    }
262
+	/**
263
+	 * @param string $key
264
+	 * @param string $value
265
+	 * @return void|string
266
+	 */
267
+	protected function buildOptionRating($key, $value)
268
+	{
269
+		if (!$this->isHiddenOrEmpty($key, $value)) {
270
+			return glsr_star_rating($value);
271
+		}
272
+	}
273 273
 
274
-    /**
275
-     * @param string $key
276
-     * @param string $value
277
-     * @return void|string
278
-     */
279
-    protected function buildOptionResponse($key, $value)
280
-    {
281
-        if ($this->isHiddenOrEmpty($key, $value)) {
282
-            return;
283
-        }
284
-        $title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name'));
285
-        $text = $this->normalizeText($value);
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']);
289
-        return $response.$background;
290
-    }
274
+	/**
275
+	 * @param string $key
276
+	 * @param string $value
277
+	 * @return void|string
278
+	 */
279
+	protected function buildOptionResponse($key, $value)
280
+	{
281
+		if ($this->isHiddenOrEmpty($key, $value)) {
282
+			return;
283
+		}
284
+		$title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name'));
285
+		$text = $this->normalizeText($value);
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']);
289
+		return $response.$background;
290
+	}
291 291
 
292
-    /**
293
-     * @param string $key
294
-     * @param string $value
295
-     * @return void|string
296
-     */
297
-    protected function buildOptionTitle($key, $value)
298
-    {
299
-        if ($this->isHidden($key)) {
300
-            return;
301
-        }
302
-        if (empty($value)) {
303
-            $value = __('No Title', 'site-reviews');
304
-        }
305
-        return '<h3>'.$value.'</h3>';
306
-    }
292
+	/**
293
+	 * @param string $key
294
+	 * @param string $value
295
+	 * @return void|string
296
+	 */
297
+	protected function buildOptionTitle($key, $value)
298
+	{
299
+		if ($this->isHidden($key)) {
300
+			return;
301
+		}
302
+		if (empty($value)) {
303
+			$value = __('No Title', 'site-reviews');
304
+		}
305
+		return '<h3>'.$value.'</h3>';
306
+	}
307 307
 
308
-    /**
309
-     * @param string $avatarUrl
310
-     * @return string
311
-     */
312
-    protected function generateAvatar($avatarUrl)
313
-    {
314
-        if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) {
315
-            return $avatarUrl;
316
-        }
317
-        $authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id);
318
-        if (empty($authorIdOrEmail)) {
319
-            $authorIdOrEmail = $this->current->email;
320
-        }
321
-        if ($newAvatar = get_avatar_url($authorIdOrEmail)) {
322
-            return $newAvatar;
323
-        }
324
-        return $avatarUrl;
325
-    }
308
+	/**
309
+	 * @param string $avatarUrl
310
+	 * @return string
311
+	 */
312
+	protected function generateAvatar($avatarUrl)
313
+	{
314
+		if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) {
315
+			return $avatarUrl;
316
+		}
317
+		$authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id);
318
+		if (empty($authorIdOrEmail)) {
319
+			$authorIdOrEmail = $this->current->email;
320
+		}
321
+		if ($newAvatar = get_avatar_url($authorIdOrEmail)) {
322
+			return $newAvatar;
323
+		}
324
+		return $avatarUrl;
325
+	}
326 326
 
327
-    /**
328
-     * @param string $text
329
-     * @param int $limit
330
-     * @return int
331
-     */
332
-    protected function getExcerptIntlSplit($text, $limit)
333
-    {
334
-        $words = IntlRuleBasedBreakIterator::createWordInstance('');
335
-        $words->setText($text);
336
-        $count = 0;
337
-        foreach ($words as $offset) {
338
-            if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) {
339
-                continue;
340
-            }
341
-            ++$count;
342
-            if ($count != $limit) {
343
-                continue;
344
-            }
345
-            return $offset;
346
-        }
347
-        return strlen($text);
348
-    }
327
+	/**
328
+	 * @param string $text
329
+	 * @param int $limit
330
+	 * @return int
331
+	 */
332
+	protected function getExcerptIntlSplit($text, $limit)
333
+	{
334
+		$words = IntlRuleBasedBreakIterator::createWordInstance('');
335
+		$words->setText($text);
336
+		$count = 0;
337
+		foreach ($words as $offset) {
338
+			if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) {
339
+				continue;
340
+			}
341
+			++$count;
342
+			if ($count != $limit) {
343
+				continue;
344
+			}
345
+			return $offset;
346
+		}
347
+		return strlen($text);
348
+	}
349 349
 
350
-    /**
351
-     * @param string $text
352
-     * @param int $limit
353
-     * @return int
354
-     */
355
-    protected function getExcerptSplit($text, $limit)
356
-    {
357
-        if (str_word_count($text, 0) > $limit) {
358
-            $words = array_keys(str_word_count($text, 2));
359
-            return $words[$limit];
360
-        }
361
-        return strlen($text);
362
-    }
350
+	/**
351
+	 * @param string $text
352
+	 * @param int $limit
353
+	 * @return int
354
+	 */
355
+	protected function getExcerptSplit($text, $limit)
356
+	{
357
+		if (str_word_count($text, 0) > $limit) {
358
+			$words = array_keys(str_word_count($text, 2));
359
+			return $words[$limit];
360
+		}
361
+		return strlen($text);
362
+	}
363 363
 
364
-    /**
365
-     * @param string $path
366
-     * @param mixed $fallback
367
-     * @return mixed
368
-     */
369
-    protected function getOption($path, $fallback = '')
370
-    {
371
-        if (array_key_exists($path, $this->options)) {
372
-            return $this->options[$path];
373
-        }
374
-        return $fallback;
375
-    }
364
+	/**
365
+	 * @param string $path
366
+	 * @param mixed $fallback
367
+	 * @return mixed
368
+	 */
369
+	protected function getOption($path, $fallback = '')
370
+	{
371
+		if (array_key_exists($path, $this->options)) {
372
+			return $this->options[$path];
373
+		}
374
+		return $fallback;
375
+	}
376 376
 
377
-    /**
378
-     * @param string $path
379
-     * @return bool
380
-     */
381
-    protected function isOptionEnabled($path)
382
-    {
383
-        return 'yes' == $this->getOption($path);
384
-    }
377
+	/**
378
+	 * @param string $path
379
+	 * @return bool
380
+	 */
381
+	protected function isOptionEnabled($path)
382
+	{
383
+		return 'yes' == $this->getOption($path);
384
+	}
385 385
 
386
-    /**
387
-     * @return void
388
-     */
389
-    protected function wrap(array &$renderedFields, Review $review)
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)) {
395
-                return;
396
-            }
397
-            $value = glsr(Builder::class)->div($value, [
398
-                'class' => 'glsr-review-'.$key,
399
-            ]);
400
-        });
401
-    }
386
+	/**
387
+	 * @return void
388
+	 */
389
+	protected function wrap(array &$renderedFields, Review $review)
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)) {
395
+				return;
396
+			}
397
+			$value = glsr(Builder::class)->div($value, [
398
+				'class' => 'glsr-review-'.$key,
399
+			]);
400
+		});
401
+	}
402 402
 }
Please login to merge, or discard this 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(']]>', ']]&gt;', $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( ']]>', ']]&gt;', $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 2 patches
Indentation   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -12,190 +12,190 @@
 block discarded – undo
12 12
 
13 13
 class QueryBuilder
14 14
 {
15
-    /**
16
-     * Build a WP_Query meta_query/tax_query.
17
-     * @return array
18
-     */
19
-    public function buildQuery(array $keys = [], array $values = [])
20
-    {
21
-        $queries = [];
22
-        foreach ($keys as $key) {
23
-            if (!array_key_exists($key, $values)) {
24
-                continue;
25
-            }
26
-            $methodName = Helper::buildMethodName($key, __FUNCTION__);
27
-            if (!method_exists($this, $methodName)) {
28
-                continue;
29
-            }
30
-            $query = call_user_func([$this, $methodName], $values[$key]);
31
-            if (is_array($query)) {
32
-                $queries[] = $query;
33
-            }
34
-        }
35
-        return $queries;
36
-    }
15
+	/**
16
+	 * Build a WP_Query meta_query/tax_query.
17
+	 * @return array
18
+	 */
19
+	public function buildQuery(array $keys = [], array $values = [])
20
+	{
21
+		$queries = [];
22
+		foreach ($keys as $key) {
23
+			if (!array_key_exists($key, $values)) {
24
+				continue;
25
+			}
26
+			$methodName = Helper::buildMethodName($key, __FUNCTION__);
27
+			if (!method_exists($this, $methodName)) {
28
+				continue;
29
+			}
30
+			$query = call_user_func([$this, $methodName], $values[$key]);
31
+			if (is_array($query)) {
32
+				$queries[] = $query;
33
+			}
34
+		}
35
+		return $queries;
36
+	}
37 37
 
38
-    /**
39
-     * @return string
40
-     */
41
-    public function buildSqlLines(array $values, array $conditions)
42
-    {
43
-        $string = '';
44
-        $values = array_filter($values);
45
-        foreach ($conditions as $key => $value) {
46
-            if (!isset($values[$key])) {
47
-                continue;
48
-            }
49
-            $values[$key] = implode(',', (array) $values[$key]);
50
-            $string.= Str::contains($value, '%s')
51
-                ? sprintf($value, strval($values[$key]))
52
-                : $value;
53
-        }
54
-        return $string;
55
-    }
38
+	/**
39
+	 * @return string
40
+	 */
41
+	public function buildSqlLines(array $values, array $conditions)
42
+	{
43
+		$string = '';
44
+		$values = array_filter($values);
45
+		foreach ($conditions as $key => $value) {
46
+			if (!isset($values[$key])) {
47
+				continue;
48
+			}
49
+			$values[$key] = implode(',', (array) $values[$key]);
50
+			$string.= Str::contains($value, '%s')
51
+				? sprintf($value, strval($values[$key]))
52
+				: $value;
53
+		}
54
+		return $string;
55
+	}
56 56
 
57
-    /**
58
-     * Build a SQL 'OR' string from an array.
59
-     * @param string|array $values
60
-     * @param string $sprintfFormat
61
-     * @return string
62
-     */
63
-    public function buildSqlOr($values, $sprintfFormat)
64
-    {
65
-        if (!is_array($values)) {
66
-            $values = explode(',', $values);
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);
73
-    }
57
+	/**
58
+	 * Build a SQL 'OR' string from an array.
59
+	 * @param string|array $values
60
+	 * @param string $sprintfFormat
61
+	 * @return string
62
+	 */
63
+	public function buildSqlOr($values, $sprintfFormat)
64
+	{
65
+		if (!is_array($values)) {
66
+			$values = explode(',', $values);
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);
73
+	}
74 74
 
75
-    /**
76
-     * Search SQL filter for matching against post title only.
77
-     * @see http://wordpress.stackexchange.com/a/11826/1685
78
-     * @param string $search
79
-     * @return string
80
-     * @filter posts_search
81
-     */
82
-    public function filterSearchByTitle($search, WP_Query $query)
83
-    {
84
-        if (empty($search) || empty($query->get('search_terms'))) {
85
-            return $search;
86
-        }
87
-        global $wpdb;
88
-        $n = empty($query->get('exact'))
89
-            ? '%'
90
-            : '';
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);
94
-        }
95
-        if (!is_user_logged_in()) {
96
-            $search[] = "{$wpdb->posts}.post_password = ''";
97
-        }
98
-        return ' AND '.implode(' AND ', $search);
99
-    }
75
+	/**
76
+	 * Search SQL filter for matching against post title only.
77
+	 * @see http://wordpress.stackexchange.com/a/11826/1685
78
+	 * @param string $search
79
+	 * @return string
80
+	 * @filter posts_search
81
+	 */
82
+	public function filterSearchByTitle($search, WP_Query $query)
83
+	{
84
+		if (empty($search) || empty($query->get('search_terms'))) {
85
+			return $search;
86
+		}
87
+		global $wpdb;
88
+		$n = empty($query->get('exact'))
89
+			? '%'
90
+			: '';
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);
94
+		}
95
+		if (!is_user_logged_in()) {
96
+			$search[] = "{$wpdb->posts}.post_password = ''";
97
+		}
98
+		return ' AND '.implode(' AND ', $search);
99
+	}
100 100
 
101
-    /**
102
-     * Get the current page number from the global query.
103
-     * @param bool $isEnabled
104
-     * @return int
105
-     */
106
-    public function getPaged($isEnabled = true)
107
-    {
108
-        return $isEnabled
109
-            ? max(1, intval(filter_input(INPUT_GET, glsr()->constant('PAGED_QUERY_VAR'))))
110
-            : 1;
111
-    }
101
+	/**
102
+	 * Get the current page number from the global query.
103
+	 * @param bool $isEnabled
104
+	 * @return int
105
+	 */
106
+	public function getPaged($isEnabled = true)
107
+	{
108
+		return $isEnabled
109
+			? max(1, intval(filter_input(INPUT_GET, glsr()->constant('PAGED_QUERY_VAR'))))
110
+			: 1;
111
+	}
112 112
 
113
-    /**
114
-     * @param string $value
115
-     * @return void|array
116
-     */
117
-    protected function buildQueryAssignedTo($value)
118
-    {
119
-        if (!empty($value)) {
120
-            $postIds = Arr::convertStringToArray($value, 'is_numeric');
121
-            return [
122
-                'compare' => 'IN',
123
-                'key' => '_assigned_to',
124
-                'value' => glsr(Multilingual::class)->getPostIds($postIds),
125
-            ];
126
-        }
127
-    }
113
+	/**
114
+	 * @param string $value
115
+	 * @return void|array
116
+	 */
117
+	protected function buildQueryAssignedTo($value)
118
+	{
119
+		if (!empty($value)) {
120
+			$postIds = Arr::convertStringToArray($value, 'is_numeric');
121
+			return [
122
+				'compare' => 'IN',
123
+				'key' => '_assigned_to',
124
+				'value' => glsr(Multilingual::class)->getPostIds($postIds),
125
+			];
126
+		}
127
+	}
128 128
 
129
-    /**
130
-     * @param array $value
131
-     * @return void|array
132
-     */
133
-    protected function buildQueryCategory($value)
134
-    {
135
-        if (!empty($value)) {
136
-            return [
137
-                'field' => 'term_id',
138
-                'taxonomy' => Application::TAXONOMY,
139
-                'terms' => $value,
140
-            ];
141
-        }
142
-    }
129
+	/**
130
+	 * @param array $value
131
+	 * @return void|array
132
+	 */
133
+	protected function buildQueryCategory($value)
134
+	{
135
+		if (!empty($value)) {
136
+			return [
137
+				'field' => 'term_id',
138
+				'taxonomy' => Application::TAXONOMY,
139
+				'terms' => $value,
140
+			];
141
+		}
142
+	}
143 143
 
144
-    /**
145
-     * @param string $value
146
-     * @return void|array
147
-     */
148
-    protected function buildQueryEmail($value)
149
-    {
150
-        if (!empty($value)) {
151
-            return [
152
-                'key' => '_email',
153
-                'value' => $value,
154
-            ];
155
-        }
156
-    }
144
+	/**
145
+	 * @param string $value
146
+	 * @return void|array
147
+	 */
148
+	protected function buildQueryEmail($value)
149
+	{
150
+		if (!empty($value)) {
151
+			return [
152
+				'key' => '_email',
153
+				'value' => $value,
154
+			];
155
+		}
156
+	}
157 157
 
158
-    /**
159
-     * @param string $value
160
-     * @return void|array
161
-     */
162
-    protected function buildQueryIpAddress($value)
163
-    {
164
-        if (!empty($value)) {
165
-            return [
166
-                'key' => '_ip_address',
167
-                'value' => $value,
168
-            ];
169
-        }
170
-    }
158
+	/**
159
+	 * @param string $value
160
+	 * @return void|array
161
+	 */
162
+	protected function buildQueryIpAddress($value)
163
+	{
164
+		if (!empty($value)) {
165
+			return [
166
+				'key' => '_ip_address',
167
+				'value' => $value,
168
+			];
169
+		}
170
+	}
171 171
 
172
-    /**
173
-     * @param string $value
174
-     * @return void|array
175
-     */
176
-    protected function buildQueryRating($value)
177
-    {
178
-        if (is_numeric($value)
179
-            && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) {
180
-            return [
181
-                'compare' => '>=',
182
-                'key' => '_rating',
183
-                'value' => $value,
184
-            ];
185
-        }
186
-    }
172
+	/**
173
+	 * @param string $value
174
+	 * @return void|array
175
+	 */
176
+	protected function buildQueryRating($value)
177
+	{
178
+		if (is_numeric($value)
179
+			&& in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) {
180
+			return [
181
+				'compare' => '>=',
182
+				'key' => '_rating',
183
+				'value' => $value,
184
+			];
185
+		}
186
+	}
187 187
 
188
-    /**
189
-     * @param string $value
190
-     * @return void|array
191
-     */
192
-    protected function buildQueryType($value)
193
-    {
194
-        if (!in_array($value, ['', 'all'])) {
195
-            return [
196
-                'key' => '_review_type',
197
-                'value' => $value,
198
-            ];
199
-        }
200
-    }
188
+	/**
189
+	 * @param string $value
190
+	 * @return void|array
191
+	 */
192
+	protected function buildQueryType($value)
193
+	{
194
+		if (!in_array($value, ['', 'all'])) {
195
+			return [
196
+				'key' => '_review_type',
197
+				'value' => $value,
198
+			];
199
+		}
200
+	}
201 201
 }
Please login to merge, or discard this 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 2 patches
Indentation   +354 added lines, -354 removed lines patch added patch discarded remove patch
@@ -12,385 +12,385 @@
 block discarded – undo
12 12
 
13 13
 class CountsManager
14 14
 {
15
-    const LIMIT = 500;
16
-    const META_AVERAGE = '_glsr_average';
17
-    const META_COUNT = '_glsr_count';
18
-    const META_RANKING = '_glsr_ranking';
15
+	const LIMIT = 500;
16
+	const META_AVERAGE = '_glsr_average';
17
+	const META_COUNT = '_glsr_count';
18
+	const META_RANKING = '_glsr_ranking';
19 19
 
20
-    /**
21
-     * @return array
22
-     * @todo verify the additional type checks are needed
23
-     */
24
-    public function buildCounts(array $args = [])
25
-    {
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])) {
34
-                    continue;
35
-            }
36
-                $counts[$type] = array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0);
37
-            }
38
-            foreach ($query->reviews as $review) {
39
-                $type = $this->normalizeType($review->type);
40
-                ++$counts[$type][$review->rating];
41
-            }
42
-            $query = $query->has_more
43
-                ? $this->queryReviews($args, end($query->reviews)->ID)
44
-                : false;
45
-        }
46
-        return $counts;
47
-    }
20
+	/**
21
+	 * @return array
22
+	 * @todo verify the additional type checks are needed
23
+	 */
24
+	public function buildCounts(array $args = [])
25
+	{
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])) {
34
+					continue;
35
+			}
36
+				$counts[$type] = array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0);
37
+			}
38
+			foreach ($query->reviews as $review) {
39
+				$type = $this->normalizeType($review->type);
40
+				++$counts[$type][$review->rating];
41
+			}
42
+			$query = $query->has_more
43
+				? $this->queryReviews($args, end($query->reviews)->ID)
44
+				: false;
45
+		}
46
+		return $counts;
47
+	}
48 48
 
49
-    /**
50
-     * @param int $postId
51
-     * @return array
52
-     */
53
-    public function buildPostCounts($postId)
54
-    {
55
-        return $this->buildCounts(['post_ids' => [$postId]]);
56
-    }
49
+	/**
50
+	 * @param int $postId
51
+	 * @return array
52
+	 */
53
+	public function buildPostCounts($postId)
54
+	{
55
+		return $this->buildCounts(['post_ids' => [$postId]]);
56
+	}
57 57
 
58
-    /**
59
-     * @param int $termTaxonomyId
60
-     * @return array
61
-     */
62
-    public function buildTermCounts($termTaxonomyId)
63
-    {
64
-        return $this->buildCounts(['term_ids' => [$termTaxonomyId]]);
65
-    }
58
+	/**
59
+	 * @param int $termTaxonomyId
60
+	 * @return array
61
+	 */
62
+	public function buildTermCounts($termTaxonomyId)
63
+	{
64
+		return $this->buildCounts(['term_ids' => [$termTaxonomyId]]);
65
+	}
66 66
 
67
-    /**
68
-     * @return void
69
-     */
70
-    public function countAll()
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));
75
-        }
76
-        $postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to');
77
-        foreach ($postIds as $postId) {
78
-            $this->setPostCounts($postId, $this->buildPostCounts($postId));
79
-        }
80
-        $this->setCounts($this->buildCounts());
81
-    }
67
+	/**
68
+	 * @return void
69
+	 */
70
+	public function countAll()
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));
75
+		}
76
+		$postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to');
77
+		foreach ($postIds as $postId) {
78
+			$this->setPostCounts($postId, $this->buildPostCounts($postId));
79
+		}
80
+		$this->setCounts($this->buildCounts());
81
+	}
82 82
 
83
-    /**
84
-     * @return void
85
-     */
86
-    public function decrease(Review $review)
87
-    {
88
-        $this->decreaseCounts($review);
89
-        $this->decreasePostCounts($review);
90
-        $this->decreaseTermCounts($review);
91
-    }
83
+	/**
84
+	 * @return void
85
+	 */
86
+	public function decrease(Review $review)
87
+	{
88
+		$this->decreaseCounts($review);
89
+		$this->decreasePostCounts($review);
90
+		$this->decreaseTermCounts($review);
91
+	}
92 92
 
93
-    /**
94
-     * @return void
95
-     */
96
-    public function decreaseCounts(Review $review)
97
-    {
98
-        $this->setCounts($this->decreaseRating(
99
-            $this->getCounts(),
100
-            $review->review_type,
101
-            $review->rating
102
-        ));
103
-    }
93
+	/**
94
+	 * @return void
95
+	 */
96
+	public function decreaseCounts(Review $review)
97
+	{
98
+		$this->setCounts($this->decreaseRating(
99
+			$this->getCounts(),
100
+			$review->review_type,
101
+			$review->rating
102
+		));
103
+	}
104 104
 
105
-    /**
106
-     * @return void
107
-     */
108
-    public function decreasePostCounts(Review $review)
109
-    {
110
-        if (empty($counts = $this->getPostCounts($review->assigned_to))) {
111
-            return;
112
-        }
113
-        $counts = $this->decreaseRating($counts, $review->review_type, $review->rating);
114
-        $this->setPostCounts($review->assigned_to, $counts);
115
-    }
105
+	/**
106
+	 * @return void
107
+	 */
108
+	public function decreasePostCounts(Review $review)
109
+	{
110
+		if (empty($counts = $this->getPostCounts($review->assigned_to))) {
111
+			return;
112
+		}
113
+		$counts = $this->decreaseRating($counts, $review->review_type, $review->rating);
114
+		$this->setPostCounts($review->assigned_to, $counts);
115
+	}
116 116
 
117
-    /**
118
-     * @return void
119
-     */
120
-    public function decreaseTermCounts(Review $review)
121
-    {
122
-        foreach ($review->term_ids as $termId) {
123
-            if (empty($counts = $this->getTermCounts($termId))) {
124
-                continue;
125
-            }
126
-            $counts = $this->decreaseRating($counts, $review->review_type, $review->rating);
127
-            $this->setTermCounts($termId, $counts);
128
-        }
129
-    }
117
+	/**
118
+	 * @return void
119
+	 */
120
+	public function decreaseTermCounts(Review $review)
121
+	{
122
+		foreach ($review->term_ids as $termId) {
123
+			if (empty($counts = $this->getTermCounts($termId))) {
124
+				continue;
125
+			}
126
+			$counts = $this->decreaseRating($counts, $review->review_type, $review->rating);
127
+			$this->setTermCounts($termId, $counts);
128
+		}
129
+	}
130 130
 
131
-    /**
132
-     * @return array
133
-     */
134
-    public function flatten(array $reviewCounts, array $args = [])
135
-    {
136
-        $counts = [];
137
-        array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) {
138
-            $counts[$index] = $num + intval(Arr::get($counts, $index, 0));
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'])) {
146
-                continue;
147
-            }
148
-            $num = 0;
149
-        }
150
-        return $counts;
151
-    }
131
+	/**
132
+	 * @return array
133
+	 */
134
+	public function flatten(array $reviewCounts, array $args = [])
135
+	{
136
+		$counts = [];
137
+		array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) {
138
+			$counts[$index] = $num + intval(Arr::get($counts, $index, 0));
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'])) {
146
+				continue;
147
+			}
148
+			$num = 0;
149
+		}
150
+		return $counts;
151
+	}
152 152
 
153
-    /**
154
-     * @return array
155
-     */
156
-    public function get(array $args = [])
157
-    {
158
-        $args = $this->normalizeArgs($args);
159
-        $counts = [];
160
-        if ($this->isMixedCount($args)) {
161
-            $counts = [$this->buildCounts($args)]; // force query the database
162
-        } else {
163
-            foreach ($args['post_ids'] as $postId) {
164
-                $counts[] = $this->getPostCounts($postId);
165
-        }
166
-            foreach ($args['term_ids'] as $termId) {
167
-                $counts[] = $this->getTermCounts($termId);
168
-            }
169
-            if (empty($counts)) {
170
-                $counts[] = $this->getCounts();
171
-            }
172
-        }
173
-        return in_array($args['type'], ['', 'all'])
174
-            ? $this->normalize([$this->flatten($counts)])
175
-            : $this->normalize(glsr_array_column($counts, $args['type']));
176
-    }
153
+	/**
154
+	 * @return array
155
+	 */
156
+	public function get(array $args = [])
157
+	{
158
+		$args = $this->normalizeArgs($args);
159
+		$counts = [];
160
+		if ($this->isMixedCount($args)) {
161
+			$counts = [$this->buildCounts($args)]; // force query the database
162
+		} else {
163
+			foreach ($args['post_ids'] as $postId) {
164
+				$counts[] = $this->getPostCounts($postId);
165
+		}
166
+			foreach ($args['term_ids'] as $termId) {
167
+				$counts[] = $this->getTermCounts($termId);
168
+			}
169
+			if (empty($counts)) {
170
+				$counts[] = $this->getCounts();
171
+			}
172
+		}
173
+		return in_array($args['type'], ['', 'all'])
174
+			? $this->normalize([$this->flatten($counts)])
175
+			: $this->normalize(glsr_array_column($counts, $args['type']));
176
+	}
177 177
 
178
-    /**
179
-     * @return array
180
-     */
181
-    public function getCounts()
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);
186
-            return [];
187
-        }
188
-        return $counts;
189
-    }
178
+	/**
179
+	 * @return array
180
+	 */
181
+	public function getCounts()
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);
186
+			return [];
187
+		}
188
+		return $counts;
189
+	}
190 190
 
191
-    /**
192
-     * @param int $postId
193
-     * @return array
194
-     */
195
-    public function getPostCounts($postId)
196
-    {
197
-        return array_filter((array) get_post_meta($postId, static::META_COUNT, true));
198
-    }
191
+	/**
192
+	 * @param int $postId
193
+	 * @return array
194
+	 */
195
+	public function getPostCounts($postId)
196
+	{
197
+		return array_filter((array) get_post_meta($postId, static::META_COUNT, true));
198
+	}
199 199
 
200
-    /**
201
-     * @param int $termId
202
-     * @return array
203
-     */
204
-    public function getTermCounts($termId)
205
-    {
206
-        return array_filter((array) get_term_meta($termId, static::META_COUNT, true));
207
-    }
200
+	/**
201
+	 * @param int $termId
202
+	 * @return array
203
+	 */
204
+	public function getTermCounts($termId)
205
+	{
206
+		return array_filter((array) get_term_meta($termId, static::META_COUNT, true));
207
+	}
208 208
 
209
-    /**
210
-     * @return void
211
-     */
212
-    public function increase(Review $review)
213
-    {
214
-        $this->increaseCounts($review);
215
-        $this->increasePostCounts($review);
216
-        $this->increaseTermCounts($review);
217
-    }
209
+	/**
210
+	 * @return void
211
+	 */
212
+	public function increase(Review $review)
213
+	{
214
+		$this->increaseCounts($review);
215
+		$this->increasePostCounts($review);
216
+		$this->increaseTermCounts($review);
217
+	}
218 218
 
219
-    /**
220
-     * @return void
221
-     */
222
-    public function increaseCounts(Review $review)
223
-    {
224
-        if (empty($counts = $this->getCounts())) {
225
-            $counts = $this->buildCounts();
226
-        }
227
-        $this->setCounts($this->increaseRating($counts, $review->review_type, $review->rating));
228
-    }
219
+	/**
220
+	 * @return void
221
+	 */
222
+	public function increaseCounts(Review $review)
223
+	{
224
+		if (empty($counts = $this->getCounts())) {
225
+			$counts = $this->buildCounts();
226
+		}
227
+		$this->setCounts($this->increaseRating($counts, $review->review_type, $review->rating));
228
+	}
229 229
 
230
-    /**
231
-     * @return void
232
-     */
233
-    public function increasePostCounts(Review $review)
234
-    {
235
-        if (!(get_post($review->assigned_to) instanceof WP_Post)) {
236
-            return;
237
-        }
238
-        $counts = $this->getPostCounts($review->assigned_to);
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);
243
-    }
230
+	/**
231
+	 * @return void
232
+	 */
233
+	public function increasePostCounts(Review $review)
234
+	{
235
+		if (!(get_post($review->assigned_to) instanceof WP_Post)) {
236
+			return;
237
+		}
238
+		$counts = $this->getPostCounts($review->assigned_to);
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);
243
+	}
244 244
 
245
-    /**
246
-     * @return void
247
-     */
248
-    public function increaseTermCounts(Review $review)
249
-    {
250
-        $terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids));
251
-        foreach ($terms as $term) {
252
-            $counts = $this->getTermCounts($term['term_id']);
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);
257
-        }
258
-    }
245
+	/**
246
+	 * @return void
247
+	 */
248
+	public function increaseTermCounts(Review $review)
249
+	{
250
+		$terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids));
251
+		foreach ($terms as $term) {
252
+			$counts = $this->getTermCounts($term['term_id']);
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);
257
+		}
258
+	}
259 259
 
260
-    /**
261
-     * @return void
262
-     */
263
-    public function setCounts(array $reviewCounts)
264
-    {
265
-        glsr(OptionManager::class)->set('counts', $reviewCounts);
266
-    }
260
+	/**
261
+	 * @return void
262
+	 */
263
+	public function setCounts(array $reviewCounts)
264
+	{
265
+		glsr(OptionManager::class)->set('counts', $reviewCounts);
266
+	}
267 267
 
268
-    /**
269
-     * @param int $postId
270
-     * @return void
271
-     */
272
-    public function setPostCounts($postId, array $reviewCounts)
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));
278
-    }
268
+	/**
269
+	 * @param int $postId
270
+	 * @return void
271
+	 */
272
+	public function setPostCounts($postId, array $reviewCounts)
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));
278
+	}
279 279
 
280
-    /**
281
-     * @param int $termId
282
-     * @return void
283
-     */
284
-    public function setTermCounts($termId, array $reviewCounts)
285
-    {
286
-        $term = get_term($termId, Application::TAXONOMY);
287
-        if (!isset($term->term_id)) {
288
-            return;
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));
294
-    }
280
+	/**
281
+	 * @param int $termId
282
+	 * @return void
283
+	 */
284
+	public function setTermCounts($termId, array $reviewCounts)
285
+	{
286
+		$term = get_term($termId, Application::TAXONOMY);
287
+		if (!isset($term->term_id)) {
288
+			return;
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));
294
+	}
295 295
 
296
-    /**
297
-     * @param string $type
298
-     * @param int $rating
299
-     * @return array
300
-     */
301
-    protected function decreaseRating(array $reviewCounts, $type, $rating)
302
-    {
303
-        if (isset($reviewCounts[$type][$rating])) {
304
-            $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1);
305
-        }
306
-        return $reviewCounts;
307
-    }
296
+	/**
297
+	 * @param string $type
298
+	 * @param int $rating
299
+	 * @return array
300
+	 */
301
+	protected function decreaseRating(array $reviewCounts, $type, $rating)
302
+	{
303
+		if (isset($reviewCounts[$type][$rating])) {
304
+			$reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1);
305
+		}
306
+		return $reviewCounts;
307
+	}
308 308
 
309
-    /**
310
-     * @param string $type
311
-     * @param int $rating
312
-     * @return array
313
-     */
314
-    protected function increaseRating(array $reviewCounts, $type, $rating)
315
-    {
316
-        if (!array_key_exists($type, glsr()->reviewTypes)) {
317
-            return $reviewCounts;
318
-        }
319
-        if (!array_key_exists($type, $reviewCounts)) {
320
-            $reviewCounts[$type] = [];
321
-        }
322
-        $reviewCounts = $this->normalize($reviewCounts);
323
-        $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1;
324
-        return $reviewCounts;
325
-    }
309
+	/**
310
+	 * @param string $type
311
+	 * @param int $rating
312
+	 * @return array
313
+	 */
314
+	protected function increaseRating(array $reviewCounts, $type, $rating)
315
+	{
316
+		if (!array_key_exists($type, glsr()->reviewTypes)) {
317
+			return $reviewCounts;
318
+		}
319
+		if (!array_key_exists($type, $reviewCounts)) {
320
+			$reviewCounts[$type] = [];
321
+		}
322
+		$reviewCounts = $this->normalize($reviewCounts);
323
+		$reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1;
324
+		return $reviewCounts;
325
+	}
326 326
 
327
-    /**
328
-     * @return bool
329
-     */
330
-    protected function isMixedCount(array $args)
331
-    {
332
-        return !empty($args['post_ids']) && !empty($args['term_ids']);
333
-    }
327
+	/**
328
+	 * @return bool
329
+	 */
330
+	protected function isMixedCount(array $args)
331
+	{
332
+		return !empty($args['post_ids']) && !empty($args['term_ids']);
333
+	}
334 334
 
335
-    /**
336
-     * @return array
337
-     */
338
-    protected function normalize(array $reviewCounts)
339
-    {
340
-        if (empty($reviewCounts)) {
341
-            $reviewCounts = [[]];
342
-        }
343
-        foreach ($reviewCounts as &$counts) {
344
-            foreach (range(0, glsr()->constant('MAX_RATING', Rating::class)) as $index) {
345
-                if (isset($counts[$index])) {
346
-                    continue;
347
-                }
348
-                $counts[$index] = 0;
349
-            }
350
-            ksort($counts);
351
-        }
352
-        return $reviewCounts;
353
-    }
335
+	/**
336
+	 * @return array
337
+	 */
338
+	protected function normalize(array $reviewCounts)
339
+	{
340
+		if (empty($reviewCounts)) {
341
+			$reviewCounts = [[]];
342
+		}
343
+		foreach ($reviewCounts as &$counts) {
344
+			foreach (range(0, glsr()->constant('MAX_RATING', Rating::class)) as $index) {
345
+				if (isset($counts[$index])) {
346
+					continue;
347
+				}
348
+				$counts[$index] = 0;
349
+			}
350
+			ksort($counts);
351
+		}
352
+		return $reviewCounts;
353
+	}
354 354
 
355
-    /**
356
-     * @return array
357
-     */
358
-    protected function normalizeArgs(array $args)
359
-    {
360
-        $args = wp_parse_args(array_filter($args), [
361
-            'post_ids' => [],
362
-            'term_ids' => [],
363
-            'type' => 'local',
364
-        ]);
365
-        $args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']);
366
-        $args['type'] = $this->normalizeType($args['type']);
367
-        return $args;
368
-    }
355
+	/**
356
+	 * @return array
357
+	 */
358
+	protected function normalizeArgs(array $args)
359
+	{
360
+		$args = wp_parse_args(array_filter($args), [
361
+			'post_ids' => [],
362
+			'term_ids' => [],
363
+			'type' => 'local',
364
+		]);
365
+		$args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']);
366
+		$args['type'] = $this->normalizeType($args['type']);
367
+		return $args;
368
+	}
369 369
 
370
-    /**
371
-     * @param string $type
372
-     * @return string
373
-     */
374
-    protected function normalizeType($type)
375
-    {
376
-        return empty($type) || !is_string($type)
377
-            ? 'local'
378
-            : $type;
379
-    }
370
+	/**
371
+	 * @param string $type
372
+	 * @return string
373
+	 */
374
+	protected function normalizeType($type)
375
+	{
376
+		return empty($type) || !is_string($type)
377
+			? 'local'
378
+			: $type;
379
+	}
380 380
 
381
-    /**
382
-     * @param int $lastPostId
383
-     * @return object
384
-     */
385
-    protected function queryReviews(array $args = [], $lastPostId = 0)
386
-    {
387
-        $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT);
388
-        $hasMore = is_array($reviews)
389
-            ? count($reviews) == static::LIMIT
390
-            : false;
391
-        return (object) [
392
-            'has_more' => $hasMore,
393
-            'reviews' => $reviews,
394
-        ];
395
-    }
381
+	/**
382
+	 * @param int $lastPostId
383
+	 * @return object
384
+	 */
385
+	protected function queryReviews(array $args = [], $lastPostId = 0)
386
+	{
387
+		$reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT);
388
+		$hasMore = is_array($reviews)
389
+			? count($reviews) == static::LIMIT
390
+			: false;
391
+		return (object) [
392
+			'has_more' => $hasMore,
393
+			'reviews' => $reviews,
394
+		];
395
+	}
396 396
 }
Please login to merge, or discard this 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/Controllers/SettingsController.php 3 patches
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -9,121 +9,121 @@
 block discarded – undo
9 9
 
10 10
 class SettingsController extends Controller
11 11
 {
12
-    /**
13
-     * @param mixed $input
14
-     * @return array
15
-     * @callback register_setting
16
-     */
17
-    public function callbackRegisterSettings($input)
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'));
28
-            }
29
-            return $options;
30
-        }
31
-        return $input;
32
-    }
12
+	/**
13
+	 * @param mixed $input
14
+	 * @return array
15
+	 * @callback register_setting
16
+	 */
17
+	public function callbackRegisterSettings($input)
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'));
28
+			}
29
+			return $options;
30
+		}
31
+		return $input;
32
+	}
33 33
 
34
-    /**
35
-     * @return void
36
-     * @action admin_init
37
-     */
38
-    public function registerSettings()
39
-    {
40
-        register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [
41
-            'sanitize_callback' => [$this, 'callbackRegisterSettings'],
42
-        ]);
43
-    }
34
+	/**
35
+	 * @return void
36
+	 * @action admin_init
37
+	 */
38
+	public function registerSettings()
39
+	{
40
+		register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [
41
+			'sanitize_callback' => [$this, 'callbackRegisterSettings'],
42
+		]);
43
+	}
44 44
 
45
-    /**
46
-     * @return array
47
-     */
48
-    protected function sanitizeGeneral(array $input, array $options)
49
-    {
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', '');
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);
58
-        }
59
-        $defaultValue = Arr::get($inputForm, 'notifications', []);
60
-        $options = Arr::set($options, $key.'.notifications', $defaultValue);
61
-        return $options;
62
-    }
45
+	/**
46
+	 * @return array
47
+	 */
48
+	protected function sanitizeGeneral(array $input, array $options)
49
+	{
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', '');
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);
58
+		}
59
+		$defaultValue = Arr::get($inputForm, 'notifications', []);
60
+		$options = Arr::set($options, $key.'.notifications', $defaultValue);
61
+		return $options;
62
+	}
63 63
 
64
-    /**
65
-     * @return array
66
-     */
67
-    protected function sanitizeSubmissions(array $input, array $options)
68
-    {
69
-        $key = 'settings.submissions';
70
-        $inputForm = Arr::get($input, $key);
71
-        $defaultValue = isset($inputForm['required'])
72
-            ? $inputForm['required']
73
-            : [];
74
-        $options = Arr::set($options, $key.'.required', $defaultValue);
75
-        return $options;
76
-    }
64
+	/**
65
+	 * @return array
66
+	 */
67
+	protected function sanitizeSubmissions(array $input, array $options)
68
+	{
69
+		$key = 'settings.submissions';
70
+		$inputForm = Arr::get($input, $key);
71
+		$defaultValue = isset($inputForm['required'])
72
+			? $inputForm['required']
73
+			: [];
74
+		$options = Arr::set($options, $key.'.required', $defaultValue);
75
+		return $options;
76
+	}
77 77
 
78
-    /**
79
-     * @return array
80
-     */
81
-    protected function sanitizeTranslations(array $input, array $options)
82
-    {
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)));
87
-            $allowedTags = [
88
-                'a' => ['class' => [], 'href' => [], 'target' => []],
89
-                'span' => ['class' => []],
90
-            ];
91
-            array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) {
92
-                if (isset($string['s2'])) {
93
-                    $string['s2'] = wp_kses($string['s2'], $allowedTags);
94
-                }
95
-                if (isset($string['p2'])) {
96
-                    $string['p2'] = wp_kses($string['p2'], $allowedTags);
97
-                }
98
-            });
99
-        }
100
-        return $options;
101
-    }
78
+	/**
79
+	 * @return array
80
+	 */
81
+	protected function sanitizeTranslations(array $input, array $options)
82
+	{
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)));
87
+			$allowedTags = [
88
+				'a' => ['class' => [], 'href' => [], 'target' => []],
89
+				'span' => ['class' => []],
90
+			];
91
+			array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) {
92
+				if (isset($string['s2'])) {
93
+					$string['s2'] = wp_kses($string['s2'], $allowedTags);
94
+				}
95
+				if (isset($string['p2'])) {
96
+					$string['p2'] = wp_kses($string['p2'], $allowedTags);
97
+				}
98
+			});
99
+		}
100
+		return $options;
101
+	}
102 102
 
103
-    /**
104
-     * @param string $integrationSlug
105
-     * @return bool
106
-     */
107
-    protected function hasMultilingualIntegration($integrationSlug)
108
-    {
109
-        $integration = glsr(Multilingual::class)->getIntegration($integrationSlug);
110
-        if (!$integration) {
111
-            return false;
112
-        }
113
-        if (!$integration->isActive()) {
114
-            glsr(Notice::class)->addError(sprintf(
115
-                __('Please install/activate the %s plugin to enable integration.', 'site-reviews'),
116
-                $integration->pluginName
117
-            ));
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'),
122
-                $integration->pluginName,
123
-                $integration->supportedVersion
124
-            ));
125
-            return false;
126
-        }
127
-        return true;
128
-    }
103
+	/**
104
+	 * @param string $integrationSlug
105
+	 * @return bool
106
+	 */
107
+	protected function hasMultilingualIntegration($integrationSlug)
108
+	{
109
+		$integration = glsr(Multilingual::class)->getIntegration($integrationSlug);
110
+		if (!$integration) {
111
+			return false;
112
+		}
113
+		if (!$integration->isActive()) {
114
+			glsr(Notice::class)->addError(sprintf(
115
+				__('Please install/activate the %s plugin to enable integration.', 'site-reviews'),
116
+				$integration->pluginName
117
+			));
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'),
122
+				$integration->pluginName,
123
+				$integration->supportedVersion
124
+			));
125
+			return false;
126
+		}
127
+		return true;
128
+	}
129 129
 }
Please login to merge, or discard this 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.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -116,7 +116,8 @@
 block discarded – undo
116 116
                 $integration->pluginName
117 117
             ));
118 118
             return false;
119
-        } elseif (!$integration->isSupported()) {
119
+        }
120
+        elseif (!$integration->isSupported()) {
120 121
             glsr(Notice::class)->addError(sprintf(
121 122
                 __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'),
122 123
                 $integration->pluginName,
Please login to merge, or discard this patch.
plugin/Helpers/Arr.php 2 patches
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -4,197 +4,197 @@
 block discarded – undo
4 4
 
5 5
 class Arr
6 6
 {
7
-    /**
8
-     * @return bool
9
-     */
10
-    public static function compareArrays(array $arr1, array $arr2)
11
-    {
12
-        sort($arr1);
13
-        sort($arr2);
14
-        return $arr1 == $arr2;
15
-    }
7
+	/**
8
+	 * @return bool
9
+	 */
10
+	public static function compareArrays(array $arr1, array $arr2)
11
+	{
12
+		sort($arr1);
13
+		sort($arr2);
14
+		return $arr1 == $arr2;
15
+	}
16 16
 
17
-    /**
18
-     * @param mixed $array
19
-     * @return array
20
-     */
21
-    public static function consolidateArray($array)
22
-    {
23
-        return is_array($array) || is_object($array)
24
-            ? (array) $array
25
-            : [];
26
-    }
17
+	/**
18
+	 * @param mixed $array
19
+	 * @return array
20
+	 */
21
+	public static function consolidateArray($array)
22
+	{
23
+		return is_array($array) || is_object($array)
24
+			? (array) $array
25
+			: [];
26
+	}
27 27
 
28
-    /**
29
-     * @return array
30
-     */
31
-    public static function convertDotNotationArray(array $array)
32
-    {
33
-        $results = [];
34
-        foreach ($array as $path => $value) {
35
-            $results = static::set($results, $path, $value);
36
-        }
37
-        return $results;
38
-    }
28
+	/**
29
+	 * @return array
30
+	 */
31
+	public static function convertDotNotationArray(array $array)
32
+	{
33
+		$results = [];
34
+		foreach ($array as $path => $value) {
35
+			$results = static::set($results, $path, $value);
36
+		}
37
+		return $results;
38
+	}
39 39
 
40
-    /**
41
-     * @param string $string
42
-     * @param mixed $callback
43
-     * @return array
44
-     */
45
-    public static function convertStringToArray($string, $callback = null)
46
-    {
47
-        $array = array_map('trim', explode(',', $string));
48
-        return $callback
49
-            ? array_filter($array, $callback)
50
-            : array_filter($array);
51
-    }
40
+	/**
41
+	 * @param string $string
42
+	 * @param mixed $callback
43
+	 * @return array
44
+	 */
45
+	public static function convertStringToArray($string, $callback = null)
46
+	{
47
+		$array = array_map('trim', explode(',', $string));
48
+		return $callback
49
+			? array_filter($array, $callback)
50
+			: array_filter($array);
51
+	}
52 52
 
53
-    /**
54
-     * @param bool $flattenValue
55
-     * @param string $prefix
56
-     * @return array
57
-     */
58
-    public static function flattenArray(array $array, $flattenValue = false, $prefix = '')
59
-    {
60
-        $result = [];
61
-        foreach ($array as $key => $value) {
62
-            $newKey = ltrim($prefix.'.'.$key, '.');
63
-            if (static::isIndexedFlatArray($value)) {
64
-                if ($flattenValue) {
65
-                    $value = '['.implode(', ', $value).']';
66
-                }
67
-            } elseif (is_array($value)) {
68
-                $result = array_merge($result, static::flattenArray($value, $flattenValue, $newKey));
69
-                continue;
70
-            }
71
-            $result[$newKey] = $value;
72
-        }
73
-        return $result;
74
-    }
53
+	/**
54
+	 * @param bool $flattenValue
55
+	 * @param string $prefix
56
+	 * @return array
57
+	 */
58
+	public static function flattenArray(array $array, $flattenValue = false, $prefix = '')
59
+	{
60
+		$result = [];
61
+		foreach ($array as $key => $value) {
62
+			$newKey = ltrim($prefix.'.'.$key, '.');
63
+			if (static::isIndexedFlatArray($value)) {
64
+				if ($flattenValue) {
65
+					$value = '['.implode(', ', $value).']';
66
+				}
67
+			} elseif (is_array($value)) {
68
+				$result = array_merge($result, static::flattenArray($value, $flattenValue, $newKey));
69
+				continue;
70
+			}
71
+			$result[$newKey] = $value;
72
+		}
73
+		return $result;
74
+	}
75 75
 
76
-    /**
77
-     * Get a value from an array of values using a dot-notation path as reference.
78
-     * @param mixed $data
79
-     * @param string $path
80
-     * @param mixed $fallback
81
-     * @return mixed
82
-     */
83
-    public static function get($data, $path = '', $fallback = '')
84
-    {
85
-        $data = static::consolidateArray($data);
86
-        $keys = explode('.', $path);
87
-        foreach ($keys as $key) {
88
-            if (!isset($data[$key])) {
89
-                return $fallback;
90
-            }
91
-            $data = $data[$key];
92
-        }
93
-        return $data;
94
-    }
76
+	/**
77
+	 * Get a value from an array of values using a dot-notation path as reference.
78
+	 * @param mixed $data
79
+	 * @param string $path
80
+	 * @param mixed $fallback
81
+	 * @return mixed
82
+	 */
83
+	public static function get($data, $path = '', $fallback = '')
84
+	{
85
+		$data = static::consolidateArray($data);
86
+		$keys = explode('.', $path);
87
+		foreach ($keys as $key) {
88
+			if (!isset($data[$key])) {
89
+				return $fallback;
90
+			}
91
+			$data = $data[$key];
92
+		}
93
+		return $data;
94
+	}
95 95
 
96
-    /**
97
-     * @param string $key
98
-     * @param string $position
99
-     * @return array
100
-     */
101
-    public static function insertInArray(array $array, array $insert, $key, $position = 'before')
102
-    {
103
-        $keyPosition = intval(array_search($key, array_keys($array)));
104
-        if ('after' == $position) {
105
-            ++$keyPosition;
106
-        }
107
-        if (false !== $keyPosition) {
108
-            $result = array_slice($array, 0, $keyPosition);
109
-            $result = array_merge($result, $insert);
110
-            return array_merge($result, array_slice($array, $keyPosition));
111
-        }
112
-        return array_merge($array, $insert);
113
-    }
96
+	/**
97
+	 * @param string $key
98
+	 * @param string $position
99
+	 * @return array
100
+	 */
101
+	public static function insertInArray(array $array, array $insert, $key, $position = 'before')
102
+	{
103
+		$keyPosition = intval(array_search($key, array_keys($array)));
104
+		if ('after' == $position) {
105
+			++$keyPosition;
106
+		}
107
+		if (false !== $keyPosition) {
108
+			$result = array_slice($array, 0, $keyPosition);
109
+			$result = array_merge($result, $insert);
110
+			return array_merge($result, array_slice($array, $keyPosition));
111
+		}
112
+		return array_merge($array, $insert);
113
+	}
114 114
 
115
-    /**
116
-     * @param mixed $array
117
-     * @return bool
118
-     */
119
-    public static function isIndexedFlatArray($array)
120
-    {
121
-        if (!is_array($array) || array_filter($array, 'is_array')) {
122
-            return false;
123
-        }
124
-        return wp_is_numeric_array($array);
125
-    }
115
+	/**
116
+	 * @param mixed $array
117
+	 * @return bool
118
+	 */
119
+	public static function isIndexedFlatArray($array)
120
+	{
121
+		if (!is_array($array) || array_filter($array, 'is_array')) {
122
+			return false;
123
+		}
124
+		return wp_is_numeric_array($array);
125
+	}
126 126
 
127
-    /**
128
-     * @param bool $prefixed
129
-     * @return array
130
-     */
131
-    public static function prefixArrayKeys(array $values, $prefixed = true)
132
-    {
133
-        $trim = '_';
134
-        $prefix = $prefixed
135
-            ? $trim
136
-            : '';
137
-        $prefixed = [];
138
-        foreach ($values as $key => $value) {
139
-            $key = trim($key);
140
-            if (0 === strpos($key, $trim)) {
141
-                $key = substr($key, strlen($trim));
142
-            }
143
-            $prefixed[$prefix.$key] = $value;
144
-        }
145
-        return $prefixed;
146
-    }
127
+	/**
128
+	 * @param bool $prefixed
129
+	 * @return array
130
+	 */
131
+	public static function prefixArrayKeys(array $values, $prefixed = true)
132
+	{
133
+		$trim = '_';
134
+		$prefix = $prefixed
135
+			? $trim
136
+			: '';
137
+		$prefixed = [];
138
+		foreach ($values as $key => $value) {
139
+			$key = trim($key);
140
+			if (0 === strpos($key, $trim)) {
141
+				$key = substr($key, strlen($trim));
142
+			}
143
+			$prefixed[$prefix.$key] = $value;
144
+		}
145
+		return $prefixed;
146
+	}
147 147
 
148
-    /**
149
-     * @return array
150
-     */
151
-    public static function removeEmptyArrayValues(array $array)
152
-    {
153
-        $result = [];
154
-        foreach ($array as $key => $value) {
155
-            if (!$value) {
156
-                continue;
157
-            }
158
-            $result[$key] = is_array($value)
159
-                ? static::removeEmptyArrayValues($value)
160
-                : $value;
161
-        }
162
-        return $result;
163
-    }
148
+	/**
149
+	 * @return array
150
+	 */
151
+	public static function removeEmptyArrayValues(array $array)
152
+	{
153
+		$result = [];
154
+		foreach ($array as $key => $value) {
155
+			if (!$value) {
156
+				continue;
157
+			}
158
+			$result[$key] = is_array($value)
159
+				? static::removeEmptyArrayValues($value)
160
+				: $value;
161
+		}
162
+		return $result;
163
+	}
164 164
 
165 165
 
166
-    /**
167
-     * Set a value to an array of values using a dot-notation path as reference.
168
-     * @param string $path
169
-     * @param mixed $value
170
-     * @return array
171
-     */
172
-    public static function set(array $data, $path, $value)
173
-    {
174
-        $token = strtok($path, '.');
175
-        $ref = &$data;
176
-        while (false !== $token) {
177
-            $ref = static::consolidateArray($ref);
178
-            $ref = &$ref[$token];
179
-            $token = strtok('.');
180
-        }
181
-        $ref = $value;
182
-        return $data;
183
-    }
166
+	/**
167
+	 * Set a value to an array of values using a dot-notation path as reference.
168
+	 * @param string $path
169
+	 * @param mixed $value
170
+	 * @return array
171
+	 */
172
+	public static function set(array $data, $path, $value)
173
+	{
174
+		$token = strtok($path, '.');
175
+		$ref = &$data;
176
+		while (false !== $token) {
177
+			$ref = static::consolidateArray($ref);
178
+			$ref = &$ref[$token];
179
+			$token = strtok('.');
180
+		}
181
+		$ref = $value;
182
+		return $data;
183
+	}
184 184
 
185
-    /**
186
-     * @return array
187
-     */
188
-    public static function unique(array $values)
189
-    {
190
-        return array_filter(array_unique($values));
191
-    }
185
+	/**
186
+	 * @return array
187
+	 */
188
+	public static function unique(array $values)
189
+	{
190
+		return array_filter(array_unique($values));
191
+	}
192 192
 
193
-    /**
194
-     * @return array
195
-     */
196
-    public static function unprefixArrayKeys(array $values)
197
-    {
198
-        return static::prefixArrayKeys($values, false);
199
-    }
193
+	/**
194
+	 * @return array
195
+	 */
196
+	public static function unprefixArrayKeys(array $values)
197
+	{
198
+		return static::prefixArrayKeys($values, false);
199
+	}
200 200
 }
Please login to merge, or discard this patch.
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -7,10 +7,10 @@  discard block
 block discarded – undo
7 7
     /**
8 8
      * @return bool
9 9
      */
10
-    public static function compareArrays(array $arr1, array $arr2)
10
+    public static function compareArrays( array $arr1, array $arr2 )
11 11
     {
12
-        sort($arr1);
13
-        sort($arr2);
12
+        sort( $arr1 );
13
+        sort( $arr2 );
14 14
         return $arr1 == $arr2;
15 15
     }
16 16
 
@@ -18,21 +18,21 @@  discard block
 block discarded – undo
18 18
      * @param mixed $array
19 19
      * @return array
20 20
      */
21
-    public static function consolidateArray($array)
21
+    public static function consolidateArray( $array )
22 22
     {
23
-        return is_array($array) || is_object($array)
24
-            ? (array) $array
23
+        return is_array( $array ) || is_object( $array )
24
+            ? (array)$array
25 25
             : [];
26 26
     }
27 27
 
28 28
     /**
29 29
      * @return array
30 30
      */
31
-    public static function convertDotNotationArray(array $array)
31
+    public static function convertDotNotationArray( array $array )
32 32
     {
33 33
         $results = [];
34
-        foreach ($array as $path => $value) {
35
-            $results = static::set($results, $path, $value);
34
+        foreach( $array as $path => $value ) {
35
+            $results = static::set( $results, $path, $value );
36 36
         }
37 37
         return $results;
38 38
     }
@@ -42,12 +42,12 @@  discard block
 block discarded – undo
42 42
      * @param mixed $callback
43 43
      * @return array
44 44
      */
45
-    public static function convertStringToArray($string, $callback = null)
45
+    public static function convertStringToArray( $string, $callback = null )
46 46
     {
47
-        $array = array_map('trim', explode(',', $string));
47
+        $array = array_map( 'trim', explode( ',', $string ) );
48 48
         return $callback
49
-            ? array_filter($array, $callback)
50
-            : array_filter($array);
49
+            ? array_filter( $array, $callback )
50
+            : array_filter( $array );
51 51
     }
52 52
 
53 53
     /**
@@ -55,17 +55,17 @@  discard block
 block discarded – undo
55 55
      * @param string $prefix
56 56
      * @return array
57 57
      */
58
-    public static function flattenArray(array $array, $flattenValue = false, $prefix = '')
58
+    public static function flattenArray( array $array, $flattenValue = false, $prefix = '' )
59 59
     {
60 60
         $result = [];
61
-        foreach ($array as $key => $value) {
62
-            $newKey = ltrim($prefix.'.'.$key, '.');
63
-            if (static::isIndexedFlatArray($value)) {
64
-                if ($flattenValue) {
65
-                    $value = '['.implode(', ', $value).']';
61
+        foreach( $array as $key => $value ) {
62
+            $newKey = ltrim( $prefix.'.'.$key, '.' );
63
+            if( static::isIndexedFlatArray( $value ) ) {
64
+                if( $flattenValue ) {
65
+                    $value = '['.implode( ', ', $value ).']';
66 66
                 }
67
-            } elseif (is_array($value)) {
68
-                $result = array_merge($result, static::flattenArray($value, $flattenValue, $newKey));
67
+            } elseif( is_array( $value ) ) {
68
+                $result = array_merge( $result, static::flattenArray( $value, $flattenValue, $newKey ) );
69 69
                 continue;
70 70
             }
71 71
             $result[$newKey] = $value;
@@ -80,12 +80,12 @@  discard block
 block discarded – undo
80 80
      * @param mixed $fallback
81 81
      * @return mixed
82 82
      */
83
-    public static function get($data, $path = '', $fallback = '')
83
+    public static function get( $data, $path = '', $fallback = '' )
84 84
     {
85
-        $data = static::consolidateArray($data);
86
-        $keys = explode('.', $path);
87
-        foreach ($keys as $key) {
88
-            if (!isset($data[$key])) {
85
+        $data = static::consolidateArray( $data );
86
+        $keys = explode( '.', $path );
87
+        foreach( $keys as $key ) {
88
+            if( !isset($data[$key]) ) {
89 89
                 return $fallback;
90 90
             }
91 91
             $data = $data[$key];
@@ -98,47 +98,47 @@  discard block
 block discarded – undo
98 98
      * @param string $position
99 99
      * @return array
100 100
      */
101
-    public static function insertInArray(array $array, array $insert, $key, $position = 'before')
101
+    public static function insertInArray( array $array, array $insert, $key, $position = 'before' )
102 102
     {
103
-        $keyPosition = intval(array_search($key, array_keys($array)));
104
-        if ('after' == $position) {
103
+        $keyPosition = intval( array_search( $key, array_keys( $array ) ) );
104
+        if( 'after' == $position ) {
105 105
             ++$keyPosition;
106 106
         }
107
-        if (false !== $keyPosition) {
108
-            $result = array_slice($array, 0, $keyPosition);
109
-            $result = array_merge($result, $insert);
110
-            return array_merge($result, array_slice($array, $keyPosition));
107
+        if( false !== $keyPosition ) {
108
+            $result = array_slice( $array, 0, $keyPosition );
109
+            $result = array_merge( $result, $insert );
110
+            return array_merge( $result, array_slice( $array, $keyPosition ) );
111 111
         }
112
-        return array_merge($array, $insert);
112
+        return array_merge( $array, $insert );
113 113
     }
114 114
 
115 115
     /**
116 116
      * @param mixed $array
117 117
      * @return bool
118 118
      */
119
-    public static function isIndexedFlatArray($array)
119
+    public static function isIndexedFlatArray( $array )
120 120
     {
121
-        if (!is_array($array) || array_filter($array, 'is_array')) {
121
+        if( !is_array( $array ) || array_filter( $array, 'is_array' ) ) {
122 122
             return false;
123 123
         }
124
-        return wp_is_numeric_array($array);
124
+        return wp_is_numeric_array( $array );
125 125
     }
126 126
 
127 127
     /**
128 128
      * @param bool $prefixed
129 129
      * @return array
130 130
      */
131
-    public static function prefixArrayKeys(array $values, $prefixed = true)
131
+    public static function prefixArrayKeys( array $values, $prefixed = true )
132 132
     {
133 133
         $trim = '_';
134 134
         $prefix = $prefixed
135 135
             ? $trim
136 136
             : '';
137 137
         $prefixed = [];
138
-        foreach ($values as $key => $value) {
139
-            $key = trim($key);
140
-            if (0 === strpos($key, $trim)) {
141
-                $key = substr($key, strlen($trim));
138
+        foreach( $values as $key => $value ) {
139
+            $key = trim( $key );
140
+            if( 0 === strpos( $key, $trim ) ) {
141
+                $key = substr( $key, strlen( $trim ) );
142 142
             }
143 143
             $prefixed[$prefix.$key] = $value;
144 144
         }
@@ -148,15 +148,15 @@  discard block
 block discarded – undo
148 148
     /**
149 149
      * @return array
150 150
      */
151
-    public static function removeEmptyArrayValues(array $array)
151
+    public static function removeEmptyArrayValues( array $array )
152 152
     {
153 153
         $result = [];
154
-        foreach ($array as $key => $value) {
155
-            if (!$value) {
154
+        foreach( $array as $key => $value ) {
155
+            if( !$value ) {
156 156
                 continue;
157 157
             }
158
-            $result[$key] = is_array($value)
159
-                ? static::removeEmptyArrayValues($value)
158
+            $result[$key] = is_array( $value )
159
+                ? static::removeEmptyArrayValues( $value )
160 160
                 : $value;
161 161
         }
162 162
         return $result;
@@ -169,14 +169,14 @@  discard block
 block discarded – undo
169 169
      * @param mixed $value
170 170
      * @return array
171 171
      */
172
-    public static function set(array $data, $path, $value)
172
+    public static function set( array $data, $path, $value )
173 173
     {
174
-        $token = strtok($path, '.');
174
+        $token = strtok( $path, '.' );
175 175
         $ref = &$data;
176
-        while (false !== $token) {
177
-            $ref = static::consolidateArray($ref);
176
+        while( false !== $token ) {
177
+            $ref = static::consolidateArray( $ref );
178 178
             $ref = &$ref[$token];
179
-            $token = strtok('.');
179
+            $token = strtok( '.' );
180 180
         }
181 181
         $ref = $value;
182 182
         return $data;
@@ -185,16 +185,16 @@  discard block
 block discarded – undo
185 185
     /**
186 186
      * @return array
187 187
      */
188
-    public static function unique(array $values)
188
+    public static function unique( array $values )
189 189
     {
190
-        return array_filter(array_unique($values));
190
+        return array_filter( array_unique( $values ) );
191 191
     }
192 192
 
193 193
     /**
194 194
      * @return array
195 195
      */
196
-    public static function unprefixArrayKeys(array $values)
196
+    public static function unprefixArrayKeys( array $values )
197 197
     {
198
-        return static::prefixArrayKeys($values, false);
198
+        return static::prefixArrayKeys( $values, false );
199 199
     }
200 200
 }
Please login to merge, or discard this patch.
plugin/Modules/Multilingual.php 2 patches
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -14,50 +14,50 @@
 block discarded – undo
14 14
  */
15 15
 class Multilingual
16 16
 {
17
-    protected $integration;
17
+	protected $integration;
18 18
 
19
-    /**
20
-     * @param string $method
21
-     * @param array $args
22
-     * @return 
23
-     */
24
-    public function __call($method, $args = [])
25
-    {
26
-        if ($this->isIntegrated() && method_exists($this->integration, $method)) {
27
-            return call_user_func_array([$this->integration, $method], $args);
28
-        }
29
-        return Arr::get($args, 0, false);
30
-    }
19
+	/**
20
+	 * @param string $method
21
+	 * @param array $args
22
+	 * @return 
23
+	 */
24
+	public function __call($method, $args = [])
25
+	{
26
+		if ($this->isIntegrated() && method_exists($this->integration, $method)) {
27
+			return call_user_func_array([$this->integration, $method], $args);
28
+		}
29
+		return Arr::get($args, 0, false);
30
+	}
31 31
 
32
-    /**
33
-     * @param string $integration
34
-     * @return false|\GeminiLabs\SiteReviews\Modules\Multilingual\Polylang|\GeminiLabs\SiteReviews\Modules\Multilingual\Wpml
35
-     */
36
-    public function getIntegration($integration = '')
37
-    {
38
-        if (empty($integration)) {
39
-            $integration = ucfirst(glsr(OptionManager::class)->get('settings.general.multilingual'));
40
-        }
41
-        $integrationClass = 'GeminiLabs\SiteReviews\Modules\Multilingual\\'.$integration;
42
-        if (class_exists($integrationClass)) {
43
-            return glsr($integrationClass);
44
-        }
45
-        glsr_log()->error($integrationClass.' does not exist');
46
-        return false;
47
-    }
32
+	/**
33
+	 * @param string $integration
34
+	 * @return false|\GeminiLabs\SiteReviews\Modules\Multilingual\Polylang|\GeminiLabs\SiteReviews\Modules\Multilingual\Wpml
35
+	 */
36
+	public function getIntegration($integration = '')
37
+	{
38
+		if (empty($integration)) {
39
+			$integration = ucfirst(glsr(OptionManager::class)->get('settings.general.multilingual'));
40
+		}
41
+		$integrationClass = 'GeminiLabs\SiteReviews\Modules\Multilingual\\'.$integration;
42
+		if (class_exists($integrationClass)) {
43
+			return glsr($integrationClass);
44
+		}
45
+		glsr_log()->error($integrationClass.' does not exist');
46
+		return false;
47
+	}
48 48
 
49
-    /**
50
-     * return bool
51
-     */
52
-    public function isIntegrated()
53
-    {
54
-        if (!empty($this->integration)) {
55
-            return true;
56
-        }
57
-        if ($integration = $this->getIntegration()) {
58
-            $this->integration = $integration;
59
-            return true;
60
-        }
61
-        return false;
62
-    }
49
+	/**
50
+	 * return bool
51
+	 */
52
+	public function isIntegrated()
53
+	{
54
+		if (!empty($this->integration)) {
55
+			return true;
56
+		}
57
+		if ($integration = $this->getIntegration()) {
58
+			$this->integration = $integration;
59
+			return true;
60
+		}
61
+		return false;
62
+	}
63 63
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -21,28 +21,28 @@  discard block
 block discarded – undo
21 21
      * @param array $args
22 22
      * @return 
23 23
      */
24
-    public function __call($method, $args = [])
24
+    public function __call( $method, $args = [] )
25 25
     {
26
-        if ($this->isIntegrated() && method_exists($this->integration, $method)) {
27
-            return call_user_func_array([$this->integration, $method], $args);
26
+        if( $this->isIntegrated() && method_exists( $this->integration, $method ) ) {
27
+            return call_user_func_array( [$this->integration, $method], $args );
28 28
         }
29
-        return Arr::get($args, 0, false);
29
+        return Arr::get( $args, 0, false );
30 30
     }
31 31
 
32 32
     /**
33 33
      * @param string $integration
34 34
      * @return false|\GeminiLabs\SiteReviews\Modules\Multilingual\Polylang|\GeminiLabs\SiteReviews\Modules\Multilingual\Wpml
35 35
      */
36
-    public function getIntegration($integration = '')
36
+    public function getIntegration( $integration = '' )
37 37
     {
38
-        if (empty($integration)) {
39
-            $integration = ucfirst(glsr(OptionManager::class)->get('settings.general.multilingual'));
38
+        if( empty($integration) ) {
39
+            $integration = ucfirst( glsr( OptionManager::class )->get( 'settings.general.multilingual' ) );
40 40
         }
41 41
         $integrationClass = 'GeminiLabs\SiteReviews\Modules\Multilingual\\'.$integration;
42
-        if (class_exists($integrationClass)) {
43
-            return glsr($integrationClass);
42
+        if( class_exists( $integrationClass ) ) {
43
+            return glsr( $integrationClass );
44 44
         }
45
-        glsr_log()->error($integrationClass.' does not exist');
45
+        glsr_log()->error( $integrationClass.' does not exist' );
46 46
         return false;
47 47
     }
48 48
 
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
      */
52 52
     public function isIntegrated()
53 53
     {
54
-        if (!empty($this->integration)) {
54
+        if( !empty($this->integration) ) {
55 55
             return true;
56 56
         }
57
-        if ($integration = $this->getIntegration()) {
57
+        if( $integration = $this->getIntegration() ) {
58 58
             $this->integration = $integration;
59 59
             return true;
60 60
         }
Please login to merge, or discard this patch.
plugin/Modules/Multilingual/Wpml.php 2 patches
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -8,75 +8,75 @@
 block discarded – undo
8 8
 
9 9
 class Wpml implements Contract
10 10
 {
11
-    public $pluginName = 'WPML';
12
-    public $supportedVersion = '3.3.5';
11
+	public $pluginName = 'WPML';
12
+	public $supportedVersion = '3.3.5';
13 13
 
14
-    /**
15
-     * {@inheritdoc}
16
-     */
17
-    public function getPost($postId)
18
-    {
19
-        $postId = trim($postId);
20
-        if (!is_numeric($postId)) {
21
-            return;
22
-        }
23
-        if ($this->isEnabled()) {
24
-            $postId = apply_filters('wpml_object_id', $postId, 'any', true);
25
-        }
26
-        return get_post(intval($postId));
27
-    }
14
+	/**
15
+	 * {@inheritdoc}
16
+	 */
17
+	public function getPost($postId)
18
+	{
19
+		$postId = trim($postId);
20
+		if (!is_numeric($postId)) {
21
+			return;
22
+		}
23
+		if ($this->isEnabled()) {
24
+			$postId = apply_filters('wpml_object_id', $postId, 'any', true);
25
+		}
26
+		return get_post(intval($postId));
27
+	}
28 28
 
29
-    /**
30
-     * {@inheritdoc}
31
-     */
32
-    public function getPostIds(array $postIds)
33
-    {
34
-        if (!$this->isEnabled()) {
35
-            return $postIds;
36
-        }
37
-        $newPostIds = [];
38
-        foreach (Arr::unique($postIds) as $postId) {
39
-            $postType = get_post_type($postId);
40
-            if (!$postType) {
41
-                continue;
42
-            }
43
-            $elementType = 'post_'.$postType;
44
-            $trid = apply_filters('wpml_element_trid', null, $postId, $elementType);
45
-            $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType);
46
-            if (!is_array($translations)) {
47
-                $translations = [];
48
-            }
49
-            $newPostIds = array_merge(
50
-                $newPostIds,
51
-                array_column($translations, 'element_id')
52
-            );
53
-        }
54
-        return Arr::unique($newPostIds);
55
-    }
29
+	/**
30
+	 * {@inheritdoc}
31
+	 */
32
+	public function getPostIds(array $postIds)
33
+	{
34
+		if (!$this->isEnabled()) {
35
+			return $postIds;
36
+		}
37
+		$newPostIds = [];
38
+		foreach (Arr::unique($postIds) as $postId) {
39
+			$postType = get_post_type($postId);
40
+			if (!$postType) {
41
+				continue;
42
+			}
43
+			$elementType = 'post_'.$postType;
44
+			$trid = apply_filters('wpml_element_trid', null, $postId, $elementType);
45
+			$translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType);
46
+			if (!is_array($translations)) {
47
+				$translations = [];
48
+			}
49
+			$newPostIds = array_merge(
50
+				$newPostIds,
51
+				array_column($translations, 'element_id')
52
+			);
53
+		}
54
+		return Arr::unique($newPostIds);
55
+	}
56 56
 
57
-    /**
58
-     * {@inheritdoc}
59
-     */
60
-    public function isActive()
61
-    {
62
-        return defined('ICL_SITEPRESS_VERSION');
63
-    }
57
+	/**
58
+	 * {@inheritdoc}
59
+	 */
60
+	public function isActive()
61
+	{
62
+		return defined('ICL_SITEPRESS_VERSION');
63
+	}
64 64
 
65
-    /**
66
-     * {@inheritdoc}
67
-     */
68
-    public function isEnabled()
69
-    {
70
-        return $this->isActive()
71
-            && 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual');
72
-    }
65
+	/**
66
+	 * {@inheritdoc}
67
+	 */
68
+	public function isEnabled()
69
+	{
70
+		return $this->isActive()
71
+			&& 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual');
72
+	}
73 73
 
74
-    /**
75
-     * {@inheritdoc}
76
-     */
77
-    public function isSupported()
78
-    {
79
-        return $this->isActive()
80
-            && version_compare(ICL_SITEPRESS_VERSION, $this->supportedVersion, '>=');
81
-    }
74
+	/**
75
+	 * {@inheritdoc}
76
+	 */
77
+	public function isSupported()
78
+	{
79
+		return $this->isActive()
80
+			&& version_compare(ICL_SITEPRESS_VERSION, $this->supportedVersion, '>=');
81
+	}
82 82
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -14,44 +14,44 @@  discard block
 block discarded – undo
14 14
     /**
15 15
      * {@inheritdoc}
16 16
      */
17
-    public function getPost($postId)
17
+    public function getPost( $postId )
18 18
     {
19
-        $postId = trim($postId);
20
-        if (!is_numeric($postId)) {
19
+        $postId = trim( $postId );
20
+        if( !is_numeric( $postId ) ) {
21 21
             return;
22 22
         }
23
-        if ($this->isEnabled()) {
24
-            $postId = apply_filters('wpml_object_id', $postId, 'any', true);
23
+        if( $this->isEnabled() ) {
24
+            $postId = apply_filters( 'wpml_object_id', $postId, 'any', true );
25 25
         }
26
-        return get_post(intval($postId));
26
+        return get_post( intval( $postId ) );
27 27
     }
28 28
 
29 29
     /**
30 30
      * {@inheritdoc}
31 31
      */
32
-    public function getPostIds(array $postIds)
32
+    public function getPostIds( array $postIds )
33 33
     {
34
-        if (!$this->isEnabled()) {
34
+        if( !$this->isEnabled() ) {
35 35
             return $postIds;
36 36
         }
37 37
         $newPostIds = [];
38
-        foreach (Arr::unique($postIds) as $postId) {
39
-            $postType = get_post_type($postId);
40
-            if (!$postType) {
38
+        foreach( Arr::unique( $postIds ) as $postId ) {
39
+            $postType = get_post_type( $postId );
40
+            if( !$postType ) {
41 41
                 continue;
42 42
             }
43 43
             $elementType = 'post_'.$postType;
44
-            $trid = apply_filters('wpml_element_trid', null, $postId, $elementType);
45
-            $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType);
46
-            if (!is_array($translations)) {
44
+            $trid = apply_filters( 'wpml_element_trid', null, $postId, $elementType );
45
+            $translations = apply_filters( 'wpml_get_element_translations', null, $trid, $elementType );
46
+            if( !is_array( $translations ) ) {
47 47
                 $translations = [];
48 48
             }
49 49
             $newPostIds = array_merge(
50 50
                 $newPostIds,
51
-                array_column($translations, 'element_id')
51
+                array_column( $translations, 'element_id' )
52 52
             );
53 53
         }
54
-        return Arr::unique($newPostIds);
54
+        return Arr::unique( $newPostIds );
55 55
     }
56 56
 
57 57
     /**
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
      */
60 60
     public function isActive()
61 61
     {
62
-        return defined('ICL_SITEPRESS_VERSION');
62
+        return defined( 'ICL_SITEPRESS_VERSION' );
63 63
     }
64 64
 
65 65
     /**
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     public function isEnabled()
69 69
     {
70 70
         return $this->isActive()
71
-            && 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual');
71
+            && 'wpml' == glsr( OptionManager::class )->get( 'settings.general.multilingual' );
72 72
     }
73 73
 
74 74
     /**
@@ -77,6 +77,6 @@  discard block
 block discarded – undo
77 77
     public function isSupported()
78 78
     {
79 79
         return $this->isActive()
80
-            && version_compare(ICL_SITEPRESS_VERSION, $this->supportedVersion, '>=');
80
+            && version_compare( ICL_SITEPRESS_VERSION, $this->supportedVersion, '>=' );
81 81
     }
82 82
 }
Please login to merge, or discard this patch.
plugin/Modules/Multilingual/Polylang.php 2 patches
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -8,71 +8,71 @@
 block discarded – undo
8 8
 
9 9
 class Polylang implements Contract
10 10
 {
11
-    public $pluginName = 'Polylang';
12
-    public $supportedVersion = '2.3';
11
+	public $pluginName = 'Polylang';
12
+	public $supportedVersion = '2.3';
13 13
 
14
-    /**
15
-     * {@inheritdoc}
16
-     */
17
-    public function getPost($postId)
18
-    {
19
-        $postId = trim($postId);
20
-        if (!is_numeric($postId)) {
21
-            return;
22
-        }
23
-        if ($this->isEnabled()) {
24
-            $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID()));
25
-        }
26
-        if (!empty($polylangPostId)) {
27
-            $postId = $polylangPostId;
28
-        }
29
-        return get_post(intval($postId));
30
-    }
14
+	/**
15
+	 * {@inheritdoc}
16
+	 */
17
+	public function getPost($postId)
18
+	{
19
+		$postId = trim($postId);
20
+		if (!is_numeric($postId)) {
21
+			return;
22
+		}
23
+		if ($this->isEnabled()) {
24
+			$polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID()));
25
+		}
26
+		if (!empty($polylangPostId)) {
27
+			$postId = $polylangPostId;
28
+		}
29
+		return get_post(intval($postId));
30
+	}
31 31
 
32
-    /**
33
-     * {@inheritdoc}
34
-     */
35
-    public function getPostIds(array $postIds)
36
-    {
37
-        if (!$this->isEnabled()) {
38
-            return $postIds;
39
-        }
40
-        $newPostIds = [];
41
-        foreach (Arr::unique($postIds) as $postId) {
42
-            $newPostIds = array_merge(
43
-                $newPostIds,
44
-                array_values(pll_get_post_translations($postId))
45
-            );
46
-        }
47
-        return Arr::unique($newPostIds);
48
-    }
32
+	/**
33
+	 * {@inheritdoc}
34
+	 */
35
+	public function getPostIds(array $postIds)
36
+	{
37
+		if (!$this->isEnabled()) {
38
+			return $postIds;
39
+		}
40
+		$newPostIds = [];
41
+		foreach (Arr::unique($postIds) as $postId) {
42
+			$newPostIds = array_merge(
43
+				$newPostIds,
44
+				array_values(pll_get_post_translations($postId))
45
+			);
46
+		}
47
+		return Arr::unique($newPostIds);
48
+	}
49 49
 
50
-    /**
51
-     * {@inheritdoc}
52
-     */
53
-    public function isActive()
54
-    {
55
-        return function_exists('PLL')
56
-            && function_exists('pll_get_post')
57
-            && function_exists('pll_get_post_language')
58
-            && function_exists('pll_get_post_translations');
59
-    }
50
+	/**
51
+	 * {@inheritdoc}
52
+	 */
53
+	public function isActive()
54
+	{
55
+		return function_exists('PLL')
56
+			&& function_exists('pll_get_post')
57
+			&& function_exists('pll_get_post_language')
58
+			&& function_exists('pll_get_post_translations');
59
+	}
60 60
 
61
-    /**
62
-     * {@inheritdoc}
63
-     */
64
-    public function isEnabled()
65
-    {
66
-        return $this->isActive()
67
-            && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual');
68
-    }
61
+	/**
62
+	 * {@inheritdoc}
63
+	 */
64
+	public function isEnabled()
65
+	{
66
+		return $this->isActive()
67
+			&& 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual');
68
+	}
69 69
 
70
-    /**
71
-     * {@inheritdoc}
72
-     */
73
-    public function isSupported()
74
-    {
75
-        return defined('POLYLANG_VERSION')
76
-            && version_compare(POLYLANG_VERSION, $this->supportedVersion, '>=');
77
-    }
70
+	/**
71
+	 * {@inheritdoc}
72
+	 */
73
+	public function isSupported()
74
+	{
75
+		return defined('POLYLANG_VERSION')
76
+			&& version_compare(POLYLANG_VERSION, $this->supportedVersion, '>=');
77
+	}
78 78
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -14,37 +14,37 @@  discard block
 block discarded – undo
14 14
     /**
15 15
      * {@inheritdoc}
16 16
      */
17
-    public function getPost($postId)
17
+    public function getPost( $postId )
18 18
     {
19
-        $postId = trim($postId);
20
-        if (!is_numeric($postId)) {
19
+        $postId = trim( $postId );
20
+        if( !is_numeric( $postId ) ) {
21 21
             return;
22 22
         }
23
-        if ($this->isEnabled()) {
24
-            $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID()));
23
+        if( $this->isEnabled() ) {
24
+            $polylangPostId = pll_get_post( $postId, pll_get_post_language( get_the_ID() ) );
25 25
         }
26
-        if (!empty($polylangPostId)) {
26
+        if( !empty($polylangPostId) ) {
27 27
             $postId = $polylangPostId;
28 28
         }
29
-        return get_post(intval($postId));
29
+        return get_post( intval( $postId ) );
30 30
     }
31 31
 
32 32
     /**
33 33
      * {@inheritdoc}
34 34
      */
35
-    public function getPostIds(array $postIds)
35
+    public function getPostIds( array $postIds )
36 36
     {
37
-        if (!$this->isEnabled()) {
37
+        if( !$this->isEnabled() ) {
38 38
             return $postIds;
39 39
         }
40 40
         $newPostIds = [];
41
-        foreach (Arr::unique($postIds) as $postId) {
41
+        foreach( Arr::unique( $postIds ) as $postId ) {
42 42
             $newPostIds = array_merge(
43 43
                 $newPostIds,
44
-                array_values(pll_get_post_translations($postId))
44
+                array_values( pll_get_post_translations( $postId ) )
45 45
             );
46 46
         }
47
-        return Arr::unique($newPostIds);
47
+        return Arr::unique( $newPostIds );
48 48
     }
49 49
 
50 50
     /**
@@ -52,10 +52,10 @@  discard block
 block discarded – undo
52 52
      */
53 53
     public function isActive()
54 54
     {
55
-        return function_exists('PLL')
56
-            && function_exists('pll_get_post')
57
-            && function_exists('pll_get_post_language')
58
-            && function_exists('pll_get_post_translations');
55
+        return function_exists( 'PLL' )
56
+            && function_exists( 'pll_get_post' )
57
+            && function_exists( 'pll_get_post_language' )
58
+            && function_exists( 'pll_get_post_translations' );
59 59
     }
60 60
 
61 61
     /**
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
     public function isEnabled()
65 65
     {
66 66
         return $this->isActive()
67
-            && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual');
67
+            && 'polylang' == glsr( OptionManager::class )->get( 'settings.general.multilingual' );
68 68
     }
69 69
 
70 70
     /**
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
      */
73 73
     public function isSupported()
74 74
     {
75
-        return defined('POLYLANG_VERSION')
76
-            && version_compare(POLYLANG_VERSION, $this->supportedVersion, '>=');
75
+        return defined( 'POLYLANG_VERSION' )
76
+            && version_compare( POLYLANG_VERSION, $this->supportedVersion, '>=' );
77 77
     }
78 78
 }
Please login to merge, or discard this patch.