@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | { |
| 35 | 35 | $this->args = $args; |
| 36 | 36 | $this->reviews = glsr( Database::class )->getReviews( $args )->results; |
| 37 | - if( empty( $this->reviews ) && $this->isHidden( 'if_empty' ))return; |
|
| 37 | + if( empty($this->reviews) && $this->isHidden( 'if_empty' ) )return; |
|
| 38 | 38 | $this->rating = glsr( Rating::class )->getAverage( $this->reviews ); |
| 39 | 39 | $this->generateSchema(); |
| 40 | 40 | glsr_debug( $args ); |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | 'stars' => $this->buildStars(), |
| 48 | 48 | 'text' => $this->buildText(), |
| 49 | 49 | ], |
| 50 | - ]); |
|
| 50 | + ] ); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -55,16 +55,16 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | protected function buildPercentage() |
| 57 | 57 | { |
| 58 | - if( $this->isHidden( 'bars' ))return; |
|
| 58 | + if( $this->isHidden( 'bars' ) )return; |
|
| 59 | 59 | $range = range( Rating::MAX_RATING, 1 ); |
| 60 | - $percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->reviews )); |
|
| 61 | - $bars = array_reduce( $range, function( $carry, $level ) use( $percentages ) { |
|
| 60 | + $percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->reviews ) ); |
|
| 61 | + $bars = array_reduce( $range, function( $carry, $level ) use($percentages) { |
|
| 62 | 62 | $label = $this->buildPercentageLabel( $this->args['labels'][$level] ); |
| 63 | 63 | $background = $this->buildPercentageBackground( $percentages[$level] ); |
| 64 | 64 | $percent = $this->buildPercentagePercent( $percentages[$level] ); |
| 65 | 65 | return $carry.glsr( Builder::class )->div( $label.$background.$percent, [ |
| 66 | 66 | 'class' => 'glsr-bar', |
| 67 | - ]); |
|
| 67 | + ] ); |
|
| 68 | 68 | }); |
| 69 | 69 | return $this->wrap( 'percentage', $bars ); |
| 70 | 70 | } |
@@ -75,13 +75,13 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | protected function buildPercentageBackground( $percent ) |
| 77 | 77 | { |
| 78 | - $backgroundPercent = glsr( Builder::class )->span([ |
|
| 78 | + $backgroundPercent = glsr( Builder::class )->span( [ |
|
| 79 | 79 | 'class' => 'glsr-bar-background-percent', |
| 80 | 80 | 'style' => 'width:'.$percent, |
| 81 | - ]); |
|
| 81 | + ] ); |
|
| 82 | 82 | return glsr( Builder::class )->span( $backgroundPercent, [ |
| 83 | 83 | 'class' => 'glsr-bar-background', |
| 84 | - ]); |
|
| 84 | + ] ); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | { |
| 93 | 93 | return glsr( Builder::class )->span( $label, [ |
| 94 | 94 | 'class' => 'glsr-bar-label', |
| 95 | - ]); |
|
| 95 | + ] ); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | { |
| 104 | 104 | return glsr( Builder::class )->span( $percent, [ |
| 105 | 105 | 'class' => 'glsr-bar-percent', |
| 106 | - ]); |
|
| 106 | + ] ); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | protected function buildRating() |
| 113 | 113 | { |
| 114 | - if( $this->isHidden( 'rating' ))return; |
|
| 114 | + if( $this->isHidden( 'rating' ) )return; |
|
| 115 | 115 | return $this->wrap( 'rating', '<span>'.$this->rating.'</span>' ); |
| 116 | 116 | } |
| 117 | 117 | |
@@ -120,11 +120,11 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | protected function buildStars() |
| 122 | 122 | { |
| 123 | - if( $this->isHidden( 'stars' ))return; |
|
| 123 | + if( $this->isHidden( 'stars' ) )return; |
|
| 124 | 124 | $stars = glsr( Partial::class )->build( 'star-rating', [ |
| 125 | 125 | 'number' => count( $this->reviews ), |
| 126 | 126 | 'rating' => $this->rating, |
| 127 | - ]); |
|
| 127 | + ] ); |
|
| 128 | 128 | return $this->wrap( 'stars', $stars ); |
| 129 | 129 | } |
| 130 | 130 | |
@@ -133,9 +133,9 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | protected function buildText() |
| 135 | 135 | { |
| 136 | - if( $this->isHidden( 'summary' ))return; |
|
| 136 | + if( $this->isHidden( 'summary' ) )return; |
|
| 137 | 137 | $count = count( $this->reviews ); |
| 138 | - if( empty( $this->args['text'] )) { |
|
| 138 | + if( empty($this->args['text']) ) { |
|
| 139 | 139 | $this->args['text'] = _nx( |
| 140 | 140 | '{rating} out of {max} stars (based on %d review)', |
| 141 | 141 | '{rating} out of {max} stars (based on %d reviews)', |
@@ -144,8 +144,8 @@ discard block |
||
| 144 | 144 | 'site-reviews' |
| 145 | 145 | ); |
| 146 | 146 | } |
| 147 | - $summary = str_replace( ['{rating}','{max}'], [$this->rating, Rating::MAX_RATING], $this->args['text'] ); |
|
| 148 | - $summary = str_replace( ['%s','%d'], $count, $summary ); |
|
| 147 | + $summary = str_replace( ['{rating}', '{max}'], [$this->rating, Rating::MAX_RATING], $this->args['text'] ); |
|
| 148 | + $summary = str_replace( ['%s', '%d'], $count, $summary ); |
|
| 149 | 149 | return $this->wrap( 'text', '<span>'.$summary.'</span>' ); |
| 150 | 150 | } |
| 151 | 151 | |
@@ -154,8 +154,8 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | protected function generateSchema() |
| 156 | 156 | { |
| 157 | - if( !wp_validate_boolean( $this->args['schema'] ))return; |
|
| 158 | - glsr( Schema::class )->store( glsr( Schema::class )->buildSummary( $this->args )); |
|
| 157 | + if( !wp_validate_boolean( $this->args['schema'] ) )return; |
|
| 158 | + glsr( Schema::class )->store( glsr( Schema::class )->buildSummary( $this->args ) ); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
@@ -185,6 +185,6 @@ discard block |
||
| 185 | 185 | { |
| 186 | 186 | return glsr( Builder::class )->div( $value, [ |
| 187 | 187 | 'class' => 'glsr-summary-'.$key, |
| 188 | - ]); |
|
| 188 | + ] ); |
|
| 189 | 189 | } |
| 190 | 190 | } |