Passed
Push — master ( 7e4cda...ab680b )
by Paul
08:39 queued 04:32
created
views/pages/welcome/getting-started.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -1,17 +1,17 @@  discard block
 block discarded – undo
1
-<?php defined('WPINC') || die; ?>
1
+<?php defined( 'WPINC' ) || die; ?>
2 2
 
3 3
 <div class="is-fullwidth">
4 4
     <div class="glsr-flex-row glsr-has-2-columns">
5 5
         <div class="glsr-column">
6 6
             <h3>Editor Blocks</h3>
7 7
             <p>The fastest way to getting started with Site Reviews is to use the three provided blocks in the WordPress Block Editor. Each block comes with multiple settings which let you configure the block exactly as needed. To add a block to your page, click the "Add Block" button and search for "Site Reviews".</p>
8
-            <img class="screenshot" src="<?= glsr()->url('assets/images/blocks.png'); ?>" alt="Editor Blocks" />
8
+            <img class="screenshot" src="<?= glsr()->url( 'assets/images/blocks.png' ); ?>" alt="Editor Blocks" />
9 9
         </div>
10 10
         <div class="glsr-column">
11 11
             <h3>Shortcodes and Widgets</h3>
12 12
             <p>You can also use the shortcodes or widgets on your page. Keep in mind, however, that widgets are limited in options compared to the shortcodes (for example, the "Latest Reviews" widget does not allow pagination). If you are using the Classic Editor in WordPress, you can click on the Site Reviews shortcode button above the editor (next to the media button) to add a shortcode via a friendly popup.</p>
13 13
             <p>To learn more about the shortcodes and the available shortcode options, please see the Shortcode Documentation page of the plugin.</p>
14
-            <a class="button" href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=documentation#!shortcodes'); ?>">View Shortcode Documentation</a>
14
+            <a class="button" href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=documentation#!shortcodes' ); ?>">View Shortcode Documentation</a>
15 15
         </div>
16 16
     </div>
17 17
 </div>
@@ -20,31 +20,31 @@  discard block
 block discarded – undo
20 20
     <h2>Features</h2>
21 21
     <ul class="glsr-flex-row glsr-has-3-columns">
22 22
         <li class="glsr-column">
23
-            <h3><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=addons'); ?>">Add-ons</a></h3>
23
+            <h3><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=addons' ); ?>">Add-ons</a></h3>
24 24
             <p>Extend Site Reviews with add-ons that provide additional features.</p>
25 25
         </li>
26 26
         <li class="glsr-column">
27
-            <h3><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=settings#!reviews'); ?>">Avatars</a></h3>
27
+            <h3><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=settings#!reviews' ); ?>">Avatars</a></h3>
28 28
             <p>Enable avatars to generate images using the WordPress Gravatar service.</p>
29 29
         </li>
30 30
         <li class="glsr-column">
31
-            <h3><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=tools#!general'); ?>">Backup/Restore</a></h3>
31
+            <h3><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=tools#!general' ); ?>">Backup/Restore</a></h3>
32 32
             <p>Backup and restore your plugin settings as needed.</p>
33 33
         </li>
34 34
         <li class="glsr-column">
35
-            <h3><a data-expand="#faq-14" href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=documentation#!faq'); ?>">Bayesian Ranking</a></h3>
35
+            <h3><a data-expand="#faq-14" href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=documentation#!faq' ); ?>">Bayesian Ranking</a></h3>
36 36
             <p>Easily rank pages with assigned reviews using the bayesian algorithm.</p>
37 37
         </li>
38 38
         <li class="glsr-column">
39
-            <h3><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=settings#!submissions'); ?>">Blacklist</a></h3>
39
+            <h3><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=settings#!submissions' ); ?>">Blacklist</a></h3>
40 40
             <p>Blacklist words, phrases, IP addresses, names, and emails.</p>
41 41
         </li>
42 42
         <li class="glsr-column">
43
-            <h3><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=settings#!general'); ?>">Blockchain Validation</a></h3>
43
+            <h3><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=settings#!general' ); ?>">Blockchain Validation</a></h3>
44 44
             <p>Verify your reviews on the Blockchain with <a href="https://rebusify.com?ref=105">Rebusify</a>.</p>
45 45
         </li>
46 46
         <li class="glsr-column">
47
-            <h3><a href="<?= admin_url('edit-tags.php?taxonomy=site-review-category&post_type=site-review'); ?>">Categories</a></h3>
47
+            <h3><a href="<?= admin_url( 'edit-tags.php?taxonomy=site-review-category&post_type=site-review' ); ?>">Categories</a></h3>
48 48
             <p>Add your own categories and assign reviews to them.</p>
49 49
         </li>
50 50
         <li class="glsr-column">
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
             <p>Designed for WordPress developers with over 100 filter hooks and convenient functions.</p>
53 53
         </li>
54 54
         <li class="glsr-column">
55
-            <h3><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=documentation#!faq'); ?>">Documentation</a></h3>
55
+            <h3><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=documentation#!faq' ); ?>">Documentation</a></h3>
56 56
             <p>Provides FAQ and documenation for hooks and all shortcodes and functions.</p>
57 57
         </li>
58 58
         <li class="glsr-column">
@@ -60,11 +60,11 @@  discard block
 block discarded – undo
60 60
             <p>Use configurable editor blocks in the new WordPress 5.0 editor.</p>
61 61
         </li>
62 62
         <li class="glsr-column">
63
-            <h3><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=settings#!schema'); ?>">JSON-LD Schema</a></h3>
63
+            <h3><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=settings#!schema' ); ?>">JSON-LD Schema</a></h3>
64 64
             <p>Enable JSON-LD schema to display your reviews and ratings in search results.</p>
65 65
         </li>
66 66
         <li class="glsr-column">
67
-            <h3><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=settings#!general'); ?>">Multilingual</a></h3>
67
+            <h3><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=settings#!general' ); ?>">Multilingual</a></h3>
68 68
             <p>Integrates with Polylang and WPML and provides easy search/replace translation.</p>
69 69
         </li>
70 70
         <li class="glsr-column">
@@ -72,47 +72,47 @@  discard block
 block discarded – undo
72 72
             <p>Provides full support for the WordPress multisite feature.</p>
73 73
         </li>
74 74
         <li class="glsr-column">
75
-            <h3><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=settings#!general'); ?>">Notifications</a></h3>
75
+            <h3><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=settings#!general' ); ?>">Notifications</a></h3>
76 76
             <p>Send notifications to one or more emails when a review is submitted.</p>
77 77
         </li>
78 78
         <li class="glsr-column">
79
-            <h3><a data-expand="#faq-03" href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=documentation#!faq'); ?>">Page Assignment</a></h3>
79
+            <h3><a data-expand="#faq-03" href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=documentation#!faq' ); ?>">Page Assignment</a></h3>
80 80
             <p>Assign reviews to Posts, Pages, and Custom Post Types.</p>
81 81
         </li>
82 82
         <li class="glsr-column">
83
-            <h3><a data-expand="#faq-02" href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=documentation#!faq'); ?>">Pagination</a></h3>
83
+            <h3><a data-expand="#faq-02" href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=documentation#!faq' ); ?>">Pagination</a></h3>
84 84
             <p>Enable AJAX pagination to display a custom number of reviews per-page.</p>
85 85
         </li>
86 86
         <li class="glsr-column">
87
-            <h3><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.''); ?>">Responses</a></h3>
87
+            <h3><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'' ); ?>">Responses</a></h3>
88 88
             <p>Write a response to reviews that require a response.</p>
89 89
         </li>
90 90
         <li class="glsr-column">
91
-            <h3><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=settings#!general'); ?>">Restrictions</a></h3>
91
+            <h3><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=settings#!general' ); ?>">Restrictions</a></h3>
92 92
             <p>Require approval before publishing reviews and limit to registered users.</p>
93 93
         </li>
94 94
         <li class="glsr-column">
95
-            <h3><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=settings#!submissions'); ?>">Review Limits</a></h3>
95
+            <h3><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=settings#!submissions' ); ?>">Review Limits</a></h3>
96 96
             <p>Limit review submissions by email address, IP address, or username.</p>
97 97
         </li>
98 98
         <li class="glsr-column">
99
-            <h3><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=documentation#!shortcodes'); ?>">Review Summaries</a></h3>
99
+            <h3><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=documentation#!shortcodes' ); ?>">Review Summaries</a></h3>
100 100
             <p>Display a summary of your review ratings from high to low.</p>
101 101
         </li>
102 102
         <li class="glsr-column">
103
-            <h3><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=documentation#!shortcodes'); ?>">Shortcodes</a></h3>
103
+            <h3><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=documentation#!shortcodes' ); ?>">Shortcodes</a></h3>
104 104
             <p>Use the configurable shortcodes complete with documentation.</p>
105 105
         </li>
106 106
         <li class="glsr-column">
107
-            <h3><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=settings#!general'); ?>">Slack</a></h3>
107
+            <h3><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=settings#!general' ); ?>">Slack</a></h3>
108 108
             <p>Receive notifications in Slack when a review is submitted.</p>
109 109
         </li>
110 110
         <li class="glsr-column">
111
-            <h3><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=settings#!submissions'); ?>">SPAM Protection</a></h3>
111
+            <h3><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=settings#!submissions' ); ?>">SPAM Protection</a></h3>
112 112
             <p>Uses a Honeypot and integrates with Invisible reCAPTCHA and Akismet.</p>
113 113
         </li>
114 114
         <li class="glsr-column">
115
-            <h3><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=settings#!general'); ?>">Styles</a></h3>
115
+            <h3><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=settings#!general' ); ?>">Styles</a></h3>
116 116
             <p>Change the submission form style to match popular themes and form plugins.</p>
117 117
         </li>
118 118
         <li class="glsr-column">
@@ -120,11 +120,11 @@  discard block
 block discarded – undo
120 120
             <p>Free premium-level support included on the WordPress support forum.</p>
121 121
         </li>
122 122
         <li class="glsr-column">
123
-            <h3><a data-expand="#faq-17" href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=documentation#!faq'); ?>">Templates</a></h3>
123
+            <h3><a data-expand="#faq-17" href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=documentation#!faq' ); ?>">Templates</a></h3>
124 124
             <p>Use the Site Reviews templates in your theme for full control over the HTML.</p>
125 125
         </li>
126 126
         <li class="glsr-column">
127
-            <h3><a href="<?= admin_url('widgets.php'); ?>">Widgets</a></h3>
127
+            <h3><a href="<?= admin_url( 'widgets.php' ); ?>">Widgets</a></h3>
128 128
             <p>Use the configurable widgets in your sidebars.</p>
129 129
         </li>
130 130
     </ul>
Please login to merge, or discard this patch.
plugin/Helpers/Str.php 2 patches
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -4,186 +4,186 @@
 block discarded – undo
4 4
 
5 5
 class Str
6 6
 {
7
-    /**
8
-     * @param string $subject
9
-     * @param string $search
10
-     * @return string
11
-     */
12
-    public static function afterLast($subject, $search)
13
-    {
14
-        return '' === $search
15
-            ? $subject
16
-            : array_reverse(explode($search, $subject))[0];
17
-    }
7
+	/**
8
+	 * @param string $subject
9
+	 * @param string $search
10
+	 * @return string
11
+	 */
12
+	public static function afterLast($subject, $search)
13
+	{
14
+		return '' === $search
15
+			? $subject
16
+			: array_reverse(explode($search, $subject))[0];
17
+	}
18 18
 
19
-    /**
20
-     * @param string $string
21
-     * @return string
22
-     */
23
-    public static function camelCase($string)
24
-    {
25
-        $string = ucwords(str_replace(['-', '_'], ' ', trim($string)));
26
-        return str_replace(' ', '', $string);
27
-    }
19
+	/**
20
+	 * @param string $string
21
+	 * @return string
22
+	 */
23
+	public static function camelCase($string)
24
+	{
25
+		$string = ucwords(str_replace(['-', '_'], ' ', trim($string)));
26
+		return str_replace(' ', '', $string);
27
+	}
28 28
 
29
-    /**
30
-     * @param string $haystack
31
-     * @param string $needle
32
-     * @return bool
33
-     */
34
-    public static function contains($haystack, $needle)
35
-    {
36
-        return false !== strpos($haystack, $needle);
37
-    }
29
+	/**
30
+	 * @param string $haystack
31
+	 * @param string $needle
32
+	 * @return bool
33
+	 */
34
+	public static function contains($haystack, $needle)
35
+	{
36
+		return false !== strpos($haystack, $needle);
37
+	}
38 38
 
39
-    /**
40
-     * @param string $name
41
-     * @param string $nameType first|first_initial|initials|last|last_initial
42
-     * @param string $initialType period|period_space|space
43
-     * @return string
44
-     */
45
-    public static function convertName($name, $nameType = '', $initialType = '')
46
-    {
47
-        $names = preg_split('/\W/', $name, 0, PREG_SPLIT_NO_EMPTY);
48
-        $firstName = array_shift($names);
49
-        $lastName = array_pop($names);
50
-        $initialTypes = [
51
-            'period' => '.',
52
-            'period_space' => '. ',
53
-            'space' => ' ',
54
-        ];
55
-        $initialPunctuation = (string) Arr::get($initialTypes, $initialType, ' ');
56
-        if ('initials' == $nameType) {
57
-            return static::convertToInitials($name, $initialPunctuation);
58
-        }
59
-        $nameTypes = [
60
-            'first' => $firstName,
61
-            'first_initial' => substr($firstName, 0, 1).$initialPunctuation.$lastName,
62
-            'last' => $lastName,
63
-            'last_initial' => $firstName.' '.substr($lastName, 0, 1).$initialPunctuation,
64
-        ];
65
-        return trim((string) Arr::get($nameTypes, $nameType, $name));
66
-    }
39
+	/**
40
+	 * @param string $name
41
+	 * @param string $nameType first|first_initial|initials|last|last_initial
42
+	 * @param string $initialType period|period_space|space
43
+	 * @return string
44
+	 */
45
+	public static function convertName($name, $nameType = '', $initialType = '')
46
+	{
47
+		$names = preg_split('/\W/', $name, 0, PREG_SPLIT_NO_EMPTY);
48
+		$firstName = array_shift($names);
49
+		$lastName = array_pop($names);
50
+		$initialTypes = [
51
+			'period' => '.',
52
+			'period_space' => '. ',
53
+			'space' => ' ',
54
+		];
55
+		$initialPunctuation = (string) Arr::get($initialTypes, $initialType, ' ');
56
+		if ('initials' == $nameType) {
57
+			return static::convertToInitials($name, $initialPunctuation);
58
+		}
59
+		$nameTypes = [
60
+			'first' => $firstName,
61
+			'first_initial' => substr($firstName, 0, 1).$initialPunctuation.$lastName,
62
+			'last' => $lastName,
63
+			'last_initial' => $firstName.' '.substr($lastName, 0, 1).$initialPunctuation,
64
+		];
65
+		return trim((string) Arr::get($nameTypes, $nameType, $name));
66
+	}
67 67
 
68
-    /**
69
-     * @param string $path
70
-     * @param string $prefix
71
-     * @return string
72
-     */
73
-    public static function convertPathToId($path, $prefix = '')
74
-    {
75
-        return str_replace(['[', ']'], ['-', ''], static::convertPathToName($path, $prefix));
76
-    }
68
+	/**
69
+	 * @param string $path
70
+	 * @param string $prefix
71
+	 * @return string
72
+	 */
73
+	public static function convertPathToId($path, $prefix = '')
74
+	{
75
+		return str_replace(['[', ']'], ['-', ''], static::convertPathToName($path, $prefix));
76
+	}
77 77
 
78
-    /**
79
-     * @param string $path
80
-     * @param string $prefix
81
-     * @return string
82
-     */
83
-    public static function convertPathToName($path, $prefix = '')
84
-    {
85
-        $levels = explode('.', $path);
86
-        return array_reduce($levels, function ($result, $value) {
87
-            return $result .= '['.$value.']';
88
-        }, $prefix);
89
-    }
78
+	/**
79
+	 * @param string $path
80
+	 * @param string $prefix
81
+	 * @return string
82
+	 */
83
+	public static function convertPathToName($path, $prefix = '')
84
+	{
85
+		$levels = explode('.', $path);
86
+		return array_reduce($levels, function ($result, $value) {
87
+			return $result .= '['.$value.']';
88
+		}, $prefix);
89
+	}
90 90
 
91
-    /**
92
-     * @param string $name
93
-     * @param string $initialPunctuation
94
-     * @return string
95
-     */
96
-    public static function convertToInitials($name, $initialPunctuation = '')
97
-    {
98
-        preg_match_all('/(?<=\s|\b)\pL/u', $name, $matches);
99
-        return array_reduce($matches[0], function ($carry, $word) use ($initialPunctuation) {
100
-            return $carry.strtoupper(substr($word, 0, 1)).$initialPunctuation;
101
-        });
102
-    }
91
+	/**
92
+	 * @param string $name
93
+	 * @param string $initialPunctuation
94
+	 * @return string
95
+	 */
96
+	public static function convertToInitials($name, $initialPunctuation = '')
97
+	{
98
+		preg_match_all('/(?<=\s|\b)\pL/u', $name, $matches);
99
+		return array_reduce($matches[0], function ($carry, $word) use ($initialPunctuation) {
100
+			return $carry.strtoupper(substr($word, 0, 1)).$initialPunctuation;
101
+		});
102
+	}
103 103
 
104
-    /**
105
-     * @param string $string
106
-     * @return string
107
-     */
108
-    public static function dashCase($string)
109
-    {
110
-        return str_replace('_', '-', static::snakeCase($string));
111
-    }
104
+	/**
105
+	 * @param string $string
106
+	 * @return string
107
+	 */
108
+	public static function dashCase($string)
109
+	{
110
+		return str_replace('_', '-', static::snakeCase($string));
111
+	}
112 112
 
113
-    /**
114
-     * @param string $needle
115
-     * @param string $haystack
116
-     * @return bool
117
-     */
118
-    public static function endsWith($needle, $haystack)
119
-    {
120
-        $length = strlen($needle);
121
-        return 0 != $length
122
-            ? substr($haystack, -$length) === $needle
123
-            : true;
124
-    }
113
+	/**
114
+	 * @param string $needle
115
+	 * @param string $haystack
116
+	 * @return bool
117
+	 */
118
+	public static function endsWith($needle, $haystack)
119
+	{
120
+		$length = strlen($needle);
121
+		return 0 != $length
122
+			? substr($haystack, -$length) === $needle
123
+			: true;
124
+	}
125 125
 
126
-    /**
127
-     * @param string $prefix
128
-     * @param string $string
129
-     * @param string|null $trim
130
-     * @return string
131
-     */
132
-    public static function prefix($prefix, $string, $trim = null)
133
-    {
134
-        if (null === $trim) {
135
-            $trim = $prefix;
136
-        }
137
-        return $prefix.trim(static::removePrefix($trim, $string));
138
-    }
126
+	/**
127
+	 * @param string $prefix
128
+	 * @param string $string
129
+	 * @param string|null $trim
130
+	 * @return string
131
+	 */
132
+	public static function prefix($prefix, $string, $trim = null)
133
+	{
134
+		if (null === $trim) {
135
+			$trim = $prefix;
136
+		}
137
+		return $prefix.trim(static::removePrefix($trim, $string));
138
+	}
139 139
 
140
-    /**
141
-     * @param string $prefix
142
-     * @param string $string
143
-     * @return string
144
-     */
145
-    public static function removePrefix($prefix, $string)
146
-    {
147
-        return static::startsWith($prefix, $string)
148
-            ? substr($string, strlen($prefix))
149
-            : $string;
150
-    }
140
+	/**
141
+	 * @param string $prefix
142
+	 * @param string $string
143
+	 * @return string
144
+	 */
145
+	public static function removePrefix($prefix, $string)
146
+	{
147
+		return static::startsWith($prefix, $string)
148
+			? substr($string, strlen($prefix))
149
+			: $string;
150
+	}
151 151
 
152
-    /**
153
-     * @param string $string
154
-     * @return string
155
-     */
156
-    public static function snakeCase($string)
157
-    {
158
-        if (!ctype_lower($string)) {
159
-            $string = preg_replace('/\s+/u', '', $string);
160
-            $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string);
161
-            $string = function_exists('mb_strtolower')
162
-                ? mb_strtolower($string, 'UTF-8')
163
-                : strtolower($string);
164
-        }
165
-        return str_replace('-', '_', $string);
166
-    }
152
+	/**
153
+	 * @param string $string
154
+	 * @return string
155
+	 */
156
+	public static function snakeCase($string)
157
+	{
158
+		if (!ctype_lower($string)) {
159
+			$string = preg_replace('/\s+/u', '', $string);
160
+			$string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string);
161
+			$string = function_exists('mb_strtolower')
162
+				? mb_strtolower($string, 'UTF-8')
163
+				: strtolower($string);
164
+		}
165
+		return str_replace('-', '_', $string);
166
+	}
167 167
 
168
-    /**
169
-     * @param string $needle
170
-     * @param string $haystack
171
-     * @return bool
172
-     */
173
-    public static function startsWith($needle, $haystack)
174
-    {
175
-        return substr($haystack, 0, strlen($needle)) === $needle;
176
-    }
168
+	/**
169
+	 * @param string $needle
170
+	 * @param string $haystack
171
+	 * @return bool
172
+	 */
173
+	public static function startsWith($needle, $haystack)
174
+	{
175
+		return substr($haystack, 0, strlen($needle)) === $needle;
176
+	}
177 177
 
178
-    /**
179
-     * @param string $string
180
-     * @param int $length
181
-     * @return string
182
-     */
183
-    public static function truncate($string, $length)
184
-    {
185
-        return strlen($string) > $length
186
-            ? substr($string, 0, $length)
187
-            : $string;
188
-    }
178
+	/**
179
+	 * @param string $string
180
+	 * @param int $length
181
+	 * @return string
182
+	 */
183
+	public static function truncate($string, $length)
184
+	{
185
+		return strlen($string) > $length
186
+			? substr($string, 0, $length)
187
+			: $string;
188
+	}
189 189
 }
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -9,21 +9,21 @@  discard block
 block discarded – undo
9 9
      * @param string $search
10 10
      * @return string
11 11
      */
12
-    public static function afterLast($subject, $search)
12
+    public static function afterLast( $subject, $search )
13 13
     {
14 14
         return '' === $search
15 15
             ? $subject
16
-            : array_reverse(explode($search, $subject))[0];
16
+            : array_reverse( explode( $search, $subject ) )[0];
17 17
     }
18 18
 
19 19
     /**
20 20
      * @param string $string
21 21
      * @return string
22 22
      */
23
-    public static function camelCase($string)
23
+    public static function camelCase( $string )
24 24
     {
25
-        $string = ucwords(str_replace(['-', '_'], ' ', trim($string)));
26
-        return str_replace(' ', '', $string);
25
+        $string = ucwords( str_replace( ['-', '_'], ' ', trim( $string ) ) );
26
+        return str_replace( ' ', '', $string );
27 27
     }
28 28
 
29 29
     /**
@@ -31,9 +31,9 @@  discard block
 block discarded – undo
31 31
      * @param string $needle
32 32
      * @return bool
33 33
      */
34
-    public static function contains($haystack, $needle)
34
+    public static function contains( $haystack, $needle )
35 35
     {
36
-        return false !== strpos($haystack, $needle);
36
+        return false !== strpos( $haystack, $needle );
37 37
     }
38 38
 
39 39
     /**
@@ -42,27 +42,27 @@  discard block
 block discarded – undo
42 42
      * @param string $initialType period|period_space|space
43 43
      * @return string
44 44
      */
45
-    public static function convertName($name, $nameType = '', $initialType = '')
45
+    public static function convertName( $name, $nameType = '', $initialType = '' )
46 46
     {
47
-        $names = preg_split('/\W/', $name, 0, PREG_SPLIT_NO_EMPTY);
48
-        $firstName = array_shift($names);
49
-        $lastName = array_pop($names);
47
+        $names = preg_split( '/\W/', $name, 0, PREG_SPLIT_NO_EMPTY );
48
+        $firstName = array_shift( $names );
49
+        $lastName = array_pop( $names );
50 50
         $initialTypes = [
51 51
             'period' => '.',
52 52
             'period_space' => '. ',
53 53
             'space' => ' ',
54 54
         ];
55
-        $initialPunctuation = (string) Arr::get($initialTypes, $initialType, ' ');
56
-        if ('initials' == $nameType) {
57
-            return static::convertToInitials($name, $initialPunctuation);
55
+        $initialPunctuation = (string)Arr::get( $initialTypes, $initialType, ' ' );
56
+        if( 'initials' == $nameType ) {
57
+            return static::convertToInitials( $name, $initialPunctuation );
58 58
         }
59 59
         $nameTypes = [
60 60
             'first' => $firstName,
61
-            'first_initial' => substr($firstName, 0, 1).$initialPunctuation.$lastName,
61
+            'first_initial' => substr( $firstName, 0, 1 ).$initialPunctuation.$lastName,
62 62
             'last' => $lastName,
63
-            'last_initial' => $firstName.' '.substr($lastName, 0, 1).$initialPunctuation,
63
+            'last_initial' => $firstName.' '.substr( $lastName, 0, 1 ).$initialPunctuation,
64 64
         ];
65
-        return trim((string) Arr::get($nameTypes, $nameType, $name));
65
+        return trim( (string)Arr::get( $nameTypes, $nameType, $name ) );
66 66
     }
67 67
 
68 68
     /**
@@ -70,9 +70,9 @@  discard block
 block discarded – undo
70 70
      * @param string $prefix
71 71
      * @return string
72 72
      */
73
-    public static function convertPathToId($path, $prefix = '')
73
+    public static function convertPathToId( $path, $prefix = '' )
74 74
     {
75
-        return str_replace(['[', ']'], ['-', ''], static::convertPathToName($path, $prefix));
75
+        return str_replace( ['[', ']'], ['-', ''], static::convertPathToName( $path, $prefix ) );
76 76
     }
77 77
 
78 78
     /**
@@ -80,12 +80,12 @@  discard block
 block discarded – undo
80 80
      * @param string $prefix
81 81
      * @return string
82 82
      */
83
-    public static function convertPathToName($path, $prefix = '')
83
+    public static function convertPathToName( $path, $prefix = '' )
84 84
     {
85
-        $levels = explode('.', $path);
86
-        return array_reduce($levels, function ($result, $value) {
85
+        $levels = explode( '.', $path );
86
+        return array_reduce( $levels, function( $result, $value ) {
87 87
             return $result .= '['.$value.']';
88
-        }, $prefix);
88
+        }, $prefix );
89 89
     }
90 90
 
91 91
     /**
@@ -93,11 +93,11 @@  discard block
 block discarded – undo
93 93
      * @param string $initialPunctuation
94 94
      * @return string
95 95
      */
96
-    public static function convertToInitials($name, $initialPunctuation = '')
96
+    public static function convertToInitials( $name, $initialPunctuation = '' )
97 97
     {
98
-        preg_match_all('/(?<=\s|\b)\pL/u', $name, $matches);
99
-        return array_reduce($matches[0], function ($carry, $word) use ($initialPunctuation) {
100
-            return $carry.strtoupper(substr($word, 0, 1)).$initialPunctuation;
98
+        preg_match_all( '/(?<=\s|\b)\pL/u', $name, $matches );
99
+        return array_reduce( $matches[0], function( $carry, $word ) use ($initialPunctuation) {
100
+            return $carry.strtoupper( substr( $word, 0, 1 ) ).$initialPunctuation;
101 101
         });
102 102
     }
103 103
 
@@ -105,9 +105,9 @@  discard block
 block discarded – undo
105 105
      * @param string $string
106 106
      * @return string
107 107
      */
108
-    public static function dashCase($string)
108
+    public static function dashCase( $string )
109 109
     {
110
-        return str_replace('_', '-', static::snakeCase($string));
110
+        return str_replace( '_', '-', static::snakeCase( $string ) );
111 111
     }
112 112
 
113 113
     /**
@@ -115,11 +115,11 @@  discard block
 block discarded – undo
115 115
      * @param string $haystack
116 116
      * @return bool
117 117
      */
118
-    public static function endsWith($needle, $haystack)
118
+    public static function endsWith( $needle, $haystack )
119 119
     {
120
-        $length = strlen($needle);
120
+        $length = strlen( $needle );
121 121
         return 0 != $length
122
-            ? substr($haystack, -$length) === $needle
122
+            ? substr( $haystack, -$length ) === $needle
123 123
             : true;
124 124
     }
125 125
 
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
      * @param string|null $trim
130 130
      * @return string
131 131
      */
132
-    public static function prefix($prefix, $string, $trim = null)
132
+    public static function prefix( $prefix, $string, $trim = null )
133 133
     {
134
-        if (null === $trim) {
134
+        if( null === $trim ) {
135 135
             $trim = $prefix;
136 136
         }
137
-        return $prefix.trim(static::removePrefix($trim, $string));
137
+        return $prefix.trim( static::removePrefix( $trim, $string ) );
138 138
     }
139 139
 
140 140
     /**
@@ -142,10 +142,10 @@  discard block
 block discarded – undo
142 142
      * @param string $string
143 143
      * @return string
144 144
      */
145
-    public static function removePrefix($prefix, $string)
145
+    public static function removePrefix( $prefix, $string )
146 146
     {
147
-        return static::startsWith($prefix, $string)
148
-            ? substr($string, strlen($prefix))
147
+        return static::startsWith( $prefix, $string )
148
+            ? substr( $string, strlen( $prefix ) )
149 149
             : $string;
150 150
     }
151 151
 
@@ -153,16 +153,16 @@  discard block
 block discarded – undo
153 153
      * @param string $string
154 154
      * @return string
155 155
      */
156
-    public static function snakeCase($string)
156
+    public static function snakeCase( $string )
157 157
     {
158
-        if (!ctype_lower($string)) {
159
-            $string = preg_replace('/\s+/u', '', $string);
160
-            $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string);
161
-            $string = function_exists('mb_strtolower')
162
-                ? mb_strtolower($string, 'UTF-8')
163
-                : strtolower($string);
158
+        if( !ctype_lower( $string ) ) {
159
+            $string = preg_replace( '/\s+/u', '', $string );
160
+            $string = preg_replace( '/(.)(?=[A-Z])/u', '$1_', $string );
161
+            $string = function_exists( 'mb_strtolower' )
162
+                ? mb_strtolower( $string, 'UTF-8' )
163
+                : strtolower( $string );
164 164
         }
165
-        return str_replace('-', '_', $string);
165
+        return str_replace( '-', '_', $string );
166 166
     }
167 167
 
168 168
     /**
@@ -170,9 +170,9 @@  discard block
 block discarded – undo
170 170
      * @param string $haystack
171 171
      * @return bool
172 172
      */
173
-    public static function startsWith($needle, $haystack)
173
+    public static function startsWith( $needle, $haystack )
174 174
     {
175
-        return substr($haystack, 0, strlen($needle)) === $needle;
175
+        return substr( $haystack, 0, strlen( $needle ) ) === $needle;
176 176
     }
177 177
 
178 178
     /**
@@ -180,10 +180,10 @@  discard block
 block discarded – undo
180 180
      * @param int $length
181 181
      * @return string
182 182
      */
183
-    public static function truncate($string, $length)
183
+    public static function truncate( $string, $length )
184 184
     {
185
-        return strlen($string) > $length
186
-            ? substr($string, 0, $length)
185
+        return strlen( $string ) > $length
186
+            ? substr( $string, 0, $length )
187 187
             : $string;
188 188
     }
189 189
 }
Please login to merge, or discard this patch.
plugin/Database/CountsManager.php 2 patches
Indentation   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -13,247 +13,247 @@
 block discarded – undo
13 13
 
14 14
 class CountsManager
15 15
 {
16
-    const LIMIT = 500;
17
-    const META_AVERAGE = '_glsr_average';
18
-    const META_COUNT = '_glsr_count';
19
-    const META_RANKING = '_glsr_ranking';
16
+	const LIMIT = 500;
17
+	const META_AVERAGE = '_glsr_average';
18
+	const META_COUNT = '_glsr_count';
19
+	const META_RANKING = '_glsr_ranking';
20 20
 
21
-    /**
22
-     * @return array
23
-     */
24
-    public function buildCounts(array $args = [])
25
-    {
26
-        $counts = [
27
-            'local' => $this->generateEmptyCountsArray(),
28
-        ];
29
-        $query = $this->queryReviews($args);
30
-        while ($query) {
31
-            $counts = $this->populateCountsFromQuery($query, $counts);
32
-            $query = $query->has_more
33
-                ? $this->queryReviews($args, end($query->reviews)->ID)
34
-                : false;
35
-        }
36
-        return $counts;
37
-    }
21
+	/**
22
+	 * @return array
23
+	 */
24
+	public function buildCounts(array $args = [])
25
+	{
26
+		$counts = [
27
+			'local' => $this->generateEmptyCountsArray(),
28
+		];
29
+		$query = $this->queryReviews($args);
30
+		while ($query) {
31
+			$counts = $this->populateCountsFromQuery($query, $counts);
32
+			$query = $query->has_more
33
+				? $this->queryReviews($args, end($query->reviews)->ID)
34
+				: false;
35
+		}
36
+		return $counts;
37
+	}
38 38
 
39
-    /**
40
-     * @return void
41
-     */
42
-    public function decreaseAll(Review $review)
43
-    {
44
-        glsr(GlobalCountsManager::class)->decrease($review);
45
-        glsr(PostCountsManager::class)->decrease($review);
46
-        glsr(TermCountsManager::class)->decrease($review);
47
-    }
39
+	/**
40
+	 * @return void
41
+	 */
42
+	public function decreaseAll(Review $review)
43
+	{
44
+		glsr(GlobalCountsManager::class)->decrease($review);
45
+		glsr(PostCountsManager::class)->decrease($review);
46
+		glsr(TermCountsManager::class)->decrease($review);
47
+	}
48 48
 
49
-    /**
50
-     * @param string $type
51
-     * @param int $rating
52
-     * @return array
53
-     */
54
-    public function decreaseRating(array $reviewCounts, $type, $rating)
55
-    {
56
-        if (isset($reviewCounts[$type][$rating])) {
57
-            $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1);
58
-        }
59
-        return $reviewCounts;
60
-    }
49
+	/**
50
+	 * @param string $type
51
+	 * @param int $rating
52
+	 * @return array
53
+	 */
54
+	public function decreaseRating(array $reviewCounts, $type, $rating)
55
+	{
56
+		if (isset($reviewCounts[$type][$rating])) {
57
+			$reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1);
58
+		}
59
+		return $reviewCounts;
60
+	}
61 61
 
62
-    /**
63
-     * @return array
64
-     */
65
-    public function flatten(array $reviewCounts, array $args = [])
66
-    {
67
-        $counts = [];
68
-        array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) {
69
-            $counts[$index] = $num + intval(Arr::get($counts, $index, 0));
70
-        });
71
-        $min = Arr::get($args, 'min', glsr()->constant('MIN_RATING', Rating::class));
72
-        $max = Arr::get($args, 'max', glsr()->constant('MAX_RATING', Rating::class));
73
-        foreach ($counts as $index => &$num) {
74
-            if (!Helper::inRange($index, $min, $max)) {
75
-                $num = 0;
76
-            }
77
-        }
78
-        return $counts;
79
-    }
62
+	/**
63
+	 * @return array
64
+	 */
65
+	public function flatten(array $reviewCounts, array $args = [])
66
+	{
67
+		$counts = [];
68
+		array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) {
69
+			$counts[$index] = $num + intval(Arr::get($counts, $index, 0));
70
+		});
71
+		$min = Arr::get($args, 'min', glsr()->constant('MIN_RATING', Rating::class));
72
+		$max = Arr::get($args, 'max', glsr()->constant('MAX_RATING', Rating::class));
73
+		foreach ($counts as $index => &$num) {
74
+			if (!Helper::inRange($index, $min, $max)) {
75
+				$num = 0;
76
+			}
77
+		}
78
+		return $counts;
79
+	}
80 80
 
81
-    /**
82
-     * @return array
83
-     */
84
-    public function getCounts(array $args = [])
85
-    {
86
-        $args = $this->normalizeArgs($args);
87
-        $counts = $this->hasMixedAssignment($args)
88
-            ? $this->buildCounts($args) // force query the database
89
-            : $this->get($args);
90
-        return $this->normalize($counts);
91
-    }
81
+	/**
82
+	 * @return array
83
+	 */
84
+	public function getCounts(array $args = [])
85
+	{
86
+		$args = $this->normalizeArgs($args);
87
+		$counts = $this->hasMixedAssignment($args)
88
+			? $this->buildCounts($args) // force query the database
89
+			: $this->get($args);
90
+		return $this->normalize($counts);
91
+	}
92 92
 
93
-    /**
94
-     * @return void
95
-     */
96
-    public function increaseAll(Review $review)
97
-    {
98
-        glsr(GlobalCountsManager::class)->increase($review);
99
-        glsr(PostCountsManager::class)->increase($review);
100
-        glsr(TermCountsManager::class)->increase($review);
101
-    }
93
+	/**
94
+	 * @return void
95
+	 */
96
+	public function increaseAll(Review $review)
97
+	{
98
+		glsr(GlobalCountsManager::class)->increase($review);
99
+		glsr(PostCountsManager::class)->increase($review);
100
+		glsr(TermCountsManager::class)->increase($review);
101
+	}
102 102
 
103
-    /**
104
-     * @param string $type
105
-     * @param int $rating
106
-     * @return array
107
-     */
108
-    public function increaseRating(array $reviewCounts, $type, $rating)
109
-    {
110
-        if (!array_key_exists($type, glsr()->reviewTypes)) {
111
-            return $reviewCounts;
112
-        }
113
-        if (!array_key_exists($type, $reviewCounts)) {
114
-            $reviewCounts[$type] = [];
115
-        }
116
-        $reviewCounts = $this->normalize($reviewCounts);
117
-        $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1;
118
-        return $reviewCounts;
119
-    }
103
+	/**
104
+	 * @param string $type
105
+	 * @param int $rating
106
+	 * @return array
107
+	 */
108
+	public function increaseRating(array $reviewCounts, $type, $rating)
109
+	{
110
+		if (!array_key_exists($type, glsr()->reviewTypes)) {
111
+			return $reviewCounts;
112
+		}
113
+		if (!array_key_exists($type, $reviewCounts)) {
114
+			$reviewCounts[$type] = [];
115
+		}
116
+		$reviewCounts = $this->normalize($reviewCounts);
117
+		$reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1;
118
+		return $reviewCounts;
119
+	}
120 120
 
121
-    /**
122
-     * @return void
123
-     */
124
-    public function updateAll()
125
-    {
126
-        glsr(GlobalCountsManager::class)->updateAll();
127
-        glsr(PostCountsManager::class)->updateAll();
128
-        glsr(TermCountsManager::class)->updateAll();
129
-    }
121
+	/**
122
+	 * @return void
123
+	 */
124
+	public function updateAll()
125
+	{
126
+		glsr(GlobalCountsManager::class)->updateAll();
127
+		glsr(PostCountsManager::class)->updateAll();
128
+		glsr(TermCountsManager::class)->updateAll();
129
+	}
130 130
 
131
-    /**
132
-     * @return array
133
-     */
134
-    protected function combine(array $results)
135
-    {
136
-        if (!wp_is_numeric_array($results)) {
137
-            return $results;
138
-        }
139
-        $mergedKeys = array_keys(array_merge(...$results));
140
-        $counts = array_fill_keys($mergedKeys, $this->generateEmptyCountsArray());
141
-        foreach ($results as $typeRatings) {
142
-            foreach ($typeRatings as $type => $ratings) {
143
-                foreach ($ratings as $index => $rating) {
144
-                    $counts[$type][$index] = intval($rating) + $counts[$type][$index];
145
-                }
146
-            }
147
-        }
148
-        return $counts;
149
-    }
131
+	/**
132
+	 * @return array
133
+	 */
134
+	protected function combine(array $results)
135
+	{
136
+		if (!wp_is_numeric_array($results)) {
137
+			return $results;
138
+		}
139
+		$mergedKeys = array_keys(array_merge(...$results));
140
+		$counts = array_fill_keys($mergedKeys, $this->generateEmptyCountsArray());
141
+		foreach ($results as $typeRatings) {
142
+			foreach ($typeRatings as $type => $ratings) {
143
+				foreach ($ratings as $index => $rating) {
144
+					$counts[$type][$index] = intval($rating) + $counts[$type][$index];
145
+				}
146
+			}
147
+		}
148
+		return $counts;
149
+	}
150 150
 
151
-    /**
152
-     * @return array
153
-     */
154
-    protected function generateEmptyCountsArray()
155
-    {
156
-        return array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0);
157
-    }
151
+	/**
152
+	 * @return array
153
+	 */
154
+	protected function generateEmptyCountsArray()
155
+	{
156
+		return array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0);
157
+	}
158 158
 
159
-    /**
160
-     * @return array
161
-     */
162
-    protected function get($args)
163
-    {
164
-        $results = [];
165
-        foreach ($args['post_ids'] as $postId) {
166
-            $results[] = glsr(PostCountsManager::class)->get($postId);
167
-        }
168
-        foreach ($args['term_ids'] as $termId) {
169
-            $results[] = glsr(TermCountsManager::class)->get($termId);
170
-        }
171
-        if (empty($results)) {
172
-            $results[] = glsr(GlobalCountsManager::class)->get();
173
-        }
174
-        $results[] = ['local' => $this->generateEmptyCountsArray()]; // make sure there is a fallback
175
-        return $this->combine($results);
176
-    }
159
+	/**
160
+	 * @return array
161
+	 */
162
+	protected function get($args)
163
+	{
164
+		$results = [];
165
+		foreach ($args['post_ids'] as $postId) {
166
+			$results[] = glsr(PostCountsManager::class)->get($postId);
167
+		}
168
+		foreach ($args['term_ids'] as $termId) {
169
+			$results[] = glsr(TermCountsManager::class)->get($termId);
170
+		}
171
+		if (empty($results)) {
172
+			$results[] = glsr(GlobalCountsManager::class)->get();
173
+		}
174
+		$results[] = ['local' => $this->generateEmptyCountsArray()]; // make sure there is a fallback
175
+		return $this->combine($results);
176
+	}
177 177
 
178
-    /**
179
-     * @return bool
180
-     */
181
-    protected function hasMixedAssignment(array $args)
182
-    {
183
-        return !empty($args['post_ids']) && !empty($args['term_ids']);
184
-    }
178
+	/**
179
+	 * @return bool
180
+	 */
181
+	protected function hasMixedAssignment(array $args)
182
+	{
183
+		return !empty($args['post_ids']) && !empty($args['term_ids']);
184
+	}
185 185
 
186
-    /**
187
-     * @return array
188
-     */
189
-    protected function normalize(array $reviewCounts)
190
-    {
191
-        foreach ($reviewCounts as &$counts) {
192
-            foreach (array_keys($this->generateEmptyCountsArray()) as $index) {
193
-                if (!isset($counts[$index])) {
194
-                    $counts[$index] = 0;
195
-                }
196
-            }
197
-            ksort($counts);
198
-        }
199
-        return $reviewCounts;
200
-    }
186
+	/**
187
+	 * @return array
188
+	 */
189
+	protected function normalize(array $reviewCounts)
190
+	{
191
+		foreach ($reviewCounts as &$counts) {
192
+			foreach (array_keys($this->generateEmptyCountsArray()) as $index) {
193
+				if (!isset($counts[$index])) {
194
+					$counts[$index] = 0;
195
+				}
196
+			}
197
+			ksort($counts);
198
+		}
199
+		return $reviewCounts;
200
+	}
201 201
 
202
-    /**
203
-     * @return array
204
-     */
205
-    protected function normalizeArgs(array $args)
206
-    {
207
-        $args = wp_parse_args(array_filter($args), [
208
-            'post_ids' => [],
209
-            'term_ids' => [],
210
-            'type' => 'local',
211
-        ]);
212
-        $args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']);
213
-        $args['type'] = $this->normalizeType($args['type']);
214
-        return $args;
215
-    }
202
+	/**
203
+	 * @return array
204
+	 */
205
+	protected function normalizeArgs(array $args)
206
+	{
207
+		$args = wp_parse_args(array_filter($args), [
208
+			'post_ids' => [],
209
+			'term_ids' => [],
210
+			'type' => 'local',
211
+		]);
212
+		$args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']);
213
+		$args['type'] = $this->normalizeType($args['type']);
214
+		return $args;
215
+	}
216 216
 
217
-    /**
218
-     * @param string $type
219
-     * @return string
220
-     */
221
-    protected function normalizeType($type)
222
-    {
223
-        return empty($type) || !is_string($type)
224
-            ? 'local'
225
-            : $type;
226
-    }
217
+	/**
218
+	 * @param string $type
219
+	 * @return string
220
+	 */
221
+	protected function normalizeType($type)
222
+	{
223
+		return empty($type) || !is_string($type)
224
+			? 'local'
225
+			: $type;
226
+	}
227 227
 
228
-    /**
229
-     * @param object $query
230
-     * @return array
231
-     */
232
-    protected function populateCountsFromQuery($query, array $counts)
233
-    {
234
-        foreach ($query->reviews as $review) {
235
-            $type = $this->normalizeType($review->type);
236
-            if (!array_key_exists($type, $counts)) {
237
-                $counts[$type] = $this->generateEmptyCountsArray();
238
-            }
239
-            ++$counts[$type][$review->rating];
240
-        }
241
-        return $counts;
242
-    }
228
+	/**
229
+	 * @param object $query
230
+	 * @return array
231
+	 */
232
+	protected function populateCountsFromQuery($query, array $counts)
233
+	{
234
+		foreach ($query->reviews as $review) {
235
+			$type = $this->normalizeType($review->type);
236
+			if (!array_key_exists($type, $counts)) {
237
+				$counts[$type] = $this->generateEmptyCountsArray();
238
+			}
239
+			++$counts[$type][$review->rating];
240
+		}
241
+		return $counts;
242
+	}
243 243
 
244
-    /**
245
-     * @param int $lastPostId
246
-     * @return object
247
-     */
248
-    protected function queryReviews(array $args = [], $lastPostId = 0)
249
-    {
250
-        $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT);
251
-        $hasMore = is_array($reviews)
252
-            ? count($reviews) == static::LIMIT
253
-            : false;
254
-        return (object) [
255
-            'has_more' => $hasMore,
256
-            'reviews' => $reviews,
257
-        ];
258
-    }
244
+	/**
245
+	 * @param int $lastPostId
246
+	 * @return object
247
+	 */
248
+	protected function queryReviews(array $args = [], $lastPostId = 0)
249
+	{
250
+		$reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT);
251
+		$hasMore = is_array($reviews)
252
+			? count($reviews) == static::LIMIT
253
+			: false;
254
+		return (object) [
255
+			'has_more' => $hasMore,
256
+			'reviews' => $reviews,
257
+		];
258
+	}
259 259
 }
Please login to merge, or discard this patch.
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -21,16 +21,16 @@  discard block
 block discarded – undo
21 21
     /**
22 22
      * @return array
23 23
      */
24
-    public function buildCounts(array $args = [])
24
+    public function buildCounts( array $args = [] )
25 25
     {
26 26
         $counts = [
27 27
             'local' => $this->generateEmptyCountsArray(),
28 28
         ];
29
-        $query = $this->queryReviews($args);
30
-        while ($query) {
31
-            $counts = $this->populateCountsFromQuery($query, $counts);
29
+        $query = $this->queryReviews( $args );
30
+        while( $query ) {
31
+            $counts = $this->populateCountsFromQuery( $query, $counts );
32 32
             $query = $query->has_more
33
-                ? $this->queryReviews($args, end($query->reviews)->ID)
33
+                ? $this->queryReviews( $args, end( $query->reviews )->ID )
34 34
                 : false;
35 35
         }
36 36
         return $counts;
@@ -39,11 +39,11 @@  discard block
 block discarded – undo
39 39
     /**
40 40
      * @return void
41 41
      */
42
-    public function decreaseAll(Review $review)
42
+    public function decreaseAll( Review $review )
43 43
     {
44
-        glsr(GlobalCountsManager::class)->decrease($review);
45
-        glsr(PostCountsManager::class)->decrease($review);
46
-        glsr(TermCountsManager::class)->decrease($review);
44
+        glsr( GlobalCountsManager::class )->decrease( $review );
45
+        glsr( PostCountsManager::class )->decrease( $review );
46
+        glsr( TermCountsManager::class )->decrease( $review );
47 47
     }
48 48
 
49 49
     /**
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
      * @param int $rating
52 52
      * @return array
53 53
      */
54
-    public function decreaseRating(array $reviewCounts, $type, $rating)
54
+    public function decreaseRating( array $reviewCounts, $type, $rating )
55 55
     {
56
-        if (isset($reviewCounts[$type][$rating])) {
57
-            $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1);
56
+        if( isset($reviewCounts[$type][$rating]) ) {
57
+            $reviewCounts[$type][$rating] = max( 0, $reviewCounts[$type][$rating] - 1 );
58 58
         }
59 59
         return $reviewCounts;
60 60
     }
@@ -62,16 +62,16 @@  discard block
 block discarded – undo
62 62
     /**
63 63
      * @return array
64 64
      */
65
-    public function flatten(array $reviewCounts, array $args = [])
65
+    public function flatten( array $reviewCounts, array $args = [] )
66 66
     {
67 67
         $counts = [];
68
-        array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) {
69
-            $counts[$index] = $num + intval(Arr::get($counts, $index, 0));
68
+        array_walk_recursive( $reviewCounts, function( $num, $index ) use (&$counts) {
69
+            $counts[$index] = $num + intval( Arr::get( $counts, $index, 0 ) );
70 70
         });
71
-        $min = Arr::get($args, 'min', glsr()->constant('MIN_RATING', Rating::class));
72
-        $max = Arr::get($args, 'max', glsr()->constant('MAX_RATING', Rating::class));
73
-        foreach ($counts as $index => &$num) {
74
-            if (!Helper::inRange($index, $min, $max)) {
71
+        $min = Arr::get( $args, 'min', glsr()->constant( 'MIN_RATING', Rating::class ) );
72
+        $max = Arr::get( $args, 'max', glsr()->constant( 'MAX_RATING', Rating::class ) );
73
+        foreach( $counts as $index => &$num ) {
74
+            if( !Helper::inRange( $index, $min, $max ) ) {
75 75
                 $num = 0;
76 76
             }
77 77
         }
@@ -81,23 +81,23 @@  discard block
 block discarded – undo
81 81
     /**
82 82
      * @return array
83 83
      */
84
-    public function getCounts(array $args = [])
84
+    public function getCounts( array $args = [] )
85 85
     {
86
-        $args = $this->normalizeArgs($args);
87
-        $counts = $this->hasMixedAssignment($args)
88
-            ? $this->buildCounts($args) // force query the database
89
-            : $this->get($args);
90
-        return $this->normalize($counts);
86
+        $args = $this->normalizeArgs( $args );
87
+        $counts = $this->hasMixedAssignment( $args )
88
+            ? $this->buildCounts( $args ) // force query the database
89
+            : $this->get( $args );
90
+        return $this->normalize( $counts );
91 91
     }
92 92
 
93 93
     /**
94 94
      * @return void
95 95
      */
96
-    public function increaseAll(Review $review)
96
+    public function increaseAll( Review $review )
97 97
     {
98
-        glsr(GlobalCountsManager::class)->increase($review);
99
-        glsr(PostCountsManager::class)->increase($review);
100
-        glsr(TermCountsManager::class)->increase($review);
98
+        glsr( GlobalCountsManager::class )->increase( $review );
99
+        glsr( PostCountsManager::class )->increase( $review );
100
+        glsr( TermCountsManager::class )->increase( $review );
101 101
     }
102 102
 
103 103
     /**
@@ -105,16 +105,16 @@  discard block
 block discarded – undo
105 105
      * @param int $rating
106 106
      * @return array
107 107
      */
108
-    public function increaseRating(array $reviewCounts, $type, $rating)
108
+    public function increaseRating( array $reviewCounts, $type, $rating )
109 109
     {
110
-        if (!array_key_exists($type, glsr()->reviewTypes)) {
110
+        if( !array_key_exists( $type, glsr()->reviewTypes ) ) {
111 111
             return $reviewCounts;
112 112
         }
113
-        if (!array_key_exists($type, $reviewCounts)) {
113
+        if( !array_key_exists( $type, $reviewCounts ) ) {
114 114
             $reviewCounts[$type] = [];
115 115
         }
116
-        $reviewCounts = $this->normalize($reviewCounts);
117
-        $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1;
116
+        $reviewCounts = $this->normalize( $reviewCounts );
117
+        $reviewCounts[$type][$rating] = intval( $reviewCounts[$type][$rating] ) + 1;
118 118
         return $reviewCounts;
119 119
     }
120 120
 
@@ -123,25 +123,25 @@  discard block
 block discarded – undo
123 123
      */
124 124
     public function updateAll()
125 125
     {
126
-        glsr(GlobalCountsManager::class)->updateAll();
127
-        glsr(PostCountsManager::class)->updateAll();
128
-        glsr(TermCountsManager::class)->updateAll();
126
+        glsr( GlobalCountsManager::class )->updateAll();
127
+        glsr( PostCountsManager::class )->updateAll();
128
+        glsr( TermCountsManager::class )->updateAll();
129 129
     }
130 130
 
131 131
     /**
132 132
      * @return array
133 133
      */
134
-    protected function combine(array $results)
134
+    protected function combine( array $results )
135 135
     {
136
-        if (!wp_is_numeric_array($results)) {
136
+        if( !wp_is_numeric_array( $results ) ) {
137 137
             return $results;
138 138
         }
139
-        $mergedKeys = array_keys(array_merge(...$results));
140
-        $counts = array_fill_keys($mergedKeys, $this->generateEmptyCountsArray());
141
-        foreach ($results as $typeRatings) {
142
-            foreach ($typeRatings as $type => $ratings) {
143
-                foreach ($ratings as $index => $rating) {
144
-                    $counts[$type][$index] = intval($rating) + $counts[$type][$index];
139
+        $mergedKeys = array_keys( array_merge( ...$results ) );
140
+        $counts = array_fill_keys( $mergedKeys, $this->generateEmptyCountsArray() );
141
+        foreach( $results as $typeRatings ) {
142
+            foreach( $typeRatings as $type => $ratings ) {
143
+                foreach( $ratings as $index => $rating ) {
144
+                    $counts[$type][$index] = intval( $rating ) + $counts[$type][$index];
145 145
                 }
146 146
             }
147 147
         }
@@ -153,32 +153,32 @@  discard block
 block discarded – undo
153 153
      */
154 154
     protected function generateEmptyCountsArray()
155 155
     {
156
-        return array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0);
156
+        return array_fill_keys( range( 0, glsr()->constant( 'MAX_RATING', Rating::class ) ), 0 );
157 157
     }
158 158
 
159 159
     /**
160 160
      * @return array
161 161
      */
162
-    protected function get($args)
162
+    protected function get( $args )
163 163
     {
164 164
         $results = [];
165
-        foreach ($args['post_ids'] as $postId) {
166
-            $results[] = glsr(PostCountsManager::class)->get($postId);
165
+        foreach( $args['post_ids'] as $postId ) {
166
+            $results[] = glsr( PostCountsManager::class )->get( $postId );
167 167
         }
168
-        foreach ($args['term_ids'] as $termId) {
169
-            $results[] = glsr(TermCountsManager::class)->get($termId);
168
+        foreach( $args['term_ids'] as $termId ) {
169
+            $results[] = glsr( TermCountsManager::class )->get( $termId );
170 170
         }
171
-        if (empty($results)) {
172
-            $results[] = glsr(GlobalCountsManager::class)->get();
171
+        if( empty($results) ) {
172
+            $results[] = glsr( GlobalCountsManager::class )->get();
173 173
         }
174 174
         $results[] = ['local' => $this->generateEmptyCountsArray()]; // make sure there is a fallback
175
-        return $this->combine($results);
175
+        return $this->combine( $results );
176 176
     }
177 177
 
178 178
     /**
179 179
      * @return bool
180 180
      */
181
-    protected function hasMixedAssignment(array $args)
181
+    protected function hasMixedAssignment( array $args )
182 182
     {
183 183
         return !empty($args['post_ids']) && !empty($args['term_ids']);
184 184
     }
@@ -186,15 +186,15 @@  discard block
 block discarded – undo
186 186
     /**
187 187
      * @return array
188 188
      */
189
-    protected function normalize(array $reviewCounts)
189
+    protected function normalize( array $reviewCounts )
190 190
     {
191
-        foreach ($reviewCounts as &$counts) {
192
-            foreach (array_keys($this->generateEmptyCountsArray()) as $index) {
193
-                if (!isset($counts[$index])) {
191
+        foreach( $reviewCounts as &$counts ) {
192
+            foreach( array_keys( $this->generateEmptyCountsArray() ) as $index ) {
193
+                if( !isset($counts[$index]) ) {
194 194
                     $counts[$index] = 0;
195 195
                 }
196 196
             }
197
-            ksort($counts);
197
+            ksort( $counts );
198 198
         }
199 199
         return $reviewCounts;
200 200
     }
@@ -202,15 +202,15 @@  discard block
 block discarded – undo
202 202
     /**
203 203
      * @return array
204 204
      */
205
-    protected function normalizeArgs(array $args)
205
+    protected function normalizeArgs( array $args )
206 206
     {
207
-        $args = wp_parse_args(array_filter($args), [
207
+        $args = wp_parse_args( array_filter( $args ), [
208 208
             'post_ids' => [],
209 209
             'term_ids' => [],
210 210
             'type' => 'local',
211
-        ]);
212
-        $args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']);
213
-        $args['type'] = $this->normalizeType($args['type']);
211
+        ] );
212
+        $args['post_ids'] = glsr( Multilingual::class )->getPostIds( $args['post_ids'] );
213
+        $args['type'] = $this->normalizeType( $args['type'] );
214 214
         return $args;
215 215
     }
216 216
 
@@ -218,9 +218,9 @@  discard block
 block discarded – undo
218 218
      * @param string $type
219 219
      * @return string
220 220
      */
221
-    protected function normalizeType($type)
221
+    protected function normalizeType( $type )
222 222
     {
223
-        return empty($type) || !is_string($type)
223
+        return empty($type) || !is_string( $type )
224 224
             ? 'local'
225 225
             : $type;
226 226
     }
@@ -229,11 +229,11 @@  discard block
 block discarded – undo
229 229
      * @param object $query
230 230
      * @return array
231 231
      */
232
-    protected function populateCountsFromQuery($query, array $counts)
232
+    protected function populateCountsFromQuery( $query, array $counts )
233 233
     {
234
-        foreach ($query->reviews as $review) {
235
-            $type = $this->normalizeType($review->type);
236
-            if (!array_key_exists($type, $counts)) {
234
+        foreach( $query->reviews as $review ) {
235
+            $type = $this->normalizeType( $review->type );
236
+            if( !array_key_exists( $type, $counts ) ) {
237 237
                 $counts[$type] = $this->generateEmptyCountsArray();
238 238
             }
239 239
             ++$counts[$type][$review->rating];
@@ -245,13 +245,13 @@  discard block
 block discarded – undo
245 245
      * @param int $lastPostId
246 246
      * @return object
247 247
      */
248
-    protected function queryReviews(array $args = [], $lastPostId = 0)
248
+    protected function queryReviews( array $args = [], $lastPostId = 0 )
249 249
     {
250
-        $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT);
251
-        $hasMore = is_array($reviews)
252
-            ? count($reviews) == static::LIMIT
250
+        $reviews = glsr( SqlQueries::class )->getReviewCounts( $args, $lastPostId, static::LIMIT );
251
+        $hasMore = is_array( $reviews )
252
+            ? count( $reviews ) == static::LIMIT
253 253
             : false;
254
-        return (object) [
254
+        return (object)[
255 255
             'has_more' => $hasMore,
256 256
             'reviews' => $reviews,
257 257
         ];
Please login to merge, or discard this patch.