| @@ -13,11 +13,11 @@ discard block | ||
| 13 | 13 | public function defaults() | 
| 14 | 14 |  	{ | 
| 15 | 15 | $settings = $this->settings(); | 
| 16 | - $defaults = array_combine( array_keys( $settings ), glsr_array_column( $settings, 'default' )); | |
| 16 | + $defaults = array_combine( array_keys( $settings ), glsr_array_column( $settings, 'default' ) ); | |
| 17 | 17 | return wp_parse_args( $defaults, [ | 
| 18 | 18 | 'version' => '', | 
| 19 | 19 | 'version_upgraded_from' => '', | 
| 20 | - ]); | |
| 20 | + ] ); | |
| 21 | 21 | } | 
| 22 | 22 | |
| 23 | 23 | /** | 
| @@ -46,7 +46,7 @@ discard block | ||
| 46 | 46 | */ | 
| 47 | 47 | public function settings() | 
| 48 | 48 |  	{ | 
| 49 | - $settings = apply_filters( 'site-reviews/addon/settings', glsr()->config( 'settings' )); | |
| 49 | + $settings = apply_filters( 'site-reviews/addon/settings', glsr()->config( 'settings' ) ); | |
| 50 | 50 | return $this->normalize( $settings ); | 
| 51 | 51 | } | 
| 52 | 52 | |
| @@ -56,7 +56,7 @@ discard block | ||
| 56 | 56 | protected function normalize( array $settings ) | 
| 57 | 57 |  	{ | 
| 58 | 58 |  		array_walk( $settings, function( &$setting ) { | 
| 59 | - if( isset( $setting['default'] ))return; | |
| 59 | + if( isset($setting['default']) )return; | |
| 60 | 60 | $setting['default'] = ''; | 
| 61 | 61 | }); | 
| 62 | 62 | return $settings; | 
| @@ -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( glsr_array_column( $counts, $args['type'] )); | |
| 138 | + : $this->normalize( glsr_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 | /** | 
| @@ -264,12 +264,12 @@ discard block | ||
| 264 | 264 |  	{ | 
| 265 | 265 | $counts = []; | 
| 266 | 266 | $lastPostId = 0; | 
| 267 | -		while( $reviews = $this->queryReviews( $args, $lastPostId, $limit )) { | |
| 268 | - $types = array_keys( array_flip( glsr_array_column( $reviews, 'type' ))); | |
| 269 | - $types = array_unique( array_merge( ['local'], $types )); | |
| 267 | +		while( $reviews = $this->queryReviews( $args, $lastPostId, $limit ) ) { | |
| 268 | + $types = array_keys( array_flip( glsr_array_column( $reviews, 'type' ) ) ); | |
| 269 | + $types = array_unique( array_merge( ['local'], $types ) ); | |
| 270 | 270 |  			foreach( $types as $type ) { | 
| 271 | 271 | $type = $this->normalizeType( $type ); | 
| 272 | - if( isset( $counts[$type] ))continue; | |
| 272 | + if( isset($counts[$type]) )continue; | |
| 273 | 273 | $counts[$type] = array_fill_keys( range( 0, Rating::MAX_RATING ), 0 ); | 
| 274 | 274 | } | 
| 275 | 275 |  			foreach( $reviews as $review ) { | 
| @@ -288,7 +288,7 @@ discard block | ||
| 288 | 288 | */ | 
| 289 | 289 | protected function decreaseRating( array $reviewCounts, $type, $rating ) | 
| 290 | 290 |  	{ | 
| 291 | -		if( isset( $reviewCounts[$type][$rating] )) { | |
| 291 | +		if( isset($reviewCounts[$type][$rating]) ) { | |
| 292 | 292 | $reviewCounts[$type][$rating] = max( 0, $reviewCounts[$type][$rating] - 1 ); | 
| 293 | 293 | } | 
| 294 | 294 | return $reviewCounts; | 
| @@ -301,10 +301,10 @@ discard block | ||
| 301 | 301 | */ | 
| 302 | 302 | protected function increaseRating( array $reviewCounts, $type, $rating ) | 
| 303 | 303 |  	{ | 
| 304 | -		if( !array_key_exists( $type, glsr()->reviewTypes )) { | |
| 304 | +		if( !array_key_exists( $type, glsr()->reviewTypes ) ) { | |
| 305 | 305 | return $reviewCounts; | 
| 306 | 306 | } | 
| 307 | -		if( !array_key_exists( $type, $reviewCounts )) { | |
| 307 | +		if( !array_key_exists( $type, $reviewCounts ) ) { | |
| 308 | 308 | $reviewCounts[$type] = []; | 
| 309 | 309 | } | 
| 310 | 310 | $reviewCounts = $this->normalize( $reviewCounts ); | 
| @@ -317,12 +317,12 @@ discard block | ||
| 317 | 317 | */ | 
| 318 | 318 | protected function normalize( array $reviewCounts ) | 
| 319 | 319 |  	{ | 
| 320 | -		if( empty( $reviewCounts )) { | |
| 320 | +		if( empty($reviewCounts) ) { | |
| 321 | 321 | $reviewCounts = [[]]; | 
| 322 | 322 | } | 
| 323 | 323 |  		foreach( $reviewCounts as &$counts ) { | 
| 324 | 324 |  			foreach( range( 0, Rating::MAX_RATING ) as $index ) { | 
| 325 | - if( isset( $counts[$index] ))continue; | |
| 325 | + if( isset($counts[$index]) )continue; | |
| 326 | 326 | $counts[$index] = 0; | 
| 327 | 327 | } | 
| 328 | 328 | ksort( $counts ); | 
| @@ -336,7 +336,7 @@ discard block | ||
| 336 | 336 | */ | 
| 337 | 337 | protected function normalizeType( $type ) | 
| 338 | 338 |  	{ | 
| 339 | - return empty( $type ) || !is_string( $type ) | |
| 339 | + return empty($type) || !is_string( $type ) | |
| 340 | 340 | ? 'local' | 
| 341 | 341 | : $type; | 
| 342 | 342 | } | 
| @@ -348,14 +348,14 @@ discard block | ||
| 348 | 348 | */ | 
| 349 | 349 | protected function queryReviews( array $args = [], $lastPostId, $limit ) | 
| 350 | 350 |  	{ | 
| 351 | - $args = wp_parse_args( $args, array_fill_keys( ['post_id', 'term_id'], '' )); | |
| 352 | -		if( empty( array_filter( $args ))) { | |
| 351 | + $args = wp_parse_args( $args, array_fill_keys( ['post_id', 'term_id'], '' ) ); | |
| 352 | +		if( empty(array_filter( $args )) ) { | |
| 353 | 353 | return glsr( SqlQueries::class )->getReviewCounts( $lastPostId, $limit ); | 
| 354 | 354 | } | 
| 355 | -		if( !empty( $args['post_id'] )) { | |
| 355 | +		if( !empty($args['post_id']) ) { | |
| 356 | 356 | return glsr( SqlQueries::class )->getReviewPostCounts( $args['post_id'], $lastPostId, $limit ); | 
| 357 | 357 | } | 
| 358 | -		if( !empty( $args['term_id'] )) { | |
| 358 | +		if( !empty($args['term_id']) ) { | |
| 359 | 359 | return glsr( SqlQueries::class )->getReviewTermCounts( $args['term_id'], $lastPostId, $limit ); | 
| 360 | 360 | } | 
| 361 | 361 | } | 
| @@ -46,7 +46,7 @@ discard block | ||
| 46 | 46 | 'label' => '['.$tag.']', | 
| 47 | 47 | 'required' => $this->required, | 
| 48 | 48 | 'title' => esc_html__( 'Shortcode', 'site-reviews' ), | 
| 49 | - ]); | |
| 49 | + ] ); | |
| 50 | 50 | return $this; | 
| 51 | 51 | } | 
| 52 | 52 | |
| @@ -56,12 +56,12 @@ discard block | ||
| 56 | 56 | protected function generateFields( array $fields ) | 
| 57 | 57 |  	{ | 
| 58 | 58 |  		$generatedFields = array_map( function( $field ) { | 
| 59 | - if( empty( $field ))return; | |
| 59 | + if( empty($field) )return; | |
| 60 | 60 | $field = $this->normalize( $field ); | 
| 61 | - if( !method_exists( $this, $method = 'normalize'.ucfirst( $field['type'] )))return; | |
| 61 | + if( !method_exists( $this, $method = 'normalize'.ucfirst( $field['type'] ) ) )return; | |
| 62 | 62 | return $this->$method( $field ); | 
| 63 | 63 | }, $fields ); | 
| 64 | - return array_values( array_filter( $generatedFields )); | |
| 64 | + return array_values( array_filter( $generatedFields ) ); | |
| 65 | 65 | } | 
| 66 | 66 | |
| 67 | 67 | /** | 
| @@ -70,15 +70,15 @@ discard block | ||
| 70 | 70 | protected function getFields() | 
| 71 | 71 |  	{ | 
| 72 | 72 | $fields = $this->generateFields( $this->fields() ); | 
| 73 | -		if( !empty( $this->errors )) { | |
| 73 | +		if( !empty($this->errors) ) { | |
| 74 | 74 | $errors = []; | 
| 75 | 75 |  			foreach( $this->required as $name => $alert ) { | 
| 76 | - if( false !== array_search( $name, glsr_array_column( $fields, 'name' )))continue; | |
| 76 | + if( false !== array_search( $name, glsr_array_column( $fields, 'name' ) ) )continue; | |
| 77 | 77 | $errors[] = $this->errors[$name]; | 
| 78 | 78 | } | 
| 79 | 79 | $this->errors = $errors; | 
| 80 | 80 | } | 
| 81 | - return empty( $this->errors ) | |
| 81 | + return empty($this->errors) | |
| 82 | 82 | ? $fields | 
| 83 | 83 | : $this->errors; | 
| 84 | 84 | } | 
| @@ -91,7 +91,7 @@ discard block | ||
| 91 | 91 | return wp_parse_args( $field, [ | 
| 92 | 92 | 'items' => [], | 
| 93 | 93 | 'type' => '', | 
| 94 | - ]); | |
| 94 | + ] ); | |
| 95 | 95 | } | 
| 96 | 96 | |
| 97 | 97 | /** | 
| @@ -109,7 +109,7 @@ discard block | ||
| 109 | 109 | 'tooltip' => '', | 
| 110 | 110 | 'type' => '', | 
| 111 | 111 | 'value' => '', | 
| 112 | - ]); | |
| 112 | + ] ); | |
| 113 | 113 | } | 
| 114 | 114 | |
| 115 | 115 | /** | 
| @@ -117,7 +117,7 @@ discard block | ||
| 117 | 117 | */ | 
| 118 | 118 | protected function normalizeContainer( array $field ) | 
| 119 | 119 |  	{ | 
| 120 | - if( !array_key_exists( 'html', $field ) && !array_key_exists( 'items', $field ))return; | |
| 120 | + if( !array_key_exists( 'html', $field ) && !array_key_exists( 'items', $field ) )return; | |
| 121 | 121 | $field['items'] = $this->generateFields( $field['items'] ); | 
| 122 | 122 | return $field; | 
| 123 | 123 | } | 
| @@ -127,7 +127,7 @@ discard block | ||
| 127 | 127 | */ | 
| 128 | 128 | protected function normalizeField( array $field, array $defaults ) | 
| 129 | 129 |  	{ | 
| 130 | - if( !$this->validate( $field ))return; | |
| 130 | + if( !$this->validate( $field ) )return; | |
| 131 | 131 |  		return array_filter( shortcode_atts( $defaults, $field ), function( $value ) { | 
| 132 | 132 | return $value !== ''; | 
| 133 | 133 | }); | 
| @@ -147,9 +147,9 @@ discard block | ||
| 147 | 147 | 'tooltip' => '', | 
| 148 | 148 | 'type' => '', | 
| 149 | 149 | 'value' => '', | 
| 150 | - ]); | |
| 151 | - if( !is_array( $listbox ))return; | |
| 152 | -		if( !array_key_exists( '', $listbox['options'] )) { | |
| 150 | + ] ); | |
| 151 | + if( !is_array( $listbox ) )return; | |
| 152 | +		if( !array_key_exists( '', $listbox['options'] ) ) { | |
| 153 | 153 | $listbox['options'] = ['' => $listbox['placeholder']] + $listbox['options']; | 
| 154 | 154 | } | 
| 155 | 155 |  		foreach( $listbox['options'] as $value => $text ) { | 
| @@ -166,7 +166,7 @@ discard block | ||
| 166 | 166 | */ | 
| 167 | 167 | protected function normalizePost( array $field ) | 
| 168 | 168 |  	{ | 
| 169 | -		if( !is_array( $field['query_args'] )) { | |
| 169 | +		if( !is_array( $field['query_args'] ) ) { | |
| 170 | 170 | $field['query_args'] = []; | 
| 171 | 171 | } | 
| 172 | 172 | $posts = get_posts( wp_parse_args( $field['query_args'], [ | 
| @@ -174,8 +174,8 @@ discard block | ||
| 174 | 174 | 'orderby' => 'title', | 
| 175 | 175 | 'post_type' => 'post', | 
| 176 | 176 | 'posts_per_page' => 30, | 
| 177 | - ])); | |
| 178 | -		if( !empty( $posts )) { | |
| 177 | + ] ) ); | |
| 178 | +		if( !empty($posts) ) { | |
| 179 | 179 | $options = []; | 
| 180 | 180 |  			foreach( $posts as $post ) { | 
| 181 | 181 | $options[$post->ID] = esc_html( $post->post_title ); | 
| @@ -205,7 +205,7 @@ discard block | ||
| 205 | 205 | 'tooltip' => '', | 
| 206 | 206 | 'type' => '', | 
| 207 | 207 | 'value' => '', | 
| 208 | - ]); | |
| 208 | + ] ); | |
| 209 | 209 | } | 
| 210 | 210 | |
| 211 | 211 | /** | 
| @@ -213,7 +213,7 @@ discard block | ||
| 213 | 213 | */ | 
| 214 | 214 | protected function validate( array $field ) | 
| 215 | 215 |  	{ | 
| 216 | - $args = shortcode_atts([ | |
| 216 | + $args = shortcode_atts( [ | |
| 217 | 217 | 'label' => '', | 
| 218 | 218 | 'name' => false, | 
| 219 | 219 | 'required' => false, | 
| @@ -229,13 +229,13 @@ discard block | ||
| 229 | 229 | */ | 
| 230 | 230 | protected function validateErrors( array $args ) | 
| 231 | 231 |  	{ | 
| 232 | -		if( !isset( $args['required']['error'] )) { | |
| 232 | +		if( !isset($args['required']['error']) ) { | |
| 233 | 233 | return true; | 
| 234 | 234 | } | 
| 235 | - $this->errors[$args['name']] = $this->normalizeContainer([ | |
| 235 | + $this->errors[$args['name']] = $this->normalizeContainer( [ | |
| 236 | 236 | 'html' => $args['required']['error'], | 
| 237 | 237 | 'type' => 'container', | 
| 238 | - ]); | |
| 238 | + ] ); | |
| 239 | 239 | return false; | 
| 240 | 240 | } | 
| 241 | 241 | |
| @@ -248,10 +248,10 @@ discard block | ||
| 248 | 248 | return true; | 
| 249 | 249 | } | 
| 250 | 250 | $alert = esc_html__( 'Some of the shortcode options are required.', 'site-reviews' ); | 
| 251 | -		if( isset( $args['required']['alert'] )) { | |
| 251 | +		if( isset($args['required']['alert']) ) { | |
| 252 | 252 | $alert = $args['required']['alert']; | 
| 253 | 253 | } | 
| 254 | -		else if( !empty( $args['label'] )) { | |
| 254 | +		else if( !empty($args['label']) ) { | |
| 255 | 255 | $alert = sprintf( | 
| 256 | 256 | esc_html_x( 'The "%s" option is required.', 'the option label', 'site-reviews' ), | 
| 257 | 257 | str_replace( ':', '', $args['label'] ) | 
| @@ -56,9 +56,13 @@ discard block | ||
| 56 | 56 | protected function generateFields( array $fields ) | 
| 57 | 57 |  	{ | 
| 58 | 58 |  		$generatedFields = array_map( function( $field ) { | 
| 59 | - if( empty( $field ))return; | |
| 59 | +			if( empty( $field )) { | |
| 60 | + return; | |
| 61 | + } | |
| 60 | 62 | $field = $this->normalize( $field ); | 
| 61 | - if( !method_exists( $this, $method = 'normalize'.ucfirst( $field['type'] )))return; | |
| 63 | +			if( !method_exists( $this, $method = 'normalize'.ucfirst( $field['type'] ))) { | |
| 64 | + return; | |
| 65 | + } | |
| 62 | 66 | return $this->$method( $field ); | 
| 63 | 67 | }, $fields ); | 
| 64 | 68 | return array_values( array_filter( $generatedFields )); | 
| @@ -73,7 +77,9 @@ discard block | ||
| 73 | 77 |  		if( !empty( $this->errors )) { | 
| 74 | 78 | $errors = []; | 
| 75 | 79 |  			foreach( $this->required as $name => $alert ) { | 
| 76 | - if( false !== array_search( $name, glsr_array_column( $fields, 'name' )))continue; | |
| 80 | +				if( false !== array_search( $name, glsr_array_column( $fields, 'name' ))) { | |
| 81 | + continue; | |
| 82 | + } | |
| 77 | 83 | $errors[] = $this->errors[$name]; | 
| 78 | 84 | } | 
| 79 | 85 | $this->errors = $errors; | 
| @@ -117,7 +123,9 @@ discard block | ||
| 117 | 123 | */ | 
| 118 | 124 | protected function normalizeContainer( array $field ) | 
| 119 | 125 |  	{ | 
| 120 | - if( !array_key_exists( 'html', $field ) && !array_key_exists( 'items', $field ))return; | |
| 126 | +		if( !array_key_exists( 'html', $field ) && !array_key_exists( 'items', $field )) { | |
| 127 | + return; | |
| 128 | + } | |
| 121 | 129 | $field['items'] = $this->generateFields( $field['items'] ); | 
| 122 | 130 | return $field; | 
| 123 | 131 | } | 
| @@ -127,7 +135,9 @@ discard block | ||
| 127 | 135 | */ | 
| 128 | 136 | protected function normalizeField( array $field, array $defaults ) | 
| 129 | 137 |  	{ | 
| 130 | - if( !$this->validate( $field ))return; | |
| 138 | +		if( !$this->validate( $field )) { | |
| 139 | + return; | |
| 140 | + } | |
| 131 | 141 |  		return array_filter( shortcode_atts( $defaults, $field ), function( $value ) { | 
| 132 | 142 | return $value !== ''; | 
| 133 | 143 | }); | 
| @@ -148,7 +158,9 @@ discard block | ||
| 148 | 158 | 'type' => '', | 
| 149 | 159 | 'value' => '', | 
| 150 | 160 | ]); | 
| 151 | - if( !is_array( $listbox ))return; | |
| 161 | +		if( !is_array( $listbox )) { | |
| 162 | + return; | |
| 163 | + } | |
| 152 | 164 |  		if( !array_key_exists( '', $listbox['options'] )) { | 
| 153 | 165 | $listbox['options'] = ['' => $listbox['placeholder']] + $listbox['options']; | 
| 154 | 166 | } | 
| @@ -49,9 +49,9 @@ discard block | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 168 | 168 | $remainders = glsr_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( glsr_array_column( $percentages, 'percent' )) > 0 ) { | |
| 172 | -			while( array_sum( glsr_array_column( $percentages, 'percent' )) < $totalPercent ) { | |
| 171 | +		if( array_sum( glsr_array_column( $percentages, 'percent' ) ) > 0 ) { | |
| 172 | +			while( array_sum( glsr_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, glsr_array_column( $percentages, 'percent' )); | |
| 178 | + return array_combine( $indexes, glsr_array_column( $percentages, 'percent' ) ); | |
| 179 | 179 | } | 
| 180 | 180 | |
| 181 | 181 | /** | 
| @@ -183,8 +183,8 @@ discard block | ||
| 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 | ||
| 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 | } | 
| @@ -30,7 +30,7 @@ discard block | ||
| 30 | 30 |  	{ | 
| 31 | 31 | $translations = $this->translations(); | 
| 32 | 32 | $entries = $this->filter( $translations, $this->entries() )->results(); | 
| 33 | -		array_walk( $translations, function( &$entry ) use( $entries ) { | |
| 33 | +		array_walk( $translations, function( &$entry ) use($entries) { | |
| 34 | 34 | $entry['desc'] = array_key_exists( $entry['id'], $entries ) | 
| 35 | 35 | ? $this->getEntryString( $entries[$entry['id']], 'msgctxt' ) | 
| 36 | 36 | : ''; | 
| @@ -43,7 +43,7 @@ discard block | ||
| 43 | 43 | */ | 
| 44 | 44 | public function entries() | 
| 45 | 45 |  	{ | 
| 46 | -		if( !isset( $this->entries )) { | |
| 46 | +		if( !isset($this->entries) ) { | |
| 47 | 47 | $potFile = glsr()->path( glsr()->languages.'/'.Application::ID.'.pot' ); | 
| 48 | 48 | $entries = $this->extractEntriesFromPotFile( $potFile ); | 
| 49 | 49 | $entries = apply_filters( 'site-reviews/translation/entries', $entries ); | 
| @@ -88,13 +88,13 @@ discard block | ||
| 88 | 88 | */ | 
| 89 | 89 | public function filter( $filterWith = null, $entries = null, $intersect = true ) | 
| 90 | 90 |  	{ | 
| 91 | -		if( !is_array( $entries )) { | |
| 91 | +		if( !is_array( $entries ) ) { | |
| 92 | 92 | $entries = $this->results; | 
| 93 | 93 | } | 
| 94 | -		if( !is_array( $filterWith )) { | |
| 94 | +		if( !is_array( $filterWith ) ) { | |
| 95 | 95 | $filterWith = $this->translations(); | 
| 96 | 96 | } | 
| 97 | - $keys = array_flip( glsr_array_column( $filterWith, 'id' )); | |
| 97 | + $keys = array_flip( glsr_array_column( $filterWith, 'id' ) ); | |
| 98 | 98 | $this->results = $intersect | 
| 99 | 99 | ? array_intersect_key( $entries, $keys ) | 
| 100 | 100 | : array_diff_key( $entries, $keys ); | 
| @@ -108,17 +108,17 @@ discard block | ||
| 108 | 108 | public function render( $template, array $entry ) | 
| 109 | 109 |  	{ | 
| 110 | 110 | $data = array_combine( | 
| 111 | -			array_map( function( $key ) { return 'data.'.$key; }, array_keys( $entry )), | |
| 111 | +			array_map( function( $key ) { return 'data.'.$key; }, array_keys( $entry ) ), | |
| 112 | 112 | $entry | 
| 113 | 113 | ); | 
| 114 | 114 | $data['data.class'] = $data['data.error'] = ''; | 
| 115 | -		if( array_search( $entry['s1'], glsr_array_column( $this->entries(), 'msgid' )) === false ) { | |
| 115 | +		if( array_search( $entry['s1'], glsr_array_column( $this->entries(), 'msgid' ) ) === false ) { | |
| 116 | 116 | $data['data.class'] = 'is-invalid'; | 
| 117 | 117 | $data['data.error'] = __( 'This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews' ); | 
| 118 | 118 | } | 
| 119 | 119 | return glsr( Template::class )->build( 'partials/translations/'.$template, [ | 
| 120 | 120 | 'context' => $data, | 
| 121 | - ]); | |
| 121 | + ] ); | |
| 122 | 122 | } | 
| 123 | 123 | |
| 124 | 124 | /** | 
| @@ -150,13 +150,13 @@ discard block | ||
| 150 | 150 | 'p1' => $this->getEntryString( $entry, 'msgid_plural' ), | 
| 151 | 151 | 's1' => $this->getEntryString( $entry, 'msgid' ), | 
| 152 | 152 | ]; | 
| 153 | - $text = !empty( $data['p1'] ) | |
| 153 | + $text = !empty($data['p1']) | |
| 154 | 154 | ? sprintf( '%s | %s', $data['s1'], $data['p1'] ) | 
| 155 | 155 | : $data['s1']; | 
| 156 | 156 | $rendered .= $this->render( 'result', [ | 
| 157 | - 'entry' => json_encode( $data, JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_TAG|JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE ), | |
| 157 | + 'entry' => json_encode( $data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ), | |
| 158 | 158 | 'text' => wp_strip_all_tags( $text ), | 
| 159 | - ]); | |
| 159 | + ] ); | |
| 160 | 160 | } | 
| 161 | 161 |  		if( $resetAfterRender ) { | 
| 162 | 162 | $this->reset(); | 
| @@ -189,12 +189,12 @@ discard block | ||
| 189 | 189 | public function search( $needle = '' ) | 
| 190 | 190 |  	{ | 
| 191 | 191 | $this->reset(); | 
| 192 | - $needle = trim( strtolower( $needle )); | |
| 192 | + $needle = trim( strtolower( $needle ) ); | |
| 193 | 193 |  		foreach( $this->entries() as $key => $entry ) { | 
| 194 | - $single = strtolower( $this->getEntryString( $entry, 'msgid' )); | |
| 195 | - $plural = strtolower( $this->getEntryString( $entry, 'msgid_plural' )); | |
| 194 | + $single = strtolower( $this->getEntryString( $entry, 'msgid' ) ); | |
| 195 | + $plural = strtolower( $this->getEntryString( $entry, 'msgid_plural' ) ); | |
| 196 | 196 |  			if( strlen( $needle ) < static::SEARCH_THRESHOLD ) { | 
| 197 | -				if( in_array( $needle, [$single, $plural] )) { | |
| 197 | +				if( in_array( $needle, [$single, $plural] ) ) { | |
| 198 | 198 | $this->results[$key] = $entry; | 
| 199 | 199 | } | 
| 200 | 200 | } | 
| @@ -212,10 +212,10 @@ discard block | ||
| 212 | 212 | public function translations() | 
| 213 | 213 |  	{ | 
| 214 | 214 | static $translations; | 
| 215 | -		if( empty( $translations )) { | |
| 215 | +		if( empty($translations) ) { | |
| 216 | 216 | $settings = glsr( OptionManager::class )->get( 'settings' ); | 
| 217 | - $translations = isset( $settings['strings'] ) | |
| 218 | - ? $this->normalizeSettings( (array) $settings['strings'] ) | |
| 217 | + $translations = isset($settings['strings']) | |
| 218 | + ? $this->normalizeSettings( (array)$settings['strings'] ) | |
| 219 | 219 | : []; | 
| 220 | 220 | } | 
| 221 | 221 | return $translations; | 
| @@ -227,8 +227,8 @@ discard block | ||
| 227 | 227 | */ | 
| 228 | 228 | protected function getEntryString( array $entry, $key ) | 
| 229 | 229 |  	{ | 
| 230 | - return isset( $entry[$key] ) | |
| 231 | - ? implode( '', (array) $entry[$key] ) | |
| 230 | + return isset($entry[$key]) | |
| 231 | + ? implode( '', (array)$entry[$key] ) | |
| 232 | 232 | : ''; | 
| 233 | 233 | } | 
| 234 | 234 | |
| @@ -240,7 +240,7 @@ discard block | ||
| 240 | 240 | $keys = [ | 
| 241 | 241 | 'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]', | 
| 242 | 242 | ]; | 
| 243 | -		array_walk( $entries, function( &$entry ) use( $keys ) { | |
| 243 | +		array_walk( $entries, function( &$entry ) use($keys) { | |
| 244 | 244 |  			foreach( $keys as $key ) { | 
| 245 | 245 | $entry = $this->normalizeEntryString( $entry, $key ); | 
| 246 | 246 | } | 
| @@ -254,7 +254,7 @@ discard block | ||
| 254 | 254 | */ | 
| 255 | 255 | protected function normalizeEntryString( array $entry, $key ) | 
| 256 | 256 |  	{ | 
| 257 | -		if( isset( $entry[$key] )) { | |
| 257 | +		if( isset($entry[$key]) ) { | |
| 258 | 258 | $entry[$key] = $this->getEntryString( $entry, $key ); | 
| 259 | 259 | } | 
| 260 | 260 | return $entry; | 
| @@ -268,11 +268,11 @@ discard block | ||
| 268 | 268 | $defaultString = array_fill_keys( ['id', 's1', 's2', 'p1', 'p2'], '' ); | 
| 269 | 269 | $strings = array_filter( $strings, 'is_array' ); | 
| 270 | 270 |  		foreach( $strings as &$string ) { | 
| 271 | - $string['type'] = isset( $string['p1'] ) ? 'plural' : 'single'; | |
| 271 | + $string['type'] = isset($string['p1']) ? 'plural' : 'single'; | |
| 272 | 272 | $string = wp_parse_args( $string, $defaultString ); | 
| 273 | 273 | } | 
| 274 | 274 |  		return array_filter( $strings, function( $string ) { | 
| 275 | - return !empty( $string['id'] ); | |
| 275 | + return !empty($string['id']); | |
| 276 | 276 | }); | 
| 277 | 277 | } | 
| 278 | 278 | } | 
| @@ -19,8 +19,8 @@ discard block | ||
| 19 | 19 | 'glsr_get_review', 'glsr_get_reviews', | 
| 20 | 20 | 'glsr_log', | 
| 21 | 21 | ); | 
| 22 | - if( !in_array( $hook, $hooks ) || !function_exists( $hook ))return; | |
| 23 | -	add_filter( $hook, function() use( $hook, $args ) { | |
| 22 | + if( !in_array( $hook, $hooks ) || !function_exists( $hook ) )return; | |
| 23 | +	add_filter( $hook, function() use($hook, $args) { | |
| 24 | 24 | array_shift( $args ); // remove the fallback value | 
| 25 | 25 | return call_user_func_array( $hook, $args ); | 
| 26 | 26 | }); | 
| @@ -31,7 +31,7 @@ discard block | ||
| 31 | 31 | */ | 
| 32 | 32 |  function glsr( $alias = null ) { | 
| 33 | 33 | $app = \GeminiLabs\SiteReviews\Application::load(); | 
| 34 | - return !empty( $alias ) | |
| 34 | + return !empty($alias) | |
| 35 | 35 | ? $app->make( $alias ) | 
| 36 | 36 | : $app; | 
| 37 | 37 | } | 
| @@ -45,7 +45,7 @@ discard block | ||
| 45 | 45 | $result = array(); | 
| 46 | 46 |  	foreach( $array as $subarray ) { | 
| 47 | 47 | $subarray = (array)$subarray; | 
| 48 | - if( !isset( $subarray[$column] ))continue; | |
| 48 | + if( !isset($subarray[$column]) )continue; | |
| 49 | 49 | $result[] = $subarray[$column]; | 
| 50 | 50 | } | 
| 51 | 51 | return $result; | 
| @@ -56,19 +56,19 @@ discard block | ||
| 56 | 56 | */ | 
| 57 | 57 |  function glsr_calculate_ratings() { | 
| 58 | 58 | glsr( 'Controllers\AdminController' )->routerCountReviews( false ); | 
| 59 | - glsr_log()->info( __( 'Recalculated rating counts.', 'site-reviews' )); | |
| 59 | + glsr_log()->info( __( 'Recalculated rating counts.', 'site-reviews' ) ); | |
| 60 | 60 | } | 
| 61 | 61 | |
| 62 | 62 | /** | 
| 63 | 63 | * @return null|\GeminiLabs\SiteReviews\Review | 
| 64 | 64 | */ | 
| 65 | 65 |  function glsr_create_review( $reviewValues = array() ) { | 
| 66 | -	if( !is_array( $reviewValues )) { | |
| 66 | +	if( !is_array( $reviewValues ) ) { | |
| 67 | 67 | $reviewValues = array(); | 
| 68 | 68 | } | 
| 69 | 69 | $review = new \GeminiLabs\SiteReviews\Commands\CreateReview( $reviewValues ); | 
| 70 | 70 | $result = glsr( 'Database\ReviewManager' )->create( $review ); | 
| 71 | - return !empty( $result ) | |
| 71 | + return !empty($result) | |
| 72 | 72 | ? $result | 
| 73 | 73 | : null; | 
| 74 | 74 | } | 
| @@ -77,10 +77,10 @@ discard block | ||
| 77 | 77 | * @return \WP_Screen|object | 
| 78 | 78 | */ | 
| 79 | 79 |  function glsr_current_screen() { | 
| 80 | -	if( function_exists( 'get_current_screen' )) { | |
| 80 | +	if( function_exists( 'get_current_screen' ) ) { | |
| 81 | 81 | $screen = get_current_screen(); | 
| 82 | 82 | } | 
| 83 | - return empty( $screen ) | |
| 83 | + return empty($screen) | |
| 84 | 84 | ? (object)array_fill_keys( ['base', 'id', 'post_type'], null ) | 
| 85 | 85 | : $screen; | 
| 86 | 86 | } | 
| @@ -126,7 +126,7 @@ discard block | ||
| 126 | 126 | * @return \GeminiLabs\SiteReviews\Review|void | 
| 127 | 127 | */ | 
| 128 | 128 |  function glsr_get_review( $post_id ) { | 
| 129 | - if( !is_numeric( $post_id ))return; | |
| 129 | + if( !is_numeric( $post_id ) )return; | |
| 130 | 130 | $post = get_post( $post_id ); | 
| 131 | 131 |  	if( $post instanceof WP_Post ) { | 
| 132 | 132 | return glsr( 'Database\ReviewManager' )->single( $post ); | 
| @@ -138,7 +138,7 @@ discard block | ||
| 138 | 138 | * @todo document change of $reviews->reviews to $reviews->results | 
| 139 | 139 | */ | 
| 140 | 140 |  function glsr_get_reviews( $args = array() ) { | 
| 141 | -	if( !is_array( $args )) { | |
| 141 | +	if( !is_array( $args ) ) { | |
| 142 | 142 | $args = []; | 
| 143 | 143 | } | 
| 144 | 144 | return glsr( 'Database\ReviewManager' )->get( $args ); | 
| @@ -149,11 +149,11 @@ discard block | ||
| 149 | 149 | */ | 
| 150 | 150 |  function glsr_log() { | 
| 151 | 151 | $args = func_get_args(); | 
| 152 | - $context = isset( $args[1] ) | |
| 152 | + $context = isset($args[1]) | |
| 153 | 153 | ? $args[1] | 
| 154 | 154 | : []; | 
| 155 | 155 | $console = glsr( 'Modules\Console' ); | 
| 156 | - return !empty( $args ) | |
| 156 | + return !empty($args) | |
| 157 | 157 | ? $console->log( 'debug', $args[0], $context ) | 
| 158 | 158 | : $console; | 
| 159 | 159 | } | 
| @@ -19,7 +19,9 @@ discard block | ||
| 19 | 19 | 'glsr_get_review', 'glsr_get_reviews', | 
| 20 | 20 | 'glsr_log', | 
| 21 | 21 | ); | 
| 22 | - if( !in_array( $hook, $hooks ) || !function_exists( $hook ))return; | |
| 22 | +	if( !in_array( $hook, $hooks ) || !function_exists( $hook )) { | |
| 23 | + return; | |
| 24 | + } | |
| 23 | 25 |  	add_filter( $hook, function() use( $hook, $args ) { | 
| 24 | 26 | array_shift( $args ); // remove the fallback value | 
| 25 | 27 | return call_user_func_array( $hook, $args ); | 
| @@ -29,7 +31,8 @@ discard block | ||
| 29 | 31 | /** | 
| 30 | 32 | * @return mixed | 
| 31 | 33 | */ | 
| 32 | -function glsr( $alias = null ) { | |
| 34 | +function glsr( $alias = null ) | |
| 35 | +{ | |
| 33 | 36 | $app = \GeminiLabs\SiteReviews\Application::load(); | 
| 34 | 37 | return !empty( $alias ) | 
| 35 | 38 | ? $app->make( $alias ) | 
| @@ -41,11 +44,14 @@ discard block | ||
| 41 | 44 | * @param $column string | 
| 42 | 45 | * @return array | 
| 43 | 46 | */ | 
| 44 | -function glsr_array_column( array $array, $column ) { | |
| 47 | +function glsr_array_column( array $array, $column ) | |
| 48 | +{ | |
| 45 | 49 | $result = array(); | 
| 46 | 50 |  	foreach( $array as $subarray ) { | 
| 47 | 51 | $subarray = (array)$subarray; | 
| 48 | - if( !isset( $subarray[$column] ))continue; | |
| 52 | +		if( !isset( $subarray[$column] )) { | |
| 53 | + continue; | |
| 54 | + } | |
| 49 | 55 | $result[] = $subarray[$column]; | 
| 50 | 56 | } | 
| 51 | 57 | return $result; | 
| @@ -54,7 +60,8 @@ discard block | ||
| 54 | 60 | /** | 
| 55 | 61 | * @return void | 
| 56 | 62 | */ | 
| 57 | -function glsr_calculate_ratings() { | |
| 63 | +function glsr_calculate_ratings() | |
| 64 | +{ | |
| 58 | 65 | glsr( 'Controllers\AdminController' )->routerCountReviews( false ); | 
| 59 | 66 | glsr_log()->info( __( 'Recalculated rating counts.', 'site-reviews' )); | 
| 60 | 67 | } | 
| @@ -62,7 +69,8 @@ discard block | ||
| 62 | 69 | /** | 
| 63 | 70 | * @return null|\GeminiLabs\SiteReviews\Review | 
| 64 | 71 | */ | 
| 65 | -function glsr_create_review( $reviewValues = array() ) { | |
| 72 | +function glsr_create_review( $reviewValues = array() ) | |
| 73 | +{ | |
| 66 | 74 |  	if( !is_array( $reviewValues )) { | 
| 67 | 75 | $reviewValues = array(); | 
| 68 | 76 | } | 
| @@ -76,7 +84,8 @@ discard block | ||
| 76 | 84 | /** | 
| 77 | 85 | * @return \WP_Screen|object | 
| 78 | 86 | */ | 
| 79 | -function glsr_current_screen() { | |
| 87 | +function glsr_current_screen() | |
| 88 | +{ | |
| 80 | 89 |  	if( function_exists( 'get_current_screen' )) { | 
| 81 | 90 | $screen = get_current_screen(); | 
| 82 | 91 | } | 
| @@ -89,7 +98,8 @@ discard block | ||
| 89 | 98 | * @param mixed ...$vars | 
| 90 | 99 | * @return void | 
| 91 | 100 | */ | 
| 92 | -function glsr_debug( ...$vars ) { | |
| 101 | +function glsr_debug( ...$vars ) | |
| 102 | +{ | |
| 93 | 103 |  	if( count( $vars ) == 1 ) { | 
| 94 | 104 | $value = htmlspecialchars( print_r( $vars[0], true ), ENT_QUOTES, 'UTF-8' ); | 
| 95 | 105 | printf( '<div class="glsr-debug"><pre>%s</pre></div>', $value ); | 
| @@ -108,7 +118,8 @@ discard block | ||
| 108 | 118 | * @param mixed $fallback | 
| 109 | 119 | * @return string|array | 
| 110 | 120 | */ | 
| 111 | -function glsr_get_option( $path = '', $fallback = '' ) { | |
| 121 | +function glsr_get_option( $path = '', $fallback = '' ) | |
| 122 | +{ | |
| 112 | 123 | return is_string( $path ) | 
| 113 | 124 | ? glsr( 'Database\OptionManager' )->get( 'settings.'.$path, $fallback ) | 
| 114 | 125 | : $fallback; | 
| @@ -117,7 +128,8 @@ discard block | ||
| 117 | 128 | /** | 
| 118 | 129 | * @return array | 
| 119 | 130 | */ | 
| 120 | -function glsr_get_options() { | |
| 131 | +function glsr_get_options() | |
| 132 | +{ | |
| 121 | 133 | return glsr( 'Database\OptionManager' )->get( 'settings' ); | 
| 122 | 134 | } | 
| 123 | 135 | |
| @@ -125,8 +137,11 @@ discard block | ||
| 125 | 137 | * @param int $post_id | 
| 126 | 138 | * @return \GeminiLabs\SiteReviews\Review|void | 
| 127 | 139 | */ | 
| 128 | -function glsr_get_review( $post_id ) { | |
| 129 | - if( !is_numeric( $post_id ))return; | |
| 140 | +function glsr_get_review( $post_id ) | |
| 141 | +{ | |
| 142 | +	if( !is_numeric( $post_id )) { | |
| 143 | + return; | |
| 144 | + } | |
| 130 | 145 | $post = get_post( $post_id ); | 
| 131 | 146 |  	if( $post instanceof WP_Post ) { | 
| 132 | 147 | return glsr( 'Database\ReviewManager' )->single( $post ); | 
| @@ -137,7 +152,8 @@ discard block | ||
| 137 | 152 | * @return array | 
| 138 | 153 | * @todo document change of $reviews->reviews to $reviews->results | 
| 139 | 154 | */ | 
| 140 | -function glsr_get_reviews( $args = array() ) { | |
| 155 | +function glsr_get_reviews( $args = array() ) | |
| 156 | +{ | |
| 141 | 157 |  	if( !is_array( $args )) { | 
| 142 | 158 | $args = []; | 
| 143 | 159 | } | 
| @@ -147,7 +163,8 @@ discard block | ||
| 147 | 163 | /** | 
| 148 | 164 | * @return \GeminiLabs\SiteReviews\Modules\Console | 
| 149 | 165 | */ | 
| 150 | -function glsr_log() { | |
| 166 | +function glsr_log() | |
| 167 | +{ | |
| 151 | 168 | $args = func_get_args(); | 
| 152 | 169 | $context = isset( $args[1] ) | 
| 153 | 170 | ? $args[1] |