@@ -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 | } |
@@ -23,13 +23,13 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function getReviewCounts( $metaKey ) |
25 | 25 | { |
26 | - return (array) $this->db->get_results(" |
|
26 | + return (array)$this->db->get_results( " |
|
27 | 27 | SELECT m.meta_value AS name, COUNT(*) num_posts |
28 | 28 | FROM {$this->db->posts} AS p |
29 | 29 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
30 | 30 | WHERE p.post_type = '{$this->postType}' AND m.meta_key = '{$metaKey}' |
31 | 31 | GROUP BY name |
32 | - "); |
|
32 | + " ); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -38,14 +38,14 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function getReviewPostId( $metaReviewId ) |
40 | 40 | { |
41 | - $postId = $this->db->get_var(" |
|
41 | + $postId = $this->db->get_var( " |
|
42 | 42 | SELECT p.ID |
43 | 43 | FROM {$this->db->posts} AS p |
44 | 44 | INNER JOIN {$this->db->postmeta} AS pm ON p.ID = pm.post_id |
45 | 45 | WHERE p.post_type = '{$this->postType}' |
46 | 46 | AND pm.meta_key = 'review_id' |
47 | 47 | AND pm.meta_value = '{$metaReviewId}' |
48 | - "); |
|
48 | + " ); |
|
49 | 49 | return intval( $postId ); |
50 | 50 | } |
51 | 51 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | */ |
56 | 56 | public function getReviewIdsByType( $metaReviewType ) |
57 | 57 | { |
58 | - $query = $this->db->get_col(" |
|
58 | + $query = $this->db->get_col( " |
|
59 | 59 | SELECT m1.meta_value AS review_id |
60 | 60 | FROM {$this->db->posts} AS p |
61 | 61 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | AND m1.meta_key = 'review_id' |
65 | 65 | AND m2.meta_key = 'review_type' |
66 | 66 | AND m2.meta_value = '{$metaReviewType}' |
67 | - "); |
|
68 | - return array_keys( array_flip( $query )); |
|
67 | + " ); |
|
68 | + return array_keys( array_flip( $query ) ); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -78,13 +78,13 @@ discard block |
||
78 | 78 | $queryBuilder = glsr( QueryBuilder::class ); |
79 | 79 | $keys = $queryBuilder->buildSqlOr( $keys, "pm.meta_key = '%s'" ); |
80 | 80 | $status = $queryBuilder->buildSqlOr( $status, "p.post_status = '%s'" ); |
81 | - return $this->db->get_col(" |
|
81 | + return $this->db->get_col( " |
|
82 | 82 | SELECT DISTINCT pm.meta_value FROM {$this->db->postmeta} pm |
83 | 83 | LEFT JOIN {$this->db->posts} p ON p.ID = pm.post_id |
84 | 84 | WHERE p.post_type = '{$this->postType}' |
85 | 85 | AND ({$keys}) |
86 | 86 | AND ({$status}) |
87 | 87 | ORDER BY pm.meta_value |
88 | - "); |
|
88 | + " ); |
|
89 | 89 | } |
90 | 90 | } |
@@ -16,11 +16,11 @@ discard block |
||
16 | 16 | { |
17 | 17 | $queries = []; |
18 | 18 | foreach( $keys as $key ) { |
19 | - if( !array_key_exists( $key, $values ))continue; |
|
19 | + if( !array_key_exists( $key, $values ) )continue; |
|
20 | 20 | $methodName = glsr( Helper::class )->buildMethodName( $key, $prefix = __METHOD__ ); |
21 | - if( !method_exists( $this, $methodName ))continue; |
|
21 | + if( !method_exists( $this, $methodName ) )continue; |
|
22 | 22 | $query = call_user_func( [$this, $methodName], $values[$key] ); |
23 | - if( is_array( $query )) { |
|
23 | + if( is_array( $query ) ) { |
|
24 | 24 | $queries[] = $query; |
25 | 25 | } |
26 | 26 | } |
@@ -35,11 +35,11 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function buildSqlOr( $values, $sprintfFormat ) |
37 | 37 | { |
38 | - if( !is_array( $values )) { |
|
38 | + if( !is_array( $values ) ) { |
|
39 | 39 | $values = explode( ',', $values ); |
40 | 40 | } |
41 | - $values = array_filter( array_map( 'trim', (array)$values )); |
|
42 | - $values = array_map( function( $value ) use( $sprintfFormat ) { |
|
41 | + $values = array_filter( array_map( 'trim', (array)$values ) ); |
|
42 | + $values = array_map( function( $value ) use($sprintfFormat) { |
|
43 | 43 | return sprintf( $sprintfFormat, $value ); |
44 | 44 | }, $values ); |
45 | 45 | return implode( ' OR ', $values ); |
@@ -54,11 +54,11 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function filterSearchByTitle( $search, WP_Query $query ) |
56 | 56 | { |
57 | - if( empty( $search ) || empty( $query->get( 'search_terms' ))) { |
|
57 | + if( empty($search) || empty($query->get( 'search_terms' )) ) { |
|
58 | 58 | return $search; |
59 | 59 | } |
60 | 60 | global $wpdb; |
61 | - $n = empty( $query->get( 'exact' )) |
|
61 | + $n = empty($query->get( 'exact' )) |
|
62 | 62 | ? '%' |
63 | 63 | : ''; |
64 | 64 | $search = []; |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | public function getPaged( $isEnabled = true ) |
80 | 80 | { |
81 | 81 | $paged = $isEnabled |
82 | - ? intval( get_query_var( is_front_page() ? 'page' : Application::PAGED_QUERY_VAR )) |
|
82 | + ? intval( get_query_var( is_front_page() ? 'page' : Application::PAGED_QUERY_VAR ) ) |
|
83 | 83 | : 1; |
84 | 84 | return max( 1, $paged ); |
85 | 85 | } |
@@ -90,11 +90,11 @@ discard block |
||
90 | 90 | */ |
91 | 91 | protected function buildQueryAssignedTo( $value ) |
92 | 92 | { |
93 | - if( empty( $value ))return; |
|
93 | + if( empty($value) )return; |
|
94 | 94 | return [ |
95 | 95 | 'compare' => 'IN', |
96 | 96 | 'key' => 'assigned_to', |
97 | - 'value' => array_filter( array_map( 'trim', explode( ',', $value )), 'is_numeric' ), |
|
97 | + 'value' => array_filter( array_map( 'trim', explode( ',', $value ) ), 'is_numeric' ), |
|
98 | 98 | ]; |
99 | 99 | } |
100 | 100 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | */ |
105 | 105 | protected function buildQueryCategory( $value ) |
106 | 106 | { |
107 | - if( empty( $value ))return; |
|
107 | + if( empty($value) )return; |
|
108 | 108 | return [ |
109 | 109 | 'field' => 'term_id', |
110 | 110 | 'taxonomy' => Application::TAXONOMY, |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | */ |
119 | 119 | protected function buildQueryRating( $value ) |
120 | 120 | { |
121 | - if( !is_numeric( $value ) || !in_array( intval( $value ), range( 1, 5 )))return; |
|
121 | + if( !is_numeric( $value ) || !in_array( intval( $value ), range( 1, 5 ) ) )return; |
|
122 | 122 | return [ |
123 | 123 | 'compare' => '>=', |
124 | 124 | 'key' => 'rating', |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | */ |
133 | 133 | protected function buildQueryType( $value ) |
134 | 134 | { |
135 | - if( in_array( $value, ['','all'] ))return; |
|
135 | + if( in_array( $value, ['', 'all'] ) )return; |
|
136 | 136 | return [ |
137 | 137 | 'key' => 'review_type', |
138 | 138 | 'value' => $value, |
@@ -16,7 +16,7 @@ |
||
16 | 16 | 'author' => '', |
17 | 17 | 'avatar' => '', |
18 | 18 | 'content' => '', |
19 | - 'date' => get_date_from_gmt( gmdate( 'Y-m-d H:i:s' )), |
|
19 | + 'date' => get_date_from_gmt( gmdate( 'Y-m-d H:i:s' ) ), |
|
20 | 20 | 'email' => '', |
21 | 21 | 'ip_address' => '', |
22 | 22 | 'pinned' => false, |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | defined( 'WPINC' ) || die; |
4 | 4 | |
5 | -require_once( ABSPATH.WPINC.'/class-phpass.php' ); |
|
5 | +require_once(ABSPATH.WPINC.'/class-phpass.php'); |
|
6 | 6 | |
7 | 7 | spl_autoload_register( function( $className ) { |
8 | 8 | $namespaces = [ |
@@ -16,8 +16,8 @@ discard block |
||
16 | 16 | foreach( $namespaces as $prefix => $base_dir ) { |
17 | 17 | $len = strlen( $prefix ); |
18 | 18 | if( strncmp( $prefix, $className, $len ) !== 0 )continue; |
19 | - $file = $base_dir.str_replace( '\\', '/', substr( $className, $len )).'.php'; |
|
20 | - if( !file_exists( $file ))continue; |
|
19 | + $file = $base_dir.str_replace( '\\', '/', substr( $className, $len ) ).'.php'; |
|
20 | + if( !file_exists( $file ) )continue; |
|
21 | 21 | require $file; |
22 | 22 | break; |
23 | 23 | } |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public static function isPhpValid( $version = '' ) |
34 | 34 | { |
35 | - if( !empty( $version )) { |
|
36 | - static::normalize( array( 'php' => $version )); |
|
35 | + if( !empty($version) ) { |
|
36 | + static::normalize( array( 'php' => $version ) ); |
|
37 | 37 | } |
38 | 38 | return !version_compare( PHP_VERSION, static::$versions->php, '<' ); |
39 | 39 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public static function isValid( array $args = array() ) |
45 | 45 | { |
46 | - if( !empty( $args )) { |
|
46 | + if( !empty($args) ) { |
|
47 | 47 | static::normalize( $args ); |
48 | 48 | } |
49 | 49 | return static::isPhpValid() && static::isWpValid(); |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | public static function isWpValid( $version = '' ) |
57 | 57 | { |
58 | 58 | global $wp_version; |
59 | - if( !empty( $version )) { |
|
60 | - static::normalize( array( 'wordpress' => $version )); |
|
59 | + if( !empty($version) ) { |
|
60 | + static::normalize( array( 'wordpress' => $version ) ); |
|
61 | 61 | } |
62 | 62 | return !version_compare( $wp_version, static::$versions->wordpress, '<' ); |
63 | 63 | } |
@@ -68,14 +68,14 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public static function shouldDeactivate( $file, array $args = array() ) |
70 | 70 | { |
71 | - if( empty( static::$instance )) { |
|
71 | + if( empty(static::$instance) ) { |
|
72 | 72 | static::$file = realpath( $file ); |
73 | 73 | static::$instance = new static; |
74 | 74 | static::$versions = static::normalize( $args ); |
75 | 75 | } |
76 | 76 | if( !static::isValid() ) { |
77 | - add_action( 'activated_plugin', array( static::$instance, 'deactivate' )); |
|
78 | - add_action( 'admin_notices', array( static::$instance, 'deactivate' )); |
|
77 | + add_action( 'activated_plugin', array( static::$instance, 'deactivate' ) ); |
|
78 | + add_action( 'admin_notices', array( static::$instance, 'deactivate' ) ); |
|
79 | 79 | return true; |
80 | 80 | } |
81 | 81 | return false; |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | return (object)wp_parse_args( $args, array( |
106 | 106 | 'php' => static::MIN_PHP_VERSION, |
107 | 107 | 'wordpress' => static::MIN_WORDPRESS_VERSION, |
108 | - )); |
|
108 | + ) ); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | filter_input( INPUT_GET, 'plugin_status' ), |
118 | 118 | filter_input( INPUT_GET, 'paged' ), |
119 | 119 | filter_input( INPUT_GET, 's' ) |
120 | - ))); |
|
120 | + ) ) ); |
|
121 | 121 | exit; |
122 | 122 | } |
123 | 123 |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | |
24 | 24 | public function __construct( $input ) |
25 | 25 | { |
26 | - $this->ajaxRequest = isset( $input['ajax_request'] ); |
|
26 | + $this->ajaxRequest = isset($input['ajax_request']); |
|
27 | 27 | $this->assignedTo = is_numeric( $input['assign_to'] ) |
28 | 28 | ? $input['assign_to'] |
29 | 29 | : ''; |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | $this->rating = intval( $input['rating'] ); |
38 | 38 | $this->referrer = $input['_wp_http_referer']; |
39 | 39 | $this->request = $input; |
40 | - $this->terms = isset( $input['terms'] ); |
|
40 | + $this->terms = isset($input['terms']); |
|
41 | 41 | $this->title = sanitize_text_field( $input['title'] ); |
42 | 42 | } |
43 | 43 | } |