@@ -82,7 +82,7 @@ |
||
| 82 | 82 | { |
| 83 | 83 | $this->render()->div( glsr( Notice::class )->get(), [ |
| 84 | 84 | 'id' => 'glsr-notices', |
| 85 | - ]); |
|
| 85 | + ] ); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -130,8 +130,8 @@ |
||
| 130 | 130 | public function validateRequired( $attribute, $value ) |
| 131 | 131 | { |
| 132 | 132 | return is_null( $value ) |
| 133 | - || ( is_string( $value ) && trim( $value ) === '' ) |
|
| 134 | - || ( is_array( $value ) && count( $value ) < 1 ) |
|
| 133 | + || (is_string( $value ) && trim( $value ) === '') |
|
| 134 | + || (is_array( $value ) && count( $value ) < 1) |
|
| 135 | 135 | ? false |
| 136 | 136 | : true; |
| 137 | 137 | } |
@@ -15,10 +15,10 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | public function add( $type, $message, array $args = [] ) |
| 17 | 17 | { |
| 18 | - if( empty( array_filter( [$message, $type] )))return; |
|
| 18 | + if( empty(array_filter( [$message, $type] )) )return; |
|
| 19 | 19 | $args['message'] = $message; |
| 20 | 20 | $args['type'] = $type; |
| 21 | - add_settings_error( Application::ID, '', json_encode( $this->normalize( $args ))); |
|
| 21 | + add_settings_error( Application::ID, '', json_encode( $this->normalize( $args ) ) ); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -54,11 +54,11 @@ discard block |
||
| 54 | 54 | public function get() |
| 55 | 55 | { |
| 56 | 56 | $notices = array_map( 'unserialize', |
| 57 | - array_unique( array_map( 'serialize', get_settings_errors( Application::ID ))) |
|
| 57 | + array_unique( array_map( 'serialize', get_settings_errors( Application::ID ) ) ) |
|
| 58 | 58 | ); |
| 59 | - if( empty( $notices ))return; |
|
| 59 | + if( empty($notices) )return; |
|
| 60 | 60 | return array_reduce( $notices, function( $carry, $notice ) { |
| 61 | - return $carry.$this->buildNotice( json_decode( $notice['message'], true )); |
|
| 61 | + return $carry.$this->buildNotice( json_decode( $notice['message'], true ) ); |
|
| 62 | 62 | }); |
| 63 | 63 | } |
| 64 | 64 | |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | } |
| 80 | 80 | return glsr( Builder::class )->div( $messages, [ |
| 81 | 81 | 'class' => $class, |
| 82 | - ]); |
|
| 82 | + ] ); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -94,13 +94,13 @@ discard block |
||
| 94 | 94 | 'type' => '', |
| 95 | 95 | ]; |
| 96 | 96 | $args = shortcode_atts( $defaults, $args ); |
| 97 | - if( !in_array( $args['type'], ['error', 'warning', 'success'] )) { |
|
| 97 | + if( !in_array( $args['type'], ['error', 'warning', 'success'] ) ) { |
|
| 98 | 98 | $args['type'] = 'success'; |
| 99 | 99 | } |
| 100 | 100 | $args['messages'] = is_wp_error( $args['message'] ) |
| 101 | 101 | ? (array)$args['message']->get_error_message() |
| 102 | 102 | : (array)$args['message']; |
| 103 | - unset( $args['message'] ); |
|
| 103 | + unset($args['message']); |
|
| 104 | 104 | return $args; |
| 105 | 105 | } |
| 106 | 106 | } |
@@ -14,14 +14,14 @@ |
||
| 14 | 14 | { |
| 15 | 15 | $partial = glsr( Html::class )->buildTemplate( 'templates/reviews-form', [ |
| 16 | 16 | 'globals' => $args, |
| 17 | - ]); |
|
| 17 | + ] ); |
|
| 18 | 18 | $form = glsr( Builder::class )->form( $partial, [ |
| 19 | 19 | 'class' => 'glsr-form', |
| 20 | 20 | 'id' => $args['id'], |
| 21 | 21 | 'method' => 'post', |
| 22 | - ]); |
|
| 22 | + ] ); |
|
| 23 | 23 | return glsr( Builder::class )->div( $form, [ |
| 24 | 24 | 'class' => 'glsr-form-wrap '.$args['class'], |
| 25 | - ]); |
|
| 25 | + ] ); |
|
| 26 | 26 | } |
| 27 | 27 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | return glsr( Builder::class )->div( $this->buildSummary().$this->buildPercentageBars(), [ |
| 39 | 39 | 'class' => 'glsr-summary-wrap '.$args['class'], |
| 40 | 40 | 'id' => $args['id'], |
| 41 | - ]); |
|
| 41 | + ] ); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -51,20 +51,20 @@ discard block |
||
| 51 | 51 | $build = glsr( Builder::class ); |
| 52 | 52 | $label = $build->span( $this->args['labels'][$index], [ |
| 53 | 53 | 'class' => 'glsr-bar-label', |
| 54 | - ]); |
|
| 55 | - $barBackground = $build->span([ |
|
| 54 | + ] ); |
|
| 55 | + $barBackground = $build->span( [ |
|
| 56 | 56 | 'class' => 'glsr-bar-percent', |
| 57 | 57 | 'style' => 'width:'.$percent, |
| 58 | - ]); |
|
| 58 | + ] ); |
|
| 59 | 59 | $barPercent = $build->span( $barBackground, [ |
| 60 | 60 | 'class' => 'glsr-bar-background', |
| 61 | - ]); |
|
| 61 | + ] ); |
|
| 62 | 62 | $percent = $build->span( $percent, [ |
| 63 | 63 | 'class' => 'glsr-bar-count', |
| 64 | - ]); |
|
| 64 | + ] ); |
|
| 65 | 65 | return $build->div( $label.$barPercent.$percent, [ |
| 66 | 66 | 'class' => 'glsr-percentage-bar', |
| 67 | - ]); |
|
| 67 | + ] ); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -72,15 +72,15 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | protected function buildPercentageBars() |
| 74 | 74 | { |
| 75 | - if( in_array( 'bars', $this->args['hide'] ))return; |
|
| 76 | - $percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->reviews->results )); |
|
| 75 | + if( in_array( 'bars', $this->args['hide'] ) )return; |
|
| 76 | + $percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->reviews->results ) ); |
|
| 77 | 77 | $range = range( Rating::MAX_RATING, 1 ); |
| 78 | - $bars = array_reduce( $range, function( $carry, $index ) use( $percentages ) { |
|
| 78 | + $bars = array_reduce( $range, function( $carry, $index ) use($percentages) { |
|
| 79 | 79 | return $carry.$this->buildPercentageBar( intval( $index ), $percentages[$index] ); |
| 80 | 80 | }); |
| 81 | 81 | return glsr( Builder::class )->div( $bars, [ |
| 82 | 82 | 'class' => 'glsr-percentage-bars', |
| 83 | - ]); |
|
| 83 | + ] ); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | { |
| 91 | 91 | if( !$this->args['schema'] )return; |
| 92 | 92 | $schema = glsr( Schema::class ); |
| 93 | - $schema->store( $schema->buildSummary( $this->args )); |
|
| 93 | + $schema->store( $schema->buildSummary( $this->args ) ); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -99,10 +99,10 @@ discard block |
||
| 99 | 99 | protected function buildSummary() |
| 100 | 100 | { |
| 101 | 101 | $summary = $this->buildSummaryRating().$this->buildSummaryStars().$this->buildSummaryText(); |
| 102 | - if( empty( $summary ))return; |
|
| 102 | + if( empty($summary) )return; |
|
| 103 | 103 | return glsr( Builder::class )->div( $summary, [ |
| 104 | 104 | 'class' => 'glsr-summary', |
| 105 | - ]); |
|
| 105 | + ] ); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -110,10 +110,10 @@ discard block |
||
| 110 | 110 | */ |
| 111 | 111 | protected function buildSummaryRating() |
| 112 | 112 | { |
| 113 | - if( in_array( 'rating', $this->args['hide'] ))return; |
|
| 113 | + if( in_array( 'rating', $this->args['hide'] ) )return; |
|
| 114 | 114 | return glsr( Builder::class )->span( $this->rating, [ |
| 115 | 115 | 'class' => 'glsr-summary-rating', |
| 116 | - ]); |
|
| 116 | + ] ); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -121,13 +121,13 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | protected function buildSummaryStars() |
| 123 | 123 | { |
| 124 | - if( in_array( 'stars', $this->args['hide'] ))return; |
|
| 124 | + if( in_array( 'stars', $this->args['hide'] ) )return; |
|
| 125 | 125 | $stars = glsr( Html::class )->buildPartial( 'star-rating', [ |
| 126 | 126 | 'rating' => $this->rating, |
| 127 | - ]); |
|
| 127 | + ] ); |
|
| 128 | 128 | return glsr( Builder::class )->span( $stars, [ |
| 129 | 129 | 'class' => 'glsr-summary-stars', |
| 130 | - ]); |
|
| 130 | + ] ); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -135,9 +135,9 @@ discard block |
||
| 135 | 135 | */ |
| 136 | 136 | protected function buildSummaryText() |
| 137 | 137 | { |
| 138 | - if( in_array( 'summary', $this->args['hide'] ))return; |
|
| 138 | + if( in_array( 'summary', $this->args['hide'] ) )return; |
|
| 139 | 139 | $count = count( $this->reviews->results ); |
| 140 | - if( empty( $this->args['text'] )) { |
|
| 140 | + if( empty($this->args['text']) ) { |
|
| 141 | 141 | $this->args['text'] = _nx( |
| 142 | 142 | '{rating} out of {max} stars (based on %d review)', |
| 143 | 143 | '{rating} out of {max} stars (based on %d reviews)', |
@@ -147,9 +147,9 @@ discard block |
||
| 147 | 147 | ); |
| 148 | 148 | } |
| 149 | 149 | $summary = str_replace( |
| 150 | - ['{rating}','{max}'], [$this->rating, Rating::MAX_RATING], $this->args['text'] |
|
| 150 | + ['{rating}', '{max}'], [$this->rating, Rating::MAX_RATING], $this->args['text'] |
|
| 151 | 151 | ); |
| 152 | - return str_replace( ['%s','%d'], $count, $summary ); |
|
| 152 | + return str_replace( ['%s', '%d'], $count, $summary ); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -157,6 +157,6 @@ discard block |
||
| 157 | 157 | */ |
| 158 | 158 | protected function isHidden() |
| 159 | 159 | { |
| 160 | - return empty( $this->reviews->results ) && in_array( 'if_empty', $this->args['hide'] ); |
|
| 160 | + return empty($this->reviews->results) && in_array( 'if_empty', $this->args['hide'] ); |
|
| 161 | 161 | } |
| 162 | 162 | } |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | public function build( $partialPath, array $args = [] ) |
| 14 | 14 | { |
| 15 | 15 | $className = glsr( Helper::class )->buildClassName( $partialPath, 'Modules\Html\Partials' ); |
| 16 | - if( !class_exists( $className )) { |
|
| 16 | + if( !class_exists( $className ) ) { |
|
| 17 | 17 | glsr_log()->error( 'Partial missing: '.$className ); |
| 18 | 18 | return; |
| 19 | 19 | } |
@@ -50,9 +50,9 @@ discard block |
||
| 50 | 50 | { |
| 51 | 51 | $average = count( $reviews ); |
| 52 | 52 | if( $average > 0 ) { |
| 53 | - $average = round( $this->getTotal( $reviews ) / $average, intval( $roundBy )); |
|
| 53 | + $average = round( $this->getTotal( $reviews ) / $average, intval( $roundBy ) ); |
|
| 54 | 54 | } |
| 55 | - return floatval( apply_filters( 'site-reviews/rating/average', $average, $reviews )); |
|
| 55 | + return floatval( apply_filters( 'site-reviews/rating/average', $average, $reviews ) ); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -60,12 +60,12 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | public function getCounts( array $reviews ) |
| 62 | 62 | { |
| 63 | - $counts = array_fill_keys( [5,4,3,2,1], [] ); |
|
| 64 | - array_walk( $counts, function( &$count, $key ) use( $reviews ) { |
|
| 65 | - $count = count( array_filter( $reviews, function( $review ) use( $key ) { |
|
| 66 | - if( !isset( $review->rating ))return; |
|
| 63 | + $counts = array_fill_keys( [5, 4, 3, 2, 1], [] ); |
|
| 64 | + array_walk( $counts, function( &$count, $key ) use($reviews) { |
|
| 65 | + $count = count( array_filter( $reviews, function( $review ) use($key) { |
|
| 66 | + if( !isset($review->rating) )return; |
|
| 67 | 67 | return $review->rating == $key; |
| 68 | - })); |
|
| 68 | + }) ); |
|
| 69 | 69 | }); |
| 70 | 70 | return $counts; |
| 71 | 71 | } |
@@ -86,10 +86,10 @@ discard block |
||
| 86 | 86 | if( !$numRatings )return 0; |
| 87 | 87 | $positiveRatings = count( array_filter( $upDownRatings, function( $value ) { |
| 88 | 88 | return $value > 0; |
| 89 | - })); |
|
| 89 | + }) ); |
|
| 90 | 90 | $z = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage]; |
| 91 | 91 | $phat = 1 * $positiveRatings / $numRatings; |
| 92 | - return ( $phat + $z * $z / ( 2 * $numRatings ) - $z * sqrt(( $phat * ( 1 - $phat ) + $z * $z / ( 4 * $numRatings )) / $numRatings )) / ( 1 + $z * $z / $numRatings ); |
|
| 92 | + return ($phat + $z * $z / (2 * $numRatings) - $z * sqrt( ($phat * (1 - $phat) + $z * $z / (4 * $numRatings)) / $numRatings )) / (1 + $z * $z / $numRatings); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -108,9 +108,9 @@ discard block |
||
| 108 | 108 | public function getPercentages( array $reviews ) |
| 109 | 109 | { |
| 110 | 110 | $counts = $this->getCounts( $reviews ); |
| 111 | - array_walk( $counts, function( &$count, $rating ) use( $counts ) { |
|
| 111 | + array_walk( $counts, function( &$count, $rating ) use($counts) { |
|
| 112 | 112 | $total = array_sum( $counts ); |
| 113 | - $count = !empty( $total ) && !empty( $counts[$rating] ) |
|
| 113 | + $count = !empty($total) && !empty($counts[$rating]) |
|
| 114 | 114 | ? $counts[$rating] / array_sum( $counts ) * 100 |
| 115 | 115 | : 0; |
| 116 | 116 | }); |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | $this->getRankingUsingImdb( $reviews ), |
| 128 | 128 | $reviews, |
| 129 | 129 | $this |
| 130 | - )); |
|
| 130 | + ) ); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -157,11 +157,11 @@ discard block |
||
| 157 | 157 | $bayesMinimal = 10; // confidence |
| 158 | 158 | // Represents a prior (your prior opinion without data) for the average star rating. A higher prior also means a higher margin for error. |
| 159 | 159 | // This could also be the average score of all items instead of a fixed value. |
| 160 | - $bayesMean = ( $confidencePercentage / 100 ) * static::MAX_RATING; // prior, 70% = 3.5 |
|
| 160 | + $bayesMean = ($confidencePercentage / 100) * static::MAX_RATING; // prior, 70% = 3.5 |
|
| 161 | 161 | $numOfReviews = count( $reviews ); |
| 162 | 162 | $avgRating = $this->getAverage( $reviews ); |
| 163 | 163 | return $avgRating > 0 |
| 164 | - ? (( $bayesMinimal * $bayesMean ) + ( $avgRating * $numOfReviews )) / ( $bayesMinimal + $numOfReviews ) |
|
| 164 | + ? (($bayesMinimal * $bayesMean) + ($avgRating * $numOfReviews)) / ($bayesMinimal + $numOfReviews) |
|
| 165 | 165 | : 0; |
| 166 | 166 | } |
| 167 | 167 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | $weight = $this->getWeight( $ratingCounts, $ratingCountsSum ); |
| 183 | 183 | $weightPow2 = $this->getWeight( $ratingCounts, $ratingCountsSum, true ); |
| 184 | 184 | $zScore = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage]; |
| 185 | - return $weight - $zScore * sqrt(( $weightPow2 - pow( $weight, 2 )) / ( $ratingCountsSum + 1 )); |
|
| 185 | + return $weight - $zScore * sqrt( ($weightPow2 - pow( $weight, 2 )) / ($ratingCountsSum + 1) ); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -202,14 +202,14 @@ discard block |
||
| 202 | 202 | $remainders = array_column( $percentages, 'remainder' ); |
| 203 | 203 | array_multisort( $remainders, SORT_DESC, SORT_STRING, $indexes, SORT_DESC, $percentages ); |
| 204 | 204 | $i = 0; |
| 205 | - if( array_sum( array_column( $percentages, 'percent' )) > 0 ) { |
|
| 206 | - while( array_sum( array_column( $percentages, 'percent' )) < $target ) { |
|
| 205 | + if( array_sum( array_column( $percentages, 'percent' ) ) > 0 ) { |
|
| 206 | + while( array_sum( array_column( $percentages, 'percent' ) ) < $target ) { |
|
| 207 | 207 | $percentages[$i]['percent']++; |
| 208 | 208 | $i++; |
| 209 | 209 | } |
| 210 | 210 | } |
| 211 | 211 | array_multisort( $indexes, SORT_DESC, $percentages ); |
| 212 | - return array_combine( $indexes, array_column( $percentages, 'percent' )); |
|
| 212 | + return array_combine( $indexes, array_column( $percentages, 'percent' ) ); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -220,9 +220,9 @@ discard block |
||
| 220 | 220 | protected function getWeight( array $ratingCounts, $ratingCountsSum, $powerOf2 = false ) |
| 221 | 221 | { |
| 222 | 222 | return array_reduce( array_keys( $ratingCounts ), |
| 223 | - function( $count, $rating ) use( $ratingCounts, $ratingCountsSum, $powerOf2 ) { |
|
| 223 | + function( $count, $rating ) use($ratingCounts, $ratingCountsSum, $powerOf2) { |
|
| 224 | 224 | $ratingLevel = $powerOf2 ? pow( $rating, 2 ) : $rating; |
| 225 | - return $count + ( $ratingLevel * ( $ratingCounts[$rating] + 1 )) / $ratingCountsSum; |
|
| 225 | + return $count + ($ratingLevel * ($ratingCounts[$rating] + 1)) / $ratingCountsSum; |
|
| 226 | 226 | } |
| 227 | 227 | ); |
| 228 | 228 | } |
@@ -31,10 +31,10 @@ discard block |
||
| 31 | 31 | // 'is_test' => 1, |
| 32 | 32 | ]; |
| 33 | 33 | foreach( $_SERVER as $key => $value ) { |
| 34 | - if( is_array( $value ) || in_array( $key, ['HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW'] ))continue; |
|
| 34 | + if( is_array( $value ) || in_array( $key, ['HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW'] ) )continue; |
|
| 35 | 35 | $submission[$key] = $value; |
| 36 | 36 | } |
| 37 | - return $this->check( apply_filters( 'site-reviews/akismet/submission', $submission, $review )); |
|
| 37 | + return $this->check( apply_filters( 'site-reviews/akismet/submission', $submission, $review ) ); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -57,12 +57,12 @@ discard block |
||
| 57 | 57 | { |
| 58 | 58 | $query = []; |
| 59 | 59 | foreach( $data as $key => $value ) { |
| 60 | - if( is_array( $value ) || is_object( $value ))continue; |
|
| 60 | + if( is_array( $value ) || is_object( $value ) )continue; |
|
| 61 | 61 | if( $value === false ) { |
| 62 | 62 | $value = '0'; |
| 63 | 63 | } |
| 64 | 64 | $value = trim( $value ); |
| 65 | - if( !strlen( $value ))continue; |
|
| 65 | + if( !strlen( $value ) )continue; |
|
| 66 | 66 | $query[] = urlencode( $key ).'='.urlencode( $value ); |
| 67 | 67 | } |
| 68 | 68 | return implode( '&', $query ); |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | || !is_callable( ['Akismet', 'get_api_key'] ) |
| 78 | 78 | || !is_callable( ['Akismet', 'http_post'] ) |
| 79 | 79 | ? false |
| 80 | - : (bool) AkismetPlugin::get_api_key(); |
|
| 80 | + : (bool)AkismetPlugin::get_api_key(); |
|
| 81 | 81 | return apply_filters( 'site-reviews/akismet/is-active', $check ); |
| 82 | 82 | } |
| 83 | 83 | } |
@@ -10,7 +10,7 @@ |
||
| 10 | 10 | public function __construct( $input ) |
| 11 | 11 | { |
| 12 | 12 | $this->id = $input['id']; |
| 13 | - $this->pinned = isset( $input['pinned'] ) |
|
| 13 | + $this->pinned = isset($input['pinned']) |
|
| 14 | 14 | ? wp_validate_boolean( $input['pinned'] ) |
| 15 | 15 | : null; |
| 16 | 16 | } |