Passed
Push — master ( 0cc399...87713c )
by Paul
04:04
created
plugin/Controllers/AjaxController.php 2 patches
Indentation   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -14,169 +14,169 @@
 block discarded – undo
14 14
 
15 15
 class AjaxController extends Controller
16 16
 {
17
-    /**
18
-     * @return void
19
-     */
20
-    public function routerChangeStatus(array $request)
21
-    {
22
-        wp_send_json_success($this->execute(new ChangeStatus($request)));
23
-    }
17
+	/**
18
+	 * @return void
19
+	 */
20
+	public function routerChangeStatus(array $request)
21
+	{
22
+		wp_send_json_success($this->execute(new ChangeStatus($request)));
23
+	}
24 24
 
25
-    /**
26
-     * @return void
27
-     */
28
-    public function routerClearConsole()
29
-    {
30
-        glsr(AdminController::class)->routerClearConsole();
31
-        wp_send_json_success([
32
-            'console' => glsr(Console::class)->get(),
33
-            'notices' => glsr(Notice::class)->get(),
34
-        ]);
35
-    }
25
+	/**
26
+	 * @return void
27
+	 */
28
+	public function routerClearConsole()
29
+	{
30
+		glsr(AdminController::class)->routerClearConsole();
31
+		wp_send_json_success([
32
+			'console' => glsr(Console::class)->get(),
33
+			'notices' => glsr(Notice::class)->get(),
34
+		]);
35
+	}
36 36
 
37
-    /**
38
-     * @return void
39
-     */
40
-    public function routerCountReviews()
41
-    {
42
-        glsr(AdminController::class)->routerCountReviews();
43
-        wp_send_json_success([
44
-            'notices' => glsr(Notice::class)->get(),
45
-        ]);
46
-    }
37
+	/**
38
+	 * @return void
39
+	 */
40
+	public function routerCountReviews()
41
+	{
42
+		glsr(AdminController::class)->routerCountReviews();
43
+		wp_send_json_success([
44
+			'notices' => glsr(Notice::class)->get(),
45
+		]);
46
+	}
47 47
 
48
-    /**
49
-     * @return void
50
-     */
51
-    public function routerDismissNotice(array $request)
52
-    {
53
-        glsr(NoticeController::class)->routerDismissNotice($request);
54
-        wp_send_json_success();
55
-    }
48
+	/**
49
+	 * @return void
50
+	 */
51
+	public function routerDismissNotice(array $request)
52
+	{
53
+		glsr(NoticeController::class)->routerDismissNotice($request);
54
+		wp_send_json_success();
55
+	}
56 56
 
57
-    /**
58
-     * @return void
59
-     */
60
-    public function routerMceShortcode(array $request)
61
-    {
62
-        $shortcode = $request['shortcode'];
63
-        $response = false;
64
-        if (array_key_exists($shortcode, glsr()->mceShortcodes)) {
65
-            $data = glsr()->mceShortcodes[$shortcode];
66
-            if (!empty($data['errors'])) {
67
-                $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')];
68
-            }
69
-            $response = [
70
-                'body' => $data['fields'],
71
-                'close' => $data['btn_close'],
72
-                'ok' => $data['btn_okay'],
73
-                'shortcode' => $shortcode,
74
-                'title' => $data['title'],
75
-            ];
76
-        }
77
-        wp_send_json_success($response);
78
-    }
57
+	/**
58
+	 * @return void
59
+	 */
60
+	public function routerMceShortcode(array $request)
61
+	{
62
+		$shortcode = $request['shortcode'];
63
+		$response = false;
64
+		if (array_key_exists($shortcode, glsr()->mceShortcodes)) {
65
+			$data = glsr()->mceShortcodes[$shortcode];
66
+			if (!empty($data['errors'])) {
67
+				$data['btn_okay'] = [esc_html__('Okay', 'site-reviews')];
68
+			}
69
+			$response = [
70
+				'body' => $data['fields'],
71
+				'close' => $data['btn_close'],
72
+				'ok' => $data['btn_okay'],
73
+				'shortcode' => $shortcode,
74
+				'title' => $data['title'],
75
+			];
76
+		}
77
+		wp_send_json_success($response);
78
+	}
79 79
 
80
-    /**
81
-     * @return void
82
-     */
83
-    public function routerFetchConsole()
84
-    {
85
-        glsr(AdminController::class)->routerFetchConsole();
86
-        wp_send_json_success([
87
-            'console' => glsr(Console::class)->get(),
88
-            'notices' => glsr(Notice::class)->get(),
89
-        ]);
90
-    }
80
+	/**
81
+	 * @return void
82
+	 */
83
+	public function routerFetchConsole()
84
+	{
85
+		glsr(AdminController::class)->routerFetchConsole();
86
+		wp_send_json_success([
87
+			'console' => glsr(Console::class)->get(),
88
+			'notices' => glsr(Notice::class)->get(),
89
+		]);
90
+	}
91 91
 
92
-    /**
93
-     * @return void
94
-     */
95
-    public function routerSearchPosts(array $request)
96
-    {
97
-        $results = glsr(Database::class)->searchPosts($request['search']);
98
-        wp_send_json_success([
99
-            'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>',
100
-            'items' => $results,
101
-        ]);
102
-    }
92
+	/**
93
+	 * @return void
94
+	 */
95
+	public function routerSearchPosts(array $request)
96
+	{
97
+		$results = glsr(Database::class)->searchPosts($request['search']);
98
+		wp_send_json_success([
99
+			'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>',
100
+			'items' => $results,
101
+		]);
102
+	}
103 103
 
104
-    /**
105
-     * @return void
106
-     */
107
-    public function routerSearchTranslations(array $request)
108
-    {
109
-        if (empty($request['exclude'])) {
110
-            $request['exclude'] = [];
111
-        }
112
-        $results = glsr(Translation::class)
113
-            ->search($request['search'])
114
-            ->exclude()
115
-            ->exclude($request['exclude'])
116
-            ->renderResults();
117
-        wp_send_json_success([
118
-            'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>',
119
-            'items' => $results,
120
-        ]);
121
-    }
104
+	/**
105
+	 * @return void
106
+	 */
107
+	public function routerSearchTranslations(array $request)
108
+	{
109
+		if (empty($request['exclude'])) {
110
+			$request['exclude'] = [];
111
+		}
112
+		$results = glsr(Translation::class)
113
+			->search($request['search'])
114
+			->exclude()
115
+			->exclude($request['exclude'])
116
+			->renderResults();
117
+		wp_send_json_success([
118
+			'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>',
119
+			'items' => $results,
120
+		]);
121
+	}
122 122
 
123
-    /**
124
-     * @return void
125
-     */
126
-    public function routerSubmitReview(array $request)
127
-    {
128
-        $command = glsr(PublicController::class)->routerSubmitReview($request);
129
-        $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true)));
130
-        $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command);
131
-        $data = [
132
-            'errors' => glsr()->sessionGet($command->form_id.'errors', false),
133
-            'message' => glsr()->sessionGet($command->form_id.'message', ''),
134
-            'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false),
135
-            'redirect' => $redirect,
136
-        ];
137
-        if (false === $data['errors']) {
138
-            glsr()->sessionClear();
139
-            wp_send_json_success($data);
140
-        }
141
-        wp_send_json_error($data);
142
-    }
123
+	/**
124
+	 * @return void
125
+	 */
126
+	public function routerSubmitReview(array $request)
127
+	{
128
+		$command = glsr(PublicController::class)->routerSubmitReview($request);
129
+		$redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true)));
130
+		$redirect = apply_filters('site-reviews/review/redirect', $redirect, $command);
131
+		$data = [
132
+			'errors' => glsr()->sessionGet($command->form_id.'errors', false),
133
+			'message' => glsr()->sessionGet($command->form_id.'message', ''),
134
+			'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false),
135
+			'redirect' => $redirect,
136
+		];
137
+		if (false === $data['errors']) {
138
+			glsr()->sessionClear();
139
+			wp_send_json_success($data);
140
+		}
141
+		wp_send_json_error($data);
142
+	}
143 143
 
144
-    /**
145
-     * @return void
146
-     */
147
-    public function routerFetchPagedReviews(array $request)
148
-    {
149
-        $homePath = untrailingslashit(parse_url(home_url(), PHP_URL_PATH));
150
-        $urlPath = untrailingslashit(parse_url(Arr::get($request, 'url'), PHP_URL_PATH));
151
-        $urlQuery = [];
152
-        parse_str(parse_url(Arr::get($request, 'url'), PHP_URL_QUERY), $urlQuery);
153
-        $pagedUrl = $homePath === $urlPath
154
-            ? home_url()
155
-            : home_url($urlPath);
156
-        $args = [
157
-            'paged' => (int) Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1),
158
-            'pagedUrl' => trailingslashit($pagedUrl),
159
-            'pagination' => 'ajax',
160
-            'schema' => false,
161
-        ];
162
-        $atts = (array) json_decode(Arr::get($request, 'atts'));
163
-        $atts = glsr(SiteReviewsShortcode::class)->normalizeAtts($atts);
164
-        $html = glsr(SiteReviewsPartial::class)->build(wp_parse_args($args, $atts));
165
-        return wp_send_json_success([
166
-            'pagination' => $html->getPagination(),
167
-            'reviews' => $html->getReviews(),
168
-        ]);
169
-    }
144
+	/**
145
+	 * @return void
146
+	 */
147
+	public function routerFetchPagedReviews(array $request)
148
+	{
149
+		$homePath = untrailingslashit(parse_url(home_url(), PHP_URL_PATH));
150
+		$urlPath = untrailingslashit(parse_url(Arr::get($request, 'url'), PHP_URL_PATH));
151
+		$urlQuery = [];
152
+		parse_str(parse_url(Arr::get($request, 'url'), PHP_URL_QUERY), $urlQuery);
153
+		$pagedUrl = $homePath === $urlPath
154
+			? home_url()
155
+			: home_url($urlPath);
156
+		$args = [
157
+			'paged' => (int) Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1),
158
+			'pagedUrl' => trailingslashit($pagedUrl),
159
+			'pagination' => 'ajax',
160
+			'schema' => false,
161
+		];
162
+		$atts = (array) json_decode(Arr::get($request, 'atts'));
163
+		$atts = glsr(SiteReviewsShortcode::class)->normalizeAtts($atts);
164
+		$html = glsr(SiteReviewsPartial::class)->build(wp_parse_args($args, $atts));
165
+		return wp_send_json_success([
166
+			'pagination' => $html->getPagination(),
167
+			'reviews' => $html->getReviews(),
168
+		]);
169
+	}
170 170
 
171
-    /**
172
-     * @return void
173
-     */
174
-    public function routerTogglePinned(array $request)
175
-    {
176
-        $isPinned = $this->execute(new TogglePinned($request));
177
-        wp_send_json_success([
178
-            'notices' => glsr(Notice::class)->get(),
179
-            'pinned' => $isPinned,
180
-        ]);
181
-    }
171
+	/**
172
+	 * @return void
173
+	 */
174
+	public function routerTogglePinned(array $request)
175
+	{
176
+		$isPinned = $this->execute(new TogglePinned($request));
177
+		wp_send_json_success([
178
+			'notices' => glsr(Notice::class)->get(),
179
+			'pinned' => $isPinned,
180
+		]);
181
+	}
182 182
 }
Please login to merge, or discard this patch.
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -17,9 +17,9 @@  discard block
 block discarded – undo
17 17
     /**
18 18
      * @return void
19 19
      */
20
-    public function routerChangeStatus(array $request)
20
+    public function routerChangeStatus( array $request )
21 21
     {
22
-        wp_send_json_success($this->execute(new ChangeStatus($request)));
22
+        wp_send_json_success( $this->execute( new ChangeStatus( $request ) ) );
23 23
     }
24 24
 
25 25
     /**
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
      */
28 28
     public function routerClearConsole()
29 29
     {
30
-        glsr(AdminController::class)->routerClearConsole();
31
-        wp_send_json_success([
32
-            'console' => glsr(Console::class)->get(),
33
-            'notices' => glsr(Notice::class)->get(),
34
-        ]);
30
+        glsr( AdminController::class )->routerClearConsole();
31
+        wp_send_json_success( [
32
+            'console' => glsr( Console::class )->get(),
33
+            'notices' => glsr( Notice::class )->get(),
34
+        ] );
35 35
     }
36 36
 
37 37
     /**
@@ -39,32 +39,32 @@  discard block
 block discarded – undo
39 39
      */
40 40
     public function routerCountReviews()
41 41
     {
42
-        glsr(AdminController::class)->routerCountReviews();
43
-        wp_send_json_success([
44
-            'notices' => glsr(Notice::class)->get(),
45
-        ]);
42
+        glsr( AdminController::class )->routerCountReviews();
43
+        wp_send_json_success( [
44
+            'notices' => glsr( Notice::class )->get(),
45
+        ] );
46 46
     }
47 47
 
48 48
     /**
49 49
      * @return void
50 50
      */
51
-    public function routerDismissNotice(array $request)
51
+    public function routerDismissNotice( array $request )
52 52
     {
53
-        glsr(NoticeController::class)->routerDismissNotice($request);
53
+        glsr( NoticeController::class )->routerDismissNotice( $request );
54 54
         wp_send_json_success();
55 55
     }
56 56
 
57 57
     /**
58 58
      * @return void
59 59
      */
60
-    public function routerMceShortcode(array $request)
60
+    public function routerMceShortcode( array $request )
61 61
     {
62 62
         $shortcode = $request['shortcode'];
63 63
         $response = false;
64
-        if (array_key_exists($shortcode, glsr()->mceShortcodes)) {
64
+        if( array_key_exists( $shortcode, glsr()->mceShortcodes ) ) {
65 65
             $data = glsr()->mceShortcodes[$shortcode];
66
-            if (!empty($data['errors'])) {
67
-                $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')];
66
+            if( !empty($data['errors']) ) {
67
+                $data['btn_okay'] = [esc_html__( 'Okay', 'site-reviews' )];
68 68
             }
69 69
             $response = [
70 70
                 'body' => $data['fields'],
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
                 'title' => $data['title'],
75 75
             ];
76 76
         }
77
-        wp_send_json_success($response);
77
+        wp_send_json_success( $response );
78 78
     }
79 79
 
80 80
     /**
@@ -82,101 +82,101 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public function routerFetchConsole()
84 84
     {
85
-        glsr(AdminController::class)->routerFetchConsole();
86
-        wp_send_json_success([
87
-            'console' => glsr(Console::class)->get(),
88
-            'notices' => glsr(Notice::class)->get(),
89
-        ]);
85
+        glsr( AdminController::class )->routerFetchConsole();
86
+        wp_send_json_success( [
87
+            'console' => glsr( Console::class )->get(),
88
+            'notices' => glsr( Notice::class )->get(),
89
+        ] );
90 90
     }
91 91
 
92 92
     /**
93 93
      * @return void
94 94
      */
95
-    public function routerSearchPosts(array $request)
95
+    public function routerSearchPosts( array $request )
96 96
     {
97
-        $results = glsr(Database::class)->searchPosts($request['search']);
98
-        wp_send_json_success([
99
-            'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>',
97
+        $results = glsr( Database::class )->searchPosts( $request['search'] );
98
+        wp_send_json_success( [
99
+            'empty' => '<div>'.__( 'Nothing found.', 'site-reviews' ).'</div>',
100 100
             'items' => $results,
101
-        ]);
101
+        ] );
102 102
     }
103 103
 
104 104
     /**
105 105
      * @return void
106 106
      */
107
-    public function routerSearchTranslations(array $request)
107
+    public function routerSearchTranslations( array $request )
108 108
     {
109
-        if (empty($request['exclude'])) {
109
+        if( empty($request['exclude']) ) {
110 110
             $request['exclude'] = [];
111 111
         }
112
-        $results = glsr(Translation::class)
113
-            ->search($request['search'])
112
+        $results = glsr( Translation::class )
113
+            ->search( $request['search'] )
114 114
             ->exclude()
115
-            ->exclude($request['exclude'])
115
+            ->exclude( $request['exclude'] )
116 116
             ->renderResults();
117
-        wp_send_json_success([
118
-            'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>',
117
+        wp_send_json_success( [
118
+            'empty' => '<div>'.__( 'Nothing found.', 'site-reviews' ).'</div>',
119 119
             'items' => $results,
120
-        ]);
120
+        ] );
121 121
     }
122 122
 
123 123
     /**
124 124
      * @return void
125 125
      */
126
-    public function routerSubmitReview(array $request)
126
+    public function routerSubmitReview( array $request )
127 127
     {
128
-        $command = glsr(PublicController::class)->routerSubmitReview($request);
129
-        $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true)));
130
-        $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command);
128
+        $command = glsr( PublicController::class )->routerSubmitReview( $request );
129
+        $redirect = trim( strval( get_post_meta( $command->post_id, 'redirect_to', true ) ) );
130
+        $redirect = apply_filters( 'site-reviews/review/redirect', $redirect, $command );
131 131
         $data = [
132
-            'errors' => glsr()->sessionGet($command->form_id.'errors', false),
133
-            'message' => glsr()->sessionGet($command->form_id.'message', ''),
134
-            'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false),
132
+            'errors' => glsr()->sessionGet( $command->form_id.'errors', false ),
133
+            'message' => glsr()->sessionGet( $command->form_id.'message', '' ),
134
+            'recaptcha' => glsr()->sessionGet( $command->form_id.'recaptcha', false ),
135 135
             'redirect' => $redirect,
136 136
         ];
137
-        if (false === $data['errors']) {
137
+        if( false === $data['errors'] ) {
138 138
             glsr()->sessionClear();
139
-            wp_send_json_success($data);
139
+            wp_send_json_success( $data );
140 140
         }
141
-        wp_send_json_error($data);
141
+        wp_send_json_error( $data );
142 142
     }
143 143
 
144 144
     /**
145 145
      * @return void
146 146
      */
147
-    public function routerFetchPagedReviews(array $request)
147
+    public function routerFetchPagedReviews( array $request )
148 148
     {
149
-        $homePath = untrailingslashit(parse_url(home_url(), PHP_URL_PATH));
150
-        $urlPath = untrailingslashit(parse_url(Arr::get($request, 'url'), PHP_URL_PATH));
149
+        $homePath = untrailingslashit( parse_url( home_url(), PHP_URL_PATH ) );
150
+        $urlPath = untrailingslashit( parse_url( Arr::get( $request, 'url' ), PHP_URL_PATH ) );
151 151
         $urlQuery = [];
152
-        parse_str(parse_url(Arr::get($request, 'url'), PHP_URL_QUERY), $urlQuery);
152
+        parse_str( parse_url( Arr::get( $request, 'url' ), PHP_URL_QUERY ), $urlQuery );
153 153
         $pagedUrl = $homePath === $urlPath
154 154
             ? home_url()
155
-            : home_url($urlPath);
155
+            : home_url( $urlPath );
156 156
         $args = [
157
-            'paged' => (int) Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1),
158
-            'pagedUrl' => trailingslashit($pagedUrl),
157
+            'paged' => (int)Arr::get( $urlQuery, glsr()->constant( 'PAGED_QUERY_VAR' ), 1 ),
158
+            'pagedUrl' => trailingslashit( $pagedUrl ),
159 159
             'pagination' => 'ajax',
160 160
             'schema' => false,
161 161
         ];
162
-        $atts = (array) json_decode(Arr::get($request, 'atts'));
163
-        $atts = glsr(SiteReviewsShortcode::class)->normalizeAtts($atts);
164
-        $html = glsr(SiteReviewsPartial::class)->build(wp_parse_args($args, $atts));
165
-        return wp_send_json_success([
162
+        $atts = (array)json_decode( Arr::get( $request, 'atts' ) );
163
+        $atts = glsr( SiteReviewsShortcode::class )->normalizeAtts( $atts );
164
+        $html = glsr( SiteReviewsPartial::class )->build( wp_parse_args( $args, $atts ) );
165
+        return wp_send_json_success( [
166 166
             'pagination' => $html->getPagination(),
167 167
             'reviews' => $html->getReviews(),
168
-        ]);
168
+        ] );
169 169
     }
170 170
 
171 171
     /**
172 172
      * @return void
173 173
      */
174
-    public function routerTogglePinned(array $request)
174
+    public function routerTogglePinned( array $request )
175 175
     {
176
-        $isPinned = $this->execute(new TogglePinned($request));
177
-        wp_send_json_success([
178
-            'notices' => glsr(Notice::class)->get(),
176
+        $isPinned = $this->execute( new TogglePinned( $request ) );
177
+        wp_send_json_success( [
178
+            'notices' => glsr( Notice::class )->get(),
179 179
             'pinned' => $isPinned,
180
-        ]);
180
+        ] );
181 181
     }
182 182
 }
Please login to merge, or discard this patch.
plugin/Modules/Rating.php 2 patches
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -4,207 +4,207 @@
 block discarded – undo
4 4
 
5 5
 class Rating
6 6
 {
7
-    /**
8
-     * The more sure we are of the confidence interval (the higher the confidence level), the less
9
-     * precise the estimation will be as the margin for error will be higher.
10
-     * @see http://homepages.math.uic.edu/~bpower6/stat101/Confidence%20Intervals.pdf
11
-     * @see https://www.thecalculator.co/math/Confidence-Interval-Calculator-210.html
12
-     * @see https://www.youtube.com/watch?v=grodoLzThy4
13
-     * @see https://en.wikipedia.org/wiki/Standard_score
14
-     * @var array
15
-     */
16
-    const CONFIDENCE_LEVEL_Z_SCORES = [
17
-        50 => 0.67449,
18
-        70 => 1.04,
19
-        75 => 1.15035,
20
-        80 => 1.282,
21
-        85 => 1.44,
22
-        90 => 1.64485,
23
-        92 => 1.75,
24
-        95 => 1.95996,
25
-        96 => 2.05,
26
-        97 => 2.17009,
27
-        98 => 2.326,
28
-        99 => 2.57583,
29
-        '99.5' => 2.81,
30
-        '99.8' => 3.08,
31
-        '99.9' => 3.29053,
32
-    ];
7
+	/**
8
+	 * The more sure we are of the confidence interval (the higher the confidence level), the less
9
+	 * precise the estimation will be as the margin for error will be higher.
10
+	 * @see http://homepages.math.uic.edu/~bpower6/stat101/Confidence%20Intervals.pdf
11
+	 * @see https://www.thecalculator.co/math/Confidence-Interval-Calculator-210.html
12
+	 * @see https://www.youtube.com/watch?v=grodoLzThy4
13
+	 * @see https://en.wikipedia.org/wiki/Standard_score
14
+	 * @var array
15
+	 */
16
+	const CONFIDENCE_LEVEL_Z_SCORES = [
17
+		50 => 0.67449,
18
+		70 => 1.04,
19
+		75 => 1.15035,
20
+		80 => 1.282,
21
+		85 => 1.44,
22
+		90 => 1.64485,
23
+		92 => 1.75,
24
+		95 => 1.95996,
25
+		96 => 2.05,
26
+		97 => 2.17009,
27
+		98 => 2.326,
28
+		99 => 2.57583,
29
+		'99.5' => 2.81,
30
+		'99.8' => 3.08,
31
+		'99.9' => 3.29053,
32
+	];
33 33
 
34
-    /**
35
-     * @var int
36
-     */
37
-    const MAX_RATING = 5;
34
+	/**
35
+	 * @var int
36
+	 */
37
+	const MAX_RATING = 5;
38 38
 
39
-    /**
40
-     * @var int
41
-     */
42
-    const MIN_RATING = 1;
39
+	/**
40
+	 * @var int
41
+	 */
42
+	const MIN_RATING = 1;
43 43
 
44
-    /**
45
-     * @param int $roundBy
46
-     * @return float
47
-     */
48
-    public function getAverage(array $ratingCounts, $roundBy = 1)
49
-    {
50
-        $average = array_sum($ratingCounts);
51
-        if ($average > 0) {
52
-            $average = $this->getTotalSum($ratingCounts) / $average;
53
-        }
54
-        $roundedAverage = round($average, intval($roundBy));
55
-        return floatval(apply_filters('site-reviews/rating/average', $roundedAverage, $ratingCounts, $average));
56
-    }
44
+	/**
45
+	 * @param int $roundBy
46
+	 * @return float
47
+	 */
48
+	public function getAverage(array $ratingCounts, $roundBy = 1)
49
+	{
50
+		$average = array_sum($ratingCounts);
51
+		if ($average > 0) {
52
+			$average = $this->getTotalSum($ratingCounts) / $average;
53
+		}
54
+		$roundedAverage = round($average, intval($roundBy));
55
+		return floatval(apply_filters('site-reviews/rating/average', $roundedAverage, $ratingCounts, $average));
56
+	}
57 57
 
58
-    /**
59
-     * Get the lower bound for up/down ratings
60
-     * Method receives an up/down ratings array: [1, -1, -1, 1, 1, -1].
61
-     * @see http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
62
-     * @see https://news.ycombinator.com/item?id=10481507
63
-     * @see https://dataorigami.net/blogs/napkin-folding/79030467-an-algorithm-to-sort-top-comments
64
-     * @see http://julesjacobs.github.io/2015/08/17/bayesian-scoring-of-ratings.html
65
-     * @param int $confidencePercentage
66
-     * @return int|float
67
-     */
68
-    public function getLowerBound(array $upDownCounts = [0, 0], $confidencePercentage = 95)
69
-    {
70
-        $numRatings = array_sum($upDownCounts);
71
-        if ($numRatings < 1) {
72
-            return 0;
73
-        }
74
-        $z = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage];
75
-        $phat = 1 * $upDownCounts[1] / $numRatings;
76
-        return ($phat + $z * $z / (2 * $numRatings) - $z * sqrt(($phat * (1 - $phat) + $z * $z / (4 * $numRatings)) / $numRatings)) / (1 + $z * $z / $numRatings);
77
-    }
58
+	/**
59
+	 * Get the lower bound for up/down ratings
60
+	 * Method receives an up/down ratings array: [1, -1, -1, 1, 1, -1].
61
+	 * @see http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
62
+	 * @see https://news.ycombinator.com/item?id=10481507
63
+	 * @see https://dataorigami.net/blogs/napkin-folding/79030467-an-algorithm-to-sort-top-comments
64
+	 * @see http://julesjacobs.github.io/2015/08/17/bayesian-scoring-of-ratings.html
65
+	 * @param int $confidencePercentage
66
+	 * @return int|float
67
+	 */
68
+	public function getLowerBound(array $upDownCounts = [0, 0], $confidencePercentage = 95)
69
+	{
70
+		$numRatings = array_sum($upDownCounts);
71
+		if ($numRatings < 1) {
72
+			return 0;
73
+		}
74
+		$z = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage];
75
+		$phat = 1 * $upDownCounts[1] / $numRatings;
76
+		return ($phat + $z * $z / (2 * $numRatings) - $z * sqrt(($phat * (1 - $phat) + $z * $z / (4 * $numRatings)) / $numRatings)) / (1 + $z * $z / $numRatings);
77
+	}
78 78
 
79
-    /**
80
-     * @return int|float
81
-     */
82
-    public function getOverallPercentage(array $ratingCounts)
83
-    {
84
-        return round($this->getAverage($ratingCounts) * 100 / glsr()->constant('MAX_RATING', __CLASS__), 2);
85
-    }
79
+	/**
80
+	 * @return int|float
81
+	 */
82
+	public function getOverallPercentage(array $ratingCounts)
83
+	{
84
+		return round($this->getAverage($ratingCounts) * 100 / glsr()->constant('MAX_RATING', __CLASS__), 2);
85
+	}
86 86
 
87
-    /**
88
-     * @return array
89
-     */
90
-    public function getPercentages(array $ratingCounts)
91
-    {
92
-        $total = array_sum($ratingCounts);
93
-        foreach ($ratingCounts as $index => $count) {
94
-            if (empty($count)) {
95
-                continue;
96
-            }
97
-            $ratingCounts[$index] = $count / $total * 100;
98
-        }
99
-        return $this->getRoundedPercentages($ratingCounts);
100
-    }
87
+	/**
88
+	 * @return array
89
+	 */
90
+	public function getPercentages(array $ratingCounts)
91
+	{
92
+		$total = array_sum($ratingCounts);
93
+		foreach ($ratingCounts as $index => $count) {
94
+			if (empty($count)) {
95
+				continue;
96
+			}
97
+			$ratingCounts[$index] = $count / $total * 100;
98
+		}
99
+		return $this->getRoundedPercentages($ratingCounts);
100
+	}
101 101
 
102
-    /**
103
-     * @return float
104
-     */
105
-    public function getRanking(array $ratingCounts)
106
-    {
107
-        return floatval(apply_filters('site-reviews/rating/ranking',
108
-            $this->getRankingUsingImdb($ratingCounts),
109
-            $ratingCounts,
110
-            $this
111
-        ));
112
-    }
102
+	/**
103
+	 * @return float
104
+	 */
105
+	public function getRanking(array $ratingCounts)
106
+	{
107
+		return floatval(apply_filters('site-reviews/rating/ranking',
108
+			$this->getRankingUsingImdb($ratingCounts),
109
+			$ratingCounts,
110
+			$this
111
+		));
112
+	}
113 113
 
114
-    /**
115
-     * Get the bayesian ranking for an array of reviews
116
-     * This formula is the same one used by IMDB to rank their top 250 films.
117
-     * @see https://www.xkcd.com/937/
118
-     * @see https://districtdatalabs.silvrback.com/computing-a-bayesian-estimate-of-star-rating-means
119
-     * @see http://fulmicoton.com/posts/bayesian_rating/
120
-     * @see https://stats.stackexchange.com/questions/93974/is-there-an-equivalent-to-lower-bound-of-wilson-score-confidence-interval-for-va
121
-     * @param int $confidencePercentage
122
-     * @return int|float
123
-     */
124
-    public function getRankingUsingImdb(array $ratingCounts, $confidencePercentage = 70)
125
-    {
126
-        $avgRating = $this->getAverage($ratingCounts);
127
-        // Represents a prior (your prior opinion without data) for the average star rating. A higher prior also means a higher margin for error.
128
-        // This could also be the average score of all items instead of a fixed value.
129
-        $bayesMean = ($confidencePercentage / 100) * glsr()->constant('MAX_RATING', __CLASS__); // prior, 70% = 3.5
130
-        // Represents the number of ratings expected to begin observing a pattern that would put confidence in the prior.
131
-        $bayesMinimal = 10; // confidence
132
-        $numOfReviews = array_sum($ratingCounts);
133
-        return $avgRating > 0
134
-            ? (($bayesMinimal * $bayesMean) + ($avgRating * $numOfReviews)) / ($bayesMinimal + $numOfReviews)
135
-            : 0;
136
-    }
114
+	/**
115
+	 * Get the bayesian ranking for an array of reviews
116
+	 * This formula is the same one used by IMDB to rank their top 250 films.
117
+	 * @see https://www.xkcd.com/937/
118
+	 * @see https://districtdatalabs.silvrback.com/computing-a-bayesian-estimate-of-star-rating-means
119
+	 * @see http://fulmicoton.com/posts/bayesian_rating/
120
+	 * @see https://stats.stackexchange.com/questions/93974/is-there-an-equivalent-to-lower-bound-of-wilson-score-confidence-interval-for-va
121
+	 * @param int $confidencePercentage
122
+	 * @return int|float
123
+	 */
124
+	public function getRankingUsingImdb(array $ratingCounts, $confidencePercentage = 70)
125
+	{
126
+		$avgRating = $this->getAverage($ratingCounts);
127
+		// Represents a prior (your prior opinion without data) for the average star rating. A higher prior also means a higher margin for error.
128
+		// This could also be the average score of all items instead of a fixed value.
129
+		$bayesMean = ($confidencePercentage / 100) * glsr()->constant('MAX_RATING', __CLASS__); // prior, 70% = 3.5
130
+		// Represents the number of ratings expected to begin observing a pattern that would put confidence in the prior.
131
+		$bayesMinimal = 10; // confidence
132
+		$numOfReviews = array_sum($ratingCounts);
133
+		return $avgRating > 0
134
+			? (($bayesMinimal * $bayesMean) + ($avgRating * $numOfReviews)) / ($bayesMinimal + $numOfReviews)
135
+			: 0;
136
+	}
137 137
 
138
-    /**
139
-     * The quality of a 5 star rating depends not only on the average number of stars but also on
140
-     * the number of reviews. This method calculates the bayesian ranking of a page by its number
141
-     * of reviews and their rating.
142
-     * @see http://www.evanmiller.org/ranking-items-with-star-ratings.html
143
-     * @see https://stackoverflow.com/questions/1411199/what-is-a-better-way-to-sort-by-a-5-star-rating/1411268
144
-     * @see http://julesjacobs.github.io/2015/08/17/bayesian-scoring-of-ratings.html
145
-     * @param int $confidencePercentage
146
-     * @return float
147
-     */
148
-    public function getRankingUsingZScores(array $ratingCounts, $confidencePercentage = 90)
149
-    {
150
-        $ratingCountsSum = array_sum($ratingCounts) + glsr()->constant('MAX_RATING', __CLASS__);
151
-        $weight = $this->getWeight($ratingCounts, $ratingCountsSum);
152
-        $weightPow2 = $this->getWeight($ratingCounts, $ratingCountsSum, true);
153
-        $zScore = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage];
154
-        return $weight - $zScore * sqrt(($weightPow2 - pow($weight, 2)) / ($ratingCountsSum + 1));
155
-    }
138
+	/**
139
+	 * The quality of a 5 star rating depends not only on the average number of stars but also on
140
+	 * the number of reviews. This method calculates the bayesian ranking of a page by its number
141
+	 * of reviews and their rating.
142
+	 * @see http://www.evanmiller.org/ranking-items-with-star-ratings.html
143
+	 * @see https://stackoverflow.com/questions/1411199/what-is-a-better-way-to-sort-by-a-5-star-rating/1411268
144
+	 * @see http://julesjacobs.github.io/2015/08/17/bayesian-scoring-of-ratings.html
145
+	 * @param int $confidencePercentage
146
+	 * @return float
147
+	 */
148
+	public function getRankingUsingZScores(array $ratingCounts, $confidencePercentage = 90)
149
+	{
150
+		$ratingCountsSum = array_sum($ratingCounts) + glsr()->constant('MAX_RATING', __CLASS__);
151
+		$weight = $this->getWeight($ratingCounts, $ratingCountsSum);
152
+		$weightPow2 = $this->getWeight($ratingCounts, $ratingCountsSum, true);
153
+		$zScore = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage];
154
+		return $weight - $zScore * sqrt(($weightPow2 - pow($weight, 2)) / ($ratingCountsSum + 1));
155
+	}
156 156
 
157
-    /**
158
-     * @param int $target
159
-     * @return array
160
-     */
161
-    protected function getRoundedPercentages(array $percentages, $totalPercent = 100)
162
-    {
163
-        array_walk($percentages, function (&$percent, $index) {
164
-            $percent = [
165
-                'index' => $index,
166
-                'percent' => floor($percent),
167
-                'remainder' => fmod($percent, 1),
168
-            ];
169
-        });
170
-        $indexes = glsr_array_column($percentages, 'index');
171
-        $remainders = glsr_array_column($percentages, 'remainder');
172
-        array_multisort($remainders, SORT_DESC, SORT_STRING, $indexes, SORT_DESC, $percentages);
173
-        $i = 0;
174
-        if (array_sum(glsr_array_column($percentages, 'percent')) > 0) {
175
-            while (array_sum(glsr_array_column($percentages, 'percent')) < $totalPercent) {
176
-                ++$percentages[$i]['percent'];
177
-                ++$i;
178
-            }
179
-        }
180
-        array_multisort($indexes, SORT_DESC, $percentages);
181
-        return array_combine($indexes, glsr_array_column($percentages, 'percent'));
182
-    }
157
+	/**
158
+	 * @param int $target
159
+	 * @return array
160
+	 */
161
+	protected function getRoundedPercentages(array $percentages, $totalPercent = 100)
162
+	{
163
+		array_walk($percentages, function (&$percent, $index) {
164
+			$percent = [
165
+				'index' => $index,
166
+				'percent' => floor($percent),
167
+				'remainder' => fmod($percent, 1),
168
+			];
169
+		});
170
+		$indexes = glsr_array_column($percentages, 'index');
171
+		$remainders = glsr_array_column($percentages, 'remainder');
172
+		array_multisort($remainders, SORT_DESC, SORT_STRING, $indexes, SORT_DESC, $percentages);
173
+		$i = 0;
174
+		if (array_sum(glsr_array_column($percentages, 'percent')) > 0) {
175
+			while (array_sum(glsr_array_column($percentages, 'percent')) < $totalPercent) {
176
+				++$percentages[$i]['percent'];
177
+				++$i;
178
+			}
179
+		}
180
+		array_multisort($indexes, SORT_DESC, $percentages);
181
+		return array_combine($indexes, glsr_array_column($percentages, 'percent'));
182
+	}
183 183
 
184
-    /**
185
-     * @return int
186
-     */
187
-    protected function getTotalSum(array $ratingCounts)
188
-    {
189
-        return array_reduce(array_keys($ratingCounts), function ($carry, $index) use ($ratingCounts) {
190
-            return $carry + ($index * $ratingCounts[$index]);
191
-        });
192
-    }
184
+	/**
185
+	 * @return int
186
+	 */
187
+	protected function getTotalSum(array $ratingCounts)
188
+	{
189
+		return array_reduce(array_keys($ratingCounts), function ($carry, $index) use ($ratingCounts) {
190
+			return $carry + ($index * $ratingCounts[$index]);
191
+		});
192
+	}
193 193
 
194
-    /**
195
-     * @param int|float $ratingCountsSum
196
-     * @param bool $powerOf2
197
-     * @return float
198
-     */
199
-    protected function getWeight(array $ratingCounts, $ratingCountsSum, $powerOf2 = false)
200
-    {
201
-        return array_reduce(array_keys($ratingCounts),
202
-            function ($count, $rating) use ($ratingCounts, $ratingCountsSum, $powerOf2) {
203
-                $ratingLevel = $powerOf2
204
-                    ? pow($rating, 2)
205
-                    : $rating;
206
-                return $count + ($ratingLevel * ($ratingCounts[$rating] + 1)) / $ratingCountsSum;
207
-            }
208
-        );
209
-    }
194
+	/**
195
+	 * @param int|float $ratingCountsSum
196
+	 * @param bool $powerOf2
197
+	 * @return float
198
+	 */
199
+	protected function getWeight(array $ratingCounts, $ratingCountsSum, $powerOf2 = false)
200
+	{
201
+		return array_reduce(array_keys($ratingCounts),
202
+			function ($count, $rating) use ($ratingCounts, $ratingCountsSum, $powerOf2) {
203
+				$ratingLevel = $powerOf2
204
+					? pow($rating, 2)
205
+					: $rating;
206
+				return $count + ($ratingLevel * ($ratingCounts[$rating] + 1)) / $ratingCountsSum;
207
+			}
208
+		);
209
+	}
210 210
 }
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -45,14 +45,14 @@  discard block
 block discarded – undo
45 45
      * @param int $roundBy
46 46
      * @return float
47 47
      */
48
-    public function getAverage(array $ratingCounts, $roundBy = 1)
48
+    public function getAverage( array $ratingCounts, $roundBy = 1 )
49 49
     {
50
-        $average = array_sum($ratingCounts);
51
-        if ($average > 0) {
52
-            $average = $this->getTotalSum($ratingCounts) / $average;
50
+        $average = array_sum( $ratingCounts );
51
+        if( $average > 0 ) {
52
+            $average = $this->getTotalSum( $ratingCounts ) / $average;
53 53
         }
54
-        $roundedAverage = round($average, intval($roundBy));
55
-        return floatval(apply_filters('site-reviews/rating/average', $roundedAverage, $ratingCounts, $average));
54
+        $roundedAverage = round( $average, intval( $roundBy ) );
55
+        return floatval( apply_filters( 'site-reviews/rating/average', $roundedAverage, $ratingCounts, $average ) );
56 56
     }
57 57
 
58 58
     /**
@@ -65,50 +65,50 @@  discard block
 block discarded – undo
65 65
      * @param int $confidencePercentage
66 66
      * @return int|float
67 67
      */
68
-    public function getLowerBound(array $upDownCounts = [0, 0], $confidencePercentage = 95)
68
+    public function getLowerBound( array $upDownCounts = [0, 0], $confidencePercentage = 95 )
69 69
     {
70
-        $numRatings = array_sum($upDownCounts);
71
-        if ($numRatings < 1) {
70
+        $numRatings = array_sum( $upDownCounts );
71
+        if( $numRatings < 1 ) {
72 72
             return 0;
73 73
         }
74 74
         $z = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage];
75 75
         $phat = 1 * $upDownCounts[1] / $numRatings;
76
-        return ($phat + $z * $z / (2 * $numRatings) - $z * sqrt(($phat * (1 - $phat) + $z * $z / (4 * $numRatings)) / $numRatings)) / (1 + $z * $z / $numRatings);
76
+        return ($phat + $z * $z / (2 * $numRatings) - $z * sqrt( ($phat * (1 - $phat) + $z * $z / (4 * $numRatings)) / $numRatings )) / (1 + $z * $z / $numRatings);
77 77
     }
78 78
 
79 79
     /**
80 80
      * @return int|float
81 81
      */
82
-    public function getOverallPercentage(array $ratingCounts)
82
+    public function getOverallPercentage( array $ratingCounts )
83 83
     {
84
-        return round($this->getAverage($ratingCounts) * 100 / glsr()->constant('MAX_RATING', __CLASS__), 2);
84
+        return round( $this->getAverage( $ratingCounts ) * 100 / glsr()->constant( 'MAX_RATING', __CLASS__ ), 2 );
85 85
     }
86 86
 
87 87
     /**
88 88
      * @return array
89 89
      */
90
-    public function getPercentages(array $ratingCounts)
90
+    public function getPercentages( array $ratingCounts )
91 91
     {
92
-        $total = array_sum($ratingCounts);
93
-        foreach ($ratingCounts as $index => $count) {
94
-            if (empty($count)) {
92
+        $total = array_sum( $ratingCounts );
93
+        foreach( $ratingCounts as $index => $count ) {
94
+            if( empty($count) ) {
95 95
                 continue;
96 96
             }
97 97
             $ratingCounts[$index] = $count / $total * 100;
98 98
         }
99
-        return $this->getRoundedPercentages($ratingCounts);
99
+        return $this->getRoundedPercentages( $ratingCounts );
100 100
     }
101 101
 
102 102
     /**
103 103
      * @return float
104 104
      */
105
-    public function getRanking(array $ratingCounts)
105
+    public function getRanking( array $ratingCounts )
106 106
     {
107
-        return floatval(apply_filters('site-reviews/rating/ranking',
108
-            $this->getRankingUsingImdb($ratingCounts),
107
+        return floatval( apply_filters( 'site-reviews/rating/ranking',
108
+            $this->getRankingUsingImdb( $ratingCounts ),
109 109
             $ratingCounts,
110 110
             $this
111
-        ));
111
+        ) );
112 112
     }
113 113
 
114 114
     /**
@@ -121,15 +121,15 @@  discard block
 block discarded – undo
121 121
      * @param int $confidencePercentage
122 122
      * @return int|float
123 123
      */
124
-    public function getRankingUsingImdb(array $ratingCounts, $confidencePercentage = 70)
124
+    public function getRankingUsingImdb( array $ratingCounts, $confidencePercentage = 70 )
125 125
     {
126
-        $avgRating = $this->getAverage($ratingCounts);
126
+        $avgRating = $this->getAverage( $ratingCounts );
127 127
         // Represents a prior (your prior opinion without data) for the average star rating. A higher prior also means a higher margin for error.
128 128
         // This could also be the average score of all items instead of a fixed value.
129
-        $bayesMean = ($confidencePercentage / 100) * glsr()->constant('MAX_RATING', __CLASS__); // prior, 70% = 3.5
129
+        $bayesMean = ($confidencePercentage / 100) * glsr()->constant( 'MAX_RATING', __CLASS__ ); // prior, 70% = 3.5
130 130
         // Represents the number of ratings expected to begin observing a pattern that would put confidence in the prior.
131 131
         $bayesMinimal = 10; // confidence
132
-        $numOfReviews = array_sum($ratingCounts);
132
+        $numOfReviews = array_sum( $ratingCounts );
133 133
         return $avgRating > 0
134 134
             ? (($bayesMinimal * $bayesMean) + ($avgRating * $numOfReviews)) / ($bayesMinimal + $numOfReviews)
135 135
             : 0;
@@ -145,48 +145,48 @@  discard block
 block discarded – undo
145 145
      * @param int $confidencePercentage
146 146
      * @return float
147 147
      */
148
-    public function getRankingUsingZScores(array $ratingCounts, $confidencePercentage = 90)
148
+    public function getRankingUsingZScores( array $ratingCounts, $confidencePercentage = 90 )
149 149
     {
150
-        $ratingCountsSum = array_sum($ratingCounts) + glsr()->constant('MAX_RATING', __CLASS__);
151
-        $weight = $this->getWeight($ratingCounts, $ratingCountsSum);
152
-        $weightPow2 = $this->getWeight($ratingCounts, $ratingCountsSum, true);
150
+        $ratingCountsSum = array_sum( $ratingCounts ) + glsr()->constant( 'MAX_RATING', __CLASS__ );
151
+        $weight = $this->getWeight( $ratingCounts, $ratingCountsSum );
152
+        $weightPow2 = $this->getWeight( $ratingCounts, $ratingCountsSum, true );
153 153
         $zScore = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage];
154
-        return $weight - $zScore * sqrt(($weightPow2 - pow($weight, 2)) / ($ratingCountsSum + 1));
154
+        return $weight - $zScore * sqrt( ($weightPow2 - pow( $weight, 2 )) / ($ratingCountsSum + 1) );
155 155
     }
156 156
 
157 157
     /**
158 158
      * @param int $target
159 159
      * @return array
160 160
      */
161
-    protected function getRoundedPercentages(array $percentages, $totalPercent = 100)
161
+    protected function getRoundedPercentages( array $percentages, $totalPercent = 100 )
162 162
     {
163
-        array_walk($percentages, function (&$percent, $index) {
163
+        array_walk( $percentages, function( &$percent, $index ) {
164 164
             $percent = [
165 165
                 'index' => $index,
166
-                'percent' => floor($percent),
167
-                'remainder' => fmod($percent, 1),
166
+                'percent' => floor( $percent ),
167
+                'remainder' => fmod( $percent, 1 ),
168 168
             ];
169 169
         });
170
-        $indexes = glsr_array_column($percentages, 'index');
171
-        $remainders = glsr_array_column($percentages, 'remainder');
172
-        array_multisort($remainders, SORT_DESC, SORT_STRING, $indexes, SORT_DESC, $percentages);
170
+        $indexes = glsr_array_column( $percentages, 'index' );
171
+        $remainders = glsr_array_column( $percentages, 'remainder' );
172
+        array_multisort( $remainders, SORT_DESC, SORT_STRING, $indexes, SORT_DESC, $percentages );
173 173
         $i = 0;
174
-        if (array_sum(glsr_array_column($percentages, 'percent')) > 0) {
175
-            while (array_sum(glsr_array_column($percentages, 'percent')) < $totalPercent) {
174
+        if( array_sum( glsr_array_column( $percentages, 'percent' ) ) > 0 ) {
175
+            while( array_sum( glsr_array_column( $percentages, 'percent' ) ) < $totalPercent ) {
176 176
                 ++$percentages[$i]['percent'];
177 177
                 ++$i;
178 178
             }
179 179
         }
180
-        array_multisort($indexes, SORT_DESC, $percentages);
181
-        return array_combine($indexes, glsr_array_column($percentages, 'percent'));
180
+        array_multisort( $indexes, SORT_DESC, $percentages );
181
+        return array_combine( $indexes, glsr_array_column( $percentages, 'percent' ) );
182 182
     }
183 183
 
184 184
     /**
185 185
      * @return int
186 186
      */
187
-    protected function getTotalSum(array $ratingCounts)
187
+    protected function getTotalSum( array $ratingCounts )
188 188
     {
189
-        return array_reduce(array_keys($ratingCounts), function ($carry, $index) use ($ratingCounts) {
189
+        return array_reduce( array_keys( $ratingCounts ), function( $carry, $index ) use ($ratingCounts) {
190 190
             return $carry + ($index * $ratingCounts[$index]);
191 191
         });
192 192
     }
@@ -196,12 +196,12 @@  discard block
 block discarded – undo
196 196
      * @param bool $powerOf2
197 197
      * @return float
198 198
      */
199
-    protected function getWeight(array $ratingCounts, $ratingCountsSum, $powerOf2 = false)
199
+    protected function getWeight( array $ratingCounts, $ratingCountsSum, $powerOf2 = false )
200 200
     {
201
-        return array_reduce(array_keys($ratingCounts),
202
-            function ($count, $rating) use ($ratingCounts, $ratingCountsSum, $powerOf2) {
201
+        return array_reduce( array_keys( $ratingCounts ),
202
+            function( $count, $rating ) use ($ratingCounts, $ratingCountsSum, $powerOf2) {
203 203
                 $ratingLevel = $powerOf2
204
-                    ? pow($rating, 2)
204
+                    ? pow( $rating, 2 )
205 205
                     : $rating;
206 206
                 return $count + ($ratingLevel * ($ratingCounts[$rating] + 1)) / $ratingCountsSum;
207 207
             }
Please login to merge, or discard this patch.
plugin/Database/QueryBuilder.php 2 patches
Indentation   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -12,190 +12,190 @@
 block discarded – undo
12 12
 
13 13
 class QueryBuilder
14 14
 {
15
-    /**
16
-     * Build a WP_Query meta_query/tax_query.
17
-     * @return array
18
-     */
19
-    public function buildQuery(array $keys = [], array $values = [])
20
-    {
21
-        $queries = [];
22
-        foreach ($keys as $key) {
23
-            if (!array_key_exists($key, $values)) {
24
-                continue;
25
-            }
26
-            $methodName = Helper::buildMethodName($key, __FUNCTION__);
27
-            if (!method_exists($this, $methodName)) {
28
-                continue;
29
-            }
30
-            $query = call_user_func([$this, $methodName], $values[$key]);
31
-            if (is_array($query)) {
32
-                $queries[] = $query;
33
-            }
34
-        }
35
-        return $queries;
36
-    }
15
+	/**
16
+	 * Build a WP_Query meta_query/tax_query.
17
+	 * @return array
18
+	 */
19
+	public function buildQuery(array $keys = [], array $values = [])
20
+	{
21
+		$queries = [];
22
+		foreach ($keys as $key) {
23
+			if (!array_key_exists($key, $values)) {
24
+				continue;
25
+			}
26
+			$methodName = Helper::buildMethodName($key, __FUNCTION__);
27
+			if (!method_exists($this, $methodName)) {
28
+				continue;
29
+			}
30
+			$query = call_user_func([$this, $methodName], $values[$key]);
31
+			if (is_array($query)) {
32
+				$queries[] = $query;
33
+			}
34
+		}
35
+		return $queries;
36
+	}
37 37
 
38
-    /**
39
-     * @return string
40
-     */
41
-    public function buildSqlLines(array $values, array $conditions)
42
-    {
43
-        $string = '';
44
-        $values = array_filter($values);
45
-        foreach ($conditions as $key => $value) {
46
-            if (!isset($values[$key])) {
47
-                continue;
48
-            }
49
-            $values[$key] = implode(',', (array) $values[$key]);
50
-            $string.= Str::contains($value, '%s')
51
-                ? sprintf($value, strval($values[$key]))
52
-                : $value;
53
-        }
54
-        return $string;
55
-    }
38
+	/**
39
+	 * @return string
40
+	 */
41
+	public function buildSqlLines(array $values, array $conditions)
42
+	{
43
+		$string = '';
44
+		$values = array_filter($values);
45
+		foreach ($conditions as $key => $value) {
46
+			if (!isset($values[$key])) {
47
+				continue;
48
+			}
49
+			$values[$key] = implode(',', (array) $values[$key]);
50
+			$string.= Str::contains($value, '%s')
51
+				? sprintf($value, strval($values[$key]))
52
+				: $value;
53
+		}
54
+		return $string;
55
+	}
56 56
 
57
-    /**
58
-     * Build a SQL 'OR' string from an array.
59
-     * @param string|array $values
60
-     * @param string $sprintfFormat
61
-     * @return string
62
-     */
63
-    public function buildSqlOr($values, $sprintfFormat)
64
-    {
65
-        if (!is_array($values)) {
66
-            $values = explode(',', $values);
67
-        }
68
-        $values = array_filter(array_map('trim', (array) $values));
69
-        $values = array_map(function ($value) use ($sprintfFormat) {
70
-            return sprintf($sprintfFormat, $value);
71
-        }, $values);
72
-        return implode(' OR ', $values);
73
-    }
57
+	/**
58
+	 * Build a SQL 'OR' string from an array.
59
+	 * @param string|array $values
60
+	 * @param string $sprintfFormat
61
+	 * @return string
62
+	 */
63
+	public function buildSqlOr($values, $sprintfFormat)
64
+	{
65
+		if (!is_array($values)) {
66
+			$values = explode(',', $values);
67
+		}
68
+		$values = array_filter(array_map('trim', (array) $values));
69
+		$values = array_map(function ($value) use ($sprintfFormat) {
70
+			return sprintf($sprintfFormat, $value);
71
+		}, $values);
72
+		return implode(' OR ', $values);
73
+	}
74 74
 
75
-    /**
76
-     * Search SQL filter for matching against post title only.
77
-     * @see http://wordpress.stackexchange.com/a/11826/1685
78
-     * @param string $search
79
-     * @return string
80
-     * @filter posts_search
81
-     */
82
-    public function filterSearchByTitle($search, WP_Query $query)
83
-    {
84
-        if (empty($search) || empty($query->get('search_terms'))) {
85
-            return $search;
86
-        }
87
-        global $wpdb;
88
-        $n = empty($query->get('exact'))
89
-            ? '%'
90
-            : '';
91
-        $search = [];
92
-        foreach ((array) $query->get('search_terms') as $term) {
93
-            $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n);
94
-        }
95
-        if (!is_user_logged_in()) {
96
-            $search[] = "{$wpdb->posts}.post_password = ''";
97
-        }
98
-        return ' AND '.implode(' AND ', $search);
99
-    }
75
+	/**
76
+	 * Search SQL filter for matching against post title only.
77
+	 * @see http://wordpress.stackexchange.com/a/11826/1685
78
+	 * @param string $search
79
+	 * @return string
80
+	 * @filter posts_search
81
+	 */
82
+	public function filterSearchByTitle($search, WP_Query $query)
83
+	{
84
+		if (empty($search) || empty($query->get('search_terms'))) {
85
+			return $search;
86
+		}
87
+		global $wpdb;
88
+		$n = empty($query->get('exact'))
89
+			? '%'
90
+			: '';
91
+		$search = [];
92
+		foreach ((array) $query->get('search_terms') as $term) {
93
+			$search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n);
94
+		}
95
+		if (!is_user_logged_in()) {
96
+			$search[] = "{$wpdb->posts}.post_password = ''";
97
+		}
98
+		return ' AND '.implode(' AND ', $search);
99
+	}
100 100
 
101
-    /**
102
-     * Get the current page number from the global query.
103
-     * @param bool $isEnabled
104
-     * @return int
105
-     */
106
-    public function getPaged($isEnabled = true)
107
-    {
108
-        return $isEnabled
109
-            ? max(1, intval(filter_input(INPUT_GET, glsr()->constant('PAGED_QUERY_VAR'))))
110
-            : 1;
111
-    }
101
+	/**
102
+	 * Get the current page number from the global query.
103
+	 * @param bool $isEnabled
104
+	 * @return int
105
+	 */
106
+	public function getPaged($isEnabled = true)
107
+	{
108
+		return $isEnabled
109
+			? max(1, intval(filter_input(INPUT_GET, glsr()->constant('PAGED_QUERY_VAR'))))
110
+			: 1;
111
+	}
112 112
 
113
-    /**
114
-     * @param string $value
115
-     * @return void|array
116
-     */
117
-    protected function buildQueryAssignedTo($value)
118
-    {
119
-        if (!empty($value)) {
120
-            $postIds = Arr::convertStringToArray($value, 'is_numeric');
121
-            return [
122
-                'compare' => 'IN',
123
-                'key' => '_assigned_to',
124
-                'value' => glsr(Polylang::class)->getPostIds($postIds),
125
-            ];
126
-        }
127
-    }
113
+	/**
114
+	 * @param string $value
115
+	 * @return void|array
116
+	 */
117
+	protected function buildQueryAssignedTo($value)
118
+	{
119
+		if (!empty($value)) {
120
+			$postIds = Arr::convertStringToArray($value, 'is_numeric');
121
+			return [
122
+				'compare' => 'IN',
123
+				'key' => '_assigned_to',
124
+				'value' => glsr(Polylang::class)->getPostIds($postIds),
125
+			];
126
+		}
127
+	}
128 128
 
129
-    /**
130
-     * @param array $value
131
-     * @return void|array
132
-     */
133
-    protected function buildQueryCategory($value)
134
-    {
135
-        if (!empty($value)) {
136
-            return [
137
-                'field' => 'term_id',
138
-                'taxonomy' => Application::TAXONOMY,
139
-                'terms' => $value,
140
-            ];
141
-        }
142
-    }
129
+	/**
130
+	 * @param array $value
131
+	 * @return void|array
132
+	 */
133
+	protected function buildQueryCategory($value)
134
+	{
135
+		if (!empty($value)) {
136
+			return [
137
+				'field' => 'term_id',
138
+				'taxonomy' => Application::TAXONOMY,
139
+				'terms' => $value,
140
+			];
141
+		}
142
+	}
143 143
 
144
-    /**
145
-     * @param string $value
146
-     * @return void|array
147
-     */
148
-    protected function buildQueryEmail($value)
149
-    {
150
-        if (!empty($value)) {
151
-            return [
152
-                'key' => '_email',
153
-                'value' => $value,
154
-            ];
155
-        }
156
-    }
144
+	/**
145
+	 * @param string $value
146
+	 * @return void|array
147
+	 */
148
+	protected function buildQueryEmail($value)
149
+	{
150
+		if (!empty($value)) {
151
+			return [
152
+				'key' => '_email',
153
+				'value' => $value,
154
+			];
155
+		}
156
+	}
157 157
 
158
-    /**
159
-     * @param string $value
160
-     * @return void|array
161
-     */
162
-    protected function buildQueryIpAddress($value)
163
-    {
164
-        if (!empty($value)) {
165
-            return [
166
-                'key' => '_ip_address',
167
-                'value' => $value,
168
-            ];
169
-        }
170
-    }
158
+	/**
159
+	 * @param string $value
160
+	 * @return void|array
161
+	 */
162
+	protected function buildQueryIpAddress($value)
163
+	{
164
+		if (!empty($value)) {
165
+			return [
166
+				'key' => '_ip_address',
167
+				'value' => $value,
168
+			];
169
+		}
170
+	}
171 171
 
172
-    /**
173
-     * @param string $value
174
-     * @return void|array
175
-     */
176
-    protected function buildQueryRating($value)
177
-    {
178
-        if (is_numeric($value)
179
-            && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) {
180
-            return [
181
-                'compare' => '>=',
182
-                'key' => '_rating',
183
-                'value' => $value,
184
-            ];
185
-        }
186
-    }
172
+	/**
173
+	 * @param string $value
174
+	 * @return void|array
175
+	 */
176
+	protected function buildQueryRating($value)
177
+	{
178
+		if (is_numeric($value)
179
+			&& in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) {
180
+			return [
181
+				'compare' => '>=',
182
+				'key' => '_rating',
183
+				'value' => $value,
184
+			];
185
+		}
186
+	}
187 187
 
188
-    /**
189
-     * @param string $value
190
-     * @return void|array
191
-     */
192
-    protected function buildQueryType($value)
193
-    {
194
-        if (!in_array($value, ['', 'all'])) {
195
-            return [
196
-                'key' => '_review_type',
197
-                'value' => $value,
198
-            ];
199
-        }
200
-    }
188
+	/**
189
+	 * @param string $value
190
+	 * @return void|array
191
+	 */
192
+	protected function buildQueryType($value)
193
+	{
194
+		if (!in_array($value, ['', 'all'])) {
195
+			return [
196
+				'key' => '_review_type',
197
+				'value' => $value,
198
+			];
199
+		}
200
+	}
201 201
 }
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -16,19 +16,19 @@  discard block
 block discarded – undo
16 16
      * Build a WP_Query meta_query/tax_query.
17 17
      * @return array
18 18
      */
19
-    public function buildQuery(array $keys = [], array $values = [])
19
+    public function buildQuery( array $keys = [], array $values = [] )
20 20
     {
21 21
         $queries = [];
22
-        foreach ($keys as $key) {
23
-            if (!array_key_exists($key, $values)) {
22
+        foreach( $keys as $key ) {
23
+            if( !array_key_exists( $key, $values ) ) {
24 24
                 continue;
25 25
             }
26
-            $methodName = Helper::buildMethodName($key, __FUNCTION__);
27
-            if (!method_exists($this, $methodName)) {
26
+            $methodName = Helper::buildMethodName( $key, __FUNCTION__ );
27
+            if( !method_exists( $this, $methodName ) ) {
28 28
                 continue;
29 29
             }
30
-            $query = call_user_func([$this, $methodName], $values[$key]);
31
-            if (is_array($query)) {
30
+            $query = call_user_func( [$this, $methodName], $values[$key] );
31
+            if( is_array( $query ) ) {
32 32
                 $queries[] = $query;
33 33
             }
34 34
         }
@@ -38,17 +38,17 @@  discard block
 block discarded – undo
38 38
     /**
39 39
      * @return string
40 40
      */
41
-    public function buildSqlLines(array $values, array $conditions)
41
+    public function buildSqlLines( array $values, array $conditions )
42 42
     {
43 43
         $string = '';
44
-        $values = array_filter($values);
45
-        foreach ($conditions as $key => $value) {
46
-            if (!isset($values[$key])) {
44
+        $values = array_filter( $values );
45
+        foreach( $conditions as $key => $value ) {
46
+            if( !isset($values[$key]) ) {
47 47
                 continue;
48 48
             }
49
-            $values[$key] = implode(',', (array) $values[$key]);
50
-            $string.= Str::contains($value, '%s')
51
-                ? sprintf($value, strval($values[$key]))
49
+            $values[$key] = implode( ',', (array)$values[$key] );
50
+            $string .= Str::contains( $value, '%s' )
51
+                ? sprintf( $value, strval( $values[$key] ) )
52 52
                 : $value;
53 53
         }
54 54
         return $string;
@@ -60,16 +60,16 @@  discard block
 block discarded – undo
60 60
      * @param string $sprintfFormat
61 61
      * @return string
62 62
      */
63
-    public function buildSqlOr($values, $sprintfFormat)
63
+    public function buildSqlOr( $values, $sprintfFormat )
64 64
     {
65
-        if (!is_array($values)) {
66
-            $values = explode(',', $values);
65
+        if( !is_array( $values ) ) {
66
+            $values = explode( ',', $values );
67 67
         }
68
-        $values = array_filter(array_map('trim', (array) $values));
69
-        $values = array_map(function ($value) use ($sprintfFormat) {
70
-            return sprintf($sprintfFormat, $value);
71
-        }, $values);
72
-        return implode(' OR ', $values);
68
+        $values = array_filter( array_map( 'trim', (array)$values ) );
69
+        $values = array_map( function( $value ) use ($sprintfFormat) {
70
+            return sprintf( $sprintfFormat, $value );
71
+        }, $values );
72
+        return implode( ' OR ', $values );
73 73
     }
74 74
 
75 75
     /**
@@ -79,23 +79,23 @@  discard block
 block discarded – undo
79 79
      * @return string
80 80
      * @filter posts_search
81 81
      */
82
-    public function filterSearchByTitle($search, WP_Query $query)
82
+    public function filterSearchByTitle( $search, WP_Query $query )
83 83
     {
84
-        if (empty($search) || empty($query->get('search_terms'))) {
84
+        if( empty($search) || empty($query->get( 'search_terms' )) ) {
85 85
             return $search;
86 86
         }
87 87
         global $wpdb;
88
-        $n = empty($query->get('exact'))
88
+        $n = empty($query->get( 'exact' ))
89 89
             ? '%'
90 90
             : '';
91 91
         $search = [];
92
-        foreach ((array) $query->get('search_terms') as $term) {
93
-            $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n);
92
+        foreach( (array)$query->get( 'search_terms' ) as $term ) {
93
+            $search[] = $wpdb->prepare( "{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like( $term ).$n );
94 94
         }
95
-        if (!is_user_logged_in()) {
95
+        if( !is_user_logged_in() ) {
96 96
             $search[] = "{$wpdb->posts}.post_password = ''";
97 97
         }
98
-        return ' AND '.implode(' AND ', $search);
98
+        return ' AND '.implode( ' AND ', $search );
99 99
     }
100 100
 
101 101
     /**
@@ -103,10 +103,10 @@  discard block
 block discarded – undo
103 103
      * @param bool $isEnabled
104 104
      * @return int
105 105
      */
106
-    public function getPaged($isEnabled = true)
106
+    public function getPaged( $isEnabled = true )
107 107
     {
108 108
         return $isEnabled
109
-            ? max(1, intval(filter_input(INPUT_GET, glsr()->constant('PAGED_QUERY_VAR'))))
109
+            ? max( 1, intval( filter_input( INPUT_GET, glsr()->constant( 'PAGED_QUERY_VAR' ) ) ) )
110 110
             : 1;
111 111
     }
112 112
 
@@ -114,14 +114,14 @@  discard block
 block discarded – undo
114 114
      * @param string $value
115 115
      * @return void|array
116 116
      */
117
-    protected function buildQueryAssignedTo($value)
117
+    protected function buildQueryAssignedTo( $value )
118 118
     {
119
-        if (!empty($value)) {
120
-            $postIds = Arr::convertStringToArray($value, 'is_numeric');
119
+        if( !empty($value) ) {
120
+            $postIds = Arr::convertStringToArray( $value, 'is_numeric' );
121 121
             return [
122 122
                 'compare' => 'IN',
123 123
                 'key' => '_assigned_to',
124
-                'value' => glsr(Polylang::class)->getPostIds($postIds),
124
+                'value' => glsr( Polylang::class )->getPostIds( $postIds ),
125 125
             ];
126 126
         }
127 127
     }
@@ -130,9 +130,9 @@  discard block
 block discarded – undo
130 130
      * @param array $value
131 131
      * @return void|array
132 132
      */
133
-    protected function buildQueryCategory($value)
133
+    protected function buildQueryCategory( $value )
134 134
     {
135
-        if (!empty($value)) {
135
+        if( !empty($value) ) {
136 136
             return [
137 137
                 'field' => 'term_id',
138 138
                 'taxonomy' => Application::TAXONOMY,
@@ -145,9 +145,9 @@  discard block
 block discarded – undo
145 145
      * @param string $value
146 146
      * @return void|array
147 147
      */
148
-    protected function buildQueryEmail($value)
148
+    protected function buildQueryEmail( $value )
149 149
     {
150
-        if (!empty($value)) {
150
+        if( !empty($value) ) {
151 151
             return [
152 152
                 'key' => '_email',
153 153
                 'value' => $value,
@@ -159,9 +159,9 @@  discard block
 block discarded – undo
159 159
      * @param string $value
160 160
      * @return void|array
161 161
      */
162
-    protected function buildQueryIpAddress($value)
162
+    protected function buildQueryIpAddress( $value )
163 163
     {
164
-        if (!empty($value)) {
164
+        if( !empty($value) ) {
165 165
             return [
166 166
                 'key' => '_ip_address',
167 167
                 'value' => $value,
@@ -173,10 +173,10 @@  discard block
 block discarded – undo
173 173
      * @param string $value
174 174
      * @return void|array
175 175
      */
176
-    protected function buildQueryRating($value)
176
+    protected function buildQueryRating( $value )
177 177
     {
178
-        if (is_numeric($value)
179
-            && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) {
178
+        if( is_numeric( $value )
179
+            && in_array( intval( $value ), range( 1, glsr()->constant( 'MAX_RATING', Rating::class ) ) ) ) {
180 180
             return [
181 181
                 'compare' => '>=',
182 182
                 'key' => '_rating',
@@ -189,9 +189,9 @@  discard block
 block discarded – undo
189 189
      * @param string $value
190 190
      * @return void|array
191 191
      */
192
-    protected function buildQueryType($value)
192
+    protected function buildQueryType( $value )
193 193
     {
194
-        if (!in_array($value, ['', 'all'])) {
194
+        if( !in_array( $value, ['', 'all'] ) ) {
195 195
             return [
196 196
                 'key' => '_review_type',
197 197
                 'value' => $value,
Please login to merge, or discard this patch.