Passed
Push — master ( 876108...8633df )
by Paul
06:37
created
plugin/Defaults/ValidateReviewDefaults.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -6,22 +6,22 @@
 block discarded – undo
6 6
 
7 7
 class ValidateReviewDefaults extends Defaults
8 8
 {
9
-    /**
10
-     * @return array
11
-     */
12
-    protected function defaults()
13
-    {
14
-        return [
15
-            'assign_to' => '',
16
-            'category' => '',
17
-            'content' => '',
18
-            'email' => '',
19
-            'form_id' => '',
20
-            'ip_address' => '',
21
-            'name' => '',
22
-            'rating' => '0',
23
-            'terms' => '',
24
-            'title' => '',
25
-        ];
26
-    }
9
+	/**
10
+	 * @return array
11
+	 */
12
+	protected function defaults()
13
+	{
14
+		return [
15
+			'assign_to' => '',
16
+			'category' => '',
17
+			'content' => '',
18
+			'email' => '',
19
+			'form_id' => '',
20
+			'ip_address' => '',
21
+			'name' => '',
22
+			'rating' => '0',
23
+			'terms' => '',
24
+			'title' => '',
25
+		];
26
+	}
27 27
 }
Please login to merge, or discard this patch.
deprecated.php 2 patches
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -3,134 +3,134 @@
 block discarded – undo
3 3
 defined('WPINC') || die;
4 4
 
5 5
 if (apply_filters('site-reviews/support/deprecated/v4', true)) {
6
-    // Unprotected review meta has been deprecated
7
-    add_filter('get_post_metadata', function ($data, $postId, $metaKey, $single) {
8
-        $metaKeys = array_keys(glsr('Defaults\CreateReviewDefaults')->defaults());
9
-        if (!in_array($metaKey, $metaKeys) || glsr()->post_type != get_post_type($postId)) {
10
-            return $data;
11
-        }
12
-        glsr()->deprecated[] = sprintf(
13
-            'The "%1$s" meta_key has been deprecated for Reviews. Please use the protected "_%1$s" meta_key instead.',
14
-            $metaKey
15
-        );
16
-        return get_post_meta($postId, '_'.$metaKey, $single);
17
-    }, 10, 4);
6
+	// Unprotected review meta has been deprecated
7
+	add_filter('get_post_metadata', function ($data, $postId, $metaKey, $single) {
8
+		$metaKeys = array_keys(glsr('Defaults\CreateReviewDefaults')->defaults());
9
+		if (!in_array($metaKey, $metaKeys) || glsr()->post_type != get_post_type($postId)) {
10
+			return $data;
11
+		}
12
+		glsr()->deprecated[] = sprintf(
13
+			'The "%1$s" meta_key has been deprecated for Reviews. Please use the protected "_%1$s" meta_key instead.',
14
+			$metaKey
15
+		);
16
+		return get_post_meta($postId, '_'.$metaKey, $single);
17
+	}, 10, 4);
18 18
 
19
-    // Modules/Html/Template.php
20
-    add_filter('site-reviews/interpolate/reviews', function ($context, $template) {
21
-        $search = '{{ navigation }}';
22
-        if (false !== strpos($template, $search)) {
23
-            $context['navigation'] = $context['pagination'];
24
-            glsr()->deprecated[] = 'The {{ navigation }} template key in "YOUR_THEME/site-reviews/reviews.php" has been deprecated. Please use the {{ pagination }} template key instead.';
25
-        }
26
-        return $context;
27
-    }, 10, 2);
19
+	// Modules/Html/Template.php
20
+	add_filter('site-reviews/interpolate/reviews', function ($context, $template) {
21
+		$search = '{{ navigation }}';
22
+		if (false !== strpos($template, $search)) {
23
+			$context['navigation'] = $context['pagination'];
24
+			glsr()->deprecated[] = 'The {{ navigation }} template key in "YOUR_THEME/site-reviews/reviews.php" has been deprecated. Please use the {{ pagination }} template key instead.';
25
+		}
26
+		return $context;
27
+	}, 10, 2);
28 28
 
29
-    // Database/ReviewManager.php
30
-    add_action('site-reviews/review/created', function ($review) {
31
-        if (has_action('site-reviews/local/review/create')) {
32
-            glsr()->deprecated[] = 'The "site-reviews/local/review/create" hook has been deprecated. Please use the "site-reviews/review/created" hook instead.';
33
-            do_action('site-reviews/local/review/create', (array) get_post($review->ID), (array) $review, $review->ID);
34
-        }
35
-    }, 9);
29
+	// Database/ReviewManager.php
30
+	add_action('site-reviews/review/created', function ($review) {
31
+		if (has_action('site-reviews/local/review/create')) {
32
+			glsr()->deprecated[] = 'The "site-reviews/local/review/create" hook has been deprecated. Please use the "site-reviews/review/created" hook instead.';
33
+			do_action('site-reviews/local/review/create', (array) get_post($review->ID), (array) $review, $review->ID);
34
+		}
35
+	}, 9);
36 36
 
37
-    // Handlers/CreateReview.php
38
-    add_action('site-reviews/review/submitted', function ($review) {
39
-        if (has_action('site-reviews/local/review/submitted')) {
40
-            glsr()->deprecated[] = 'The "site-reviews/local/review/submitted" hook has been deprecated. Please use the "site-reviews/review/submitted" hook instead.';
41
-            do_action('site-reviews/local/review/submitted', null, $review);
42
-        }
43
-        if (has_filter('site-reviews/local/review/submitted/message')) {
44
-            glsr()->deprecated[] = 'The "site-reviews/local/review/submitted/message" hook has been deprecated.';
45
-        }
46
-    }, 9);
37
+	// Handlers/CreateReview.php
38
+	add_action('site-reviews/review/submitted', function ($review) {
39
+		if (has_action('site-reviews/local/review/submitted')) {
40
+			glsr()->deprecated[] = 'The "site-reviews/local/review/submitted" hook has been deprecated. Please use the "site-reviews/review/submitted" hook instead.';
41
+			do_action('site-reviews/local/review/submitted', null, $review);
42
+		}
43
+		if (has_filter('site-reviews/local/review/submitted/message')) {
44
+			glsr()->deprecated[] = 'The "site-reviews/local/review/submitted/message" hook has been deprecated.';
45
+		}
46
+	}, 9);
47 47
 
48
-    // Database/ReviewManager.php
49
-    add_filter('site-reviews/create/review-values', function ($values, $command) {
50
-        if (has_filter('site-reviews/local/review')) {
51
-            glsr()->deprecated[] = 'The "site-reviews/local/review" hook has been deprecated. Please use the "site-reviews/create/review-values" hook instead.';
52
-            return apply_filters('site-reviews/local/review', $values, $command);
53
-        }
54
-        return $values;
55
-    }, 9, 2);
48
+	// Database/ReviewManager.php
49
+	add_filter('site-reviews/create/review-values', function ($values, $command) {
50
+		if (has_filter('site-reviews/local/review')) {
51
+			glsr()->deprecated[] = 'The "site-reviews/local/review" hook has been deprecated. Please use the "site-reviews/create/review-values" hook instead.';
52
+			return apply_filters('site-reviews/local/review', $values, $command);
53
+		}
54
+		return $values;
55
+	}, 9, 2);
56 56
 
57
-    // Handlers/EnqueuePublicAssets.php
58
-    add_filter('site-reviews/enqueue/public/localize', function ($variables) {
59
-        if (has_filter('site-reviews/enqueue/localize')) {
60
-            glsr()->deprecated[] = 'The "site-reviews/enqueue/localize" hook has been deprecated. Please use the "site-reviews/enqueue/public/localize" hook instead.';
61
-            return apply_filters('site-reviews/enqueue/localize', $variables);
62
-        }
63
-        return $variables;
64
-    }, 9);
57
+	// Handlers/EnqueuePublicAssets.php
58
+	add_filter('site-reviews/enqueue/public/localize', function ($variables) {
59
+		if (has_filter('site-reviews/enqueue/localize')) {
60
+			glsr()->deprecated[] = 'The "site-reviews/enqueue/localize" hook has been deprecated. Please use the "site-reviews/enqueue/public/localize" hook instead.';
61
+			return apply_filters('site-reviews/enqueue/localize', $variables);
62
+		}
63
+		return $variables;
64
+	}, 9);
65 65
 
66
-    // Modules/Rating.php
67
-    add_filter('site-reviews/rating/average', function ($average) {
68
-        if (has_filter('site-reviews/average/rating')) {
69
-            glsr()->deprecated[] = 'The "site-reviews/average/rating" hook has been deprecated. Please use the "site-reviews/rating/average" hook instead.';
70
-        }
71
-        return $average;
72
-    }, 9);
66
+	// Modules/Rating.php
67
+	add_filter('site-reviews/rating/average', function ($average) {
68
+		if (has_filter('site-reviews/average/rating')) {
69
+			glsr()->deprecated[] = 'The "site-reviews/average/rating" hook has been deprecated. Please use the "site-reviews/rating/average" hook instead.';
70
+		}
71
+		return $average;
72
+	}, 9);
73 73
 
74
-    // Modules/Rating.php
75
-    add_filter('site-reviews/rating/ranking', function ($ranking) {
76
-        if (has_filter('site-reviews/bayesian/ranking')) {
77
-            glsr()->deprecated[] = 'The "site-reviews/bayesian/ranking" hook has been deprecated. Please use the "site-reviews/rating/ranking" hook instead.';
78
-        }
79
-        return $ranking;
80
-    }, 9);
74
+	// Modules/Rating.php
75
+	add_filter('site-reviews/rating/ranking', function ($ranking) {
76
+		if (has_filter('site-reviews/bayesian/ranking')) {
77
+			glsr()->deprecated[] = 'The "site-reviews/bayesian/ranking" hook has been deprecated. Please use the "site-reviews/rating/ranking" hook instead.';
78
+		}
79
+		return $ranking;
80
+	}, 9);
81 81
 
82
-    // Modules/Html/Partials/SiteReviews.php
83
-    add_filter('site-reviews/review/build/after', function ($renderedFields) {
84
-        if (has_filter('site-reviews/reviews/review/text')) {
85
-            glsr()->deprecated[] = 'The "site-reviews/reviews/review/text" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.';
86
-        }
87
-        if (has_filter('site-reviews/reviews/review/title')) {
88
-            glsr()->deprecated[] = 'The "site-reviews/reviews/review/title" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.';
89
-        }
90
-        return $renderedFields;
91
-    }, 9);
82
+	// Modules/Html/Partials/SiteReviews.php
83
+	add_filter('site-reviews/review/build/after', function ($renderedFields) {
84
+		if (has_filter('site-reviews/reviews/review/text')) {
85
+			glsr()->deprecated[] = 'The "site-reviews/reviews/review/text" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.';
86
+		}
87
+		if (has_filter('site-reviews/reviews/review/title')) {
88
+			glsr()->deprecated[] = 'The "site-reviews/reviews/review/title" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.';
89
+		}
90
+		return $renderedFields;
91
+	}, 9);
92 92
 
93
-    // Modules/Html/Partials/SiteReviews.php
94
-    add_filter('site-reviews/review/build/before', function ($review) {
95
-        if (has_filter('site-reviews/rendered/review')) {
96
-            glsr()->deprecated[] = 'The "site-reviews/rendered/review" hook has been deprecated. Please either use a custom "review.php" template (refer to the documentation), or use the "site-reviews/review/build/after" hook instead.';
97
-        }
98
-        if (has_filter('site-reviews/rendered/review/meta/order')) {
99
-            glsr()->deprecated[] = 'The "site-reviews/rendered/review/meta/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).';
100
-        }
101
-        if (has_filter('site-reviews/rendered/review/order')) {
102
-            glsr()->deprecated[] = 'The "site-reviews/rendered/review/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).';
103
-        }
104
-        if (has_filter('site-reviews/rendered/review-form/login-register')) {
105
-            glsr()->deprecated[] = 'The "site-reviews/rendered/review-form/login-register" hook has been deprecated. Please use a custom "login-register.php" template instead (refer to the documentation).';
106
-        }
107
-        if (has_filter('site-reviews/reviews/navigation_links')) {
108
-            glsr()->deprecated[] = 'The "site-reviews/reviews/navigation_links" hook has been deprecated. Please use a custom "pagination.php" template instead (refer to the documentation).';
109
-        }
110
-        return $review;
111
-    }, 9);
93
+	// Modules/Html/Partials/SiteReviews.php
94
+	add_filter('site-reviews/review/build/before', function ($review) {
95
+		if (has_filter('site-reviews/rendered/review')) {
96
+			glsr()->deprecated[] = 'The "site-reviews/rendered/review" hook has been deprecated. Please either use a custom "review.php" template (refer to the documentation), or use the "site-reviews/review/build/after" hook instead.';
97
+		}
98
+		if (has_filter('site-reviews/rendered/review/meta/order')) {
99
+			glsr()->deprecated[] = 'The "site-reviews/rendered/review/meta/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).';
100
+		}
101
+		if (has_filter('site-reviews/rendered/review/order')) {
102
+			glsr()->deprecated[] = 'The "site-reviews/rendered/review/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).';
103
+		}
104
+		if (has_filter('site-reviews/rendered/review-form/login-register')) {
105
+			glsr()->deprecated[] = 'The "site-reviews/rendered/review-form/login-register" hook has been deprecated. Please use a custom "login-register.php" template instead (refer to the documentation).';
106
+		}
107
+		if (has_filter('site-reviews/reviews/navigation_links')) {
108
+			glsr()->deprecated[] = 'The "site-reviews/reviews/navigation_links" hook has been deprecated. Please use a custom "pagination.php" template instead (refer to the documentation).';
109
+		}
110
+		return $review;
111
+	}, 9);
112 112
 
113
-    add_filter('site-reviews/validate/custom', function ($result, $request) {
114
-        if (has_filter('site-reviews/validate/review/submission')) {
115
-            glsr_log()->warning('The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.');
116
-            return apply_filters('site-reviews/validate/review/submission', $result, $request);
117
-        }
118
-        return $result;
119
-    }, 9, 2);
113
+	add_filter('site-reviews/validate/custom', function ($result, $request) {
114
+		if (has_filter('site-reviews/validate/review/submission')) {
115
+			glsr_log()->warning('The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.');
116
+			return apply_filters('site-reviews/validate/review/submission', $result, $request);
117
+		}
118
+		return $result;
119
+	}, 9, 2);
120 120
 
121
-    add_filter('site-reviews/views/file', function ($file, $view, $data) {
122
-        if (has_filter('site-reviews/addon/views/file')) {
123
-            glsr()->deprecated[] = 'The "site-reviews/addon/views/file" hook has been deprecated. Please use the "site-reviews/views/file" hook instead.';
124
-            $file = apply_filters('site-reviews/addon/views/file', $file, $view, $data);
125
-        }
126
-        return $file;
127
-    }, 9, 3);
121
+	add_filter('site-reviews/views/file', function ($file, $view, $data) {
122
+		if (has_filter('site-reviews/addon/views/file')) {
123
+			glsr()->deprecated[] = 'The "site-reviews/addon/views/file" hook has been deprecated. Please use the "site-reviews/views/file" hook instead.';
124
+			$file = apply_filters('site-reviews/addon/views/file', $file, $view, $data);
125
+		}
126
+		return $file;
127
+	}, 9, 3);
128 128
 }
129 129
 
130 130
 add_action('wp_footer', function () {
131
-    $notices = array_keys(array_flip(glsr()->deprecated));
132
-    natsort($notices);
133
-    foreach ($notices as $notice) {
134
-        glsr_log()->warning($notice);
135
-    }
131
+	$notices = array_keys(array_flip(glsr()->deprecated));
132
+	natsort($notices);
133
+	foreach ($notices as $notice) {
134
+		glsr_log()->warning($notice);
135
+	}
136 136
 });
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -1,136 +1,136 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-defined('WPINC') || die;
3
+defined( 'WPINC' ) || die;
4 4
 
5
-if (apply_filters('site-reviews/support/deprecated/v4', true)) {
5
+if( apply_filters( 'site-reviews/support/deprecated/v4', true ) ) {
6 6
     // Unprotected review meta has been deprecated
7
-    add_filter('get_post_metadata', function ($data, $postId, $metaKey, $single) {
8
-        $metaKeys = array_keys(glsr('Defaults\CreateReviewDefaults')->defaults());
9
-        if (!in_array($metaKey, $metaKeys) || glsr()->post_type != get_post_type($postId)) {
7
+    add_filter( 'get_post_metadata', function( $data, $postId, $metaKey, $single ) {
8
+        $metaKeys = array_keys( glsr( 'Defaults\CreateReviewDefaults' )->defaults() );
9
+        if( !in_array( $metaKey, $metaKeys ) || glsr()->post_type != get_post_type( $postId ) ) {
10 10
             return $data;
11 11
         }
12 12
         glsr()->deprecated[] = sprintf(
13 13
             'The "%1$s" meta_key has been deprecated for Reviews. Please use the protected "_%1$s" meta_key instead.',
14 14
             $metaKey
15 15
         );
16
-        return get_post_meta($postId, '_'.$metaKey, $single);
17
-    }, 10, 4);
16
+        return get_post_meta( $postId, '_'.$metaKey, $single );
17
+    }, 10, 4 );
18 18
 
19 19
     // Modules/Html/Template.php
20
-    add_filter('site-reviews/interpolate/reviews', function ($context, $template) {
20
+    add_filter( 'site-reviews/interpolate/reviews', function( $context, $template ) {
21 21
         $search = '{{ navigation }}';
22
-        if (false !== strpos($template, $search)) {
22
+        if( false !== strpos( $template, $search ) ) {
23 23
             $context['navigation'] = $context['pagination'];
24 24
             glsr()->deprecated[] = 'The {{ navigation }} template key in "YOUR_THEME/site-reviews/reviews.php" has been deprecated. Please use the {{ pagination }} template key instead.';
25 25
         }
26 26
         return $context;
27
-    }, 10, 2);
27
+    }, 10, 2 );
28 28
 
29 29
     // Database/ReviewManager.php
30
-    add_action('site-reviews/review/created', function ($review) {
31
-        if (has_action('site-reviews/local/review/create')) {
30
+    add_action( 'site-reviews/review/created', function( $review ) {
31
+        if( has_action( 'site-reviews/local/review/create' ) ) {
32 32
             glsr()->deprecated[] = 'The "site-reviews/local/review/create" hook has been deprecated. Please use the "site-reviews/review/created" hook instead.';
33
-            do_action('site-reviews/local/review/create', (array) get_post($review->ID), (array) $review, $review->ID);
33
+            do_action( 'site-reviews/local/review/create', (array)get_post( $review->ID ), (array)$review, $review->ID );
34 34
         }
35
-    }, 9);
35
+    }, 9 );
36 36
 
37 37
     // Handlers/CreateReview.php
38
-    add_action('site-reviews/review/submitted', function ($review) {
39
-        if (has_action('site-reviews/local/review/submitted')) {
38
+    add_action( 'site-reviews/review/submitted', function( $review ) {
39
+        if( has_action( 'site-reviews/local/review/submitted' ) ) {
40 40
             glsr()->deprecated[] = 'The "site-reviews/local/review/submitted" hook has been deprecated. Please use the "site-reviews/review/submitted" hook instead.';
41
-            do_action('site-reviews/local/review/submitted', null, $review);
41
+            do_action( 'site-reviews/local/review/submitted', null, $review );
42 42
         }
43
-        if (has_filter('site-reviews/local/review/submitted/message')) {
43
+        if( has_filter( 'site-reviews/local/review/submitted/message' ) ) {
44 44
             glsr()->deprecated[] = 'The "site-reviews/local/review/submitted/message" hook has been deprecated.';
45 45
         }
46
-    }, 9);
46
+    }, 9 );
47 47
 
48 48
     // Database/ReviewManager.php
49
-    add_filter('site-reviews/create/review-values', function ($values, $command) {
50
-        if (has_filter('site-reviews/local/review')) {
49
+    add_filter( 'site-reviews/create/review-values', function( $values, $command ) {
50
+        if( has_filter( 'site-reviews/local/review' ) ) {
51 51
             glsr()->deprecated[] = 'The "site-reviews/local/review" hook has been deprecated. Please use the "site-reviews/create/review-values" hook instead.';
52
-            return apply_filters('site-reviews/local/review', $values, $command);
52
+            return apply_filters( 'site-reviews/local/review', $values, $command );
53 53
         }
54 54
         return $values;
55
-    }, 9, 2);
55
+    }, 9, 2 );
56 56
 
57 57
     // Handlers/EnqueuePublicAssets.php
58
-    add_filter('site-reviews/enqueue/public/localize', function ($variables) {
59
-        if (has_filter('site-reviews/enqueue/localize')) {
58
+    add_filter( 'site-reviews/enqueue/public/localize', function( $variables ) {
59
+        if( has_filter( 'site-reviews/enqueue/localize' ) ) {
60 60
             glsr()->deprecated[] = 'The "site-reviews/enqueue/localize" hook has been deprecated. Please use the "site-reviews/enqueue/public/localize" hook instead.';
61
-            return apply_filters('site-reviews/enqueue/localize', $variables);
61
+            return apply_filters( 'site-reviews/enqueue/localize', $variables );
62 62
         }
63 63
         return $variables;
64
-    }, 9);
64
+    }, 9 );
65 65
 
66 66
     // Modules/Rating.php
67
-    add_filter('site-reviews/rating/average', function ($average) {
68
-        if (has_filter('site-reviews/average/rating')) {
67
+    add_filter( 'site-reviews/rating/average', function( $average ) {
68
+        if( has_filter( 'site-reviews/average/rating' ) ) {
69 69
             glsr()->deprecated[] = 'The "site-reviews/average/rating" hook has been deprecated. Please use the "site-reviews/rating/average" hook instead.';
70 70
         }
71 71
         return $average;
72
-    }, 9);
72
+    }, 9 );
73 73
 
74 74
     // Modules/Rating.php
75
-    add_filter('site-reviews/rating/ranking', function ($ranking) {
76
-        if (has_filter('site-reviews/bayesian/ranking')) {
75
+    add_filter( 'site-reviews/rating/ranking', function( $ranking ) {
76
+        if( has_filter( 'site-reviews/bayesian/ranking' ) ) {
77 77
             glsr()->deprecated[] = 'The "site-reviews/bayesian/ranking" hook has been deprecated. Please use the "site-reviews/rating/ranking" hook instead.';
78 78
         }
79 79
         return $ranking;
80
-    }, 9);
80
+    }, 9 );
81 81
 
82 82
     // Modules/Html/Partials/SiteReviews.php
83
-    add_filter('site-reviews/review/build/after', function ($renderedFields) {
84
-        if (has_filter('site-reviews/reviews/review/text')) {
83
+    add_filter( 'site-reviews/review/build/after', function( $renderedFields ) {
84
+        if( has_filter( 'site-reviews/reviews/review/text' ) ) {
85 85
             glsr()->deprecated[] = 'The "site-reviews/reviews/review/text" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.';
86 86
         }
87
-        if (has_filter('site-reviews/reviews/review/title')) {
87
+        if( has_filter( 'site-reviews/reviews/review/title' ) ) {
88 88
             glsr()->deprecated[] = 'The "site-reviews/reviews/review/title" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.';
89 89
         }
90 90
         return $renderedFields;
91
-    }, 9);
91
+    }, 9 );
92 92
 
93 93
     // Modules/Html/Partials/SiteReviews.php
94
-    add_filter('site-reviews/review/build/before', function ($review) {
95
-        if (has_filter('site-reviews/rendered/review')) {
94
+    add_filter( 'site-reviews/review/build/before', function( $review ) {
95
+        if( has_filter( 'site-reviews/rendered/review' ) ) {
96 96
             glsr()->deprecated[] = 'The "site-reviews/rendered/review" hook has been deprecated. Please either use a custom "review.php" template (refer to the documentation), or use the "site-reviews/review/build/after" hook instead.';
97 97
         }
98
-        if (has_filter('site-reviews/rendered/review/meta/order')) {
98
+        if( has_filter( 'site-reviews/rendered/review/meta/order' ) ) {
99 99
             glsr()->deprecated[] = 'The "site-reviews/rendered/review/meta/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).';
100 100
         }
101
-        if (has_filter('site-reviews/rendered/review/order')) {
101
+        if( has_filter( 'site-reviews/rendered/review/order' ) ) {
102 102
             glsr()->deprecated[] = 'The "site-reviews/rendered/review/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).';
103 103
         }
104
-        if (has_filter('site-reviews/rendered/review-form/login-register')) {
104
+        if( has_filter( 'site-reviews/rendered/review-form/login-register' ) ) {
105 105
             glsr()->deprecated[] = 'The "site-reviews/rendered/review-form/login-register" hook has been deprecated. Please use a custom "login-register.php" template instead (refer to the documentation).';
106 106
         }
107
-        if (has_filter('site-reviews/reviews/navigation_links')) {
107
+        if( has_filter( 'site-reviews/reviews/navigation_links' ) ) {
108 108
             glsr()->deprecated[] = 'The "site-reviews/reviews/navigation_links" hook has been deprecated. Please use a custom "pagination.php" template instead (refer to the documentation).';
109 109
         }
110 110
         return $review;
111
-    }, 9);
111
+    }, 9 );
112 112
 
113
-    add_filter('site-reviews/validate/custom', function ($result, $request) {
114
-        if (has_filter('site-reviews/validate/review/submission')) {
115
-            glsr_log()->warning('The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.');
116
-            return apply_filters('site-reviews/validate/review/submission', $result, $request);
113
+    add_filter( 'site-reviews/validate/custom', function( $result, $request ) {
114
+        if( has_filter( 'site-reviews/validate/review/submission' ) ) {
115
+            glsr_log()->warning( 'The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.' );
116
+            return apply_filters( 'site-reviews/validate/review/submission', $result, $request );
117 117
         }
118 118
         return $result;
119
-    }, 9, 2);
119
+    }, 9, 2 );
120 120
 
121
-    add_filter('site-reviews/views/file', function ($file, $view, $data) {
122
-        if (has_filter('site-reviews/addon/views/file')) {
121
+    add_filter( 'site-reviews/views/file', function( $file, $view, $data ) {
122
+        if( has_filter( 'site-reviews/addon/views/file' ) ) {
123 123
             glsr()->deprecated[] = 'The "site-reviews/addon/views/file" hook has been deprecated. Please use the "site-reviews/views/file" hook instead.';
124
-            $file = apply_filters('site-reviews/addon/views/file', $file, $view, $data);
124
+            $file = apply_filters( 'site-reviews/addon/views/file', $file, $view, $data );
125 125
         }
126 126
         return $file;
127
-    }, 9, 3);
127
+    }, 9, 3 );
128 128
 }
129 129
 
130
-add_action('wp_footer', function () {
131
-    $notices = array_keys(array_flip(glsr()->deprecated));
132
-    natsort($notices);
133
-    foreach ($notices as $notice) {
134
-        glsr_log()->warning($notice);
130
+add_action( 'wp_footer', function() {
131
+    $notices = array_keys( array_flip( glsr()->deprecated ) );
132
+    natsort( $notices );
133
+    foreach( $notices as $notice ) {
134
+        glsr_log()->warning( $notice );
135 135
     }
136 136
 });
Please login to merge, or discard this patch.
plugin/Modules/Schema.php 2 patches
Indentation   +296 added lines, -296 removed lines patch added patch discarded remove patch
@@ -12,322 +12,322 @@
 block discarded – undo
12 12
 
13 13
 class Schema
14 14
 {
15
-    /**
16
-     * @var array
17
-     */
18
-    protected $args;
15
+	/**
16
+	 * @var array
17
+	 */
18
+	protected $args;
19 19
 
20
-    /**
21
-     * @var array
22
-     */
23
-    protected $keyValues = [];
20
+	/**
21
+	 * @var array
22
+	 */
23
+	protected $keyValues = [];
24 24
 
25
-    /**
26
-     * @var array
27
-     */
28
-    protected $ratingCounts;
25
+	/**
26
+	 * @var array
27
+	 */
28
+	protected $ratingCounts;
29 29
 
30
-    /**
31
-     * @return array
32
-     */
33
-    public function build(array $args = [])
34
-    {
35
-        $this->args = $args;
36
-        $schema = $this->buildSummary($args);
37
-        $reviews = [];
38
-        foreach (glsr(ReviewManager::class)->get($this->args) as $review) {
39
-            // Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews.
40
-            // @see https://developers.google.com/search/docs/data-types/review
41
-            if ('local' != $review->review_type) {
42
-                continue;
43
-            }
44
-            $reviews[] = $this->buildReview($review);
45
-        }
46
-        if (!empty($reviews)) {
47
-            array_walk($reviews, function (&$review) {
48
-                unset($review['@context']);
49
-                unset($review['itemReviewed']);
50
-            });
51
-            $schema['review'] = $reviews;
52
-        }
53
-        return $schema;
54
-    }
30
+	/**
31
+	 * @return array
32
+	 */
33
+	public function build(array $args = [])
34
+	{
35
+		$this->args = $args;
36
+		$schema = $this->buildSummary($args);
37
+		$reviews = [];
38
+		foreach (glsr(ReviewManager::class)->get($this->args) as $review) {
39
+			// Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews.
40
+			// @see https://developers.google.com/search/docs/data-types/review
41
+			if ('local' != $review->review_type) {
42
+				continue;
43
+			}
44
+			$reviews[] = $this->buildReview($review);
45
+		}
46
+		if (!empty($reviews)) {
47
+			array_walk($reviews, function (&$review) {
48
+				unset($review['@context']);
49
+				unset($review['itemReviewed']);
50
+			});
51
+			$schema['review'] = $reviews;
52
+		}
53
+		return $schema;
54
+	}
55 55
 
56
-    /**
57
-     * @param array|null $args
58
-     * @return array
59
-     */
60
-    public function buildSummary($args = null)
61
-    {
62
-        if (is_array($args)) {
63
-            $this->args = $args;
64
-        }
65
-        $buildSummary = Helper::buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor');
66
-        $count = array_sum($this->getRatingCounts());
67
-        $schema = method_exists($this, $buildSummary)
68
-            ? $this->$buildSummary()
69
-            : $this->buildSummaryForCustom();
70
-        if (!empty($count)) {
71
-            $schema->aggregateRating(
72
-                $this->getSchemaType('AggregateRating')
73
-                    ->ratingValue($this->getRatingValue())
74
-                    ->reviewCount($count)
75
-                    ->bestRating(glsr()->constant('MAX_RATING', Rating::class))
76
-                    ->worstRating(glsr()->constant('MIN_RATING', Rating::class))
77
-            );
78
-        }
79
-        $schema = $schema->toArray();
80
-        return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args);
81
-    }
56
+	/**
57
+	 * @param array|null $args
58
+	 * @return array
59
+	 */
60
+	public function buildSummary($args = null)
61
+	{
62
+		if (is_array($args)) {
63
+			$this->args = $args;
64
+		}
65
+		$buildSummary = Helper::buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor');
66
+		$count = array_sum($this->getRatingCounts());
67
+		$schema = method_exists($this, $buildSummary)
68
+			? $this->$buildSummary()
69
+			: $this->buildSummaryForCustom();
70
+		if (!empty($count)) {
71
+			$schema->aggregateRating(
72
+				$this->getSchemaType('AggregateRating')
73
+					->ratingValue($this->getRatingValue())
74
+					->reviewCount($count)
75
+					->bestRating(glsr()->constant('MAX_RATING', Rating::class))
76
+					->worstRating(glsr()->constant('MIN_RATING', Rating::class))
77
+			);
78
+		}
79
+		$schema = $schema->toArray();
80
+		return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args);
81
+	}
82 82
 
83
-    /**
84
-     * @return void
85
-     */
86
-    public function render()
87
-    {
88
-        if (empty(glsr()->schemas)) {
89
-            return;
90
-        }
91
-        printf('<script type="application/ld+json">%s</script>', json_encode(
92
-            apply_filters('site-reviews/schema/all', glsr()->schemas),
93
-            JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
94
-        ));
95
-    }
83
+	/**
84
+	 * @return void
85
+	 */
86
+	public function render()
87
+	{
88
+		if (empty(glsr()->schemas)) {
89
+			return;
90
+		}
91
+		printf('<script type="application/ld+json">%s</script>', json_encode(
92
+			apply_filters('site-reviews/schema/all', glsr()->schemas),
93
+			JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
94
+		));
95
+	}
96 96
 
97
-    /**
98
-     * @return void
99
-     */
100
-    public function store(array $schema)
101
-    {
102
-        $schemas = glsr()->schemas;
103
-        $schemas[] = $schema;
104
-        glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas)));
105
-    }
97
+	/**
98
+	 * @return void
99
+	 */
100
+	public function store(array $schema)
101
+	{
102
+		$schemas = glsr()->schemas;
103
+		$schemas[] = $schema;
104
+		glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas)));
105
+	}
106 106
 
107
-    /**
108
-     * @param Review $review
109
-     * @return array
110
-     */
111
-    protected function buildReview($review)
112
-    {
113
-        $schema = $this->getSchemaType('Review')
114
-            ->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) {
115
-                $schema->name($review->title);
116
-            })
117
-            ->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) {
118
-                $schema->reviewBody($review->content);
119
-            })
120
-            ->datePublished((new DateTime($review->date)))
121
-            ->author($this->getSchemaType('Person')->name($review->author))
122
-            ->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name')));
123
-        if (!empty($review->rating)) {
124
-            $schema->reviewRating(
125
-                $this->getSchemaType('Rating')
126
-                    ->ratingValue($review->rating)
127
-                    ->bestRating(glsr()->constant('MAX_RATING', Rating::class))
128
-                    ->worstRating(glsr()->constant('MIN_RATING', Rating::class))
129
-            );
130
-        }
131
-        return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args);
132
-    }
107
+	/**
108
+	 * @param Review $review
109
+	 * @return array
110
+	 */
111
+	protected function buildReview($review)
112
+	{
113
+		$schema = $this->getSchemaType('Review')
114
+			->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) {
115
+				$schema->name($review->title);
116
+			})
117
+			->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) {
118
+				$schema->reviewBody($review->content);
119
+			})
120
+			->datePublished((new DateTime($review->date)))
121
+			->author($this->getSchemaType('Person')->name($review->author))
122
+			->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name')));
123
+		if (!empty($review->rating)) {
124
+			$schema->reviewRating(
125
+				$this->getSchemaType('Rating')
126
+					->ratingValue($review->rating)
127
+					->bestRating(glsr()->constant('MAX_RATING', Rating::class))
128
+					->worstRating(glsr()->constant('MIN_RATING', Rating::class))
129
+			);
130
+		}
131
+		return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args);
132
+	}
133 133
 
134
-    /**
135
-     * @param mixed $schema
136
-     * @return mixed
137
-     */
138
-    protected function buildSchemaValues($schema, array $values = [])
139
-    {
140
-        foreach ($values as $value) {
141
-            $option = $this->getSchemaOptionValue($value);
142
-            if (empty($option)) {
143
-                continue;
144
-            }
145
-            $schema->$value($option);
146
-        }
147
-        return $schema;
148
-    }
134
+	/**
135
+	 * @param mixed $schema
136
+	 * @return mixed
137
+	 */
138
+	protected function buildSchemaValues($schema, array $values = [])
139
+	{
140
+		foreach ($values as $value) {
141
+			$option = $this->getSchemaOptionValue($value);
142
+			if (empty($option)) {
143
+				continue;
144
+			}
145
+			$schema->$value($option);
146
+		}
147
+		return $schema;
148
+	}
149 149
 
150
-    /**
151
-     * @return mixed
152
-     */
153
-    protected function buildSummaryForCustom()
154
-    {
155
-        return $this->buildSchemaValues($this->getSchemaType(), [
156
-            'description', 'image', 'name', 'url',
157
-        ]);
158
-    }
150
+	/**
151
+	 * @return mixed
152
+	 */
153
+	protected function buildSummaryForCustom()
154
+	{
155
+		return $this->buildSchemaValues($this->getSchemaType(), [
156
+			'description', 'image', 'name', 'url',
157
+		]);
158
+	}
159 159
 
160
-    /**
161
-     * @return mixed
162
-     */
163
-    protected function buildSummaryForLocalBusiness()
164
-    {
165
-        return $this->buildSchemaValues($this->buildSummaryForCustom(), [
166
-            'address', 'priceRange', 'telephone',
167
-        ]);
168
-    }
160
+	/**
161
+	 * @return mixed
162
+	 */
163
+	protected function buildSummaryForLocalBusiness()
164
+	{
165
+		return $this->buildSchemaValues($this->buildSummaryForCustom(), [
166
+			'address', 'priceRange', 'telephone',
167
+		]);
168
+	}
169 169
 
170
-    /**
171
-     * @return mixed
172
-     */
173
-    protected function buildSummaryForProduct()
174
-    {
175
-        $offerType = $this->getSchemaOption('offerType', 'AggregateOffer');
176
-        $offers = $this->buildSchemaValues($this->getSchemaType($offerType), [
177
-            'highPrice', 'lowPrice', 'price', 'priceCurrency',
178
-        ]);
179
-        return $this->buildSummaryForCustom()
180
-            ->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) {
181
-                $schema->offers($offers);
182
-            })
183
-            ->setProperty('@id', $this->getSchemaOptionValue('url').'#product');
184
-    }
170
+	/**
171
+	 * @return mixed
172
+	 */
173
+	protected function buildSummaryForProduct()
174
+	{
175
+		$offerType = $this->getSchemaOption('offerType', 'AggregateOffer');
176
+		$offers = $this->buildSchemaValues($this->getSchemaType($offerType), [
177
+			'highPrice', 'lowPrice', 'price', 'priceCurrency',
178
+		]);
179
+		return $this->buildSummaryForCustom()
180
+			->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) {
181
+				$schema->offers($offers);
182
+			})
183
+			->setProperty('@id', $this->getSchemaOptionValue('url').'#product');
184
+	}
185 185
 
186
-    /**
187
-     * @return array
188
-     */
189
-    protected function getRatingCounts()
190
-    {
191
-        if (!isset($this->ratingCounts)) {
192
-            $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args);
193
-        }
194
-        return $this->ratingCounts;
195
-    }
186
+	/**
187
+	 * @return array
188
+	 */
189
+	protected function getRatingCounts()
190
+	{
191
+		if (!isset($this->ratingCounts)) {
192
+			$this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args);
193
+		}
194
+		return $this->ratingCounts;
195
+	}
196 196
 
197
-    /**
198
-     * @return int|float
199
-     */
200
-    protected function getRatingValue()
201
-    {
202
-        return glsr(Rating::class)->getAverage($this->getRatingCounts());
203
-    }
197
+	/**
198
+	 * @return int|float
199
+	 */
200
+	protected function getRatingValue()
201
+	{
202
+		return glsr(Rating::class)->getAverage($this->getRatingCounts());
203
+	}
204 204
 
205
-    /**
206
-     * @param string $option
207
-     * @param string $fallback
208
-     * @return string
209
-     */
210
-    protected function getSchemaOption($option, $fallback)
211
-    {
212
-        $option = strtolower($option);
213
-        if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) {
214
-            return $schemaOption;
215
-        }
216
-        $setting = glsr(OptionManager::class)->get('settings.schema.'.$option);
217
-        if (is_array($setting)) {
218
-            return $this->getSchemaOptionDefault($setting, $fallback);
219
-        }
220
-        return !empty($setting)
221
-            ? $setting
222
-            : $fallback;
223
-    }
205
+	/**
206
+	 * @param string $option
207
+	 * @param string $fallback
208
+	 * @return string
209
+	 */
210
+	protected function getSchemaOption($option, $fallback)
211
+	{
212
+		$option = strtolower($option);
213
+		if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) {
214
+			return $schemaOption;
215
+		}
216
+		$setting = glsr(OptionManager::class)->get('settings.schema.'.$option);
217
+		if (is_array($setting)) {
218
+			return $this->getSchemaOptionDefault($setting, $fallback);
219
+		}
220
+		return !empty($setting)
221
+			? $setting
222
+			: $fallback;
223
+	}
224 224
 
225
-    /**
226
-     * @param string $fallback
227
-     * @return string
228
-     */
229
-    protected function getSchemaOptionDefault(array $setting, $fallback)
230
-    {
231
-        $setting = wp_parse_args($setting, [
232
-            'custom' => '',
233
-            'default' => $fallback,
234
-        ]);
235
-        return 'custom' != $setting['default']
236
-            ? $setting['default']
237
-            : $setting['custom'];
238
-    }
225
+	/**
226
+	 * @param string $fallback
227
+	 * @return string
228
+	 */
229
+	protected function getSchemaOptionDefault(array $setting, $fallback)
230
+	{
231
+		$setting = wp_parse_args($setting, [
232
+			'custom' => '',
233
+			'default' => $fallback,
234
+		]);
235
+		return 'custom' != $setting['default']
236
+			? $setting['default']
237
+			: $setting['custom'];
238
+	}
239 239
 
240
-    /**
241
-     * @param string $option
242
-     * @param string $fallback
243
-     * @return void|string
244
-     */
245
-    protected function getSchemaOptionValue($option, $fallback = 'post')
246
-    {
247
-        if (array_key_exists($option, $this->keyValues)) {
248
-            return $this->keyValues[$option];
249
-        }
250
-        $value = $this->getSchemaOption($option, $fallback);
251
-        if ($value != $fallback) {
252
-            return $this->setAndGetKeyValue($option, $value);
253
-        }
254
-        if (!is_single() && !is_page()) {
255
-            return;
256
-        }
257
-        $method = Helper::buildMethodName($option, 'getThing');
258
-        if (method_exists($this, $method)) {
259
-            return $this->setAndGetKeyValue($option, $this->$method());
260
-        }
261
-    }
240
+	/**
241
+	 * @param string $option
242
+	 * @param string $fallback
243
+	 * @return void|string
244
+	 */
245
+	protected function getSchemaOptionValue($option, $fallback = 'post')
246
+	{
247
+		if (array_key_exists($option, $this->keyValues)) {
248
+			return $this->keyValues[$option];
249
+		}
250
+		$value = $this->getSchemaOption($option, $fallback);
251
+		if ($value != $fallback) {
252
+			return $this->setAndGetKeyValue($option, $value);
253
+		}
254
+		if (!is_single() && !is_page()) {
255
+			return;
256
+		}
257
+		$method = Helper::buildMethodName($option, 'getThing');
258
+		if (method_exists($this, $method)) {
259
+			return $this->setAndGetKeyValue($option, $this->$method());
260
+		}
261
+	}
262 262
 
263
-    /**
264
-     * @param string|null $type
265
-     * @return mixed
266
-     */
267
-    protected function getSchemaType($type = null)
268
-    {
269
-        if (!is_string($type)) {
270
-            $type = $this->getSchemaOption('type', 'LocalBusiness');
271
-        }
272
-        $className = Helper::buildClassName($type, 'Modules\Schema');
273
-        return class_exists($className)
274
-            ? new $className()
275
-            : new UnknownType($type);
276
-    }
263
+	/**
264
+	 * @param string|null $type
265
+	 * @return mixed
266
+	 */
267
+	protected function getSchemaType($type = null)
268
+	{
269
+		if (!is_string($type)) {
270
+			$type = $this->getSchemaOption('type', 'LocalBusiness');
271
+		}
272
+		$className = Helper::buildClassName($type, 'Modules\Schema');
273
+		return class_exists($className)
274
+			? new $className()
275
+			: new UnknownType($type);
276
+	}
277 277
 
278
-    /**
279
-     * @return string
280
-     */
281
-    protected function getThingDescription()
282
-    {
283
-        $post = get_post();
284
-        $text = Arr::get($post, 'post_excerpt');
285
-        if (empty($text)) {
286
-            $text = Arr::get($post, 'post_content');
287
-        }
288
-        if (function_exists('excerpt_remove_blocks')) {
289
-            $text = excerpt_remove_blocks($text);
290
-        }
291
-        $text = strip_shortcodes($text);
292
-        $text = wpautop($text);
293
-        $text = wptexturize($text);
294
-        $text = wp_strip_all_tags($text);
295
-        $text = str_replace(']]>', ']]&gt;', $text);
296
-        return wp_trim_words($text, apply_filters('excerpt_length', 55));
297
-    }
278
+	/**
279
+	 * @return string
280
+	 */
281
+	protected function getThingDescription()
282
+	{
283
+		$post = get_post();
284
+		$text = Arr::get($post, 'post_excerpt');
285
+		if (empty($text)) {
286
+			$text = Arr::get($post, 'post_content');
287
+		}
288
+		if (function_exists('excerpt_remove_blocks')) {
289
+			$text = excerpt_remove_blocks($text);
290
+		}
291
+		$text = strip_shortcodes($text);
292
+		$text = wpautop($text);
293
+		$text = wptexturize($text);
294
+		$text = wp_strip_all_tags($text);
295
+		$text = str_replace(']]>', ']]&gt;', $text);
296
+		return wp_trim_words($text, apply_filters('excerpt_length', 55));
297
+	}
298 298
 
299
-    /**
300
-     * @return string
301
-     */
302
-    protected function getThingImage()
303
-    {
304
-        return (string) get_the_post_thumbnail_url(null, 'large');
305
-    }
299
+	/**
300
+	 * @return string
301
+	 */
302
+	protected function getThingImage()
303
+	{
304
+		return (string) get_the_post_thumbnail_url(null, 'large');
305
+	}
306 306
 
307
-    /**
308
-     * @return string
309
-     */
310
-    protected function getThingName()
311
-    {
312
-        return get_the_title();
313
-    }
307
+	/**
308
+	 * @return string
309
+	 */
310
+	protected function getThingName()
311
+	{
312
+		return get_the_title();
313
+	}
314 314
 
315
-    /**
316
-     * @return string
317
-     */
318
-    protected function getThingUrl()
319
-    {
320
-        return (string) get_the_permalink();
321
-    }
315
+	/**
316
+	 * @return string
317
+	 */
318
+	protected function getThingUrl()
319
+	{
320
+		return (string) get_the_permalink();
321
+	}
322 322
 
323
-    /**
324
-     * @param string $option
325
-     * @param string $value
326
-     * @return string
327
-     */
328
-    protected function setAndGetKeyValue($option, $value)
329
-    {
330
-        $this->keyValues[$option] = $value;
331
-        return $value;
332
-    }
323
+	/**
324
+	 * @param string $option
325
+	 * @param string $value
326
+	 * @return string
327
+	 */
328
+	protected function setAndGetKeyValue($option, $value)
329
+	{
330
+		$this->keyValues[$option] = $value;
331
+		return $value;
332
+	}
333 333
 }
Please login to merge, or discard this patch.
Spacing   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -30,21 +30,21 @@  discard block
 block discarded – undo
30 30
     /**
31 31
      * @return array
32 32
      */
33
-    public function build(array $args = [])
33
+    public function build( array $args = [] )
34 34
     {
35 35
         $this->args = $args;
36
-        $schema = $this->buildSummary($args);
36
+        $schema = $this->buildSummary( $args );
37 37
         $reviews = [];
38
-        foreach (glsr(ReviewManager::class)->get($this->args) as $review) {
38
+        foreach( glsr( ReviewManager::class )->get( $this->args ) as $review ) {
39 39
             // Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews.
40 40
             // @see https://developers.google.com/search/docs/data-types/review
41
-            if ('local' != $review->review_type) {
41
+            if( 'local' != $review->review_type ) {
42 42
                 continue;
43 43
             }
44
-            $reviews[] = $this->buildReview($review);
44
+            $reviews[] = $this->buildReview( $review );
45 45
         }
46
-        if (!empty($reviews)) {
47
-            array_walk($reviews, function (&$review) {
46
+        if( !empty($reviews) ) {
47
+            array_walk( $reviews, function( &$review ) {
48 48
                 unset($review['@context']);
49 49
                 unset($review['itemReviewed']);
50 50
             });
@@ -57,27 +57,27 @@  discard block
 block discarded – undo
57 57
      * @param array|null $args
58 58
      * @return array
59 59
      */
60
-    public function buildSummary($args = null)
60
+    public function buildSummary( $args = null )
61 61
     {
62
-        if (is_array($args)) {
62
+        if( is_array( $args ) ) {
63 63
             $this->args = $args;
64 64
         }
65
-        $buildSummary = Helper::buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor');
66
-        $count = array_sum($this->getRatingCounts());
67
-        $schema = method_exists($this, $buildSummary)
65
+        $buildSummary = Helper::buildMethodName( $this->getSchemaOptionValue( 'type' ), 'buildSummaryFor' );
66
+        $count = array_sum( $this->getRatingCounts() );
67
+        $schema = method_exists( $this, $buildSummary )
68 68
             ? $this->$buildSummary()
69 69
             : $this->buildSummaryForCustom();
70
-        if (!empty($count)) {
70
+        if( !empty($count) ) {
71 71
             $schema->aggregateRating(
72
-                $this->getSchemaType('AggregateRating')
73
-                    ->ratingValue($this->getRatingValue())
74
-                    ->reviewCount($count)
75
-                    ->bestRating(glsr()->constant('MAX_RATING', Rating::class))
76
-                    ->worstRating(glsr()->constant('MIN_RATING', Rating::class))
72
+                $this->getSchemaType( 'AggregateRating' )
73
+                    ->ratingValue( $this->getRatingValue() )
74
+                    ->reviewCount( $count )
75
+                    ->bestRating( glsr()->constant( 'MAX_RATING', Rating::class ) )
76
+                    ->worstRating( glsr()->constant( 'MIN_RATING', Rating::class ) )
77 77
             );
78 78
         }
79 79
         $schema = $schema->toArray();
80
-        return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args);
80
+        return apply_filters( 'site-reviews/schema/'.$schema['@type'], $schema, $args );
81 81
     }
82 82
 
83 83
     /**
@@ -85,64 +85,64 @@  discard block
 block discarded – undo
85 85
      */
86 86
     public function render()
87 87
     {
88
-        if (empty(glsr()->schemas)) {
88
+        if( empty(glsr()->schemas) ) {
89 89
             return;
90 90
         }
91
-        printf('<script type="application/ld+json">%s</script>', json_encode(
92
-            apply_filters('site-reviews/schema/all', glsr()->schemas),
91
+        printf( '<script type="application/ld+json">%s</script>', json_encode(
92
+            apply_filters( 'site-reviews/schema/all', glsr()->schemas ),
93 93
             JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
94
-        ));
94
+        ) );
95 95
     }
96 96
 
97 97
     /**
98 98
      * @return void
99 99
      */
100
-    public function store(array $schema)
100
+    public function store( array $schema )
101 101
     {
102 102
         $schemas = glsr()->schemas;
103 103
         $schemas[] = $schema;
104
-        glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas)));
104
+        glsr()->schemas = array_map( 'unserialize', array_unique( array_map( 'serialize', $schemas ) ) );
105 105
     }
106 106
 
107 107
     /**
108 108
      * @param Review $review
109 109
      * @return array
110 110
      */
111
-    protected function buildReview($review)
111
+    protected function buildReview( $review )
112 112
     {
113
-        $schema = $this->getSchemaType('Review')
114
-            ->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) {
115
-                $schema->name($review->title);
113
+        $schema = $this->getSchemaType( 'Review' )
114
+            ->doIf( !in_array( 'title', $this->args['hide'] ), function( $schema ) use ($review) {
115
+                $schema->name( $review->title );
116 116
             })
117
-            ->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) {
118
-                $schema->reviewBody($review->content);
117
+            ->doIf( !in_array( 'excerpt', $this->args['hide'] ), function( $schema ) use ($review) {
118
+                $schema->reviewBody( $review->content );
119 119
             })
120
-            ->datePublished((new DateTime($review->date)))
121
-            ->author($this->getSchemaType('Person')->name($review->author))
122
-            ->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name')));
123
-        if (!empty($review->rating)) {
120
+            ->datePublished( (new DateTime( $review->date )) )
121
+            ->author( $this->getSchemaType( 'Person' )->name( $review->author ) )
122
+            ->itemReviewed( $this->getSchemaType()->name( $this->getSchemaOptionValue( 'name' ) ) );
123
+        if( !empty($review->rating) ) {
124 124
             $schema->reviewRating(
125
-                $this->getSchemaType('Rating')
126
-                    ->ratingValue($review->rating)
127
-                    ->bestRating(glsr()->constant('MAX_RATING', Rating::class))
128
-                    ->worstRating(glsr()->constant('MIN_RATING', Rating::class))
125
+                $this->getSchemaType( 'Rating' )
126
+                    ->ratingValue( $review->rating )
127
+                    ->bestRating( glsr()->constant( 'MAX_RATING', Rating::class ) )
128
+                    ->worstRating( glsr()->constant( 'MIN_RATING', Rating::class ) )
129 129
             );
130 130
         }
131
-        return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args);
131
+        return apply_filters( 'site-reviews/schema/review', $schema->toArray(), $review, $this->args );
132 132
     }
133 133
 
134 134
     /**
135 135
      * @param mixed $schema
136 136
      * @return mixed
137 137
      */
138
-    protected function buildSchemaValues($schema, array $values = [])
138
+    protected function buildSchemaValues( $schema, array $values = [] )
139 139
     {
140
-        foreach ($values as $value) {
141
-            $option = $this->getSchemaOptionValue($value);
142
-            if (empty($option)) {
140
+        foreach( $values as $value ) {
141
+            $option = $this->getSchemaOptionValue( $value );
142
+            if( empty($option) ) {
143 143
                 continue;
144 144
             }
145
-            $schema->$value($option);
145
+            $schema->$value( $option );
146 146
         }
147 147
         return $schema;
148 148
     }
@@ -152,9 +152,9 @@  discard block
 block discarded – undo
152 152
      */
153 153
     protected function buildSummaryForCustom()
154 154
     {
155
-        return $this->buildSchemaValues($this->getSchemaType(), [
155
+        return $this->buildSchemaValues( $this->getSchemaType(), [
156 156
             'description', 'image', 'name', 'url',
157
-        ]);
157
+        ] );
158 158
     }
159 159
 
160 160
     /**
@@ -162,9 +162,9 @@  discard block
 block discarded – undo
162 162
      */
163 163
     protected function buildSummaryForLocalBusiness()
164 164
     {
165
-        return $this->buildSchemaValues($this->buildSummaryForCustom(), [
165
+        return $this->buildSchemaValues( $this->buildSummaryForCustom(), [
166 166
             'address', 'priceRange', 'telephone',
167
-        ]);
167
+        ] );
168 168
     }
169 169
 
170 170
     /**
@@ -172,15 +172,15 @@  discard block
 block discarded – undo
172 172
      */
173 173
     protected function buildSummaryForProduct()
174 174
     {
175
-        $offerType = $this->getSchemaOption('offerType', 'AggregateOffer');
176
-        $offers = $this->buildSchemaValues($this->getSchemaType($offerType), [
175
+        $offerType = $this->getSchemaOption( 'offerType', 'AggregateOffer' );
176
+        $offers = $this->buildSchemaValues( $this->getSchemaType( $offerType ), [
177 177
             'highPrice', 'lowPrice', 'price', 'priceCurrency',
178
-        ]);
178
+        ] );
179 179
         return $this->buildSummaryForCustom()
180
-            ->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) {
181
-                $schema->offers($offers);
180
+            ->doIf( !empty($offers->getProperties()), function( $schema ) use ($offers) {
181
+                $schema->offers( $offers );
182 182
             })
183
-            ->setProperty('@id', $this->getSchemaOptionValue('url').'#product');
183
+            ->setProperty( '@id', $this->getSchemaOptionValue( 'url' ).'#product' );
184 184
     }
185 185
 
186 186
     /**
@@ -188,8 +188,8 @@  discard block
 block discarded – undo
188 188
      */
189 189
     protected function getRatingCounts()
190 190
     {
191
-        if (!isset($this->ratingCounts)) {
192
-            $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args);
191
+        if( !isset($this->ratingCounts) ) {
192
+            $this->ratingCounts = glsr( ReviewManager::class )->getRatingCounts( $this->args );
193 193
         }
194 194
         return $this->ratingCounts;
195 195
     }
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
      */
200 200
     protected function getRatingValue()
201 201
     {
202
-        return glsr(Rating::class)->getAverage($this->getRatingCounts());
202
+        return glsr( Rating::class )->getAverage( $this->getRatingCounts() );
203 203
     }
204 204
 
205 205
     /**
@@ -207,15 +207,15 @@  discard block
 block discarded – undo
207 207
      * @param string $fallback
208 208
      * @return string
209 209
      */
210
-    protected function getSchemaOption($option, $fallback)
210
+    protected function getSchemaOption( $option, $fallback )
211 211
     {
212
-        $option = strtolower($option);
213
-        if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) {
212
+        $option = strtolower( $option );
213
+        if( $schemaOption = trim( (string)get_post_meta( intval( get_the_ID() ), 'schema_'.$option, true ) ) ) {
214 214
             return $schemaOption;
215 215
         }
216
-        $setting = glsr(OptionManager::class)->get('settings.schema.'.$option);
217
-        if (is_array($setting)) {
218
-            return $this->getSchemaOptionDefault($setting, $fallback);
216
+        $setting = glsr( OptionManager::class )->get( 'settings.schema.'.$option );
217
+        if( is_array( $setting ) ) {
218
+            return $this->getSchemaOptionDefault( $setting, $fallback );
219 219
         }
220 220
         return !empty($setting)
221 221
             ? $setting
@@ -226,12 +226,12 @@  discard block
 block discarded – undo
226 226
      * @param string $fallback
227 227
      * @return string
228 228
      */
229
-    protected function getSchemaOptionDefault(array $setting, $fallback)
229
+    protected function getSchemaOptionDefault( array $setting, $fallback )
230 230
     {
231
-        $setting = wp_parse_args($setting, [
231
+        $setting = wp_parse_args( $setting, [
232 232
             'custom' => '',
233 233
             'default' => $fallback,
234
-        ]);
234
+        ] );
235 235
         return 'custom' != $setting['default']
236 236
             ? $setting['default']
237 237
             : $setting['custom'];
@@ -242,21 +242,21 @@  discard block
 block discarded – undo
242 242
      * @param string $fallback
243 243
      * @return void|string
244 244
      */
245
-    protected function getSchemaOptionValue($option, $fallback = 'post')
245
+    protected function getSchemaOptionValue( $option, $fallback = 'post' )
246 246
     {
247
-        if (array_key_exists($option, $this->keyValues)) {
247
+        if( array_key_exists( $option, $this->keyValues ) ) {
248 248
             return $this->keyValues[$option];
249 249
         }
250
-        $value = $this->getSchemaOption($option, $fallback);
251
-        if ($value != $fallback) {
252
-            return $this->setAndGetKeyValue($option, $value);
250
+        $value = $this->getSchemaOption( $option, $fallback );
251
+        if( $value != $fallback ) {
252
+            return $this->setAndGetKeyValue( $option, $value );
253 253
         }
254
-        if (!is_single() && !is_page()) {
254
+        if( !is_single() && !is_page() ) {
255 255
             return;
256 256
         }
257
-        $method = Helper::buildMethodName($option, 'getThing');
258
-        if (method_exists($this, $method)) {
259
-            return $this->setAndGetKeyValue($option, $this->$method());
257
+        $method = Helper::buildMethodName( $option, 'getThing' );
258
+        if( method_exists( $this, $method ) ) {
259
+            return $this->setAndGetKeyValue( $option, $this->$method() );
260 260
         }
261 261
     }
262 262
 
@@ -264,15 +264,15 @@  discard block
 block discarded – undo
264 264
      * @param string|null $type
265 265
      * @return mixed
266 266
      */
267
-    protected function getSchemaType($type = null)
267
+    protected function getSchemaType( $type = null )
268 268
     {
269
-        if (!is_string($type)) {
270
-            $type = $this->getSchemaOption('type', 'LocalBusiness');
269
+        if( !is_string( $type ) ) {
270
+            $type = $this->getSchemaOption( 'type', 'LocalBusiness' );
271 271
         }
272
-        $className = Helper::buildClassName($type, 'Modules\Schema');
273
-        return class_exists($className)
272
+        $className = Helper::buildClassName( $type, 'Modules\Schema' );
273
+        return class_exists( $className )
274 274
             ? new $className()
275
-            : new UnknownType($type);
275
+            : new UnknownType( $type );
276 276
     }
277 277
 
278 278
     /**
@@ -281,19 +281,19 @@  discard block
 block discarded – undo
281 281
     protected function getThingDescription()
282 282
     {
283 283
         $post = get_post();
284
-        $text = Arr::get($post, 'post_excerpt');
285
-        if (empty($text)) {
286
-            $text = Arr::get($post, 'post_content');
284
+        $text = Arr::get( $post, 'post_excerpt' );
285
+        if( empty($text) ) {
286
+            $text = Arr::get( $post, 'post_content' );
287 287
         }
288
-        if (function_exists('excerpt_remove_blocks')) {
289
-            $text = excerpt_remove_blocks($text);
288
+        if( function_exists( 'excerpt_remove_blocks' ) ) {
289
+            $text = excerpt_remove_blocks( $text );
290 290
         }
291
-        $text = strip_shortcodes($text);
292
-        $text = wpautop($text);
293
-        $text = wptexturize($text);
294
-        $text = wp_strip_all_tags($text);
295
-        $text = str_replace(']]>', ']]&gt;', $text);
296
-        return wp_trim_words($text, apply_filters('excerpt_length', 55));
291
+        $text = strip_shortcodes( $text );
292
+        $text = wpautop( $text );
293
+        $text = wptexturize( $text );
294
+        $text = wp_strip_all_tags( $text );
295
+        $text = str_replace( ']]>', ']]&gt;', $text );
296
+        return wp_trim_words( $text, apply_filters( 'excerpt_length', 55 ) );
297 297
     }
298 298
 
299 299
     /**
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
      */
302 302
     protected function getThingImage()
303 303
     {
304
-        return (string) get_the_post_thumbnail_url(null, 'large');
304
+        return (string)get_the_post_thumbnail_url( null, 'large' );
305 305
     }
306 306
 
307 307
     /**
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
      */
318 318
     protected function getThingUrl()
319 319
     {
320
-        return (string) get_the_permalink();
320
+        return (string)get_the_permalink();
321 321
     }
322 322
 
323 323
     /**
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
      * @param string $value
326 326
      * @return string
327 327
      */
328
-    protected function setAndGetKeyValue($option, $value)
328
+    protected function setAndGetKeyValue( $option, $value )
329 329
     {
330 330
         $this->keyValues[$option] = $value;
331 331
         return $value;
Please login to merge, or discard this patch.
plugin/Handlers/EnqueuePublicAssets.php 2 patches
Indentation   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -9,148 +9,148 @@
 block discarded – undo
9 9
 
10 10
 class EnqueuePublicAssets
11 11
 {
12
-    /**
13
-     * @return void
14
-     */
15
-    public function handle()
16
-    {
17
-        $this->enqueueAssets();
18
-        $this->enqueuePolyfillService();
19
-        $this->enqueueRecaptchaScript();
20
-        $this->inlineScript();
21
-        $this->inlineStyles();
22
-    }
12
+	/**
13
+	 * @return void
14
+	 */
15
+	public function handle()
16
+	{
17
+		$this->enqueueAssets();
18
+		$this->enqueuePolyfillService();
19
+		$this->enqueueRecaptchaScript();
20
+		$this->inlineScript();
21
+		$this->inlineStyles();
22
+	}
23 23
 
24
-    /**
25
-     * @return void
26
-     */
27
-    public function enqueueAssets()
28
-    {
29
-        if (apply_filters('site-reviews/assets/css', true)) {
30
-            wp_enqueue_style(
31
-                Application::ID,
32
-                $this->getStylesheet(),
33
-                [],
34
-                glsr()->version
35
-            );
36
-        }
37
-        if (apply_filters('site-reviews/assets/js', true)) {
38
-            $dependencies = apply_filters('site-reviews/assets/polyfill', true)
39
-                ? [Application::ID.'/polyfill']
40
-                : [];
41
-            $dependencies = apply_filters('site-reviews/enqueue/public/dependencies', $dependencies);
42
-            wp_enqueue_script(
43
-                Application::ID,
44
-                glsr()->url('assets/scripts/'.Application::ID.'.js'),
45
-                $dependencies,
46
-                glsr()->version,
47
-                true
48
-            );
49
-        }
50
-    }
24
+	/**
25
+	 * @return void
26
+	 */
27
+	public function enqueueAssets()
28
+	{
29
+		if (apply_filters('site-reviews/assets/css', true)) {
30
+			wp_enqueue_style(
31
+				Application::ID,
32
+				$this->getStylesheet(),
33
+				[],
34
+				glsr()->version
35
+			);
36
+		}
37
+		if (apply_filters('site-reviews/assets/js', true)) {
38
+			$dependencies = apply_filters('site-reviews/assets/polyfill', true)
39
+				? [Application::ID.'/polyfill']
40
+				: [];
41
+			$dependencies = apply_filters('site-reviews/enqueue/public/dependencies', $dependencies);
42
+			wp_enqueue_script(
43
+				Application::ID,
44
+				glsr()->url('assets/scripts/'.Application::ID.'.js'),
45
+				$dependencies,
46
+				glsr()->version,
47
+				true
48
+			);
49
+		}
50
+	}
51 51
 
52
-    /**
53
-     * @return void
54
-     */
55
-    public function enqueuePolyfillService()
56
-    {
57
-        if (!apply_filters('site-reviews/assets/polyfill', true)) {
58
-            return;
59
-        }
60
-        wp_enqueue_script(Application::ID.'/polyfill', add_query_arg([
61
-            'features' => 'Array.prototype.findIndex,CustomEvent,Element.prototype.closest,Element.prototype.dataset,Event,XMLHttpRequest,MutationObserver',
62
-            'flags' => 'gated',
63
-        ], 'https://polyfill.io/v3/polyfill.min.js'));
64
-    }
52
+	/**
53
+	 * @return void
54
+	 */
55
+	public function enqueuePolyfillService()
56
+	{
57
+		if (!apply_filters('site-reviews/assets/polyfill', true)) {
58
+			return;
59
+		}
60
+		wp_enqueue_script(Application::ID.'/polyfill', add_query_arg([
61
+			'features' => 'Array.prototype.findIndex,CustomEvent,Element.prototype.closest,Element.prototype.dataset,Event,XMLHttpRequest,MutationObserver',
62
+			'flags' => 'gated',
63
+		], 'https://polyfill.io/v3/polyfill.min.js'));
64
+	}
65 65
 
66
-    /**
67
-     * @return void
68
-     */
69
-    public function enqueueRecaptchaScript()
70
-    {
71
-        // wpforms-recaptcha
72
-        // google-recaptcha
73
-        // nf-google-recaptcha
74
-        if (!glsr(OptionManager::class)->isRecaptchaEnabled()) {
75
-            return;
76
-        }
77
-        $language = apply_filters('site-reviews/recaptcha/language', get_locale());
78
-        wp_enqueue_script(Application::ID.'/google-recaptcha', add_query_arg([
79
-            'hl' => $language,
80
-            'render' => 'explicit',
81
-        ], 'https://www.google.com/recaptcha/api.js'));
82
-    }
66
+	/**
67
+	 * @return void
68
+	 */
69
+	public function enqueueRecaptchaScript()
70
+	{
71
+		// wpforms-recaptcha
72
+		// google-recaptcha
73
+		// nf-google-recaptcha
74
+		if (!glsr(OptionManager::class)->isRecaptchaEnabled()) {
75
+			return;
76
+		}
77
+		$language = apply_filters('site-reviews/recaptcha/language', get_locale());
78
+		wp_enqueue_script(Application::ID.'/google-recaptcha', add_query_arg([
79
+			'hl' => $language,
80
+			'render' => 'explicit',
81
+		], 'https://www.google.com/recaptcha/api.js'));
82
+	}
83 83
 
84
-    /**
85
-     * @return void
86
-     */
87
-    public function inlineScript()
88
-    {
89
-        $variables = [
90
-            'action' => Application::PREFIX.'action',
91
-            'ajaxpagination' => $this->getFixedSelectorsForPagination(),
92
-            'ajaxurl' => admin_url('admin-ajax.php'),
93
-            'nameprefix' => Application::ID,
94
-            'validationconfig' => glsr(Style::class)->validation,
95
-            'validationstrings' => glsr(ValidationStringsDefaults::class)->defaults(),
96
-        ];
97
-        $variables = apply_filters('site-reviews/enqueue/public/localize', $variables);
98
-        wp_add_inline_script(Application::ID, $this->buildInlineScript($variables), 'before');
99
-    }
84
+	/**
85
+	 * @return void
86
+	 */
87
+	public function inlineScript()
88
+	{
89
+		$variables = [
90
+			'action' => Application::PREFIX.'action',
91
+			'ajaxpagination' => $this->getFixedSelectorsForPagination(),
92
+			'ajaxurl' => admin_url('admin-ajax.php'),
93
+			'nameprefix' => Application::ID,
94
+			'validationconfig' => glsr(Style::class)->validation,
95
+			'validationstrings' => glsr(ValidationStringsDefaults::class)->defaults(),
96
+		];
97
+		$variables = apply_filters('site-reviews/enqueue/public/localize', $variables);
98
+		wp_add_inline_script(Application::ID, $this->buildInlineScript($variables), 'before');
99
+	}
100 100
 
101
-    /**
102
-     * @return void
103
-     */
104
-    public function inlineStyles()
105
-    {
106
-        $inlineStylesheetPath = glsr()->path('assets/styles/inline-styles.css');
107
-        if (!apply_filters('site-reviews/assets/css', true)) {
108
-            return;
109
-        }
110
-        if (!file_exists($inlineStylesheetPath)) {
111
-            glsr_log()->error('Inline stylesheet is missing: '.$inlineStylesheetPath);
112
-            return;
113
-        }
114
-        $inlineStylesheetValues = glsr()->config('inline-styles');
115
-        $stylesheet = str_replace(
116
-            array_keys($inlineStylesheetValues),
117
-            array_values($inlineStylesheetValues),
118
-            file_get_contents($inlineStylesheetPath)
119
-        );
120
-        wp_add_inline_style(Application::ID, $stylesheet);
121
-    }
101
+	/**
102
+	 * @return void
103
+	 */
104
+	public function inlineStyles()
105
+	{
106
+		$inlineStylesheetPath = glsr()->path('assets/styles/inline-styles.css');
107
+		if (!apply_filters('site-reviews/assets/css', true)) {
108
+			return;
109
+		}
110
+		if (!file_exists($inlineStylesheetPath)) {
111
+			glsr_log()->error('Inline stylesheet is missing: '.$inlineStylesheetPath);
112
+			return;
113
+		}
114
+		$inlineStylesheetValues = glsr()->config('inline-styles');
115
+		$stylesheet = str_replace(
116
+			array_keys($inlineStylesheetValues),
117
+			array_values($inlineStylesheetValues),
118
+			file_get_contents($inlineStylesheetPath)
119
+		);
120
+		wp_add_inline_style(Application::ID, $stylesheet);
121
+	}
122 122
 
123
-    /**
124
-     * @return string
125
-     */
126
-    protected function buildInlineScript(array $variables)
127
-    {
128
-        $script = 'window.hasOwnProperty("GLSR")||(window.GLSR={});';
129
-        foreach ($variables as $key => $value) {
130
-            $script.= sprintf('GLSR.%s=%s;', $key, json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
131
-        }
132
-        $pattern = '/\"([^ \-\"]+)\"(:[{\[\"])/'; // removes unnecessary quotes surrounding object keys
133
-        $optimizedScript = preg_replace($pattern, '$1$2', $script);
134
-        return apply_filters('site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables);
135
-    }
123
+	/**
124
+	 * @return string
125
+	 */
126
+	protected function buildInlineScript(array $variables)
127
+	{
128
+		$script = 'window.hasOwnProperty("GLSR")||(window.GLSR={});';
129
+		foreach ($variables as $key => $value) {
130
+			$script.= sprintf('GLSR.%s=%s;', $key, json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
131
+		}
132
+		$pattern = '/\"([^ \-\"]+)\"(:[{\[\"])/'; // removes unnecessary quotes surrounding object keys
133
+		$optimizedScript = preg_replace($pattern, '$1$2', $script);
134
+		return apply_filters('site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables);
135
+	}
136 136
 
137
-    /**
138
-     * @return array
139
-     */
140
-    protected function getFixedSelectorsForPagination()
141
-    {
142
-        $selectors = ['#wpadminbar', '.site-navigation-fixed'];
143
-        return apply_filters('site-reviews/enqueue/public/localize/ajax-pagination', $selectors);
144
-    }
137
+	/**
138
+	 * @return array
139
+	 */
140
+	protected function getFixedSelectorsForPagination()
141
+	{
142
+		$selectors = ['#wpadminbar', '.site-navigation-fixed'];
143
+		return apply_filters('site-reviews/enqueue/public/localize/ajax-pagination', $selectors);
144
+	}
145 145
 
146
-    /**
147
-     * @return string
148
-     */
149
-    protected function getStylesheet()
150
-    {
151
-        $currentStyle = glsr(Style::class)->style;
152
-        return file_exists(glsr()->path('assets/styles/custom/'.$currentStyle.'.css'))
153
-            ? glsr()->url('assets/styles/custom/'.$currentStyle.'.css')
154
-            : glsr()->url('assets/styles/'.Application::ID.'.css');
155
-    }
146
+	/**
147
+	 * @return string
148
+	 */
149
+	protected function getStylesheet()
150
+	{
151
+		$currentStyle = glsr(Style::class)->style;
152
+		return file_exists(glsr()->path('assets/styles/custom/'.$currentStyle.'.css'))
153
+			? glsr()->url('assets/styles/custom/'.$currentStyle.'.css')
154
+			: glsr()->url('assets/styles/'.Application::ID.'.css');
155
+	}
156 156
 }
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
      */
27 27
     public function enqueueAssets()
28 28
     {
29
-        if (apply_filters('site-reviews/assets/css', true)) {
29
+        if( apply_filters( 'site-reviews/assets/css', true ) ) {
30 30
             wp_enqueue_style(
31 31
                 Application::ID,
32 32
                 $this->getStylesheet(),
@@ -34,14 +34,14 @@  discard block
 block discarded – undo
34 34
                 glsr()->version
35 35
             );
36 36
         }
37
-        if (apply_filters('site-reviews/assets/js', true)) {
38
-            $dependencies = apply_filters('site-reviews/assets/polyfill', true)
37
+        if( apply_filters( 'site-reviews/assets/js', true ) ) {
38
+            $dependencies = apply_filters( 'site-reviews/assets/polyfill', true )
39 39
                 ? [Application::ID.'/polyfill']
40 40
                 : [];
41
-            $dependencies = apply_filters('site-reviews/enqueue/public/dependencies', $dependencies);
41
+            $dependencies = apply_filters( 'site-reviews/enqueue/public/dependencies', $dependencies );
42 42
             wp_enqueue_script(
43 43
                 Application::ID,
44
-                glsr()->url('assets/scripts/'.Application::ID.'.js'),
44
+                glsr()->url( 'assets/scripts/'.Application::ID.'.js' ),
45 45
                 $dependencies,
46 46
                 glsr()->version,
47 47
                 true
@@ -54,13 +54,13 @@  discard block
 block discarded – undo
54 54
      */
55 55
     public function enqueuePolyfillService()
56 56
     {
57
-        if (!apply_filters('site-reviews/assets/polyfill', true)) {
57
+        if( !apply_filters( 'site-reviews/assets/polyfill', true ) ) {
58 58
             return;
59 59
         }
60
-        wp_enqueue_script(Application::ID.'/polyfill', add_query_arg([
60
+        wp_enqueue_script( Application::ID.'/polyfill', add_query_arg( [
61 61
             'features' => 'Array.prototype.findIndex,CustomEvent,Element.prototype.closest,Element.prototype.dataset,Event,XMLHttpRequest,MutationObserver',
62 62
             'flags' => 'gated',
63
-        ], 'https://polyfill.io/v3/polyfill.min.js'));
63
+        ], 'https://polyfill.io/v3/polyfill.min.js' ) );
64 64
     }
65 65
 
66 66
     /**
@@ -71,14 +71,14 @@  discard block
 block discarded – undo
71 71
         // wpforms-recaptcha
72 72
         // google-recaptcha
73 73
         // nf-google-recaptcha
74
-        if (!glsr(OptionManager::class)->isRecaptchaEnabled()) {
74
+        if( !glsr( OptionManager::class )->isRecaptchaEnabled() ) {
75 75
             return;
76 76
         }
77
-        $language = apply_filters('site-reviews/recaptcha/language', get_locale());
78
-        wp_enqueue_script(Application::ID.'/google-recaptcha', add_query_arg([
77
+        $language = apply_filters( 'site-reviews/recaptcha/language', get_locale() );
78
+        wp_enqueue_script( Application::ID.'/google-recaptcha', add_query_arg( [
79 79
             'hl' => $language,
80 80
             'render' => 'explicit',
81
-        ], 'https://www.google.com/recaptcha/api.js'));
81
+        ], 'https://www.google.com/recaptcha/api.js' ) );
82 82
     }
83 83
 
84 84
     /**
@@ -89,13 +89,13 @@  discard block
 block discarded – undo
89 89
         $variables = [
90 90
             'action' => Application::PREFIX.'action',
91 91
             'ajaxpagination' => $this->getFixedSelectorsForPagination(),
92
-            'ajaxurl' => admin_url('admin-ajax.php'),
92
+            'ajaxurl' => admin_url( 'admin-ajax.php' ),
93 93
             'nameprefix' => Application::ID,
94
-            'validationconfig' => glsr(Style::class)->validation,
95
-            'validationstrings' => glsr(ValidationStringsDefaults::class)->defaults(),
94
+            'validationconfig' => glsr( Style::class )->validation,
95
+            'validationstrings' => glsr( ValidationStringsDefaults::class )->defaults(),
96 96
         ];
97
-        $variables = apply_filters('site-reviews/enqueue/public/localize', $variables);
98
-        wp_add_inline_script(Application::ID, $this->buildInlineScript($variables), 'before');
97
+        $variables = apply_filters( 'site-reviews/enqueue/public/localize', $variables );
98
+        wp_add_inline_script( Application::ID, $this->buildInlineScript( $variables ), 'before' );
99 99
     }
100 100
 
101 101
     /**
@@ -103,35 +103,35 @@  discard block
 block discarded – undo
103 103
      */
104 104
     public function inlineStyles()
105 105
     {
106
-        $inlineStylesheetPath = glsr()->path('assets/styles/inline-styles.css');
107
-        if (!apply_filters('site-reviews/assets/css', true)) {
106
+        $inlineStylesheetPath = glsr()->path( 'assets/styles/inline-styles.css' );
107
+        if( !apply_filters( 'site-reviews/assets/css', true ) ) {
108 108
             return;
109 109
         }
110
-        if (!file_exists($inlineStylesheetPath)) {
111
-            glsr_log()->error('Inline stylesheet is missing: '.$inlineStylesheetPath);
110
+        if( !file_exists( $inlineStylesheetPath ) ) {
111
+            glsr_log()->error( 'Inline stylesheet is missing: '.$inlineStylesheetPath );
112 112
             return;
113 113
         }
114
-        $inlineStylesheetValues = glsr()->config('inline-styles');
114
+        $inlineStylesheetValues = glsr()->config( 'inline-styles' );
115 115
         $stylesheet = str_replace(
116
-            array_keys($inlineStylesheetValues),
117
-            array_values($inlineStylesheetValues),
118
-            file_get_contents($inlineStylesheetPath)
116
+            array_keys( $inlineStylesheetValues ),
117
+            array_values( $inlineStylesheetValues ),
118
+            file_get_contents( $inlineStylesheetPath )
119 119
         );
120
-        wp_add_inline_style(Application::ID, $stylesheet);
120
+        wp_add_inline_style( Application::ID, $stylesheet );
121 121
     }
122 122
 
123 123
     /**
124 124
      * @return string
125 125
      */
126
-    protected function buildInlineScript(array $variables)
126
+    protected function buildInlineScript( array $variables )
127 127
     {
128 128
         $script = 'window.hasOwnProperty("GLSR")||(window.GLSR={});';
129
-        foreach ($variables as $key => $value) {
130
-            $script.= sprintf('GLSR.%s=%s;', $key, json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
129
+        foreach( $variables as $key => $value ) {
130
+            $script .= sprintf( 'GLSR.%s=%s;', $key, json_encode( $value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) );
131 131
         }
132 132
         $pattern = '/\"([^ \-\"]+)\"(:[{\[\"])/'; // removes unnecessary quotes surrounding object keys
133
-        $optimizedScript = preg_replace($pattern, '$1$2', $script);
134
-        return apply_filters('site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables);
133
+        $optimizedScript = preg_replace( $pattern, '$1$2', $script );
134
+        return apply_filters( 'site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables );
135 135
     }
136 136
 
137 137
     /**
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
     protected function getFixedSelectorsForPagination()
141 141
     {
142 142
         $selectors = ['#wpadminbar', '.site-navigation-fixed'];
143
-        return apply_filters('site-reviews/enqueue/public/localize/ajax-pagination', $selectors);
143
+        return apply_filters( 'site-reviews/enqueue/public/localize/ajax-pagination', $selectors );
144 144
     }
145 145
 
146 146
     /**
@@ -148,9 +148,9 @@  discard block
 block discarded – undo
148 148
      */
149 149
     protected function getStylesheet()
150 150
     {
151
-        $currentStyle = glsr(Style::class)->style;
152
-        return file_exists(glsr()->path('assets/styles/custom/'.$currentStyle.'.css'))
153
-            ? glsr()->url('assets/styles/custom/'.$currentStyle.'.css')
154
-            : glsr()->url('assets/styles/'.Application::ID.'.css');
151
+        $currentStyle = glsr( Style::class )->style;
152
+        return file_exists( glsr()->path( 'assets/styles/custom/'.$currentStyle.'.css' ) )
153
+            ? glsr()->url( 'assets/styles/custom/'.$currentStyle.'.css' )
154
+            : glsr()->url( 'assets/styles/'.Application::ID.'.css' );
155 155
     }
156 156
 }
Please login to merge, or discard this patch.
plugin/Defaults/StyleValidationDefaults.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -6,23 +6,23 @@
 block discarded – undo
6 6
 
7 7
 class StyleValidationDefaults extends Defaults
8 8
 {
9
-    /**
10
-     * @return array
11
-     */
12
-    protected function defaults()
13
-    {
14
-        return [
15
-            'error_tag' => 'div',
16
-            'error_tag_class' => 'glsr-field-error',
17
-            'field_class' => 'glsr-field',
18
-            'field_error_class' => 'glsr-has-error',
19
-            'input_error_class' => 'glsr-is-invalid',
20
-            'input_valid_class' => 'glsr-is-valid',
21
-            'message_error_class' => 'glsr-has-errors',
22
-            'message_initial_class' => 'glsr-is-visible',
23
-            'message_success_class' => 'glsr-has-success',
24
-            'message_tag' => 'div',
25
-            'message_tag_class' => 'glsr-form-message',
26
-        ];
27
-    }
9
+	/**
10
+	 * @return array
11
+	 */
12
+	protected function defaults()
13
+	{
14
+		return [
15
+			'error_tag' => 'div',
16
+			'error_tag_class' => 'glsr-field-error',
17
+			'field_class' => 'glsr-field',
18
+			'field_error_class' => 'glsr-has-error',
19
+			'input_error_class' => 'glsr-is-invalid',
20
+			'input_valid_class' => 'glsr-is-valid',
21
+			'message_error_class' => 'glsr-has-errors',
22
+			'message_initial_class' => 'glsr-is-visible',
23
+			'message_success_class' => 'glsr-has-success',
24
+			'message_tag' => 'div',
25
+			'message_tag_class' => 'glsr-form-message',
26
+		];
27
+	}
28 28
 }
Please login to merge, or discard this patch.
views/pages/tools/console.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,22 +1,22 @@
 block discarded – undo
1
-<?php defined('WPINC') || die; ?>
1
+<?php defined( 'WPINC' ) || die; ?>
2 2
 
3 3
 <textarea id="log-file" class="large-text code glsr-code glsr-code-large" rows="20" readonly>{{ console }}</textarea>
4 4
 <form method="post" class="glsr-float-left">
5 5
     <input type="hidden" name="{{ id }}[_action]" value="download-console">
6
-    <?php wp_nonce_field('download-console'); ?>
7
-    <?php submit_button(__('Download Console', 'site-reviews'), 'primary', '', false); ?>
6
+    <?php wp_nonce_field( 'download-console' ); ?>
7
+    <?php submit_button( __( 'Download Console', 'site-reviews' ), 'primary', '', false ); ?>
8 8
 </form>
9 9
 <form method="post" class="glsr-float-left">
10 10
     <input type="hidden" name="{{ id }}[_action]" value="fetch-console">
11
-    <?php wp_nonce_field('fetch-console'); ?>
11
+    <?php wp_nonce_field( 'fetch-console' ); ?>
12 12
     <button type="submit" class="glsr-button button" id="fetch-console">
13
-        <span data-loading="<?= __('Reloading...', 'site-reviews'); ?>"><?= __('Reload', 'site-reviews'); ?></span>
13
+        <span data-loading="<?= __( 'Reloading...', 'site-reviews' ); ?>"><?= __( 'Reload', 'site-reviews' ); ?></span>
14 14
     </button>
15 15
 </form>
16 16
 <form method="post">
17 17
     <input type="hidden" name="{{ id }}[_action]" value="clear-console">
18
-    <?php wp_nonce_field('clear-console'); ?>
18
+    <?php wp_nonce_field( 'clear-console' ); ?>
19 19
     <button type="submit" class="glsr-button button" id="clear-console">
20
-        <span data-loading="<?= __('Clearing...', 'site-reviews'); ?>"><?= __('Clear', 'site-reviews'); ?></span>
20
+        <span data-loading="<?= __( 'Clearing...', 'site-reviews' ); ?>"><?= __( 'Clear', 'site-reviews' ); ?></span>
21 21
     </button>
22 22
 </form>
Please login to merge, or discard this patch.
plugin/Handlers/EnqueueAdminAssets.php 2 patches
Indentation   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -10,158 +10,158 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -18,9 +18,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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'];
Please login to merge, or discard this patch.
plugin/Controllers/AjaxController.php 2 patches
Indentation   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -14,169 +14,169 @@
 block discarded – undo
14 14
 
15 15
 class AjaxController extends Controller
16 16
 {
17
-    /**
18
-     * @return void
19
-     */
20
-    public function routerChangeStatus(array $request)
21
-    {
22
-        wp_send_json_success($this->execute(new ChangeStatus($request)));
23
-    }
17
+	/**
18
+	 * @return void
19
+	 */
20
+	public function routerChangeStatus(array $request)
21
+	{
22
+		wp_send_json_success($this->execute(new ChangeStatus($request)));
23
+	}
24 24
 
25
-    /**
26
-     * @return void
27
-     */
28
-    public function routerClearConsole()
29
-    {
30
-        glsr(AdminController::class)->routerClearConsole();
31
-        wp_send_json_success([
32
-            'console' => glsr(Console::class)->get(),
33
-            'notices' => glsr(Notice::class)->get(),
34
-        ]);
35
-    }
25
+	/**
26
+	 * @return void
27
+	 */
28
+	public function routerClearConsole()
29
+	{
30
+		glsr(AdminController::class)->routerClearConsole();
31
+		wp_send_json_success([
32
+			'console' => glsr(Console::class)->get(),
33
+			'notices' => glsr(Notice::class)->get(),
34
+		]);
35
+	}
36 36
 
37
-    /**
38
-     * @return void
39
-     */
40
-    public function routerCountReviews()
41
-    {
42
-        glsr(AdminController::class)->routerCountReviews();
43
-        wp_send_json_success([
44
-            'notices' => glsr(Notice::class)->get(),
45
-        ]);
46
-    }
37
+	/**
38
+	 * @return void
39
+	 */
40
+	public function routerCountReviews()
41
+	{
42
+		glsr(AdminController::class)->routerCountReviews();
43
+		wp_send_json_success([
44
+			'notices' => glsr(Notice::class)->get(),
45
+		]);
46
+	}
47 47
 
48
-    /**
49
-     * @return void
50
-     */
51
-    public function routerDismissNotice(array $request)
52
-    {
53
-        glsr(NoticeController::class)->routerDismissNotice($request);
54
-        wp_send_json_success();
55
-    }
48
+	/**
49
+	 * @return void
50
+	 */
51
+	public function routerDismissNotice(array $request)
52
+	{
53
+		glsr(NoticeController::class)->routerDismissNotice($request);
54
+		wp_send_json_success();
55
+	}
56 56
 
57
-    /**
58
-     * @return void
59
-     */
60
-    public function routerMceShortcode(array $request)
61
-    {
62
-        $shortcode = $request['shortcode'];
63
-        $response = false;
64
-        if (array_key_exists($shortcode, glsr()->mceShortcodes)) {
65
-            $data = glsr()->mceShortcodes[$shortcode];
66
-            if (!empty($data['errors'])) {
67
-                $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')];
68
-            }
69
-            $response = [
70
-                'body' => $data['fields'],
71
-                'close' => $data['btn_close'],
72
-                'ok' => $data['btn_okay'],
73
-                'shortcode' => $shortcode,
74
-                'title' => $data['title'],
75
-            ];
76
-        }
77
-        wp_send_json_success($response);
78
-    }
57
+	/**
58
+	 * @return void
59
+	 */
60
+	public function routerMceShortcode(array $request)
61
+	{
62
+		$shortcode = $request['shortcode'];
63
+		$response = false;
64
+		if (array_key_exists($shortcode, glsr()->mceShortcodes)) {
65
+			$data = glsr()->mceShortcodes[$shortcode];
66
+			if (!empty($data['errors'])) {
67
+				$data['btn_okay'] = [esc_html__('Okay', 'site-reviews')];
68
+			}
69
+			$response = [
70
+				'body' => $data['fields'],
71
+				'close' => $data['btn_close'],
72
+				'ok' => $data['btn_okay'],
73
+				'shortcode' => $shortcode,
74
+				'title' => $data['title'],
75
+			];
76
+		}
77
+		wp_send_json_success($response);
78
+	}
79 79
 
80
-    /**
81
-     * @return void
82
-     */
83
-    public function routerFetchConsole()
84
-    {
85
-        glsr(AdminController::class)->routerFetchConsole();
86
-        wp_send_json_success([
87
-            'console' => glsr(Console::class)->get(),
88
-            'notices' => glsr(Notice::class)->get(),
89
-        ]);
90
-    }
80
+	/**
81
+	 * @return void
82
+	 */
83
+	public function routerFetchConsole()
84
+	{
85
+		glsr(AdminController::class)->routerFetchConsole();
86
+		wp_send_json_success([
87
+			'console' => glsr(Console::class)->get(),
88
+			'notices' => glsr(Notice::class)->get(),
89
+		]);
90
+	}
91 91
 
92
-    /**
93
-     * @return void
94
-     */
95
-    public function routerSearchPosts(array $request)
96
-    {
97
-        $results = glsr(Database::class)->searchPosts($request['search']);
98
-        wp_send_json_success([
99
-            'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>',
100
-            'items' => $results,
101
-        ]);
102
-    }
92
+	/**
93
+	 * @return void
94
+	 */
95
+	public function routerSearchPosts(array $request)
96
+	{
97
+		$results = glsr(Database::class)->searchPosts($request['search']);
98
+		wp_send_json_success([
99
+			'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>',
100
+			'items' => $results,
101
+		]);
102
+	}
103 103
 
104
-    /**
105
-     * @return void
106
-     */
107
-    public function routerSearchTranslations(array $request)
108
-    {
109
-        if (empty($request['exclude'])) {
110
-            $request['exclude'] = [];
111
-        }
112
-        $results = glsr(Translation::class)
113
-            ->search($request['search'])
114
-            ->exclude()
115
-            ->exclude($request['exclude'])
116
-            ->renderResults();
117
-        wp_send_json_success([
118
-            'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>',
119
-            'items' => $results,
120
-        ]);
121
-    }
104
+	/**
105
+	 * @return void
106
+	 */
107
+	public function routerSearchTranslations(array $request)
108
+	{
109
+		if (empty($request['exclude'])) {
110
+			$request['exclude'] = [];
111
+		}
112
+		$results = glsr(Translation::class)
113
+			->search($request['search'])
114
+			->exclude()
115
+			->exclude($request['exclude'])
116
+			->renderResults();
117
+		wp_send_json_success([
118
+			'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>',
119
+			'items' => $results,
120
+		]);
121
+	}
122 122
 
123
-    /**
124
-     * @return void
125
-     */
126
-    public function routerSubmitReview(array $request)
127
-    {
128
-        $command = glsr(PublicController::class)->routerSubmitReview($request);
129
-        $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true)));
130
-        $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command);
131
-        $data = [
132
-            'errors' => glsr()->sessionGet($command->form_id.'errors', false),
133
-            'message' => glsr()->sessionGet($command->form_id.'message', ''),
134
-            'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false),
135
-            'redirect' => $redirect,
136
-        ];
137
-        if (false === $data['errors']) {
138
-            glsr()->sessionClear();
139
-            wp_send_json_success($data);
140
-        }
141
-        wp_send_json_error($data);
142
-    }
123
+	/**
124
+	 * @return void
125
+	 */
126
+	public function routerSubmitReview(array $request)
127
+	{
128
+		$command = glsr(PublicController::class)->routerSubmitReview($request);
129
+		$redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true)));
130
+		$redirect = apply_filters('site-reviews/review/redirect', $redirect, $command);
131
+		$data = [
132
+			'errors' => glsr()->sessionGet($command->form_id.'errors', false),
133
+			'message' => glsr()->sessionGet($command->form_id.'message', ''),
134
+			'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false),
135
+			'redirect' => $redirect,
136
+		];
137
+		if (false === $data['errors']) {
138
+			glsr()->sessionClear();
139
+			wp_send_json_success($data);
140
+		}
141
+		wp_send_json_error($data);
142
+	}
143 143
 
144
-    /**
145
-     * @return void
146
-     */
147
-    public function routerFetchPagedReviews(array $request)
148
-    {
149
-        $homePath = untrailingslashit(parse_url(home_url(), PHP_URL_PATH));
150
-        $urlPath = untrailingslashit(parse_url(Arr::get($request, 'url'), PHP_URL_PATH));
151
-        $urlQuery = [];
152
-        parse_str(parse_url(Arr::get($request, 'url'), PHP_URL_QUERY), $urlQuery);
153
-        $pagedUrl = $homePath === $urlPath
154
-            ? home_url()
155
-            : home_url($urlPath);
156
-        $args = [
157
-            'paged' => (int) Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1),
158
-            'pagedUrl' => trailingslashit($pagedUrl),
159
-            'pagination' => 'ajax',
160
-            'schema' => false,
161
-        ];
162
-        $atts = (array) json_decode(Arr::get($request, 'atts'));
163
-        $atts = glsr(SiteReviewsShortcode::class)->normalizeAtts($atts);
164
-        $html = glsr(SiteReviewsPartial::class)->build(wp_parse_args($args, $atts));
165
-        return wp_send_json_success([
166
-            'pagination' => $html->getPagination(),
167
-            'reviews' => $html->getReviews(),
168
-        ]);
169
-    }
144
+	/**
145
+	 * @return void
146
+	 */
147
+	public function routerFetchPagedReviews(array $request)
148
+	{
149
+		$homePath = untrailingslashit(parse_url(home_url(), PHP_URL_PATH));
150
+		$urlPath = untrailingslashit(parse_url(Arr::get($request, 'url'), PHP_URL_PATH));
151
+		$urlQuery = [];
152
+		parse_str(parse_url(Arr::get($request, 'url'), PHP_URL_QUERY), $urlQuery);
153
+		$pagedUrl = $homePath === $urlPath
154
+			? home_url()
155
+			: home_url($urlPath);
156
+		$args = [
157
+			'paged' => (int) Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1),
158
+			'pagedUrl' => trailingslashit($pagedUrl),
159
+			'pagination' => 'ajax',
160
+			'schema' => false,
161
+		];
162
+		$atts = (array) json_decode(Arr::get($request, 'atts'));
163
+		$atts = glsr(SiteReviewsShortcode::class)->normalizeAtts($atts);
164
+		$html = glsr(SiteReviewsPartial::class)->build(wp_parse_args($args, $atts));
165
+		return wp_send_json_success([
166
+			'pagination' => $html->getPagination(),
167
+			'reviews' => $html->getReviews(),
168
+		]);
169
+	}
170 170
 
171
-    /**
172
-     * @return void
173
-     */
174
-    public function routerTogglePinned(array $request)
175
-    {
176
-        $isPinned = $this->execute(new TogglePinned($request));
177
-        wp_send_json_success([
178
-            'notices' => glsr(Notice::class)->get(),
179
-            'pinned' => $isPinned,
180
-        ]);
181
-    }
171
+	/**
172
+	 * @return void
173
+	 */
174
+	public function routerTogglePinned(array $request)
175
+	{
176
+		$isPinned = $this->execute(new TogglePinned($request));
177
+		wp_send_json_success([
178
+			'notices' => glsr(Notice::class)->get(),
179
+			'pinned' => $isPinned,
180
+		]);
181
+	}
182 182
 }
Please login to merge, or discard this patch.
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -17,9 +17,9 @@  discard block
 block discarded – undo
17 17
     /**
18 18
      * @return void
19 19
      */
20
-    public function routerChangeStatus(array $request)
20
+    public function routerChangeStatus( array $request )
21 21
     {
22
-        wp_send_json_success($this->execute(new ChangeStatus($request)));
22
+        wp_send_json_success( $this->execute( new ChangeStatus( $request ) ) );
23 23
     }
24 24
 
25 25
     /**
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
      */
28 28
     public function routerClearConsole()
29 29
     {
30
-        glsr(AdminController::class)->routerClearConsole();
31
-        wp_send_json_success([
32
-            'console' => glsr(Console::class)->get(),
33
-            'notices' => glsr(Notice::class)->get(),
34
-        ]);
30
+        glsr( AdminController::class )->routerClearConsole();
31
+        wp_send_json_success( [
32
+            'console' => glsr( Console::class )->get(),
33
+            'notices' => glsr( Notice::class )->get(),
34
+        ] );
35 35
     }
36 36
 
37 37
     /**
@@ -39,32 +39,32 @@  discard block
 block discarded – undo
39 39
      */
40 40
     public function routerCountReviews()
41 41
     {
42
-        glsr(AdminController::class)->routerCountReviews();
43
-        wp_send_json_success([
44
-            'notices' => glsr(Notice::class)->get(),
45
-        ]);
42
+        glsr( AdminController::class )->routerCountReviews();
43
+        wp_send_json_success( [
44
+            'notices' => glsr( Notice::class )->get(),
45
+        ] );
46 46
     }
47 47
 
48 48
     /**
49 49
      * @return void
50 50
      */
51
-    public function routerDismissNotice(array $request)
51
+    public function routerDismissNotice( array $request )
52 52
     {
53
-        glsr(NoticeController::class)->routerDismissNotice($request);
53
+        glsr( NoticeController::class )->routerDismissNotice( $request );
54 54
         wp_send_json_success();
55 55
     }
56 56
 
57 57
     /**
58 58
      * @return void
59 59
      */
60
-    public function routerMceShortcode(array $request)
60
+    public function routerMceShortcode( array $request )
61 61
     {
62 62
         $shortcode = $request['shortcode'];
63 63
         $response = false;
64
-        if (array_key_exists($shortcode, glsr()->mceShortcodes)) {
64
+        if( array_key_exists( $shortcode, glsr()->mceShortcodes ) ) {
65 65
             $data = glsr()->mceShortcodes[$shortcode];
66
-            if (!empty($data['errors'])) {
67
-                $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')];
66
+            if( !empty($data['errors']) ) {
67
+                $data['btn_okay'] = [esc_html__( 'Okay', 'site-reviews' )];
68 68
             }
69 69
             $response = [
70 70
                 'body' => $data['fields'],
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
                 'title' => $data['title'],
75 75
             ];
76 76
         }
77
-        wp_send_json_success($response);
77
+        wp_send_json_success( $response );
78 78
     }
79 79
 
80 80
     /**
@@ -82,101 +82,101 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public function routerFetchConsole()
84 84
     {
85
-        glsr(AdminController::class)->routerFetchConsole();
86
-        wp_send_json_success([
87
-            'console' => glsr(Console::class)->get(),
88
-            'notices' => glsr(Notice::class)->get(),
89
-        ]);
85
+        glsr( AdminController::class )->routerFetchConsole();
86
+        wp_send_json_success( [
87
+            'console' => glsr( Console::class )->get(),
88
+            'notices' => glsr( Notice::class )->get(),
89
+        ] );
90 90
     }
91 91
 
92 92
     /**
93 93
      * @return void
94 94
      */
95
-    public function routerSearchPosts(array $request)
95
+    public function routerSearchPosts( array $request )
96 96
     {
97
-        $results = glsr(Database::class)->searchPosts($request['search']);
98
-        wp_send_json_success([
99
-            'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>',
97
+        $results = glsr( Database::class )->searchPosts( $request['search'] );
98
+        wp_send_json_success( [
99
+            'empty' => '<div>'.__( 'Nothing found.', 'site-reviews' ).'</div>',
100 100
             'items' => $results,
101
-        ]);
101
+        ] );
102 102
     }
103 103
 
104 104
     /**
105 105
      * @return void
106 106
      */
107
-    public function routerSearchTranslations(array $request)
107
+    public function routerSearchTranslations( array $request )
108 108
     {
109
-        if (empty($request['exclude'])) {
109
+        if( empty($request['exclude']) ) {
110 110
             $request['exclude'] = [];
111 111
         }
112
-        $results = glsr(Translation::class)
113
-            ->search($request['search'])
112
+        $results = glsr( Translation::class )
113
+            ->search( $request['search'] )
114 114
             ->exclude()
115
-            ->exclude($request['exclude'])
115
+            ->exclude( $request['exclude'] )
116 116
             ->renderResults();
117
-        wp_send_json_success([
118
-            'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>',
117
+        wp_send_json_success( [
118
+            'empty' => '<div>'.__( 'Nothing found.', 'site-reviews' ).'</div>',
119 119
             'items' => $results,
120
-        ]);
120
+        ] );
121 121
     }
122 122
 
123 123
     /**
124 124
      * @return void
125 125
      */
126
-    public function routerSubmitReview(array $request)
126
+    public function routerSubmitReview( array $request )
127 127
     {
128
-        $command = glsr(PublicController::class)->routerSubmitReview($request);
129
-        $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true)));
130
-        $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command);
128
+        $command = glsr( PublicController::class )->routerSubmitReview( $request );
129
+        $redirect = trim( strval( get_post_meta( $command->post_id, 'redirect_to', true ) ) );
130
+        $redirect = apply_filters( 'site-reviews/review/redirect', $redirect, $command );
131 131
         $data = [
132
-            'errors' => glsr()->sessionGet($command->form_id.'errors', false),
133
-            'message' => glsr()->sessionGet($command->form_id.'message', ''),
134
-            'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false),
132
+            'errors' => glsr()->sessionGet( $command->form_id.'errors', false ),
133
+            'message' => glsr()->sessionGet( $command->form_id.'message', '' ),
134
+            'recaptcha' => glsr()->sessionGet( $command->form_id.'recaptcha', false ),
135 135
             'redirect' => $redirect,
136 136
         ];
137
-        if (false === $data['errors']) {
137
+        if( false === $data['errors'] ) {
138 138
             glsr()->sessionClear();
139
-            wp_send_json_success($data);
139
+            wp_send_json_success( $data );
140 140
         }
141
-        wp_send_json_error($data);
141
+        wp_send_json_error( $data );
142 142
     }
143 143
 
144 144
     /**
145 145
      * @return void
146 146
      */
147
-    public function routerFetchPagedReviews(array $request)
147
+    public function routerFetchPagedReviews( array $request )
148 148
     {
149
-        $homePath = untrailingslashit(parse_url(home_url(), PHP_URL_PATH));
150
-        $urlPath = untrailingslashit(parse_url(Arr::get($request, 'url'), PHP_URL_PATH));
149
+        $homePath = untrailingslashit( parse_url( home_url(), PHP_URL_PATH ) );
150
+        $urlPath = untrailingslashit( parse_url( Arr::get( $request, 'url' ), PHP_URL_PATH ) );
151 151
         $urlQuery = [];
152
-        parse_str(parse_url(Arr::get($request, 'url'), PHP_URL_QUERY), $urlQuery);
152
+        parse_str( parse_url( Arr::get( $request, 'url' ), PHP_URL_QUERY ), $urlQuery );
153 153
         $pagedUrl = $homePath === $urlPath
154 154
             ? home_url()
155
-            : home_url($urlPath);
155
+            : home_url( $urlPath );
156 156
         $args = [
157
-            'paged' => (int) Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1),
158
-            'pagedUrl' => trailingslashit($pagedUrl),
157
+            'paged' => (int)Arr::get( $urlQuery, glsr()->constant( 'PAGED_QUERY_VAR' ), 1 ),
158
+            'pagedUrl' => trailingslashit( $pagedUrl ),
159 159
             'pagination' => 'ajax',
160 160
             'schema' => false,
161 161
         ];
162
-        $atts = (array) json_decode(Arr::get($request, 'atts'));
163
-        $atts = glsr(SiteReviewsShortcode::class)->normalizeAtts($atts);
164
-        $html = glsr(SiteReviewsPartial::class)->build(wp_parse_args($args, $atts));
165
-        return wp_send_json_success([
162
+        $atts = (array)json_decode( Arr::get( $request, 'atts' ) );
163
+        $atts = glsr( SiteReviewsShortcode::class )->normalizeAtts( $atts );
164
+        $html = glsr( SiteReviewsPartial::class )->build( wp_parse_args( $args, $atts ) );
165
+        return wp_send_json_success( [
166 166
             'pagination' => $html->getPagination(),
167 167
             'reviews' => $html->getReviews(),
168
-        ]);
168
+        ] );
169 169
     }
170 170
 
171 171
     /**
172 172
      * @return void
173 173
      */
174
-    public function routerTogglePinned(array $request)
174
+    public function routerTogglePinned( array $request )
175 175
     {
176
-        $isPinned = $this->execute(new TogglePinned($request));
177
-        wp_send_json_success([
178
-            'notices' => glsr(Notice::class)->get(),
176
+        $isPinned = $this->execute( new TogglePinned( $request ) );
177
+        wp_send_json_success( [
178
+            'notices' => glsr( Notice::class )->get(),
179 179
             'pinned' => $isPinned,
180
-        ]);
180
+        ] );
181 181
     }
182 182
 }
Please login to merge, or discard this patch.
plugin/Modules/Rating.php 2 patches
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -4,207 +4,207 @@
 block discarded – undo
4 4
 
5 5
 class Rating
6 6
 {
7
-    /**
8
-     * The more sure we are of the confidence interval (the higher the confidence level), the less
9
-     * precise the estimation will be as the margin for error will be higher.
10
-     * @see http://homepages.math.uic.edu/~bpower6/stat101/Confidence%20Intervals.pdf
11
-     * @see https://www.thecalculator.co/math/Confidence-Interval-Calculator-210.html
12
-     * @see https://www.youtube.com/watch?v=grodoLzThy4
13
-     * @see https://en.wikipedia.org/wiki/Standard_score
14
-     * @var array
15
-     */
16
-    const CONFIDENCE_LEVEL_Z_SCORES = [
17
-        50 => 0.67449,
18
-        70 => 1.04,
19
-        75 => 1.15035,
20
-        80 => 1.282,
21
-        85 => 1.44,
22
-        90 => 1.64485,
23
-        92 => 1.75,
24
-        95 => 1.95996,
25
-        96 => 2.05,
26
-        97 => 2.17009,
27
-        98 => 2.326,
28
-        99 => 2.57583,
29
-        '99.5' => 2.81,
30
-        '99.8' => 3.08,
31
-        '99.9' => 3.29053,
32
-    ];
7
+	/**
8
+	 * The more sure we are of the confidence interval (the higher the confidence level), the less
9
+	 * precise the estimation will be as the margin for error will be higher.
10
+	 * @see http://homepages.math.uic.edu/~bpower6/stat101/Confidence%20Intervals.pdf
11
+	 * @see https://www.thecalculator.co/math/Confidence-Interval-Calculator-210.html
12
+	 * @see https://www.youtube.com/watch?v=grodoLzThy4
13
+	 * @see https://en.wikipedia.org/wiki/Standard_score
14
+	 * @var array
15
+	 */
16
+	const CONFIDENCE_LEVEL_Z_SCORES = [
17
+		50 => 0.67449,
18
+		70 => 1.04,
19
+		75 => 1.15035,
20
+		80 => 1.282,
21
+		85 => 1.44,
22
+		90 => 1.64485,
23
+		92 => 1.75,
24
+		95 => 1.95996,
25
+		96 => 2.05,
26
+		97 => 2.17009,
27
+		98 => 2.326,
28
+		99 => 2.57583,
29
+		'99.5' => 2.81,
30
+		'99.8' => 3.08,
31
+		'99.9' => 3.29053,
32
+	];
33 33
 
34
-    /**
35
-     * @var int
36
-     */
37
-    const MAX_RATING = 5;
34
+	/**
35
+	 * @var int
36
+	 */
37
+	const MAX_RATING = 5;
38 38
 
39
-    /**
40
-     * @var int
41
-     */
42
-    const MIN_RATING = 1;
39
+	/**
40
+	 * @var int
41
+	 */
42
+	const MIN_RATING = 1;
43 43
 
44
-    /**
45
-     * @param int $roundBy
46
-     * @return float
47
-     */
48
-    public function getAverage(array $ratingCounts, $roundBy = 1)
49
-    {
50
-        $average = array_sum($ratingCounts);
51
-        if ($average > 0) {
52
-            $average = $this->getTotalSum($ratingCounts) / $average;
53
-        }
54
-        $roundedAverage = round($average, intval($roundBy));
55
-        return floatval(apply_filters('site-reviews/rating/average', $roundedAverage, $ratingCounts, $average));
56
-    }
44
+	/**
45
+	 * @param int $roundBy
46
+	 * @return float
47
+	 */
48
+	public function getAverage(array $ratingCounts, $roundBy = 1)
49
+	{
50
+		$average = array_sum($ratingCounts);
51
+		if ($average > 0) {
52
+			$average = $this->getTotalSum($ratingCounts) / $average;
53
+		}
54
+		$roundedAverage = round($average, intval($roundBy));
55
+		return floatval(apply_filters('site-reviews/rating/average', $roundedAverage, $ratingCounts, $average));
56
+	}
57 57
 
58
-    /**
59
-     * Get the lower bound for up/down ratings
60
-     * Method receives an up/down ratings array: [1, -1, -1, 1, 1, -1].
61
-     * @see http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
62
-     * @see https://news.ycombinator.com/item?id=10481507
63
-     * @see https://dataorigami.net/blogs/napkin-folding/79030467-an-algorithm-to-sort-top-comments
64
-     * @see http://julesjacobs.github.io/2015/08/17/bayesian-scoring-of-ratings.html
65
-     * @param int $confidencePercentage
66
-     * @return int|float
67
-     */
68
-    public function getLowerBound(array $upDownCounts = [0, 0], $confidencePercentage = 95)
69
-    {
70
-        $numRatings = array_sum($upDownCounts);
71
-        if ($numRatings < 1) {
72
-            return 0;
73
-        }
74
-        $z = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage];
75
-        $phat = 1 * $upDownCounts[1] / $numRatings;
76
-        return ($phat + $z * $z / (2 * $numRatings) - $z * sqrt(($phat * (1 - $phat) + $z * $z / (4 * $numRatings)) / $numRatings)) / (1 + $z * $z / $numRatings);
77
-    }
58
+	/**
59
+	 * Get the lower bound for up/down ratings
60
+	 * Method receives an up/down ratings array: [1, -1, -1, 1, 1, -1].
61
+	 * @see http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
62
+	 * @see https://news.ycombinator.com/item?id=10481507
63
+	 * @see https://dataorigami.net/blogs/napkin-folding/79030467-an-algorithm-to-sort-top-comments
64
+	 * @see http://julesjacobs.github.io/2015/08/17/bayesian-scoring-of-ratings.html
65
+	 * @param int $confidencePercentage
66
+	 * @return int|float
67
+	 */
68
+	public function getLowerBound(array $upDownCounts = [0, 0], $confidencePercentage = 95)
69
+	{
70
+		$numRatings = array_sum($upDownCounts);
71
+		if ($numRatings < 1) {
72
+			return 0;
73
+		}
74
+		$z = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage];
75
+		$phat = 1 * $upDownCounts[1] / $numRatings;
76
+		return ($phat + $z * $z / (2 * $numRatings) - $z * sqrt(($phat * (1 - $phat) + $z * $z / (4 * $numRatings)) / $numRatings)) / (1 + $z * $z / $numRatings);
77
+	}
78 78
 
79
-    /**
80
-     * @return int|float
81
-     */
82
-    public function getOverallPercentage(array $ratingCounts)
83
-    {
84
-        return round($this->getAverage($ratingCounts) * 100 / glsr()->constant('MAX_RATING', __CLASS__), 2);
85
-    }
79
+	/**
80
+	 * @return int|float
81
+	 */
82
+	public function getOverallPercentage(array $ratingCounts)
83
+	{
84
+		return round($this->getAverage($ratingCounts) * 100 / glsr()->constant('MAX_RATING', __CLASS__), 2);
85
+	}
86 86
 
87
-    /**
88
-     * @return array
89
-     */
90
-    public function getPercentages(array $ratingCounts)
91
-    {
92
-        $total = array_sum($ratingCounts);
93
-        foreach ($ratingCounts as $index => $count) {
94
-            if (empty($count)) {
95
-                continue;
96
-            }
97
-            $ratingCounts[$index] = $count / $total * 100;
98
-        }
99
-        return $this->getRoundedPercentages($ratingCounts);
100
-    }
87
+	/**
88
+	 * @return array
89
+	 */
90
+	public function getPercentages(array $ratingCounts)
91
+	{
92
+		$total = array_sum($ratingCounts);
93
+		foreach ($ratingCounts as $index => $count) {
94
+			if (empty($count)) {
95
+				continue;
96
+			}
97
+			$ratingCounts[$index] = $count / $total * 100;
98
+		}
99
+		return $this->getRoundedPercentages($ratingCounts);
100
+	}
101 101
 
102
-    /**
103
-     * @return float
104
-     */
105
-    public function getRanking(array $ratingCounts)
106
-    {
107
-        return floatval(apply_filters('site-reviews/rating/ranking',
108
-            $this->getRankingUsingImdb($ratingCounts),
109
-            $ratingCounts,
110
-            $this
111
-        ));
112
-    }
102
+	/**
103
+	 * @return float
104
+	 */
105
+	public function getRanking(array $ratingCounts)
106
+	{
107
+		return floatval(apply_filters('site-reviews/rating/ranking',
108
+			$this->getRankingUsingImdb($ratingCounts),
109
+			$ratingCounts,
110
+			$this
111
+		));
112
+	}
113 113
 
114
-    /**
115
-     * Get the bayesian ranking for an array of reviews
116
-     * This formula is the same one used by IMDB to rank their top 250 films.
117
-     * @see https://www.xkcd.com/937/
118
-     * @see https://districtdatalabs.silvrback.com/computing-a-bayesian-estimate-of-star-rating-means
119
-     * @see http://fulmicoton.com/posts/bayesian_rating/
120
-     * @see https://stats.stackexchange.com/questions/93974/is-there-an-equivalent-to-lower-bound-of-wilson-score-confidence-interval-for-va
121
-     * @param int $confidencePercentage
122
-     * @return int|float
123
-     */
124
-    public function getRankingUsingImdb(array $ratingCounts, $confidencePercentage = 70)
125
-    {
126
-        $avgRating = $this->getAverage($ratingCounts);
127
-        // Represents a prior (your prior opinion without data) for the average star rating. A higher prior also means a higher margin for error.
128
-        // This could also be the average score of all items instead of a fixed value.
129
-        $bayesMean = ($confidencePercentage / 100) * glsr()->constant('MAX_RATING', __CLASS__); // prior, 70% = 3.5
130
-        // Represents the number of ratings expected to begin observing a pattern that would put confidence in the prior.
131
-        $bayesMinimal = 10; // confidence
132
-        $numOfReviews = array_sum($ratingCounts);
133
-        return $avgRating > 0
134
-            ? (($bayesMinimal * $bayesMean) + ($avgRating * $numOfReviews)) / ($bayesMinimal + $numOfReviews)
135
-            : 0;
136
-    }
114
+	/**
115
+	 * Get the bayesian ranking for an array of reviews
116
+	 * This formula is the same one used by IMDB to rank their top 250 films.
117
+	 * @see https://www.xkcd.com/937/
118
+	 * @see https://districtdatalabs.silvrback.com/computing-a-bayesian-estimate-of-star-rating-means
119
+	 * @see http://fulmicoton.com/posts/bayesian_rating/
120
+	 * @see https://stats.stackexchange.com/questions/93974/is-there-an-equivalent-to-lower-bound-of-wilson-score-confidence-interval-for-va
121
+	 * @param int $confidencePercentage
122
+	 * @return int|float
123
+	 */
124
+	public function getRankingUsingImdb(array $ratingCounts, $confidencePercentage = 70)
125
+	{
126
+		$avgRating = $this->getAverage($ratingCounts);
127
+		// Represents a prior (your prior opinion without data) for the average star rating. A higher prior also means a higher margin for error.
128
+		// This could also be the average score of all items instead of a fixed value.
129
+		$bayesMean = ($confidencePercentage / 100) * glsr()->constant('MAX_RATING', __CLASS__); // prior, 70% = 3.5
130
+		// Represents the number of ratings expected to begin observing a pattern that would put confidence in the prior.
131
+		$bayesMinimal = 10; // confidence
132
+		$numOfReviews = array_sum($ratingCounts);
133
+		return $avgRating > 0
134
+			? (($bayesMinimal * $bayesMean) + ($avgRating * $numOfReviews)) / ($bayesMinimal + $numOfReviews)
135
+			: 0;
136
+	}
137 137
 
138
-    /**
139
-     * The quality of a 5 star rating depends not only on the average number of stars but also on
140
-     * the number of reviews. This method calculates the bayesian ranking of a page by its number
141
-     * of reviews and their rating.
142
-     * @see http://www.evanmiller.org/ranking-items-with-star-ratings.html
143
-     * @see https://stackoverflow.com/questions/1411199/what-is-a-better-way-to-sort-by-a-5-star-rating/1411268
144
-     * @see http://julesjacobs.github.io/2015/08/17/bayesian-scoring-of-ratings.html
145
-     * @param int $confidencePercentage
146
-     * @return float
147
-     */
148
-    public function getRankingUsingZScores(array $ratingCounts, $confidencePercentage = 90)
149
-    {
150
-        $ratingCountsSum = array_sum($ratingCounts) + glsr()->constant('MAX_RATING', __CLASS__);
151
-        $weight = $this->getWeight($ratingCounts, $ratingCountsSum);
152
-        $weightPow2 = $this->getWeight($ratingCounts, $ratingCountsSum, true);
153
-        $zScore = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage];
154
-        return $weight - $zScore * sqrt(($weightPow2 - pow($weight, 2)) / ($ratingCountsSum + 1));
155
-    }
138
+	/**
139
+	 * The quality of a 5 star rating depends not only on the average number of stars but also on
140
+	 * the number of reviews. This method calculates the bayesian ranking of a page by its number
141
+	 * of reviews and their rating.
142
+	 * @see http://www.evanmiller.org/ranking-items-with-star-ratings.html
143
+	 * @see https://stackoverflow.com/questions/1411199/what-is-a-better-way-to-sort-by-a-5-star-rating/1411268
144
+	 * @see http://julesjacobs.github.io/2015/08/17/bayesian-scoring-of-ratings.html
145
+	 * @param int $confidencePercentage
146
+	 * @return float
147
+	 */
148
+	public function getRankingUsingZScores(array $ratingCounts, $confidencePercentage = 90)
149
+	{
150
+		$ratingCountsSum = array_sum($ratingCounts) + glsr()->constant('MAX_RATING', __CLASS__);
151
+		$weight = $this->getWeight($ratingCounts, $ratingCountsSum);
152
+		$weightPow2 = $this->getWeight($ratingCounts, $ratingCountsSum, true);
153
+		$zScore = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage];
154
+		return $weight - $zScore * sqrt(($weightPow2 - pow($weight, 2)) / ($ratingCountsSum + 1));
155
+	}
156 156
 
157
-    /**
158
-     * @param int $target
159
-     * @return array
160
-     */
161
-    protected function getRoundedPercentages(array $percentages, $totalPercent = 100)
162
-    {
163
-        array_walk($percentages, function (&$percent, $index) {
164
-            $percent = [
165
-                'index' => $index,
166
-                'percent' => floor($percent),
167
-                'remainder' => fmod($percent, 1),
168
-            ];
169
-        });
170
-        $indexes = glsr_array_column($percentages, 'index');
171
-        $remainders = glsr_array_column($percentages, 'remainder');
172
-        array_multisort($remainders, SORT_DESC, SORT_STRING, $indexes, SORT_DESC, $percentages);
173
-        $i = 0;
174
-        if (array_sum(glsr_array_column($percentages, 'percent')) > 0) {
175
-            while (array_sum(glsr_array_column($percentages, 'percent')) < $totalPercent) {
176
-                ++$percentages[$i]['percent'];
177
-                ++$i;
178
-            }
179
-        }
180
-        array_multisort($indexes, SORT_DESC, $percentages);
181
-        return array_combine($indexes, glsr_array_column($percentages, 'percent'));
182
-    }
157
+	/**
158
+	 * @param int $target
159
+	 * @return array
160
+	 */
161
+	protected function getRoundedPercentages(array $percentages, $totalPercent = 100)
162
+	{
163
+		array_walk($percentages, function (&$percent, $index) {
164
+			$percent = [
165
+				'index' => $index,
166
+				'percent' => floor($percent),
167
+				'remainder' => fmod($percent, 1),
168
+			];
169
+		});
170
+		$indexes = glsr_array_column($percentages, 'index');
171
+		$remainders = glsr_array_column($percentages, 'remainder');
172
+		array_multisort($remainders, SORT_DESC, SORT_STRING, $indexes, SORT_DESC, $percentages);
173
+		$i = 0;
174
+		if (array_sum(glsr_array_column($percentages, 'percent')) > 0) {
175
+			while (array_sum(glsr_array_column($percentages, 'percent')) < $totalPercent) {
176
+				++$percentages[$i]['percent'];
177
+				++$i;
178
+			}
179
+		}
180
+		array_multisort($indexes, SORT_DESC, $percentages);
181
+		return array_combine($indexes, glsr_array_column($percentages, 'percent'));
182
+	}
183 183
 
184
-    /**
185
-     * @return int
186
-     */
187
-    protected function getTotalSum(array $ratingCounts)
188
-    {
189
-        return array_reduce(array_keys($ratingCounts), function ($carry, $index) use ($ratingCounts) {
190
-            return $carry + ($index * $ratingCounts[$index]);
191
-        });
192
-    }
184
+	/**
185
+	 * @return int
186
+	 */
187
+	protected function getTotalSum(array $ratingCounts)
188
+	{
189
+		return array_reduce(array_keys($ratingCounts), function ($carry, $index) use ($ratingCounts) {
190
+			return $carry + ($index * $ratingCounts[$index]);
191
+		});
192
+	}
193 193
 
194
-    /**
195
-     * @param int|float $ratingCountsSum
196
-     * @param bool $powerOf2
197
-     * @return float
198
-     */
199
-    protected function getWeight(array $ratingCounts, $ratingCountsSum, $powerOf2 = false)
200
-    {
201
-        return array_reduce(array_keys($ratingCounts),
202
-            function ($count, $rating) use ($ratingCounts, $ratingCountsSum, $powerOf2) {
203
-                $ratingLevel = $powerOf2
204
-                    ? pow($rating, 2)
205
-                    : $rating;
206
-                return $count + ($ratingLevel * ($ratingCounts[$rating] + 1)) / $ratingCountsSum;
207
-            }
208
-        );
209
-    }
194
+	/**
195
+	 * @param int|float $ratingCountsSum
196
+	 * @param bool $powerOf2
197
+	 * @return float
198
+	 */
199
+	protected function getWeight(array $ratingCounts, $ratingCountsSum, $powerOf2 = false)
200
+	{
201
+		return array_reduce(array_keys($ratingCounts),
202
+			function ($count, $rating) use ($ratingCounts, $ratingCountsSum, $powerOf2) {
203
+				$ratingLevel = $powerOf2
204
+					? pow($rating, 2)
205
+					: $rating;
206
+				return $count + ($ratingLevel * ($ratingCounts[$rating] + 1)) / $ratingCountsSum;
207
+			}
208
+		);
209
+	}
210 210
 }
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -45,14 +45,14 @@  discard block
 block discarded – undo
45 45
      * @param int $roundBy
46 46
      * @return float
47 47
      */
48
-    public function getAverage(array $ratingCounts, $roundBy = 1)
48
+    public function getAverage( array $ratingCounts, $roundBy = 1 )
49 49
     {
50
-        $average = array_sum($ratingCounts);
51
-        if ($average > 0) {
52
-            $average = $this->getTotalSum($ratingCounts) / $average;
50
+        $average = array_sum( $ratingCounts );
51
+        if( $average > 0 ) {
52
+            $average = $this->getTotalSum( $ratingCounts ) / $average;
53 53
         }
54
-        $roundedAverage = round($average, intval($roundBy));
55
-        return floatval(apply_filters('site-reviews/rating/average', $roundedAverage, $ratingCounts, $average));
54
+        $roundedAverage = round( $average, intval( $roundBy ) );
55
+        return floatval( apply_filters( 'site-reviews/rating/average', $roundedAverage, $ratingCounts, $average ) );
56 56
     }
57 57
 
58 58
     /**
@@ -65,50 +65,50 @@  discard block
 block discarded – undo
65 65
      * @param int $confidencePercentage
66 66
      * @return int|float
67 67
      */
68
-    public function getLowerBound(array $upDownCounts = [0, 0], $confidencePercentage = 95)
68
+    public function getLowerBound( array $upDownCounts = [0, 0], $confidencePercentage = 95 )
69 69
     {
70
-        $numRatings = array_sum($upDownCounts);
71
-        if ($numRatings < 1) {
70
+        $numRatings = array_sum( $upDownCounts );
71
+        if( $numRatings < 1 ) {
72 72
             return 0;
73 73
         }
74 74
         $z = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage];
75 75
         $phat = 1 * $upDownCounts[1] / $numRatings;
76
-        return ($phat + $z * $z / (2 * $numRatings) - $z * sqrt(($phat * (1 - $phat) + $z * $z / (4 * $numRatings)) / $numRatings)) / (1 + $z * $z / $numRatings);
76
+        return ($phat + $z * $z / (2 * $numRatings) - $z * sqrt( ($phat * (1 - $phat) + $z * $z / (4 * $numRatings)) / $numRatings )) / (1 + $z * $z / $numRatings);
77 77
     }
78 78
 
79 79
     /**
80 80
      * @return int|float
81 81
      */
82
-    public function getOverallPercentage(array $ratingCounts)
82
+    public function getOverallPercentage( array $ratingCounts )
83 83
     {
84
-        return round($this->getAverage($ratingCounts) * 100 / glsr()->constant('MAX_RATING', __CLASS__), 2);
84
+        return round( $this->getAverage( $ratingCounts ) * 100 / glsr()->constant( 'MAX_RATING', __CLASS__ ), 2 );
85 85
     }
86 86
 
87 87
     /**
88 88
      * @return array
89 89
      */
90
-    public function getPercentages(array $ratingCounts)
90
+    public function getPercentages( array $ratingCounts )
91 91
     {
92
-        $total = array_sum($ratingCounts);
93
-        foreach ($ratingCounts as $index => $count) {
94
-            if (empty($count)) {
92
+        $total = array_sum( $ratingCounts );
93
+        foreach( $ratingCounts as $index => $count ) {
94
+            if( empty($count) ) {
95 95
                 continue;
96 96
             }
97 97
             $ratingCounts[$index] = $count / $total * 100;
98 98
         }
99
-        return $this->getRoundedPercentages($ratingCounts);
99
+        return $this->getRoundedPercentages( $ratingCounts );
100 100
     }
101 101
 
102 102
     /**
103 103
      * @return float
104 104
      */
105
-    public function getRanking(array $ratingCounts)
105
+    public function getRanking( array $ratingCounts )
106 106
     {
107
-        return floatval(apply_filters('site-reviews/rating/ranking',
108
-            $this->getRankingUsingImdb($ratingCounts),
107
+        return floatval( apply_filters( 'site-reviews/rating/ranking',
108
+            $this->getRankingUsingImdb( $ratingCounts ),
109 109
             $ratingCounts,
110 110
             $this
111
-        ));
111
+        ) );
112 112
     }
113 113
 
114 114
     /**
@@ -121,15 +121,15 @@  discard block
 block discarded – undo
121 121
      * @param int $confidencePercentage
122 122
      * @return int|float
123 123
      */
124
-    public function getRankingUsingImdb(array $ratingCounts, $confidencePercentage = 70)
124
+    public function getRankingUsingImdb( array $ratingCounts, $confidencePercentage = 70 )
125 125
     {
126
-        $avgRating = $this->getAverage($ratingCounts);
126
+        $avgRating = $this->getAverage( $ratingCounts );
127 127
         // Represents a prior (your prior opinion without data) for the average star rating. A higher prior also means a higher margin for error.
128 128
         // This could also be the average score of all items instead of a fixed value.
129
-        $bayesMean = ($confidencePercentage / 100) * glsr()->constant('MAX_RATING', __CLASS__); // prior, 70% = 3.5
129
+        $bayesMean = ($confidencePercentage / 100) * glsr()->constant( 'MAX_RATING', __CLASS__ ); // prior, 70% = 3.5
130 130
         // Represents the number of ratings expected to begin observing a pattern that would put confidence in the prior.
131 131
         $bayesMinimal = 10; // confidence
132
-        $numOfReviews = array_sum($ratingCounts);
132
+        $numOfReviews = array_sum( $ratingCounts );
133 133
         return $avgRating > 0
134 134
             ? (($bayesMinimal * $bayesMean) + ($avgRating * $numOfReviews)) / ($bayesMinimal + $numOfReviews)
135 135
             : 0;
@@ -145,48 +145,48 @@  discard block
 block discarded – undo
145 145
      * @param int $confidencePercentage
146 146
      * @return float
147 147
      */
148
-    public function getRankingUsingZScores(array $ratingCounts, $confidencePercentage = 90)
148
+    public function getRankingUsingZScores( array $ratingCounts, $confidencePercentage = 90 )
149 149
     {
150
-        $ratingCountsSum = array_sum($ratingCounts) + glsr()->constant('MAX_RATING', __CLASS__);
151
-        $weight = $this->getWeight($ratingCounts, $ratingCountsSum);
152
-        $weightPow2 = $this->getWeight($ratingCounts, $ratingCountsSum, true);
150
+        $ratingCountsSum = array_sum( $ratingCounts ) + glsr()->constant( 'MAX_RATING', __CLASS__ );
151
+        $weight = $this->getWeight( $ratingCounts, $ratingCountsSum );
152
+        $weightPow2 = $this->getWeight( $ratingCounts, $ratingCountsSum, true );
153 153
         $zScore = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage];
154
-        return $weight - $zScore * sqrt(($weightPow2 - pow($weight, 2)) / ($ratingCountsSum + 1));
154
+        return $weight - $zScore * sqrt( ($weightPow2 - pow( $weight, 2 )) / ($ratingCountsSum + 1) );
155 155
     }
156 156
 
157 157
     /**
158 158
      * @param int $target
159 159
      * @return array
160 160
      */
161
-    protected function getRoundedPercentages(array $percentages, $totalPercent = 100)
161
+    protected function getRoundedPercentages( array $percentages, $totalPercent = 100 )
162 162
     {
163
-        array_walk($percentages, function (&$percent, $index) {
163
+        array_walk( $percentages, function( &$percent, $index ) {
164 164
             $percent = [
165 165
                 'index' => $index,
166
-                'percent' => floor($percent),
167
-                'remainder' => fmod($percent, 1),
166
+                'percent' => floor( $percent ),
167
+                'remainder' => fmod( $percent, 1 ),
168 168
             ];
169 169
         });
170
-        $indexes = glsr_array_column($percentages, 'index');
171
-        $remainders = glsr_array_column($percentages, 'remainder');
172
-        array_multisort($remainders, SORT_DESC, SORT_STRING, $indexes, SORT_DESC, $percentages);
170
+        $indexes = glsr_array_column( $percentages, 'index' );
171
+        $remainders = glsr_array_column( $percentages, 'remainder' );
172
+        array_multisort( $remainders, SORT_DESC, SORT_STRING, $indexes, SORT_DESC, $percentages );
173 173
         $i = 0;
174
-        if (array_sum(glsr_array_column($percentages, 'percent')) > 0) {
175
-            while (array_sum(glsr_array_column($percentages, 'percent')) < $totalPercent) {
174
+        if( array_sum( glsr_array_column( $percentages, 'percent' ) ) > 0 ) {
175
+            while( array_sum( glsr_array_column( $percentages, 'percent' ) ) < $totalPercent ) {
176 176
                 ++$percentages[$i]['percent'];
177 177
                 ++$i;
178 178
             }
179 179
         }
180
-        array_multisort($indexes, SORT_DESC, $percentages);
181
-        return array_combine($indexes, glsr_array_column($percentages, 'percent'));
180
+        array_multisort( $indexes, SORT_DESC, $percentages );
181
+        return array_combine( $indexes, glsr_array_column( $percentages, 'percent' ) );
182 182
     }
183 183
 
184 184
     /**
185 185
      * @return int
186 186
      */
187
-    protected function getTotalSum(array $ratingCounts)
187
+    protected function getTotalSum( array $ratingCounts )
188 188
     {
189
-        return array_reduce(array_keys($ratingCounts), function ($carry, $index) use ($ratingCounts) {
189
+        return array_reduce( array_keys( $ratingCounts ), function( $carry, $index ) use ($ratingCounts) {
190 190
             return $carry + ($index * $ratingCounts[$index]);
191 191
         });
192 192
     }
@@ -196,12 +196,12 @@  discard block
 block discarded – undo
196 196
      * @param bool $powerOf2
197 197
      * @return float
198 198
      */
199
-    protected function getWeight(array $ratingCounts, $ratingCountsSum, $powerOf2 = false)
199
+    protected function getWeight( array $ratingCounts, $ratingCountsSum, $powerOf2 = false )
200 200
     {
201
-        return array_reduce(array_keys($ratingCounts),
202
-            function ($count, $rating) use ($ratingCounts, $ratingCountsSum, $powerOf2) {
201
+        return array_reduce( array_keys( $ratingCounts ),
202
+            function( $count, $rating ) use ($ratingCounts, $ratingCountsSum, $powerOf2) {
203 203
                 $ratingLevel = $powerOf2
204
-                    ? pow($rating, 2)
204
+                    ? pow( $rating, 2 )
205 205
                     : $rating;
206 206
                 return $count + ($ratingLevel * ($ratingCounts[$rating] + 1)) / $ratingCountsSum;
207 207
             }
Please login to merge, or discard this patch.