Passed
Push — feature/rebusify ( 0fe5b2...103190 )
by Paul
08:37 queued 03:55
created
plugin/HelperTraits/Arr.php 1 patch
Indentation   +173 added lines, -173 removed lines patch added patch discarded remove patch
@@ -4,188 +4,188 @@
 block discarded – undo
4 4
 
5 5
 trait Arr
6 6
 {
7
-    /**
8
-     * @return bool
9
-     */
10
-    public function compareArrays(array $arr1, array $arr2)
11
-    {
12
-        sort($arr1);
13
-        sort($arr2);
14
-        return $arr1 == $arr2;
15
-    }
7
+	/**
8
+	 * @return bool
9
+	 */
10
+	public function compareArrays(array $arr1, array $arr2)
11
+	{
12
+		sort($arr1);
13
+		sort($arr2);
14
+		return $arr1 == $arr2;
15
+	}
16 16
 
17
-    /**
18
-     * @param mixed $array
19
-     * @return array
20
-     */
21
-    public function consolidateArray($array)
22
-    {
23
-        return is_array($array) || is_object($array)
24
-            ? (array) $array
25
-            : [];
26
-    }
17
+	/**
18
+	 * @param mixed $array
19
+	 * @return array
20
+	 */
21
+	public function consolidateArray($array)
22
+	{
23
+		return is_array($array) || is_object($array)
24
+			? (array) $array
25
+			: [];
26
+	}
27 27
 
28
-    /**
29
-     * @return array
30
-     */
31
-    public function convertDotNotationArray(array $array)
32
-    {
33
-        $results = [];
34
-        foreach ($array as $path => $value) {
35
-            $results = $this->dataSet($results, $path, $value);
36
-        }
37
-        return $results;
38
-    }
28
+	/**
29
+	 * @return array
30
+	 */
31
+	public function convertDotNotationArray(array $array)
32
+	{
33
+		$results = [];
34
+		foreach ($array as $path => $value) {
35
+			$results = $this->dataSet($results, $path, $value);
36
+		}
37
+		return $results;
38
+	}
39 39
 
40
-    /**
41
-     * @param string $string
42
-     * @param mixed $callback
43
-     * @return array
44
-     */
45
-    public function convertStringToArray($string, $callback = null)
46
-    {
47
-        $array = array_map('trim', explode(',', $string));
48
-        return $callback
49
-            ? array_filter($array, $callback)
50
-            : array_filter($array);
51
-    }
40
+	/**
41
+	 * @param string $string
42
+	 * @param mixed $callback
43
+	 * @return array
44
+	 */
45
+	public function convertStringToArray($string, $callback = null)
46
+	{
47
+		$array = array_map('trim', explode(',', $string));
48
+		return $callback
49
+			? array_filter($array, $callback)
50
+			: array_filter($array);
51
+	}
52 52
 
53
-    /**
54
-     * Get a value from an array of values using a dot-notation path as reference.
55
-     * @param array $data
56
-     * @param string $path
57
-     * @param mixed $fallback
58
-     * @return mixed
59
-     */
60
-    public function dataGet($data, $path = '', $fallback = '')
61
-    {
62
-        $data = $this->consolidateArray($data);
63
-        $keys = explode('.', $path);
64
-        foreach ($keys as $key) {
65
-            if (!isset($data[$key])) {
66
-                return $fallback;
67
-            }
68
-            $data = $data[$key];
69
-        }
70
-        return $data;
71
-    }
53
+	/**
54
+	 * Get a value from an array of values using a dot-notation path as reference.
55
+	 * @param array $data
56
+	 * @param string $path
57
+	 * @param mixed $fallback
58
+	 * @return mixed
59
+	 */
60
+	public function dataGet($data, $path = '', $fallback = '')
61
+	{
62
+		$data = $this->consolidateArray($data);
63
+		$keys = explode('.', $path);
64
+		foreach ($keys as $key) {
65
+			if (!isset($data[$key])) {
66
+				return $fallback;
67
+			}
68
+			$data = $data[$key];
69
+		}
70
+		return $data;
71
+	}
72 72
 
73
-    /**
74
-     * Set a value to an array of values using a dot-notation path as reference.
75
-     * @param string $path
76
-     * @param mixed $value
77
-     * @return array
78
-     */
79
-    public function dataSet(array $data, $path, $value)
80
-    {
81
-        $token = strtok($path, '.');
82
-        $ref = &$data;
83
-        while (false !== $token) {
84
-            $ref = $this->consolidateArray($ref);
85
-            $ref = &$ref[$token];
86
-            $token = strtok('.');
87
-        }
88
-        $ref = $value;
89
-        return $data;
90
-    }
73
+	/**
74
+	 * Set a value to an array of values using a dot-notation path as reference.
75
+	 * @param string $path
76
+	 * @param mixed $value
77
+	 * @return array
78
+	 */
79
+	public function dataSet(array $data, $path, $value)
80
+	{
81
+		$token = strtok($path, '.');
82
+		$ref = &$data;
83
+		while (false !== $token) {
84
+			$ref = $this->consolidateArray($ref);
85
+			$ref = &$ref[$token];
86
+			$token = strtok('.');
87
+		}
88
+		$ref = $value;
89
+		return $data;
90
+	}
91 91
 
92
-    /**
93
-     * @param bool $flattenValue
94
-     * @param string $prefix
95
-     * @return array
96
-     */
97
-    public function flattenArray(array $array, $flattenValue = false, $prefix = '')
98
-    {
99
-        $result = [];
100
-        foreach ($array as $key => $value) {
101
-            $newKey = ltrim($prefix.'.'.$key, '.');
102
-            if ($this->isIndexedFlatArray($value)) {
103
-                if ($flattenValue) {
104
-                    $value = '['.implode(', ', $value).']';
105
-                }
106
-            } elseif (is_array($value)) {
107
-                $result = array_merge($result, $this->flattenArray($value, $flattenValue, $newKey));
108
-                continue;
109
-            }
110
-            $result[$newKey] = $value;
111
-        }
112
-        return $result;
113
-    }
92
+	/**
93
+	 * @param bool $flattenValue
94
+	 * @param string $prefix
95
+	 * @return array
96
+	 */
97
+	public function flattenArray(array $array, $flattenValue = false, $prefix = '')
98
+	{
99
+		$result = [];
100
+		foreach ($array as $key => $value) {
101
+			$newKey = ltrim($prefix.'.'.$key, '.');
102
+			if ($this->isIndexedFlatArray($value)) {
103
+				if ($flattenValue) {
104
+					$value = '['.implode(', ', $value).']';
105
+				}
106
+			} elseif (is_array($value)) {
107
+				$result = array_merge($result, $this->flattenArray($value, $flattenValue, $newKey));
108
+				continue;
109
+			}
110
+			$result[$newKey] = $value;
111
+		}
112
+		return $result;
113
+	}
114 114
 
115
-    /**
116
-     * @param string $key
117
-     * @param string $position
118
-     * @return array
119
-     */
120
-    public function insertInArray(array $array, array $insert, $key, $position = 'before')
121
-    {
122
-        $keyPosition = intval(array_search($key, array_keys($array)));
123
-        if ('after' == $position) {
124
-            ++$keyPosition;
125
-        }
126
-        if (false !== $keyPosition) {
127
-            $result = array_slice($array, 0, $keyPosition);
128
-            $result = array_merge($result, $insert);
129
-            return array_merge($result, array_slice($array, $keyPosition));
130
-        }
131
-        return array_merge($array, $insert);
132
-    }
115
+	/**
116
+	 * @param string $key
117
+	 * @param string $position
118
+	 * @return array
119
+	 */
120
+	public function insertInArray(array $array, array $insert, $key, $position = 'before')
121
+	{
122
+		$keyPosition = intval(array_search($key, array_keys($array)));
123
+		if ('after' == $position) {
124
+			++$keyPosition;
125
+		}
126
+		if (false !== $keyPosition) {
127
+			$result = array_slice($array, 0, $keyPosition);
128
+			$result = array_merge($result, $insert);
129
+			return array_merge($result, array_slice($array, $keyPosition));
130
+		}
131
+		return array_merge($array, $insert);
132
+	}
133 133
 
134
-    /**
135
-     * @param mixed $array
136
-     * @return bool
137
-     */
138
-    public function isIndexedFlatArray($array)
139
-    {
140
-        if (!is_array($array) || array_filter($array, 'is_array')) {
141
-            return false;
142
-        }
143
-        return wp_is_numeric_array($array);
144
-    }
134
+	/**
135
+	 * @param mixed $array
136
+	 * @return bool
137
+	 */
138
+	public function isIndexedFlatArray($array)
139
+	{
140
+		if (!is_array($array) || array_filter($array, 'is_array')) {
141
+			return false;
142
+		}
143
+		return wp_is_numeric_array($array);
144
+	}
145 145
 
146
-    /**
147
-     * @param bool $prefixed
148
-     * @return array
149
-     */
150
-    public function prefixArrayKeys(array $values, $prefixed = true)
151
-    {
152
-        $trim = '_';
153
-        $prefix = $prefixed
154
-            ? $trim
155
-            : '';
156
-        $prefixed = [];
157
-        foreach ($values as $key => $value) {
158
-            $key = trim($key);
159
-            if (0 === strpos($key, $trim)) {
160
-                $key = substr($key, strlen($trim));
161
-            }
162
-            $prefixed[$prefix.$key] = $value;
163
-        }
164
-        return $prefixed;
165
-    }
146
+	/**
147
+	 * @param bool $prefixed
148
+	 * @return array
149
+	 */
150
+	public function prefixArrayKeys(array $values, $prefixed = true)
151
+	{
152
+		$trim = '_';
153
+		$prefix = $prefixed
154
+			? $trim
155
+			: '';
156
+		$prefixed = [];
157
+		foreach ($values as $key => $value) {
158
+			$key = trim($key);
159
+			if (0 === strpos($key, $trim)) {
160
+				$key = substr($key, strlen($trim));
161
+			}
162
+			$prefixed[$prefix.$key] = $value;
163
+		}
164
+		return $prefixed;
165
+	}
166 166
 
167
-    /**
168
-     * @return array
169
-     */
170
-    public function removeEmptyArrayValues(array $array)
171
-    {
172
-        $result = [];
173
-        foreach ($array as $key => $value) {
174
-            if (!$value) {
175
-                continue;
176
-            }
177
-            $result[$key] = is_array($value)
178
-                ? $this->removeEmptyArrayValues($value)
179
-                : $value;
180
-        }
181
-        return $result;
182
-    }
167
+	/**
168
+	 * @return array
169
+	 */
170
+	public function removeEmptyArrayValues(array $array)
171
+	{
172
+		$result = [];
173
+		foreach ($array as $key => $value) {
174
+			if (!$value) {
175
+				continue;
176
+			}
177
+			$result[$key] = is_array($value)
178
+				? $this->removeEmptyArrayValues($value)
179
+				: $value;
180
+		}
181
+		return $result;
182
+	}
183 183
 
184
-    /**
185
-     * @return array
186
-     */
187
-    public function unprefixArrayKeys(array $values)
188
-    {
189
-        return $this->prefixArrayKeys($values, false);
190
-    }
184
+	/**
185
+	 * @return array
186
+	 */
187
+	public function unprefixArrayKeys(array $values)
188
+	{
189
+		return $this->prefixArrayKeys($values, false);
190
+	}
191 191
 }
Please login to merge, or discard this patch.
plugin/HelperTraits/Str.php 1 patch
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -4,108 +4,108 @@
 block discarded – undo
4 4
 
5 5
 trait Str
6 6
 {
7
-    /**
8
-     * @param string $string
9
-     * @return string
10
-     */
11
-    public function camelCase($string)
12
-    {
13
-        $string = ucwords(str_replace(['-', '_'], ' ', trim($string)));
14
-        return str_replace(' ', '', $string);
15
-    }
7
+	/**
8
+	 * @param string $string
9
+	 * @return string
10
+	 */
11
+	public function camelCase($string)
12
+	{
13
+		$string = ucwords(str_replace(['-', '_'], ' ', trim($string)));
14
+		return str_replace(' ', '', $string);
15
+	}
16 16
 
17
-    /**
18
-     * @param string $name
19
-     * @return string
20
-     */
21
-    public function convertPathToId($path, $prefix = '')
22
-    {
23
-        return str_replace(['[', ']'], ['-', ''], $this->convertPathToName($path, $prefix));
24
-    }
17
+	/**
18
+	 * @param string $name
19
+	 * @return string
20
+	 */
21
+	public function convertPathToId($path, $prefix = '')
22
+	{
23
+		return str_replace(['[', ']'], ['-', ''], $this->convertPathToName($path, $prefix));
24
+	}
25 25
 
26
-    /**
27
-     * @param string $path
28
-     * @return string
29
-     */
30
-    public function convertPathToName($path, $prefix = '')
31
-    {
32
-        $levels = explode('.', $path);
33
-        return array_reduce($levels, function ($result, $value) {
34
-            return $result .= '['.$value.']';
35
-        }, $prefix);
36
-    }
26
+	/**
27
+	 * @param string $path
28
+	 * @return string
29
+	 */
30
+	public function convertPathToName($path, $prefix = '')
31
+	{
32
+		$levels = explode('.', $path);
33
+		return array_reduce($levels, function ($result, $value) {
34
+			return $result .= '['.$value.']';
35
+		}, $prefix);
36
+	}
37 37
 
38
-    /**
39
-     * @param string $string
40
-     * @return string
41
-     */
42
-    public function dashCase($string)
43
-    {
44
-        return str_replace('_', '-', $this->snakeCase($string));
45
-    }
38
+	/**
39
+	 * @param string $string
40
+	 * @return string
41
+	 */
42
+	public function dashCase($string)
43
+	{
44
+		return str_replace('_', '-', $this->snakeCase($string));
45
+	}
46 46
 
47
-    /**
48
-     * @param string $needle
49
-     * @param string $haystack
50
-     * @return bool
51
-     */
52
-    public function endsWith($needle, $haystack)
53
-    {
54
-        $length = strlen($needle);
55
-        return 0 != $length
56
-            ? substr($haystack, -$length) === $needle
57
-            : true;
58
-    }
47
+	/**
48
+	 * @param string $needle
49
+	 * @param string $haystack
50
+	 * @return bool
51
+	 */
52
+	public function endsWith($needle, $haystack)
53
+	{
54
+		$length = strlen($needle);
55
+		return 0 != $length
56
+			? substr($haystack, -$length) === $needle
57
+			: true;
58
+	}
59 59
 
60
-    /**
61
-     * @param string $prefix
62
-     * @param string $string
63
-     * @param string|null $trim
64
-     * @return string
65
-     */
66
-    public function prefix($prefix, $string, $trim = null)
67
-    {
68
-        if (null === $trim) {
69
-            $trim = $prefix;
70
-        }
71
-        return $prefix.trim($this->removePrefix($trim, $string));
72
-    }
60
+	/**
61
+	 * @param string $prefix
62
+	 * @param string $string
63
+	 * @param string|null $trim
64
+	 * @return string
65
+	 */
66
+	public function prefix($prefix, $string, $trim = null)
67
+	{
68
+		if (null === $trim) {
69
+			$trim = $prefix;
70
+		}
71
+		return $prefix.trim($this->removePrefix($trim, $string));
72
+	}
73 73
 
74
-    /**
75
-     * @param string $prefix
76
-     * @param string $string
77
-     * @return string
78
-     */
79
-    public function removePrefix($prefix, $string)
80
-    {
81
-        return $this->startsWith($prefix, $string)
82
-            ? substr($string, strlen($prefix))
83
-            : $string;
84
-    }
74
+	/**
75
+	 * @param string $prefix
76
+	 * @param string $string
77
+	 * @return string
78
+	 */
79
+	public function removePrefix($prefix, $string)
80
+	{
81
+		return $this->startsWith($prefix, $string)
82
+			? substr($string, strlen($prefix))
83
+			: $string;
84
+	}
85 85
 
86
-    /**
87
-     * @param string $string
88
-     * @return string
89
-     */
90
-    public function snakeCase($string)
91
-    {
92
-        if (!ctype_lower($string)) {
93
-            $string = preg_replace('/\s+/u', '', $string);
94
-            $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string);
95
-            $string = function_exists('mb_strtolower')
96
-                ? mb_strtolower($string, 'UTF-8')
97
-                : strtolower($string);
98
-        }
99
-        return str_replace('-', '_', $string);
100
-    }
86
+	/**
87
+	 * @param string $string
88
+	 * @return string
89
+	 */
90
+	public function snakeCase($string)
91
+	{
92
+		if (!ctype_lower($string)) {
93
+			$string = preg_replace('/\s+/u', '', $string);
94
+			$string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string);
95
+			$string = function_exists('mb_strtolower')
96
+				? mb_strtolower($string, 'UTF-8')
97
+				: strtolower($string);
98
+		}
99
+		return str_replace('-', '_', $string);
100
+	}
101 101
 
102
-    /**
103
-     * @param string $needle
104
-     * @param string $haystack
105
-     * @return bool
106
-     */
107
-    public function startsWith($needle, $haystack)
108
-    {
109
-        return substr($haystack, 0, strlen($needle)) === $needle;
110
-    }
102
+	/**
103
+	 * @param string $needle
104
+	 * @param string $haystack
105
+	 * @return bool
106
+	 */
107
+	public function startsWith($needle, $haystack)
108
+	{
109
+		return substr($haystack, 0, strlen($needle)) === $needle;
110
+	}
111 111
 }
Please login to merge, or discard this patch.
helpers.php 1 patch
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -9,25 +9,25 @@  discard block
 block discarded – undo
9 9
  * @return mixed
10 10
  */
11 11
 add_filter('plugins_loaded', function () {
12
-    $hooks = array(
13
-        'glsr_calculate_ratings' => 1,
14
-        'glsr_create_review' => 2,
15
-        'glsr_debug' => 10,
16
-        'glsr_get' => 4,
17
-        'glsr_get_option' => 4,
18
-        'glsr_get_options' => 1,
19
-        'glsr_get_review' => 2,
20
-        'glsr_get_reviews' => 2,
21
-        'glsr_log' => 3,
22
-        'glsr_star_rating' => 2,
23
-    );
24
-    foreach ($hooks as $function => $acceptedArgs) {
25
-        add_filter($function, function () use ($function) {
26
-            $args = func_get_args();
27
-            array_shift($args); // remove the fallback value
28
-            return call_user_func_array($function, $args);
29
-        }, 10, $acceptedArgs);
30
-    }
12
+	$hooks = array(
13
+		'glsr_calculate_ratings' => 1,
14
+		'glsr_create_review' => 2,
15
+		'glsr_debug' => 10,
16
+		'glsr_get' => 4,
17
+		'glsr_get_option' => 4,
18
+		'glsr_get_options' => 1,
19
+		'glsr_get_review' => 2,
20
+		'glsr_get_reviews' => 2,
21
+		'glsr_log' => 3,
22
+		'glsr_star_rating' => 2,
23
+	);
24
+	foreach ($hooks as $function => $acceptedArgs) {
25
+		add_filter($function, function () use ($function) {
26
+			$args = func_get_args();
27
+			array_shift($args); // remove the fallback value
28
+			return call_user_func_array($function, $args);
29
+		}, 10, $acceptedArgs);
30
+	}
31 31
 });
32 32
 
33 33
 /**
@@ -35,10 +35,10 @@  discard block
 block discarded – undo
35 35
  */
36 36
 function glsr($alias = null)
37 37
 {
38
-    $app = \GeminiLabs\SiteReviews\Application::load();
39
-    return !empty($alias)
40
-        ? $app->make($alias)
41
-        : $app;
38
+	$app = \GeminiLabs\SiteReviews\Application::load();
39
+	return !empty($alias)
40
+		? $app->make($alias)
41
+		: $app;
42 42
 }
43 43
 
44 44
 /**
@@ -48,15 +48,15 @@  discard block
 block discarded – undo
48 48
  */
49 49
 function glsr_array_column(array $array, $column)
50 50
 {
51
-    $result = array();
52
-    foreach ($array as $subarray) {
53
-        $subarray = (array) $subarray;
54
-        if (!isset($subarray[$column])) {
55
-            continue;
56
-        }
57
-        $result[] = $subarray[$column];
58
-    }
59
-    return $result;
51
+	$result = array();
52
+	foreach ($array as $subarray) {
53
+		$subarray = (array) $subarray;
54
+		if (!isset($subarray[$column])) {
55
+			continue;
56
+		}
57
+		$result[] = $subarray[$column];
58
+	}
59
+	return $result;
60 60
 }
61 61
 
62 62
 /**
@@ -64,8 +64,8 @@  discard block
 block discarded – undo
64 64
  */
65 65
 function glsr_calculate_ratings()
66 66
 {
67
-    glsr('Controllers\AdminController')->routerCountReviews(false);
68
-    glsr_log()->notice(__('Recalculated rating counts.', 'site-reviews'));
67
+	glsr('Controllers\AdminController')->routerCountReviews(false);
68
+	glsr_log()->notice(__('Recalculated rating counts.', 'site-reviews'));
69 69
 }
70 70
 
71 71
 /**
@@ -73,10 +73,10 @@  discard block
 block discarded – undo
73 73
  */
74 74
 function glsr_create_review($reviewValues = array())
75 75
 {
76
-    $review = new \GeminiLabs\SiteReviews\Commands\CreateReview(
77
-        glsr('Helper')->consolidateArray($reviewValues)
78
-    );
79
-    return glsr('Database\ReviewManager')->create($review);
76
+	$review = new \GeminiLabs\SiteReviews\Commands\CreateReview(
77
+		glsr('Helper')->consolidateArray($reviewValues)
78
+	);
79
+	return glsr('Database\ReviewManager')->create($review);
80 80
 }
81 81
 
82 82
 /**
@@ -84,12 +84,12 @@  discard block
 block discarded – undo
84 84
  */
85 85
 function glsr_current_screen()
86 86
 {
87
-    if (function_exists('get_current_screen')) {
88
-        $screen = get_current_screen();
89
-    }
90
-    return empty($screen)
91
-        ? (object) array_fill_keys(['base', 'id', 'post_type'], null)
92
-        : $screen;
87
+	if (function_exists('get_current_screen')) {
88
+		$screen = get_current_screen();
89
+	}
90
+	return empty($screen)
91
+		? (object) array_fill_keys(['base', 'id', 'post_type'], null)
92
+		: $screen;
93 93
 }
94 94
 
95 95
 /**
@@ -98,16 +98,16 @@  discard block
 block discarded – undo
98 98
  */
99 99
 function glsr_debug(...$vars)
100 100
 {
101
-    if (1 == count($vars)) {
102
-        $value = htmlspecialchars(print_r($vars[0], true), ENT_QUOTES, 'UTF-8');
103
-        printf('<div class="glsr-debug"><pre>%s</pre></div>', $value);
104
-    } else {
105
-        echo '<div class="glsr-debug-group">';
106
-        foreach ($vars as $var) {
107
-            glsr_debug($var);
108
-        }
109
-        echo '</div>';
110
-    }
101
+	if (1 == count($vars)) {
102
+		$value = htmlspecialchars(print_r($vars[0], true), ENT_QUOTES, 'UTF-8');
103
+		printf('<div class="glsr-debug"><pre>%s</pre></div>', $value);
104
+	} else {
105
+		echo '<div class="glsr-debug-group">';
106
+		foreach ($vars as $var) {
107
+			glsr_debug($var);
108
+		}
109
+		echo '</div>';
110
+	}
111 111
 }
112 112
 
113 113
 /**
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
  */
119 119
 function glsr_get($array, $path = '', $fallback = '')
120 120
 {
121
-    return glsr('Helper')->dataGet($array, $path, $fallback);
121
+	return glsr('Helper')->dataGet($array, $path, $fallback);
122 122
 }
123 123
 
124 124
 /**
@@ -129,9 +129,9 @@  discard block
 block discarded – undo
129 129
  */
130 130
 function glsr_get_option($path = '', $fallback = '', $cast = '')
131 131
 {
132
-    return is_string($path)
133
-        ? glsr('Database\OptionManager')->get('settings.'.$path, $fallback, $cast)
134
-        : $fallback;
132
+	return is_string($path)
133
+		? glsr('Database\OptionManager')->get('settings.'.$path, $fallback, $cast)
134
+		: $fallback;
135 135
 }
136 136
 
137 137
 /**
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
  */
140 140
 function glsr_get_options()
141 141
 {
142
-    return glsr('Database\OptionManager')->get('settings');
142
+	return glsr('Database\OptionManager')->get('settings');
143 143
 }
144 144
 
145 145
 /**
@@ -148,13 +148,13 @@  discard block
 block discarded – undo
148 148
  */
149 149
 function glsr_get_review($post)
150 150
 {
151
-    if (is_numeric($post)) {
152
-        $post = get_post($post);
153
-    }
154
-    if (!($post instanceof WP_Post)) {
155
-        $post = new WP_Post((object) []);
156
-    }
157
-    return glsr('Database\ReviewManager')->single($post);
151
+	if (is_numeric($post)) {
152
+		$post = get_post($post);
153
+	}
154
+	if (!($post instanceof WP_Post)) {
155
+		$post = new WP_Post((object) []);
156
+	}
157
+	return glsr('Database\ReviewManager')->single($post);
158 158
 }
159 159
 
160 160
 /**
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
  */
163 163
 function glsr_get_reviews($args = array())
164 164
 {
165
-    return glsr('Database\ReviewManager')->get(glsr('Helper')->consolidateArray($args));
165
+	return glsr('Database\ReviewManager')->get(glsr('Helper')->consolidateArray($args));
166 166
 }
167 167
 
168 168
 /**
@@ -170,12 +170,12 @@  discard block
 block discarded – undo
170 170
  */
171 171
 function glsr_log()
172 172
 {
173
-    $args = func_get_args();
174
-    $console = glsr('Modules\Console');
175
-    if ($value = glsr_get($args, '0')) {
176
-        return $console->debug($value, glsr_get($args, '1', []));
177
-    }
178
-    return $console;
173
+	$args = func_get_args();
174
+	$console = glsr('Modules\Console');
175
+	if ($value = glsr_get($args, '0')) {
176
+		return $console->debug($value, glsr_get($args, '1', []));
177
+	}
178
+	return $console;
179 179
 }
180 180
 
181 181
 /**
@@ -183,5 +183,5 @@  discard block
 block discarded – undo
183 183
  */
184 184
 function glsr_star_rating($rating)
185 185
 {
186
-    return glsr('Modules\Html\Partial')->build('star-rating', ['rating' => $rating]);
186
+	return glsr('Modules\Html\Partial')->build('star-rating', ['rating' => $rating]);
187 187
 }
Please login to merge, or discard this patch.
plugin/Controllers/SettingsController.php 1 patch
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -9,112 +9,112 @@
 block discarded – undo
9 9
 
10 10
 class SettingsController extends Controller
11 11
 {
12
-    /**
13
-     * @param mixed $input
14
-     * @return array
15
-     * @callback register_setting
16
-     */
17
-    public function callbackRegisterSettings($input)
18
-    {
19
-        $settings = glsr(Helper::class)->consolidateArray($input);
20
-        if (1 === count($settings) && array_key_exists('settings', $settings)) {
21
-            $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input);
22
-            $options = $this->sanitizeGeneral($input, $options);
23
-            $options = $this->sanitizeSubmissions($input, $options);
24
-            $options = $this->sanitizeTranslations($input, $options);
25
-            if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') {
26
-                glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews'));
27
-            }
28
-            return $options;
29
-        }
30
-        return $input;
31
-    }
12
+	/**
13
+	 * @param mixed $input
14
+	 * @return array
15
+	 * @callback register_setting
16
+	 */
17
+	public function callbackRegisterSettings($input)
18
+	{
19
+		$settings = glsr(Helper::class)->consolidateArray($input);
20
+		if (1 === count($settings) && array_key_exists('settings', $settings)) {
21
+			$options = array_replace_recursive(glsr(OptionManager::class)->all(), $input);
22
+			$options = $this->sanitizeGeneral($input, $options);
23
+			$options = $this->sanitizeSubmissions($input, $options);
24
+			$options = $this->sanitizeTranslations($input, $options);
25
+			if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') {
26
+				glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews'));
27
+			}
28
+			return $options;
29
+		}
30
+		return $input;
31
+	}
32 32
 
33
-    /**
34
-     * @return void
35
-     * @action admin_init
36
-     */
37
-    public function registerSettings()
38
-    {
39
-        register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [
40
-            'sanitize_callback' => [$this, 'callbackRegisterSettings'],
41
-        ]);
42
-    }
33
+	/**
34
+	 * @return void
35
+	 * @action admin_init
36
+	 */
37
+	public function registerSettings()
38
+	{
39
+		register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [
40
+			'sanitize_callback' => [$this, 'callbackRegisterSettings'],
41
+		]);
42
+	}
43 43
 
44
-    /**
45
-     * @return array
46
-     */
47
-    protected function sanitizeGeneral(array $input, array $options)
48
-    {
49
-        $inputForm = $input['settings']['general'];
50
-        if (!$this->hasMultilingualIntegration($inputForm['support']['multilingual'])) {
51
-            $options['settings']['general']['support']['multilingual'] = '';
52
-        }
53
-        if ('' == trim($inputForm['notification_message'])) {
54
-            $options['settings']['general']['notification_message'] = glsr()->defaults['settings']['general']['notification_message'];
55
-        }
56
-        $options['settings']['general']['notifications'] = glsr_get($inputForm, 'notifications', []);
57
-        return $options;
58
-    }
44
+	/**
45
+	 * @return array
46
+	 */
47
+	protected function sanitizeGeneral(array $input, array $options)
48
+	{
49
+		$inputForm = $input['settings']['general'];
50
+		if (!$this->hasMultilingualIntegration($inputForm['support']['multilingual'])) {
51
+			$options['settings']['general']['support']['multilingual'] = '';
52
+		}
53
+		if ('' == trim($inputForm['notification_message'])) {
54
+			$options['settings']['general']['notification_message'] = glsr()->defaults['settings']['general']['notification_message'];
55
+		}
56
+		$options['settings']['general']['notifications'] = glsr_get($inputForm, 'notifications', []);
57
+		return $options;
58
+	}
59 59
 
60
-    /**
61
-     * @return array
62
-     */
63
-    protected function sanitizeSubmissions(array $input, array $options)
64
-    {
65
-        $inputForm = $input['settings']['submissions'];
66
-        $options['settings']['submissions']['required'] = isset($inputForm['required'])
67
-            ? $inputForm['required']
68
-            : [];
69
-        return $options;
70
-    }
60
+	/**
61
+	 * @return array
62
+	 */
63
+	protected function sanitizeSubmissions(array $input, array $options)
64
+	{
65
+		$inputForm = $input['settings']['submissions'];
66
+		$options['settings']['submissions']['required'] = isset($inputForm['required'])
67
+			? $inputForm['required']
68
+			: [];
69
+		return $options;
70
+	}
71 71
 
72
-    /**
73
-     * @return array
74
-     */
75
-    protected function sanitizeTranslations(array $input, array $options)
76
-    {
77
-        if (isset($input['settings']['strings'])) {
78
-            $options['settings']['strings'] = array_values(array_filter($input['settings']['strings']));
79
-            $allowedTags = [
80
-                'a' => ['class' => [], 'href' => [], 'target' => []],
81
-                'span' => ['class' => []],
82
-            ];
83
-            array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) {
84
-                if (isset($string['s2'])) {
85
-                    $string['s2'] = wp_kses($string['s2'], $allowedTags);
86
-                }
87
-                if (isset($string['p2'])) {
88
-                    $string['p2'] = wp_kses($string['p2'], $allowedTags);
89
-                }
90
-            });
91
-        }
92
-        return $options;
93
-    }
72
+	/**
73
+	 * @return array
74
+	 */
75
+	protected function sanitizeTranslations(array $input, array $options)
76
+	{
77
+		if (isset($input['settings']['strings'])) {
78
+			$options['settings']['strings'] = array_values(array_filter($input['settings']['strings']));
79
+			$allowedTags = [
80
+				'a' => ['class' => [], 'href' => [], 'target' => []],
81
+				'span' => ['class' => []],
82
+			];
83
+			array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) {
84
+				if (isset($string['s2'])) {
85
+					$string['s2'] = wp_kses($string['s2'], $allowedTags);
86
+				}
87
+				if (isset($string['p2'])) {
88
+					$string['p2'] = wp_kses($string['p2'], $allowedTags);
89
+				}
90
+			});
91
+		}
92
+		return $options;
93
+	}
94 94
 
95
-    /**
96
-     * @return bool
97
-     */
98
-    protected function hasMultilingualIntegration($integration)
99
-    {
100
-        if (!in_array($integration, ['polylang', 'wpml'])) {
101
-            return false;
102
-        }
103
-        $integrationClass = 'GeminiLabs\SiteReviews\Modules\\'.ucfirst($integration);
104
-        if (!glsr($integrationClass)->isActive()) {
105
-            glsr(Notice::class)->addError(sprintf(
106
-                __('Please install/activate the %s plugin to enable integration.', 'site-reviews'),
107
-                constant($integrationClass.'::PLUGIN_NAME')
108
-            ));
109
-            return false;
110
-        } elseif (!glsr($integrationClass)->isSupported()) {
111
-            glsr(Notice::class)->addError(sprintf(
112
-                __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'),
113
-                constant($integrationClass.'::PLUGIN_NAME'),
114
-                constant($integrationClass.'::SUPPORTED_VERSION')
115
-            ));
116
-            return false;
117
-        }
118
-        return true;
119
-    }
95
+	/**
96
+	 * @return bool
97
+	 */
98
+	protected function hasMultilingualIntegration($integration)
99
+	{
100
+		if (!in_array($integration, ['polylang', 'wpml'])) {
101
+			return false;
102
+		}
103
+		$integrationClass = 'GeminiLabs\SiteReviews\Modules\\'.ucfirst($integration);
104
+		if (!glsr($integrationClass)->isActive()) {
105
+			glsr(Notice::class)->addError(sprintf(
106
+				__('Please install/activate the %s plugin to enable integration.', 'site-reviews'),
107
+				constant($integrationClass.'::PLUGIN_NAME')
108
+			));
109
+			return false;
110
+		} elseif (!glsr($integrationClass)->isSupported()) {
111
+			glsr(Notice::class)->addError(sprintf(
112
+				__('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'),
113
+				constant($integrationClass.'::PLUGIN_NAME'),
114
+				constant($integrationClass.'::SUPPORTED_VERSION')
115
+			));
116
+			return false;
117
+		}
118
+		return true;
119
+	}
120 120
 }
Please login to merge, or discard this patch.
plugin/Database/OptionManager.php 1 patch
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -7,155 +7,155 @@
 block discarded – undo
7 7
 
8 8
 class OptionManager
9 9
 {
10
-    /**
11
-     * @var array
12
-     */
13
-    protected $options;
10
+	/**
11
+	 * @var array
12
+	 */
13
+	protected $options;
14 14
 
15
-    /**
16
-     * @return string
17
-     */
18
-    public static function databaseKey($version = null)
19
-    {
20
-        if (null === $version) {
21
-            $version = explode('.', glsr()->version);
22
-            $version = array_shift($version);
23
-        }
24
-        return glsr(Helper::class)->snakeCase(
25
-            Application::ID.'-v'.intval($version)
26
-        );
27
-    }
15
+	/**
16
+	 * @return string
17
+	 */
18
+	public static function databaseKey($version = null)
19
+	{
20
+		if (null === $version) {
21
+			$version = explode('.', glsr()->version);
22
+			$version = array_shift($version);
23
+		}
24
+		return glsr(Helper::class)->snakeCase(
25
+			Application::ID.'-v'.intval($version)
26
+		);
27
+	}
28 28
 
29
-    /**
30
-     * @return array
31
-     */
32
-    public function all()
33
-    {
34
-        if (empty($this->options)) {
35
-            $this->reset();
36
-        }
37
-        return $this->options;
38
-    }
29
+	/**
30
+	 * @return array
31
+	 */
32
+	public function all()
33
+	{
34
+		if (empty($this->options)) {
35
+			$this->reset();
36
+		}
37
+		return $this->options;
38
+	}
39 39
 
40
-    /**
41
-     * @param string $path
42
-     * @return bool
43
-     */
44
-    public function delete($path)
45
-    {
46
-        $keys = explode('.', $path);
47
-        $last = array_pop($keys);
48
-        $options = $this->all();
49
-        $pointer = &$options;
50
-        foreach ($keys as $key) {
51
-            if (!isset($pointer[$key]) || !is_array($pointer[$key])) {
52
-                continue;
53
-            }
54
-            $pointer = &$pointer[$key];
55
-        }
56
-        unset($pointer[$last]);
57
-        return $this->set($options);
58
-    }
40
+	/**
41
+	 * @param string $path
42
+	 * @return bool
43
+	 */
44
+	public function delete($path)
45
+	{
46
+		$keys = explode('.', $path);
47
+		$last = array_pop($keys);
48
+		$options = $this->all();
49
+		$pointer = &$options;
50
+		foreach ($keys as $key) {
51
+			if (!isset($pointer[$key]) || !is_array($pointer[$key])) {
52
+				continue;
53
+			}
54
+			$pointer = &$pointer[$key];
55
+		}
56
+		unset($pointer[$last]);
57
+		return $this->set($options);
58
+	}
59 59
 
60
-    /**
61
-     * @param string $path
62
-     * @param mixed $fallback
63
-     * @param string $cast
64
-     * @return mixed
65
-     */
66
-    public function get($path = '', $fallback = '', $cast = '')
67
-    {
68
-        $result = glsr(Helper::class)->dataGet($this->all(), $path, $fallback);
69
-        return glsr(Helper::class)->castTo($cast, $result);
70
-    }
60
+	/**
61
+	 * @param string $path
62
+	 * @param mixed $fallback
63
+	 * @param string $cast
64
+	 * @return mixed
65
+	 */
66
+	public function get($path = '', $fallback = '', $cast = '')
67
+	{
68
+		$result = glsr(Helper::class)->dataGet($this->all(), $path, $fallback);
69
+		return glsr(Helper::class)->castTo($cast, $result);
70
+	}
71 71
 
72
-    /**
73
-     * @param string $path
74
-     * @return bool
75
-     */
76
-    public function getBool($path)
77
-    {
78
-        return 'yes' == $this->get($path)
79
-            ? true
80
-            : false;
81
-    }
72
+	/**
73
+	 * @param string $path
74
+	 * @return bool
75
+	 */
76
+	public function getBool($path)
77
+	{
78
+		return 'yes' == $this->get($path)
79
+			? true
80
+			: false;
81
+	}
82 82
 
83
-    /**
84
-     * @param string $path
85
-     * @param mixed $fallback
86
-     * @param string $cast
87
-     * @return mixed
88
-     */
89
-    public function getWP($path, $fallback = '', $cast = '')
90
-    {
91
-        $option = get_option($path, $fallback);
92
-        if (empty($option)) {
93
-            $option = $fallback;
94
-        }
95
-        return glsr(Helper::class)->castTo($cast, $option);
96
-    }
83
+	/**
84
+	 * @param string $path
85
+	 * @param mixed $fallback
86
+	 * @param string $cast
87
+	 * @return mixed
88
+	 */
89
+	public function getWP($path, $fallback = '', $cast = '')
90
+	{
91
+		$option = get_option($path, $fallback);
92
+		if (empty($option)) {
93
+			$option = $fallback;
94
+		}
95
+		return glsr(Helper::class)->castTo($cast, $option);
96
+	}
97 97
 
98
-    /**
99
-     * @return string
100
-     */
101
-    public function json()
102
-    {
103
-        return json_encode($this->all());
104
-    }
98
+	/**
99
+	 * @return string
100
+	 */
101
+	public function json()
102
+	{
103
+		return json_encode($this->all());
104
+	}
105 105
 
106
-    /**
107
-     * @return array
108
-     */
109
-    public function normalize(array $options = [])
110
-    {
111
-        $options = wp_parse_args(
112
-            glsr(Helper::class)->flattenArray($options),
113
-            glsr(DefaultsManager::class)->defaults()
114
-        );
115
-        array_walk($options, function (&$value) {
116
-            if (!is_string($value)) {
117
-                return;
118
-            }
119
-            $value = wp_kses($value, wp_kses_allowed_html('post'));
120
-        });
121
-        return glsr(Helper::class)->convertDotNotationArray($options);
122
-    }
106
+	/**
107
+	 * @return array
108
+	 */
109
+	public function normalize(array $options = [])
110
+	{
111
+		$options = wp_parse_args(
112
+			glsr(Helper::class)->flattenArray($options),
113
+			glsr(DefaultsManager::class)->defaults()
114
+		);
115
+		array_walk($options, function (&$value) {
116
+			if (!is_string($value)) {
117
+				return;
118
+			}
119
+			$value = wp_kses($value, wp_kses_allowed_html('post'));
120
+		});
121
+		return glsr(Helper::class)->convertDotNotationArray($options);
122
+	}
123 123
 
124
-    /**
125
-     * @return bool
126
-     */
127
-    public function isRecaptchaEnabled()
128
-    {
129
-        $integration = $this->get('settings.submissions.recaptcha.integration');
130
-        return 'all' == $integration || ('guest' == $integration && !is_user_logged_in());
131
-    }
124
+	/**
125
+	 * @return bool
126
+	 */
127
+	public function isRecaptchaEnabled()
128
+	{
129
+		$integration = $this->get('settings.submissions.recaptcha.integration');
130
+		return 'all' == $integration || ('guest' == $integration && !is_user_logged_in());
131
+	}
132 132
 
133
-    /**
134
-     * @return array
135
-     */
136
-    public function reset()
137
-    {
138
-        $options = $this->getWP(static::databaseKey(), []);
139
-        if (!is_array($options) || empty($options)) {
140
-            delete_option(static::databaseKey());
141
-            $options = glsr()->defaults;
142
-        }
143
-        $this->options = $options;
144
-    }
133
+	/**
134
+	 * @return array
135
+	 */
136
+	public function reset()
137
+	{
138
+		$options = $this->getWP(static::databaseKey(), []);
139
+		if (!is_array($options) || empty($options)) {
140
+			delete_option(static::databaseKey());
141
+			$options = glsr()->defaults;
142
+		}
143
+		$this->options = $options;
144
+	}
145 145
 
146
-    /**
147
-     * @param string|array $pathOrOptions
148
-     * @param mixed $value
149
-     * @return bool
150
-     */
151
-    public function set($pathOrOptions, $value = '')
152
-    {
153
-        if (is_string($pathOrOptions)) {
154
-            $pathOrOptions = glsr(Helper::class)->dataSet($this->all(), $pathOrOptions, $value);
155
-        }
156
-        if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) {
157
-            $this->reset();
158
-        }
159
-        return $result;
160
-    }
146
+	/**
147
+	 * @param string|array $pathOrOptions
148
+	 * @param mixed $value
149
+	 * @return bool
150
+	 */
151
+	public function set($pathOrOptions, $value = '')
152
+	{
153
+		if (is_string($pathOrOptions)) {
154
+			$pathOrOptions = glsr(Helper::class)->dataSet($this->all(), $pathOrOptions, $value);
155
+		}
156
+		if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) {
157
+			$this->reset();
158
+		}
159
+		return $result;
160
+	}
161 161
 }
Please login to merge, or discard this patch.
plugin/Database/SqlQueries.php 1 patch
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -7,23 +7,23 @@  discard block
 block discarded – undo
7 7
 
8 8
 class SqlQueries
9 9
 {
10
-    protected $db;
11
-    protected $postType;
10
+	protected $db;
11
+	protected $postType;
12 12
 
13
-    public function __construct()
14
-    {
15
-        global $wpdb;
16
-        $this->db = $wpdb;
17
-        $this->postType = Application::POST_TYPE;
18
-    }
13
+	public function __construct()
14
+	{
15
+		global $wpdb;
16
+		$this->db = $wpdb;
17
+		$this->postType = Application::POST_TYPE;
18
+	}
19 19
 
20
-    /**
21
-     * @param string $metaReviewId
22
-     * @return int
23
-     */
24
-    public function getPostIdFromReviewId($metaReviewId)
25
-    {
26
-        $postId = $this->db->get_var("
20
+	/**
21
+	 * @param string $metaReviewId
22
+	 * @return int
23
+	 */
24
+	public function getPostIdFromReviewId($metaReviewId)
25
+	{
26
+		$postId = $this->db->get_var("
27 27
             SELECT p.ID
28 28
             FROM {$this->db->posts} AS p
29 29
             INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
@@ -31,17 +31,17 @@  discard block
 block discarded – undo
31 31
             AND m.meta_key = '_review_id'
32 32
             AND m.meta_value = '{$metaReviewId}'
33 33
         ");
34
-        return intval($postId);
35
-    }
34
+		return intval($postId);
35
+	}
36 36
 
37
-    /**
38
-     * @param int $lastPostId
39
-     * @param int $limit
40
-     * @return array
41
-     */
42
-    public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500)
43
-    {
44
-        return (array) $this->db->get_results("
37
+	/**
38
+	 * @param int $lastPostId
39
+	 * @param int $limit
40
+	 * @return array
41
+	 */
42
+	public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500)
43
+	{
44
+		return (array) $this->db->get_results("
45 45
             SELECT DISTINCT p.ID, m1.meta_value AS rating, m2.meta_value AS type
46 46
             FROM {$this->db->posts} AS p
47 47
             INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id
@@ -56,17 +56,17 @@  discard block
 block discarded – undo
56 56
             ORDER By p.ID ASC
57 57
             LIMIT {$limit}
58 58
         ");
59
-    }
59
+	}
60 60
 
61
-    /**
62
-     * @todo remove this?
63
-     * @param string $metaKey
64
-     * @return array
65
-     */
66
-    public function getReviewCountsFor($metaKey)
67
-    {
68
-        $metaKey = glsr(Helper::class)->prefix('_', $metaKey);
69
-        return (array) $this->db->get_results("
61
+	/**
62
+	 * @todo remove this?
63
+	 * @param string $metaKey
64
+	 * @return array
65
+	 */
66
+	public function getReviewCountsFor($metaKey)
67
+	{
68
+		$metaKey = glsr(Helper::class)->prefix('_', $metaKey);
69
+		return (array) $this->db->get_results("
70 70
             SELECT DISTINCT m.meta_value AS name, COUNT(*) num_posts
71 71
             FROM {$this->db->posts} AS p
72 72
             INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
@@ -74,16 +74,16 @@  discard block
 block discarded – undo
74 74
             AND m.meta_key = '{$metaKey}'
75 75
             GROUP BY name
76 76
         ");
77
-    }
77
+	}
78 78
 
79
-    /**
80
-     * @todo remove this?
81
-     * @param string $reviewType
82
-     * @return array
83
-     */
84
-    public function getReviewIdsByType($reviewType)
85
-    {
86
-        $results = $this->db->get_col("
79
+	/**
80
+	 * @todo remove this?
81
+	 * @param string $reviewType
82
+	 * @return array
83
+	 */
84
+	public function getReviewIdsByType($reviewType)
85
+	{
86
+		$results = $this->db->get_col("
87 87
             SELECT DISTINCT m1.meta_value AS review_id
88 88
             FROM {$this->db->posts} AS p
89 89
             INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id
@@ -93,20 +93,20 @@  discard block
 block discarded – undo
93 93
             AND m2.meta_key = '_review_type'
94 94
             AND m2.meta_value = '{$reviewType}'
95 95
         ");
96
-        return array_keys(array_flip($results));
97
-    }
96
+		return array_keys(array_flip($results));
97
+	}
98 98
 
99
-    /**
100
-     * @param int $greaterThanId
101
-     * @param int $limit
102
-     * @return array
103
-     */
104
-    public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100)
105
-    {
106
-        sort($postIds);
107
-        $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit);
108
-        $postIds = implode(',', $postIds);
109
-        return (array) $this->db->get_results("
99
+	/**
100
+	 * @param int $greaterThanId
101
+	 * @param int $limit
102
+	 * @return array
103
+	 */
104
+	public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100)
105
+	{
106
+		sort($postIds);
107
+		$postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit);
108
+		$postIds = implode(',', $postIds);
109
+		return (array) $this->db->get_results("
110 110
             SELECT p.ID, m.meta_value AS rating
111 111
             FROM {$this->db->posts} AS p
112 112
             INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
@@ -119,17 +119,17 @@  discard block
 block discarded – undo
119 119
             ORDER By p.ID ASC
120 120
             LIMIT {$limit}
121 121
         ");
122
-    }
122
+	}
123 123
 
124
-    /**
125
-     * @param string $key
126
-     * @param string $status
127
-     * @return array
128
-     */
129
-    public function getReviewsMeta($key, $status = 'publish')
130
-    {
131
-        $key = glsr(Helper::class)->prefix('_', $key);
132
-        $values = $this->db->get_col("
124
+	/**
125
+	 * @param string $key
126
+	 * @param string $status
127
+	 * @return array
128
+	 */
129
+	public function getReviewsMeta($key, $status = 'publish')
130
+	{
131
+		$key = glsr(Helper::class)->prefix('_', $key);
132
+		$values = $this->db->get_col("
133 133
             SELECT DISTINCT m.meta_value
134 134
             FROM {$this->db->postmeta} m
135 135
             LEFT JOIN {$this->db->posts} p ON p.ID = m.post_id
@@ -140,42 +140,42 @@  discard block
 block discarded – undo
140 140
             GROUP BY p.ID -- remove duplicate meta_value entries
141 141
             ORDER BY m.meta_id ASC -- sort by oldest meta_value
142 142
         ");
143
-        sort($values);
144
-        return $values;
145
-    }
143
+		sort($values);
144
+		return $values;
145
+	}
146 146
 
147
-    /**
148
-     * @param string $and
149
-     * @return string
150
-     */
151
-    protected function getAndForCounts(array $args, $and = '')
152
-    {
153
-        $postIds = implode(',', array_filter(glsr_get($args, 'post_ids', [])));
154
-        $termIds = implode(',', array_filter(glsr_get($args, 'term_ids', [])));
155
-        if (!empty($args['type'])) {
156
-            $and.= "AND m2.meta_value = '{$args['type']}' ";
157
-        }
158
-        if ($postIds) {
159
-            $and.= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) ";
160
-        }
161
-        if ($termIds) {
162
-            $and.= "AND tr.term_taxonomy_id IN ({$termIds}) ";
163
-        }
164
-        return apply_filters('site-reviews/query/and-for-counts', $and);
165
-    }
147
+	/**
148
+	 * @param string $and
149
+	 * @return string
150
+	 */
151
+	protected function getAndForCounts(array $args, $and = '')
152
+	{
153
+		$postIds = implode(',', array_filter(glsr_get($args, 'post_ids', [])));
154
+		$termIds = implode(',', array_filter(glsr_get($args, 'term_ids', [])));
155
+		if (!empty($args['type'])) {
156
+			$and.= "AND m2.meta_value = '{$args['type']}' ";
157
+		}
158
+		if ($postIds) {
159
+			$and.= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) ";
160
+		}
161
+		if ($termIds) {
162
+			$and.= "AND tr.term_taxonomy_id IN ({$termIds}) ";
163
+		}
164
+		return apply_filters('site-reviews/query/and-for-counts', $and);
165
+	}
166 166
 
167
-    /**
168
-     * @param string $innerJoin
169
-     * @return string
170
-     */
171
-    protected function getInnerJoinForCounts(array $args, $innerJoin = '')
172
-    {
173
-        if (!empty(glsr_get($args, 'post_ids'))) {
174
-            $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id ";
175
-        }
176
-        if (!empty(glsr_get($args, 'term_ids'))) {
177
-            $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id ";
178
-        }
179
-        return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin);
180
-    }
167
+	/**
168
+	 * @param string $innerJoin
169
+	 * @return string
170
+	 */
171
+	protected function getInnerJoinForCounts(array $args, $innerJoin = '')
172
+	{
173
+		if (!empty(glsr_get($args, 'post_ids'))) {
174
+			$innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id ";
175
+		}
176
+		if (!empty(glsr_get($args, 'term_ids'))) {
177
+			$innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id ";
178
+		}
179
+		return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin);
180
+	}
181 181
 }
Please login to merge, or discard this patch.
plugin/Modules/Upgrader.php 1 patch
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -7,84 +7,84 @@
 block discarded – undo
7 7
 
8 8
 class Upgrader
9 9
 {
10
-    /**
11
-     * @return string
12
-     */
13
-    public $currentVersion;
10
+	/**
11
+	 * @return string
12
+	 */
13
+	public $currentVersion;
14 14
 
15
-    /**
16
-     * @return void
17
-     */
18
-    public function run()
19
-    {
20
-        $filenames = [];
21
-        $iterator = new DirectoryIterator(dirname(__FILE__).'/Upgrader');
22
-        foreach ($iterator as $fileinfo) {
23
-            if ($fileinfo->isFile()) {
24
-                $filenames[] = $fileinfo->getFilename();
25
-            }
26
-        }
27
-        natsort($filenames);
28
-        $this->currentVersion = $this->currentVersion();
29
-        array_walk($filenames, function ($file) {
30
-            $className = str_replace('.php', '', $file);
31
-            $upgradeFromVersion = str_replace(['Upgrade_', '_'], ['', '.'], $className);
32
-            $suffix = preg_replace('/[\d.]+(.+)?/', '${1}', glsr()->version); // allow alpha/beta versions
33
-            if ('0.0.0' == $this->currentVersion
34
-                || version_compare($this->currentVersion, $upgradeFromVersion.$suffix, '>=')) {
35
-                return;
36
-            }
37
-            glsr('Modules\\Upgrader\\'.$className);
38
-            glsr_log()->notice('Completed Upgrade for v'.$upgradeFromVersion.$suffix);
39
-        });
40
-        $this->finish();
41
-    }
15
+	/**
16
+	 * @return void
17
+	 */
18
+	public function run()
19
+	{
20
+		$filenames = [];
21
+		$iterator = new DirectoryIterator(dirname(__FILE__).'/Upgrader');
22
+		foreach ($iterator as $fileinfo) {
23
+			if ($fileinfo->isFile()) {
24
+				$filenames[] = $fileinfo->getFilename();
25
+			}
26
+		}
27
+		natsort($filenames);
28
+		$this->currentVersion = $this->currentVersion();
29
+		array_walk($filenames, function ($file) {
30
+			$className = str_replace('.php', '', $file);
31
+			$upgradeFromVersion = str_replace(['Upgrade_', '_'], ['', '.'], $className);
32
+			$suffix = preg_replace('/[\d.]+(.+)?/', '${1}', glsr()->version); // allow alpha/beta versions
33
+			if ('0.0.0' == $this->currentVersion
34
+				|| version_compare($this->currentVersion, $upgradeFromVersion.$suffix, '>=')) {
35
+				return;
36
+			}
37
+			glsr('Modules\\Upgrader\\'.$className);
38
+			glsr_log()->notice('Completed Upgrade for v'.$upgradeFromVersion.$suffix);
39
+		});
40
+		$this->finish();
41
+	}
42 42
 
43
-    /**
44
-     * @return void
45
-     */
46
-    public function finish()
47
-    {
48
-        if ($this->currentVersion !== glsr()->version) {
49
-            $this->setReviewCounts();
50
-            $this->updateVersionFrom($this->currentVersion);
51
-        } elseif (!glsr(OptionManager::class)->get('last_review_count', false)) {
52
-            $this->setReviewCounts();
53
-        }
54
-    }
43
+	/**
44
+	 * @return void
45
+	 */
46
+	public function finish()
47
+	{
48
+		if ($this->currentVersion !== glsr()->version) {
49
+			$this->setReviewCounts();
50
+			$this->updateVersionFrom($this->currentVersion);
51
+		} elseif (!glsr(OptionManager::class)->get('last_review_count', false)) {
52
+			$this->setReviewCounts();
53
+		}
54
+	}
55 55
 
56
-    /**
57
-     * @return string
58
-     */
59
-    protected function currentVersion()
60
-    {
61
-        $fallback = '0.0.0';
62
-        $majorVersions = [4, 3, 2];
63
-        foreach ($majorVersions as $majorVersion) {
64
-            $settings = get_option(OptionManager::databaseKey($majorVersion));
65
-            $version = glsr_get($settings, 'version', $fallback);
66
-            if (version_compare($version, $fallback, '>')) {
67
-                return $version;
68
-            }
69
-        }
70
-        return $fallback;
71
-    }
56
+	/**
57
+	 * @return string
58
+	 */
59
+	protected function currentVersion()
60
+	{
61
+		$fallback = '0.0.0';
62
+		$majorVersions = [4, 3, 2];
63
+		foreach ($majorVersions as $majorVersion) {
64
+			$settings = get_option(OptionManager::databaseKey($majorVersion));
65
+			$version = glsr_get($settings, 'version', $fallback);
66
+			if (version_compare($version, $fallback, '>')) {
67
+				return $version;
68
+			}
69
+		}
70
+		return $fallback;
71
+	}
72 72
 
73
-    /**
74
-     * @return void
75
-     */
76
-    protected function setReviewCounts()
77
-    {
78
-        add_action('admin_init', 'glsr_calculate_ratings');
79
-    }
73
+	/**
74
+	 * @return void
75
+	 */
76
+	protected function setReviewCounts()
77
+	{
78
+		add_action('admin_init', 'glsr_calculate_ratings');
79
+	}
80 80
 
81
-    /**
82
-     * @param string $previousVersion
83
-     * @return void
84
-     */
85
-    protected function updateVersionFrom($previousVersion)
86
-    {
87
-        glsr(OptionManager::class)->set('version', glsr()->version);
88
-        glsr(OptionManager::class)->set('version_upgraded_from', $previousVersion);
89
-    }
81
+	/**
82
+	 * @param string $previousVersion
83
+	 * @return void
84
+	 */
85
+	protected function updateVersionFrom($previousVersion)
86
+	{
87
+		glsr(OptionManager::class)->set('version', glsr()->version);
88
+		glsr(OptionManager::class)->set('version_upgraded_from', $previousVersion);
89
+	}
90 90
 }
Please login to merge, or discard this patch.
plugin/Modules/Wpml.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -7,83 +7,83 @@
 block discarded – undo
7 7
 
8 8
 class Wpml implements Contract
9 9
 {
10
-    const PLUGIN_NAME = 'WPML';
11
-    const SUPPORTED_VERSION = '3.3.5';
10
+	const PLUGIN_NAME = 'WPML';
11
+	const SUPPORTED_VERSION = '3.3.5';
12 12
 
13
-    /**
14
-     * {@inheritdoc}
15
-     */
16
-    public function getPost($postId)
17
-    {
18
-        $postId = trim($postId);
19
-        if (!is_numeric($postId)) {
20
-            return;
21
-        }
22
-        if ($this->isEnabled()) {
23
-            $postId = apply_filters('wpml_object_id', $postId, 'any', true);
24
-        }
25
-        return get_post(intval($postId));
26
-    }
13
+	/**
14
+	 * {@inheritdoc}
15
+	 */
16
+	public function getPost($postId)
17
+	{
18
+		$postId = trim($postId);
19
+		if (!is_numeric($postId)) {
20
+			return;
21
+		}
22
+		if ($this->isEnabled()) {
23
+			$postId = apply_filters('wpml_object_id', $postId, 'any', true);
24
+		}
25
+		return get_post(intval($postId));
26
+	}
27 27
 
28
-    /**
29
-     * {@inheritdoc}
30
-     */
31
-    public function getPostIds(array $postIds)
32
-    {
33
-        if (!$this->isEnabled()) {
34
-            return $postIds;
35
-        }
36
-        $newPostIds = [];
37
-        foreach ($this->cleanIds($postIds) as $postId) {
38
-            $postType = get_post_type($postId);
39
-            if (!$postType) {
40
-                continue;
41
-            }
42
-            $elementType = 'post_'.$postType;
43
-            $trid = apply_filters('wpml_element_trid', null, $postId, $elementType);
44
-            $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType);
45
-            if (!is_array($translations)) {
46
-                $translations = [];
47
-            }
48
-            $newPostIds = array_merge(
49
-                $newPostIds,
50
-                array_column($translations, 'element_id')
51
-            );
52
-        }
53
-        return $this->cleanIds($newPostIds);
54
-    }
28
+	/**
29
+	 * {@inheritdoc}
30
+	 */
31
+	public function getPostIds(array $postIds)
32
+	{
33
+		if (!$this->isEnabled()) {
34
+			return $postIds;
35
+		}
36
+		$newPostIds = [];
37
+		foreach ($this->cleanIds($postIds) as $postId) {
38
+			$postType = get_post_type($postId);
39
+			if (!$postType) {
40
+				continue;
41
+			}
42
+			$elementType = 'post_'.$postType;
43
+			$trid = apply_filters('wpml_element_trid', null, $postId, $elementType);
44
+			$translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType);
45
+			if (!is_array($translations)) {
46
+				$translations = [];
47
+			}
48
+			$newPostIds = array_merge(
49
+				$newPostIds,
50
+				array_column($translations, 'element_id')
51
+			);
52
+		}
53
+		return $this->cleanIds($newPostIds);
54
+	}
55 55
 
56
-    /**
57
-     * {@inheritdoc}
58
-     */
59
-    public function isActive()
60
-    {
61
-        return defined('ICL_SITEPRESS_VERSION');
62
-    }
56
+	/**
57
+	 * {@inheritdoc}
58
+	 */
59
+	public function isActive()
60
+	{
61
+		return defined('ICL_SITEPRESS_VERSION');
62
+	}
63 63
 
64
-    /**
65
-     * {@inheritdoc}
66
-     */
67
-    public function isEnabled()
68
-    {
69
-        return $this->isActive()
70
-            && 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual');
71
-    }
64
+	/**
65
+	 * {@inheritdoc}
66
+	 */
67
+	public function isEnabled()
68
+	{
69
+		return $this->isActive()
70
+			&& 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual');
71
+	}
72 72
 
73
-    /**
74
-     * {@inheritdoc}
75
-     */
76
-    public function isSupported()
77
-    {
78
-        return $this->isActive()
79
-            && version_compare(ICL_SITEPRESS_VERSION, static::SUPPORTED_VERSION, '>=');
80
-    }
73
+	/**
74
+	 * {@inheritdoc}
75
+	 */
76
+	public function isSupported()
77
+	{
78
+		return $this->isActive()
79
+			&& version_compare(ICL_SITEPRESS_VERSION, static::SUPPORTED_VERSION, '>=');
80
+	}
81 81
 
82
-    /**
83
-     * @return array
84
-     */
85
-    protected function cleanIds(array $postIds)
86
-    {
87
-        return array_filter(array_unique($postIds));
88
-    }
82
+	/**
83
+	 * @return array
84
+	 */
85
+	protected function cleanIds(array $postIds)
86
+	{
87
+		return array_filter(array_unique($postIds));
88
+	}
89 89
 }
Please login to merge, or discard this patch.
plugin/Modules/Polylang.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -7,79 +7,79 @@
 block discarded – undo
7 7
 
8 8
 class Polylang implements Contract
9 9
 {
10
-    const PLUGIN_NAME = 'Polylang';
11
-    const SUPPORTED_VERSION = '2.3';
10
+	const PLUGIN_NAME = 'Polylang';
11
+	const SUPPORTED_VERSION = '2.3';
12 12
 
13
-    /**
14
-     * {@inheritdoc}
15
-     */
16
-    public function getPost($postId)
17
-    {
18
-        $postId = trim($postId);
19
-        if (!is_numeric($postId)) {
20
-            return;
21
-        }
22
-        if ($this->isEnabled()) {
23
-            $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID()));
24
-        }
25
-        if (!empty($polylangPostId)) {
26
-            $postId = $polylangPostId;
27
-        }
28
-        return get_post(intval($postId));
29
-    }
13
+	/**
14
+	 * {@inheritdoc}
15
+	 */
16
+	public function getPost($postId)
17
+	{
18
+		$postId = trim($postId);
19
+		if (!is_numeric($postId)) {
20
+			return;
21
+		}
22
+		if ($this->isEnabled()) {
23
+			$polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID()));
24
+		}
25
+		if (!empty($polylangPostId)) {
26
+			$postId = $polylangPostId;
27
+		}
28
+		return get_post(intval($postId));
29
+	}
30 30
 
31
-    /**
32
-     * {@inheritdoc}
33
-     */
34
-    public function getPostIds(array $postIds)
35
-    {
36
-        if (!$this->isEnabled()) {
37
-            return $postIds;
38
-        }
39
-        $newPostIds = [];
40
-        foreach ($this->cleanIds($postIds) as $postId) {
41
-            $newPostIds = array_merge(
42
-                $newPostIds,
43
-                array_values(pll_get_post_translations($postId))
44
-            );
45
-        }
46
-        return $this->cleanIds($newPostIds);
47
-    }
31
+	/**
32
+	 * {@inheritdoc}
33
+	 */
34
+	public function getPostIds(array $postIds)
35
+	{
36
+		if (!$this->isEnabled()) {
37
+			return $postIds;
38
+		}
39
+		$newPostIds = [];
40
+		foreach ($this->cleanIds($postIds) as $postId) {
41
+			$newPostIds = array_merge(
42
+				$newPostIds,
43
+				array_values(pll_get_post_translations($postId))
44
+			);
45
+		}
46
+		return $this->cleanIds($newPostIds);
47
+	}
48 48
 
49
-    /**
50
-     * {@inheritdoc}
51
-     */
52
-    public function isActive()
53
-    {
54
-        return function_exists('PLL')
55
-            && function_exists('pll_get_post')
56
-            && function_exists('pll_get_post_language')
57
-            && function_exists('pll_get_post_translations');
58
-    }
49
+	/**
50
+	 * {@inheritdoc}
51
+	 */
52
+	public function isActive()
53
+	{
54
+		return function_exists('PLL')
55
+			&& function_exists('pll_get_post')
56
+			&& function_exists('pll_get_post_language')
57
+			&& function_exists('pll_get_post_translations');
58
+	}
59 59
 
60
-    /**
61
-     * {@inheritdoc}
62
-     */
63
-    public function isEnabled()
64
-    {
65
-        return $this->isActive()
66
-            && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual');
67
-    }
60
+	/**
61
+	 * {@inheritdoc}
62
+	 */
63
+	public function isEnabled()
64
+	{
65
+		return $this->isActive()
66
+			&& 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual');
67
+	}
68 68
 
69
-    /**
70
-     * {@inheritdoc}
71
-     */
72
-    public function isSupported()
73
-    {
74
-        return defined('POLYLANG_VERSION')
75
-            && version_compare(POLYLANG_VERSION, static::SUPPORTED_VERSION, '>=');
76
-    }
69
+	/**
70
+	 * {@inheritdoc}
71
+	 */
72
+	public function isSupported()
73
+	{
74
+		return defined('POLYLANG_VERSION')
75
+			&& version_compare(POLYLANG_VERSION, static::SUPPORTED_VERSION, '>=');
76
+	}
77 77
 
78
-    /**
79
-     * @return array
80
-     */
81
-    protected function cleanIds(array $postIds)
82
-    {
83
-        return array_filter(array_unique($postIds));
84
-    }
78
+	/**
79
+	 * @return array
80
+	 */
81
+	protected function cleanIds(array $postIds)
82
+	{
83
+		return array_filter(array_unique($postIds));
84
+	}
85 85
 }
Please login to merge, or discard this patch.