@@ -10,158 +10,158 @@ |
||
10 | 10 | |
11 | 11 | class EnqueueAdminAssets |
12 | 12 | { |
13 | - /** |
|
14 | - * @var array |
|
15 | - */ |
|
16 | - protected $pointers; |
|
13 | + /** |
|
14 | + * @var array |
|
15 | + */ |
|
16 | + protected $pointers; |
|
17 | 17 | |
18 | - /** |
|
19 | - * @return void |
|
20 | - */ |
|
21 | - public function handle(Command $command) |
|
22 | - { |
|
23 | - $this->generatePointers($command->pointers); |
|
24 | - $this->enqueueAssets(); |
|
25 | - $this->localizeAssets(); |
|
26 | - } |
|
18 | + /** |
|
19 | + * @return void |
|
20 | + */ |
|
21 | + public function handle(Command $command) |
|
22 | + { |
|
23 | + $this->generatePointers($command->pointers); |
|
24 | + $this->enqueueAssets(); |
|
25 | + $this->localizeAssets(); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * @return void |
|
30 | - */ |
|
31 | - public function enqueueAssets() |
|
32 | - { |
|
33 | - if (!$this->isCurrentScreen()) { |
|
34 | - return; |
|
35 | - } |
|
36 | - wp_enqueue_style( |
|
37 | - Application::ID, |
|
38 | - glsr()->url('assets/styles/'.Application::ID.'-admin.css'), |
|
39 | - [], |
|
40 | - glsr()->version |
|
41 | - ); |
|
42 | - wp_enqueue_script( |
|
43 | - Application::ID, |
|
44 | - glsr()->url('assets/scripts/'.Application::ID.'-admin.js'), |
|
45 | - $this->getDependencies(), |
|
46 | - glsr()->version, |
|
47 | - true |
|
48 | - ); |
|
49 | - if (!empty($this->pointers)) { |
|
50 | - wp_enqueue_style('wp-pointer'); |
|
51 | - wp_enqueue_script('wp-pointer'); |
|
52 | - } |
|
53 | - } |
|
28 | + /** |
|
29 | + * @return void |
|
30 | + */ |
|
31 | + public function enqueueAssets() |
|
32 | + { |
|
33 | + if (!$this->isCurrentScreen()) { |
|
34 | + return; |
|
35 | + } |
|
36 | + wp_enqueue_style( |
|
37 | + Application::ID, |
|
38 | + glsr()->url('assets/styles/'.Application::ID.'-admin.css'), |
|
39 | + [], |
|
40 | + glsr()->version |
|
41 | + ); |
|
42 | + wp_enqueue_script( |
|
43 | + Application::ID, |
|
44 | + glsr()->url('assets/scripts/'.Application::ID.'-admin.js'), |
|
45 | + $this->getDependencies(), |
|
46 | + glsr()->version, |
|
47 | + true |
|
48 | + ); |
|
49 | + if (!empty($this->pointers)) { |
|
50 | + wp_enqueue_style('wp-pointer'); |
|
51 | + wp_enqueue_script('wp-pointer'); |
|
52 | + } |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public function localizeAssets() |
|
59 | - { |
|
60 | - $variables = [ |
|
61 | - 'action' => Application::PREFIX.'action', |
|
62 | - 'addons' => [], |
|
63 | - 'ajaxurl' => admin_url('admin-ajax.php'), |
|
64 | - 'hideoptions' => [ |
|
65 | - 'site_reviews' => glsr(SiteReviewsShortcode::class)->getHideOptions(), |
|
66 | - 'site_reviews_form' => glsr(SiteReviewsFormShortcode::class)->getHideOptions(), |
|
67 | - 'site_reviews_summary' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(), |
|
68 | - ], |
|
69 | - 'nameprefix' => Application::ID, |
|
70 | - 'nonce' => [ |
|
71 | - 'change-status' => wp_create_nonce('change-status'), |
|
72 | - 'clear-console' => wp_create_nonce('clear-console'), |
|
73 | - 'count-reviews' => wp_create_nonce('count-reviews'), |
|
74 | - 'fetch-console' => wp_create_nonce('fetch-console'), |
|
75 | - 'mce-shortcode' => wp_create_nonce('mce-shortcode'), |
|
76 | - 'sync-reviews' => wp_create_nonce('sync-reviews'), |
|
77 | - 'toggle-pinned' => wp_create_nonce('toggle-pinned'), |
|
78 | - ], |
|
79 | - 'pointers' => $this->pointers, |
|
80 | - 'shortcodes' => [], |
|
81 | - 'tinymce' => [ |
|
82 | - 'glsr_shortcode' => glsr()->url('assets/scripts/mce-plugin.js'), |
|
83 | - ], |
|
84 | - ]; |
|
85 | - if (user_can_richedit()) { |
|
86 | - $variables['shortcodes'] = $this->localizeShortcodes(); |
|
87 | - } |
|
88 | - $variables = apply_filters('site-reviews/enqueue/admin/localize', $variables); |
|
89 | - wp_localize_script(Application::ID, 'GLSR', $variables); |
|
90 | - } |
|
55 | + /** |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public function localizeAssets() |
|
59 | + { |
|
60 | + $variables = [ |
|
61 | + 'action' => Application::PREFIX.'action', |
|
62 | + 'addons' => [], |
|
63 | + 'ajaxurl' => admin_url('admin-ajax.php'), |
|
64 | + 'hideoptions' => [ |
|
65 | + 'site_reviews' => glsr(SiteReviewsShortcode::class)->getHideOptions(), |
|
66 | + 'site_reviews_form' => glsr(SiteReviewsFormShortcode::class)->getHideOptions(), |
|
67 | + 'site_reviews_summary' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(), |
|
68 | + ], |
|
69 | + 'nameprefix' => Application::ID, |
|
70 | + 'nonce' => [ |
|
71 | + 'change-status' => wp_create_nonce('change-status'), |
|
72 | + 'clear-console' => wp_create_nonce('clear-console'), |
|
73 | + 'count-reviews' => wp_create_nonce('count-reviews'), |
|
74 | + 'fetch-console' => wp_create_nonce('fetch-console'), |
|
75 | + 'mce-shortcode' => wp_create_nonce('mce-shortcode'), |
|
76 | + 'sync-reviews' => wp_create_nonce('sync-reviews'), |
|
77 | + 'toggle-pinned' => wp_create_nonce('toggle-pinned'), |
|
78 | + ], |
|
79 | + 'pointers' => $this->pointers, |
|
80 | + 'shortcodes' => [], |
|
81 | + 'tinymce' => [ |
|
82 | + 'glsr_shortcode' => glsr()->url('assets/scripts/mce-plugin.js'), |
|
83 | + ], |
|
84 | + ]; |
|
85 | + if (user_can_richedit()) { |
|
86 | + $variables['shortcodes'] = $this->localizeShortcodes(); |
|
87 | + } |
|
88 | + $variables = apply_filters('site-reviews/enqueue/admin/localize', $variables); |
|
89 | + wp_localize_script(Application::ID, 'GLSR', $variables); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @return array |
|
94 | - */ |
|
95 | - protected function getDependencies() |
|
96 | - { |
|
97 | - $dependencies = apply_filters('site-reviews/enqueue/admin/dependencies', []); |
|
98 | - $dependencies = array_merge($dependencies, [ |
|
99 | - 'jquery', 'jquery-ui-sortable', 'underscore', 'wp-util', |
|
100 | - ]); |
|
101 | - return $dependencies; |
|
102 | - } |
|
92 | + /** |
|
93 | + * @return array |
|
94 | + */ |
|
95 | + protected function getDependencies() |
|
96 | + { |
|
97 | + $dependencies = apply_filters('site-reviews/enqueue/admin/dependencies', []); |
|
98 | + $dependencies = array_merge($dependencies, [ |
|
99 | + 'jquery', 'jquery-ui-sortable', 'underscore', 'wp-util', |
|
100 | + ]); |
|
101 | + return $dependencies; |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @return array |
|
106 | - */ |
|
107 | - protected function generatePointer(array $pointer) |
|
108 | - { |
|
109 | - return [ |
|
110 | - 'id' => $pointer['id'], |
|
111 | - 'options' => [ |
|
112 | - 'content' => '<h3>'.$pointer['title'].'</h3><p>'.$pointer['content'].'</p>', |
|
113 | - 'position' => $pointer['position'], |
|
114 | - ], |
|
115 | - 'screen' => $pointer['screen'], |
|
116 | - 'target' => $pointer['target'], |
|
117 | - ]; |
|
118 | - } |
|
104 | + /** |
|
105 | + * @return array |
|
106 | + */ |
|
107 | + protected function generatePointer(array $pointer) |
|
108 | + { |
|
109 | + return [ |
|
110 | + 'id' => $pointer['id'], |
|
111 | + 'options' => [ |
|
112 | + 'content' => '<h3>'.$pointer['title'].'</h3><p>'.$pointer['content'].'</p>', |
|
113 | + 'position' => $pointer['position'], |
|
114 | + ], |
|
115 | + 'screen' => $pointer['screen'], |
|
116 | + 'target' => $pointer['target'], |
|
117 | + ]; |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * @return void |
|
122 | - */ |
|
123 | - protected function generatePointers(array $pointers) |
|
124 | - { |
|
125 | - $dismissedPointers = get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true); |
|
126 | - $dismissedPointers = explode(',', (string) $dismissedPointers); |
|
127 | - $generatedPointers = []; |
|
128 | - foreach ($pointers as $pointer) { |
|
129 | - if ($pointer['screen'] != glsr_current_screen()->id) { |
|
130 | - continue; |
|
131 | - } |
|
132 | - if (in_array($pointer['id'], $dismissedPointers)) { |
|
133 | - continue; |
|
134 | - } |
|
135 | - $generatedPointers[] = $this->generatePointer($pointer); |
|
136 | - } |
|
137 | - $this->pointers = $generatedPointers; |
|
138 | - } |
|
120 | + /** |
|
121 | + * @return void |
|
122 | + */ |
|
123 | + protected function generatePointers(array $pointers) |
|
124 | + { |
|
125 | + $dismissedPointers = get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true); |
|
126 | + $dismissedPointers = explode(',', (string) $dismissedPointers); |
|
127 | + $generatedPointers = []; |
|
128 | + foreach ($pointers as $pointer) { |
|
129 | + if ($pointer['screen'] != glsr_current_screen()->id) { |
|
130 | + continue; |
|
131 | + } |
|
132 | + if (in_array($pointer['id'], $dismissedPointers)) { |
|
133 | + continue; |
|
134 | + } |
|
135 | + $generatedPointers[] = $this->generatePointer($pointer); |
|
136 | + } |
|
137 | + $this->pointers = $generatedPointers; |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * @return bool |
|
142 | - */ |
|
143 | - protected function isCurrentScreen() |
|
144 | - { |
|
145 | - $screen = glsr_current_screen(); |
|
146 | - return Application::POST_TYPE == $screen->post_type |
|
147 | - || 'dashboard' == $screen->id |
|
148 | - || 'plugins_page_'.Application::ID == $screen->id |
|
149 | - || 'post' == $screen->base |
|
150 | - || 'widgets' == $screen->id; |
|
151 | - } |
|
140 | + /** |
|
141 | + * @return bool |
|
142 | + */ |
|
143 | + protected function isCurrentScreen() |
|
144 | + { |
|
145 | + $screen = glsr_current_screen(); |
|
146 | + return Application::POST_TYPE == $screen->post_type |
|
147 | + || 'dashboard' == $screen->id |
|
148 | + || 'plugins_page_'.Application::ID == $screen->id |
|
149 | + || 'post' == $screen->base |
|
150 | + || 'widgets' == $screen->id; |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * @return array |
|
155 | - */ |
|
156 | - protected function localizeShortcodes() |
|
157 | - { |
|
158 | - $variables = []; |
|
159 | - foreach (glsr()->mceShortcodes as $tag => $args) { |
|
160 | - if (empty($args['required'])) { |
|
161 | - continue; |
|
162 | - } |
|
163 | - $variables[$tag] = $args['required']; |
|
164 | - } |
|
165 | - return $variables; |
|
166 | - } |
|
153 | + /** |
|
154 | + * @return array |
|
155 | + */ |
|
156 | + protected function localizeShortcodes() |
|
157 | + { |
|
158 | + $variables = []; |
|
159 | + foreach (glsr()->mceShortcodes as $tag => $args) { |
|
160 | + if (empty($args['required'])) { |
|
161 | + continue; |
|
162 | + } |
|
163 | + $variables[$tag] = $args['required']; |
|
164 | + } |
|
165 | + return $variables; |
|
166 | + } |
|
167 | 167 | } |
@@ -18,9 +18,9 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * @return void |
20 | 20 | */ |
21 | - public function handle(Command $command) |
|
21 | + public function handle( Command $command ) |
|
22 | 22 | { |
23 | - $this->generatePointers($command->pointers); |
|
23 | + $this->generatePointers( $command->pointers ); |
|
24 | 24 | $this->enqueueAssets(); |
25 | 25 | $this->localizeAssets(); |
26 | 26 | } |
@@ -30,25 +30,25 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function enqueueAssets() |
32 | 32 | { |
33 | - if (!$this->isCurrentScreen()) { |
|
33 | + if( !$this->isCurrentScreen() ) { |
|
34 | 34 | return; |
35 | 35 | } |
36 | 36 | wp_enqueue_style( |
37 | 37 | Application::ID, |
38 | - glsr()->url('assets/styles/'.Application::ID.'-admin.css'), |
|
38 | + glsr()->url( 'assets/styles/'.Application::ID.'-admin.css' ), |
|
39 | 39 | [], |
40 | 40 | glsr()->version |
41 | 41 | ); |
42 | 42 | wp_enqueue_script( |
43 | 43 | Application::ID, |
44 | - glsr()->url('assets/scripts/'.Application::ID.'-admin.js'), |
|
44 | + glsr()->url( 'assets/scripts/'.Application::ID.'-admin.js' ), |
|
45 | 45 | $this->getDependencies(), |
46 | 46 | glsr()->version, |
47 | 47 | true |
48 | 48 | ); |
49 | - if (!empty($this->pointers)) { |
|
50 | - wp_enqueue_style('wp-pointer'); |
|
51 | - wp_enqueue_script('wp-pointer'); |
|
49 | + if( !empty($this->pointers) ) { |
|
50 | + wp_enqueue_style( 'wp-pointer' ); |
|
51 | + wp_enqueue_script( 'wp-pointer' ); |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
@@ -60,33 +60,33 @@ discard block |
||
60 | 60 | $variables = [ |
61 | 61 | 'action' => Application::PREFIX.'action', |
62 | 62 | 'addons' => [], |
63 | - 'ajaxurl' => admin_url('admin-ajax.php'), |
|
63 | + 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
64 | 64 | 'hideoptions' => [ |
65 | - 'site_reviews' => glsr(SiteReviewsShortcode::class)->getHideOptions(), |
|
66 | - 'site_reviews_form' => glsr(SiteReviewsFormShortcode::class)->getHideOptions(), |
|
67 | - 'site_reviews_summary' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(), |
|
65 | + 'site_reviews' => glsr( SiteReviewsShortcode::class )->getHideOptions(), |
|
66 | + 'site_reviews_form' => glsr( SiteReviewsFormShortcode::class )->getHideOptions(), |
|
67 | + 'site_reviews_summary' => glsr( SiteReviewsSummaryShortcode::class )->getHideOptions(), |
|
68 | 68 | ], |
69 | 69 | 'nameprefix' => Application::ID, |
70 | 70 | 'nonce' => [ |
71 | - 'change-status' => wp_create_nonce('change-status'), |
|
72 | - 'clear-console' => wp_create_nonce('clear-console'), |
|
73 | - 'count-reviews' => wp_create_nonce('count-reviews'), |
|
74 | - 'fetch-console' => wp_create_nonce('fetch-console'), |
|
75 | - 'mce-shortcode' => wp_create_nonce('mce-shortcode'), |
|
76 | - 'sync-reviews' => wp_create_nonce('sync-reviews'), |
|
77 | - 'toggle-pinned' => wp_create_nonce('toggle-pinned'), |
|
71 | + 'change-status' => wp_create_nonce( 'change-status' ), |
|
72 | + 'clear-console' => wp_create_nonce( 'clear-console' ), |
|
73 | + 'count-reviews' => wp_create_nonce( 'count-reviews' ), |
|
74 | + 'fetch-console' => wp_create_nonce( 'fetch-console' ), |
|
75 | + 'mce-shortcode' => wp_create_nonce( 'mce-shortcode' ), |
|
76 | + 'sync-reviews' => wp_create_nonce( 'sync-reviews' ), |
|
77 | + 'toggle-pinned' => wp_create_nonce( 'toggle-pinned' ), |
|
78 | 78 | ], |
79 | 79 | 'pointers' => $this->pointers, |
80 | 80 | 'shortcodes' => [], |
81 | 81 | 'tinymce' => [ |
82 | - 'glsr_shortcode' => glsr()->url('assets/scripts/mce-plugin.js'), |
|
82 | + 'glsr_shortcode' => glsr()->url( 'assets/scripts/mce-plugin.js' ), |
|
83 | 83 | ], |
84 | 84 | ]; |
85 | - if (user_can_richedit()) { |
|
85 | + if( user_can_richedit() ) { |
|
86 | 86 | $variables['shortcodes'] = $this->localizeShortcodes(); |
87 | 87 | } |
88 | - $variables = apply_filters('site-reviews/enqueue/admin/localize', $variables); |
|
89 | - wp_localize_script(Application::ID, 'GLSR', $variables); |
|
88 | + $variables = apply_filters( 'site-reviews/enqueue/admin/localize', $variables ); |
|
89 | + wp_localize_script( Application::ID, 'GLSR', $variables ); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -94,17 +94,17 @@ discard block |
||
94 | 94 | */ |
95 | 95 | protected function getDependencies() |
96 | 96 | { |
97 | - $dependencies = apply_filters('site-reviews/enqueue/admin/dependencies', []); |
|
98 | - $dependencies = array_merge($dependencies, [ |
|
97 | + $dependencies = apply_filters( 'site-reviews/enqueue/admin/dependencies', [] ); |
|
98 | + $dependencies = array_merge( $dependencies, [ |
|
99 | 99 | 'jquery', 'jquery-ui-sortable', 'underscore', 'wp-util', |
100 | - ]); |
|
100 | + ] ); |
|
101 | 101 | return $dependencies; |
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
105 | 105 | * @return array |
106 | 106 | */ |
107 | - protected function generatePointer(array $pointer) |
|
107 | + protected function generatePointer( array $pointer ) |
|
108 | 108 | { |
109 | 109 | return [ |
110 | 110 | 'id' => $pointer['id'], |
@@ -120,19 +120,19 @@ discard block |
||
120 | 120 | /** |
121 | 121 | * @return void |
122 | 122 | */ |
123 | - protected function generatePointers(array $pointers) |
|
123 | + protected function generatePointers( array $pointers ) |
|
124 | 124 | { |
125 | - $dismissedPointers = get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true); |
|
126 | - $dismissedPointers = explode(',', (string) $dismissedPointers); |
|
125 | + $dismissedPointers = get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ); |
|
126 | + $dismissedPointers = explode( ',', (string)$dismissedPointers ); |
|
127 | 127 | $generatedPointers = []; |
128 | - foreach ($pointers as $pointer) { |
|
129 | - if ($pointer['screen'] != glsr_current_screen()->id) { |
|
128 | + foreach( $pointers as $pointer ) { |
|
129 | + if( $pointer['screen'] != glsr_current_screen()->id ) { |
|
130 | 130 | continue; |
131 | 131 | } |
132 | - if (in_array($pointer['id'], $dismissedPointers)) { |
|
132 | + if( in_array( $pointer['id'], $dismissedPointers ) ) { |
|
133 | 133 | continue; |
134 | 134 | } |
135 | - $generatedPointers[] = $this->generatePointer($pointer); |
|
135 | + $generatedPointers[] = $this->generatePointer( $pointer ); |
|
136 | 136 | } |
137 | 137 | $this->pointers = $generatedPointers; |
138 | 138 | } |
@@ -156,8 +156,8 @@ discard block |
||
156 | 156 | protected function localizeShortcodes() |
157 | 157 | { |
158 | 158 | $variables = []; |
159 | - foreach (glsr()->mceShortcodes as $tag => $args) { |
|
160 | - if (empty($args['required'])) { |
|
159 | + foreach( glsr()->mceShortcodes as $tag => $args ) { |
|
160 | + if( empty($args['required']) ) { |
|
161 | 161 | continue; |
162 | 162 | } |
163 | 163 | $variables[$tag] = $args['required']; |
@@ -4,207 +4,207 @@ |
||
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 | } |
@@ -45,14 +45,14 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -8,23 +8,23 @@ discard block |
||
8 | 8 | |
9 | 9 | class SqlQueries |
10 | 10 | { |
11 | - protected $db; |
|
12 | - protected $postType; |
|
11 | + protected $db; |
|
12 | + protected $postType; |
|
13 | 13 | |
14 | - public function __construct() |
|
15 | - { |
|
16 | - global $wpdb; |
|
17 | - $this->db = $wpdb; |
|
18 | - $this->postType = Application::POST_TYPE; |
|
19 | - } |
|
14 | + public function __construct() |
|
15 | + { |
|
16 | + global $wpdb; |
|
17 | + $this->db = $wpdb; |
|
18 | + $this->postType = Application::POST_TYPE; |
|
19 | + } |
|
20 | 20 | |
21 | - /** |
|
22 | - * @param string $metaReviewId |
|
23 | - * @return int |
|
24 | - */ |
|
25 | - public function getPostIdFromReviewId($metaReviewId) |
|
26 | - { |
|
27 | - $postId = $this->db->get_var(" |
|
21 | + /** |
|
22 | + * @param string $metaReviewId |
|
23 | + * @return int |
|
24 | + */ |
|
25 | + public function getPostIdFromReviewId($metaReviewId) |
|
26 | + { |
|
27 | + $postId = $this->db->get_var(" |
|
28 | 28 | SELECT p.ID |
29 | 29 | FROM {$this->db->posts} AS p |
30 | 30 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
@@ -32,17 +32,17 @@ discard block |
||
32 | 32 | AND m.meta_key = '_review_id' |
33 | 33 | AND m.meta_value = '{$metaReviewId}' |
34 | 34 | "); |
35 | - return intval($postId); |
|
36 | - } |
|
35 | + return intval($postId); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param int $lastPostId |
|
40 | - * @param int $limit |
|
41 | - * @return array |
|
42 | - */ |
|
43 | - public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500) |
|
44 | - { |
|
45 | - return (array) $this->db->get_results(" |
|
38 | + /** |
|
39 | + * @param int $lastPostId |
|
40 | + * @param int $limit |
|
41 | + * @return array |
|
42 | + */ |
|
43 | + public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500) |
|
44 | + { |
|
45 | + return (array) $this->db->get_results(" |
|
46 | 46 | SELECT DISTINCT p.ID, m1.meta_value AS rating, m2.meta_value AS type |
47 | 47 | FROM {$this->db->posts} AS p |
48 | 48 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -57,17 +57,17 @@ discard block |
||
57 | 57 | ORDER By p.ID ASC |
58 | 58 | LIMIT {$limit} |
59 | 59 | "); |
60 | - } |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @todo remove this? |
|
64 | - * @param string $metaKey |
|
65 | - * @return array |
|
66 | - */ |
|
67 | - public function getReviewCountsFor($metaKey) |
|
68 | - { |
|
69 | - $metaKey = Str::prefix('_', $metaKey); |
|
70 | - return (array) $this->db->get_results(" |
|
62 | + /** |
|
63 | + * @todo remove this? |
|
64 | + * @param string $metaKey |
|
65 | + * @return array |
|
66 | + */ |
|
67 | + public function getReviewCountsFor($metaKey) |
|
68 | + { |
|
69 | + $metaKey = Str::prefix('_', $metaKey); |
|
70 | + return (array) $this->db->get_results(" |
|
71 | 71 | SELECT DISTINCT m.meta_value AS name, COUNT(*) num_posts |
72 | 72 | FROM {$this->db->posts} AS p |
73 | 73 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
@@ -75,16 +75,16 @@ discard block |
||
75 | 75 | AND m.meta_key = '{$metaKey}' |
76 | 76 | GROUP BY name |
77 | 77 | "); |
78 | - } |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @todo remove this? |
|
82 | - * @param string $reviewType |
|
83 | - * @return array |
|
84 | - */ |
|
85 | - public function getReviewIdsByType($reviewType) |
|
86 | - { |
|
87 | - $results = $this->db->get_col(" |
|
80 | + /** |
|
81 | + * @todo remove this? |
|
82 | + * @param string $reviewType |
|
83 | + * @return array |
|
84 | + */ |
|
85 | + public function getReviewIdsByType($reviewType) |
|
86 | + { |
|
87 | + $results = $this->db->get_col(" |
|
88 | 88 | SELECT DISTINCT m1.meta_value AS review_id |
89 | 89 | FROM {$this->db->posts} AS p |
90 | 90 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -94,20 +94,20 @@ discard block |
||
94 | 94 | AND m2.meta_key = '_review_type' |
95 | 95 | AND m2.meta_value = '{$reviewType}' |
96 | 96 | "); |
97 | - return array_keys(array_flip($results)); |
|
98 | - } |
|
97 | + return array_keys(array_flip($results)); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @param int $greaterThanId |
|
102 | - * @param int $limit |
|
103 | - * @return array |
|
104 | - */ |
|
105 | - public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100) |
|
106 | - { |
|
107 | - sort($postIds); |
|
108 | - $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit); |
|
109 | - $postIds = implode(',', $postIds); |
|
110 | - return (array) $this->db->get_results(" |
|
100 | + /** |
|
101 | + * @param int $greaterThanId |
|
102 | + * @param int $limit |
|
103 | + * @return array |
|
104 | + */ |
|
105 | + public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100) |
|
106 | + { |
|
107 | + sort($postIds); |
|
108 | + $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit); |
|
109 | + $postIds = implode(',', $postIds); |
|
110 | + return (array) $this->db->get_results(" |
|
111 | 111 | SELECT p.ID, m.meta_value AS rating |
112 | 112 | FROM {$this->db->posts} AS p |
113 | 113 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
@@ -120,20 +120,20 @@ discard block |
||
120 | 120 | ORDER By p.ID ASC |
121 | 121 | LIMIT {$limit} |
122 | 122 | "); |
123 | - } |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * @param string $key |
|
127 | - * @param string $status |
|
128 | - * @return array |
|
129 | - */ |
|
130 | - public function getReviewsMeta($key, $status = 'publish') |
|
131 | - { |
|
132 | - $postStatusQuery = 'all' != $status && !empty($status) |
|
133 | - ? "AND p.post_status = '{$status}'" |
|
134 | - : ''; |
|
135 | - $key = Str::prefix('_', $key); |
|
136 | - $values = $this->db->get_col(" |
|
125 | + /** |
|
126 | + * @param string $key |
|
127 | + * @param string $status |
|
128 | + * @return array |
|
129 | + */ |
|
130 | + public function getReviewsMeta($key, $status = 'publish') |
|
131 | + { |
|
132 | + $postStatusQuery = 'all' != $status && !empty($status) |
|
133 | + ? "AND p.post_status = '{$status}'" |
|
134 | + : ''; |
|
135 | + $key = Str::prefix('_', $key); |
|
136 | + $values = $this->db->get_col(" |
|
137 | 137 | SELECT DISTINCT m.meta_value |
138 | 138 | FROM {$this->db->postmeta} m |
139 | 139 | LEFT JOIN {$this->db->posts} p ON p.ID = m.post_id |
@@ -144,42 +144,42 @@ discard block |
||
144 | 144 | GROUP BY p.ID -- remove duplicate meta_value entries |
145 | 145 | ORDER BY m.meta_id ASC -- sort by oldest meta_value |
146 | 146 | "); |
147 | - sort($values); |
|
148 | - return $values; |
|
149 | - } |
|
147 | + sort($values); |
|
148 | + return $values; |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * @param string $and |
|
153 | - * @return string |
|
154 | - */ |
|
155 | - protected function getAndForCounts(array $args, $and = '') |
|
156 | - { |
|
157 | - $postIds = implode(',', array_filter(Arr::get($args, 'post_ids', []))); |
|
158 | - $termIds = implode(',', array_filter(Arr::get($args, 'term_ids', []))); |
|
159 | - if (!empty($args['type'])) { |
|
160 | - $and.= "AND m2.meta_value = '{$args['type']}' "; |
|
161 | - } |
|
162 | - if ($postIds) { |
|
163 | - $and.= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
164 | - } |
|
165 | - if ($termIds) { |
|
166 | - $and.= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
167 | - } |
|
168 | - return apply_filters('site-reviews/query/and-for-counts', $and); |
|
169 | - } |
|
151 | + /** |
|
152 | + * @param string $and |
|
153 | + * @return string |
|
154 | + */ |
|
155 | + protected function getAndForCounts(array $args, $and = '') |
|
156 | + { |
|
157 | + $postIds = implode(',', array_filter(Arr::get($args, 'post_ids', []))); |
|
158 | + $termIds = implode(',', array_filter(Arr::get($args, 'term_ids', []))); |
|
159 | + if (!empty($args['type'])) { |
|
160 | + $and.= "AND m2.meta_value = '{$args['type']}' "; |
|
161 | + } |
|
162 | + if ($postIds) { |
|
163 | + $and.= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
164 | + } |
|
165 | + if ($termIds) { |
|
166 | + $and.= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
167 | + } |
|
168 | + return apply_filters('site-reviews/query/and-for-counts', $and); |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * @param string $innerJoin |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - protected function getInnerJoinForCounts(array $args, $innerJoin = '') |
|
176 | - { |
|
177 | - if (!empty(Arr::get($args, 'post_ids'))) { |
|
178 | - $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
179 | - } |
|
180 | - if (!empty(Arr::get($args, 'term_ids'))) { |
|
181 | - $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
182 | - } |
|
183 | - return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin); |
|
184 | - } |
|
171 | + /** |
|
172 | + * @param string $innerJoin |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + protected function getInnerJoinForCounts(array $args, $innerJoin = '') |
|
176 | + { |
|
177 | + if (!empty(Arr::get($args, 'post_ids'))) { |
|
178 | + $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
179 | + } |
|
180 | + if (!empty(Arr::get($args, 'term_ids'))) { |
|
181 | + $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
182 | + } |
|
183 | + return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin); |
|
184 | + } |
|
185 | 185 | } |
@@ -22,17 +22,17 @@ discard block |
||
22 | 22 | * @param string $metaReviewId |
23 | 23 | * @return int |
24 | 24 | */ |
25 | - public function getPostIdFromReviewId($metaReviewId) |
|
25 | + public function getPostIdFromReviewId( $metaReviewId ) |
|
26 | 26 | { |
27 | - $postId = $this->db->get_var(" |
|
27 | + $postId = $this->db->get_var( " |
|
28 | 28 | SELECT p.ID |
29 | 29 | FROM {$this->db->posts} AS p |
30 | 30 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
31 | 31 | WHERE p.post_type = '{$this->postType}' |
32 | 32 | AND m.meta_key = '_review_id' |
33 | 33 | AND m.meta_value = '{$metaReviewId}' |
34 | - "); |
|
35 | - return intval($postId); |
|
34 | + " ); |
|
35 | + return intval( $postId ); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -40,23 +40,23 @@ discard block |
||
40 | 40 | * @param int $limit |
41 | 41 | * @return array |
42 | 42 | */ |
43 | - public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500) |
|
43 | + public function getReviewCounts( array $args, $lastPostId = 0, $limit = 500 ) |
|
44 | 44 | { |
45 | - return (array) $this->db->get_results(" |
|
45 | + return (array)$this->db->get_results( " |
|
46 | 46 | SELECT DISTINCT p.ID, m1.meta_value AS rating, m2.meta_value AS type |
47 | 47 | FROM {$this->db->posts} AS p |
48 | 48 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
49 | 49 | INNER JOIN {$this->db->postmeta} AS m2 ON p.ID = m2.post_id |
50 | - {$this->getInnerJoinForCounts($args)} |
|
50 | + {$this->getInnerJoinForCounts( $args )} |
|
51 | 51 | WHERE p.ID > {$lastPostId} |
52 | 52 | AND p.post_status = 'publish' |
53 | 53 | AND p.post_type = '{$this->postType}' |
54 | 54 | AND m1.meta_key = '_rating' |
55 | 55 | AND m2.meta_key = '_review_type' |
56 | - {$this->getAndForCounts($args)} |
|
56 | + {$this->getAndForCounts( $args )} |
|
57 | 57 | ORDER By p.ID ASC |
58 | 58 | LIMIT {$limit} |
59 | - "); |
|
59 | + " ); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -64,17 +64,17 @@ discard block |
||
64 | 64 | * @param string $metaKey |
65 | 65 | * @return array |
66 | 66 | */ |
67 | - public function getReviewCountsFor($metaKey) |
|
67 | + public function getReviewCountsFor( $metaKey ) |
|
68 | 68 | { |
69 | - $metaKey = Str::prefix('_', $metaKey); |
|
70 | - return (array) $this->db->get_results(" |
|
69 | + $metaKey = Str::prefix( '_', $metaKey ); |
|
70 | + return (array)$this->db->get_results( " |
|
71 | 71 | SELECT DISTINCT m.meta_value AS name, COUNT(*) num_posts |
72 | 72 | FROM {$this->db->posts} AS p |
73 | 73 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
74 | 74 | WHERE p.post_type = '{$this->postType}' |
75 | 75 | AND m.meta_key = '{$metaKey}' |
76 | 76 | GROUP BY name |
77 | - "); |
|
77 | + " ); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | * @param string $reviewType |
83 | 83 | * @return array |
84 | 84 | */ |
85 | - public function getReviewIdsByType($reviewType) |
|
85 | + public function getReviewIdsByType( $reviewType ) |
|
86 | 86 | { |
87 | - $results = $this->db->get_col(" |
|
87 | + $results = $this->db->get_col( " |
|
88 | 88 | SELECT DISTINCT m1.meta_value AS review_id |
89 | 89 | FROM {$this->db->posts} AS p |
90 | 90 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | AND m1.meta_key = '_review_id' |
94 | 94 | AND m2.meta_key = '_review_type' |
95 | 95 | AND m2.meta_value = '{$reviewType}' |
96 | - "); |
|
97 | - return array_keys(array_flip($results)); |
|
96 | + " ); |
|
97 | + return array_keys( array_flip( $results ) ); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -102,12 +102,12 @@ discard block |
||
102 | 102 | * @param int $limit |
103 | 103 | * @return array |
104 | 104 | */ |
105 | - public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100) |
|
105 | + public function getReviewRatingsFromIds( array $postIds, $greaterThanId = 0, $limit = 100 ) |
|
106 | 106 | { |
107 | - sort($postIds); |
|
108 | - $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit); |
|
109 | - $postIds = implode(',', $postIds); |
|
110 | - return (array) $this->db->get_results(" |
|
107 | + sort( $postIds ); |
|
108 | + $postIds = array_slice( $postIds, intval( array_search( $greaterThanId, $postIds ) ), $limit ); |
|
109 | + $postIds = implode( ',', $postIds ); |
|
110 | + return (array)$this->db->get_results( " |
|
111 | 111 | SELECT p.ID, m.meta_value AS rating |
112 | 112 | FROM {$this->db->posts} AS p |
113 | 113 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | GROUP BY p.ID |
120 | 120 | ORDER By p.ID ASC |
121 | 121 | LIMIT {$limit} |
122 | - "); |
|
122 | + " ); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -127,13 +127,13 @@ discard block |
||
127 | 127 | * @param string $status |
128 | 128 | * @return array |
129 | 129 | */ |
130 | - public function getReviewsMeta($key, $status = 'publish') |
|
130 | + public function getReviewsMeta( $key, $status = 'publish' ) |
|
131 | 131 | { |
132 | 132 | $postStatusQuery = 'all' != $status && !empty($status) |
133 | 133 | ? "AND p.post_status = '{$status}'" |
134 | 134 | : ''; |
135 | - $key = Str::prefix('_', $key); |
|
136 | - $values = $this->db->get_col(" |
|
135 | + $key = Str::prefix( '_', $key ); |
|
136 | + $values = $this->db->get_col( " |
|
137 | 137 | SELECT DISTINCT m.meta_value |
138 | 138 | FROM {$this->db->postmeta} m |
139 | 139 | LEFT JOIN {$this->db->posts} p ON p.ID = m.post_id |
@@ -143,8 +143,8 @@ discard block |
||
143 | 143 | $postStatusQuery |
144 | 144 | GROUP BY p.ID -- remove duplicate meta_value entries |
145 | 145 | ORDER BY m.meta_id ASC -- sort by oldest meta_value |
146 | - "); |
|
147 | - sort($values); |
|
146 | + " ); |
|
147 | + sort( $values ); |
|
148 | 148 | return $values; |
149 | 149 | } |
150 | 150 | |
@@ -152,34 +152,34 @@ discard block |
||
152 | 152 | * @param string $and |
153 | 153 | * @return string |
154 | 154 | */ |
155 | - protected function getAndForCounts(array $args, $and = '') |
|
155 | + protected function getAndForCounts( array $args, $and = '' ) |
|
156 | 156 | { |
157 | - $postIds = implode(',', array_filter(Arr::get($args, 'post_ids', []))); |
|
158 | - $termIds = implode(',', array_filter(Arr::get($args, 'term_ids', []))); |
|
159 | - if (!empty($args['type'])) { |
|
160 | - $and.= "AND m2.meta_value = '{$args['type']}' "; |
|
157 | + $postIds = implode( ',', array_filter( Arr::get( $args, 'post_ids', [] ) ) ); |
|
158 | + $termIds = implode( ',', array_filter( Arr::get( $args, 'term_ids', [] ) ) ); |
|
159 | + if( !empty($args['type']) ) { |
|
160 | + $and .= "AND m2.meta_value = '{$args['type']}' "; |
|
161 | 161 | } |
162 | - if ($postIds) { |
|
163 | - $and.= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
162 | + if( $postIds ) { |
|
163 | + $and .= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
164 | 164 | } |
165 | - if ($termIds) { |
|
166 | - $and.= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
165 | + if( $termIds ) { |
|
166 | + $and .= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
167 | 167 | } |
168 | - return apply_filters('site-reviews/query/and-for-counts', $and); |
|
168 | + return apply_filters( 'site-reviews/query/and-for-counts', $and ); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
172 | 172 | * @param string $innerJoin |
173 | 173 | * @return string |
174 | 174 | */ |
175 | - protected function getInnerJoinForCounts(array $args, $innerJoin = '') |
|
175 | + protected function getInnerJoinForCounts( array $args, $innerJoin = '' ) |
|
176 | 176 | { |
177 | - if (!empty(Arr::get($args, 'post_ids'))) { |
|
178 | - $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
177 | + if( !empty(Arr::get( $args, 'post_ids' )) ) { |
|
178 | + $innerJoin .= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
179 | 179 | } |
180 | - if (!empty(Arr::get($args, 'term_ids'))) { |
|
181 | - $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
180 | + if( !empty(Arr::get( $args, 'term_ids' )) ) { |
|
181 | + $innerJoin .= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
182 | 182 | } |
183 | - return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin); |
|
183 | + return apply_filters( 'site-reviews/query/inner-join-for-counts', $innerJoin ); |
|
184 | 184 | } |
185 | 185 | } |
@@ -6,29 +6,29 @@ |
||
6 | 6 | |
7 | 7 | class SiteReviewsFormShortcode extends Shortcode |
8 | 8 | { |
9 | - protected function hideOptions() |
|
10 | - { |
|
11 | - return [ |
|
12 | - 'rating' => __('Hide the rating field', 'site-reviews'), |
|
13 | - 'title' => __('Hide the title field', 'site-reviews'), |
|
14 | - 'content' => __('Hide the review field', 'site-reviews'), |
|
15 | - 'name' => __('Hide the name field', 'site-reviews'), |
|
16 | - 'email' => __('Hide the email field', 'site-reviews'), |
|
17 | - 'terms' => __('Hide the terms field', 'site-reviews'), |
|
18 | - ]; |
|
19 | - } |
|
9 | + protected function hideOptions() |
|
10 | + { |
|
11 | + return [ |
|
12 | + 'rating' => __('Hide the rating field', 'site-reviews'), |
|
13 | + 'title' => __('Hide the title field', 'site-reviews'), |
|
14 | + 'content' => __('Hide the review field', 'site-reviews'), |
|
15 | + 'name' => __('Hide the name field', 'site-reviews'), |
|
16 | + 'email' => __('Hide the email field', 'site-reviews'), |
|
17 | + 'terms' => __('Hide the terms field', 'site-reviews'), |
|
18 | + ]; |
|
19 | + } |
|
20 | 20 | |
21 | - /** |
|
22 | - * @param array|string $atts |
|
23 | - * @param string $type |
|
24 | - * @return array |
|
25 | - */ |
|
26 | - public function normalizeAtts($atts, $type = 'shortcode') |
|
27 | - { |
|
28 | - $atts = parent::normalizeAtts($atts, $type); |
|
29 | - if (empty($atts['id'])) { |
|
30 | - $atts['id'] = Application::PREFIX.substr(md5(serialize($atts)), 0, 8); |
|
31 | - } |
|
32 | - return $atts; |
|
33 | - } |
|
21 | + /** |
|
22 | + * @param array|string $atts |
|
23 | + * @param string $type |
|
24 | + * @return array |
|
25 | + */ |
|
26 | + public function normalizeAtts($atts, $type = 'shortcode') |
|
27 | + { |
|
28 | + $atts = parent::normalizeAtts($atts, $type); |
|
29 | + if (empty($atts['id'])) { |
|
30 | + $atts['id'] = Application::PREFIX.substr(md5(serialize($atts)), 0, 8); |
|
31 | + } |
|
32 | + return $atts; |
|
33 | + } |
|
34 | 34 | } |
@@ -9,12 +9,12 @@ discard block |
||
9 | 9 | protected function hideOptions() |
10 | 10 | { |
11 | 11 | return [ |
12 | - 'rating' => __('Hide the rating field', 'site-reviews'), |
|
13 | - 'title' => __('Hide the title field', 'site-reviews'), |
|
14 | - 'content' => __('Hide the review field', 'site-reviews'), |
|
15 | - 'name' => __('Hide the name field', 'site-reviews'), |
|
16 | - 'email' => __('Hide the email field', 'site-reviews'), |
|
17 | - 'terms' => __('Hide the terms field', 'site-reviews'), |
|
12 | + 'rating' => __( 'Hide the rating field', 'site-reviews' ), |
|
13 | + 'title' => __( 'Hide the title field', 'site-reviews' ), |
|
14 | + 'content' => __( 'Hide the review field', 'site-reviews' ), |
|
15 | + 'name' => __( 'Hide the name field', 'site-reviews' ), |
|
16 | + 'email' => __( 'Hide the email field', 'site-reviews' ), |
|
17 | + 'terms' => __( 'Hide the terms field', 'site-reviews' ), |
|
18 | 18 | ]; |
19 | 19 | } |
20 | 20 | |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | * @param string $type |
24 | 24 | * @return array |
25 | 25 | */ |
26 | - public function normalizeAtts($atts, $type = 'shortcode') |
|
26 | + public function normalizeAtts( $atts, $type = 'shortcode' ) |
|
27 | 27 | { |
28 | - $atts = parent::normalizeAtts($atts, $type); |
|
29 | - if (empty($atts['id'])) { |
|
30 | - $atts['id'] = Application::PREFIX.substr(md5(serialize($atts)), 0, 8); |
|
28 | + $atts = parent::normalizeAtts( $atts, $type ); |
|
29 | + if( empty($atts['id']) ) { |
|
30 | + $atts['id'] = Application::PREFIX.substr( md5( serialize( $atts ) ), 0, 8 ); |
|
31 | 31 | } |
32 | 32 | return $atts; |
33 | 33 | } |
@@ -12,190 +12,190 @@ |
||
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(Multilingual::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(Multilingual::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 | } |
@@ -16,19 +16,19 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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(Multilingual::class)->getPostIds($postIds), |
|
124 | + 'value' => glsr( Multilingual::class )->getPostIds( $postIds ), |
|
125 | 125 | ]; |
126 | 126 | } |
127 | 127 | } |
@@ -130,9 +130,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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, |
@@ -14,52 +14,52 @@ |
||
14 | 14 | */ |
15 | 15 | class Multilingual |
16 | 16 | { |
17 | - protected $integration; |
|
17 | + protected $integration; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @param string $method |
|
21 | - * @param array $args |
|
22 | - * @return |
|
23 | - */ |
|
24 | - public function __call($method, $args = []) |
|
25 | - { |
|
26 | - if ($this->isIntegrated() && method_exists($this->integration, $method)) { |
|
27 | - return call_user_func_array([$this->integration, $method], $args); |
|
28 | - } |
|
29 | - return Arr::get($args, 0, false); |
|
30 | - } |
|
19 | + /** |
|
20 | + * @param string $method |
|
21 | + * @param array $args |
|
22 | + * @return |
|
23 | + */ |
|
24 | + public function __call($method, $args = []) |
|
25 | + { |
|
26 | + if ($this->isIntegrated() && method_exists($this->integration, $method)) { |
|
27 | + return call_user_func_array([$this->integration, $method], $args); |
|
28 | + } |
|
29 | + return Arr::get($args, 0, false); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * @param string $integration |
|
34 | - * @return false|\GeminiLabs\SiteReviews\Modules\Multilingual\Polylang|\GeminiLabs\SiteReviews\Modules\Multilingual\Wpml |
|
35 | - */ |
|
36 | - public function getIntegration($integration = '') |
|
37 | - { |
|
38 | - if (empty($integration)) { |
|
39 | - $integration = glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
40 | - } |
|
41 | - if (!empty($integration)) { |
|
42 | - $integrationClass = 'GeminiLabs\SiteReviews\Modules\Multilingual\\'.ucfirst($integration); |
|
43 | - if (class_exists($integrationClass)) { |
|
44 | - return glsr($integrationClass); |
|
45 | - } |
|
46 | - glsr_log()->error($integrationClass.' does not exist'); |
|
47 | - } |
|
48 | - return false; |
|
49 | - } |
|
32 | + /** |
|
33 | + * @param string $integration |
|
34 | + * @return false|\GeminiLabs\SiteReviews\Modules\Multilingual\Polylang|\GeminiLabs\SiteReviews\Modules\Multilingual\Wpml |
|
35 | + */ |
|
36 | + public function getIntegration($integration = '') |
|
37 | + { |
|
38 | + if (empty($integration)) { |
|
39 | + $integration = glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
40 | + } |
|
41 | + if (!empty($integration)) { |
|
42 | + $integrationClass = 'GeminiLabs\SiteReviews\Modules\Multilingual\\'.ucfirst($integration); |
|
43 | + if (class_exists($integrationClass)) { |
|
44 | + return glsr($integrationClass); |
|
45 | + } |
|
46 | + glsr_log()->error($integrationClass.' does not exist'); |
|
47 | + } |
|
48 | + return false; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * return bool |
|
53 | - */ |
|
54 | - public function isIntegrated() |
|
55 | - { |
|
56 | - if (!empty($this->integration)) { |
|
57 | - return true; |
|
58 | - } |
|
59 | - if ($integration = $this->getIntegration()) { |
|
60 | - $this->integration = $integration; |
|
61 | - return true; |
|
62 | - } |
|
63 | - return false; |
|
64 | - } |
|
51 | + /** |
|
52 | + * return bool |
|
53 | + */ |
|
54 | + public function isIntegrated() |
|
55 | + { |
|
56 | + if (!empty($this->integration)) { |
|
57 | + return true; |
|
58 | + } |
|
59 | + if ($integration = $this->getIntegration()) { |
|
60 | + $this->integration = $integration; |
|
61 | + return true; |
|
62 | + } |
|
63 | + return false; |
|
64 | + } |
|
65 | 65 | } |
@@ -21,29 +21,29 @@ discard block |
||
21 | 21 | * @param array $args |
22 | 22 | * @return |
23 | 23 | */ |
24 | - public function __call($method, $args = []) |
|
24 | + public function __call( $method, $args = [] ) |
|
25 | 25 | { |
26 | - if ($this->isIntegrated() && method_exists($this->integration, $method)) { |
|
27 | - return call_user_func_array([$this->integration, $method], $args); |
|
26 | + if( $this->isIntegrated() && method_exists( $this->integration, $method ) ) { |
|
27 | + return call_user_func_array( [$this->integration, $method], $args ); |
|
28 | 28 | } |
29 | - return Arr::get($args, 0, false); |
|
29 | + return Arr::get( $args, 0, false ); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
33 | 33 | * @param string $integration |
34 | 34 | * @return false|\GeminiLabs\SiteReviews\Modules\Multilingual\Polylang|\GeminiLabs\SiteReviews\Modules\Multilingual\Wpml |
35 | 35 | */ |
36 | - public function getIntegration($integration = '') |
|
36 | + public function getIntegration( $integration = '' ) |
|
37 | 37 | { |
38 | - if (empty($integration)) { |
|
39 | - $integration = glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
38 | + if( empty($integration) ) { |
|
39 | + $integration = glsr( OptionManager::class )->get( 'settings.general.multilingual' ); |
|
40 | 40 | } |
41 | - if (!empty($integration)) { |
|
42 | - $integrationClass = 'GeminiLabs\SiteReviews\Modules\Multilingual\\'.ucfirst($integration); |
|
43 | - if (class_exists($integrationClass)) { |
|
44 | - return glsr($integrationClass); |
|
41 | + if( !empty($integration) ) { |
|
42 | + $integrationClass = 'GeminiLabs\SiteReviews\Modules\Multilingual\\'.ucfirst( $integration ); |
|
43 | + if( class_exists( $integrationClass ) ) { |
|
44 | + return glsr( $integrationClass ); |
|
45 | 45 | } |
46 | - glsr_log()->error($integrationClass.' does not exist'); |
|
46 | + glsr_log()->error( $integrationClass.' does not exist' ); |
|
47 | 47 | } |
48 | 48 | return false; |
49 | 49 | } |
@@ -53,10 +53,10 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function isIntegrated() |
55 | 55 | { |
56 | - if (!empty($this->integration)) { |
|
56 | + if( !empty($this->integration) ) { |
|
57 | 57 | return true; |
58 | 58 | } |
59 | - if ($integration = $this->getIntegration()) { |
|
59 | + if( $integration = $this->getIntegration() ) { |
|
60 | 60 | $this->integration = $integration; |
61 | 61 | return true; |
62 | 62 | } |
@@ -1,22 +1,22 @@ discard block |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | -<p><?= sprintf(__('Here you can customise any text of the plugin, including the submission form labels and placeholders. However, if you have a multilingual website you should use the %s plugin instead.', 'site-reviews'), '<a href="https://wordpress.org/plugins/loco-translate/">Loco Translate</a>'); ?></p> |
|
3 | +<p><?= sprintf( __( 'Here you can customise any text of the plugin, including the submission form labels and placeholders. However, if you have a multilingual website you should use the %s plugin instead.', 'site-reviews' ), '<a href="https://wordpress.org/plugins/loco-translate/">Loco Translate</a>' ); ?></p> |
|
4 | 4 | |
5 | 5 | <div class="glsr-strings-form"> |
6 | 6 | <div class="glsr-search-box" id="glsr-search-translations"> |
7 | - <span class="screen-reader-text"><?= __('Search for translatable text', 'site-reviews'); ?></span> |
|
7 | + <span class="screen-reader-text"><?= __( 'Search for translatable text', 'site-reviews' ); ?></span> |
|
8 | 8 | <div class="glsr-spinner"> |
9 | 9 | <span class="spinner"></span> |
10 | 10 | </div> |
11 | - <input type="search" class="glsr-search-input" autocomplete="off" placeholder="<?= __('Search here for text to translate...', 'site-reviews'); ?>"> |
|
12 | - <?php wp_nonce_field('search-translations', '_search_nonce', false); ?> |
|
11 | + <input type="search" class="glsr-search-input" autocomplete="off" placeholder="<?= __( 'Search here for text to translate...', 'site-reviews' ); ?>"> |
|
12 | + <?php wp_nonce_field( 'search-translations', '_search_nonce', false ); ?> |
|
13 | 13 | <div class="glsr-search-results" data-prefix="{{ database_key }}"></div> |
14 | 14 | </div> |
15 | 15 | <table class="glsr-strings-table wp-list-table widefat striped {{ class }}"> |
16 | 16 | <thead> |
17 | 17 | <tr> |
18 | - <th scope="col" class="manage-column column-primary"><?= __('Original Text', 'site-reviews'); ?></th> |
|
19 | - <th scope="col" class="manage-column"><?= __('Custom Translation', 'site-reviews'); ?></th> |
|
18 | + <th scope="col" class="manage-column column-primary"><?= __( 'Original Text', 'site-reviews' ); ?></th> |
|
19 | + <th scope="col" class="manage-column"><?= __( 'Custom Translation', 'site-reviews' ); ?></th> |
|
20 | 20 | </tr> |
21 | 21 | </thead> |
22 | 22 | <tbody>{{ translations }}</tbody> |
@@ -25,8 +25,8 @@ discard block |
||
25 | 25 | </div> |
26 | 26 | |
27 | 27 | <script type="text/html" id="tmpl-glsr-string-plural"> |
28 | -<?php include glsr()->path('views/partials/translations/plural.php'); ?> |
|
28 | +<?php include glsr()->path( 'views/partials/translations/plural.php' ); ?> |
|
29 | 29 | </script> |
30 | 30 | <script type="text/html" id="tmpl-glsr-string-single"> |
31 | -<?php include glsr()->path('views/partials/translations/single.php'); ?> |
|
31 | +<?php include glsr()->path( 'views/partials/translations/single.php' ); ?> |
|
32 | 32 | </script> |
@@ -8,105 +8,105 @@ |
||
8 | 8 | |
9 | 9 | class ReviewLimits |
10 | 10 | { |
11 | - protected $request; |
|
11 | + protected $request; |
|
12 | 12 | |
13 | - /** |
|
14 | - * @return array |
|
15 | - * @filter site-reviews/get/reviews/query |
|
16 | - */ |
|
17 | - public function filterReviewsQuery(array $parameters, array $args) |
|
18 | - { |
|
19 | - if ($authorId = get_current_user_id()) { |
|
20 | - $parameters['author'] = $authorId; |
|
21 | - } |
|
22 | - $parameters['post_status'] = ['pending', 'publish']; |
|
23 | - return apply_filters('site-reviews/review-limits/query', $parameters, $args); |
|
24 | - } |
|
13 | + /** |
|
14 | + * @return array |
|
15 | + * @filter site-reviews/get/reviews/query |
|
16 | + */ |
|
17 | + public function filterReviewsQuery(array $parameters, array $args) |
|
18 | + { |
|
19 | + if ($authorId = get_current_user_id()) { |
|
20 | + $parameters['author'] = $authorId; |
|
21 | + } |
|
22 | + $parameters['post_status'] = ['pending', 'publish']; |
|
23 | + return apply_filters('site-reviews/review-limits/query', $parameters, $args); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * @return bool |
|
28 | - */ |
|
29 | - public function hasReachedLimit(array $request = []) |
|
30 | - { |
|
31 | - $this->request = $request; |
|
32 | - $method = Helper::buildMethodName( |
|
33 | - glsr(OptionManager::class)->get('settings.submissions.limit'), 'validateBy' |
|
34 | - ); |
|
35 | - return method_exists($this, $method) |
|
36 | - ? !call_user_func([$this, $method]) |
|
37 | - : false; |
|
38 | - } |
|
26 | + /** |
|
27 | + * @return bool |
|
28 | + */ |
|
29 | + public function hasReachedLimit(array $request = []) |
|
30 | + { |
|
31 | + $this->request = $request; |
|
32 | + $method = Helper::buildMethodName( |
|
33 | + glsr(OptionManager::class)->get('settings.submissions.limit'), 'validateBy' |
|
34 | + ); |
|
35 | + return method_exists($this, $method) |
|
36 | + ? !call_user_func([$this, $method]) |
|
37 | + : false; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param string $value |
|
42 | - * @param string $whitelist |
|
43 | - * @return bool |
|
44 | - */ |
|
45 | - public function isWhitelisted($value, $whitelist) |
|
46 | - { |
|
47 | - if (empty($whitelist)) { |
|
48 | - return false; |
|
49 | - } |
|
50 | - return in_array($value, array_filter(explode("\n", $whitelist), 'trim')); |
|
51 | - } |
|
40 | + /** |
|
41 | + * @param string $value |
|
42 | + * @param string $whitelist |
|
43 | + * @return bool |
|
44 | + */ |
|
45 | + public function isWhitelisted($value, $whitelist) |
|
46 | + { |
|
47 | + if (empty($whitelist)) { |
|
48 | + return false; |
|
49 | + } |
|
50 | + return in_array($value, array_filter(explode("\n", $whitelist), 'trim')); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param string $whitelistName |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - protected function getWhitelist($whitelistName) |
|
58 | - { |
|
59 | - return glsr(OptionManager::class)->get('settings.submissions.limit_whitelist.'.$whitelistName); |
|
60 | - } |
|
53 | + /** |
|
54 | + * @param string $whitelistName |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + protected function getWhitelist($whitelistName) |
|
58 | + { |
|
59 | + return glsr(OptionManager::class)->get('settings.submissions.limit_whitelist.'.$whitelistName); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return bool |
|
64 | - */ |
|
65 | - protected function validate($key, $value, $addMetaQuery = true) |
|
66 | - { |
|
67 | - if ($this->isWhitelisted($value, $this->getWhitelist($key))) { |
|
68 | - return true; |
|
69 | - } |
|
70 | - add_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5, 2); |
|
71 | - $args = ['assigned_to' => Arr::get($this->request, 'assign_to')]; |
|
72 | - if ($addMetaQuery) { |
|
73 | - $args[$key] = $value; |
|
74 | - } |
|
75 | - $reviews = glsr_get_reviews($args); |
|
76 | - remove_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5); |
|
77 | - $result = 0 === count($reviews); |
|
78 | - $result = apply_filters('site-reviews/review-limits/validate', $result, $reviews, $this->request, $key); |
|
79 | - return wp_validate_boolean($result); |
|
80 | - } |
|
62 | + /** |
|
63 | + * @return bool |
|
64 | + */ |
|
65 | + protected function validate($key, $value, $addMetaQuery = true) |
|
66 | + { |
|
67 | + if ($this->isWhitelisted($value, $this->getWhitelist($key))) { |
|
68 | + return true; |
|
69 | + } |
|
70 | + add_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5, 2); |
|
71 | + $args = ['assigned_to' => Arr::get($this->request, 'assign_to')]; |
|
72 | + if ($addMetaQuery) { |
|
73 | + $args[$key] = $value; |
|
74 | + } |
|
75 | + $reviews = glsr_get_reviews($args); |
|
76 | + remove_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5); |
|
77 | + $result = 0 === count($reviews); |
|
78 | + $result = apply_filters('site-reviews/review-limits/validate', $result, $reviews, $this->request, $key); |
|
79 | + return wp_validate_boolean($result); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return bool |
|
84 | - */ |
|
85 | - protected function validateByEmail() |
|
86 | - { |
|
87 | - glsr_log()->debug('Email is: '.Arr::get($this->request, 'email')); |
|
88 | - return $this->validate('email', Arr::get($this->request, 'email')); |
|
89 | - } |
|
82 | + /** |
|
83 | + * @return bool |
|
84 | + */ |
|
85 | + protected function validateByEmail() |
|
86 | + { |
|
87 | + glsr_log()->debug('Email is: '.Arr::get($this->request, 'email')); |
|
88 | + return $this->validate('email', Arr::get($this->request, 'email')); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @return bool |
|
93 | - */ |
|
94 | - protected function validateByIpAddress() |
|
95 | - { |
|
96 | - glsr_log()->debug('IP Address is: '.Arr::get($this->request, 'ip_address')); |
|
97 | - return $this->validate('ip_address', Arr::get($this->request, 'ip_address')); |
|
98 | - } |
|
91 | + /** |
|
92 | + * @return bool |
|
93 | + */ |
|
94 | + protected function validateByIpAddress() |
|
95 | + { |
|
96 | + glsr_log()->debug('IP Address is: '.Arr::get($this->request, 'ip_address')); |
|
97 | + return $this->validate('ip_address', Arr::get($this->request, 'ip_address')); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @return bool |
|
102 | - */ |
|
103 | - protected function validateByUsername() |
|
104 | - { |
|
105 | - $user = wp_get_current_user(); |
|
106 | - if (!$user->exists()) { |
|
107 | - return true; |
|
108 | - } |
|
109 | - glsr_log()->debug('Username is: '.$user->user_login); |
|
110 | - return $this->validate('username', $user->user_login, false); |
|
111 | - } |
|
100 | + /** |
|
101 | + * @return bool |
|
102 | + */ |
|
103 | + protected function validateByUsername() |
|
104 | + { |
|
105 | + $user = wp_get_current_user(); |
|
106 | + if (!$user->exists()) { |
|
107 | + return true; |
|
108 | + } |
|
109 | + glsr_log()->debug('Username is: '.$user->user_login); |
|
110 | + return $this->validate('username', $user->user_login, false); |
|
111 | + } |
|
112 | 112 | } |
@@ -14,26 +14,26 @@ discard block |
||
14 | 14 | * @return array |
15 | 15 | * @filter site-reviews/get/reviews/query |
16 | 16 | */ |
17 | - public function filterReviewsQuery(array $parameters, array $args) |
|
17 | + public function filterReviewsQuery( array $parameters, array $args ) |
|
18 | 18 | { |
19 | - if ($authorId = get_current_user_id()) { |
|
19 | + if( $authorId = get_current_user_id() ) { |
|
20 | 20 | $parameters['author'] = $authorId; |
21 | 21 | } |
22 | 22 | $parameters['post_status'] = ['pending', 'publish']; |
23 | - return apply_filters('site-reviews/review-limits/query', $parameters, $args); |
|
23 | + return apply_filters( 'site-reviews/review-limits/query', $parameters, $args ); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @return bool |
28 | 28 | */ |
29 | - public function hasReachedLimit(array $request = []) |
|
29 | + public function hasReachedLimit( array $request = [] ) |
|
30 | 30 | { |
31 | 31 | $this->request = $request; |
32 | 32 | $method = Helper::buildMethodName( |
33 | - glsr(OptionManager::class)->get('settings.submissions.limit'), 'validateBy' |
|
33 | + glsr( OptionManager::class )->get( 'settings.submissions.limit' ), 'validateBy' |
|
34 | 34 | ); |
35 | - return method_exists($this, $method) |
|
36 | - ? !call_user_func([$this, $method]) |
|
35 | + return method_exists( $this, $method ) |
|
36 | + ? !call_user_func( [$this, $method] ) |
|
37 | 37 | : false; |
38 | 38 | } |
39 | 39 | |
@@ -42,41 +42,41 @@ discard block |
||
42 | 42 | * @param string $whitelist |
43 | 43 | * @return bool |
44 | 44 | */ |
45 | - public function isWhitelisted($value, $whitelist) |
|
45 | + public function isWhitelisted( $value, $whitelist ) |
|
46 | 46 | { |
47 | - if (empty($whitelist)) { |
|
47 | + if( empty($whitelist) ) { |
|
48 | 48 | return false; |
49 | 49 | } |
50 | - return in_array($value, array_filter(explode("\n", $whitelist), 'trim')); |
|
50 | + return in_array( $value, array_filter( explode( "\n", $whitelist ), 'trim' ) ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
54 | 54 | * @param string $whitelistName |
55 | 55 | * @return string |
56 | 56 | */ |
57 | - protected function getWhitelist($whitelistName) |
|
57 | + protected function getWhitelist( $whitelistName ) |
|
58 | 58 | { |
59 | - return glsr(OptionManager::class)->get('settings.submissions.limit_whitelist.'.$whitelistName); |
|
59 | + return glsr( OptionManager::class )->get( 'settings.submissions.limit_whitelist.'.$whitelistName ); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
63 | 63 | * @return bool |
64 | 64 | */ |
65 | - protected function validate($key, $value, $addMetaQuery = true) |
|
65 | + protected function validate( $key, $value, $addMetaQuery = true ) |
|
66 | 66 | { |
67 | - if ($this->isWhitelisted($value, $this->getWhitelist($key))) { |
|
67 | + if( $this->isWhitelisted( $value, $this->getWhitelist( $key ) ) ) { |
|
68 | 68 | return true; |
69 | 69 | } |
70 | - add_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5, 2); |
|
71 | - $args = ['assigned_to' => Arr::get($this->request, 'assign_to')]; |
|
72 | - if ($addMetaQuery) { |
|
70 | + add_filter( 'site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5, 2 ); |
|
71 | + $args = ['assigned_to' => Arr::get( $this->request, 'assign_to' )]; |
|
72 | + if( $addMetaQuery ) { |
|
73 | 73 | $args[$key] = $value; |
74 | 74 | } |
75 | - $reviews = glsr_get_reviews($args); |
|
76 | - remove_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5); |
|
77 | - $result = 0 === count($reviews); |
|
78 | - $result = apply_filters('site-reviews/review-limits/validate', $result, $reviews, $this->request, $key); |
|
79 | - return wp_validate_boolean($result); |
|
75 | + $reviews = glsr_get_reviews( $args ); |
|
76 | + remove_filter( 'site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5 ); |
|
77 | + $result = 0 === count( $reviews ); |
|
78 | + $result = apply_filters( 'site-reviews/review-limits/validate', $result, $reviews, $this->request, $key ); |
|
79 | + return wp_validate_boolean( $result ); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | */ |
85 | 85 | protected function validateByEmail() |
86 | 86 | { |
87 | - glsr_log()->debug('Email is: '.Arr::get($this->request, 'email')); |
|
88 | - return $this->validate('email', Arr::get($this->request, 'email')); |
|
87 | + glsr_log()->debug( 'Email is: '.Arr::get( $this->request, 'email' ) ); |
|
88 | + return $this->validate( 'email', Arr::get( $this->request, 'email' ) ); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | */ |
94 | 94 | protected function validateByIpAddress() |
95 | 95 | { |
96 | - glsr_log()->debug('IP Address is: '.Arr::get($this->request, 'ip_address')); |
|
97 | - return $this->validate('ip_address', Arr::get($this->request, 'ip_address')); |
|
96 | + glsr_log()->debug( 'IP Address is: '.Arr::get( $this->request, 'ip_address' ) ); |
|
97 | + return $this->validate( 'ip_address', Arr::get( $this->request, 'ip_address' ) ); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -103,10 +103,10 @@ discard block |
||
103 | 103 | protected function validateByUsername() |
104 | 104 | { |
105 | 105 | $user = wp_get_current_user(); |
106 | - if (!$user->exists()) { |
|
106 | + if( !$user->exists() ) { |
|
107 | 107 | return true; |
108 | 108 | } |
109 | - glsr_log()->debug('Username is: '.$user->user_login); |
|
110 | - return $this->validate('username', $user->user_login, false); |
|
109 | + glsr_log()->debug( 'Username is: '.$user->user_login ); |
|
110 | + return $this->validate( 'username', $user->user_login, false ); |
|
111 | 111 | } |
112 | 112 | } |
@@ -10,126 +10,126 @@ |
||
10 | 10 | */ |
11 | 11 | trait ValidationRules |
12 | 12 | { |
13 | - /** |
|
14 | - * Get the size of an attribute. |
|
15 | - * @param string $attribute |
|
16 | - * @param mixed $value |
|
17 | - * @return mixed |
|
18 | - */ |
|
19 | - abstract protected function getSize($attribute, $value); |
|
13 | + /** |
|
14 | + * Get the size of an attribute. |
|
15 | + * @param string $attribute |
|
16 | + * @param mixed $value |
|
17 | + * @return mixed |
|
18 | + */ |
|
19 | + abstract protected function getSize($attribute, $value); |
|
20 | 20 | |
21 | - /** |
|
22 | - * Replace all placeholders. |
|
23 | - * @param string $message |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - protected function replace($message, array $parameters) |
|
27 | - { |
|
28 | - if (!Str::contains($message, '%s')) { |
|
29 | - return $message; |
|
30 | - } |
|
31 | - return preg_replace_callback('/(%s)/', function () use (&$parameters) { |
|
32 | - foreach ($parameters as $key => $value) { |
|
33 | - return array_shift($parameters); |
|
34 | - } |
|
35 | - }, $message); |
|
36 | - } |
|
21 | + /** |
|
22 | + * Replace all placeholders. |
|
23 | + * @param string $message |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + protected function replace($message, array $parameters) |
|
27 | + { |
|
28 | + if (!Str::contains($message, '%s')) { |
|
29 | + return $message; |
|
30 | + } |
|
31 | + return preg_replace_callback('/(%s)/', function () use (&$parameters) { |
|
32 | + foreach ($parameters as $key => $value) { |
|
33 | + return array_shift($parameters); |
|
34 | + } |
|
35 | + }, $message); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Validate that an attribute was "accepted". |
|
40 | - * This validation rule implies the attribute is "required". |
|
41 | - * @param string $attribute |
|
42 | - * @param mixed $value |
|
43 | - * @return bool |
|
44 | - */ |
|
45 | - public function validateAccepted($value) |
|
46 | - { |
|
47 | - $acceptable = ['yes', 'on', '1', 1, true, 'true']; |
|
48 | - return $this->validateRequired($value) && in_array($value, $acceptable, true); |
|
49 | - } |
|
38 | + /** |
|
39 | + * Validate that an attribute was "accepted". |
|
40 | + * This validation rule implies the attribute is "required". |
|
41 | + * @param string $attribute |
|
42 | + * @param mixed $value |
|
43 | + * @return bool |
|
44 | + */ |
|
45 | + public function validateAccepted($value) |
|
46 | + { |
|
47 | + $acceptable = ['yes', 'on', '1', 1, true, 'true']; |
|
48 | + return $this->validateRequired($value) && in_array($value, $acceptable, true); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Validate the size of an attribute is between a set of values. |
|
53 | - * @param string $attribute |
|
54 | - * @param mixed $value |
|
55 | - * @return bool |
|
56 | - */ |
|
57 | - public function validateBetween($value, $attribute, array $parameters) |
|
58 | - { |
|
59 | - $this->requireParameterCount(2, $parameters, 'between'); |
|
60 | - $size = $this->getSize($attribute, $value); |
|
61 | - return $size >= $parameters[0] && $size <= $parameters[1]; |
|
62 | - } |
|
51 | + /** |
|
52 | + * Validate the size of an attribute is between a set of values. |
|
53 | + * @param string $attribute |
|
54 | + * @param mixed $value |
|
55 | + * @return bool |
|
56 | + */ |
|
57 | + public function validateBetween($value, $attribute, array $parameters) |
|
58 | + { |
|
59 | + $this->requireParameterCount(2, $parameters, 'between'); |
|
60 | + $size = $this->getSize($attribute, $value); |
|
61 | + return $size >= $parameters[0] && $size <= $parameters[1]; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Validate that an attribute is a valid e-mail address. |
|
66 | - * @param mixed $value |
|
67 | - * @return bool |
|
68 | - */ |
|
69 | - public function validateEmail($value) |
|
70 | - { |
|
71 | - return false !== filter_var($value, FILTER_VALIDATE_EMAIL); |
|
72 | - } |
|
64 | + /** |
|
65 | + * Validate that an attribute is a valid e-mail address. |
|
66 | + * @param mixed $value |
|
67 | + * @return bool |
|
68 | + */ |
|
69 | + public function validateEmail($value) |
|
70 | + { |
|
71 | + return false !== filter_var($value, FILTER_VALIDATE_EMAIL); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Validate the size of an attribute is less than a maximum value. |
|
76 | - * @param string $attribute |
|
77 | - * @param mixed $value |
|
78 | - * @return bool |
|
79 | - */ |
|
80 | - public function validateMax($value, $attribute, array $parameters) |
|
81 | - { |
|
82 | - $this->requireParameterCount(1, $parameters, 'max'); |
|
83 | - return $this->getSize($attribute, $value) <= $parameters[0]; |
|
84 | - } |
|
74 | + /** |
|
75 | + * Validate the size of an attribute is less than a maximum value. |
|
76 | + * @param string $attribute |
|
77 | + * @param mixed $value |
|
78 | + * @return bool |
|
79 | + */ |
|
80 | + public function validateMax($value, $attribute, array $parameters) |
|
81 | + { |
|
82 | + $this->requireParameterCount(1, $parameters, 'max'); |
|
83 | + return $this->getSize($attribute, $value) <= $parameters[0]; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Validate the size of an attribute is greater than a minimum value. |
|
88 | - * @param string $attribute |
|
89 | - * @param mixed $value |
|
90 | - * @return bool |
|
91 | - */ |
|
92 | - public function validateMin($value, $attribute, array $parameters) |
|
93 | - { |
|
94 | - $this->requireParameterCount(1, $parameters, 'min'); |
|
95 | - return $this->getSize($attribute, $value) >= $parameters[0]; |
|
96 | - } |
|
86 | + /** |
|
87 | + * Validate the size of an attribute is greater than a minimum value. |
|
88 | + * @param string $attribute |
|
89 | + * @param mixed $value |
|
90 | + * @return bool |
|
91 | + */ |
|
92 | + public function validateMin($value, $attribute, array $parameters) |
|
93 | + { |
|
94 | + $this->requireParameterCount(1, $parameters, 'min'); |
|
95 | + return $this->getSize($attribute, $value) >= $parameters[0]; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Validate that an attribute is numeric. |
|
100 | - * @param mixed $value |
|
101 | - * @return bool |
|
102 | - */ |
|
103 | - public function validateNumber($value) |
|
104 | - { |
|
105 | - return is_numeric($value); |
|
106 | - } |
|
98 | + /** |
|
99 | + * Validate that an attribute is numeric. |
|
100 | + * @param mixed $value |
|
101 | + * @return bool |
|
102 | + */ |
|
103 | + public function validateNumber($value) |
|
104 | + { |
|
105 | + return is_numeric($value); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * Validate that a required attribute exists. |
|
110 | - * @param mixed $value |
|
111 | - * @return bool |
|
112 | - */ |
|
113 | - public function validateRequired($value) |
|
114 | - { |
|
115 | - return is_null($value) |
|
116 | - || (is_string($value) && in_array(trim($value), ['', '[]'])) |
|
117 | - || (is_array($value) && empty($value)) |
|
118 | - ? false |
|
119 | - : true; |
|
120 | - } |
|
108 | + /** |
|
109 | + * Validate that a required attribute exists. |
|
110 | + * @param mixed $value |
|
111 | + * @return bool |
|
112 | + */ |
|
113 | + public function validateRequired($value) |
|
114 | + { |
|
115 | + return is_null($value) |
|
116 | + || (is_string($value) && in_array(trim($value), ['', '[]'])) |
|
117 | + || (is_array($value) && empty($value)) |
|
118 | + ? false |
|
119 | + : true; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Require a certain number of parameters to be present. |
|
124 | - * @param int $count |
|
125 | - * @param string $rule |
|
126 | - * @return void |
|
127 | - * @throws InvalidArgumentException |
|
128 | - */ |
|
129 | - protected function requireParameterCount($count, array $parameters, $rule) |
|
130 | - { |
|
131 | - if (count($parameters) < $count) { |
|
132 | - throw new InvalidArgumentException("Validation rule $rule requires at least $count parameters."); |
|
133 | - } |
|
134 | - } |
|
122 | + /** |
|
123 | + * Require a certain number of parameters to be present. |
|
124 | + * @param int $count |
|
125 | + * @param string $rule |
|
126 | + * @return void |
|
127 | + * @throws InvalidArgumentException |
|
128 | + */ |
|
129 | + protected function requireParameterCount($count, array $parameters, $rule) |
|
130 | + { |
|
131 | + if (count($parameters) < $count) { |
|
132 | + throw new InvalidArgumentException("Validation rule $rule requires at least $count parameters."); |
|
133 | + } |
|
134 | + } |
|
135 | 135 | } |
@@ -16,23 +16,23 @@ discard block |
||
16 | 16 | * @param mixed $value |
17 | 17 | * @return mixed |
18 | 18 | */ |
19 | - abstract protected function getSize($attribute, $value); |
|
19 | + abstract protected function getSize( $attribute, $value ); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Replace all placeholders. |
23 | 23 | * @param string $message |
24 | 24 | * @return string |
25 | 25 | */ |
26 | - protected function replace($message, array $parameters) |
|
26 | + protected function replace( $message, array $parameters ) |
|
27 | 27 | { |
28 | - if (!Str::contains($message, '%s')) { |
|
28 | + if( !Str::contains( $message, '%s' ) ) { |
|
29 | 29 | return $message; |
30 | 30 | } |
31 | - return preg_replace_callback('/(%s)/', function () use (&$parameters) { |
|
32 | - foreach ($parameters as $key => $value) { |
|
33 | - return array_shift($parameters); |
|
31 | + return preg_replace_callback( '/(%s)/', function() use (&$parameters) { |
|
32 | + foreach( $parameters as $key => $value ) { |
|
33 | + return array_shift( $parameters ); |
|
34 | 34 | } |
35 | - }, $message); |
|
35 | + }, $message ); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -42,10 +42,10 @@ discard block |
||
42 | 42 | * @param mixed $value |
43 | 43 | * @return bool |
44 | 44 | */ |
45 | - public function validateAccepted($value) |
|
45 | + public function validateAccepted( $value ) |
|
46 | 46 | { |
47 | 47 | $acceptable = ['yes', 'on', '1', 1, true, 'true']; |
48 | - return $this->validateRequired($value) && in_array($value, $acceptable, true); |
|
48 | + return $this->validateRequired( $value ) && in_array( $value, $acceptable, true ); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -54,10 +54,10 @@ discard block |
||
54 | 54 | * @param mixed $value |
55 | 55 | * @return bool |
56 | 56 | */ |
57 | - public function validateBetween($value, $attribute, array $parameters) |
|
57 | + public function validateBetween( $value, $attribute, array $parameters ) |
|
58 | 58 | { |
59 | - $this->requireParameterCount(2, $parameters, 'between'); |
|
60 | - $size = $this->getSize($attribute, $value); |
|
59 | + $this->requireParameterCount( 2, $parameters, 'between' ); |
|
60 | + $size = $this->getSize( $attribute, $value ); |
|
61 | 61 | return $size >= $parameters[0] && $size <= $parameters[1]; |
62 | 62 | } |
63 | 63 | |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | * @param mixed $value |
67 | 67 | * @return bool |
68 | 68 | */ |
69 | - public function validateEmail($value) |
|
69 | + public function validateEmail( $value ) |
|
70 | 70 | { |
71 | - return false !== filter_var($value, FILTER_VALIDATE_EMAIL); |
|
71 | + return false !== filter_var( $value, FILTER_VALIDATE_EMAIL ); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -77,10 +77,10 @@ discard block |
||
77 | 77 | * @param mixed $value |
78 | 78 | * @return bool |
79 | 79 | */ |
80 | - public function validateMax($value, $attribute, array $parameters) |
|
80 | + public function validateMax( $value, $attribute, array $parameters ) |
|
81 | 81 | { |
82 | - $this->requireParameterCount(1, $parameters, 'max'); |
|
83 | - return $this->getSize($attribute, $value) <= $parameters[0]; |
|
82 | + $this->requireParameterCount( 1, $parameters, 'max' ); |
|
83 | + return $this->getSize( $attribute, $value ) <= $parameters[0]; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | * @param mixed $value |
90 | 90 | * @return bool |
91 | 91 | */ |
92 | - public function validateMin($value, $attribute, array $parameters) |
|
92 | + public function validateMin( $value, $attribute, array $parameters ) |
|
93 | 93 | { |
94 | - $this->requireParameterCount(1, $parameters, 'min'); |
|
95 | - return $this->getSize($attribute, $value) >= $parameters[0]; |
|
94 | + $this->requireParameterCount( 1, $parameters, 'min' ); |
|
95 | + return $this->getSize( $attribute, $value ) >= $parameters[0]; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | * @param mixed $value |
101 | 101 | * @return bool |
102 | 102 | */ |
103 | - public function validateNumber($value) |
|
103 | + public function validateNumber( $value ) |
|
104 | 104 | { |
105 | - return is_numeric($value); |
|
105 | + return is_numeric( $value ); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -110,11 +110,11 @@ discard block |
||
110 | 110 | * @param mixed $value |
111 | 111 | * @return bool |
112 | 112 | */ |
113 | - public function validateRequired($value) |
|
113 | + public function validateRequired( $value ) |
|
114 | 114 | { |
115 | - return is_null($value) |
|
116 | - || (is_string($value) && in_array(trim($value), ['', '[]'])) |
|
117 | - || (is_array($value) && empty($value)) |
|
115 | + return is_null( $value ) |
|
116 | + || (is_string( $value ) && in_array( trim( $value ), ['', '[]'] )) |
|
117 | + || (is_array( $value ) && empty($value)) |
|
118 | 118 | ? false |
119 | 119 | : true; |
120 | 120 | } |
@@ -126,10 +126,10 @@ discard block |
||
126 | 126 | * @return void |
127 | 127 | * @throws InvalidArgumentException |
128 | 128 | */ |
129 | - protected function requireParameterCount($count, array $parameters, $rule) |
|
129 | + protected function requireParameterCount( $count, array $parameters, $rule ) |
|
130 | 130 | { |
131 | - if (count($parameters) < $count) { |
|
132 | - throw new InvalidArgumentException("Validation rule $rule requires at least $count parameters."); |
|
131 | + if( count( $parameters ) < $count ) { |
|
132 | + throw new InvalidArgumentException( "Validation rule $rule requires at least $count parameters." ); |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | } |