@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | $this->getCounts(), |
| 67 | 67 | $review->review_type, |
| 68 | 68 | $review->rating |
| 69 | - )); |
|
| 69 | + ) ); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function decreasePostCounts( Review $review ) |
| 76 | 76 | { |
| 77 | - if( empty( $counts = $this->getPostCounts( $review->assigned_to )))return; |
|
| 77 | + if( empty($counts = $this->getPostCounts( $review->assigned_to )) )return; |
|
| 78 | 78 | $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
| 79 | 79 | $this->setPostCounts( $review->assigned_to, $counts ); |
| 80 | 80 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | public function decreaseTermCounts( Review $review ) |
| 86 | 86 | { |
| 87 | 87 | foreach( $review->term_ids as $termId ) { |
| 88 | - if( empty( $counts = $this->getTermCounts( $termId )))continue; |
|
| 88 | + if( empty($counts = $this->getTermCounts( $termId )) )continue; |
|
| 89 | 89 | $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
| 90 | 90 | $this->setTermCounts( $termId, $counts ); |
| 91 | 91 | } |
@@ -97,17 +97,17 @@ discard block |
||
| 97 | 97 | public function flatten( array $reviewCounts, array $args = [] ) |
| 98 | 98 | { |
| 99 | 99 | $counts = []; |
| 100 | - array_walk_recursive( $reviewCounts, function( $num, $index ) use( &$counts ) { |
|
| 101 | - $counts[$index] = isset( $counts[$index] ) |
|
| 100 | + array_walk_recursive( $reviewCounts, function( $num, $index ) use(&$counts) { |
|
| 101 | + $counts[$index] = isset($counts[$index]) |
|
| 102 | 102 | ? $num + $counts[$index] |
| 103 | 103 | : $num; |
| 104 | 104 | }); |
| 105 | 105 | $args = wp_parse_args( $args, [ |
| 106 | 106 | 'max' => Rating::MAX_RATING, |
| 107 | 107 | 'min' => Rating::MIN_RATING, |
| 108 | - ]); |
|
| 108 | + ] ); |
|
| 109 | 109 | foreach( $counts as $index => &$num ) { |
| 110 | - if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ))continue; |
|
| 110 | + if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ) )continue; |
|
| 111 | 111 | $num = 0; |
| 112 | 112 | } |
| 113 | 113 | return $counts; |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | 'post_ids' => [], |
| 123 | 123 | 'term_ids' => [], |
| 124 | 124 | 'type' => 'local', |
| 125 | - ]); |
|
| 125 | + ] ); |
|
| 126 | 126 | $counts = []; |
| 127 | 127 | foreach( glsr( Polylang::class )->getPostIds( $args['post_ids'] ) as $postId ) { |
| 128 | 128 | $counts[] = $this->getPostCounts( $postId ); |
@@ -130,12 +130,12 @@ discard block |
||
| 130 | 130 | foreach( $args['term_ids'] as $termId ) { |
| 131 | 131 | $counts[] = $this->getTermCounts( $termId ); |
| 132 | 132 | } |
| 133 | - if( empty( $counts )) { |
|
| 133 | + if( empty($counts) ) { |
|
| 134 | 134 | $counts[] = $this->getCounts(); |
| 135 | 135 | } |
| 136 | 136 | return in_array( $args['type'], ['', 'all'] ) |
| 137 | 137 | ? $this->normalize( [$this->flatten( $counts )] ) |
| 138 | - : $this->normalize( array_column( $counts, $args['type'] )); |
|
| 138 | + : $this->normalize( array_column( $counts, $args['type'] ) ); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | public function getCounts() |
| 145 | 145 | { |
| 146 | 146 | $counts = glsr( OptionManager::class )->get( 'counts', [] ); |
| 147 | - if( !is_array( $counts )) { |
|
| 147 | + if( !is_array( $counts ) ) { |
|
| 148 | 148 | glsr_log()->error( 'CountsManager: counts is not an array' )->debug( $counts ); |
| 149 | 149 | return []; |
| 150 | 150 | } |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | */ |
| 158 | 158 | public function getPostCounts( $postId ) |
| 159 | 159 | { |
| 160 | - return array_filter( (array)get_post_meta( $postId, static::META_COUNT, true )); |
|
| 160 | + return array_filter( (array)get_post_meta( $postId, static::META_COUNT, true ) ); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | */ |
| 167 | 167 | public function getTermCounts( $termId ) |
| 168 | 168 | { |
| 169 | - return array_filter( (array)get_term_meta( $termId, static::META_COUNT, true )); |
|
| 169 | + return array_filter( (array)get_term_meta( $termId, static::META_COUNT, true ) ); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /** |
@@ -184,14 +184,14 @@ discard block |
||
| 184 | 184 | */ |
| 185 | 185 | public function increaseCounts( Review $review ) |
| 186 | 186 | { |
| 187 | - if( empty( $counts = $this->getCounts() )) { |
|
| 187 | + if( empty($counts = $this->getCounts()) ) { |
|
| 188 | 188 | $counts = $this->buildCounts(); |
| 189 | 189 | } |
| 190 | 190 | $this->setCounts( $this->increaseRating( |
| 191 | 191 | $counts, |
| 192 | 192 | $review->review_type, |
| 193 | 193 | $review->rating |
| 194 | - )); |
|
| 194 | + ) ); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -199,9 +199,9 @@ discard block |
||
| 199 | 199 | */ |
| 200 | 200 | public function increasePostCounts( Review $review ) |
| 201 | 201 | { |
| 202 | - if( !( get_post( $review->assigned_to ) instanceof WP_Post ))return; |
|
| 202 | + if( !(get_post( $review->assigned_to ) instanceof WP_Post) )return; |
|
| 203 | 203 | $counts = $this->getPostCounts( $review->assigned_to ); |
| 204 | - $counts = empty( $counts ) |
|
| 204 | + $counts = empty($counts) |
|
| 205 | 205 | ? $this->buildPostCounts( $review->assigned_to ) |
| 206 | 206 | : $this->increaseRating( $counts, $review->review_type, $review->rating ); |
| 207 | 207 | $this->setPostCounts( $review->assigned_to, $counts ); |
@@ -212,10 +212,10 @@ discard block |
||
| 212 | 212 | */ |
| 213 | 213 | public function increaseTermCounts( Review $review ) |
| 214 | 214 | { |
| 215 | - $termIds = glsr( ReviewManager::class )->normalizeTerms( implode( ',', $review->term_ids )); |
|
| 215 | + $termIds = glsr( ReviewManager::class )->normalizeTerms( implode( ',', $review->term_ids ) ); |
|
| 216 | 216 | foreach( $termIds as $termId ) { |
| 217 | 217 | $counts = $this->getTermCounts( $termId ); |
| 218 | - $counts = empty( $counts ) |
|
| 218 | + $counts = empty($counts) |
|
| 219 | 219 | ? $this->buildTermCounts( $termId ) |
| 220 | 220 | : $this->increaseRating( $counts, $review->review_type, $review->rating ); |
| 221 | 221 | $this->setTermCounts( $termId, $counts ); |
@@ -238,8 +238,8 @@ discard block |
||
| 238 | 238 | { |
| 239 | 239 | $ratingCounts = $this->flatten( $reviewCounts ); |
| 240 | 240 | update_post_meta( $postId, static::META_COUNT, $reviewCounts ); |
| 241 | - update_post_meta( $postId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts )); |
|
| 242 | - update_post_meta( $postId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts )); |
|
| 241 | + update_post_meta( $postId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) ); |
|
| 242 | + update_post_meta( $postId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) ); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
@@ -248,11 +248,11 @@ discard block |
||
| 248 | 248 | */ |
| 249 | 249 | public function setTermCounts( $termId, array $reviewCounts ) |
| 250 | 250 | { |
| 251 | - if( !term_exists( $termId ))return; |
|
| 251 | + if( !term_exists( $termId ) )return; |
|
| 252 | 252 | $ratingCounts = $this->flatten( $reviewCounts ); |
| 253 | 253 | update_term_meta( $termId, static::META_COUNT, $reviewCounts ); |
| 254 | - update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts )); |
|
| 255 | - update_term_meta( $termId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts )); |
|
| 254 | + update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) ); |
|
| 255 | + update_term_meta( $termId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) ); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | /** |
@@ -263,10 +263,10 @@ discard block |
||
| 263 | 263 | { |
| 264 | 264 | $counts = []; |
| 265 | 265 | $lastPostId = 0; |
| 266 | - while( $reviews = $this->queryReviews( $args, $lastPostId, $limit )) { |
|
| 267 | - $types = array_keys( array_flip( array_column( $reviews, 'type' ))); |
|
| 266 | + while( $reviews = $this->queryReviews( $args, $lastPostId, $limit ) ) { |
|
| 267 | + $types = array_keys( array_flip( array_column( $reviews, 'type' ) ) ); |
|
| 268 | 268 | foreach( $types as $type ) { |
| 269 | - if( isset( $counts[$type] ))continue; |
|
| 269 | + if( isset($counts[$type]) )continue; |
|
| 270 | 270 | $type = $this->normalizeType( $type ); |
| 271 | 271 | $counts[$type] = array_fill_keys( range( 0, Rating::MAX_RATING ), 0 ); |
| 272 | 272 | } |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | */ |
| 287 | 287 | protected function decreaseRating( array $reviewCounts, $type, $rating ) |
| 288 | 288 | { |
| 289 | - if( isset( $reviewCounts[$type][$rating] )) { |
|
| 289 | + if( isset($reviewCounts[$type][$rating]) ) { |
|
| 290 | 290 | $reviewCounts[$type][$rating] = max( 0, $reviewCounts[$type][$rating] - 1 ); |
| 291 | 291 | } |
| 292 | 292 | return $reviewCounts; |
@@ -299,10 +299,10 @@ discard block |
||
| 299 | 299 | */ |
| 300 | 300 | protected function increaseRating( array $reviewCounts, $type, $rating ) |
| 301 | 301 | { |
| 302 | - if( !array_key_exists( $type, glsr()->reviewTypes )) { |
|
| 302 | + if( !array_key_exists( $type, glsr()->reviewTypes ) ) { |
|
| 303 | 303 | return $reviewCounts; |
| 304 | 304 | } |
| 305 | - if( !array_key_exists( $type, $reviewCounts )) { |
|
| 305 | + if( !array_key_exists( $type, $reviewCounts ) ) { |
|
| 306 | 306 | $reviewCounts[$type] = []; |
| 307 | 307 | } |
| 308 | 308 | $reviewCounts = $this->normalize( $reviewCounts ); |
@@ -315,12 +315,12 @@ discard block |
||
| 315 | 315 | */ |
| 316 | 316 | protected function normalize( array $reviewCounts ) |
| 317 | 317 | { |
| 318 | - if( empty( $reviewCounts )) { |
|
| 318 | + if( empty($reviewCounts) ) { |
|
| 319 | 319 | $reviewCounts = [[]]; |
| 320 | 320 | } |
| 321 | 321 | foreach( $reviewCounts as &$counts ) { |
| 322 | 322 | foreach( range( 0, Rating::MAX_RATING ) as $index ) { |
| 323 | - if( isset( $counts[$index] ))continue; |
|
| 323 | + if( isset($counts[$index]) )continue; |
|
| 324 | 324 | $counts[$index] = 0; |
| 325 | 325 | } |
| 326 | 326 | ksort( $counts ); |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | */ |
| 335 | 335 | protected function normalizeType( $type ) |
| 336 | 336 | { |
| 337 | - return empty( $type ) || !is_string( $type ) |
|
| 337 | + return empty($type) || !is_string( $type ) |
|
| 338 | 338 | ? 'local' |
| 339 | 339 | : $type; |
| 340 | 340 | } |
@@ -346,14 +346,14 @@ discard block |
||
| 346 | 346 | */ |
| 347 | 347 | protected function queryReviews( array $args = [], $lastPostId, $limit ) |
| 348 | 348 | { |
| 349 | - $args = wp_parse_args( $args, array_fill_keys( ['post_id', 'term_id'], '' )); |
|
| 350 | - if( empty( array_filter( $args ))) { |
|
| 349 | + $args = wp_parse_args( $args, array_fill_keys( ['post_id', 'term_id'], '' ) ); |
|
| 350 | + if( empty(array_filter( $args )) ) { |
|
| 351 | 351 | return glsr( SqlQueries::class )->getReviewCounts( $lastPostId, $limit ); |
| 352 | 352 | } |
| 353 | - if( !empty( $args['post_id'] )) { |
|
| 353 | + if( !empty($args['post_id']) ) { |
|
| 354 | 354 | return glsr( SqlQueries::class )->getReviewPostCounts( $args['post_id'], $lastPostId, $limit ); |
| 355 | 355 | } |
| 356 | - if( !empty( $args['term_id'] )) { |
|
| 356 | + if( !empty($args['term_id']) ) { |
|
| 357 | 357 | return glsr( SqlQueries::class )->getReviewTermCounts( $args['term_id'], $lastPostId, $limit ); |
| 358 | 358 | } |
| 359 | 359 | } |
@@ -74,7 +74,9 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function decreasePostCounts( Review $review ) |
| 76 | 76 | { |
| 77 | - if( empty( $counts = $this->getPostCounts( $review->assigned_to )))return; |
|
| 77 | + if( empty( $counts = $this->getPostCounts( $review->assigned_to ))) { |
|
| 78 | + return; |
|
| 79 | + } |
|
| 78 | 80 | $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
| 79 | 81 | $this->setPostCounts( $review->assigned_to, $counts ); |
| 80 | 82 | } |
@@ -85,7 +87,9 @@ discard block |
||
| 85 | 87 | public function decreaseTermCounts( Review $review ) |
| 86 | 88 | { |
| 87 | 89 | foreach( $review->term_ids as $termId ) { |
| 88 | - if( empty( $counts = $this->getTermCounts( $termId )))continue; |
|
| 90 | + if( empty( $counts = $this->getTermCounts( $termId ))) { |
|
| 91 | + continue; |
|
| 92 | + } |
|
| 89 | 93 | $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
| 90 | 94 | $this->setTermCounts( $termId, $counts ); |
| 91 | 95 | } |
@@ -107,7 +111,9 @@ discard block |
||
| 107 | 111 | 'min' => Rating::MIN_RATING, |
| 108 | 112 | ]); |
| 109 | 113 | foreach( $counts as $index => &$num ) { |
| 110 | - if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ))continue; |
|
| 114 | + if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] )) { |
|
| 115 | + continue; |
|
| 116 | + } |
|
| 111 | 117 | $num = 0; |
| 112 | 118 | } |
| 113 | 119 | return $counts; |
@@ -199,7 +205,9 @@ discard block |
||
| 199 | 205 | */ |
| 200 | 206 | public function increasePostCounts( Review $review ) |
| 201 | 207 | { |
| 202 | - if( !( get_post( $review->assigned_to ) instanceof WP_Post ))return; |
|
| 208 | + if( !( get_post( $review->assigned_to ) instanceof WP_Post )) { |
|
| 209 | + return; |
|
| 210 | + } |
|
| 203 | 211 | $counts = $this->getPostCounts( $review->assigned_to ); |
| 204 | 212 | $counts = empty( $counts ) |
| 205 | 213 | ? $this->buildPostCounts( $review->assigned_to ) |
@@ -248,7 +256,9 @@ discard block |
||
| 248 | 256 | */ |
| 249 | 257 | public function setTermCounts( $termId, array $reviewCounts ) |
| 250 | 258 | { |
| 251 | - if( !term_exists( $termId ))return; |
|
| 259 | + if( !term_exists( $termId )) { |
|
| 260 | + return; |
|
| 261 | + } |
|
| 252 | 262 | $ratingCounts = $this->flatten( $reviewCounts ); |
| 253 | 263 | update_term_meta( $termId, static::META_COUNT, $reviewCounts ); |
| 254 | 264 | update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts )); |
@@ -266,7 +276,9 @@ discard block |
||
| 266 | 276 | while( $reviews = $this->queryReviews( $args, $lastPostId, $limit )) { |
| 267 | 277 | $types = array_keys( array_flip( array_column( $reviews, 'type' ))); |
| 268 | 278 | foreach( $types as $type ) { |
| 269 | - if( isset( $counts[$type] ))continue; |
|
| 279 | + if( isset( $counts[$type] )) { |
|
| 280 | + continue; |
|
| 281 | + } |
|
| 270 | 282 | $type = $this->normalizeType( $type ); |
| 271 | 283 | $counts[$type] = array_fill_keys( range( 0, Rating::MAX_RATING ), 0 ); |
| 272 | 284 | } |
@@ -320,7 +332,9 @@ discard block |
||
| 320 | 332 | } |
| 321 | 333 | foreach( $reviewCounts as &$counts ) { |
| 322 | 334 | foreach( range( 0, Rating::MAX_RATING ) as $index ) { |
| 323 | - if( isset( $counts[$index] ))continue; |
|
| 335 | + if( isset( $counts[$index] )) { |
|
| 336 | + continue; |
|
| 337 | + } |
|
| 324 | 338 | $counts[$index] = 0; |
| 325 | 339 | } |
| 326 | 340 | ksort( $counts ); |