Passed
Push — master ( b19f24...47cb12 )
by Paul
04:18
created
plugin/Modules/Schema.php 2 patches
Indentation   +308 added lines, -308 removed lines patch added patch discarded remove patch
@@ -12,335 +12,335 @@
 block discarded – undo
12 12
 
13 13
 class Schema
14 14
 {
15
-    /**
16
-     * @var array
17
-     */
18
-    protected $args;
15
+	/**
16
+	 * @var array
17
+	 */
18
+	protected $args;
19 19
 
20
-    /**
21
-     * @var array
22
-     */
23
-    protected $keyValues = [];
20
+	/**
21
+	 * @var array
22
+	 */
23
+	protected $keyValues = [];
24 24
 
25
-    /**
26
-     * @var array
27
-     */
28
-    protected $ratingCounts;
25
+	/**
26
+	 * @var array
27
+	 */
28
+	protected $ratingCounts;
29 29
 
30
-    /**
31
-     * @return array
32
-     */
33
-    public function build(array $args = [])
34
-    {
35
-        $this->args = $args;
36
-        $schema = $this->buildSummary($args);
37
-        if (!empty($schema)) {
38
-            $reviews = $this->buildReviews();
39
-            foreach ($reviews as &$review) {
40
-                unset($review['@context']);
41
-                unset($review['itemReviewed']);
42
-            }
43
-        }
44
-        if (!empty($reviews)) {
45
-            $schema['review'] = $reviews;
46
-        }
47
-        return $schema;
48
-    }
30
+	/**
31
+	 * @return array
32
+	 */
33
+	public function build(array $args = [])
34
+	{
35
+		$this->args = $args;
36
+		$schema = $this->buildSummary($args);
37
+		if (!empty($schema)) {
38
+			$reviews = $this->buildReviews();
39
+			foreach ($reviews as &$review) {
40
+				unset($review['@context']);
41
+				unset($review['itemReviewed']);
42
+			}
43
+		}
44
+		if (!empty($reviews)) {
45
+			$schema['review'] = $reviews;
46
+		}
47
+		return $schema;
48
+	}
49 49
 
50
-    /**
51
-     * @param array|null $args
52
-     * @return array
53
-     */
54
-    public function buildSummary($args = null)
55
-    {
56
-        if (is_array($args)) {
57
-            $this->args = $args;
58
-        }
59
-        $buildSummary = Helper::buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor');
60
-        if ($count = array_sum($this->getRatingCounts())) {
61
-            $schema = method_exists($this, $buildSummary)
62
-                ? $this->$buildSummary()
63
-                : $this->buildSummaryForCustom();
64
-            $schema->aggregateRating(
65
-                $this->getSchemaType('AggregateRating')
66
-                    ->ratingValue($this->getRatingValue())
67
-                    ->reviewCount($count)
68
-                    ->bestRating(glsr()->constant('MAX_RATING', Rating::class))
69
-                    ->worstRating(glsr()->constant('MIN_RATING', Rating::class))
70
-            );
71
-            $schema = $schema->toArray();
72
-            return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args);
73
-        }
74
-        return [];
75
-    }
50
+	/**
51
+	 * @param array|null $args
52
+	 * @return array
53
+	 */
54
+	public function buildSummary($args = null)
55
+	{
56
+		if (is_array($args)) {
57
+			$this->args = $args;
58
+		}
59
+		$buildSummary = Helper::buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor');
60
+		if ($count = array_sum($this->getRatingCounts())) {
61
+			$schema = method_exists($this, $buildSummary)
62
+				? $this->$buildSummary()
63
+				: $this->buildSummaryForCustom();
64
+			$schema->aggregateRating(
65
+				$this->getSchemaType('AggregateRating')
66
+					->ratingValue($this->getRatingValue())
67
+					->reviewCount($count)
68
+					->bestRating(glsr()->constant('MAX_RATING', Rating::class))
69
+					->worstRating(glsr()->constant('MIN_RATING', Rating::class))
70
+			);
71
+			$schema = $schema->toArray();
72
+			return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args);
73
+		}
74
+		return [];
75
+	}
76 76
 
77
-    /**
78
-     * @return void
79
-     */
80
-    public function render()
81
-    {
82
-        if (empty(glsr()->schemas)) {
83
-            return;
84
-        }
85
-        printf('<script type="application/ld+json">%s</script>', json_encode(
86
-            apply_filters('site-reviews/schema/all', glsr()->schemas),
87
-            JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
88
-        ));
89
-    }
77
+	/**
78
+	 * @return void
79
+	 */
80
+	public function render()
81
+	{
82
+		if (empty(glsr()->schemas)) {
83
+			return;
84
+		}
85
+		printf('<script type="application/ld+json">%s</script>', json_encode(
86
+			apply_filters('site-reviews/schema/all', glsr()->schemas),
87
+			JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
88
+		));
89
+	}
90 90
 
91
-    /**
92
-     * @return void
93
-     */
94
-    public function store(array $schema)
95
-    {
96
-        if (empty($schema)) {
97
-            return;
98
-        }
99
-        $schemas = glsr()->schemas;
100
-        $schemas[] = $schema;
101
-        glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas)));
102
-    }
91
+	/**
92
+	 * @return void
93
+	 */
94
+	public function store(array $schema)
95
+	{
96
+		if (empty($schema)) {
97
+			return;
98
+		}
99
+		$schemas = glsr()->schemas;
100
+		$schemas[] = $schema;
101
+		glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas)));
102
+	}
103 103
 
104
-    /**
105
-     * @param Review $review
106
-     * @return array
107
-     */
108
-    protected function buildReview($review)
109
-    {
110
-        $schema = $this->getSchemaType('Review')
111
-            ->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) {
112
-                $schema->name($review->title);
113
-            })
114
-            ->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) {
115
-                $schema->reviewBody($review->content);
116
-            })
117
-            ->datePublished((new DateTime($review->date)))
118
-            ->author($this->getSchemaType('Person')->name($review->author))
119
-            ->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name')));
120
-        if (!empty($review->rating)) {
121
-            $schema->reviewRating(
122
-                $this->getSchemaType('Rating')
123
-                    ->ratingValue($review->rating)
124
-                    ->bestRating(glsr()->constant('MAX_RATING', Rating::class))
125
-                    ->worstRating(glsr()->constant('MIN_RATING', Rating::class))
126
-            );
127
-        }
128
-        return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args);
129
-    }
104
+	/**
105
+	 * @param Review $review
106
+	 * @return array
107
+	 */
108
+	protected function buildReview($review)
109
+	{
110
+		$schema = $this->getSchemaType('Review')
111
+			->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) {
112
+				$schema->name($review->title);
113
+			})
114
+			->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) {
115
+				$schema->reviewBody($review->content);
116
+			})
117
+			->datePublished((new DateTime($review->date)))
118
+			->author($this->getSchemaType('Person')->name($review->author))
119
+			->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name')));
120
+		if (!empty($review->rating)) {
121
+			$schema->reviewRating(
122
+				$this->getSchemaType('Rating')
123
+					->ratingValue($review->rating)
124
+					->bestRating(glsr()->constant('MAX_RATING', Rating::class))
125
+					->worstRating(glsr()->constant('MIN_RATING', Rating::class))
126
+			);
127
+		}
128
+		return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args);
129
+	}
130 130
 
131
-    /**
132
-     * @return array
133
-     */
134
-    protected function buildReviews()
135
-    {
136
-        $reviews = [];
137
-        foreach (glsr(ReviewManager::class)->get($this->args) as $review) {
138
-            // Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews.
139
-            // @see https://developers.google.com/search/docs/data-types/review
140
-            if ('local' === $review->review_type) {
141
-                $reviews[] = $this->buildReview($review);
142
-            }
143
-        }
144
-        return $reviews;
145
-    }
131
+	/**
132
+	 * @return array
133
+	 */
134
+	protected function buildReviews()
135
+	{
136
+		$reviews = [];
137
+		foreach (glsr(ReviewManager::class)->get($this->args) as $review) {
138
+			// Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews.
139
+			// @see https://developers.google.com/search/docs/data-types/review
140
+			if ('local' === $review->review_type) {
141
+				$reviews[] = $this->buildReview($review);
142
+			}
143
+		}
144
+		return $reviews;
145
+	}
146 146
 
147
-    /**
148
-     * @param mixed $schema
149
-     * @return mixed
150
-     */
151
-    protected function buildSchemaValues($schema, array $values = [])
152
-    {
153
-        foreach ($values as $value) {
154
-            $option = $this->getSchemaOptionValue($value);
155
-            if (empty($option)) {
156
-                continue;
157
-            }
158
-            $schema->$value($option);
159
-        }
160
-        return $schema;
161
-    }
147
+	/**
148
+	 * @param mixed $schema
149
+	 * @return mixed
150
+	 */
151
+	protected function buildSchemaValues($schema, array $values = [])
152
+	{
153
+		foreach ($values as $value) {
154
+			$option = $this->getSchemaOptionValue($value);
155
+			if (empty($option)) {
156
+				continue;
157
+			}
158
+			$schema->$value($option);
159
+		}
160
+		return $schema;
161
+	}
162 162
 
163
-    /**
164
-     * @return mixed
165
-     */
166
-    protected function buildSummaryForCustom()
167
-    {
168
-        return $this->buildSchemaValues($this->getSchemaType(), [
169
-            'description', 'image', 'name', 'url',
170
-        ]);
171
-    }
163
+	/**
164
+	 * @return mixed
165
+	 */
166
+	protected function buildSummaryForCustom()
167
+	{
168
+		return $this->buildSchemaValues($this->getSchemaType(), [
169
+			'description', 'image', 'name', 'url',
170
+		]);
171
+	}
172 172
 
173
-    /**
174
-     * @return mixed
175
-     */
176
-    protected function buildSummaryForLocalBusiness()
177
-    {
178
-        return $this->buildSchemaValues($this->buildSummaryForCustom(), [
179
-            'address', 'priceRange', 'telephone',
180
-        ]);
181
-    }
173
+	/**
174
+	 * @return mixed
175
+	 */
176
+	protected function buildSummaryForLocalBusiness()
177
+	{
178
+		return $this->buildSchemaValues($this->buildSummaryForCustom(), [
179
+			'address', 'priceRange', 'telephone',
180
+		]);
181
+	}
182 182
 
183
-    /**
184
-     * @return mixed
185
-     */
186
-    protected function buildSummaryForProduct()
187
-    {
188
-        $offerType = $this->getSchemaOption('offerType', 'AggregateOffer');
189
-        $offers = $this->buildSchemaValues($this->getSchemaType($offerType), [
190
-            'highPrice', 'lowPrice', 'price', 'priceCurrency',
191
-        ]);
192
-        return $this->buildSummaryForCustom()
193
-            ->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) {
194
-                $schema->offers($offers);
195
-            })
196
-            ->setProperty('@id', $this->getSchemaOptionValue('url').'#product');
197
-    }
183
+	/**
184
+	 * @return mixed
185
+	 */
186
+	protected function buildSummaryForProduct()
187
+	{
188
+		$offerType = $this->getSchemaOption('offerType', 'AggregateOffer');
189
+		$offers = $this->buildSchemaValues($this->getSchemaType($offerType), [
190
+			'highPrice', 'lowPrice', 'price', 'priceCurrency',
191
+		]);
192
+		return $this->buildSummaryForCustom()
193
+			->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) {
194
+				$schema->offers($offers);
195
+			})
196
+			->setProperty('@id', $this->getSchemaOptionValue('url').'#product');
197
+	}
198 198
 
199
-    /**
200
-     * @return array
201
-     */
202
-    protected function getRatingCounts()
203
-    {
204
-        if (!isset($this->ratingCounts)) {
205
-            $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args);
206
-        }
207
-        return $this->ratingCounts;
208
-    }
199
+	/**
200
+	 * @return array
201
+	 */
202
+	protected function getRatingCounts()
203
+	{
204
+		if (!isset($this->ratingCounts)) {
205
+			$this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args);
206
+		}
207
+		return $this->ratingCounts;
208
+	}
209 209
 
210
-    /**
211
-     * @return int|float
212
-     */
213
-    protected function getRatingValue()
214
-    {
215
-        return glsr(Rating::class)->getAverage($this->getRatingCounts());
216
-    }
210
+	/**
211
+	 * @return int|float
212
+	 */
213
+	protected function getRatingValue()
214
+	{
215
+		return glsr(Rating::class)->getAverage($this->getRatingCounts());
216
+	}
217 217
 
218
-    /**
219
-     * @param string $option
220
-     * @param string $fallback
221
-     * @return string
222
-     */
223
-    protected function getSchemaOption($option, $fallback)
224
-    {
225
-        $option = strtolower($option);
226
-        if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) {
227
-            return $schemaOption;
228
-        }
229
-        $setting = glsr(OptionManager::class)->get('settings.schema.'.$option);
230
-        if (is_array($setting)) {
231
-            return $this->getSchemaOptionDefault($setting, $fallback);
232
-        }
233
-        return !empty($setting)
234
-            ? $setting
235
-            : $fallback;
236
-    }
218
+	/**
219
+	 * @param string $option
220
+	 * @param string $fallback
221
+	 * @return string
222
+	 */
223
+	protected function getSchemaOption($option, $fallback)
224
+	{
225
+		$option = strtolower($option);
226
+		if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) {
227
+			return $schemaOption;
228
+		}
229
+		$setting = glsr(OptionManager::class)->get('settings.schema.'.$option);
230
+		if (is_array($setting)) {
231
+			return $this->getSchemaOptionDefault($setting, $fallback);
232
+		}
233
+		return !empty($setting)
234
+			? $setting
235
+			: $fallback;
236
+	}
237 237
 
238
-    /**
239
-     * @param string $fallback
240
-     * @return string
241
-     */
242
-    protected function getSchemaOptionDefault(array $setting, $fallback)
243
-    {
244
-        $setting = wp_parse_args($setting, [
245
-            'custom' => '',
246
-            'default' => $fallback,
247
-        ]);
248
-        return 'custom' != $setting['default']
249
-            ? $setting['default']
250
-            : $setting['custom'];
251
-    }
238
+	/**
239
+	 * @param string $fallback
240
+	 * @return string
241
+	 */
242
+	protected function getSchemaOptionDefault(array $setting, $fallback)
243
+	{
244
+		$setting = wp_parse_args($setting, [
245
+			'custom' => '',
246
+			'default' => $fallback,
247
+		]);
248
+		return 'custom' != $setting['default']
249
+			? $setting['default']
250
+			: $setting['custom'];
251
+	}
252 252
 
253
-    /**
254
-     * @param string $option
255
-     * @param string $fallback
256
-     * @return void|string
257
-     */
258
-    protected function getSchemaOptionValue($option, $fallback = 'post')
259
-    {
260
-        if (array_key_exists($option, $this->keyValues)) {
261
-            return $this->keyValues[$option];
262
-        }
263
-        $value = $this->getSchemaOption($option, $fallback);
264
-        if ($value != $fallback) {
265
-            return $this->setAndGetKeyValue($option, $value);
266
-        }
267
-        if (!is_single() && !is_page()) {
268
-            return;
269
-        }
270
-        $method = Helper::buildMethodName($option, 'getThing');
271
-        if (method_exists($this, $method)) {
272
-            return $this->setAndGetKeyValue($option, $this->$method());
273
-        }
274
-    }
253
+	/**
254
+	 * @param string $option
255
+	 * @param string $fallback
256
+	 * @return void|string
257
+	 */
258
+	protected function getSchemaOptionValue($option, $fallback = 'post')
259
+	{
260
+		if (array_key_exists($option, $this->keyValues)) {
261
+			return $this->keyValues[$option];
262
+		}
263
+		$value = $this->getSchemaOption($option, $fallback);
264
+		if ($value != $fallback) {
265
+			return $this->setAndGetKeyValue($option, $value);
266
+		}
267
+		if (!is_single() && !is_page()) {
268
+			return;
269
+		}
270
+		$method = Helper::buildMethodName($option, 'getThing');
271
+		if (method_exists($this, $method)) {
272
+			return $this->setAndGetKeyValue($option, $this->$method());
273
+		}
274
+	}
275 275
 
276
-    /**
277
-     * @param string|null $type
278
-     * @return mixed
279
-     */
280
-    protected function getSchemaType($type = null)
281
-    {
282
-        if (!is_string($type)) {
283
-            $type = $this->getSchemaOption('type', 'LocalBusiness');
284
-        }
285
-        $className = Helper::buildClassName($type, 'Modules\Schema');
286
-        return class_exists($className)
287
-            ? new $className()
288
-            : new UnknownType($type);
289
-    }
276
+	/**
277
+	 * @param string|null $type
278
+	 * @return mixed
279
+	 */
280
+	protected function getSchemaType($type = null)
281
+	{
282
+		if (!is_string($type)) {
283
+			$type = $this->getSchemaOption('type', 'LocalBusiness');
284
+		}
285
+		$className = Helper::buildClassName($type, 'Modules\Schema');
286
+		return class_exists($className)
287
+			? new $className()
288
+			: new UnknownType($type);
289
+	}
290 290
 
291
-    /**
292
-     * @return string
293
-     */
294
-    protected function getThingDescription()
295
-    {
296
-        $post = get_post();
297
-        $text = Arr::get($post, 'post_excerpt');
298
-        if (empty($text)) {
299
-            $text = Arr::get($post, 'post_content');
300
-        }
301
-        if (function_exists('excerpt_remove_blocks')) {
302
-            $text = excerpt_remove_blocks($text);
303
-        }
304
-        $text = strip_shortcodes($text);
305
-        $text = wpautop($text);
306
-        $text = wptexturize($text);
307
-        $text = wp_strip_all_tags($text);
308
-        $text = str_replace(']]>', ']]&gt;', $text);
309
-        return wp_trim_words($text, apply_filters('excerpt_length', 55));
310
-    }
291
+	/**
292
+	 * @return string
293
+	 */
294
+	protected function getThingDescription()
295
+	{
296
+		$post = get_post();
297
+		$text = Arr::get($post, 'post_excerpt');
298
+		if (empty($text)) {
299
+			$text = Arr::get($post, 'post_content');
300
+		}
301
+		if (function_exists('excerpt_remove_blocks')) {
302
+			$text = excerpt_remove_blocks($text);
303
+		}
304
+		$text = strip_shortcodes($text);
305
+		$text = wpautop($text);
306
+		$text = wptexturize($text);
307
+		$text = wp_strip_all_tags($text);
308
+		$text = str_replace(']]>', ']]&gt;', $text);
309
+		return wp_trim_words($text, apply_filters('excerpt_length', 55));
310
+	}
311 311
 
312
-    /**
313
-     * @return string
314
-     */
315
-    protected function getThingImage()
316
-    {
317
-        return (string) get_the_post_thumbnail_url(null, 'large');
318
-    }
312
+	/**
313
+	 * @return string
314
+	 */
315
+	protected function getThingImage()
316
+	{
317
+		return (string) get_the_post_thumbnail_url(null, 'large');
318
+	}
319 319
 
320
-    /**
321
-     * @return string
322
-     */
323
-    protected function getThingName()
324
-    {
325
-        return get_the_title();
326
-    }
320
+	/**
321
+	 * @return string
322
+	 */
323
+	protected function getThingName()
324
+	{
325
+		return get_the_title();
326
+	}
327 327
 
328
-    /**
329
-     * @return string
330
-     */
331
-    protected function getThingUrl()
332
-    {
333
-        return (string) get_the_permalink();
334
-    }
328
+	/**
329
+	 * @return string
330
+	 */
331
+	protected function getThingUrl()
332
+	{
333
+		return (string) get_the_permalink();
334
+	}
335 335
 
336
-    /**
337
-     * @param string $option
338
-     * @param string $value
339
-     * @return string
340
-     */
341
-    protected function setAndGetKeyValue($option, $value)
342
-    {
343
-        $this->keyValues[$option] = $value;
344
-        return $value;
345
-    }
336
+	/**
337
+	 * @param string $option
338
+	 * @param string $value
339
+	 * @return string
340
+	 */
341
+	protected function setAndGetKeyValue($option, $value)
342
+	{
343
+		$this->keyValues[$option] = $value;
344
+		return $value;
345
+	}
346 346
 }
Please login to merge, or discard this patch.
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -30,18 +30,18 @@  discard block
 block discarded – undo
30 30
     /**
31 31
      * @return array
32 32
      */
33
-    public function build(array $args = [])
33
+    public function build( array $args = [] )
34 34
     {
35 35
         $this->args = $args;
36
-        $schema = $this->buildSummary($args);
37
-        if (!empty($schema)) {
36
+        $schema = $this->buildSummary( $args );
37
+        if( !empty($schema) ) {
38 38
             $reviews = $this->buildReviews();
39
-            foreach ($reviews as &$review) {
39
+            foreach( $reviews as &$review ) {
40 40
                 unset($review['@context']);
41 41
                 unset($review['itemReviewed']);
42 42
             }
43 43
         }
44
-        if (!empty($reviews)) {
44
+        if( !empty($reviews) ) {
45 45
             $schema['review'] = $reviews;
46 46
         }
47 47
         return $schema;
@@ -51,25 +51,25 @@  discard block
 block discarded – undo
51 51
      * @param array|null $args
52 52
      * @return array
53 53
      */
54
-    public function buildSummary($args = null)
54
+    public function buildSummary( $args = null )
55 55
     {
56
-        if (is_array($args)) {
56
+        if( is_array( $args ) ) {
57 57
             $this->args = $args;
58 58
         }
59
-        $buildSummary = Helper::buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor');
60
-        if ($count = array_sum($this->getRatingCounts())) {
61
-            $schema = method_exists($this, $buildSummary)
59
+        $buildSummary = Helper::buildMethodName( $this->getSchemaOptionValue( 'type' ), 'buildSummaryFor' );
60
+        if( $count = array_sum( $this->getRatingCounts() ) ) {
61
+            $schema = method_exists( $this, $buildSummary )
62 62
                 ? $this->$buildSummary()
63 63
                 : $this->buildSummaryForCustom();
64 64
             $schema->aggregateRating(
65
-                $this->getSchemaType('AggregateRating')
66
-                    ->ratingValue($this->getRatingValue())
67
-                    ->reviewCount($count)
68
-                    ->bestRating(glsr()->constant('MAX_RATING', Rating::class))
69
-                    ->worstRating(glsr()->constant('MIN_RATING', Rating::class))
65
+                $this->getSchemaType( 'AggregateRating' )
66
+                    ->ratingValue( $this->getRatingValue() )
67
+                    ->reviewCount( $count )
68
+                    ->bestRating( glsr()->constant( 'MAX_RATING', Rating::class ) )
69
+                    ->worstRating( glsr()->constant( 'MIN_RATING', Rating::class ) )
70 70
             );
71 71
             $schema = $schema->toArray();
72
-            return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args);
72
+            return apply_filters( 'site-reviews/schema/'.$schema['@type'], $schema, $args );
73 73
         }
74 74
         return [];
75 75
     }
@@ -79,53 +79,53 @@  discard block
 block discarded – undo
79 79
      */
80 80
     public function render()
81 81
     {
82
-        if (empty(glsr()->schemas)) {
82
+        if( empty(glsr()->schemas) ) {
83 83
             return;
84 84
         }
85
-        printf('<script type="application/ld+json">%s</script>', json_encode(
86
-            apply_filters('site-reviews/schema/all', glsr()->schemas),
85
+        printf( '<script type="application/ld+json">%s</script>', json_encode(
86
+            apply_filters( 'site-reviews/schema/all', glsr()->schemas ),
87 87
             JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
88
-        ));
88
+        ) );
89 89
     }
90 90
 
91 91
     /**
92 92
      * @return void
93 93
      */
94
-    public function store(array $schema)
94
+    public function store( array $schema )
95 95
     {
96
-        if (empty($schema)) {
96
+        if( empty($schema) ) {
97 97
             return;
98 98
         }
99 99
         $schemas = glsr()->schemas;
100 100
         $schemas[] = $schema;
101
-        glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas)));
101
+        glsr()->schemas = array_map( 'unserialize', array_unique( array_map( 'serialize', $schemas ) ) );
102 102
     }
103 103
 
104 104
     /**
105 105
      * @param Review $review
106 106
      * @return array
107 107
      */
108
-    protected function buildReview($review)
108
+    protected function buildReview( $review )
109 109
     {
110
-        $schema = $this->getSchemaType('Review')
111
-            ->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) {
112
-                $schema->name($review->title);
110
+        $schema = $this->getSchemaType( 'Review' )
111
+            ->doIf( !in_array( 'title', $this->args['hide'] ), function( $schema ) use ($review) {
112
+                $schema->name( $review->title );
113 113
             })
114
-            ->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) {
115
-                $schema->reviewBody($review->content);
114
+            ->doIf( !in_array( 'excerpt', $this->args['hide'] ), function( $schema ) use ($review) {
115
+                $schema->reviewBody( $review->content );
116 116
             })
117
-            ->datePublished((new DateTime($review->date)))
118
-            ->author($this->getSchemaType('Person')->name($review->author))
119
-            ->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name')));
120
-        if (!empty($review->rating)) {
117
+            ->datePublished( (new DateTime( $review->date )) )
118
+            ->author( $this->getSchemaType( 'Person' )->name( $review->author ) )
119
+            ->itemReviewed( $this->getSchemaType()->name( $this->getSchemaOptionValue( 'name' ) ) );
120
+        if( !empty($review->rating) ) {
121 121
             $schema->reviewRating(
122
-                $this->getSchemaType('Rating')
123
-                    ->ratingValue($review->rating)
124
-                    ->bestRating(glsr()->constant('MAX_RATING', Rating::class))
125
-                    ->worstRating(glsr()->constant('MIN_RATING', Rating::class))
122
+                $this->getSchemaType( 'Rating' )
123
+                    ->ratingValue( $review->rating )
124
+                    ->bestRating( glsr()->constant( 'MAX_RATING', Rating::class ) )
125
+                    ->worstRating( glsr()->constant( 'MIN_RATING', Rating::class ) )
126 126
             );
127 127
         }
128
-        return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args);
128
+        return apply_filters( 'site-reviews/schema/review', $schema->toArray(), $review, $this->args );
129 129
     }
130 130
 
131 131
     /**
@@ -134,11 +134,11 @@  discard block
 block discarded – undo
134 134
     protected function buildReviews()
135 135
     {
136 136
         $reviews = [];
137
-        foreach (glsr(ReviewManager::class)->get($this->args) as $review) {
137
+        foreach( glsr( ReviewManager::class )->get( $this->args ) as $review ) {
138 138
             // Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews.
139 139
             // @see https://developers.google.com/search/docs/data-types/review
140
-            if ('local' === $review->review_type) {
141
-                $reviews[] = $this->buildReview($review);
140
+            if( 'local' === $review->review_type ) {
141
+                $reviews[] = $this->buildReview( $review );
142 142
             }
143 143
         }
144 144
         return $reviews;
@@ -148,14 +148,14 @@  discard block
 block discarded – undo
148 148
      * @param mixed $schema
149 149
      * @return mixed
150 150
      */
151
-    protected function buildSchemaValues($schema, array $values = [])
151
+    protected function buildSchemaValues( $schema, array $values = [] )
152 152
     {
153
-        foreach ($values as $value) {
154
-            $option = $this->getSchemaOptionValue($value);
155
-            if (empty($option)) {
153
+        foreach( $values as $value ) {
154
+            $option = $this->getSchemaOptionValue( $value );
155
+            if( empty($option) ) {
156 156
                 continue;
157 157
             }
158
-            $schema->$value($option);
158
+            $schema->$value( $option );
159 159
         }
160 160
         return $schema;
161 161
     }
@@ -165,9 +165,9 @@  discard block
 block discarded – undo
165 165
      */
166 166
     protected function buildSummaryForCustom()
167 167
     {
168
-        return $this->buildSchemaValues($this->getSchemaType(), [
168
+        return $this->buildSchemaValues( $this->getSchemaType(), [
169 169
             'description', 'image', 'name', 'url',
170
-        ]);
170
+        ] );
171 171
     }
172 172
 
173 173
     /**
@@ -175,9 +175,9 @@  discard block
 block discarded – undo
175 175
      */
176 176
     protected function buildSummaryForLocalBusiness()
177 177
     {
178
-        return $this->buildSchemaValues($this->buildSummaryForCustom(), [
178
+        return $this->buildSchemaValues( $this->buildSummaryForCustom(), [
179 179
             'address', 'priceRange', 'telephone',
180
-        ]);
180
+        ] );
181 181
     }
182 182
 
183 183
     /**
@@ -185,15 +185,15 @@  discard block
 block discarded – undo
185 185
      */
186 186
     protected function buildSummaryForProduct()
187 187
     {
188
-        $offerType = $this->getSchemaOption('offerType', 'AggregateOffer');
189
-        $offers = $this->buildSchemaValues($this->getSchemaType($offerType), [
188
+        $offerType = $this->getSchemaOption( 'offerType', 'AggregateOffer' );
189
+        $offers = $this->buildSchemaValues( $this->getSchemaType( $offerType ), [
190 190
             'highPrice', 'lowPrice', 'price', 'priceCurrency',
191
-        ]);
191
+        ] );
192 192
         return $this->buildSummaryForCustom()
193
-            ->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) {
194
-                $schema->offers($offers);
193
+            ->doIf( !empty($offers->getProperties()), function( $schema ) use ($offers) {
194
+                $schema->offers( $offers );
195 195
             })
196
-            ->setProperty('@id', $this->getSchemaOptionValue('url').'#product');
196
+            ->setProperty( '@id', $this->getSchemaOptionValue( 'url' ).'#product' );
197 197
     }
198 198
 
199 199
     /**
@@ -201,8 +201,8 @@  discard block
 block discarded – undo
201 201
      */
202 202
     protected function getRatingCounts()
203 203
     {
204
-        if (!isset($this->ratingCounts)) {
205
-            $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args);
204
+        if( !isset($this->ratingCounts) ) {
205
+            $this->ratingCounts = glsr( ReviewManager::class )->getRatingCounts( $this->args );
206 206
         }
207 207
         return $this->ratingCounts;
208 208
     }
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
      */
213 213
     protected function getRatingValue()
214 214
     {
215
-        return glsr(Rating::class)->getAverage($this->getRatingCounts());
215
+        return glsr( Rating::class )->getAverage( $this->getRatingCounts() );
216 216
     }
217 217
 
218 218
     /**
@@ -220,15 +220,15 @@  discard block
 block discarded – undo
220 220
      * @param string $fallback
221 221
      * @return string
222 222
      */
223
-    protected function getSchemaOption($option, $fallback)
223
+    protected function getSchemaOption( $option, $fallback )
224 224
     {
225
-        $option = strtolower($option);
226
-        if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) {
225
+        $option = strtolower( $option );
226
+        if( $schemaOption = trim( (string)get_post_meta( intval( get_the_ID() ), 'schema_'.$option, true ) ) ) {
227 227
             return $schemaOption;
228 228
         }
229
-        $setting = glsr(OptionManager::class)->get('settings.schema.'.$option);
230
-        if (is_array($setting)) {
231
-            return $this->getSchemaOptionDefault($setting, $fallback);
229
+        $setting = glsr( OptionManager::class )->get( 'settings.schema.'.$option );
230
+        if( is_array( $setting ) ) {
231
+            return $this->getSchemaOptionDefault( $setting, $fallback );
232 232
         }
233 233
         return !empty($setting)
234 234
             ? $setting
@@ -239,12 +239,12 @@  discard block
 block discarded – undo
239 239
      * @param string $fallback
240 240
      * @return string
241 241
      */
242
-    protected function getSchemaOptionDefault(array $setting, $fallback)
242
+    protected function getSchemaOptionDefault( array $setting, $fallback )
243 243
     {
244
-        $setting = wp_parse_args($setting, [
244
+        $setting = wp_parse_args( $setting, [
245 245
             'custom' => '',
246 246
             'default' => $fallback,
247
-        ]);
247
+        ] );
248 248
         return 'custom' != $setting['default']
249 249
             ? $setting['default']
250 250
             : $setting['custom'];
@@ -255,21 +255,21 @@  discard block
 block discarded – undo
255 255
      * @param string $fallback
256 256
      * @return void|string
257 257
      */
258
-    protected function getSchemaOptionValue($option, $fallback = 'post')
258
+    protected function getSchemaOptionValue( $option, $fallback = 'post' )
259 259
     {
260
-        if (array_key_exists($option, $this->keyValues)) {
260
+        if( array_key_exists( $option, $this->keyValues ) ) {
261 261
             return $this->keyValues[$option];
262 262
         }
263
-        $value = $this->getSchemaOption($option, $fallback);
264
-        if ($value != $fallback) {
265
-            return $this->setAndGetKeyValue($option, $value);
263
+        $value = $this->getSchemaOption( $option, $fallback );
264
+        if( $value != $fallback ) {
265
+            return $this->setAndGetKeyValue( $option, $value );
266 266
         }
267
-        if (!is_single() && !is_page()) {
267
+        if( !is_single() && !is_page() ) {
268 268
             return;
269 269
         }
270
-        $method = Helper::buildMethodName($option, 'getThing');
271
-        if (method_exists($this, $method)) {
272
-            return $this->setAndGetKeyValue($option, $this->$method());
270
+        $method = Helper::buildMethodName( $option, 'getThing' );
271
+        if( method_exists( $this, $method ) ) {
272
+            return $this->setAndGetKeyValue( $option, $this->$method() );
273 273
         }
274 274
     }
275 275
 
@@ -277,15 +277,15 @@  discard block
 block discarded – undo
277 277
      * @param string|null $type
278 278
      * @return mixed
279 279
      */
280
-    protected function getSchemaType($type = null)
280
+    protected function getSchemaType( $type = null )
281 281
     {
282
-        if (!is_string($type)) {
283
-            $type = $this->getSchemaOption('type', 'LocalBusiness');
282
+        if( !is_string( $type ) ) {
283
+            $type = $this->getSchemaOption( 'type', 'LocalBusiness' );
284 284
         }
285
-        $className = Helper::buildClassName($type, 'Modules\Schema');
286
-        return class_exists($className)
285
+        $className = Helper::buildClassName( $type, 'Modules\Schema' );
286
+        return class_exists( $className )
287 287
             ? new $className()
288
-            : new UnknownType($type);
288
+            : new UnknownType( $type );
289 289
     }
290 290
 
291 291
     /**
@@ -294,19 +294,19 @@  discard block
 block discarded – undo
294 294
     protected function getThingDescription()
295 295
     {
296 296
         $post = get_post();
297
-        $text = Arr::get($post, 'post_excerpt');
298
-        if (empty($text)) {
299
-            $text = Arr::get($post, 'post_content');
297
+        $text = Arr::get( $post, 'post_excerpt' );
298
+        if( empty($text) ) {
299
+            $text = Arr::get( $post, 'post_content' );
300 300
         }
301
-        if (function_exists('excerpt_remove_blocks')) {
302
-            $text = excerpt_remove_blocks($text);
301
+        if( function_exists( 'excerpt_remove_blocks' ) ) {
302
+            $text = excerpt_remove_blocks( $text );
303 303
         }
304
-        $text = strip_shortcodes($text);
305
-        $text = wpautop($text);
306
-        $text = wptexturize($text);
307
-        $text = wp_strip_all_tags($text);
308
-        $text = str_replace(']]>', ']]&gt;', $text);
309
-        return wp_trim_words($text, apply_filters('excerpt_length', 55));
304
+        $text = strip_shortcodes( $text );
305
+        $text = wpautop( $text );
306
+        $text = wptexturize( $text );
307
+        $text = wp_strip_all_tags( $text );
308
+        $text = str_replace( ']]>', ']]&gt;', $text );
309
+        return wp_trim_words( $text, apply_filters( 'excerpt_length', 55 ) );
310 310
     }
311 311
 
312 312
     /**
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
      */
315 315
     protected function getThingImage()
316 316
     {
317
-        return (string) get_the_post_thumbnail_url(null, 'large');
317
+        return (string)get_the_post_thumbnail_url( null, 'large' );
318 318
     }
319 319
 
320 320
     /**
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
      */
331 331
     protected function getThingUrl()
332 332
     {
333
-        return (string) get_the_permalink();
333
+        return (string)get_the_permalink();
334 334
     }
335 335
 
336 336
     /**
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
      * @param string $value
339 339
      * @return string
340 340
      */
341
-    protected function setAndGetKeyValue($option, $value)
341
+    protected function setAndGetKeyValue( $option, $value )
342 342
     {
343 343
         $this->keyValues[$option] = $value;
344 344
         return $value;
Please login to merge, or discard this patch.
plugin/Modules/Date.php 2 patches
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -7,87 +7,87 @@
 block discarded – undo
7 7
 
8 8
 class Date
9 9
 {
10
-    /**
11
-     * [60, 1],
12
-     * [60 * 100, 60],
13
-     * [3600 * 70, 3600],
14
-     * [3600 * 24 * 10, 3600 * 24],
15
-     * [3600 * 24 * 30, 3600 * 24 * 7],
16
-     * [3600 * 24 * 30 * 30, 3600 * 24 * 30],
17
-     * [INF, 3600 * 24 * 265],.
18
-     */
19
-    protected static $TIME_PERIODS = [
20
-        [60, 1],
21
-        [6000, 60],
22
-        [252000, 3600],
23
-        [864000, 86400],
24
-        [2592000, 604800],
25
-        [77760000, 2592000],
26
-        [INF, 22896000],
27
-    ];
10
+	/**
11
+	 * [60, 1],
12
+	 * [60 * 100, 60],
13
+	 * [3600 * 70, 3600],
14
+	 * [3600 * 24 * 10, 3600 * 24],
15
+	 * [3600 * 24 * 30, 3600 * 24 * 7],
16
+	 * [3600 * 24 * 30 * 30, 3600 * 24 * 30],
17
+	 * [INF, 3600 * 24 * 265],.
18
+	 */
19
+	protected static $TIME_PERIODS = [
20
+		[60, 1],
21
+		[6000, 60],
22
+		[252000, 3600],
23
+		[864000, 86400],
24
+		[2592000, 604800],
25
+		[77760000, 2592000],
26
+		[INF, 22896000],
27
+	];
28 28
 
29
-    /**
30
-     * @param mixed $date
31
-     * @param string $format
32
-     * @return bool
33
-     */
34
-    public function isDate($date, $format = 'Y-m-d H:i:s')
35
-    {
36
-        $datetime = DateTime::createFromFormat($format, $date);
37
-        return $datetime && $date == $datetime->format($format);
38
-    }
29
+	/**
30
+	 * @param mixed $date
31
+	 * @param string $format
32
+	 * @return bool
33
+	 */
34
+	public function isDate($date, $format = 'Y-m-d H:i:s')
35
+	{
36
+		$datetime = DateTime::createFromFormat($format, $date);
37
+		return $datetime && $date == $datetime->format($format);
38
+	}
39 39
 
40
-    /**
41
-     * @param mixed $date
42
-     * @return bool
43
-     */
44
-    public function isTimestamp($date)
45
-    {
46
-        return ctype_digit($date)
47
-            ? true
48
-            : false;
49
-    }
40
+	/**
41
+	 * @param mixed $date
42
+	 * @return bool
43
+	 */
44
+	public function isTimestamp($date)
45
+	{
46
+		return ctype_digit($date)
47
+			? true
48
+			: false;
49
+	}
50 50
 
51
-    /**
52
-     * @param mixed $date
53
-     * @param string $fallback
54
-     * @return string
55
-     */
56
-    public function localized($date, $fallback = '')
57
-    {
58
-        return $this->isDate($date) || $this->isTimestamp($date)
59
-            ? date_i18n('Y-m-d H:i', $date)
60
-            : $fallback;
61
-    }
51
+	/**
52
+	 * @param mixed $date
53
+	 * @param string $fallback
54
+	 * @return string
55
+	 */
56
+	public function localized($date, $fallback = '')
57
+	{
58
+		return $this->isDate($date) || $this->isTimestamp($date)
59
+			? date_i18n('Y-m-d H:i', $date)
60
+			: $fallback;
61
+	}
62 62
 
63
-    /**
64
-     * @param mixed $date
65
-     * @return string
66
-     */
67
-    public function relative($date)
68
-    {
69
-        if (!$this->isDate($date)) {
70
-            return '';
71
-        }
72
-        $diff = time() - strtotime($date);
73
-        foreach (static::$TIME_PERIODS as $i => $timePeriod) {
74
-            if ($diff > $timePeriod[0]) {
75
-                continue;
76
-            }
77
-            $unit = intval(floor($diff / $timePeriod[1]));
78
-            $relativeDates = [
79
-                _n('%s second ago', '%s seconds ago', $unit, 'site-reviews'),
80
-                _n('%s minute ago', '%s minutes ago', $unit, 'site-reviews'),
81
-                _n('an hour ago', '%s hours ago', $unit, 'site-reviews'),
82
-                _n('yesterday', '%s days ago', $unit, 'site-reviews'),
83
-                _n('a week ago', '%s weeks ago', $unit, 'site-reviews'),
84
-                _n('%s month ago', '%s months ago', $unit, 'site-reviews'),
85
-                _n('%s year ago', '%s years ago', $unit, 'site-reviews'),
86
-            ];
87
-            $relativeDate = $relativeDates[$i];
88
-            return Str::contains($relativeDate, '%s')
89
-                ? sprintf($relativeDate, $unit)
90
-                : $relativeDate;
91
-        }
92
-    }
63
+	/**
64
+	 * @param mixed $date
65
+	 * @return string
66
+	 */
67
+	public function relative($date)
68
+	{
69
+		if (!$this->isDate($date)) {
70
+			return '';
71
+		}
72
+		$diff = time() - strtotime($date);
73
+		foreach (static::$TIME_PERIODS as $i => $timePeriod) {
74
+			if ($diff > $timePeriod[0]) {
75
+				continue;
76
+			}
77
+			$unit = intval(floor($diff / $timePeriod[1]));
78
+			$relativeDates = [
79
+				_n('%s second ago', '%s seconds ago', $unit, 'site-reviews'),
80
+				_n('%s minute ago', '%s minutes ago', $unit, 'site-reviews'),
81
+				_n('an hour ago', '%s hours ago', $unit, 'site-reviews'),
82
+				_n('yesterday', '%s days ago', $unit, 'site-reviews'),
83
+				_n('a week ago', '%s weeks ago', $unit, 'site-reviews'),
84
+				_n('%s month ago', '%s months ago', $unit, 'site-reviews'),
85
+				_n('%s year ago', '%s years ago', $unit, 'site-reviews'),
86
+			];
87
+			$relativeDate = $relativeDates[$i];
88
+			return Str::contains($relativeDate, '%s')
89
+				? sprintf($relativeDate, $unit)
90
+				: $relativeDate;
91
+		}
92
+	}
93 93
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -31,19 +31,19 @@  discard block
 block discarded – undo
31 31
      * @param string $format
32 32
      * @return bool
33 33
      */
34
-    public function isDate($date, $format = 'Y-m-d H:i:s')
34
+    public function isDate( $date, $format = 'Y-m-d H:i:s' )
35 35
     {
36
-        $datetime = DateTime::createFromFormat($format, $date);
37
-        return $datetime && $date == $datetime->format($format);
36
+        $datetime = DateTime::createFromFormat( $format, $date );
37
+        return $datetime && $date == $datetime->format( $format );
38 38
     }
39 39
 
40 40
     /**
41 41
      * @param mixed $date
42 42
      * @return bool
43 43
      */
44
-    public function isTimestamp($date)
44
+    public function isTimestamp( $date )
45 45
     {
46
-        return ctype_digit($date)
46
+        return ctype_digit( $date )
47 47
             ? true
48 48
             : false;
49 49
     }
@@ -53,10 +53,10 @@  discard block
 block discarded – undo
53 53
      * @param string $fallback
54 54
      * @return string
55 55
      */
56
-    public function localized($date, $fallback = '')
56
+    public function localized( $date, $fallback = '' )
57 57
     {
58
-        return $this->isDate($date) || $this->isTimestamp($date)
59
-            ? date_i18n('Y-m-d H:i', $date)
58
+        return $this->isDate( $date ) || $this->isTimestamp( $date )
59
+            ? date_i18n( 'Y-m-d H:i', $date )
60 60
             : $fallback;
61 61
     }
62 62
 
@@ -64,29 +64,29 @@  discard block
 block discarded – undo
64 64
      * @param mixed $date
65 65
      * @return string
66 66
      */
67
-    public function relative($date)
67
+    public function relative( $date )
68 68
     {
69
-        if (!$this->isDate($date)) {
69
+        if( !$this->isDate( $date ) ) {
70 70
             return '';
71 71
         }
72
-        $diff = time() - strtotime($date);
73
-        foreach (static::$TIME_PERIODS as $i => $timePeriod) {
74
-            if ($diff > $timePeriod[0]) {
72
+        $diff = time() - strtotime( $date );
73
+        foreach( static::$TIME_PERIODS as $i => $timePeriod ) {
74
+            if( $diff > $timePeriod[0] ) {
75 75
                 continue;
76 76
             }
77
-            $unit = intval(floor($diff / $timePeriod[1]));
77
+            $unit = intval( floor( $diff / $timePeriod[1] ) );
78 78
             $relativeDates = [
79
-                _n('%s second ago', '%s seconds ago', $unit, 'site-reviews'),
80
-                _n('%s minute ago', '%s minutes ago', $unit, 'site-reviews'),
81
-                _n('an hour ago', '%s hours ago', $unit, 'site-reviews'),
82
-                _n('yesterday', '%s days ago', $unit, 'site-reviews'),
83
-                _n('a week ago', '%s weeks ago', $unit, 'site-reviews'),
84
-                _n('%s month ago', '%s months ago', $unit, 'site-reviews'),
85
-                _n('%s year ago', '%s years ago', $unit, 'site-reviews'),
79
+                _n( '%s second ago', '%s seconds ago', $unit, 'site-reviews' ),
80
+                _n( '%s minute ago', '%s minutes ago', $unit, 'site-reviews' ),
81
+                _n( 'an hour ago', '%s hours ago', $unit, 'site-reviews' ),
82
+                _n( 'yesterday', '%s days ago', $unit, 'site-reviews' ),
83
+                _n( 'a week ago', '%s weeks ago', $unit, 'site-reviews' ),
84
+                _n( '%s month ago', '%s months ago', $unit, 'site-reviews' ),
85
+                _n( '%s year ago', '%s years ago', $unit, 'site-reviews' ),
86 86
             ];
87 87
             $relativeDate = $relativeDates[$i];
88
-            return Str::contains($relativeDate, '%s')
89
-                ? sprintf($relativeDate, $unit)
88
+            return Str::contains( $relativeDate, '%s' )
89
+                ? sprintf( $relativeDate, $unit )
90 90
                 : $relativeDate;
91 91
         }
92 92
     }
Please login to merge, or discard this patch.
plugin/Modules/Migrations/Migrate_4_0_2.php 2 patches
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -9,70 +9,70 @@
 block discarded – undo
9 9
 
10 10
 class Migrate_4_0_2
11 11
 {
12
-    /**
13
-     * @return void
14
-     */
15
-    public function deleteSessions()
16
-    {
17
-        global $wpdb;
18
-        $wpdb->query("
12
+	/**
13
+	 * @return void
14
+	 */
15
+	public function deleteSessions()
16
+	{
17
+		global $wpdb;
18
+		$wpdb->query("
19 19
             DELETE
20 20
             FROM {$wpdb->options}
21 21
             WHERE option_name LIKE '_glsr_session%'
22 22
         ");
23
-    }
23
+	}
24 24
 
25
-    /**
26
-     * @return void
27
-     */
28
-    public function migrateSettings()
29
-    {
30
-        if ($settings = get_option(OptionManager::databaseKey(3))) {
31
-            $multilingual = 'yes' == Arr::get($settings, 'settings.general.support.polylang')
32
-                ? 'polylang'
33
-                : '';
34
-            $settings = Arr::set($settings, 'settings.general.multilingual', $multilingual);
35
-            $settings = Arr::set($settings, 'settings.general.rebusify', 'no');
36
-            $settings = Arr::set($settings, 'settings.general.rebusify_email', '');
37
-            $settings = Arr::set($settings, 'settings.general.rebusify_serial', '');
38
-            $settings = Arr::set($settings, 'settings.reviews.name.format', '');
39
-            $settings = Arr::set($settings, 'settings.reviews.name.initial', '');
40
-            $settings = Arr::set($settings, 'settings.submissions.blacklist.integration', '');
41
-            $settings = Arr::set($settings, 'settings.submissions.limit', '');
42
-            $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.email', '');
43
-            $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.ip_address', '');
44
-            $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.username', '');
45
-            unset($settings['settings']['general']['support']);
46
-            update_option(OptionManager::databaseKey(4), $settings);
47
-        }
48
-    }
25
+	/**
26
+	 * @return void
27
+	 */
28
+	public function migrateSettings()
29
+	{
30
+		if ($settings = get_option(OptionManager::databaseKey(3))) {
31
+			$multilingual = 'yes' == Arr::get($settings, 'settings.general.support.polylang')
32
+				? 'polylang'
33
+				: '';
34
+			$settings = Arr::set($settings, 'settings.general.multilingual', $multilingual);
35
+			$settings = Arr::set($settings, 'settings.general.rebusify', 'no');
36
+			$settings = Arr::set($settings, 'settings.general.rebusify_email', '');
37
+			$settings = Arr::set($settings, 'settings.general.rebusify_serial', '');
38
+			$settings = Arr::set($settings, 'settings.reviews.name.format', '');
39
+			$settings = Arr::set($settings, 'settings.reviews.name.initial', '');
40
+			$settings = Arr::set($settings, 'settings.submissions.blacklist.integration', '');
41
+			$settings = Arr::set($settings, 'settings.submissions.limit', '');
42
+			$settings = Arr::set($settings, 'settings.submissions.limit_whitelist.email', '');
43
+			$settings = Arr::set($settings, 'settings.submissions.limit_whitelist.ip_address', '');
44
+			$settings = Arr::set($settings, 'settings.submissions.limit_whitelist.username', '');
45
+			unset($settings['settings']['general']['support']);
46
+			update_option(OptionManager::databaseKey(4), $settings);
47
+		}
48
+	}
49 49
 
50
-    /**
51
-     * @return void
52
-     */
53
-    public function protectMetaKeys()
54
-    {
55
-        global $wpdb;
56
-        $keys = array_keys(glsr(CreateReviewDefaults::class)->defaults());
57
-        $keys = implode("','", $keys);
58
-        $postType = Application::POST_TYPE;
59
-        $wpdb->query("
50
+	/**
51
+	 * @return void
52
+	 */
53
+	public function protectMetaKeys()
54
+	{
55
+		global $wpdb;
56
+		$keys = array_keys(glsr(CreateReviewDefaults::class)->defaults());
57
+		$keys = implode("','", $keys);
58
+		$postType = Application::POST_TYPE;
59
+		$wpdb->query("
60 60
             UPDATE {$wpdb->postmeta} pm
61 61
             INNER JOIN {$wpdb->posts} p ON p.id = pm.post_id
62 62
             SET pm.meta_key = CONCAT('_', pm.meta_key)
63 63
             WHERE pm.meta_key IN ('{$keys}')
64 64
             AND p.post_type = '{$postType}'
65 65
         ");
66
-    }
66
+	}
67 67
 
68
-    /**
69
-     * @return void
70
-     */
71
-    public function run()
72
-    {
73
-        $this->migrateSettings();
74
-        $this->protectMetaKeys();
75
-        $this->deleteSessions();
76
-        delete_transient(Application::ID.'_cloudflare_ips');
77
-    }
68
+	/**
69
+	 * @return void
70
+	 */
71
+	public function run()
72
+	{
73
+		$this->migrateSettings();
74
+		$this->protectMetaKeys();
75
+		$this->deleteSessions();
76
+		delete_transient(Application::ID.'_cloudflare_ips');
77
+	}
78 78
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -15,11 +15,11 @@  discard block
 block discarded – undo
15 15
     public function deleteSessions()
16 16
     {
17 17
         global $wpdb;
18
-        $wpdb->query("
18
+        $wpdb->query( "
19 19
             DELETE
20 20
             FROM {$wpdb->options}
21 21
             WHERE option_name LIKE '_glsr_session%'
22
-        ");
22
+        " );
23 23
     }
24 24
 
25 25
     /**
@@ -27,23 +27,23 @@  discard block
 block discarded – undo
27 27
      */
28 28
     public function migrateSettings()
29 29
     {
30
-        if ($settings = get_option(OptionManager::databaseKey(3))) {
31
-            $multilingual = 'yes' == Arr::get($settings, 'settings.general.support.polylang')
30
+        if( $settings = get_option( OptionManager::databaseKey( 3 ) ) ) {
31
+            $multilingual = 'yes' == Arr::get( $settings, 'settings.general.support.polylang' )
32 32
                 ? 'polylang'
33 33
                 : '';
34
-            $settings = Arr::set($settings, 'settings.general.multilingual', $multilingual);
35
-            $settings = Arr::set($settings, 'settings.general.rebusify', 'no');
36
-            $settings = Arr::set($settings, 'settings.general.rebusify_email', '');
37
-            $settings = Arr::set($settings, 'settings.general.rebusify_serial', '');
38
-            $settings = Arr::set($settings, 'settings.reviews.name.format', '');
39
-            $settings = Arr::set($settings, 'settings.reviews.name.initial', '');
40
-            $settings = Arr::set($settings, 'settings.submissions.blacklist.integration', '');
41
-            $settings = Arr::set($settings, 'settings.submissions.limit', '');
42
-            $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.email', '');
43
-            $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.ip_address', '');
44
-            $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.username', '');
34
+            $settings = Arr::set( $settings, 'settings.general.multilingual', $multilingual );
35
+            $settings = Arr::set( $settings, 'settings.general.rebusify', 'no' );
36
+            $settings = Arr::set( $settings, 'settings.general.rebusify_email', '' );
37
+            $settings = Arr::set( $settings, 'settings.general.rebusify_serial', '' );
38
+            $settings = Arr::set( $settings, 'settings.reviews.name.format', '' );
39
+            $settings = Arr::set( $settings, 'settings.reviews.name.initial', '' );
40
+            $settings = Arr::set( $settings, 'settings.submissions.blacklist.integration', '' );
41
+            $settings = Arr::set( $settings, 'settings.submissions.limit', '' );
42
+            $settings = Arr::set( $settings, 'settings.submissions.limit_whitelist.email', '' );
43
+            $settings = Arr::set( $settings, 'settings.submissions.limit_whitelist.ip_address', '' );
44
+            $settings = Arr::set( $settings, 'settings.submissions.limit_whitelist.username', '' );
45 45
             unset($settings['settings']['general']['support']);
46
-            update_option(OptionManager::databaseKey(4), $settings);
46
+            update_option( OptionManager::databaseKey( 4 ), $settings );
47 47
         }
48 48
     }
49 49
 
@@ -53,16 +53,16 @@  discard block
 block discarded – undo
53 53
     public function protectMetaKeys()
54 54
     {
55 55
         global $wpdb;
56
-        $keys = array_keys(glsr(CreateReviewDefaults::class)->defaults());
57
-        $keys = implode("','", $keys);
56
+        $keys = array_keys( glsr( CreateReviewDefaults::class )->defaults() );
57
+        $keys = implode( "','", $keys );
58 58
         $postType = Application::POST_TYPE;
59
-        $wpdb->query("
59
+        $wpdb->query( "
60 60
             UPDATE {$wpdb->postmeta} pm
61 61
             INNER JOIN {$wpdb->posts} p ON p.id = pm.post_id
62 62
             SET pm.meta_key = CONCAT('_', pm.meta_key)
63 63
             WHERE pm.meta_key IN ('{$keys}')
64 64
             AND p.post_type = '{$postType}'
65
-        ");
65
+        " );
66 66
     }
67 67
 
68 68
     /**
@@ -73,6 +73,6 @@  discard block
 block discarded – undo
73 73
         $this->migrateSettings();
74 74
         $this->protectMetaKeys();
75 75
         $this->deleteSessions();
76
-        delete_transient(Application::ID.'_cloudflare_ips');
76
+        delete_transient( Application::ID.'_cloudflare_ips' );
77 77
     }
78 78
 }
Please login to merge, or discard this patch.
plugin/Modules/Migrations/Migrate_3_0_0.php 2 patches
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -7,160 +7,160 @@
 block discarded – undo
7 7
 
8 8
 class Migrate_3_0_0
9 9
 {
10
-    const MAPPED_SETTINGS = [
11
-        'settings.general.notification' => 'settings.general.notifications', // array
12
-        'settings.general.notification_email' => 'settings.general.notification_email',
13
-        'settings.general.notification_message' => 'settings.general.notification_message',
14
-        'settings.general.require.approval' => 'settings.general.require.approval',
15
-        'settings.general.require.login' => 'settings.general.require.login',
16
-        'settings.general.require.login_register' => 'settings.general.require.login_register',
17
-        'settings.general.webhook_url' => 'settings.general.notification_slack',
18
-        'settings.reviews-form.akismet' => 'settings.submissions.akismet',
19
-        'settings.reviews-form.blacklist.action' => 'settings.submissions.blacklist.action',
20
-        'settings.reviews-form.blacklist.entries' => 'settings.submissions.blacklist.entries',
21
-        'settings.reviews-form.recaptcha.integration' => 'settings.submissions.recaptcha.integration',
22
-        'settings.reviews-form.recaptcha.key' => 'settings.submissions.recaptcha.key',
23
-        'settings.reviews-form.recaptcha.position' => 'settings.submissions.recaptcha.position',
24
-        'settings.reviews-form.recaptcha.secret' => 'settings.submissions.recaptcha.secret',
25
-        'settings.reviews-form.required' => 'settings.submissions.required', // array
26
-        'settings.reviews.assigned_links.enabled' => 'settings.reviews.assigned_links',
27
-        'settings.reviews.avatars.enabled' => 'settings.reviews.avatars',
28
-        'settings.reviews.date.custom' => 'settings.reviews.date.custom',
29
-        'settings.reviews.date.format' => 'settings.reviews.date.format',
30
-        'settings.reviews.excerpt.enabled' => 'settings.reviews.excerpts',
31
-        'settings.reviews.excerpt.length' => 'settings.reviews.excerpts_length',
32
-        'settings.reviews.schema.address' => 'settings.schema.address',
33
-        'settings.reviews.schema.description.custom' => 'settings.schema.description.custom',
34
-        'settings.reviews.schema.description.default' => 'settings.schema.description.default',
35
-        'settings.reviews.schema.highprice' => 'settings.schema.highprice',
36
-        'settings.reviews.schema.image.custom' => 'settings.schema.image.custom',
37
-        'settings.reviews.schema.image.default' => 'settings.schema.image.default',
38
-        'settings.reviews.schema.lowprice' => 'settings.schema.lowprice',
39
-        'settings.reviews.schema.name.custom' => 'settings.schema.name.custom',
40
-        'settings.reviews.schema.name.default' => 'settings.schema.name.default',
41
-        'settings.reviews.schema.pricecurrency' => 'settings.schema.pricecurrency',
42
-        'settings.reviews.schema.pricerange' => 'settings.schema.pricerange',
43
-        'settings.reviews.schema.telephone' => 'settings.schema.telephone',
44
-        'settings.reviews.schema.type.custom' => 'settings.schema.type.custom',
45
-        'settings.reviews.schema.type.default' => 'settings.schema.type.default',
46
-        'settings.reviews.schema.url.custom' => 'settings.schema.url.custom',
47
-        'settings.reviews.schema.url.default' => 'settings.schema.url.default',
48
-        'version' => 'version_upgraded_from',
49
-    ];
10
+	const MAPPED_SETTINGS = [
11
+		'settings.general.notification' => 'settings.general.notifications', // array
12
+		'settings.general.notification_email' => 'settings.general.notification_email',
13
+		'settings.general.notification_message' => 'settings.general.notification_message',
14
+		'settings.general.require.approval' => 'settings.general.require.approval',
15
+		'settings.general.require.login' => 'settings.general.require.login',
16
+		'settings.general.require.login_register' => 'settings.general.require.login_register',
17
+		'settings.general.webhook_url' => 'settings.general.notification_slack',
18
+		'settings.reviews-form.akismet' => 'settings.submissions.akismet',
19
+		'settings.reviews-form.blacklist.action' => 'settings.submissions.blacklist.action',
20
+		'settings.reviews-form.blacklist.entries' => 'settings.submissions.blacklist.entries',
21
+		'settings.reviews-form.recaptcha.integration' => 'settings.submissions.recaptcha.integration',
22
+		'settings.reviews-form.recaptcha.key' => 'settings.submissions.recaptcha.key',
23
+		'settings.reviews-form.recaptcha.position' => 'settings.submissions.recaptcha.position',
24
+		'settings.reviews-form.recaptcha.secret' => 'settings.submissions.recaptcha.secret',
25
+		'settings.reviews-form.required' => 'settings.submissions.required', // array
26
+		'settings.reviews.assigned_links.enabled' => 'settings.reviews.assigned_links',
27
+		'settings.reviews.avatars.enabled' => 'settings.reviews.avatars',
28
+		'settings.reviews.date.custom' => 'settings.reviews.date.custom',
29
+		'settings.reviews.date.format' => 'settings.reviews.date.format',
30
+		'settings.reviews.excerpt.enabled' => 'settings.reviews.excerpts',
31
+		'settings.reviews.excerpt.length' => 'settings.reviews.excerpts_length',
32
+		'settings.reviews.schema.address' => 'settings.schema.address',
33
+		'settings.reviews.schema.description.custom' => 'settings.schema.description.custom',
34
+		'settings.reviews.schema.description.default' => 'settings.schema.description.default',
35
+		'settings.reviews.schema.highprice' => 'settings.schema.highprice',
36
+		'settings.reviews.schema.image.custom' => 'settings.schema.image.custom',
37
+		'settings.reviews.schema.image.default' => 'settings.schema.image.default',
38
+		'settings.reviews.schema.lowprice' => 'settings.schema.lowprice',
39
+		'settings.reviews.schema.name.custom' => 'settings.schema.name.custom',
40
+		'settings.reviews.schema.name.default' => 'settings.schema.name.default',
41
+		'settings.reviews.schema.pricecurrency' => 'settings.schema.pricecurrency',
42
+		'settings.reviews.schema.pricerange' => 'settings.schema.pricerange',
43
+		'settings.reviews.schema.telephone' => 'settings.schema.telephone',
44
+		'settings.reviews.schema.type.custom' => 'settings.schema.type.custom',
45
+		'settings.reviews.schema.type.default' => 'settings.schema.type.default',
46
+		'settings.reviews.schema.url.custom' => 'settings.schema.url.custom',
47
+		'settings.reviews.schema.url.default' => 'settings.schema.url.default',
48
+		'version' => 'version_upgraded_from',
49
+	];
50 50
 
51
-    /**
52
-     * @var array
53
-     */
54
-    protected $newSettings;
51
+	/**
52
+	 * @var array
53
+	 */
54
+	protected $newSettings;
55 55
 
56
-    /**
57
-     * @var array
58
-     */
59
-    protected $oldSettings;
56
+	/**
57
+	 * @var array
58
+	 */
59
+	protected $oldSettings;
60 60
 
61
-    /**
62
-     * @return void
63
-     */
64
-    public function migrateSettings()
65
-    {
66
-        $this->newSettings = $this->getNewSettings();
67
-        $this->oldSettings = $this->getOldSettings();
68
-        if (empty($this->oldSettings) || empty($this->newSettings)) {
69
-            return;
70
-        }
71
-        foreach (static::MAPPED_SETTINGS as $old => $new) {
72
-            if (empty($this->oldSettings[$old])) {
73
-                continue;
74
-            }
75
-            $this->newSettings[$new] = $this->oldSettings[$old];
76
-        }
77
-        $this->migrateNotificationSettings();
78
-        $this->migrateRecaptchaSettings();
79
-        $this->migrateRequiredSettings();
80
-        $oldSettings = Arr::convertDotNotationArray($this->oldSettings);
81
-        $newSettings = Arr::convertDotNotationArray($this->newSettings);
82
-        if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) {
83
-            $newSettings['settings']['strings'] = $oldSettings['settings']['strings'];
84
-        }
85
-        update_option(OptionManager::databaseKey(3), $newSettings);
86
-    }
61
+	/**
62
+	 * @return void
63
+	 */
64
+	public function migrateSettings()
65
+	{
66
+		$this->newSettings = $this->getNewSettings();
67
+		$this->oldSettings = $this->getOldSettings();
68
+		if (empty($this->oldSettings) || empty($this->newSettings)) {
69
+			return;
70
+		}
71
+		foreach (static::MAPPED_SETTINGS as $old => $new) {
72
+			if (empty($this->oldSettings[$old])) {
73
+				continue;
74
+			}
75
+			$this->newSettings[$new] = $this->oldSettings[$old];
76
+		}
77
+		$this->migrateNotificationSettings();
78
+		$this->migrateRecaptchaSettings();
79
+		$this->migrateRequiredSettings();
80
+		$oldSettings = Arr::convertDotNotationArray($this->oldSettings);
81
+		$newSettings = Arr::convertDotNotationArray($this->newSettings);
82
+		if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) {
83
+			$newSettings['settings']['strings'] = $oldSettings['settings']['strings'];
84
+		}
85
+		update_option(OptionManager::databaseKey(3), $newSettings);
86
+	}
87 87
 
88
-    /**
89
-     * @return void
90
-     */
91
-    public function run()
92
-    {
93
-        $this->migrateSettings();
94
-    }
88
+	/**
89
+	 * @return void
90
+	 */
91
+	public function run()
92
+	{
93
+		$this->migrateSettings();
94
+	}
95 95
 
96
-    /**
97
-     * @return array
98
-     */
99
-    protected function getNewSettings()
100
-    {
101
-        return  Arr::flattenArray(Arr::consolidateArray(OptionManager::databaseKey(3)));
102
-    }
96
+	/**
97
+	 * @return array
98
+	 */
99
+	protected function getNewSettings()
100
+	{
101
+		return  Arr::flattenArray(Arr::consolidateArray(OptionManager::databaseKey(3)));
102
+	}
103 103
 
104
-    /**
105
-     * @return array
106
-     */
107
-    protected function getOldSettings()
108
-    {
109
-        $defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), '');
110
-        $settings = Arr::consolidateArray(get_option(OptionManager::databaseKey(2)));
111
-        $settings = Arr::flattenArray($settings);
112
-        return !empty($settings)
113
-            ? wp_parse_args($settings, $defaults)
114
-            : [];
115
-    }
104
+	/**
105
+	 * @return array
106
+	 */
107
+	protected function getOldSettings()
108
+	{
109
+		$defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), '');
110
+		$settings = Arr::consolidateArray(get_option(OptionManager::databaseKey(2)));
111
+		$settings = Arr::flattenArray($settings);
112
+		return !empty($settings)
113
+			? wp_parse_args($settings, $defaults)
114
+			: [];
115
+	}
116 116
 
117
-    /**
118
-     * @return void
119
-     */
120
-    protected function migrateNotificationSettings()
121
-    {
122
-        $notifications = [
123
-            'custom' => 'custom',
124
-            'default' => 'admin',
125
-            'webhook' => 'slack',
126
-        ];
127
-        $this->newSettings['settings.general.notifications'] = [];
128
-        foreach ($notifications as $old => $new) {
129
-            if ($this->oldSettings['settings.general.notification'] != $old) {
130
-                continue;
131
-            }
132
-            $this->newSettings['settings.general.notifications'][] = $new;
133
-        }
134
-    }
117
+	/**
118
+	 * @return void
119
+	 */
120
+	protected function migrateNotificationSettings()
121
+	{
122
+		$notifications = [
123
+			'custom' => 'custom',
124
+			'default' => 'admin',
125
+			'webhook' => 'slack',
126
+		];
127
+		$this->newSettings['settings.general.notifications'] = [];
128
+		foreach ($notifications as $old => $new) {
129
+			if ($this->oldSettings['settings.general.notification'] != $old) {
130
+				continue;
131
+			}
132
+			$this->newSettings['settings.general.notifications'][] = $new;
133
+		}
134
+	}
135 135
 
136
-    /**
137
-     * @return void
138
-     */
139
-    protected function migrateRecaptchaSettings()
140
-    {
141
-        $recaptcha = [
142
-            'BadgePosition' => $this->oldSettings['settings.reviews-form.recaptcha.position'],
143
-            'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'],
144
-            'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'],
145
-        ];
146
-        if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) {
147
-            $this->newSettings['settings.submissions.recaptcha.integration'] = 'all';
148
-        }
149
-        if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) {
150
-            $recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha);
151
-        }
152
-        $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey'];
153
-        $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey'];
154
-        $this->newSettings['settings.submissions.recaptcha.position'] = $recaptcha['BadgePosition'];
155
-    }
136
+	/**
137
+	 * @return void
138
+	 */
139
+	protected function migrateRecaptchaSettings()
140
+	{
141
+		$recaptcha = [
142
+			'BadgePosition' => $this->oldSettings['settings.reviews-form.recaptcha.position'],
143
+			'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'],
144
+			'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'],
145
+		];
146
+		if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) {
147
+			$this->newSettings['settings.submissions.recaptcha.integration'] = 'all';
148
+		}
149
+		if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) {
150
+			$recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha);
151
+		}
152
+		$this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey'];
153
+		$this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey'];
154
+		$this->newSettings['settings.submissions.recaptcha.position'] = $recaptcha['BadgePosition'];
155
+	}
156 156
 
157
-    /**
158
-     * @return void
159
-     */
160
-    protected function migrateRequiredSettings()
161
-    {
162
-        $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']);
163
-        $this->newSettings['settings.submissions.required'][] = 'rating';
164
-        $this->newSettings['settings.submissions.required'][] = 'terms';
165
-    }
157
+	/**
158
+	 * @return void
159
+	 */
160
+	protected function migrateRequiredSettings()
161
+	{
162
+		$this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']);
163
+		$this->newSettings['settings.submissions.required'][] = 'rating';
164
+		$this->newSettings['settings.submissions.required'][] = 'terms';
165
+	}
166 166
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -65,11 +65,11 @@  discard block
 block discarded – undo
65 65
     {
66 66
         $this->newSettings = $this->getNewSettings();
67 67
         $this->oldSettings = $this->getOldSettings();
68
-        if (empty($this->oldSettings) || empty($this->newSettings)) {
68
+        if( empty($this->oldSettings) || empty($this->newSettings) ) {
69 69
             return;
70 70
         }
71
-        foreach (static::MAPPED_SETTINGS as $old => $new) {
72
-            if (empty($this->oldSettings[$old])) {
71
+        foreach( static::MAPPED_SETTINGS as $old => $new ) {
72
+            if( empty($this->oldSettings[$old]) ) {
73 73
                 continue;
74 74
             }
75 75
             $this->newSettings[$new] = $this->oldSettings[$old];
@@ -77,12 +77,12 @@  discard block
 block discarded – undo
77 77
         $this->migrateNotificationSettings();
78 78
         $this->migrateRecaptchaSettings();
79 79
         $this->migrateRequiredSettings();
80
-        $oldSettings = Arr::convertDotNotationArray($this->oldSettings);
81
-        $newSettings = Arr::convertDotNotationArray($this->newSettings);
82
-        if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) {
80
+        $oldSettings = Arr::convertDotNotationArray( $this->oldSettings );
81
+        $newSettings = Arr::convertDotNotationArray( $this->newSettings );
82
+        if( isset($oldSettings['settings']['strings']) && is_array( $oldSettings['settings']['strings'] ) ) {
83 83
             $newSettings['settings']['strings'] = $oldSettings['settings']['strings'];
84 84
         }
85
-        update_option(OptionManager::databaseKey(3), $newSettings);
85
+        update_option( OptionManager::databaseKey( 3 ), $newSettings );
86 86
     }
87 87
 
88 88
     /**
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
      */
99 99
     protected function getNewSettings()
100 100
     {
101
-        return  Arr::flattenArray(Arr::consolidateArray(OptionManager::databaseKey(3)));
101
+        return  Arr::flattenArray( Arr::consolidateArray( OptionManager::databaseKey( 3 ) ) );
102 102
     }
103 103
 
104 104
     /**
@@ -106,11 +106,11 @@  discard block
 block discarded – undo
106 106
      */
107 107
     protected function getOldSettings()
108 108
     {
109
-        $defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), '');
110
-        $settings = Arr::consolidateArray(get_option(OptionManager::databaseKey(2)));
111
-        $settings = Arr::flattenArray($settings);
109
+        $defaults = array_fill_keys( array_keys( static::MAPPED_SETTINGS ), '' );
110
+        $settings = Arr::consolidateArray( get_option( OptionManager::databaseKey( 2 ) ) );
111
+        $settings = Arr::flattenArray( $settings );
112 112
         return !empty($settings)
113
-            ? wp_parse_args($settings, $defaults)
113
+            ? wp_parse_args( $settings, $defaults )
114 114
             : [];
115 115
     }
116 116
 
@@ -125,8 +125,8 @@  discard block
 block discarded – undo
125 125
             'webhook' => 'slack',
126 126
         ];
127 127
         $this->newSettings['settings.general.notifications'] = [];
128
-        foreach ($notifications as $old => $new) {
129
-            if ($this->oldSettings['settings.general.notification'] != $old) {
128
+        foreach( $notifications as $old => $new ) {
129
+            if( $this->oldSettings['settings.general.notification'] != $old ) {
130 130
                 continue;
131 131
             }
132 132
             $this->newSettings['settings.general.notifications'][] = $new;
@@ -143,11 +143,11 @@  discard block
 block discarded – undo
143 143
             'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'],
144 144
             'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'],
145 145
         ];
146
-        if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) {
146
+        if( in_array( $this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'] ) ) {
147 147
             $this->newSettings['settings.submissions.recaptcha.integration'] = 'all';
148 148
         }
149
-        if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) {
150
-            $recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha);
149
+        if( 'invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration'] ) {
150
+            $recaptcha = wp_parse_args( (array)get_site_option( 'ic-settings', [], false ), $recaptcha );
151 151
         }
152 152
         $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey'];
153 153
         $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey'];
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
      */
160 160
     protected function migrateRequiredSettings()
161 161
     {
162
-        $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']);
162
+        $this->newSettings['settings.submissions.required'] = array_filter( (array)$this->oldSettings['settings.reviews-form.required'] );
163 163
         $this->newSettings['settings.submissions.required'][] = 'rating';
164 164
         $this->newSettings['settings.submissions.required'][] = 'terms';
165 165
     }
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
@@ -9,75 +9,75 @@
 block discarded – undo
9 9
 
10 10
 class Wpml implements Contract
11 11
 {
12
-    public $pluginName = 'WPML';
13
-    public $supportedVersion = '3.3.5';
12
+	public $pluginName = 'WPML';
13
+	public $supportedVersion = '3.3.5';
14 14
 
15
-    /**
16
-     * {@inheritdoc}
17
-     */
18
-    public function getPostId($postId)
19
-    {
20
-        $postId = trim($postId);
21
-        if (!is_numeric($postId)) {
22
-            return 0;
23
-        }
24
-        if ($this->isEnabled()) {
25
-            $postId = apply_filters('wpml_object_id', $postId, 'any', true);
26
-        }
27
-        return intval($postId);
28
-    }
15
+	/**
16
+	 * {@inheritdoc}
17
+	 */
18
+	public function getPostId($postId)
19
+	{
20
+		$postId = trim($postId);
21
+		if (!is_numeric($postId)) {
22
+			return 0;
23
+		}
24
+		if ($this->isEnabled()) {
25
+			$postId = apply_filters('wpml_object_id', $postId, 'any', true);
26
+		}
27
+		return intval($postId);
28
+	}
29 29
 
30
-    /**
31
-     * {@inheritdoc}
32
-     */
33
-    public function getPostIds(array $postIds)
34
-    {
35
-        if (!$this->isEnabled()) {
36
-            return $postIds;
37
-        }
38
-        $newPostIds = [];
39
-        foreach (Arr::unique($postIds) as $postId) {
40
-            $postType = get_post_type($postId);
41
-            if (!$postType) {
42
-                continue;
43
-            }
44
-            $elementType = 'post_'.$postType;
45
-            $trid = apply_filters('wpml_element_trid', null, $postId, $elementType);
46
-            $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType);
47
-            if (!is_array($translations)) {
48
-                $translations = [];
49
-            }
50
-            $newPostIds = array_merge(
51
-                $newPostIds,
52
-                array_column($translations, 'element_id')
53
-            );
54
-        }
55
-        return Arr::unique($newPostIds);
56
-    }
30
+	/**
31
+	 * {@inheritdoc}
32
+	 */
33
+	public function getPostIds(array $postIds)
34
+	{
35
+		if (!$this->isEnabled()) {
36
+			return $postIds;
37
+		}
38
+		$newPostIds = [];
39
+		foreach (Arr::unique($postIds) as $postId) {
40
+			$postType = get_post_type($postId);
41
+			if (!$postType) {
42
+				continue;
43
+			}
44
+			$elementType = 'post_'.$postType;
45
+			$trid = apply_filters('wpml_element_trid', null, $postId, $elementType);
46
+			$translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType);
47
+			if (!is_array($translations)) {
48
+				$translations = [];
49
+			}
50
+			$newPostIds = array_merge(
51
+				$newPostIds,
52
+				array_column($translations, 'element_id')
53
+			);
54
+		}
55
+		return Arr::unique($newPostIds);
56
+	}
57 57
 
58
-    /**
59
-     * {@inheritdoc}
60
-     */
61
-    public function isActive()
62
-    {
63
-        return defined('ICL_SITEPRESS_VERSION');
64
-    }
58
+	/**
59
+	 * {@inheritdoc}
60
+	 */
61
+	public function isActive()
62
+	{
63
+		return defined('ICL_SITEPRESS_VERSION');
64
+	}
65 65
 
66
-    /**
67
-     * {@inheritdoc}
68
-     */
69
-    public function isEnabled()
70
-    {
71
-        return $this->isActive()
72
-            && 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual');
73
-    }
66
+	/**
67
+	 * {@inheritdoc}
68
+	 */
69
+	public function isEnabled()
70
+	{
71
+		return $this->isActive()
72
+			&& 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual');
73
+	}
74 74
 
75
-    /**
76
-     * {@inheritdoc}
77
-     */
78
-    public function isSupported()
79
-    {
80
-        return $this->isActive()
81
-            && Helper::isGreaterThanOrEqual(ICL_SITEPRESS_VERSION, $this->supportedVersion);
82
-    }
75
+	/**
76
+	 * {@inheritdoc}
77
+	 */
78
+	public function isSupported()
79
+	{
80
+		return $this->isActive()
81
+			&& Helper::isGreaterThanOrEqual(ICL_SITEPRESS_VERSION, $this->supportedVersion);
82
+	}
83 83
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -15,44 +15,44 @@  discard block
 block discarded – undo
15 15
     /**
16 16
      * {@inheritdoc}
17 17
      */
18
-    public function getPostId($postId)
18
+    public function getPostId( $postId )
19 19
     {
20
-        $postId = trim($postId);
21
-        if (!is_numeric($postId)) {
20
+        $postId = trim( $postId );
21
+        if( !is_numeric( $postId ) ) {
22 22
             return 0;
23 23
         }
24
-        if ($this->isEnabled()) {
25
-            $postId = apply_filters('wpml_object_id', $postId, 'any', true);
24
+        if( $this->isEnabled() ) {
25
+            $postId = apply_filters( 'wpml_object_id', $postId, 'any', true );
26 26
         }
27
-        return intval($postId);
27
+        return intval( $postId );
28 28
     }
29 29
 
30 30
     /**
31 31
      * {@inheritdoc}
32 32
      */
33
-    public function getPostIds(array $postIds)
33
+    public function getPostIds( array $postIds )
34 34
     {
35
-        if (!$this->isEnabled()) {
35
+        if( !$this->isEnabled() ) {
36 36
             return $postIds;
37 37
         }
38 38
         $newPostIds = [];
39
-        foreach (Arr::unique($postIds) as $postId) {
40
-            $postType = get_post_type($postId);
41
-            if (!$postType) {
39
+        foreach( Arr::unique( $postIds ) as $postId ) {
40
+            $postType = get_post_type( $postId );
41
+            if( !$postType ) {
42 42
                 continue;
43 43
             }
44 44
             $elementType = 'post_'.$postType;
45
-            $trid = apply_filters('wpml_element_trid', null, $postId, $elementType);
46
-            $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType);
47
-            if (!is_array($translations)) {
45
+            $trid = apply_filters( 'wpml_element_trid', null, $postId, $elementType );
46
+            $translations = apply_filters( 'wpml_get_element_translations', null, $trid, $elementType );
47
+            if( !is_array( $translations ) ) {
48 48
                 $translations = [];
49 49
             }
50 50
             $newPostIds = array_merge(
51 51
                 $newPostIds,
52
-                array_column($translations, 'element_id')
52
+                array_column( $translations, 'element_id' )
53 53
             );
54 54
         }
55
-        return Arr::unique($newPostIds);
55
+        return Arr::unique( $newPostIds );
56 56
     }
57 57
 
58 58
     /**
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      */
61 61
     public function isActive()
62 62
     {
63
-        return defined('ICL_SITEPRESS_VERSION');
63
+        return defined( 'ICL_SITEPRESS_VERSION' );
64 64
     }
65 65
 
66 66
     /**
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
     public function isEnabled()
70 70
     {
71 71
         return $this->isActive()
72
-            && 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual');
72
+            && 'wpml' == glsr( OptionManager::class )->get( 'settings.general.multilingual' );
73 73
     }
74 74
 
75 75
     /**
@@ -78,6 +78,6 @@  discard block
 block discarded – undo
78 78
     public function isSupported()
79 79
     {
80 80
         return $this->isActive()
81
-            && Helper::isGreaterThanOrEqual(ICL_SITEPRESS_VERSION, $this->supportedVersion);
81
+            && Helper::isGreaterThanOrEqual( ICL_SITEPRESS_VERSION, $this->supportedVersion );
82 82
     }
83 83
 }
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
@@ -9,71 +9,71 @@
 block discarded – undo
9 9
 
10 10
 class Polylang implements Contract
11 11
 {
12
-    public $pluginName = 'Polylang';
13
-    public $supportedVersion = '2.3';
12
+	public $pluginName = 'Polylang';
13
+	public $supportedVersion = '2.3';
14 14
 
15
-    /**
16
-     * {@inheritdoc}
17
-     */
18
-    public function getPostId($postId)
19
-    {
20
-        $postId = trim($postId);
21
-        if (!is_numeric($postId)) {
22
-            return 0;
23
-        }
24
-        if ($this->isEnabled()) {
25
-            $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID()));
26
-        }
27
-        if (!empty($polylangPostId)) {
28
-            $postId = $polylangPostId;
29
-        }
30
-        return intval($postId);
31
-    }
15
+	/**
16
+	 * {@inheritdoc}
17
+	 */
18
+	public function getPostId($postId)
19
+	{
20
+		$postId = trim($postId);
21
+		if (!is_numeric($postId)) {
22
+			return 0;
23
+		}
24
+		if ($this->isEnabled()) {
25
+			$polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID()));
26
+		}
27
+		if (!empty($polylangPostId)) {
28
+			$postId = $polylangPostId;
29
+		}
30
+		return intval($postId);
31
+	}
32 32
 
33
-    /**
34
-     * {@inheritdoc}
35
-     */
36
-    public function getPostIds(array $postIds)
37
-    {
38
-        if (!$this->isEnabled()) {
39
-            return $postIds;
40
-        }
41
-        $newPostIds = [];
42
-        foreach (Arr::unique($postIds) as $postId) {
43
-            $newPostIds = array_merge(
44
-                $newPostIds,
45
-                array_values(pll_get_post_translations($postId))
46
-            );
47
-        }
48
-        return Arr::unique($newPostIds);
49
-    }
33
+	/**
34
+	 * {@inheritdoc}
35
+	 */
36
+	public function getPostIds(array $postIds)
37
+	{
38
+		if (!$this->isEnabled()) {
39
+			return $postIds;
40
+		}
41
+		$newPostIds = [];
42
+		foreach (Arr::unique($postIds) as $postId) {
43
+			$newPostIds = array_merge(
44
+				$newPostIds,
45
+				array_values(pll_get_post_translations($postId))
46
+			);
47
+		}
48
+		return Arr::unique($newPostIds);
49
+	}
50 50
 
51
-    /**
52
-     * {@inheritdoc}
53
-     */
54
-    public function isActive()
55
-    {
56
-        return function_exists('PLL')
57
-            && function_exists('pll_get_post')
58
-            && function_exists('pll_get_post_language')
59
-            && function_exists('pll_get_post_translations');
60
-    }
51
+	/**
52
+	 * {@inheritdoc}
53
+	 */
54
+	public function isActive()
55
+	{
56
+		return function_exists('PLL')
57
+			&& function_exists('pll_get_post')
58
+			&& function_exists('pll_get_post_language')
59
+			&& function_exists('pll_get_post_translations');
60
+	}
61 61
 
62
-    /**
63
-     * {@inheritdoc}
64
-     */
65
-    public function isEnabled()
66
-    {
67
-        return $this->isActive()
68
-            && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual');
69
-    }
62
+	/**
63
+	 * {@inheritdoc}
64
+	 */
65
+	public function isEnabled()
66
+	{
67
+		return $this->isActive()
68
+			&& 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual');
69
+	}
70 70
 
71
-    /**
72
-     * {@inheritdoc}
73
-     */
74
-    public function isSupported()
75
-    {
76
-        return defined('POLYLANG_VERSION')
77
-            && Helper::isGreaterThanOrEqual(POLYLANG_VERSION, $this->supportedVersion);
78
-    }
71
+	/**
72
+	 * {@inheritdoc}
73
+	 */
74
+	public function isSupported()
75
+	{
76
+		return defined('POLYLANG_VERSION')
77
+			&& Helper::isGreaterThanOrEqual(POLYLANG_VERSION, $this->supportedVersion);
78
+	}
79 79
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -15,37 +15,37 @@  discard block
 block discarded – undo
15 15
     /**
16 16
      * {@inheritdoc}
17 17
      */
18
-    public function getPostId($postId)
18
+    public function getPostId( $postId )
19 19
     {
20
-        $postId = trim($postId);
21
-        if (!is_numeric($postId)) {
20
+        $postId = trim( $postId );
21
+        if( !is_numeric( $postId ) ) {
22 22
             return 0;
23 23
         }
24
-        if ($this->isEnabled()) {
25
-            $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID()));
24
+        if( $this->isEnabled() ) {
25
+            $polylangPostId = pll_get_post( $postId, pll_get_post_language( get_the_ID() ) );
26 26
         }
27
-        if (!empty($polylangPostId)) {
27
+        if( !empty($polylangPostId) ) {
28 28
             $postId = $polylangPostId;
29 29
         }
30
-        return intval($postId);
30
+        return intval( $postId );
31 31
     }
32 32
 
33 33
     /**
34 34
      * {@inheritdoc}
35 35
      */
36
-    public function getPostIds(array $postIds)
36
+    public function getPostIds( array $postIds )
37 37
     {
38
-        if (!$this->isEnabled()) {
38
+        if( !$this->isEnabled() ) {
39 39
             return $postIds;
40 40
         }
41 41
         $newPostIds = [];
42
-        foreach (Arr::unique($postIds) as $postId) {
42
+        foreach( Arr::unique( $postIds ) as $postId ) {
43 43
             $newPostIds = array_merge(
44 44
                 $newPostIds,
45
-                array_values(pll_get_post_translations($postId))
45
+                array_values( pll_get_post_translations( $postId ) )
46 46
             );
47 47
         }
48
-        return Arr::unique($newPostIds);
48
+        return Arr::unique( $newPostIds );
49 49
     }
50 50
 
51 51
     /**
@@ -53,10 +53,10 @@  discard block
 block discarded – undo
53 53
      */
54 54
     public function isActive()
55 55
     {
56
-        return function_exists('PLL')
57
-            && function_exists('pll_get_post')
58
-            && function_exists('pll_get_post_language')
59
-            && function_exists('pll_get_post_translations');
56
+        return function_exists( 'PLL' )
57
+            && function_exists( 'pll_get_post' )
58
+            && function_exists( 'pll_get_post_language' )
59
+            && function_exists( 'pll_get_post_translations' );
60 60
     }
61 61
 
62 62
     /**
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
     public function isEnabled()
66 66
     {
67 67
         return $this->isActive()
68
-            && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual');
68
+            && 'polylang' == glsr( OptionManager::class )->get( 'settings.general.multilingual' );
69 69
     }
70 70
 
71 71
     /**
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
      */
74 74
     public function isSupported()
75 75
     {
76
-        return defined('POLYLANG_VERSION')
77
-            && Helper::isGreaterThanOrEqual(POLYLANG_VERSION, $this->supportedVersion);
76
+        return defined( 'POLYLANG_VERSION' )
77
+            && Helper::isGreaterThanOrEqual( POLYLANG_VERSION, $this->supportedVersion );
78 78
     }
79 79
 }
Please login to merge, or discard this patch.
plugin/Helper.php 2 patches
Indentation   +214 added lines, -214 removed lines patch added patch discarded remove patch
@@ -8,218 +8,218 @@
 block discarded – undo
8 8
 
9 9
 class Helper
10 10
 {
11
-    /**
12
-     * @param string $name
13
-     * @param string $path
14
-     * @return string
15
-     */
16
-    public static function buildClassName($name, $path = '')
17
-    {
18
-        $className = Str::camelCase($name);
19
-        $path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\');
20
-        return !empty($path)
21
-            ? __NAMESPACE__.'\\'.$path.'\\'.$className
22
-            : $className;
23
-    }
24
-
25
-    /**
26
-     * @param string $name
27
-     * @param string $prefix
28
-     * @return string
29
-     */
30
-    public static function buildMethodName($name, $prefix = '')
31
-    {
32
-        return lcfirst($prefix.static::buildClassName($name));
33
-    }
34
-
35
-    /**
36
-     * @param string $name
37
-     * @return string
38
-     */
39
-    public static function buildPropertyName($name)
40
-    {
41
-        return static::buildMethodName($name);
42
-    }
43
-
44
-    /**
45
-     * @param string $cast
46
-     * @param mixed $value
47
-     * @return mixed
48
-     */
49
-    public static function castTo($cast = '', $value)
50
-    {
51
-        $method = static::buildMethodName($cast, 'castTo');
52
-        return !empty($cast) && method_exists(__CLASS__, $method)
53
-            ? static::$method($value)
54
-            : $value;
55
-    }
56
-
57
-    /**
58
-     * @param mixed $value
59
-     * @return array
60
-     */
61
-    public static function castToArray($value)
62
-    {
63
-        return (array) $value;
64
-    }
65
-
66
-    /**
67
-     * @param mixed $value
68
-     * @return bool
69
-     */
70
-    public static function castToBool($value)
71
-    {
72
-        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
73
-    }
74
-
75
-    /**
76
-     * @param mixed $value
77
-     * @return float
78
-     */
79
-    public static function castToFloat($value)
80
-    {
81
-        return (float) filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND);
82
-    }
83
-
84
-    /**
85
-     * @param mixed $value
86
-     * @return int
87
-     */
88
-    public static function castToInt($value)
89
-    {
90
-        return (int) filter_var($value, FILTER_VALIDATE_INT);
91
-    }
92
-
93
-    /**
94
-     * @param mixed $value
95
-     * @return object
96
-     */
97
-    public static function castToObject($value)
98
-    {
99
-        return (object) (array) $value;
100
-    }
101
-
102
-    /**
103
-     * @param mixed $value
104
-     * @return string
105
-     */
106
-    public static function castToString($value)
107
-    {
108
-        if (is_object($value) && in_array('__toString', get_class_methods($value))) {
109
-            return (string) $value->__toString();
110
-        }
111
-        if (is_array($value) || is_object($value)) {
112
-            return serialize($value);
113
-        }
114
-        return (string) $value;
115
-    }
116
-
117
-    /**
118
-     * @param string $key
119
-     * @return mixed
120
-     */
121
-    public static function filterInput($key, array $request = [])
122
-    {
123
-        if (isset($request[$key])) {
124
-            return $request[$key];
125
-        }
126
-        $variable = filter_input(INPUT_POST, $key);
127
-        if (is_null($variable) && isset($_POST[$key])) {
128
-            $variable = $_POST[$key];
129
-        }
130
-        return $variable;
131
-    }
132
-
133
-    /**
134
-     * @param string $key
135
-     * @return array
136
-     */
137
-    public static function filterInputArray($key)
138
-    {
139
-        $variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
140
-        if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) {
141
-            $variable = $_POST[$key];
142
-        }
143
-        return (array) $variable;
144
-    }
145
-
146
-    /**
147
-     * @return string
148
-     */
149
-    public static function getIpAddress()
150
-    {
151
-        $whitelist = [];
152
-        $isUsingCloudflare = !empty(filter_input(INPUT_SERVER, 'CF-Connecting-IP'));
153
-        if (apply_filters('site-reviews/whip/whitelist/cloudflare', $isUsingCloudflare)) {
154
-            $cloudflareIps = glsr(Cache::class)->getCloudflareIps();
155
-            $whitelist[Whip::CLOUDFLARE_HEADERS] = [Whip::IPV4 => $cloudflareIps['v4']];
156
-            if (defined('AF_INET6')) {
157
-                $whitelist[Whip::CLOUDFLARE_HEADERS][Whip::IPV6] = $cloudflareIps['v6'];
158
-            }
159
-        }
160
-        $whitelist = apply_filters('site-reviews/whip/whitelist', $whitelist);
161
-        $methods = apply_filters('site-reviews/whip/methods', Whip::ALL_METHODS);
162
-        $whip = new Whip($methods, $whitelist);
163
-        do_action_ref_array('site-reviews/whip', [$whip]);
164
-        if (false !== ($clientAddress = $whip->getValidIpAddress())) {
165
-            return (string) $clientAddress;
166
-        }
167
-        glsr_log()->error('Unable to detect IP address.');
168
-        return 'unknown';
169
-    }
170
-
171
-    /**
172
-     * @param mixed $value
173
-     * @param string|int $min
174
-     * @param string|int $max
175
-     * @return bool
176
-     */
177
-    public static function inRange($value, $min, $max)
178
-    {
179
-        $inRange = filter_var($value, FILTER_VALIDATE_INT, ['options' => [
180
-            'min_range' => intval($min),
181
-            'max_range' => intval($max),
182
-        ]]);
183
-        return false !== $inRange;
184
-    }
185
-
186
-    /**
187
-     * @param int|string $value
188
-     * @param int|string $compareWithValue
189
-     * @return bool
190
-     */
191
-    public static function isGreaterThan($value, $compareWithValue)
192
-    {
193
-        return version_compare($value, $compareWithValue, '>');
194
-    }
195
-
196
-    /**
197
-     * @param int|string $value
198
-     * @param int|string $compareWithValue
199
-     * @return bool
200
-     */
201
-    public static function isGreaterThanOrEqual($value, $compareWithValue)
202
-    {
203
-        return version_compare($value, $compareWithValue, '>=');
204
-    }
205
-
206
-    /**
207
-     * @param int|string $value
208
-     * @param int|string $compareWithValue
209
-     * @return bool
210
-     */
211
-    public static function isLessThan($value, $compareWithValue)
212
-    {
213
-        return version_compare($value, $compareWithValue, '<');
214
-    }
215
-
216
-    /**
217
-     * @param int|string $value
218
-     * @param int|string $compareWithValue
219
-     * @return bool
220
-     */
221
-    public static function isLessThanOrEqual($value, $compareWithValue)
222
-    {
223
-        return version_compare($value, $compareWithValue, '<=');
224
-    }
11
+	/**
12
+	 * @param string $name
13
+	 * @param string $path
14
+	 * @return string
15
+	 */
16
+	public static function buildClassName($name, $path = '')
17
+	{
18
+		$className = Str::camelCase($name);
19
+		$path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\');
20
+		return !empty($path)
21
+			? __NAMESPACE__.'\\'.$path.'\\'.$className
22
+			: $className;
23
+	}
24
+
25
+	/**
26
+	 * @param string $name
27
+	 * @param string $prefix
28
+	 * @return string
29
+	 */
30
+	public static function buildMethodName($name, $prefix = '')
31
+	{
32
+		return lcfirst($prefix.static::buildClassName($name));
33
+	}
34
+
35
+	/**
36
+	 * @param string $name
37
+	 * @return string
38
+	 */
39
+	public static function buildPropertyName($name)
40
+	{
41
+		return static::buildMethodName($name);
42
+	}
43
+
44
+	/**
45
+	 * @param string $cast
46
+	 * @param mixed $value
47
+	 * @return mixed
48
+	 */
49
+	public static function castTo($cast = '', $value)
50
+	{
51
+		$method = static::buildMethodName($cast, 'castTo');
52
+		return !empty($cast) && method_exists(__CLASS__, $method)
53
+			? static::$method($value)
54
+			: $value;
55
+	}
56
+
57
+	/**
58
+	 * @param mixed $value
59
+	 * @return array
60
+	 */
61
+	public static function castToArray($value)
62
+	{
63
+		return (array) $value;
64
+	}
65
+
66
+	/**
67
+	 * @param mixed $value
68
+	 * @return bool
69
+	 */
70
+	public static function castToBool($value)
71
+	{
72
+		return filter_var($value, FILTER_VALIDATE_BOOLEAN);
73
+	}
74
+
75
+	/**
76
+	 * @param mixed $value
77
+	 * @return float
78
+	 */
79
+	public static function castToFloat($value)
80
+	{
81
+		return (float) filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND);
82
+	}
83
+
84
+	/**
85
+	 * @param mixed $value
86
+	 * @return int
87
+	 */
88
+	public static function castToInt($value)
89
+	{
90
+		return (int) filter_var($value, FILTER_VALIDATE_INT);
91
+	}
92
+
93
+	/**
94
+	 * @param mixed $value
95
+	 * @return object
96
+	 */
97
+	public static function castToObject($value)
98
+	{
99
+		return (object) (array) $value;
100
+	}
101
+
102
+	/**
103
+	 * @param mixed $value
104
+	 * @return string
105
+	 */
106
+	public static function castToString($value)
107
+	{
108
+		if (is_object($value) && in_array('__toString', get_class_methods($value))) {
109
+			return (string) $value->__toString();
110
+		}
111
+		if (is_array($value) || is_object($value)) {
112
+			return serialize($value);
113
+		}
114
+		return (string) $value;
115
+	}
116
+
117
+	/**
118
+	 * @param string $key
119
+	 * @return mixed
120
+	 */
121
+	public static function filterInput($key, array $request = [])
122
+	{
123
+		if (isset($request[$key])) {
124
+			return $request[$key];
125
+		}
126
+		$variable = filter_input(INPUT_POST, $key);
127
+		if (is_null($variable) && isset($_POST[$key])) {
128
+			$variable = $_POST[$key];
129
+		}
130
+		return $variable;
131
+	}
132
+
133
+	/**
134
+	 * @param string $key
135
+	 * @return array
136
+	 */
137
+	public static function filterInputArray($key)
138
+	{
139
+		$variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
140
+		if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) {
141
+			$variable = $_POST[$key];
142
+		}
143
+		return (array) $variable;
144
+	}
145
+
146
+	/**
147
+	 * @return string
148
+	 */
149
+	public static function getIpAddress()
150
+	{
151
+		$whitelist = [];
152
+		$isUsingCloudflare = !empty(filter_input(INPUT_SERVER, 'CF-Connecting-IP'));
153
+		if (apply_filters('site-reviews/whip/whitelist/cloudflare', $isUsingCloudflare)) {
154
+			$cloudflareIps = glsr(Cache::class)->getCloudflareIps();
155
+			$whitelist[Whip::CLOUDFLARE_HEADERS] = [Whip::IPV4 => $cloudflareIps['v4']];
156
+			if (defined('AF_INET6')) {
157
+				$whitelist[Whip::CLOUDFLARE_HEADERS][Whip::IPV6] = $cloudflareIps['v6'];
158
+			}
159
+		}
160
+		$whitelist = apply_filters('site-reviews/whip/whitelist', $whitelist);
161
+		$methods = apply_filters('site-reviews/whip/methods', Whip::ALL_METHODS);
162
+		$whip = new Whip($methods, $whitelist);
163
+		do_action_ref_array('site-reviews/whip', [$whip]);
164
+		if (false !== ($clientAddress = $whip->getValidIpAddress())) {
165
+			return (string) $clientAddress;
166
+		}
167
+		glsr_log()->error('Unable to detect IP address.');
168
+		return 'unknown';
169
+	}
170
+
171
+	/**
172
+	 * @param mixed $value
173
+	 * @param string|int $min
174
+	 * @param string|int $max
175
+	 * @return bool
176
+	 */
177
+	public static function inRange($value, $min, $max)
178
+	{
179
+		$inRange = filter_var($value, FILTER_VALIDATE_INT, ['options' => [
180
+			'min_range' => intval($min),
181
+			'max_range' => intval($max),
182
+		]]);
183
+		return false !== $inRange;
184
+	}
185
+
186
+	/**
187
+	 * @param int|string $value
188
+	 * @param int|string $compareWithValue
189
+	 * @return bool
190
+	 */
191
+	public static function isGreaterThan($value, $compareWithValue)
192
+	{
193
+		return version_compare($value, $compareWithValue, '>');
194
+	}
195
+
196
+	/**
197
+	 * @param int|string $value
198
+	 * @param int|string $compareWithValue
199
+	 * @return bool
200
+	 */
201
+	public static function isGreaterThanOrEqual($value, $compareWithValue)
202
+	{
203
+		return version_compare($value, $compareWithValue, '>=');
204
+	}
205
+
206
+	/**
207
+	 * @param int|string $value
208
+	 * @param int|string $compareWithValue
209
+	 * @return bool
210
+	 */
211
+	public static function isLessThan($value, $compareWithValue)
212
+	{
213
+		return version_compare($value, $compareWithValue, '<');
214
+	}
215
+
216
+	/**
217
+	 * @param int|string $value
218
+	 * @param int|string $compareWithValue
219
+	 * @return bool
220
+	 */
221
+	public static function isLessThanOrEqual($value, $compareWithValue)
222
+	{
223
+		return version_compare($value, $compareWithValue, '<=');
224
+	}
225 225
 }
Please login to merge, or discard this patch.
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -13,10 +13,10 @@  discard block
 block discarded – undo
13 13
      * @param string $path
14 14
      * @return string
15 15
      */
16
-    public static function buildClassName($name, $path = '')
16
+    public static function buildClassName( $name, $path = '' )
17 17
     {
18
-        $className = Str::camelCase($name);
19
-        $path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\');
18
+        $className = Str::camelCase( $name );
19
+        $path = ltrim( str_replace( __NAMESPACE__, '', $path ), '\\' );
20 20
         return !empty($path)
21 21
             ? __NAMESPACE__.'\\'.$path.'\\'.$className
22 22
             : $className;
@@ -27,18 +27,18 @@  discard block
 block discarded – undo
27 27
      * @param string $prefix
28 28
      * @return string
29 29
      */
30
-    public static function buildMethodName($name, $prefix = '')
30
+    public static function buildMethodName( $name, $prefix = '' )
31 31
     {
32
-        return lcfirst($prefix.static::buildClassName($name));
32
+        return lcfirst( $prefix.static::buildClassName( $name ) );
33 33
     }
34 34
 
35 35
     /**
36 36
      * @param string $name
37 37
      * @return string
38 38
      */
39
-    public static function buildPropertyName($name)
39
+    public static function buildPropertyName( $name )
40 40
     {
41
-        return static::buildMethodName($name);
41
+        return static::buildMethodName( $name );
42 42
     }
43 43
 
44 44
     /**
@@ -46,11 +46,11 @@  discard block
 block discarded – undo
46 46
      * @param mixed $value
47 47
      * @return mixed
48 48
      */
49
-    public static function castTo($cast = '', $value)
49
+    public static function castTo( $cast = '', $value )
50 50
     {
51
-        $method = static::buildMethodName($cast, 'castTo');
52
-        return !empty($cast) && method_exists(__CLASS__, $method)
53
-            ? static::$method($value)
51
+        $method = static::buildMethodName( $cast, 'castTo' );
52
+        return !empty($cast) && method_exists( __CLASS__, $method )
53
+            ? static::$method( $value )
54 54
             : $value;
55 55
     }
56 56
 
@@ -58,73 +58,73 @@  discard block
 block discarded – undo
58 58
      * @param mixed $value
59 59
      * @return array
60 60
      */
61
-    public static function castToArray($value)
61
+    public static function castToArray( $value )
62 62
     {
63
-        return (array) $value;
63
+        return (array)$value;
64 64
     }
65 65
 
66 66
     /**
67 67
      * @param mixed $value
68 68
      * @return bool
69 69
      */
70
-    public static function castToBool($value)
70
+    public static function castToBool( $value )
71 71
     {
72
-        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
72
+        return filter_var( $value, FILTER_VALIDATE_BOOLEAN );
73 73
     }
74 74
 
75 75
     /**
76 76
      * @param mixed $value
77 77
      * @return float
78 78
      */
79
-    public static function castToFloat($value)
79
+    public static function castToFloat( $value )
80 80
     {
81
-        return (float) filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND);
81
+        return (float)filter_var( $value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND );
82 82
     }
83 83
 
84 84
     /**
85 85
      * @param mixed $value
86 86
      * @return int
87 87
      */
88
-    public static function castToInt($value)
88
+    public static function castToInt( $value )
89 89
     {
90
-        return (int) filter_var($value, FILTER_VALIDATE_INT);
90
+        return (int)filter_var( $value, FILTER_VALIDATE_INT );
91 91
     }
92 92
 
93 93
     /**
94 94
      * @param mixed $value
95 95
      * @return object
96 96
      */
97
-    public static function castToObject($value)
97
+    public static function castToObject( $value )
98 98
     {
99
-        return (object) (array) $value;
99
+        return (object)(array)$value;
100 100
     }
101 101
 
102 102
     /**
103 103
      * @param mixed $value
104 104
      * @return string
105 105
      */
106
-    public static function castToString($value)
106
+    public static function castToString( $value )
107 107
     {
108
-        if (is_object($value) && in_array('__toString', get_class_methods($value))) {
109
-            return (string) $value->__toString();
108
+        if( is_object( $value ) && in_array( '__toString', get_class_methods( $value ) ) ) {
109
+            return (string)$value->__toString();
110 110
         }
111
-        if (is_array($value) || is_object($value)) {
112
-            return serialize($value);
111
+        if( is_array( $value ) || is_object( $value ) ) {
112
+            return serialize( $value );
113 113
         }
114
-        return (string) $value;
114
+        return (string)$value;
115 115
     }
116 116
 
117 117
     /**
118 118
      * @param string $key
119 119
      * @return mixed
120 120
      */
121
-    public static function filterInput($key, array $request = [])
121
+    public static function filterInput( $key, array $request = [] )
122 122
     {
123
-        if (isset($request[$key])) {
123
+        if( isset($request[$key]) ) {
124 124
             return $request[$key];
125 125
         }
126
-        $variable = filter_input(INPUT_POST, $key);
127
-        if (is_null($variable) && isset($_POST[$key])) {
126
+        $variable = filter_input( INPUT_POST, $key );
127
+        if( is_null( $variable ) && isset($_POST[$key]) ) {
128 128
             $variable = $_POST[$key];
129 129
         }
130 130
         return $variable;
@@ -134,13 +134,13 @@  discard block
 block discarded – undo
134 134
      * @param string $key
135 135
      * @return array
136 136
      */
137
-    public static function filterInputArray($key)
137
+    public static function filterInputArray( $key )
138 138
     {
139
-        $variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
140
-        if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) {
139
+        $variable = filter_input( INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
140
+        if( empty($variable) && !empty($_POST[$key]) && is_array( $_POST[$key] ) ) {
141 141
             $variable = $_POST[$key];
142 142
         }
143
-        return (array) $variable;
143
+        return (array)$variable;
144 144
     }
145 145
 
146 146
     /**
@@ -149,22 +149,22 @@  discard block
 block discarded – undo
149 149
     public static function getIpAddress()
150 150
     {
151 151
         $whitelist = [];
152
-        $isUsingCloudflare = !empty(filter_input(INPUT_SERVER, 'CF-Connecting-IP'));
153
-        if (apply_filters('site-reviews/whip/whitelist/cloudflare', $isUsingCloudflare)) {
154
-            $cloudflareIps = glsr(Cache::class)->getCloudflareIps();
152
+        $isUsingCloudflare = !empty(filter_input( INPUT_SERVER, 'CF-Connecting-IP' ));
153
+        if( apply_filters( 'site-reviews/whip/whitelist/cloudflare', $isUsingCloudflare ) ) {
154
+            $cloudflareIps = glsr( Cache::class )->getCloudflareIps();
155 155
             $whitelist[Whip::CLOUDFLARE_HEADERS] = [Whip::IPV4 => $cloudflareIps['v4']];
156
-            if (defined('AF_INET6')) {
156
+            if( defined( 'AF_INET6' ) ) {
157 157
                 $whitelist[Whip::CLOUDFLARE_HEADERS][Whip::IPV6] = $cloudflareIps['v6'];
158 158
             }
159 159
         }
160
-        $whitelist = apply_filters('site-reviews/whip/whitelist', $whitelist);
161
-        $methods = apply_filters('site-reviews/whip/methods', Whip::ALL_METHODS);
162
-        $whip = new Whip($methods, $whitelist);
163
-        do_action_ref_array('site-reviews/whip', [$whip]);
164
-        if (false !== ($clientAddress = $whip->getValidIpAddress())) {
165
-            return (string) $clientAddress;
160
+        $whitelist = apply_filters( 'site-reviews/whip/whitelist', $whitelist );
161
+        $methods = apply_filters( 'site-reviews/whip/methods', Whip::ALL_METHODS );
162
+        $whip = new Whip( $methods, $whitelist );
163
+        do_action_ref_array( 'site-reviews/whip', [$whip] );
164
+        if( false !== ($clientAddress = $whip->getValidIpAddress()) ) {
165
+            return (string)$clientAddress;
166 166
         }
167
-        glsr_log()->error('Unable to detect IP address.');
167
+        glsr_log()->error( 'Unable to detect IP address.' );
168 168
         return 'unknown';
169 169
     }
170 170
 
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
      * @param string|int $max
175 175
      * @return bool
176 176
      */
177
-    public static function inRange($value, $min, $max)
177
+    public static function inRange( $value, $min, $max )
178 178
     {
179
-        $inRange = filter_var($value, FILTER_VALIDATE_INT, ['options' => [
180
-            'min_range' => intval($min),
181
-            'max_range' => intval($max),
182
-        ]]);
179
+        $inRange = filter_var( $value, FILTER_VALIDATE_INT, ['options' => [
180
+            'min_range' => intval( $min ),
181
+            'max_range' => intval( $max ),
182
+        ]] );
183 183
         return false !== $inRange;
184 184
     }
185 185
 
@@ -188,9 +188,9 @@  discard block
 block discarded – undo
188 188
      * @param int|string $compareWithValue
189 189
      * @return bool
190 190
      */
191
-    public static function isGreaterThan($value, $compareWithValue)
191
+    public static function isGreaterThan( $value, $compareWithValue )
192 192
     {
193
-        return version_compare($value, $compareWithValue, '>');
193
+        return version_compare( $value, $compareWithValue, '>' );
194 194
     }
195 195
 
196 196
     /**
@@ -198,9 +198,9 @@  discard block
 block discarded – undo
198 198
      * @param int|string $compareWithValue
199 199
      * @return bool
200 200
      */
201
-    public static function isGreaterThanOrEqual($value, $compareWithValue)
201
+    public static function isGreaterThanOrEqual( $value, $compareWithValue )
202 202
     {
203
-        return version_compare($value, $compareWithValue, '>=');
203
+        return version_compare( $value, $compareWithValue, '>=' );
204 204
     }
205 205
 
206 206
     /**
@@ -208,9 +208,9 @@  discard block
 block discarded – undo
208 208
      * @param int|string $compareWithValue
209 209
      * @return bool
210 210
      */
211
-    public static function isLessThan($value, $compareWithValue)
211
+    public static function isLessThan( $value, $compareWithValue )
212 212
     {
213
-        return version_compare($value, $compareWithValue, '<');
213
+        return version_compare( $value, $compareWithValue, '<' );
214 214
     }
215 215
 
216 216
     /**
@@ -218,8 +218,8 @@  discard block
 block discarded – undo
218 218
      * @param int|string $compareWithValue
219 219
      * @return bool
220 220
      */
221
-    public static function isLessThanOrEqual($value, $compareWithValue)
221
+    public static function isLessThanOrEqual( $value, $compareWithValue )
222 222
     {
223
-        return version_compare($value, $compareWithValue, '<=');
223
+        return version_compare( $value, $compareWithValue, '<=' );
224 224
     }
225 225
 }
Please login to merge, or discard this patch.
plugin/Database/OptionManager.php 2 patches
Indentation   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -9,157 +9,157 @@
 block discarded – undo
9 9
 
10 10
 class OptionManager
11 11
 {
12
-    /**
13
-     * @var array
14
-     */
15
-    protected $options;
12
+	/**
13
+	 * @var array
14
+	 */
15
+	protected $options;
16 16
 
17
-    /**
18
-     * @return string
19
-     */
20
-    public static function databaseKey($version = null)
21
-    {
22
-        if (1 == $version) {
23
-            return 'geminilabs_site_reviews_settings';
24
-        }
25
-        if (2 == $version) {
26
-            return 'geminilabs_site_reviews-v2';
27
-        }
28
-        if (null === $version) {
29
-            $version = explode('.', glsr()->version);
30
-            $version = array_shift($version);
31
-        }
32
-        return Str::snakeCase(Application::ID.'-v'.intval($version));
33
-    }
17
+	/**
18
+	 * @return string
19
+	 */
20
+	public static function databaseKey($version = null)
21
+	{
22
+		if (1 == $version) {
23
+			return 'geminilabs_site_reviews_settings';
24
+		}
25
+		if (2 == $version) {
26
+			return 'geminilabs_site_reviews-v2';
27
+		}
28
+		if (null === $version) {
29
+			$version = explode('.', glsr()->version);
30
+			$version = array_shift($version);
31
+		}
32
+		return Str::snakeCase(Application::ID.'-v'.intval($version));
33
+	}
34 34
 
35
-    /**
36
-     * @return array
37
-     */
38
-    public function all()
39
-    {
40
-        if (empty($this->options)) {
41
-            $this->reset();
42
-        }
43
-        return $this->options;
44
-    }
35
+	/**
36
+	 * @return array
37
+	 */
38
+	public function all()
39
+	{
40
+		if (empty($this->options)) {
41
+			$this->reset();
42
+		}
43
+		return $this->options;
44
+	}
45 45
 
46
-    /**
47
-     * @param string $path
48
-     * @return bool
49
-     */
50
-    public function delete($path)
51
-    {
52
-        $keys = explode('.', $path);
53
-        $last = array_pop($keys);
54
-        $options = $this->all();
55
-        $pointer = &$options;
56
-        foreach ($keys as $key) {
57
-            if (!isset($pointer[$key]) || !is_array($pointer[$key])) {
58
-                continue;
59
-            }
60
-            $pointer = &$pointer[$key];
61
-        }
62
-        unset($pointer[$last]);
63
-        return $this->set($options);
64
-    }
46
+	/**
47
+	 * @param string $path
48
+	 * @return bool
49
+	 */
50
+	public function delete($path)
51
+	{
52
+		$keys = explode('.', $path);
53
+		$last = array_pop($keys);
54
+		$options = $this->all();
55
+		$pointer = &$options;
56
+		foreach ($keys as $key) {
57
+			if (!isset($pointer[$key]) || !is_array($pointer[$key])) {
58
+				continue;
59
+			}
60
+			$pointer = &$pointer[$key];
61
+		}
62
+		unset($pointer[$last]);
63
+		return $this->set($options);
64
+	}
65 65
 
66
-    /**
67
-     * @param string $path
68
-     * @param mixed $fallback
69
-     * @param string $cast
70
-     * @return mixed
71
-     */
72
-    public function get($path = '', $fallback = '', $cast = '')
73
-    {
74
-        $result = Arr::get($this->all(), $path, $fallback);
75
-        return Helper::castTo($cast, $result);
76
-    }
66
+	/**
67
+	 * @param string $path
68
+	 * @param mixed $fallback
69
+	 * @param string $cast
70
+	 * @return mixed
71
+	 */
72
+	public function get($path = '', $fallback = '', $cast = '')
73
+	{
74
+		$result = Arr::get($this->all(), $path, $fallback);
75
+		return Helper::castTo($cast, $result);
76
+	}
77 77
 
78
-    /**
79
-     * @param string $path
80
-     * @return bool
81
-     */
82
-    public function getBool($path)
83
-    {
84
-        return Helper::castToBool($this->get($path));
85
-    }
78
+	/**
79
+	 * @param string $path
80
+	 * @return bool
81
+	 */
82
+	public function getBool($path)
83
+	{
84
+		return Helper::castToBool($this->get($path));
85
+	}
86 86
 
87
-    /**
88
-     * @param string $path
89
-     * @param mixed $fallback
90
-     * @param string $cast
91
-     * @return mixed
92
-     */
93
-    public function getWP($path, $fallback = '', $cast = '')
94
-    {
95
-        $option = get_option($path, $fallback);
96
-        if (empty($option)) {
97
-            $option = $fallback;
98
-        }
99
-        return Helper::castTo($cast, $option);
100
-    }
87
+	/**
88
+	 * @param string $path
89
+	 * @param mixed $fallback
90
+	 * @param string $cast
91
+	 * @return mixed
92
+	 */
93
+	public function getWP($path, $fallback = '', $cast = '')
94
+	{
95
+		$option = get_option($path, $fallback);
96
+		if (empty($option)) {
97
+			$option = $fallback;
98
+		}
99
+		return Helper::castTo($cast, $option);
100
+	}
101 101
 
102
-    /**
103
-     * @return string
104
-     */
105
-    public function json()
106
-    {
107
-        return json_encode($this->all());
108
-    }
102
+	/**
103
+	 * @return string
104
+	 */
105
+	public function json()
106
+	{
107
+		return json_encode($this->all());
108
+	}
109 109
 
110
-    /**
111
-     * @return array
112
-     */
113
-    public function normalize(array $options = [])
114
-    {
115
-        $options = wp_parse_args(
116
-            Arr::flattenArray($options),
117
-            glsr(DefaultsManager::class)->defaults()
118
-        );
119
-        array_walk($options, function (&$value) {
120
-            if (!is_string($value)) {
121
-                return;
122
-            }
123
-            $value = wp_kses($value, wp_kses_allowed_html('post'));
124
-        });
125
-        return Arr::convertDotNotationArray($options);
126
-    }
110
+	/**
111
+	 * @return array
112
+	 */
113
+	public function normalize(array $options = [])
114
+	{
115
+		$options = wp_parse_args(
116
+			Arr::flattenArray($options),
117
+			glsr(DefaultsManager::class)->defaults()
118
+		);
119
+		array_walk($options, function (&$value) {
120
+			if (!is_string($value)) {
121
+				return;
122
+			}
123
+			$value = wp_kses($value, wp_kses_allowed_html('post'));
124
+		});
125
+		return Arr::convertDotNotationArray($options);
126
+	}
127 127
 
128
-    /**
129
-     * @return bool
130
-     */
131
-    public function isRecaptchaEnabled()
132
-    {
133
-        $integration = $this->get('settings.submissions.recaptcha.integration');
134
-        return 'all' == $integration || ('guest' == $integration && !is_user_logged_in());
135
-    }
128
+	/**
129
+	 * @return bool
130
+	 */
131
+	public function isRecaptchaEnabled()
132
+	{
133
+		$integration = $this->get('settings.submissions.recaptcha.integration');
134
+		return 'all' == $integration || ('guest' == $integration && !is_user_logged_in());
135
+	}
136 136
 
137
-    /**
138
-     * @return array
139
-     */
140
-    public function reset()
141
-    {
142
-        $options = $this->getWP(static::databaseKey(), []);
143
-        if (!is_array($options) || empty($options)) {
144
-            delete_option(static::databaseKey());
145
-            $options = glsr()->defaults ?: [];
146
-        }
147
-        $this->options = $options;
148
-    }
137
+	/**
138
+	 * @return array
139
+	 */
140
+	public function reset()
141
+	{
142
+		$options = $this->getWP(static::databaseKey(), []);
143
+		if (!is_array($options) || empty($options)) {
144
+			delete_option(static::databaseKey());
145
+			$options = glsr()->defaults ?: [];
146
+		}
147
+		$this->options = $options;
148
+	}
149 149
 
150
-    /**
151
-     * @param string|array $pathOrOptions
152
-     * @param mixed $value
153
-     * @return bool
154
-     */
155
-    public function set($pathOrOptions, $value = '')
156
-    {
157
-        if (is_string($pathOrOptions)) {
158
-            $pathOrOptions = Arr::set($this->all(), $pathOrOptions, $value);
159
-        }
160
-        if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) {
161
-            $this->reset();
162
-        }
163
-        return $result;
164
-    }
150
+	/**
151
+	 * @param string|array $pathOrOptions
152
+	 * @param mixed $value
153
+	 * @return bool
154
+	 */
155
+	public function set($pathOrOptions, $value = '')
156
+	{
157
+		if (is_string($pathOrOptions)) {
158
+			$pathOrOptions = Arr::set($this->all(), $pathOrOptions, $value);
159
+		}
160
+		if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) {
161
+			$this->reset();
162
+		}
163
+		return $result;
164
+	}
165 165
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -17,19 +17,19 @@  discard block
 block discarded – undo
17 17
     /**
18 18
      * @return string
19 19
      */
20
-    public static function databaseKey($version = null)
20
+    public static function databaseKey( $version = null )
21 21
     {
22
-        if (1 == $version) {
22
+        if( 1 == $version ) {
23 23
             return 'geminilabs_site_reviews_settings';
24 24
         }
25
-        if (2 == $version) {
25
+        if( 2 == $version ) {
26 26
             return 'geminilabs_site_reviews-v2';
27 27
         }
28
-        if (null === $version) {
29
-            $version = explode('.', glsr()->version);
30
-            $version = array_shift($version);
28
+        if( null === $version ) {
29
+            $version = explode( '.', glsr()->version );
30
+            $version = array_shift( $version );
31 31
         }
32
-        return Str::snakeCase(Application::ID.'-v'.intval($version));
32
+        return Str::snakeCase( Application::ID.'-v'.intval( $version ) );
33 33
     }
34 34
 
35 35
     /**
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
      */
38 38
     public function all()
39 39
     {
40
-        if (empty($this->options)) {
40
+        if( empty($this->options) ) {
41 41
             $this->reset();
42 42
         }
43 43
         return $this->options;
@@ -47,20 +47,20 @@  discard block
 block discarded – undo
47 47
      * @param string $path
48 48
      * @return bool
49 49
      */
50
-    public function delete($path)
50
+    public function delete( $path )
51 51
     {
52
-        $keys = explode('.', $path);
53
-        $last = array_pop($keys);
52
+        $keys = explode( '.', $path );
53
+        $last = array_pop( $keys );
54 54
         $options = $this->all();
55 55
         $pointer = &$options;
56
-        foreach ($keys as $key) {
57
-            if (!isset($pointer[$key]) || !is_array($pointer[$key])) {
56
+        foreach( $keys as $key ) {
57
+            if( !isset($pointer[$key]) || !is_array( $pointer[$key] ) ) {
58 58
                 continue;
59 59
             }
60 60
             $pointer = &$pointer[$key];
61 61
         }
62 62
         unset($pointer[$last]);
63
-        return $this->set($options);
63
+        return $this->set( $options );
64 64
     }
65 65
 
66 66
     /**
@@ -69,19 +69,19 @@  discard block
 block discarded – undo
69 69
      * @param string $cast
70 70
      * @return mixed
71 71
      */
72
-    public function get($path = '', $fallback = '', $cast = '')
72
+    public function get( $path = '', $fallback = '', $cast = '' )
73 73
     {
74
-        $result = Arr::get($this->all(), $path, $fallback);
75
-        return Helper::castTo($cast, $result);
74
+        $result = Arr::get( $this->all(), $path, $fallback );
75
+        return Helper::castTo( $cast, $result );
76 76
     }
77 77
 
78 78
     /**
79 79
      * @param string $path
80 80
      * @return bool
81 81
      */
82
-    public function getBool($path)
82
+    public function getBool( $path )
83 83
     {
84
-        return Helper::castToBool($this->get($path));
84
+        return Helper::castToBool( $this->get( $path ) );
85 85
     }
86 86
 
87 87
     /**
@@ -90,13 +90,13 @@  discard block
 block discarded – undo
90 90
      * @param string $cast
91 91
      * @return mixed
92 92
      */
93
-    public function getWP($path, $fallback = '', $cast = '')
93
+    public function getWP( $path, $fallback = '', $cast = '' )
94 94
     {
95
-        $option = get_option($path, $fallback);
96
-        if (empty($option)) {
95
+        $option = get_option( $path, $fallback );
96
+        if( empty($option) ) {
97 97
             $option = $fallback;
98 98
         }
99
-        return Helper::castTo($cast, $option);
99
+        return Helper::castTo( $cast, $option );
100 100
     }
101 101
 
102 102
     /**
@@ -104,25 +104,25 @@  discard block
 block discarded – undo
104 104
      */
105 105
     public function json()
106 106
     {
107
-        return json_encode($this->all());
107
+        return json_encode( $this->all() );
108 108
     }
109 109
 
110 110
     /**
111 111
      * @return array
112 112
      */
113
-    public function normalize(array $options = [])
113
+    public function normalize( array $options = [] )
114 114
     {
115 115
         $options = wp_parse_args(
116
-            Arr::flattenArray($options),
117
-            glsr(DefaultsManager::class)->defaults()
116
+            Arr::flattenArray( $options ),
117
+            glsr( DefaultsManager::class )->defaults()
118 118
         );
119
-        array_walk($options, function (&$value) {
120
-            if (!is_string($value)) {
119
+        array_walk( $options, function( &$value ) {
120
+            if( !is_string( $value ) ) {
121 121
                 return;
122 122
             }
123
-            $value = wp_kses($value, wp_kses_allowed_html('post'));
123
+            $value = wp_kses( $value, wp_kses_allowed_html( 'post' ) );
124 124
         });
125
-        return Arr::convertDotNotationArray($options);
125
+        return Arr::convertDotNotationArray( $options );
126 126
     }
127 127
 
128 128
     /**
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
      */
131 131
     public function isRecaptchaEnabled()
132 132
     {
133
-        $integration = $this->get('settings.submissions.recaptcha.integration');
133
+        $integration = $this->get( 'settings.submissions.recaptcha.integration' );
134 134
         return 'all' == $integration || ('guest' == $integration && !is_user_logged_in());
135 135
     }
136 136
 
@@ -139,9 +139,9 @@  discard block
 block discarded – undo
139 139
      */
140 140
     public function reset()
141 141
     {
142
-        $options = $this->getWP(static::databaseKey(), []);
143
-        if (!is_array($options) || empty($options)) {
144
-            delete_option(static::databaseKey());
142
+        $options = $this->getWP( static::databaseKey(), [] );
143
+        if( !is_array( $options ) || empty($options) ) {
144
+            delete_option( static::databaseKey() );
145 145
             $options = glsr()->defaults ?: [];
146 146
         }
147 147
         $this->options = $options;
@@ -152,12 +152,12 @@  discard block
 block discarded – undo
152 152
      * @param mixed $value
153 153
      * @return bool
154 154
      */
155
-    public function set($pathOrOptions, $value = '')
155
+    public function set( $pathOrOptions, $value = '' )
156 156
     {
157
-        if (is_string($pathOrOptions)) {
158
-            $pathOrOptions = Arr::set($this->all(), $pathOrOptions, $value);
157
+        if( is_string( $pathOrOptions ) ) {
158
+            $pathOrOptions = Arr::set( $this->all(), $pathOrOptions, $value );
159 159
         }
160
-        if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) {
160
+        if( $result = update_option( static::databaseKey(), (array)$pathOrOptions ) ) {
161 161
             $this->reset();
162 162
         }
163 163
         return $result;
Please login to merge, or discard this patch.
plugin/Database/CountsManager.php 2 patches
Indentation   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -14,248 +14,248 @@
 block discarded – undo
14 14
 
15 15
 class CountsManager
16 16
 {
17
-    const LIMIT = 500;
18
-    const META_AVERAGE = '_glsr_average';
19
-    const META_COUNT = '_glsr_count';
20
-    const META_RANKING = '_glsr_ranking';
17
+	const LIMIT = 500;
18
+	const META_AVERAGE = '_glsr_average';
19
+	const META_COUNT = '_glsr_count';
20
+	const META_RANKING = '_glsr_ranking';
21 21
 
22
-    /**
23
-     * @return array
24
-     */
25
-    public function buildCounts(array $args = [])
26
-    {
27
-        $counts = [
28
-            'local' => $this->generateEmptyCountsArray(),
29
-        ];
30
-        $query = $this->queryReviews($args);
31
-        while ($query) {
32
-            $counts = $this->populateCountsFromQuery($query, $counts);
33
-            $query = $query->has_more
34
-                ? $this->queryReviews($args, end($query->reviews)->ID)
35
-                : false;
36
-        }
37
-        return $counts;
38
-    }
22
+	/**
23
+	 * @return array
24
+	 */
25
+	public function buildCounts(array $args = [])
26
+	{
27
+		$counts = [
28
+			'local' => $this->generateEmptyCountsArray(),
29
+		];
30
+		$query = $this->queryReviews($args);
31
+		while ($query) {
32
+			$counts = $this->populateCountsFromQuery($query, $counts);
33
+			$query = $query->has_more
34
+				? $this->queryReviews($args, end($query->reviews)->ID)
35
+				: false;
36
+		}
37
+		return $counts;
38
+	}
39 39
 
40
-    /**
41
-     * @return void
42
-     */
43
-    public function decreaseAll(Review $review)
44
-    {
45
-        glsr(GlobalCountsManager::class)->decrease($review);
46
-        glsr(PostCountsManager::class)->decrease($review);
47
-        glsr(TermCountsManager::class)->decrease($review);
48
-    }
40
+	/**
41
+	 * @return void
42
+	 */
43
+	public function decreaseAll(Review $review)
44
+	{
45
+		glsr(GlobalCountsManager::class)->decrease($review);
46
+		glsr(PostCountsManager::class)->decrease($review);
47
+		glsr(TermCountsManager::class)->decrease($review);
48
+	}
49 49
 
50
-    /**
51
-     * @param string $type
52
-     * @param int $rating
53
-     * @return array
54
-     */
55
-    public function decreaseRating(array $reviewCounts, $type, $rating)
56
-    {
57
-        if (isset($reviewCounts[$type][$rating])) {
58
-            $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1);
59
-        }
60
-        return $reviewCounts;
61
-    }
50
+	/**
51
+	 * @param string $type
52
+	 * @param int $rating
53
+	 * @return array
54
+	 */
55
+	public function decreaseRating(array $reviewCounts, $type, $rating)
56
+	{
57
+		if (isset($reviewCounts[$type][$rating])) {
58
+			$reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1);
59
+		}
60
+		return $reviewCounts;
61
+	}
62 62
 
63
-    /**
64
-     * @return array
65
-     */
66
-    public function flatten(array $reviewCounts, array $args = [])
67
-    {
68
-        $counts = [];
69
-        array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) {
70
-            $counts[$index] = $num + intval(Arr::get($counts, $index, 0));
71
-        });
72
-        $min = Arr::get($args, 'min', glsr()->constant('MIN_RATING', Rating::class));
73
-        $max = Arr::get($args, 'max', glsr()->constant('MAX_RATING', Rating::class));
74
-        foreach ($counts as $index => &$num) {
75
-            if (!Helper::inRange($index, $min, $max)) {
76
-                $num = 0;
77
-            }
78
-        }
79
-        return $counts;
80
-    }
63
+	/**
64
+	 * @return array
65
+	 */
66
+	public function flatten(array $reviewCounts, array $args = [])
67
+	{
68
+		$counts = [];
69
+		array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) {
70
+			$counts[$index] = $num + intval(Arr::get($counts, $index, 0));
71
+		});
72
+		$min = Arr::get($args, 'min', glsr()->constant('MIN_RATING', Rating::class));
73
+		$max = Arr::get($args, 'max', glsr()->constant('MAX_RATING', Rating::class));
74
+		foreach ($counts as $index => &$num) {
75
+			if (!Helper::inRange($index, $min, $max)) {
76
+				$num = 0;
77
+			}
78
+		}
79
+		return $counts;
80
+	}
81 81
 
82
-    /**
83
-     * @return array
84
-     */
85
-    public function getCounts(array $args = [])
86
-    {
87
-        $args = $this->normalizeArgs($args);
88
-        $counts = $this->hasMixedAssignment($args)
89
-            ? $this->buildCounts($args) // force query the database
90
-            : $this->get($args);
91
-        return $this->normalize($counts);
92
-    }
82
+	/**
83
+	 * @return array
84
+	 */
85
+	public function getCounts(array $args = [])
86
+	{
87
+		$args = $this->normalizeArgs($args);
88
+		$counts = $this->hasMixedAssignment($args)
89
+			? $this->buildCounts($args) // force query the database
90
+			: $this->get($args);
91
+		return $this->normalize($counts);
92
+	}
93 93
 
94
-    /**
95
-     * @return void
96
-     */
97
-    public function increaseAll(Review $review)
98
-    {
99
-        glsr(GlobalCountsManager::class)->increase($review);
100
-        glsr(PostCountsManager::class)->increase($review);
101
-        glsr(TermCountsManager::class)->increase($review);
102
-    }
94
+	/**
95
+	 * @return void
96
+	 */
97
+	public function increaseAll(Review $review)
98
+	{
99
+		glsr(GlobalCountsManager::class)->increase($review);
100
+		glsr(PostCountsManager::class)->increase($review);
101
+		glsr(TermCountsManager::class)->increase($review);
102
+	}
103 103
 
104
-    /**
105
-     * @param string $type
106
-     * @param int $rating
107
-     * @return array
108
-     */
109
-    public function increaseRating(array $reviewCounts, $type, $rating)
110
-    {
111
-        if (!array_key_exists($type, glsr()->reviewTypes)) {
112
-            return $reviewCounts;
113
-        }
114
-        if (!array_key_exists($type, $reviewCounts)) {
115
-            $reviewCounts[$type] = [];
116
-        }
117
-        $reviewCounts = $this->normalize($reviewCounts);
118
-        $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1;
119
-        return $reviewCounts;
120
-    }
104
+	/**
105
+	 * @param string $type
106
+	 * @param int $rating
107
+	 * @return array
108
+	 */
109
+	public function increaseRating(array $reviewCounts, $type, $rating)
110
+	{
111
+		if (!array_key_exists($type, glsr()->reviewTypes)) {
112
+			return $reviewCounts;
113
+		}
114
+		if (!array_key_exists($type, $reviewCounts)) {
115
+			$reviewCounts[$type] = [];
116
+		}
117
+		$reviewCounts = $this->normalize($reviewCounts);
118
+		$reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1;
119
+		return $reviewCounts;
120
+	}
121 121
 
122
-    /**
123
-     * @return void
124
-     */
125
-    public function updateAll()
126
-    {
127
-        glsr(GlobalCountsManager::class)->updateAll();
128
-        glsr(PostCountsManager::class)->updateAll();
129
-        glsr(TermCountsManager::class)->updateAll();
130
-        glsr(OptionManager::class)->set('last_review_count', current_time('timestamp'));
131
-    }
122
+	/**
123
+	 * @return void
124
+	 */
125
+	public function updateAll()
126
+	{
127
+		glsr(GlobalCountsManager::class)->updateAll();
128
+		glsr(PostCountsManager::class)->updateAll();
129
+		glsr(TermCountsManager::class)->updateAll();
130
+		glsr(OptionManager::class)->set('last_review_count', current_time('timestamp'));
131
+	}
132 132
 
133
-    /**
134
-     * @return array
135
-     */
136
-    protected function combine(array $results)
137
-    {
138
-        if (!wp_is_numeric_array($results)) {
139
-            return $results;
140
-        }
141
-        $mergedKeys = array_keys(array_merge(...$results));
142
-        $counts = array_fill_keys($mergedKeys, $this->generateEmptyCountsArray());
143
-        foreach ($results as $typeRatings) {
144
-            foreach ($typeRatings as $type => $ratings) {
145
-                foreach ($ratings as $index => $rating) {
146
-                    $counts[$type][$index] = intval($rating) + $counts[$type][$index];
147
-                }
148
-            }
149
-        }
150
-        return $counts;
151
-    }
133
+	/**
134
+	 * @return array
135
+	 */
136
+	protected function combine(array $results)
137
+	{
138
+		if (!wp_is_numeric_array($results)) {
139
+			return $results;
140
+		}
141
+		$mergedKeys = array_keys(array_merge(...$results));
142
+		$counts = array_fill_keys($mergedKeys, $this->generateEmptyCountsArray());
143
+		foreach ($results as $typeRatings) {
144
+			foreach ($typeRatings as $type => $ratings) {
145
+				foreach ($ratings as $index => $rating) {
146
+					$counts[$type][$index] = intval($rating) + $counts[$type][$index];
147
+				}
148
+			}
149
+		}
150
+		return $counts;
151
+	}
152 152
 
153
-    /**
154
-     * @return array
155
-     */
156
-    protected function generateEmptyCountsArray()
157
-    {
158
-        return array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0);
159
-    }
153
+	/**
154
+	 * @return array
155
+	 */
156
+	protected function generateEmptyCountsArray()
157
+	{
158
+		return array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0);
159
+	}
160 160
 
161
-    /**
162
-     * @return array
163
-     */
164
-    protected function get($args)
165
-    {
166
-        $results = [];
167
-        foreach ($args['post_ids'] as $postId) {
168
-            $results[] = glsr(PostCountsManager::class)->get($postId);
169
-        }
170
-        foreach ($args['term_ids'] as $termId) {
171
-            $results[] = glsr(TermCountsManager::class)->get($termId);
172
-        }
173
-        if (empty($results)) {
174
-            $results[] = glsr(GlobalCountsManager::class)->get();
175
-        }
176
-        $results[] = ['local' => $this->generateEmptyCountsArray()]; // make sure there is a fallback
177
-        return $this->combine($results);
178
-    }
161
+	/**
162
+	 * @return array
163
+	 */
164
+	protected function get($args)
165
+	{
166
+		$results = [];
167
+		foreach ($args['post_ids'] as $postId) {
168
+			$results[] = glsr(PostCountsManager::class)->get($postId);
169
+		}
170
+		foreach ($args['term_ids'] as $termId) {
171
+			$results[] = glsr(TermCountsManager::class)->get($termId);
172
+		}
173
+		if (empty($results)) {
174
+			$results[] = glsr(GlobalCountsManager::class)->get();
175
+		}
176
+		$results[] = ['local' => $this->generateEmptyCountsArray()]; // make sure there is a fallback
177
+		return $this->combine($results);
178
+	}
179 179
 
180
-    /**
181
-     * @return bool
182
-     */
183
-    protected function hasMixedAssignment(array $args)
184
-    {
185
-        return !empty($args['post_ids']) && !empty($args['term_ids']);
186
-    }
180
+	/**
181
+	 * @return bool
182
+	 */
183
+	protected function hasMixedAssignment(array $args)
184
+	{
185
+		return !empty($args['post_ids']) && !empty($args['term_ids']);
186
+	}
187 187
 
188
-    /**
189
-     * @return array
190
-     */
191
-    protected function normalize(array $reviewCounts)
192
-    {
193
-        foreach ($reviewCounts as &$counts) {
194
-            foreach (array_keys($this->generateEmptyCountsArray()) as $index) {
195
-                if (!isset($counts[$index])) {
196
-                    $counts[$index] = 0;
197
-                }
198
-            }
199
-            ksort($counts);
200
-        }
201
-        return $reviewCounts;
202
-    }
188
+	/**
189
+	 * @return array
190
+	 */
191
+	protected function normalize(array $reviewCounts)
192
+	{
193
+		foreach ($reviewCounts as &$counts) {
194
+			foreach (array_keys($this->generateEmptyCountsArray()) as $index) {
195
+				if (!isset($counts[$index])) {
196
+					$counts[$index] = 0;
197
+				}
198
+			}
199
+			ksort($counts);
200
+		}
201
+		return $reviewCounts;
202
+	}
203 203
 
204
-    /**
205
-     * @return array
206
-     */
207
-    protected function normalizeArgs(array $args)
208
-    {
209
-        $args = wp_parse_args(array_filter($args), [
210
-            'post_ids' => [],
211
-            'term_ids' => [],
212
-            'type' => 'local',
213
-        ]);
214
-        $args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']);
215
-        $args['type'] = $this->normalizeType($args['type']);
216
-        return $args;
217
-    }
204
+	/**
205
+	 * @return array
206
+	 */
207
+	protected function normalizeArgs(array $args)
208
+	{
209
+		$args = wp_parse_args(array_filter($args), [
210
+			'post_ids' => [],
211
+			'term_ids' => [],
212
+			'type' => 'local',
213
+		]);
214
+		$args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']);
215
+		$args['type'] = $this->normalizeType($args['type']);
216
+		return $args;
217
+	}
218 218
 
219
-    /**
220
-     * @param string $type
221
-     * @return string
222
-     */
223
-    protected function normalizeType($type)
224
-    {
225
-        return empty($type) || !is_string($type)
226
-            ? 'local'
227
-            : $type;
228
-    }
219
+	/**
220
+	 * @param string $type
221
+	 * @return string
222
+	 */
223
+	protected function normalizeType($type)
224
+	{
225
+		return empty($type) || !is_string($type)
226
+			? 'local'
227
+			: $type;
228
+	}
229 229
 
230
-    /**
231
-     * @param object $query
232
-     * @return array
233
-     */
234
-    protected function populateCountsFromQuery($query, array $counts)
235
-    {
236
-        foreach ($query->reviews as $review) {
237
-            $type = $this->normalizeType($review->type);
238
-            if (!array_key_exists($type, $counts)) {
239
-                $counts[$type] = $this->generateEmptyCountsArray();
240
-            }
241
-            ++$counts[$type][$review->rating];
242
-        }
243
-        return $counts;
244
-    }
230
+	/**
231
+	 * @param object $query
232
+	 * @return array
233
+	 */
234
+	protected function populateCountsFromQuery($query, array $counts)
235
+	{
236
+		foreach ($query->reviews as $review) {
237
+			$type = $this->normalizeType($review->type);
238
+			if (!array_key_exists($type, $counts)) {
239
+				$counts[$type] = $this->generateEmptyCountsArray();
240
+			}
241
+			++$counts[$type][$review->rating];
242
+		}
243
+		return $counts;
244
+	}
245 245
 
246
-    /**
247
-     * @param int $lastPostId
248
-     * @return object
249
-     */
250
-    protected function queryReviews(array $args = [], $lastPostId = 0)
251
-    {
252
-        $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT);
253
-        $hasMore = is_array($reviews)
254
-            ? count($reviews) == static::LIMIT
255
-            : false;
256
-        return (object) [
257
-            'has_more' => $hasMore,
258
-            'reviews' => $reviews,
259
-        ];
260
-    }
246
+	/**
247
+	 * @param int $lastPostId
248
+	 * @return object
249
+	 */
250
+	protected function queryReviews(array $args = [], $lastPostId = 0)
251
+	{
252
+		$reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT);
253
+		$hasMore = is_array($reviews)
254
+			? count($reviews) == static::LIMIT
255
+			: false;
256
+		return (object) [
257
+			'has_more' => $hasMore,
258
+			'reviews' => $reviews,
259
+		];
260
+	}
261 261
 }
Please login to merge, or discard this patch.
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -22,16 +22,16 @@  discard block
 block discarded – undo
22 22
     /**
23 23
      * @return array
24 24
      */
25
-    public function buildCounts(array $args = [])
25
+    public function buildCounts( array $args = [] )
26 26
     {
27 27
         $counts = [
28 28
             'local' => $this->generateEmptyCountsArray(),
29 29
         ];
30
-        $query = $this->queryReviews($args);
31
-        while ($query) {
32
-            $counts = $this->populateCountsFromQuery($query, $counts);
30
+        $query = $this->queryReviews( $args );
31
+        while( $query ) {
32
+            $counts = $this->populateCountsFromQuery( $query, $counts );
33 33
             $query = $query->has_more
34
-                ? $this->queryReviews($args, end($query->reviews)->ID)
34
+                ? $this->queryReviews( $args, end( $query->reviews )->ID )
35 35
                 : false;
36 36
         }
37 37
         return $counts;
@@ -40,11 +40,11 @@  discard block
 block discarded – undo
40 40
     /**
41 41
      * @return void
42 42
      */
43
-    public function decreaseAll(Review $review)
43
+    public function decreaseAll( Review $review )
44 44
     {
45
-        glsr(GlobalCountsManager::class)->decrease($review);
46
-        glsr(PostCountsManager::class)->decrease($review);
47
-        glsr(TermCountsManager::class)->decrease($review);
45
+        glsr( GlobalCountsManager::class )->decrease( $review );
46
+        glsr( PostCountsManager::class )->decrease( $review );
47
+        glsr( TermCountsManager::class )->decrease( $review );
48 48
     }
49 49
 
50 50
     /**
@@ -52,10 +52,10 @@  discard block
 block discarded – undo
52 52
      * @param int $rating
53 53
      * @return array
54 54
      */
55
-    public function decreaseRating(array $reviewCounts, $type, $rating)
55
+    public function decreaseRating( array $reviewCounts, $type, $rating )
56 56
     {
57
-        if (isset($reviewCounts[$type][$rating])) {
58
-            $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1);
57
+        if( isset($reviewCounts[$type][$rating]) ) {
58
+            $reviewCounts[$type][$rating] = max( 0, $reviewCounts[$type][$rating] - 1 );
59 59
         }
60 60
         return $reviewCounts;
61 61
     }
@@ -63,16 +63,16 @@  discard block
 block discarded – undo
63 63
     /**
64 64
      * @return array
65 65
      */
66
-    public function flatten(array $reviewCounts, array $args = [])
66
+    public function flatten( array $reviewCounts, array $args = [] )
67 67
     {
68 68
         $counts = [];
69
-        array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) {
70
-            $counts[$index] = $num + intval(Arr::get($counts, $index, 0));
69
+        array_walk_recursive( $reviewCounts, function( $num, $index ) use (&$counts) {
70
+            $counts[$index] = $num + intval( Arr::get( $counts, $index, 0 ) );
71 71
         });
72
-        $min = Arr::get($args, 'min', glsr()->constant('MIN_RATING', Rating::class));
73
-        $max = Arr::get($args, 'max', glsr()->constant('MAX_RATING', Rating::class));
74
-        foreach ($counts as $index => &$num) {
75
-            if (!Helper::inRange($index, $min, $max)) {
72
+        $min = Arr::get( $args, 'min', glsr()->constant( 'MIN_RATING', Rating::class ) );
73
+        $max = Arr::get( $args, 'max', glsr()->constant( 'MAX_RATING', Rating::class ) );
74
+        foreach( $counts as $index => &$num ) {
75
+            if( !Helper::inRange( $index, $min, $max ) ) {
76 76
                 $num = 0;
77 77
             }
78 78
         }
@@ -82,23 +82,23 @@  discard block
 block discarded – undo
82 82
     /**
83 83
      * @return array
84 84
      */
85
-    public function getCounts(array $args = [])
85
+    public function getCounts( array $args = [] )
86 86
     {
87
-        $args = $this->normalizeArgs($args);
88
-        $counts = $this->hasMixedAssignment($args)
89
-            ? $this->buildCounts($args) // force query the database
90
-            : $this->get($args);
91
-        return $this->normalize($counts);
87
+        $args = $this->normalizeArgs( $args );
88
+        $counts = $this->hasMixedAssignment( $args )
89
+            ? $this->buildCounts( $args ) // force query the database
90
+            : $this->get( $args );
91
+        return $this->normalize( $counts );
92 92
     }
93 93
 
94 94
     /**
95 95
      * @return void
96 96
      */
97
-    public function increaseAll(Review $review)
97
+    public function increaseAll( Review $review )
98 98
     {
99
-        glsr(GlobalCountsManager::class)->increase($review);
100
-        glsr(PostCountsManager::class)->increase($review);
101
-        glsr(TermCountsManager::class)->increase($review);
99
+        glsr( GlobalCountsManager::class )->increase( $review );
100
+        glsr( PostCountsManager::class )->increase( $review );
101
+        glsr( TermCountsManager::class )->increase( $review );
102 102
     }
103 103
 
104 104
     /**
@@ -106,16 +106,16 @@  discard block
 block discarded – undo
106 106
      * @param int $rating
107 107
      * @return array
108 108
      */
109
-    public function increaseRating(array $reviewCounts, $type, $rating)
109
+    public function increaseRating( array $reviewCounts, $type, $rating )
110 110
     {
111
-        if (!array_key_exists($type, glsr()->reviewTypes)) {
111
+        if( !array_key_exists( $type, glsr()->reviewTypes ) ) {
112 112
             return $reviewCounts;
113 113
         }
114
-        if (!array_key_exists($type, $reviewCounts)) {
114
+        if( !array_key_exists( $type, $reviewCounts ) ) {
115 115
             $reviewCounts[$type] = [];
116 116
         }
117
-        $reviewCounts = $this->normalize($reviewCounts);
118
-        $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1;
117
+        $reviewCounts = $this->normalize( $reviewCounts );
118
+        $reviewCounts[$type][$rating] = intval( $reviewCounts[$type][$rating] ) + 1;
119 119
         return $reviewCounts;
120 120
     }
121 121
 
@@ -124,26 +124,26 @@  discard block
 block discarded – undo
124 124
      */
125 125
     public function updateAll()
126 126
     {
127
-        glsr(GlobalCountsManager::class)->updateAll();
128
-        glsr(PostCountsManager::class)->updateAll();
129
-        glsr(TermCountsManager::class)->updateAll();
130
-        glsr(OptionManager::class)->set('last_review_count', current_time('timestamp'));
127
+        glsr( GlobalCountsManager::class )->updateAll();
128
+        glsr( PostCountsManager::class )->updateAll();
129
+        glsr( TermCountsManager::class )->updateAll();
130
+        glsr( OptionManager::class )->set( 'last_review_count', current_time( 'timestamp' ) );
131 131
     }
132 132
 
133 133
     /**
134 134
      * @return array
135 135
      */
136
-    protected function combine(array $results)
136
+    protected function combine( array $results )
137 137
     {
138
-        if (!wp_is_numeric_array($results)) {
138
+        if( !wp_is_numeric_array( $results ) ) {
139 139
             return $results;
140 140
         }
141
-        $mergedKeys = array_keys(array_merge(...$results));
142
-        $counts = array_fill_keys($mergedKeys, $this->generateEmptyCountsArray());
143
-        foreach ($results as $typeRatings) {
144
-            foreach ($typeRatings as $type => $ratings) {
145
-                foreach ($ratings as $index => $rating) {
146
-                    $counts[$type][$index] = intval($rating) + $counts[$type][$index];
141
+        $mergedKeys = array_keys( array_merge( ...$results ) );
142
+        $counts = array_fill_keys( $mergedKeys, $this->generateEmptyCountsArray() );
143
+        foreach( $results as $typeRatings ) {
144
+            foreach( $typeRatings as $type => $ratings ) {
145
+                foreach( $ratings as $index => $rating ) {
146
+                    $counts[$type][$index] = intval( $rating ) + $counts[$type][$index];
147 147
                 }
148 148
             }
149 149
         }
@@ -155,32 +155,32 @@  discard block
 block discarded – undo
155 155
      */
156 156
     protected function generateEmptyCountsArray()
157 157
     {
158
-        return array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0);
158
+        return array_fill_keys( range( 0, glsr()->constant( 'MAX_RATING', Rating::class ) ), 0 );
159 159
     }
160 160
 
161 161
     /**
162 162
      * @return array
163 163
      */
164
-    protected function get($args)
164
+    protected function get( $args )
165 165
     {
166 166
         $results = [];
167
-        foreach ($args['post_ids'] as $postId) {
168
-            $results[] = glsr(PostCountsManager::class)->get($postId);
167
+        foreach( $args['post_ids'] as $postId ) {
168
+            $results[] = glsr( PostCountsManager::class )->get( $postId );
169 169
         }
170
-        foreach ($args['term_ids'] as $termId) {
171
-            $results[] = glsr(TermCountsManager::class)->get($termId);
170
+        foreach( $args['term_ids'] as $termId ) {
171
+            $results[] = glsr( TermCountsManager::class )->get( $termId );
172 172
         }
173
-        if (empty($results)) {
174
-            $results[] = glsr(GlobalCountsManager::class)->get();
173
+        if( empty($results) ) {
174
+            $results[] = glsr( GlobalCountsManager::class )->get();
175 175
         }
176 176
         $results[] = ['local' => $this->generateEmptyCountsArray()]; // make sure there is a fallback
177
-        return $this->combine($results);
177
+        return $this->combine( $results );
178 178
     }
179 179
 
180 180
     /**
181 181
      * @return bool
182 182
      */
183
-    protected function hasMixedAssignment(array $args)
183
+    protected function hasMixedAssignment( array $args )
184 184
     {
185 185
         return !empty($args['post_ids']) && !empty($args['term_ids']);
186 186
     }
@@ -188,15 +188,15 @@  discard block
 block discarded – undo
188 188
     /**
189 189
      * @return array
190 190
      */
191
-    protected function normalize(array $reviewCounts)
191
+    protected function normalize( array $reviewCounts )
192 192
     {
193
-        foreach ($reviewCounts as &$counts) {
194
-            foreach (array_keys($this->generateEmptyCountsArray()) as $index) {
195
-                if (!isset($counts[$index])) {
193
+        foreach( $reviewCounts as &$counts ) {
194
+            foreach( array_keys( $this->generateEmptyCountsArray() ) as $index ) {
195
+                if( !isset($counts[$index]) ) {
196 196
                     $counts[$index] = 0;
197 197
                 }
198 198
             }
199
-            ksort($counts);
199
+            ksort( $counts );
200 200
         }
201 201
         return $reviewCounts;
202 202
     }
@@ -204,15 +204,15 @@  discard block
 block discarded – undo
204 204
     /**
205 205
      * @return array
206 206
      */
207
-    protected function normalizeArgs(array $args)
207
+    protected function normalizeArgs( array $args )
208 208
     {
209
-        $args = wp_parse_args(array_filter($args), [
209
+        $args = wp_parse_args( array_filter( $args ), [
210 210
             'post_ids' => [],
211 211
             'term_ids' => [],
212 212
             'type' => 'local',
213
-        ]);
214
-        $args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']);
215
-        $args['type'] = $this->normalizeType($args['type']);
213
+        ] );
214
+        $args['post_ids'] = glsr( Multilingual::class )->getPostIds( $args['post_ids'] );
215
+        $args['type'] = $this->normalizeType( $args['type'] );
216 216
         return $args;
217 217
     }
218 218
 
@@ -220,9 +220,9 @@  discard block
 block discarded – undo
220 220
      * @param string $type
221 221
      * @return string
222 222
      */
223
-    protected function normalizeType($type)
223
+    protected function normalizeType( $type )
224 224
     {
225
-        return empty($type) || !is_string($type)
225
+        return empty($type) || !is_string( $type )
226 226
             ? 'local'
227 227
             : $type;
228 228
     }
@@ -231,11 +231,11 @@  discard block
 block discarded – undo
231 231
      * @param object $query
232 232
      * @return array
233 233
      */
234
-    protected function populateCountsFromQuery($query, array $counts)
234
+    protected function populateCountsFromQuery( $query, array $counts )
235 235
     {
236
-        foreach ($query->reviews as $review) {
237
-            $type = $this->normalizeType($review->type);
238
-            if (!array_key_exists($type, $counts)) {
236
+        foreach( $query->reviews as $review ) {
237
+            $type = $this->normalizeType( $review->type );
238
+            if( !array_key_exists( $type, $counts ) ) {
239 239
                 $counts[$type] = $this->generateEmptyCountsArray();
240 240
             }
241 241
             ++$counts[$type][$review->rating];
@@ -247,13 +247,13 @@  discard block
 block discarded – undo
247 247
      * @param int $lastPostId
248 248
      * @return object
249 249
      */
250
-    protected function queryReviews(array $args = [], $lastPostId = 0)
250
+    protected function queryReviews( array $args = [], $lastPostId = 0 )
251 251
     {
252
-        $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT);
253
-        $hasMore = is_array($reviews)
254
-            ? count($reviews) == static::LIMIT
252
+        $reviews = glsr( SqlQueries::class )->getReviewCounts( $args, $lastPostId, static::LIMIT );
253
+        $hasMore = is_array( $reviews )
254
+            ? count( $reviews ) == static::LIMIT
255 255
             : false;
256
-        return (object) [
256
+        return (object)[
257 257
             'has_more' => $hasMore,
258 258
             'reviews' => $reviews,
259 259
         ];
Please login to merge, or discard this patch.