Passed
Push — master ( 642023...49ec8d )
by Paul
03:40
created
plugin/Database/SqlQueries.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -23,11 +23,11 @@  discard block
 block discarded – undo
23 23
 	 */
24 24
 	public function deleteAllSessions( $sessionCookiePrefix )
25 25
 	{
26
-		return $this->db->query("
26
+		return $this->db->query( "
27 27
 			DELETE
28 28
 			FROM {$this->db->options}
29 29
 			WHERE option_name LIKE '{$sessionCookiePrefix}_%'
30
-		");
30
+		" );
31 31
 	}
32 32
 
33 33
 	/**
@@ -36,11 +36,11 @@  discard block
 block discarded – undo
36 36
 	 */
37 37
 	public function deleteExpiredSessions( $expiredSessions )
38 38
 	{
39
-		return $this->db->query("
39
+		return $this->db->query( "
40 40
 			DELETE
41 41
 			FROM {$this->db->options}
42 42
 			WHERE option_name IN ('{$expiredSessions}')
43
-		");
43
+		" );
44 44
 	}
45 45
 
46 46
 	/**
@@ -49,14 +49,14 @@  discard block
 block discarded – undo
49 49
 	 */
50 50
 	public function getReviewCountsFor( $metaKey )
51 51
 	{
52
-		return (array) $this->db->get_results("
52
+		return (array)$this->db->get_results( "
53 53
 			SELECT m.meta_value AS name, COUNT(*) num_posts
54 54
 			FROM {$this->db->posts} AS p
55 55
 			INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
56 56
 			WHERE p.post_type = '{$this->postType}'
57 57
 			AND m.meta_key = '{$metaKey}'
58 58
 			GROUP BY name
59
-		");
59
+		" );
60 60
 	}
61 61
 
62 62
 	/**
@@ -66,13 +66,13 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public function getExpiredSessions( $sessionCookiePrefix, $limit )
68 68
 	{
69
-		return $this->db->get_results("
69
+		return $this->db->get_results( "
70 70
 			SELECT option_name AS name, option_value AS expiration
71 71
 			FROM {$this->db->options}
72 72
 			WHERE option_name LIKE '{$sessionCookiePrefix}_expires_%'
73 73
 			ORDER BY option_value ASC
74 74
 			LIMIT 0, {$limit}
75
-		");
75
+		" );
76 76
 	}
77 77
 
78 78
 	/**
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 	 */
83 83
 	public function getReviewCounts( $lastPostId = 0, $limit = 500 )
84 84
 	{
85
-		return $this->db->get_results("
85
+		return $this->db->get_results( "
86 86
 			SELECT p.ID, m1.meta_value AS rating, m2.meta_value AS type
87 87
 			FROM {$this->db->posts} AS p
88 88
 			INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id
@@ -103,14 +103,14 @@  discard block
 block discarded – undo
103 103
 	 */
104 104
 	public function getReviewPostId( $metaReviewId )
105 105
 	{
106
-		$postId = $this->db->get_var("
106
+		$postId = $this->db->get_var( "
107 107
 			SELECT p.ID
108 108
 			FROM {$this->db->posts} AS p
109 109
 			INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
110 110
 			WHERE p.post_type = '{$this->postType}'
111 111
 			AND m.meta_key = 'review_id'
112 112
 			AND m.meta_value = '{$metaReviewId}'
113
-		");
113
+		" );
114 114
 		return intval( $postId );
115 115
 	}
116 116
 
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 	 */
121 121
 	public function getReviewIdsByType( $reviewType )
122 122
 	{
123
-		$query = $this->db->get_col("
123
+		$query = $this->db->get_col( "
124 124
 			SELECT m1.meta_value AS review_id
125 125
 			FROM {$this->db->posts} AS p
126 126
 			INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
 			AND m1.meta_key = 'review_id'
130 130
 			AND m2.meta_key = 'review_type'
131 131
 			AND m2.meta_value = '{$reviewType}'
132
-		");
133
-		return array_keys( array_flip( $query ));
132
+		" );
133
+		return array_keys( array_flip( $query ) );
134 134
 	}
135 135
 
136 136
 	/**
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 	 */
142 142
 	public function getReviewPostCounts( $postId, $lastPostId = 0, $limit = 500 )
143 143
 	{
144
-		return $this->db->get_results("
144
+		return $this->db->get_results( "
145 145
 			SELECT p.ID, m1.meta_value AS rating, m2.meta_value AS type
146 146
 			FROM {$this->db->posts} AS p
147 147
 			INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id
@@ -167,9 +167,9 @@  discard block
 block discarded – undo
167 167
 	public function getReviewRatingsFromIds( array $postIds, $greaterThanId = 0, $limit = 100 )
168 168
 	{
169 169
 		sort( $postIds );
170
-		$postIds = array_slice( $postIds, intval( array_search( $greaterThanId, $postIds )), $limit );
170
+		$postIds = array_slice( $postIds, intval( array_search( $greaterThanId, $postIds ) ), $limit );
171 171
 		$postIds = implode( ',', $postIds );
172
-		return $this->db->get_results("
172
+		return $this->db->get_results( "
173 173
 			SELECT p.ID, m.meta_value AS rating
174 174
 			FROM {$this->db->posts} AS p
175 175
 			INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 		$queryBuilder = glsr( QueryBuilder::class );
194 194
 		$key = $queryBuilder->buildSqlOr( $key, "m.meta_key = '%s'" );
195 195
 		$status = $queryBuilder->buildSqlOr( $status, "p.post_status = '%s'" );
196
-		return $this->db->get_col("
196
+		return $this->db->get_col( "
197 197
 			SELECT DISTINCT m.meta_value
198 198
 			FROM {$this->db->postmeta} m
199 199
 			LEFT JOIN {$this->db->posts} p ON p.ID = m.post_id
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 			AND ({$key})
202 202
 			AND ({$status})
203 203
 			ORDER BY m.meta_value
204
-		");
204
+		" );
205 205
 	}
206 206
 
207 207
 	/**
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 	 */
213 213
 	public function getReviewTermCounts( $termId, $lastPostId = 0, $limit = 500 )
214 214
 	{
215
-		return $this->db->get_results("
215
+		return $this->db->get_results( "
216 216
 			SELECT p.ID, m1.meta_value AS rating, m2.meta_value AS type
217 217
 			FROM {$this->db->posts} AS p
218 218
 			INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id
Please login to merge, or discard this patch.
plugin/Controllers/EditorController/Metaboxes.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -13,10 +13,10 @@  discard block
 block discarded – undo
13 13
 	 */
14 14
 	public function saveAssignedToMetabox( $postId )
15 15
 	{
16
-		if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-assigned-to' ), 'assigned_to' ))return;
17
-		$assignedTo = strval( glsr( Helper::class )->filterInput( 'assigned_to' ));
16
+		if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-assigned-to' ), 'assigned_to' ) )return;
17
+		$assignedTo = strval( glsr( Helper::class )->filterInput( 'assigned_to' ) );
18 18
 		if( get_post_meta( $postId, 'assigned_to', true ) != $assignedTo ) {
19
-			$review = glsr( ReviewManager::class )->single( get_post( $postId ));
19
+			$review = glsr( ReviewManager::class )->single( get_post( $postId ) );
20 20
 			glsr( CountsManager::class )->decreasePostCounts( $review );
21 21
 		}
22 22
 		update_post_meta( $postId, 'assigned_to', $assignedTo );
@@ -28,12 +28,12 @@  discard block
 block discarded – undo
28 28
 	 */
29 29
 	public function saveResponseMetabox( $postId )
30 30
 	{
31
-		if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-response' ), 'response' ))return;
32
-		$response = strval( glsr( Helper::class )->filterInput( 'response' ));
31
+		if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-response' ), 'response' ) )return;
32
+		$response = strval( glsr( Helper::class )->filterInput( 'response' ) );
33 33
 		update_post_meta( $postId, 'response', trim( wp_kses( $response, [
34 34
 			'a' => ['href' => [], 'title' => []],
35 35
 			'em' => [],
36 36
 			'strong' => [],
37
-		])));
37
+		] ) ) );
38 38
 	}
39 39
 }
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,7 +13,9 @@  discard block
 block discarded – undo
13 13
 	 */
14 14
 	public function saveAssignedToMetabox( $postId )
15 15
 	{
16
-		if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-assigned-to' ), 'assigned_to' ))return;
16
+		if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-assigned-to' ), 'assigned_to' )) {
17
+			return;
18
+		}
17 19
 		$assignedTo = strval( glsr( Helper::class )->filterInput( 'assigned_to' ));
18 20
 		if( get_post_meta( $postId, 'assigned_to', true ) != $assignedTo ) {
19 21
 			$review = glsr( ReviewManager::class )->single( get_post( $postId ));
@@ -28,7 +30,9 @@  discard block
 block discarded – undo
28 30
 	 */
29 31
 	public function saveResponseMetabox( $postId )
30 32
 	{
31
-		if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-response' ), 'response' ))return;
33
+		if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-response' ), 'response' )) {
34
+			return;
35
+		}
32 36
 		$response = strval( glsr( Helper::class )->filterInput( 'response' ));
33 37
 		update_post_meta( $postId, 'response', trim( wp_kses( $response, [
34 38
 			'a' => ['href' => [], 'title' => []],
Please login to merge, or discard this patch.
plugin/Controllers/AdminController.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	 */
26 26
 	public function enqueueAssets()
27 27
 	{
28
-		$command = new EnqueueAdminAssets([
28
+		$command = new EnqueueAdminAssets( [
29 29
 			'pointers' => [[
30 30
 				'content' => __( 'You can pin exceptional reviews so that they are always shown first.', 'site-reviews' ),
31 31
 				'id' => 'glsr-pointer-pinned',
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 				'target' => '#misc-pub-pinned',
38 38
 				'title' => __( 'Pin Your Reviews', 'site-reviews' ),
39 39
 			]],
40
-		]);
40
+		] );
41 41
 		$this->execute( $command );
42 42
 	}
43 43
 
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 	{
50 50
 		$links['settings'] = glsr( Builder::class )->a( __( 'Settings', 'site-reviews' ), [
51 51
 			'href' => admin_url( 'edit.php?post_type='.Application::POST_TYPE.'&page=settings' ),
52
-		]);
52
+		] );
53 53
 		return $links;
54 54
 	}
55 55
 
@@ -60,19 +60,19 @@  discard block
 block discarded – undo
60 60
 	public function filterDashboardGlanceItems( array $items )
61 61
 	{
62 62
 		$postCount = wp_count_posts( Application::POST_TYPE );
63
-		if( empty( $postCount->publish )) {
63
+		if( empty($postCount->publish) ) {
64 64
 			return $items;
65 65
 		}
66 66
 		$text = _n( '%s Review', '%s Reviews', $postCount->publish, 'site-reviews' );
67
-		$text = sprintf( $text, number_format_i18n( $postCount->publish ));
67
+		$text = sprintf( $text, number_format_i18n( $postCount->publish ) );
68 68
 		$items[] = current_user_can( get_post_type_object( Application::POST_TYPE )->cap->edit_posts )
69 69
 			? glsr( Builder::class )->a( $text, [
70 70
 				'class' => 'glsr-review-count',
71 71
 				'href' => 'edit.php?post_type='.Application::POST_TYPE,
72
-			])
72
+			] )
73 73
 			: glsr( Builder::class )->span( $text, [
74 74
 				'class' => 'glsr-review-count',
75
-			]);
75
+			] );
76 76
 		return $items;
77 77
 	}
78 78
 
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	public function filterTinymcePlugins( array $plugins )
84 84
 	{
85 85
 		if( user_can_richedit()
86
-			&& ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ))) {
86
+			&& (current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' )) ) {
87 87
 			$plugins['glsr_shortcode'] = glsr()->url( 'assets/scripts/mce-plugin.js' );
88 88
 		}
89 89
 		return $plugins;
@@ -95,11 +95,11 @@  discard block
 block discarded – undo
95 95
 	 */
96 96
 	public function registerShortcodeButtons()
97 97
 	{
98
-		$command = new RegisterShortcodeButtons([
98
+		$command = new RegisterShortcodeButtons( [
99 99
 			'site_reviews' => esc_html__( 'Recent Reviews', 'site-reviews' ),
100 100
 			'site_reviews_form' => esc_html__( 'Submit a Review', 'site-reviews' ),
101 101
 			'site_reviews_summary' => esc_html__( 'Summary of Reviews', 'site-reviews' ),
102
-		]);
102
+		] );
103 103
 		$this->execute( $command );
104 104
 	}
105 105
 
@@ -109,10 +109,10 @@  discard block
 block discarded – undo
109 109
 	 */
110 110
 	public function renderReviewEditor( WP_Post $post )
111 111
 	{
112
-		if( !$this->isReviewPostType( $post ) || $this->isReviewEditable( $post ))return;
112
+		if( !$this->isReviewPostType( $post ) || $this->isReviewEditable( $post ) )return;
113 113
 		glsr()->render( 'partials/editor/review', [
114 114
 			'post' => $post,
115
-		]);
115
+		] );
116 116
 	}
117 117
 
118 118
 	/**
@@ -121,13 +121,13 @@  discard block
 block discarded – undo
121 121
 	 */
122 122
 	public function renderReviewNotice( WP_Post $post )
123 123
 	{
124
-		if( !$this->isReviewPostType( $post ) || $this->isReviewEditable( $post ))return;
125
-		glsr( Notice::class )->addWarning( __( 'This review is read-only.', 'site-reviews' ));
124
+		if( !$this->isReviewPostType( $post ) || $this->isReviewEditable( $post ) )return;
125
+		glsr( Notice::class )->addWarning( __( 'This review is read-only.', 'site-reviews' ) );
126 126
 		glsr( Html::class )->renderTemplate( 'partials/editor/notice', [
127 127
 			'context' => [
128 128
 				'notices' => glsr( Notice::class )->get(),
129 129
 			],
130
-		]);
130
+		] );
131 131
 	}
132 132
 
133 133
 	/**
@@ -139,13 +139,13 @@  discard block
 block discarded – undo
139 139
 		if( glsr_current_screen()->base != 'post' )return;
140 140
 		$shortcodes = [];
141 141
 		foreach( glsr()->mceShortcodes as $shortcode => $values ) {
142
-			if( !apply_filters( sanitize_title( $shortcode ).'_condition', true ))continue;
142
+			if( !apply_filters( sanitize_title( $shortcode ).'_condition', true ) )continue;
143 143
 			$shortcodes[$shortcode] = $values;
144 144
 		}
145
-		if( empty( $shortcodes ))return;
145
+		if( empty($shortcodes) )return;
146 146
 		glsr()->render( 'partials/editor/tinymce', [
147 147
 			'shortcodes' => $shortcodes,
148
-		]);
148
+		] );
149 149
 	}
150 150
 
151 151
 	/**
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	public function routerClearConsole()
155 155
 	{
156 156
 		glsr( Console::class )->clear();
157
-		glsr( Notice::class )->addSuccess( __( 'Console cleared.', 'site-reviews' ));
157
+		glsr( Notice::class )->addSuccess( __( 'Console cleared.', 'site-reviews' ) );
158 158
 	}
159 159
 
160 160
 	/**
@@ -163,19 +163,19 @@  discard block
 block discarded – undo
163 163
 	public function routerCountReviews()
164 164
 	{
165 165
 		$countManager = glsr( CountsManager::class );
166
-		$terms = get_terms([
166
+		$terms = get_terms( [
167 167
 			'hide_empty' => true,
168 168
 			'taxonomy' => Application::TAXONOMY,
169
-		]);
169
+		] );
170 170
 		foreach( $terms as $term ) {
171
-			$countManager->setTermCounts( $term->term_id, $countManager->buildTermCounts( $term->term_id ));
171
+			$countManager->setTermCounts( $term->term_id, $countManager->buildTermCounts( $term->term_id ) );
172 172
 		}
173 173
 		$postIds = glsr( SqlQueries::class )->getReviewsMeta( 'assigned_to' );
174 174
 		foreach( $postIds as $postId ) {
175
-			$countManager->setPostCounts( $postId, $countManager->buildPostCounts( $postId ));
175
+			$countManager->setPostCounts( $postId, $countManager->buildPostCounts( $postId ) );
176 176
 		}
177 177
 		$countManager->setCounts( $countManager->buildCounts() );
178
-		glsr( Notice::class )->addSuccess( __( 'Recalculated review counts.', 'site-reviews' ));
178
+		glsr( Notice::class )->addSuccess( __( 'Recalculated review counts.', 'site-reviews' ) );
179 179
 	}
180 180
 
181 181
 	/**
@@ -209,17 +209,17 @@  discard block
 block discarded – undo
209 209
 	{
210 210
 		$file = $_FILES['import-file'];
211 211
 		if( $file['error'] !== UPLOAD_ERR_OK ) {
212
-			return glsr( Notice::class )->addError( $this->getUploadError( $file['error'] ));
212
+			return glsr( Notice::class )->addError( $this->getUploadError( $file['error'] ) );
213 213
 		}
214
-		if( $file['type'] !== 'application/json' || !glsr( Helper::class )->endsWith( '.json', $file['name'] )) {
215
-			return glsr( Notice::class )->addError( __( 'Please use a valid Site Reviews settings file.', 'site-reviews' ));
214
+		if( $file['type'] !== 'application/json' || !glsr( Helper::class )->endsWith( '.json', $file['name'] ) ) {
215
+			return glsr( Notice::class )->addError( __( 'Please use a valid Site Reviews settings file.', 'site-reviews' ) );
216 216
 		}
217 217
 		$settings = json_decode( file_get_contents( $file['tmp_name'] ), true );
218
-		if( empty( $settings )) {
219
-			return glsr( Notice::class )->addWarning( __( 'There were no settings found to import.', 'site-reviews' ));
218
+		if( empty($settings) ) {
219
+			return glsr( Notice::class )->addWarning( __( 'There were no settings found to import.', 'site-reviews' ) );
220 220
 		}
221
-		glsr( OptionManager::class )->set( glsr( OptionManager::class )->normalize( $settings ));
222
-		glsr( Notice::class )->addSuccess( __( 'Settings imported.', 'site-reviews' ));
221
+		glsr( OptionManager::class )->set( glsr( OptionManager::class )->normalize( $settings ) );
222
+		glsr( Notice::class )->addSuccess( __( 'Settings imported.', 'site-reviews' ) );
223 223
 	}
224 224
 
225 225
 	/**
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 			UPLOAD_ERR_CANT_WRITE => __( 'Failed to write file to disk.', 'site-reviews' ),
238 238
 			UPLOAD_ERR_EXTENSION => __( 'A PHP extension stopped the file upload.', 'site-reviews' ),
239 239
 		];
240
-		return !isset( $errors[$errorCode] )
240
+		return !isset($errors[$errorCode])
241 241
 			? __( 'Unknown upload error.', 'site-reviews' )
242 242
 			: $errors[$errorCode];
243 243
 	}
Please login to merge, or discard this patch.
plugin/Controllers/Controller.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 	 */
16 16
 	public function download( $filename, $content )
17 17
 	{
18
-		if( !current_user_can( Application::CAPABILITY ))return;
18
+		if( !current_user_can( Application::CAPABILITY ) )return;
19 19
 		nocache_headers();
20 20
 		header( 'Content-Type: text/plain' );
21 21
 		header( 'Content-Disposition: attachment; filename="'.$filename.'"' );
@@ -30,8 +30,8 @@  discard block
 block discarded – undo
30 30
 	 */
31 31
 	public function execute( $command )
32 32
 	{
33
-		$handlerClass = str_replace( 'Commands', 'Handlers', get_class( $command ));
34
-		if( !class_exists( $handlerClass )) {
33
+		$handlerClass = str_replace( 'Commands', 'Handlers', get_class( $command ) );
34
+		if( !class_exists( $handlerClass ) ) {
35 35
 			throw new InvalidArgumentException( 'Handler '.$handlerClass.' not found.' );
36 36
 		}
37 37
 		try {
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 		}
40 40
 		catch( Exception $e ) {
41 41
 			status_header( 400 );
42
-			glsr( Notice::class )->addError( new WP_Error( 'site_reviews_error', $e->getMessage() ));
42
+			glsr( Notice::class )->addError( new WP_Error( 'site_reviews_error', $e->getMessage() ) );
43 43
 			glsr_log()->error( $e->getMessage() );
44 44
 		}
45 45
 	}
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 	 */
50 50
 	protected function getPostId()
51 51
 	{
52
-		return intval( filter_input( INPUT_GET, 'post' ));
52
+		return intval( filter_input( INPUT_GET, 'post' ) );
53 53
 	}
54 54
 
55 55
 	/**
Please login to merge, or discard this patch.
plugin/Modules/Rating.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
 	{
50 50
 		$average = array_sum( $ratingCounts );
51 51
 		if( $average > 0 ) {
52
-			$average = round( $this->getTotalSum( $ratingCounts ) / $average, intval( $roundBy ));
52
+			$average = round( $this->getTotalSum( $ratingCounts ) / $average, intval( $roundBy ) );
53 53
 		}
54
-		return floatval( apply_filters( 'site-reviews/rating/average', $average, $ratingCounts ));
54
+		return floatval( apply_filters( 'site-reviews/rating/average', $average, $ratingCounts ) );
55 55
 	}
56 56
 
57 57
 	/**
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 		}
73 73
 		$z = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage];
74 74
 		$phat = 1 * $upDownCounts[1] / $numRatings;
75
-		return ( $phat + $z * $z / ( 2 * $numRatings ) - $z * sqrt(( $phat * ( 1 - $phat ) + $z * $z / ( 4 * $numRatings )) / $numRatings )) / ( 1 + $z * $z / $numRatings );
75
+		return ($phat + $z * $z / (2 * $numRatings) - $z * sqrt( ($phat * (1 - $phat) + $z * $z / (4 * $numRatings)) / $numRatings )) / (1 + $z * $z / $numRatings);
76 76
 	}
77 77
 
78 78
 	/**
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 	{
91 91
 		$total = array_sum( $ratingCounts );
92 92
 		foreach( $ratingCounts as $index => $count ) {
93
-			if( empty( $count ))continue;
93
+			if( empty($count) )continue;
94 94
 			$ratingCounts[$index] = $count / $total * 100;
95 95
 		}
96 96
 		return $this->getRoundedPercentages( $ratingCounts );
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 			$this->getRankingUsingImdb( $ratingCounts ),
106 106
 			$ratingCounts,
107 107
 			$this
108
-		));
108
+		) );
109 109
 	}
110 110
 
111 111
 	/**
@@ -123,12 +123,12 @@  discard block
 block discarded – undo
123 123
 		$avgRating = $this->getAverage( $ratingCounts );
124 124
 		// Represents a prior (your prior opinion without data) for the average star rating. A higher prior also means a higher margin for error.
125 125
 		// This could also be the average score of all items instead of a fixed value.
126
-		$bayesMean = ( $confidencePercentage / 100 ) * static::MAX_RATING; // prior, 70% = 3.5
126
+		$bayesMean = ($confidencePercentage / 100) * static::MAX_RATING; // prior, 70% = 3.5
127 127
 		// Represents the number of ratings expected to begin observing a pattern that would put confidence in the prior.
128 128
 		$bayesMinimal = 10; // confidence
129 129
 		$numOfReviews = array_sum( $ratingCounts );
130 130
 		return $avgRating > 0
131
-			? (( $bayesMinimal * $bayesMean ) + ( $avgRating * $numOfReviews )) / ( $bayesMinimal + $numOfReviews )
131
+			? (($bayesMinimal * $bayesMean) + ($avgRating * $numOfReviews)) / ($bayesMinimal + $numOfReviews)
132 132
 			: 0;
133 133
 	}
134 134
 
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 		$weight = $this->getWeight( $ratingCounts, $ratingCountsSum );
149 149
 		$weightPow2 = $this->getWeight( $ratingCounts, $ratingCountsSum, true );
150 150
 		$zScore = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage];
151
-		return $weight - $zScore * sqrt(( $weightPow2 - pow( $weight, 2 )) / ( $ratingCountsSum + 1 ));
151
+		return $weight - $zScore * sqrt( ($weightPow2 - pow( $weight, 2 )) / ($ratingCountsSum + 1) );
152 152
 	}
153 153
 
154 154
 	/**
@@ -168,14 +168,14 @@  discard block
 block discarded – undo
168 168
 		$remainders = array_column( $percentages, 'remainder' );
169 169
 		array_multisort( $remainders, SORT_DESC, SORT_STRING, $indexes, SORT_DESC, $percentages );
170 170
 		$i = 0;
171
-		if( array_sum( array_column( $percentages, 'percent' )) > 0 ) {
172
-			while( array_sum( array_column( $percentages, 'percent' )) < $totalPercent ) {
171
+		if( array_sum( array_column( $percentages, 'percent' ) ) > 0 ) {
172
+			while( array_sum( array_column( $percentages, 'percent' ) ) < $totalPercent ) {
173 173
 				$percentages[$i]['percent']++;
174 174
 				$i++;
175 175
 			}
176 176
 		}
177 177
 		array_multisort( $indexes, SORT_DESC, $percentages );
178
-		return array_combine( $indexes, array_column( $percentages, 'percent' ));
178
+		return array_combine( $indexes, array_column( $percentages, 'percent' ) );
179 179
 	}
180 180
 
181 181
 	/**
@@ -183,8 +183,8 @@  discard block
 block discarded – undo
183 183
 	 */
184 184
 	protected function getTotalSum( array $ratingCounts )
185 185
 	{
186
-		return array_reduce( array_keys( $ratingCounts ), function( $carry, $index ) use( $ratingCounts ) {
187
-			return $carry + ( $index * $ratingCounts[$index] );
186
+		return array_reduce( array_keys( $ratingCounts ), function( $carry, $index ) use($ratingCounts) {
187
+			return $carry + ($index * $ratingCounts[$index]);
188 188
 		});
189 189
 	}
190 190
 
@@ -196,11 +196,11 @@  discard block
 block discarded – undo
196 196
 	protected function getWeight( array $ratingCounts, $ratingCountsSum, $powerOf2 = false )
197 197
 	{
198 198
 		return array_reduce( array_keys( $ratingCounts ),
199
-			function( $count, $rating ) use( $ratingCounts, $ratingCountsSum, $powerOf2 ) {
199
+			function( $count, $rating ) use($ratingCounts, $ratingCountsSum, $powerOf2) {
200 200
 				$ratingLevel = $powerOf2
201 201
 					? pow( $rating, 2 )
202 202
 					: $rating;
203
-				return $count + ( $ratingLevel * ( $ratingCounts[$rating] + 1 )) / $ratingCountsSum;
203
+				return $count + ($ratingLevel * ($ratingCounts[$rating] + 1)) / $ratingCountsSum;
204 204
 			}
205 205
 		);
206 206
 	}
Please login to merge, or discard this patch.
plugin/Modules/Html/Partials/SiteReviewsSummary.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
 		glsr_debug( $this->args );
37 37
 
38 38
 		// get rating counts
39
-		$this->ratingCounts = [0,0,0,0,0,0];
39
+		$this->ratingCounts = [0, 0, 0, 0, 0, 0];
40 40
 
41
-		if( !array_sum( $this->ratingCounts ) && $this->isHidden( 'if_empty' ))return;
41
+		if( !array_sum( $this->ratingCounts ) && $this->isHidden( 'if_empty' ) )return;
42 42
 		$this->averageRating = glsr( Rating::class )->getAverage( $this->ratingCounts );
43 43
 		$this->generateSchema();
44 44
 		return glsr( Template::class )->build( 'templates/reviews-summary', [
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 				'stars' => $this->buildStars(),
51 51
 				'text' => $this->buildText(),
52 52
 			],
53
-		]);
53
+		] );
54 54
 	}
55 55
 
56 56
 	/**
@@ -58,16 +58,16 @@  discard block
 block discarded – undo
58 58
 	 */
59 59
 	protected function buildPercentage()
60 60
 	{
61
-		if( $this->isHidden( 'bars' ))return;
61
+		if( $this->isHidden( 'bars' ) )return;
62 62
 		$range = range( Rating::MAX_RATING, 1 );
63
-		$percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->ratingCounts ));
64
-		$bars = array_reduce( $range, function( $carry, $level ) use( $percentages ) {
63
+		$percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->ratingCounts ) );
64
+		$bars = array_reduce( $range, function( $carry, $level ) use($percentages) {
65 65
 			$label = $this->buildPercentageLabel( $this->args['labels'][$level] );
66 66
 			$background = $this->buildPercentageBackground( $percentages[$level] );
67 67
 			$percent = $this->buildPercentagePercent( $percentages[$level] );
68 68
 			return $carry.glsr( Builder::class )->div( $label.$background.$percent, [
69 69
 				'class' => 'glsr-bar',
70
-			]);
70
+			] );
71 71
 		});
72 72
 		return $this->wrap( 'percentage', $bars );
73 73
 	}
@@ -78,10 +78,10 @@  discard block
 block discarded – undo
78 78
 	 */
79 79
 	protected function buildPercentageBackground( $percent )
80 80
 	{
81
-		$backgroundPercent = glsr( Builder::class )->span([
81
+		$backgroundPercent = glsr( Builder::class )->span( [
82 82
 			'class' => 'glsr-bar-background-percent',
83 83
 			'style' => 'width:'.$percent,
84
-		]);
84
+		] );
85 85
 		return '<span class="glsr-bar-background">'.$backgroundPercent.'</span>';
86 86
 	}
87 87
 
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 	 */
109 109
 	protected function buildRating()
110 110
 	{
111
-		if( $this->isHidden( 'rating' ))return;
111
+		if( $this->isHidden( 'rating' ) )return;
112 112
 		return $this->wrap( 'rating', '<span>'.$this->averageRating.'</span>' );
113 113
 	}
114 114
 
@@ -117,10 +117,10 @@  discard block
 block discarded – undo
117 117
 	 */
118 118
 	protected function buildStars()
119 119
 	{
120
-		if( $this->isHidden( 'stars' ))return;
120
+		if( $this->isHidden( 'stars' ) )return;
121 121
 		$stars = glsr( Partial::class )->build( 'star-rating', [
122 122
 			'rating' => $this->averageRating,
123
-		]);
123
+		] );
124 124
 		return $this->wrap( 'stars', $stars );
125 125
 	}
126 126
 
@@ -129,9 +129,9 @@  discard block
 block discarded – undo
129 129
 	 */
130 130
 	protected function buildText()
131 131
 	{
132
-		if( $this->isHidden( 'summary' ))return;
133
-		$count = intval( array_sum( $this->ratingCounts ));
134
-		if( empty( $this->args['text'] )) {
132
+		if( $this->isHidden( 'summary' ) )return;
133
+		$count = intval( array_sum( $this->ratingCounts ) );
134
+		if( empty($this->args['text']) ) {
135 135
 			// @todo document this change
136 136
 			 $this->args['text'] = _nx(
137 137
 				'{rating} out of {max} stars (based on {num} review)',
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 			);
143 143
 		}
144 144
 		$summary = str_replace(
145
-			['{rating}','{max}', '{num}'],
145
+			['{rating}', '{max}', '{num}'],
146 146
 			[$this->averageRating, Rating::MAX_RATING, $count],
147 147
 			$this->args['text']
148 148
 		);
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 */
155 155
 	protected function generateSchema()
156 156
 	{
157
-		if( !wp_validate_boolean( $this->args['schema'] ))return;
157
+		if( !wp_validate_boolean( $this->args['schema'] ) )return;
158 158
 		glsr( Schema::class )->store(
159 159
 			glsr( Schema::class )->buildSummary( $this->args )
160 160
 		);
@@ -186,6 +186,6 @@  discard block
 block discarded – undo
186 186
 	{
187 187
 		return glsr( Builder::class )->div( $value, [
188 188
 			'class' => 'glsr-summary-'.$key,
189
-		]);
189
+		] );
190 190
 	}
191 191
 }
Please login to merge, or discard this patch.
plugin/Modules/Schema.php 2 patches
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -43,10 +43,10 @@  discard block
 block discarded – undo
43 43
 			if( $review->review_type != 'local' )continue;
44 44
 			$reviews[] = $this->buildReview( $review );
45 45
 		}
46
-		if( !empty( $reviews )) {
46
+		if( !empty($reviews) ) {
47 47
 			array_walk( $reviews, function( &$review ) {
48
-				unset( $review['@context'] );
49
-				unset( $review['itemReviewed'] );
48
+				unset($review['@context']);
49
+				unset($review['itemReviewed']);
50 50
 			});
51 51
 			$schema['review'] = $reviews;
52 52
 		}
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	 */
60 60
 	public function buildSummary( $args = null )
61 61
 	{
62
-		if( is_array( $args )) {
62
+		if( is_array( $args ) ) {
63 63
 			$this->args = $args;
64 64
 		}
65 65
 		$buildSummary = glsr( Helper::class )->buildMethodName( $this->getSchemaOptionValue( 'type' ), 'buildSummaryFor' );
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 		$schema = method_exists( $this, $buildSummary )
68 68
 			? $this->$buildSummary()
69 69
 			: $this->buildSummaryForCustom();
70
-		if( !empty( $count )) {
70
+		if( !empty($count) ) {
71 71
 			$schema->aggregateRating(
72 72
 				$this->getSchemaType( 'AggregateRating' )
73 73
 					->ratingValue( $this->getRatingValue() )
@@ -85,11 +85,11 @@  discard block
 block discarded – undo
85 85
 	 */
86 86
 	public function render()
87 87
 	{
88
-		if( is_null( glsr()->schemas ))return;
88
+		if( is_null( glsr()->schemas ) )return;
89 89
 		printf( '<script type="application/ld+json">%s</script>', json_encode(
90 90
 			apply_filters( 'site-reviews/schema/all', glsr()->schemas ),
91 91
 			JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
92
-		));
92
+		) );
93 93
 	}
94 94
 
95 95
 	/**
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	{
100 100
 		$schemas = glsr()->schemas;
101 101
 		$schemas[] = $schema;
102
-		glsr()->schemas = array_map( 'unserialize', array_unique( array_map( 'serialize', $schemas )));
102
+		glsr()->schemas = array_map( 'unserialize', array_unique( array_map( 'serialize', $schemas ) ) );
103 103
 	}
104 104
 
105 105
 	/**
@@ -109,16 +109,16 @@  discard block
 block discarded – undo
109 109
 	protected function buildReview( $review )
110 110
 	{
111 111
 		$schema = $this->getSchemaType( 'Review' )
112
-			->doIf( !in_array( 'title', $this->args['hide'] ), function( $schema ) use( $review ) {
112
+			->doIf( !in_array( 'title', $this->args['hide'] ), function( $schema ) use($review) {
113 113
 				$schema->name( $review->title );
114 114
 			})
115
-			->doIf( !in_array( 'excerpt', $this->args['hide'] ), function( $schema ) use( $review ) {
115
+			->doIf( !in_array( 'excerpt', $this->args['hide'] ), function( $schema ) use($review) {
116 116
 				$schema->reviewBody( $review->content );
117 117
 			})
118
-			->datePublished(( new DateTime( $review->date )))
119
-			->author( $this->getSchemaType( 'Person' )->name( $review->author ))
120
-			->itemReviewed( $this->getSchemaType()->name( $this->getSchemaOptionValue( 'name' )));
121
-		if( !empty( $review->rating )) {
118
+			->datePublished( (new DateTime( $review->date )) )
119
+			->author( $this->getSchemaType( 'Person' )->name( $review->author ) )
120
+			->itemReviewed( $this->getSchemaType()->name( $this->getSchemaOptionValue( 'name' ) ) );
121
+		if( !empty($review->rating) ) {
122 122
 			$schema->reviewRating(
123 123
 				$this->getSchemaType( 'Rating' )
124 124
 					->ratingValue( $review->rating )
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 	{
138 138
 		foreach( $values as $value ) {
139 139
 			$option = $this->getSchemaOptionValue( $value );
140
-			if( empty( $option ))continue;
140
+			if( empty($option) )continue;
141 141
 			$schema->$value( $option );
142 142
 		}
143 143
 		return $schema;
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	{
151 151
 		return $this->buildSchemaValues( $this->getSchemaType(), [
152 152
 			'description', 'image', 'name', 'url',
153
-		]);
153
+		] );
154 154
 	}
155 155
 
156 156
 	/**
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 	{
161 161
 		return $this->buildSchemaValues( $this->buildSummaryForCustom(), [
162 162
 			'address', 'priceRange', 'telephone',
163
-		]);
163
+		] );
164 164
 	}
165 165
 
166 166
 	/**
@@ -170,10 +170,10 @@  discard block
 block discarded – undo
170 170
 	{
171 171
 		$offers = $this->buildSchemaValues( $this->getSchemaType( 'AggregateOffer' ), [
172 172
 			'highPrice', 'lowPrice', 'priceCurrency',
173
-		]);
173
+		] );
174 174
 		return $this->buildSummaryForCustom()
175 175
 			->offers( $offers )
176
-			->setProperty( '@id', $this->getSchemaOptionValue( 'url' ));
176
+			->setProperty( '@id', $this->getSchemaOptionValue( 'url' ) );
177 177
 	}
178 178
 
179 179
 	/**
@@ -181,16 +181,16 @@  discard block
 block discarded – undo
181 181
 	 */
182 182
 	protected function getRatingCounts()
183 183
 	{
184
-		if( !isset( $this->ratingCounts )) {
184
+		if( !isset($this->ratingCounts) ) {
185 185
 			$this->setPostCounts();
186 186
 			$this->setTermCounts();
187
-			if( empty( $this->reviewCounts )) {
187
+			if( empty($this->reviewCounts) ) {
188 188
 				$this->reviewCounts[] = glsr( CountsManager::class )->getCounts();
189 189
 			}
190 190
 			$counts = array_column( $this->reviewCounts, 'local' );
191 191
 			$this->ratingCounts = glsr( CountsManager::class )->flatten( $counts, [
192 192
 				'min' => $this->args['rating'],
193
-			]);
193
+			] );
194 194
 		}
195 195
 		return $this->ratingCounts;
196 196
 	}
@@ -211,14 +211,14 @@  discard block
 block discarded – undo
211 211
 	protected function getSchemaOption( $option, $fallback )
212 212
 	{
213 213
 		$option = strtolower( $option );
214
-		if( $schemaOption = trim( (string)get_post_meta( intval( get_the_ID() ), 'schema_'.$option, true ))) {
214
+		if( $schemaOption = trim( (string)get_post_meta( intval( get_the_ID() ), 'schema_'.$option, true ) ) ) {
215 215
 			return $schemaOption;
216 216
 		}
217 217
 		$setting = glsr( OptionManager::class )->get( 'settings.schema.'.$option );
218
-		if( is_array( $setting )) {
218
+		if( is_array( $setting ) ) {
219 219
 			return $this->getSchemaOptionDefault( $setting, $fallback );
220 220
 		}
221
-		return !empty( $setting )
221
+		return !empty($setting)
222 222
 			? $setting
223 223
 			: $fallback;
224 224
 	}
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 		$setting = wp_parse_args( $setting, [
233 233
 			'custom' => '',
234 234
 			'default' => $fallback,
235
-		]);
235
+		] );
236 236
 		return $setting['default'] != 'custom'
237 237
 			? $setting['default']
238 238
 			: $setting['custom'];
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 		}
252 252
 		if( !is_single() && !is_page() )return;
253 253
 		$method = glsr( Helper::class )->buildMethodName( $option, 'getThing' );
254
-		if( method_exists( $this, $method )) {
254
+		if( method_exists( $this, $method ) ) {
255 255
 			return $this->$method();
256 256
 		}
257 257
 	}
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 	 */
263 263
 	protected function getSchemaType( $type = null )
264 264
 	{
265
-		if( !is_string( $type )) {
265
+		if( !is_string( $type ) ) {
266 266
 			$type = $this->getSchemaOption( 'type', 'LocalBusiness' );
267 267
 		}
268 268
 		$className = glsr( Helper::class )->buildClassName( $type, 'Modules\Schema' );
@@ -277,11 +277,11 @@  discard block
 block discarded – undo
277 277
 	protected function getThingDescription()
278 278
 	{
279 279
 		$post = get_post();
280
-		if( !( $post instanceof WP_Post )) {
280
+		if( !($post instanceof WP_Post) ) {
281 281
 			return '';
282 282
 		}
283
-		$text = strip_shortcodes( wp_strip_all_tags( $post->post_excerpt ));
284
-		return wp_trim_words( $text, apply_filters( 'excerpt_length', 55 ));
283
+		$text = strip_shortcodes( wp_strip_all_tags( $post->post_excerpt ) );
284
+		return wp_trim_words( $text, apply_filters( 'excerpt_length', 55 ) );
285 285
 	}
286 286
 
287 287
 	/**
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
 	 */
314 314
 	protected function setPostCounts()
315 315
 	{
316
-		$postIds = array_filter( array_map( 'trim', explode( ',', $this->args['assigned_to'] )));
316
+		$postIds = array_filter( array_map( 'trim', explode( ',', $this->args['assigned_to'] ) ) );
317 317
 		foreach( $postIds as $postId ) {
318 318
 			$this->reviewCounts[] = glsr( CountsManager::class )->getPostCounts( $postId );
319 319
 		}
@@ -324,10 +324,10 @@  discard block
 block discarded – undo
324 324
 	 */
325 325
 	protected function setTermCounts()
326 326
 	{
327
-		$termIds = array_filter( array_map( 'trim', explode( ',', $this->args['category'] )));
327
+		$termIds = array_filter( array_map( 'trim', explode( ',', $this->args['category'] ) ) );
328 328
 		foreach( $termIds as $termId ) {
329 329
 			$term = get_term( $termId, Application::TAXONOMY );
330
-			if( !isset( $term->term_id ))continue;
330
+			if( !isset($term->term_id) )continue;
331 331
 			$this->reviewCounts[] = glsr( CountsManager::class )->getTermCounts( $termId );
332 332
 		}
333 333
 	}
Please login to merge, or discard this patch.
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -40,7 +40,9 @@  discard block
 block discarded – undo
40 40
 		foreach( glsr( ReviewManager::class )->get( $this->args )->results as $review ) {
41 41
 			// Only include critic reviews that have been directly produced by your site, not reviews from third- party sites or syndicated reviews.
42 42
 			// @see https://developers.google.com/search/docs/data-types/review
43
-			if( $review->review_type != 'local' )continue;
43
+			if( $review->review_type != 'local' ) {
44
+				continue;
45
+			}
44 46
 			$reviews[] = $this->buildReview( $review );
45 47
 		}
46 48
 		if( !empty( $reviews )) {
@@ -85,7 +87,9 @@  discard block
 block discarded – undo
85 87
 	 */
86 88
 	public function render()
87 89
 	{
88
-		if( is_null( glsr()->schemas ))return;
90
+		if( is_null( glsr()->schemas )) {
91
+			return;
92
+		}
89 93
 		printf( '<script type="application/ld+json">%s</script>', json_encode(
90 94
 			apply_filters( 'site-reviews/schema/all', glsr()->schemas ),
91 95
 			JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
@@ -137,7 +141,9 @@  discard block
 block discarded – undo
137 141
 	{
138 142
 		foreach( $values as $value ) {
139 143
 			$option = $this->getSchemaOptionValue( $value );
140
-			if( empty( $option ))continue;
144
+			if( empty( $option )) {
145
+				continue;
146
+			}
141 147
 			$schema->$value( $option );
142 148
 		}
143 149
 		return $schema;
@@ -249,7 +255,9 @@  discard block
 block discarded – undo
249 255
 		if( $value != $fallback ) {
250 256
 			return $value;
251 257
 		}
252
-		if( !is_single() && !is_page() )return;
258
+		if( !is_single() && !is_page() ) {
259
+			return;
260
+		}
253 261
 		$method = glsr( Helper::class )->buildMethodName( $option, 'getThing' );
254 262
 		if( method_exists( $this, $method )) {
255 263
 			return $this->$method();
@@ -327,7 +335,9 @@  discard block
 block discarded – undo
327 335
 		$termIds = array_filter( array_map( 'trim', explode( ',', $this->args['category'] )));
328 336
 		foreach( $termIds as $termId ) {
329 337
 			$term = get_term( $termId, Application::TAXONOMY );
330
-			if( !isset( $term->term_id ))continue;
338
+			if( !isset( $term->term_id )) {
339
+				continue;
340
+			}
331 341
 			$this->reviewCounts[] = glsr( CountsManager::class )->getTermCounts( $termId );
332 342
 		}
333 343
 	}
Please login to merge, or discard this patch.
plugin/Database/CountsManager.php 2 patches
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 			$this->getCounts(),
66 66
 			$review->review_type,
67 67
 			$review->rating
68
-		));
68
+		) );
69 69
 	}
70 70
 
71 71
 	/**
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 	 */
74 74
 	public function decreasePostCounts( Review $review )
75 75
 	{
76
-		if( empty( $counts = $this->getPostCounts( $review->assigned_to )))return;
76
+		if( empty($counts = $this->getPostCounts( $review->assigned_to )) )return;
77 77
 		$counts = $this->decreaseRating( $counts, $review->review_type, $review->rating );
78 78
 		$this->setPostCounts( $review->assigned_to, $counts );
79 79
 	}
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 	public function decreaseTermCounts( Review $review )
85 85
 	{
86 86
 		foreach( $review->term_ids as $termId ) {
87
-			if( empty( $counts = $this->getTermCounts( $termId )))continue;
87
+			if( empty($counts = $this->getTermCounts( $termId )) )continue;
88 88
 			$counts = $this->decreaseRating( $counts, $review->review_type, $review->rating );
89 89
 			$this->setTermCounts( $termId, $counts );
90 90
 		}
@@ -96,14 +96,14 @@  discard block
 block discarded – undo
96 96
 	public function flatten( array $reviewCounts, array $args = [] )
97 97
 	{
98 98
 		$counts = [];
99
-		array_walk_recursive( $reviewCounts, function( $num, $index ) use( &$counts ) {
100
-			$counts[$index] = isset( $counts[$index] )
99
+		array_walk_recursive( $reviewCounts, function( $num, $index ) use(&$counts) {
100
+			$counts[$index] = isset($counts[$index])
101 101
 				? $num + $counts[$index]
102 102
 				: $num;
103 103
 		});
104 104
 		$args = wp_parse_args( $args, ['max' => Rating::MAX_RATING, 'min' => Rating::MIN_RATING] );
105 105
 		foreach( $counts as $index => &$num ) {
106
-			if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ))continue;
106
+			if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ) )continue;
107 107
 			$num = 0;
108 108
 		}
109 109
 		return $counts;
@@ -150,14 +150,14 @@  discard block
 block discarded – undo
150 150
 	 */
151 151
 	public function increaseCounts( Review $review )
152 152
 	{
153
-		if( empty( $counts = $this->getCounts() )) {
153
+		if( empty($counts = $this->getCounts()) ) {
154 154
 			$counts = $this->buildCounts();
155 155
 		}
156 156
 		$this->setCounts( $this->increaseRating(
157 157
 			$counts,
158 158
 			$review->review_type,
159 159
 			$review->rating
160
-		));
160
+		) );
161 161
 	}
162 162
 
163 163
 	/**
@@ -165,8 +165,8 @@  discard block
 block discarded – undo
165 165
 	 */
166 166
 	public function increasePostCounts( Review $review )
167 167
 	{
168
-		if( !( get_post( $review->assigned_to ) instanceof WP_Post ))return;
169
-		if( empty( $counts = $this->getPostCounts( $review->assigned_to ))) {
168
+		if( !(get_post( $review->assigned_to ) instanceof WP_Post) )return;
169
+		if( empty($counts = $this->getPostCounts( $review->assigned_to )) ) {
170 170
 			$counts = $this->buildPostCounts( $review->assigned_to );
171 171
 		}
172 172
 		$counts = $this->increaseRating( $counts, $review->review_type, $review->rating );
@@ -179,8 +179,8 @@  discard block
 block discarded – undo
179 179
 	public function increaseTermCounts( Review $review )
180 180
 	{
181 181
 		foreach( $review->term_ids as $termId ) {
182
-			if( !( get_term( $termId, Application::TAXONOMY ) instanceof WP_Term ))continue;
183
-			if( empty( $counts = $this->getTermCounts( $termId ))) {
182
+			if( !(get_term( $termId, Application::TAXONOMY ) instanceof WP_Term) )continue;
183
+			if( empty($counts = $this->getTermCounts( $termId )) ) {
184 184
 				$counts = $this->buildTermCounts( $termId );
185 185
 			}
186 186
 			$counts = $this->increaseRating( $counts, $review->review_type, $review->rating );
@@ -204,8 +204,8 @@  discard block
 block discarded – undo
204 204
 	{
205 205
 		$ratingCounts = glsr( CountsManager::class )->flatten( $reviewCounts );
206 206
 		update_post_meta( $postId, static::META_COUNT, $reviewCounts );
207
-		update_post_meta( $postId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ));
208
-		update_post_meta( $postId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ));
207
+		update_post_meta( $postId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) );
208
+		update_post_meta( $postId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) );
209 209
 	}
210 210
 
211 211
 	/**
@@ -214,11 +214,11 @@  discard block
 block discarded – undo
214 214
 	 */
215 215
 	public function setTermCounts( $termId, array $reviewCounts )
216 216
 	{
217
-		if( !term_exists( $termId ))return;
217
+		if( !term_exists( $termId ) )return;
218 218
 		$ratingCounts = glsr( CountsManager::class )->flatten( $reviewCounts );
219 219
 		update_term_meta( $termId, static::META_COUNT, $reviewCounts );
220
-		update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ));
221
-		update_term_meta( $termId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ));
220
+		update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) );
221
+		update_term_meta( $termId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) );
222 222
 	}
223 223
 
224 224
 	/**
@@ -229,10 +229,10 @@  discard block
 block discarded – undo
229 229
 	{
230 230
 		$counts = [];
231 231
 		$lastPostId = 0;
232
-		while( $reviews = $this->queryReviews( $args, $lastPostId, $limit )) {
233
-			$types = array_keys( array_flip( array_column( $reviews, 'type' )));
232
+		while( $reviews = $this->queryReviews( $args, $lastPostId, $limit ) ) {
233
+			$types = array_keys( array_flip( array_column( $reviews, 'type' ) ) );
234 234
 			foreach( $types as $type ) {
235
-				if( isset( $counts[$type] ))continue;
235
+				if( isset($counts[$type]) )continue;
236 236
 				$counts[$type] = array_fill_keys( range( 0, Rating::MAX_RATING ), 0 );
237 237
 			}
238 238
 			foreach( $reviews as $review ) {
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 	 */
251 251
 	protected function decreaseRating( array $reviewCounts, $type, $rating )
252 252
 	{
253
-		if( isset( $reviewCounts[$type][$rating] )) {
253
+		if( isset($reviewCounts[$type][$rating]) ) {
254 254
 			$reviewCounts[$type][$rating] = max( 0, $reviewCounts[$type][$rating] - 1 );
255 255
 		}
256 256
 		return $reviewCounts;
@@ -263,10 +263,10 @@  discard block
 block discarded – undo
263 263
 	 */
264 264
 	protected function increaseRating( array $reviewCounts, $type, $rating )
265 265
 	{
266
-		if( !array_key_exists( $type, glsr()->reviewTypes )) {
266
+		if( !array_key_exists( $type, glsr()->reviewTypes ) ) {
267 267
 			return $reviewCounts;
268 268
 		}
269
-		if( !array_key_exists( $type, $reviewCounts )) {
269
+		if( !array_key_exists( $type, $reviewCounts ) ) {
270 270
 			$reviewCounts[$type] = [];
271 271
 		}
272 272
 		$reviewCounts = $this->normalize( $reviewCounts );
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 	{
282 282
 		foreach( $reviewCounts as &$counts ) {
283 283
 			foreach( range( 0, Rating::MAX_RATING ) as $index ) {
284
-				if( isset( $counts[$index] ))continue;
284
+				if( isset($counts[$index]) )continue;
285 285
 				$counts[$index] = 0;
286 286
 			}
287 287
 			ksort( $counts );
@@ -296,14 +296,14 @@  discard block
 block discarded – undo
296 296
 	 */
297 297
 	protected function queryReviews( array $args = [], $lastPostId, $limit )
298 298
 	{
299
-		$args = wp_parse_args( $args, array_fill_keys( ['post_id', 'term_id'], '' ));
300
-		if( empty( array_filter( $args ))) {
299
+		$args = wp_parse_args( $args, array_fill_keys( ['post_id', 'term_id'], '' ) );
300
+		if( empty(array_filter( $args )) ) {
301 301
 			return glsr( SqlQueries::class )->getReviewCounts( $lastPostId, $limit );
302 302
 		}
303
-		if( !empty( $args['post_id'] )) {
303
+		if( !empty($args['post_id']) ) {
304 304
 			return glsr( SqlQueries::class )->getReviewPostCounts( $args['post_id'], $lastPostId, $limit );
305 305
 		}
306
-		if( !empty( $args['term_id'] )) {
306
+		if( !empty($args['term_id']) ) {
307 307
 			return glsr( SqlQueries::class )->getReviewTermCounts( $args['term_id'], $lastPostId, $limit );
308 308
 		}
309 309
 	}
Please login to merge, or discard this patch.
Braces   +24 added lines, -8 removed lines patch added patch discarded remove patch
@@ -73,7 +73,9 @@  discard block
 block discarded – undo
73 73
 	 */
74 74
 	public function decreasePostCounts( Review $review )
75 75
 	{
76
-		if( empty( $counts = $this->getPostCounts( $review->assigned_to )))return;
76
+		if( empty( $counts = $this->getPostCounts( $review->assigned_to ))) {
77
+			return;
78
+		}
77 79
 		$counts = $this->decreaseRating( $counts, $review->review_type, $review->rating );
78 80
 		$this->setPostCounts( $review->assigned_to, $counts );
79 81
 	}
@@ -84,7 +86,9 @@  discard block
 block discarded – undo
84 86
 	public function decreaseTermCounts( Review $review )
85 87
 	{
86 88
 		foreach( $review->term_ids as $termId ) {
87
-			if( empty( $counts = $this->getTermCounts( $termId )))continue;
89
+			if( empty( $counts = $this->getTermCounts( $termId ))) {
90
+				continue;
91
+			}
88 92
 			$counts = $this->decreaseRating( $counts, $review->review_type, $review->rating );
89 93
 			$this->setTermCounts( $termId, $counts );
90 94
 		}
@@ -103,7 +107,9 @@  discard block
 block discarded – undo
103 107
 		});
104 108
 		$args = wp_parse_args( $args, ['max' => Rating::MAX_RATING, 'min' => Rating::MIN_RATING] );
105 109
 		foreach( $counts as $index => &$num ) {
106
-			if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ))continue;
110
+			if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] )) {
111
+				continue;
112
+			}
107 113
 			$num = 0;
108 114
 		}
109 115
 		return $counts;
@@ -165,7 +171,9 @@  discard block
 block discarded – undo
165 171
 	 */
166 172
 	public function increasePostCounts( Review $review )
167 173
 	{
168
-		if( !( get_post( $review->assigned_to ) instanceof WP_Post ))return;
174
+		if( !( get_post( $review->assigned_to ) instanceof WP_Post )) {
175
+			return;
176
+		}
169 177
 		if( empty( $counts = $this->getPostCounts( $review->assigned_to ))) {
170 178
 			$counts = $this->buildPostCounts( $review->assigned_to );
171 179
 		}
@@ -179,7 +187,9 @@  discard block
 block discarded – undo
179 187
 	public function increaseTermCounts( Review $review )
180 188
 	{
181 189
 		foreach( $review->term_ids as $termId ) {
182
-			if( !( get_term( $termId, Application::TAXONOMY ) instanceof WP_Term ))continue;
190
+			if( !( get_term( $termId, Application::TAXONOMY ) instanceof WP_Term )) {
191
+				continue;
192
+			}
183 193
 			if( empty( $counts = $this->getTermCounts( $termId ))) {
184 194
 				$counts = $this->buildTermCounts( $termId );
185 195
 			}
@@ -214,7 +224,9 @@  discard block
 block discarded – undo
214 224
 	 */
215 225
 	public function setTermCounts( $termId, array $reviewCounts )
216 226
 	{
217
-		if( !term_exists( $termId ))return;
227
+		if( !term_exists( $termId )) {
228
+			return;
229
+		}
218 230
 		$ratingCounts = glsr( CountsManager::class )->flatten( $reviewCounts );
219 231
 		update_term_meta( $termId, static::META_COUNT, $reviewCounts );
220 232
 		update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ));
@@ -232,7 +244,9 @@  discard block
 block discarded – undo
232 244
 		while( $reviews = $this->queryReviews( $args, $lastPostId, $limit )) {
233 245
 			$types = array_keys( array_flip( array_column( $reviews, 'type' )));
234 246
 			foreach( $types as $type ) {
235
-				if( isset( $counts[$type] ))continue;
247
+				if( isset( $counts[$type] )) {
248
+					continue;
249
+				}
236 250
 				$counts[$type] = array_fill_keys( range( 0, Rating::MAX_RATING ), 0 );
237 251
 			}
238 252
 			foreach( $reviews as $review ) {
@@ -281,7 +295,9 @@  discard block
 block discarded – undo
281 295
 	{
282 296
 		foreach( $reviewCounts as &$counts ) {
283 297
 			foreach( range( 0, Rating::MAX_RATING ) as $index ) {
284
-				if( isset( $counts[$index] ))continue;
298
+				if( isset( $counts[$index] )) {
299
+					continue;
300
+				}
285 301
 				$counts[$index] = 0;
286 302
 			}
287 303
 			ksort( $counts );
Please login to merge, or discard this patch.
plugin/Controllers/ReviewController.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -23,8 +23,8 @@  discard block
 block discarded – undo
23 23
 	 */
24 24
 	public function onAfterChangeCategory( $postId, $terms, $termIds, $taxonomySlug, $append, $oldTermIds )
25 25
 	{
26
-		if( !$this->isReviewPostId( $postId ))return;
27
-		$review = glsr( ReviewManager::class )->single( get_post( $postId ));
26
+		if( !$this->isReviewPostId( $postId ) )return;
27
+		$review = glsr( ReviewManager::class )->single( get_post( $postId ) );
28 28
 		$ignoredTerms = array_intersect( $oldTermIds, $termIds );
29 29
 		$review->term_ids = array_diff( $oldTermIds, $ignoredTerms );
30 30
 		glsr( CountsManager::class )->decreaseTermCounts( $review );
@@ -41,8 +41,8 @@  discard block
 block discarded – undo
41 41
 	 */
42 42
 	public function onAfterCreate( $postData, $meta, $postId )
43 43
 	{
44
-		if( !$this->isReviewPostId( $postId ))return;
45
-		$review = glsr( ReviewManager::class )->single( get_post( $postId ));
44
+		if( !$this->isReviewPostId( $postId ) )return;
45
+		$review = glsr( ReviewManager::class )->single( get_post( $postId ) );
46 46
 		glsr( CountsManager::class )->increase( $review );
47 47
 	}
48 48
 
@@ -53,8 +53,8 @@  discard block
 block discarded – undo
53 53
 	 */
54 54
 	public function onBeforeDelete( $postId )
55 55
 	{
56
-		if( !$this->isReviewPostId( $postId ))return;
57
-		$review = glsr( ReviewManager::class )->single( get_post( $postId ));
56
+		if( !$this->isReviewPostId( $postId ) )return;
57
+		$review = glsr( ReviewManager::class )->single( get_post( $postId ) );
58 58
 		glsr( CountsManager::class )->decrease( $review );
59 59
 	}
60 60
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 		if( !$this->isReviewPostId( $postId )
72 72
 			|| !in_array( $metaKey, ['assigned_to', 'rating', 'review_type'] )
73 73
 		)return;
74
-		$review = glsr( ReviewManager::class )->single( get_post( $postId ));
74
+		$review = glsr( ReviewManager::class )->single( get_post( $postId ) );
75 75
 		if( $review->$metaKey == $metaValue )return;
76 76
 		$method = glsr( Helper::class )->buildMethodName( $metaKey, 'onBeforeChange' );
77 77
 		call_user_func( [$this, $method], $review, $metaValue );
@@ -118,8 +118,8 @@  discard block
 block discarded – undo
118 118
 	 */
119 119
 	public function onChangeStatus( $newStatus, $oldStatus, WP_Post $post )
120 120
 	{
121
-		if( $post->post_type != Application::POST_TYPE || in_array( $oldStatus, ['new', $newStatus] ))return;
122
-		$review = glsr( ReviewManager::class )->single( get_post( $post->ID ));
121
+		if( $post->post_type != Application::POST_TYPE || in_array( $oldStatus, ['new', $newStatus] ) )return;
122
+		$review = glsr( ReviewManager::class )->single( get_post( $post->ID ) );
123 123
 		if( $post->post_status == 'publish' ) {
124 124
 			glsr( CountsManager::class )->increase( $review );
125 125
 		}
Please login to merge, or discard this patch.
Braces   +18 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,7 +23,9 @@  discard block
 block discarded – undo
23 23
 	 */
24 24
 	public function onAfterChangeCategory( $postId, $terms, $termIds, $taxonomySlug, $append, $oldTermIds )
25 25
 	{
26
-		if( !$this->isReviewPostId( $postId ))return;
26
+		if( !$this->isReviewPostId( $postId )) {
27
+			return;
28
+		}
27 29
 		$review = glsr( ReviewManager::class )->single( get_post( $postId ));
28 30
 		$ignoredTerms = array_intersect( $oldTermIds, $termIds );
29 31
 		$review->term_ids = array_diff( $oldTermIds, $ignoredTerms );
@@ -41,7 +43,9 @@  discard block
 block discarded – undo
41 43
 	 */
42 44
 	public function onAfterCreate( $postData, $meta, $postId )
43 45
 	{
44
-		if( !$this->isReviewPostId( $postId ))return;
46
+		if( !$this->isReviewPostId( $postId )) {
47
+			return;
48
+		}
45 49
 		$review = glsr( ReviewManager::class )->single( get_post( $postId ));
46 50
 		glsr( CountsManager::class )->increase( $review );
47 51
 	}
@@ -53,7 +57,9 @@  discard block
 block discarded – undo
53 57
 	 */
54 58
 	public function onBeforeDelete( $postId )
55 59
 	{
56
-		if( !$this->isReviewPostId( $postId ))return;
60
+		if( !$this->isReviewPostId( $postId )) {
61
+			return;
62
+		}
57 63
 		$review = glsr( ReviewManager::class )->single( get_post( $postId ));
58 64
 		glsr( CountsManager::class )->decrease( $review );
59 65
 	}
@@ -70,9 +76,13 @@  discard block
 block discarded – undo
70 76
 	{
71 77
 		if( !$this->isReviewPostId( $postId )
72 78
 			|| !in_array( $metaKey, ['assigned_to', 'rating', 'review_type'] )
73
-		)return;
79
+		) {
80
+			return;
81
+		}
74 82
 		$review = glsr( ReviewManager::class )->single( get_post( $postId ));
75
-		if( $review->$metaKey == $metaValue )return;
83
+		if( $review->$metaKey == $metaValue ) {
84
+			return;
85
+		}
76 86
 		$method = glsr( Helper::class )->buildMethodName( $metaKey, 'onBeforeChange' );
77 87
 		call_user_func( [$this, $method], $review, $metaValue );
78 88
 	}
@@ -118,7 +128,9 @@  discard block
 block discarded – undo
118 128
 	 */
119 129
 	public function onChangeStatus( $newStatus, $oldStatus, WP_Post $post )
120 130
 	{
121
-		if( $post->post_type != Application::POST_TYPE || in_array( $oldStatus, ['new', $newStatus] ))return;
131
+		if( $post->post_type != Application::POST_TYPE || in_array( $oldStatus, ['new', $newStatus] )) {
132
+			return;
133
+		}
122 134
 		$review = glsr( ReviewManager::class )->single( get_post( $post->ID ));
123 135
 		if( $post->post_status == 'publish' ) {
124 136
 			glsr( CountsManager::class )->increase( $review );
Please login to merge, or discard this patch.