Passed
Push — master ( e8093c...ec23d4 )
by Paul
04:14
created
plugin/Handlers/CreateReview.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -17,13 +17,13 @@  discard block
 block discarded – undo
17 17
 		$review = glsr( ReviewManager::class )->create( $command );
18 18
 		if( !$review ) {
19 19
 			glsr( Session::class )->set( $command->form_id.'errors', [] );
20
-			glsr( Session::class )->set( $command->form_id.'message', __( 'Your review could not be submitted and the error has been logged. Please notify the site admin.', 'site-reviews' ));
20
+			glsr( Session::class )->set( $command->form_id.'message', __( 'Your review could not be submitted and the error has been logged. Please notify the site admin.', 'site-reviews' ) );
21 21
 			return;
22 22
 		}
23
-		glsr( Session::class )->set( $command->form_id.'message', __( 'Your review has been submitted!', 'site-reviews' ));
23
+		glsr( Session::class )->set( $command->form_id.'message', __( 'Your review has been submitted!', 'site-reviews' ) );
24 24
 		glsr( Notification::class )->send( $review );
25 25
 		if( $command->ajax_request )return;
26
-		wp_safe_redirect( $this->getReferer( $command ));
26
+		wp_safe_redirect( $this->getReferer( $command ) );
27 27
 		exit;
28 28
 	}
29 29
 
@@ -32,11 +32,11 @@  discard block
 block discarded – undo
32 32
 	 */
33 33
 	protected function getReferer( Command $command )
34 34
 	{
35
-		$referer = trim( strval( get_post_meta( $command->post_id, 'redirect_to', true )));
36
-		if( empty( $referer )) {
35
+		$referer = trim( strval( get_post_meta( $command->post_id, 'redirect_to', true ) ) );
36
+		if( empty($referer) ) {
37 37
 			$referer = $command->referer;
38 38
 		}
39
-		if( empty( $referer )) {
39
+		if( empty($referer) ) {
40 40
 			glsr_log()->warning( 'The form referer ($_SERVER[REQUEST_URI]) was empty.' )->info( $command );
41 41
 			$referer = home_url();
42 42
 		}
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,9 @@
 block discarded – undo
22 22
 		}
23 23
 		glsr( Session::class )->set( $command->form_id.'message', __( 'Your review has been submitted!', 'site-reviews' ));
24 24
 		glsr( Notification::class )->send( $review );
25
-		if( $command->ajax_request )return;
25
+		if( $command->ajax_request ) {
26
+			return;
27
+		}
26 28
 		wp_safe_redirect( $this->getReferer( $command ));
27 29
 		exit;
28 30
 	}
Please login to merge, or discard this patch.
plugin/Modules/Html/Form.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@
 block discarded – undo
28 28
 	{
29 29
 		$fields = [];
30 30
 		foreach( glsr()->config( 'forms/'.$id ) as $name => $field ) {
31
-			$fields[] = new Field( wp_parse_args( $field, ['name' => $name] ));
31
+			$fields[] = new Field( wp_parse_args( $field, ['name' => $name] ) );
32 32
 		}
33 33
 		return $fields;
34 34
 	}
Please login to merge, or discard this patch.
deprecated.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 // Database/ReviewManager.php
6 6
 add_action( 'site-reviews/review/created', function( $review ) {
7
-	if( has_action( 'site-reviews/local/review/create' )) {
7
+	if( has_action( 'site-reviews/local/review/create' ) ) {
8 8
 		glsr()->deprecated[] = 'The "site-reviews/local/review/create" hook has been deprecated. Please use the "site-reviews/create/review" hook instead.';
9 9
 		do_action( 'site-reviews/local/review/create', (array)get_post( $review->ID ), (array)$review, $review->ID );
10 10
 	}
@@ -12,18 +12,18 @@  discard block
 block discarded – undo
12 12
 
13 13
 // Handlers/CreateReview.php
14 14
 add_action( 'site-reviews/review/submitted', function( $review ) {
15
-	if( has_action( 'site-reviews/local/review/submitted' )) {
15
+	if( has_action( 'site-reviews/local/review/submitted' ) ) {
16 16
 		glsr()->deprecated[] = 'The "site-reviews/local/review/submitted" hook has been deprecated. Please use the "site-reviews/review/submitted" hook instead.';
17 17
 		do_action( 'site-reviews/local/review/submitted', null, $review );
18 18
 	}
19
-	if( has_filter( 'site-reviews/local/review/submitted/message' )) {
19
+	if( has_filter( 'site-reviews/local/review/submitted/message' ) ) {
20 20
 		glsr()->deprecated[] = 'The "site-reviews/local/review/submitted/message" hook has been deprecated.';
21 21
 	}
22 22
 }, 9 );
23 23
 
24 24
 // Database/ReviewManager.php
25 25
 add_filter( 'site-reviews/create/review-values', function( $values, $command ) {
26
-	if( has_filter( 'site-reviews/local/review' )) {
26
+	if( has_filter( 'site-reviews/local/review' ) ) {
27 27
 		glsr()->deprecated[] = 'The "site-reviews/local/review" hook has been deprecated. Please use the "site-reviews/create/review-values" hook instead.';
28 28
 		return apply_filters( 'site-reviews/local/review', $values, $command );
29 29
 	}
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 
33 33
 // Handlers/EnqueuePublicAssets.php
34 34
 add_filter( 'site-reviews/enqueue/public/localize', function( $variables ) {
35
-	if( has_filter( 'site-reviews/enqueue/localize' )) {
35
+	if( has_filter( 'site-reviews/enqueue/localize' ) ) {
36 36
 		glsr()->deprecated[] = 'The "site-reviews/enqueue/localize" hook has been deprecated. Please use the "site-reviews/enqueue/public/localize" hook instead.';
37 37
 		return apply_filters( 'site-reviews/enqueue/localize', $variables );
38 38
 	}
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 
42 42
 // Modules/Rating.php
43 43
 add_filter( 'site-reviews/rating/average', function( $average ) {
44
-	if( has_filter( 'site-reviews/average/rating' )) {
44
+	if( has_filter( 'site-reviews/average/rating' ) ) {
45 45
 		glsr()->deprecated[] = 'The "site-reviews/average/rating" hook has been deprecated. Please use the "site-reviews/rating/average" hook instead.';
46 46
 	}
47 47
 	return $average;
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 
50 50
 // Modules/Rating.php
51 51
 add_filter( 'site-reviews/rating/ranking', function( $ranking ) {
52
-	if( has_filter( 'site-reviews/bayesian/ranking' )) {
52
+	if( has_filter( 'site-reviews/bayesian/ranking' ) ) {
53 53
 		glsr()->deprecated[] = 'The "site-reviews/bayesian/ranking" hook has been deprecated. Please use the "site-reviews/rating/ranking" hook instead.';
54 54
 	}
55 55
 	return $ranking;
@@ -57,13 +57,13 @@  discard block
 block discarded – undo
57 57
 
58 58
 // Modules/Html/Partials/SiteReviews.php
59 59
 add_filter( 'site-reviews/review/build/after', function( $renderedFields ) {
60
-	if( has_filter( 'site-reviews/rendered/field' )) {
60
+	if( has_filter( 'site-reviews/rendered/field' ) ) {
61 61
 		glsr()->deprecated[] = 'The "site-reviews/rendered/field" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.';
62 62
 	}
63
-	if( has_filter( 'site-reviews/reviews/review/text' )) {
63
+	if( has_filter( 'site-reviews/reviews/review/text' ) ) {
64 64
 		glsr()->deprecated[] = 'The "site-reviews/reviews/review/text" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.';
65 65
 	}
66
-	if( has_filter( 'site-reviews/reviews/review/title' )) {
66
+	if( has_filter( 'site-reviews/reviews/review/title' ) ) {
67 67
 		glsr()->deprecated[] = 'The "site-reviews/reviews/review/title" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.';
68 68
 	}
69 69
 	return $renderedFields;
@@ -71,26 +71,26 @@  discard block
 block discarded – undo
71 71
 
72 72
 // Modules/Html/Partials/SiteReviews.php
73 73
 add_filter( 'site-reviews/review/build/before', function( $review ) {
74
-	if( has_filter( 'site-reviews/rendered/review' )) {
74
+	if( has_filter( 'site-reviews/rendered/review' ) ) {
75 75
 		glsr()->deprecated[] = 'The "site-reviews/rendered/review" hook has been deprecated. Please either use a custom "review.php" template (refer to the documentation), or use the "site-reviews/review/build/after" hook instead.';
76 76
 	}
77
-	if( has_filter( 'site-reviews/rendered/review/meta/order' )) {
77
+	if( has_filter( 'site-reviews/rendered/review/meta/order' ) ) {
78 78
 		glsr()->deprecated[] = 'The "site-reviews/rendered/review/meta/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).';
79 79
 	}
80
-	if( has_filter( 'site-reviews/rendered/review/order' )) {
80
+	if( has_filter( 'site-reviews/rendered/review/order' ) ) {
81 81
 		glsr()->deprecated[] = 'The "site-reviews/rendered/review/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).';
82 82
 	}
83
-	if( has_filter( 'site-reviews/rendered/review-form/login-register' )) {
83
+	if( has_filter( 'site-reviews/rendered/review-form/login-register' ) ) {
84 84
 		glsr()->deprecated[] = 'The "site-reviews/rendered/review-form/login-register" hook has been deprecated. Please use a custom "login-register.php" template instead (refer to the documentation).';
85 85
 	}
86
-	if( has_filter( 'site-reviews/reviews/navigation_links' )) {
86
+	if( has_filter( 'site-reviews/reviews/navigation_links' ) ) {
87 87
 		glsr()->deprecated[] = 'The "site-reviews/reviews/navigation_links" hook has been deprecated. Please use a custom "pagination.php" template instead (refer to the documentation).';
88 88
 	}
89 89
 	return $review;
90 90
 }, 9 );
91 91
 
92 92
 add_filter( 'site-reviews/validate/custom', function( $result, $request ) {
93
-	if( has_filter( 'site-reviews/validate/review/submission' )) {
93
+	if( has_filter( 'site-reviews/validate/review/submission' ) ) {
94 94
 		glsr_log()->notice( 'The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.' );
95 95
 		try {
96 96
 			$result = apply_filters( 'site-reviews/validate/review/submission', $result, $request );
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 }, 9, 2 );
102 102
 
103 103
 add_filter( 'site-reviews/views/file', function( $file, $view, $data ) {
104
-	if( has_filter( 'site-reviews/addon/views/file' )) {
104
+	if( has_filter( 'site-reviews/addon/views/file' ) ) {
105 105
 		glsr()->deprecated[] = 'The "site-reviews/addon/views/file" hook has been deprecated. Please use the "site-reviews/views/file" hook instead.';
106 106
 		$file = apply_filters( 'site-reviews/addon/views/file', $file, $view, $data );
107 107
 	}
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 }, 9, 3 );
110 110
 
111 111
 add_action( 'wp_footer', function() {
112
-	$notices = array_keys( array_flip( glsr()->deprecated ));
112
+	$notices = array_keys( array_flip( glsr()->deprecated ) );
113 113
 	natsort( $notices );
114 114
 	foreach( $notices as $notice ) {
115 115
 		glsr_log()->notice( $notice );
Please login to merge, or discard this patch.
plugin/Modules/Validator/ValidateReview.php 2 patches
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 		$this->validateBlacklist();
62 62
 		$this->validateAkismet();
63 63
 		$this->validateRecaptcha();
64
-		if( !empty( $this->error )) {
64
+		if( !empty($this->error) ) {
65 65
 			$this->setSessionValues( 'message', $this->error );
66 66
 		}
67 67
 		return $this;
@@ -84,12 +84,12 @@  discard block
 block discarded – undo
84 84
 	{
85 85
 		$rules = array_intersect_key(
86 86
 			apply_filters( 'site-reviews/validation/rules', static::VALIDATION_RULES ),
87
-			array_flip( $this->getOption( 'settings.submissions.required', [] ))
87
+			array_flip( $this->getOption( 'settings.submissions.required', [] ) )
88 88
 		);
89
-		$excluded = isset( $request['excluded'] )
89
+		$excluded = isset($request['excluded'])
90 90
 			? (array)json_decode( $request['excluded'] )
91 91
 			: [];
92
-		return array_diff_key( $rules, array_flip( $excluded ));
92
+		return array_diff_key( $rules, array_flip( $excluded ) );
93 93
 	}
94 94
 
95 95
 	/**
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 		if( !glsr( OptionManager::class )->isRecaptchaEnabled() ) {
101 101
 			return true;
102 102
 		}
103
-		if( empty( $this->request['recaptcha-token'] )) {
103
+		if( empty($this->request['recaptcha-token']) ) {
104 104
 			return null; // @see $this->validateRecaptcha()
105 105
 		}
106 106
 		return $this->isRecaptchaValid( $this->request['recaptcha-token'] );
@@ -112,17 +112,17 @@  discard block
 block discarded – undo
112 112
 	 */
113 113
 	protected function isRecaptchaValid( $recaptchaToken )
114 114
 	{
115
-		$endpoint = add_query_arg([
115
+		$endpoint = add_query_arg( [
116 116
 			'remoteip' => glsr( Helper::class )->getIpAddress(),
117 117
 			'response' => $recaptchaToken,
118 118
 			'secret' => $this->getOption( 'settings.submissions.recaptcha.secret' ),
119 119
 		], static::RECAPTCHA_ENDPOINT );
120
-		if( is_wp_error( $response = wp_remote_get( $endpoint ))) {
120
+		if( is_wp_error( $response = wp_remote_get( $endpoint ) ) ) {
121 121
 			glsr_log()->error( $response->get_error_message() );
122 122
 			return false;
123 123
 		}
124
-		$response = json_decode( wp_remote_retrieve_body( $response ));
125
-		if( !empty( $response->success )) {
124
+		$response = json_decode( wp_remote_retrieve_body( $response ) );
125
+		if( !empty($response->success) ) {
126 126
 			return boolval( $response->success );
127 127
 		}
128 128
 		foreach( $response->{'error-codes'} as $error ) {
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 	{
139 139
 		$rules = $this->getValidationRules( $request );
140 140
 		$errors = glsr( Validator::class )->validate( $request, $rules );
141
-		if( empty( $errors )) {
141
+		if( empty($errors) ) {
142 142
 			return true;
143 143
 		}
144 144
 		$this->setSessionValues( 'errors', $errors );
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 	protected function setSessionValues( $type, $value, $loggedMessage = '' )
156 156
 	{
157 157
 		glsr( Session::class )->set( $this->form_id.$type, $value );
158
-		if( !empty( $loggedMessage )) {
158
+		if( !empty($loggedMessage) ) {
159 159
 			glsr_log()->warning( $loggedMessage );
160 160
 			glsr_log()->warning( $this->request );
161 161
 		}
@@ -166,8 +166,8 @@  discard block
 block discarded – undo
166 166
 	 */
167 167
 	protected function validateAkismet()
168 168
 	{
169
-		if( !empty( $this->error ))return;
170
-		if( !glsr( Akismet::class )->isSpam( $this->request ))return;
169
+		if( !empty($this->error) )return;
170
+		if( !glsr( Akismet::class )->isSpam( $this->request ) )return;
171 171
 		$this->setSessionValues( 'errors', [], 'Akismet caught a spam submission:' );
172 172
 		$this->error = __( 'Your review cannot be submitted at this time. Please try again later.', 'site-reviews' );
173 173
 	}
@@ -177,8 +177,8 @@  discard block
 block discarded – undo
177 177
 	 */
178 178
 	protected function validateBlacklist()
179 179
 	{
180
-		if( !empty( $this->error ))return;
181
-		if( !glsr( Blacklist::class )->isBlacklisted( $this->request ))return;
180
+		if( !empty($this->error) )return;
181
+		if( !glsr( Blacklist::class )->isBlacklisted( $this->request ) )return;
182 182
 		$blacklistAction = $this->getOption( 'settings.submissions.blacklist.action' );
183 183
 		if( $blacklistAction == 'reject' ) {
184 184
 			$this->setSessionValues( 'errors', [], 'Blacklisted submission detected:' );
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 	 */
194 194
 	protected function validateCustom()
195 195
 	{
196
-		if( !empty( $this->error ))return;
196
+		if( !empty($this->error) )return;
197 197
 		$validated = apply_filters( 'site-reviews/validate/custom', true, $this->request );
198 198
 		if( $validated === true )return;
199 199
 		$this->setSessionValues( 'errors', [] );
@@ -208,8 +208,8 @@  discard block
 block discarded – undo
208 208
 	 */
209 209
 	protected function validateHoneyPot()
210 210
 	{
211
-		if( !empty( $this->error ))return;
212
-		if( empty( $this->request['gotcha'] ))return;
211
+		if( !empty($this->error) )return;
212
+		if( empty($this->request['gotcha']) )return;
213 213
 		$this->setSessionValues( 'errors', [], 'The Honeypot caught a bad submission:' );
214 214
 		$this->error = __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' );
215 215
 	}
@@ -219,9 +219,9 @@  discard block
 block discarded – undo
219 219
 	 */
220 220
 	protected function validateRecaptcha()
221 221
 	{
222
-		if( !empty( $this->error ))return;
222
+		if( !empty($this->error) )return;
223 223
 		$isValid = $this->isRecaptchaResponseValid();
224
-		if( is_null( $isValid )) {
224
+		if( is_null( $isValid ) ) {
225 225
 			$this->setSessionValues( 'recaptcha', 'unset' );
226 226
 			$this->recaptchaIsUnset = true;
227 227
 		}
@@ -237,11 +237,11 @@  discard block
 block discarded – undo
237 237
 	 */
238 238
 	protected function validateRequest( array $request )
239 239
 	{
240
-		if( !$this->isRequestValid( $request )) {
240
+		if( !$this->isRequestValid( $request ) ) {
241 241
 			$this->error = __( 'Please fix the submission errors.', 'site-reviews' );
242 242
 			return $request;
243 243
 		}
244
-		if( empty( $request['title'] )) {
244
+		if( empty($request['title']) ) {
245 245
 			$request['title'] = __( 'No Title', 'site-reviews' );
246 246
 		}
247 247
 		return array_merge( glsr( ValidateReviewDefaults::class )->defaults(), $request );
Please login to merge, or discard this patch.
Braces   +27 added lines, -9 removed lines patch added patch discarded remove patch
@@ -166,8 +166,12 @@  discard block
 block discarded – undo
166 166
 	 */
167 167
 	protected function validateAkismet()
168 168
 	{
169
-		if( !empty( $this->error ))return;
170
-		if( !glsr( Akismet::class )->isSpam( $this->request ))return;
169
+		if( !empty( $this->error )) {
170
+			return;
171
+		}
172
+		if( !glsr( Akismet::class )->isSpam( $this->request )) {
173
+			return;
174
+		}
171 175
 		$this->setSessionValues( 'errors', [], 'Akismet caught a spam submission:' );
172 176
 		$this->error = __( 'Your review cannot be submitted at this time. Please try again later.', 'site-reviews' );
173 177
 	}
@@ -177,8 +181,12 @@  discard block
 block discarded – undo
177 181
 	 */
178 182
 	protected function validateBlacklist()
179 183
 	{
180
-		if( !empty( $this->error ))return;
181
-		if( !glsr( Blacklist::class )->isBlacklisted( $this->request ))return;
184
+		if( !empty( $this->error )) {
185
+			return;
186
+		}
187
+		if( !glsr( Blacklist::class )->isBlacklisted( $this->request )) {
188
+			return;
189
+		}
182 190
 		$blacklistAction = $this->getOption( 'settings.submissions.blacklist.action' );
183 191
 		if( $blacklistAction == 'reject' ) {
184 192
 			$this->setSessionValues( 'errors', [], 'Blacklisted submission detected:' );
@@ -193,9 +201,13 @@  discard block
 block discarded – undo
193 201
 	 */
194 202
 	protected function validateCustom()
195 203
 	{
196
-		if( !empty( $this->error ))return;
204
+		if( !empty( $this->error )) {
205
+			return;
206
+		}
197 207
 		$validated = apply_filters( 'site-reviews/validate/custom', true, $this->request );
198
-		if( $validated === true )return;
208
+		if( $validated === true ) {
209
+			return;
210
+		}
199 211
 		$this->setSessionValues( 'errors', [] );
200 212
 		$this->setSessionValues( 'values', $this->request );
201 213
 		$this->error = is_string( $validated )
@@ -208,8 +220,12 @@  discard block
 block discarded – undo
208 220
 	 */
209 221
 	protected function validateHoneyPot()
210 222
 	{
211
-		if( !empty( $this->error ))return;
212
-		if( empty( $this->request['gotcha'] ))return;
223
+		if( !empty( $this->error )) {
224
+			return;
225
+		}
226
+		if( empty( $this->request['gotcha'] )) {
227
+			return;
228
+		}
213 229
 		$this->setSessionValues( 'errors', [], 'The Honeypot caught a bad submission:' );
214 230
 		$this->error = __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' );
215 231
 	}
@@ -219,7 +235,9 @@  discard block
 block discarded – undo
219 235
 	 */
220 236
 	protected function validateRecaptcha()
221 237
 	{
222
-		if( !empty( $this->error ))return;
238
+		if( !empty( $this->error )) {
239
+			return;
240
+		}
223 241
 		$isValid = $this->isRecaptchaResponseValid();
224 242
 		if( is_null( $isValid )) {
225 243
 			$this->setSessionValues( 'recaptcha', 'unset' );
Please login to merge, or discard this patch.