Passed
Push — master ( ccb079...7906b4 )
by Paul
04:39
created
plugin/Helper.php 2 patches
Indentation   +214 added lines, -214 removed lines patch added patch discarded remove patch
@@ -8,218 +8,218 @@
 block discarded – undo
8 8
 
9 9
 class Helper
10 10
 {
11
-    /**
12
-     * @param string $name
13
-     * @param string $path
14
-     * @return string
15
-     */
16
-    public static function buildClassName($name, $path = '')
17
-    {
18
-        $className = Str::camelCase($name);
19
-        $path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\');
20
-        return !empty($path)
21
-            ? __NAMESPACE__.'\\'.$path.'\\'.$className
22
-            : $className;
23
-    }
24
-
25
-    /**
26
-     * @param string $name
27
-     * @param string $prefix
28
-     * @return string
29
-     */
30
-    public static function buildMethodName($name, $prefix = '')
31
-    {
32
-        return lcfirst($prefix.static::buildClassName($name));
33
-    }
34
-
35
-    /**
36
-     * @param string $name
37
-     * @return string
38
-     */
39
-    public static function buildPropertyName($name)
40
-    {
41
-        return static::buildMethodName($name);
42
-    }
43
-
44
-    /**
45
-     * @param string $cast
46
-     * @param mixed $value
47
-     * @return mixed
48
-     */
49
-    public static function castTo($cast = '', $value)
50
-    {
51
-        $method = static::buildMethodName($cast, 'castTo');
52
-        return !empty($cast) && method_exists(__CLASS__, $method)
53
-            ? static::$method($value)
54
-            : $value;
55
-    }
56
-
57
-    /**
58
-     * @param mixed $value
59
-     * @return array
60
-     */
61
-    public static function castToArray($value)
62
-    {
63
-        return (array) $value;
64
-    }
65
-
66
-    /**
67
-     * @param mixed $value
68
-     * @return bool
69
-     */
70
-    public static function castToBool($value)
71
-    {
72
-        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
73
-    }
74
-
75
-    /**
76
-     * @param mixed $value
77
-     * @return float
78
-     */
79
-    public static function castToFloat($value)
80
-    {
81
-        return (float) filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND);
82
-    }
83
-
84
-    /**
85
-     * @param mixed $value
86
-     * @return int
87
-     */
88
-    public static function castToInt($value)
89
-    {
90
-        return (int) filter_var($value, FILTER_VALIDATE_INT);
91
-    }
92
-
93
-    /**
94
-     * @param mixed $value
95
-     * @return object
96
-     */
97
-    public static function castToObject($value)
98
-    {
99
-        return (object) (array) $value;
100
-    }
101
-
102
-    /**
103
-     * @param mixed $value
104
-     * @return string
105
-     */
106
-    public static function castToString($value)
107
-    {
108
-        if (is_object($value) && in_array('__toString', get_class_methods($value))) {
109
-            return (string) $value->__toString();
110
-        }
111
-        if (is_array($value) || is_object($value)) {
112
-            return serialize($value);
113
-        }
114
-        return (string) $value;
115
-    }
116
-
117
-    /**
118
-     * @param string $key
119
-     * @return mixed
120
-     */
121
-    public static function filterInput($key, array $request = [])
122
-    {
123
-        if (isset($request[$key])) {
124
-            return $request[$key];
125
-        }
126
-        $variable = filter_input(INPUT_POST, $key);
127
-        if (is_null($variable) && isset($_POST[$key])) {
128
-            $variable = $_POST[$key];
129
-        }
130
-        return $variable;
131
-    }
132
-
133
-    /**
134
-     * @param string $key
135
-     * @return array
136
-     */
137
-    public static function filterInputArray($key)
138
-    {
139
-        $variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
140
-        if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) {
141
-            $variable = $_POST[$key];
142
-        }
143
-        return (array) $variable;
144
-    }
145
-
146
-    /**
147
-     * @return string
148
-     */
149
-    public static function getIpAddress()
150
-    {
151
-        $whitelist = [];
152
-        $isUsingCloudflare = !empty(filter_input(INPUT_SERVER, 'CF-Connecting-IP'));
153
-        if (apply_filters('site-reviews/whip/whitelist/cloudflare', $isUsingCloudflare)) {
154
-            $cloudflareIps = glsr(Cache::class)->getCloudflareIps();
155
-            $whitelist[Whip::CLOUDFLARE_HEADERS] = [Whip::IPV4 => $cloudflareIps['v4']];
156
-            if (defined('AF_INET6')) {
157
-                $whitelist[Whip::CLOUDFLARE_HEADERS][Whip::IPV6] = $cloudflareIps['v6'];
158
-            }
159
-        }
160
-        $whitelist = apply_filters('site-reviews/whip/whitelist', $whitelist);
161
-        $methods = apply_filters('site-reviews/whip/methods', Whip::ALL_METHODS);
162
-        $whip = new Whip($methods, $whitelist);
163
-        do_action_ref_array('site-reviews/whip', [$whip]);
164
-        if (false !== ($clientAddress = $whip->getValidIpAddress())) {
165
-            return (string) $clientAddress;
166
-        }
167
-        glsr_log()->error('Unable to detect IP address, please see the FAQ page for a possible solution.');
168
-        return 'unknown';
169
-    }
170
-
171
-    /**
172
-     * @param mixed $value
173
-     * @param string|int $min
174
-     * @param string|int $max
175
-     * @return bool
176
-     */
177
-    public static function inRange($value, $min, $max)
178
-    {
179
-        $inRange = filter_var($value, FILTER_VALIDATE_INT, ['options' => [
180
-            'min_range' => intval($min),
181
-            'max_range' => intval($max),
182
-        ]]);
183
-        return false !== $inRange;
184
-    }
185
-
186
-    /**
187
-     * @param int|string $value
188
-     * @param int|string $compareWithValue
189
-     * @return bool
190
-     */
191
-    public static function isGreaterThan($value, $compareWithValue)
192
-    {
193
-        return version_compare($value, $compareWithValue, '>');
194
-    }
195
-
196
-    /**
197
-     * @param int|string $value
198
-     * @param int|string $compareWithValue
199
-     * @return bool
200
-     */
201
-    public static function isGreaterThanOrEqual($value, $compareWithValue)
202
-    {
203
-        return version_compare($value, $compareWithValue, '>=');
204
-    }
205
-
206
-    /**
207
-     * @param int|string $value
208
-     * @param int|string $compareWithValue
209
-     * @return bool
210
-     */
211
-    public static function isLessThan($value, $compareWithValue)
212
-    {
213
-        return version_compare($value, $compareWithValue, '<');
214
-    }
215
-
216
-    /**
217
-     * @param int|string $value
218
-     * @param int|string $compareWithValue
219
-     * @return bool
220
-     */
221
-    public static function isLessThanOrEqual($value, $compareWithValue)
222
-    {
223
-        return version_compare($value, $compareWithValue, '<=');
224
-    }
11
+	/**
12
+	 * @param string $name
13
+	 * @param string $path
14
+	 * @return string
15
+	 */
16
+	public static function buildClassName($name, $path = '')
17
+	{
18
+		$className = Str::camelCase($name);
19
+		$path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\');
20
+		return !empty($path)
21
+			? __NAMESPACE__.'\\'.$path.'\\'.$className
22
+			: $className;
23
+	}
24
+
25
+	/**
26
+	 * @param string $name
27
+	 * @param string $prefix
28
+	 * @return string
29
+	 */
30
+	public static function buildMethodName($name, $prefix = '')
31
+	{
32
+		return lcfirst($prefix.static::buildClassName($name));
33
+	}
34
+
35
+	/**
36
+	 * @param string $name
37
+	 * @return string
38
+	 */
39
+	public static function buildPropertyName($name)
40
+	{
41
+		return static::buildMethodName($name);
42
+	}
43
+
44
+	/**
45
+	 * @param string $cast
46
+	 * @param mixed $value
47
+	 * @return mixed
48
+	 */
49
+	public static function castTo($cast = '', $value)
50
+	{
51
+		$method = static::buildMethodName($cast, 'castTo');
52
+		return !empty($cast) && method_exists(__CLASS__, $method)
53
+			? static::$method($value)
54
+			: $value;
55
+	}
56
+
57
+	/**
58
+	 * @param mixed $value
59
+	 * @return array
60
+	 */
61
+	public static function castToArray($value)
62
+	{
63
+		return (array) $value;
64
+	}
65
+
66
+	/**
67
+	 * @param mixed $value
68
+	 * @return bool
69
+	 */
70
+	public static function castToBool($value)
71
+	{
72
+		return filter_var($value, FILTER_VALIDATE_BOOLEAN);
73
+	}
74
+
75
+	/**
76
+	 * @param mixed $value
77
+	 * @return float
78
+	 */
79
+	public static function castToFloat($value)
80
+	{
81
+		return (float) filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND);
82
+	}
83
+
84
+	/**
85
+	 * @param mixed $value
86
+	 * @return int
87
+	 */
88
+	public static function castToInt($value)
89
+	{
90
+		return (int) filter_var($value, FILTER_VALIDATE_INT);
91
+	}
92
+
93
+	/**
94
+	 * @param mixed $value
95
+	 * @return object
96
+	 */
97
+	public static function castToObject($value)
98
+	{
99
+		return (object) (array) $value;
100
+	}
101
+
102
+	/**
103
+	 * @param mixed $value
104
+	 * @return string
105
+	 */
106
+	public static function castToString($value)
107
+	{
108
+		if (is_object($value) && in_array('__toString', get_class_methods($value))) {
109
+			return (string) $value->__toString();
110
+		}
111
+		if (is_array($value) || is_object($value)) {
112
+			return serialize($value);
113
+		}
114
+		return (string) $value;
115
+	}
116
+
117
+	/**
118
+	 * @param string $key
119
+	 * @return mixed
120
+	 */
121
+	public static function filterInput($key, array $request = [])
122
+	{
123
+		if (isset($request[$key])) {
124
+			return $request[$key];
125
+		}
126
+		$variable = filter_input(INPUT_POST, $key);
127
+		if (is_null($variable) && isset($_POST[$key])) {
128
+			$variable = $_POST[$key];
129
+		}
130
+		return $variable;
131
+	}
132
+
133
+	/**
134
+	 * @param string $key
135
+	 * @return array
136
+	 */
137
+	public static function filterInputArray($key)
138
+	{
139
+		$variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
140
+		if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) {
141
+			$variable = $_POST[$key];
142
+		}
143
+		return (array) $variable;
144
+	}
145
+
146
+	/**
147
+	 * @return string
148
+	 */
149
+	public static function getIpAddress()
150
+	{
151
+		$whitelist = [];
152
+		$isUsingCloudflare = !empty(filter_input(INPUT_SERVER, 'CF-Connecting-IP'));
153
+		if (apply_filters('site-reviews/whip/whitelist/cloudflare', $isUsingCloudflare)) {
154
+			$cloudflareIps = glsr(Cache::class)->getCloudflareIps();
155
+			$whitelist[Whip::CLOUDFLARE_HEADERS] = [Whip::IPV4 => $cloudflareIps['v4']];
156
+			if (defined('AF_INET6')) {
157
+				$whitelist[Whip::CLOUDFLARE_HEADERS][Whip::IPV6] = $cloudflareIps['v6'];
158
+			}
159
+		}
160
+		$whitelist = apply_filters('site-reviews/whip/whitelist', $whitelist);
161
+		$methods = apply_filters('site-reviews/whip/methods', Whip::ALL_METHODS);
162
+		$whip = new Whip($methods, $whitelist);
163
+		do_action_ref_array('site-reviews/whip', [$whip]);
164
+		if (false !== ($clientAddress = $whip->getValidIpAddress())) {
165
+			return (string) $clientAddress;
166
+		}
167
+		glsr_log()->error('Unable to detect IP address, please see the FAQ page for a possible solution.');
168
+		return 'unknown';
169
+	}
170
+
171
+	/**
172
+	 * @param mixed $value
173
+	 * @param string|int $min
174
+	 * @param string|int $max
175
+	 * @return bool
176
+	 */
177
+	public static function inRange($value, $min, $max)
178
+	{
179
+		$inRange = filter_var($value, FILTER_VALIDATE_INT, ['options' => [
180
+			'min_range' => intval($min),
181
+			'max_range' => intval($max),
182
+		]]);
183
+		return false !== $inRange;
184
+	}
185
+
186
+	/**
187
+	 * @param int|string $value
188
+	 * @param int|string $compareWithValue
189
+	 * @return bool
190
+	 */
191
+	public static function isGreaterThan($value, $compareWithValue)
192
+	{
193
+		return version_compare($value, $compareWithValue, '>');
194
+	}
195
+
196
+	/**
197
+	 * @param int|string $value
198
+	 * @param int|string $compareWithValue
199
+	 * @return bool
200
+	 */
201
+	public static function isGreaterThanOrEqual($value, $compareWithValue)
202
+	{
203
+		return version_compare($value, $compareWithValue, '>=');
204
+	}
205
+
206
+	/**
207
+	 * @param int|string $value
208
+	 * @param int|string $compareWithValue
209
+	 * @return bool
210
+	 */
211
+	public static function isLessThan($value, $compareWithValue)
212
+	{
213
+		return version_compare($value, $compareWithValue, '<');
214
+	}
215
+
216
+	/**
217
+	 * @param int|string $value
218
+	 * @param int|string $compareWithValue
219
+	 * @return bool
220
+	 */
221
+	public static function isLessThanOrEqual($value, $compareWithValue)
222
+	{
223
+		return version_compare($value, $compareWithValue, '<=');
224
+	}
225 225
 }
Please login to merge, or discard this patch.
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -13,10 +13,10 @@  discard block
 block discarded – undo
13 13
      * @param string $path
14 14
      * @return string
15 15
      */
16
-    public static function buildClassName($name, $path = '')
16
+    public static function buildClassName( $name, $path = '' )
17 17
     {
18
-        $className = Str::camelCase($name);
19
-        $path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\');
18
+        $className = Str::camelCase( $name );
19
+        $path = ltrim( str_replace( __NAMESPACE__, '', $path ), '\\' );
20 20
         return !empty($path)
21 21
             ? __NAMESPACE__.'\\'.$path.'\\'.$className
22 22
             : $className;
@@ -27,18 +27,18 @@  discard block
 block discarded – undo
27 27
      * @param string $prefix
28 28
      * @return string
29 29
      */
30
-    public static function buildMethodName($name, $prefix = '')
30
+    public static function buildMethodName( $name, $prefix = '' )
31 31
     {
32
-        return lcfirst($prefix.static::buildClassName($name));
32
+        return lcfirst( $prefix.static::buildClassName( $name ) );
33 33
     }
34 34
 
35 35
     /**
36 36
      * @param string $name
37 37
      * @return string
38 38
      */
39
-    public static function buildPropertyName($name)
39
+    public static function buildPropertyName( $name )
40 40
     {
41
-        return static::buildMethodName($name);
41
+        return static::buildMethodName( $name );
42 42
     }
43 43
 
44 44
     /**
@@ -46,11 +46,11 @@  discard block
 block discarded – undo
46 46
      * @param mixed $value
47 47
      * @return mixed
48 48
      */
49
-    public static function castTo($cast = '', $value)
49
+    public static function castTo( $cast = '', $value )
50 50
     {
51
-        $method = static::buildMethodName($cast, 'castTo');
52
-        return !empty($cast) && method_exists(__CLASS__, $method)
53
-            ? static::$method($value)
51
+        $method = static::buildMethodName( $cast, 'castTo' );
52
+        return !empty($cast) && method_exists( __CLASS__, $method )
53
+            ? static::$method( $value )
54 54
             : $value;
55 55
     }
56 56
 
@@ -58,73 +58,73 @@  discard block
 block discarded – undo
58 58
      * @param mixed $value
59 59
      * @return array
60 60
      */
61
-    public static function castToArray($value)
61
+    public static function castToArray( $value )
62 62
     {
63
-        return (array) $value;
63
+        return (array)$value;
64 64
     }
65 65
 
66 66
     /**
67 67
      * @param mixed $value
68 68
      * @return bool
69 69
      */
70
-    public static function castToBool($value)
70
+    public static function castToBool( $value )
71 71
     {
72
-        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
72
+        return filter_var( $value, FILTER_VALIDATE_BOOLEAN );
73 73
     }
74 74
 
75 75
     /**
76 76
      * @param mixed $value
77 77
      * @return float
78 78
      */
79
-    public static function castToFloat($value)
79
+    public static function castToFloat( $value )
80 80
     {
81
-        return (float) filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND);
81
+        return (float)filter_var( $value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND );
82 82
     }
83 83
 
84 84
     /**
85 85
      * @param mixed $value
86 86
      * @return int
87 87
      */
88
-    public static function castToInt($value)
88
+    public static function castToInt( $value )
89 89
     {
90
-        return (int) filter_var($value, FILTER_VALIDATE_INT);
90
+        return (int)filter_var( $value, FILTER_VALIDATE_INT );
91 91
     }
92 92
 
93 93
     /**
94 94
      * @param mixed $value
95 95
      * @return object
96 96
      */
97
-    public static function castToObject($value)
97
+    public static function castToObject( $value )
98 98
     {
99
-        return (object) (array) $value;
99
+        return (object)(array)$value;
100 100
     }
101 101
 
102 102
     /**
103 103
      * @param mixed $value
104 104
      * @return string
105 105
      */
106
-    public static function castToString($value)
106
+    public static function castToString( $value )
107 107
     {
108
-        if (is_object($value) && in_array('__toString', get_class_methods($value))) {
109
-            return (string) $value->__toString();
108
+        if( is_object( $value ) && in_array( '__toString', get_class_methods( $value ) ) ) {
109
+            return (string)$value->__toString();
110 110
         }
111
-        if (is_array($value) || is_object($value)) {
112
-            return serialize($value);
111
+        if( is_array( $value ) || is_object( $value ) ) {
112
+            return serialize( $value );
113 113
         }
114
-        return (string) $value;
114
+        return (string)$value;
115 115
     }
116 116
 
117 117
     /**
118 118
      * @param string $key
119 119
      * @return mixed
120 120
      */
121
-    public static function filterInput($key, array $request = [])
121
+    public static function filterInput( $key, array $request = [] )
122 122
     {
123
-        if (isset($request[$key])) {
123
+        if( isset($request[$key]) ) {
124 124
             return $request[$key];
125 125
         }
126
-        $variable = filter_input(INPUT_POST, $key);
127
-        if (is_null($variable) && isset($_POST[$key])) {
126
+        $variable = filter_input( INPUT_POST, $key );
127
+        if( is_null( $variable ) && isset($_POST[$key]) ) {
128 128
             $variable = $_POST[$key];
129 129
         }
130 130
         return $variable;
@@ -134,13 +134,13 @@  discard block
 block discarded – undo
134 134
      * @param string $key
135 135
      * @return array
136 136
      */
137
-    public static function filterInputArray($key)
137
+    public static function filterInputArray( $key )
138 138
     {
139
-        $variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
140
-        if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) {
139
+        $variable = filter_input( INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
140
+        if( empty($variable) && !empty($_POST[$key]) && is_array( $_POST[$key] ) ) {
141 141
             $variable = $_POST[$key];
142 142
         }
143
-        return (array) $variable;
143
+        return (array)$variable;
144 144
     }
145 145
 
146 146
     /**
@@ -149,22 +149,22 @@  discard block
 block discarded – undo
149 149
     public static function getIpAddress()
150 150
     {
151 151
         $whitelist = [];
152
-        $isUsingCloudflare = !empty(filter_input(INPUT_SERVER, 'CF-Connecting-IP'));
153
-        if (apply_filters('site-reviews/whip/whitelist/cloudflare', $isUsingCloudflare)) {
154
-            $cloudflareIps = glsr(Cache::class)->getCloudflareIps();
152
+        $isUsingCloudflare = !empty(filter_input( INPUT_SERVER, 'CF-Connecting-IP' ));
153
+        if( apply_filters( 'site-reviews/whip/whitelist/cloudflare', $isUsingCloudflare ) ) {
154
+            $cloudflareIps = glsr( Cache::class )->getCloudflareIps();
155 155
             $whitelist[Whip::CLOUDFLARE_HEADERS] = [Whip::IPV4 => $cloudflareIps['v4']];
156
-            if (defined('AF_INET6')) {
156
+            if( defined( 'AF_INET6' ) ) {
157 157
                 $whitelist[Whip::CLOUDFLARE_HEADERS][Whip::IPV6] = $cloudflareIps['v6'];
158 158
             }
159 159
         }
160
-        $whitelist = apply_filters('site-reviews/whip/whitelist', $whitelist);
161
-        $methods = apply_filters('site-reviews/whip/methods', Whip::ALL_METHODS);
162
-        $whip = new Whip($methods, $whitelist);
163
-        do_action_ref_array('site-reviews/whip', [$whip]);
164
-        if (false !== ($clientAddress = $whip->getValidIpAddress())) {
165
-            return (string) $clientAddress;
160
+        $whitelist = apply_filters( 'site-reviews/whip/whitelist', $whitelist );
161
+        $methods = apply_filters( 'site-reviews/whip/methods', Whip::ALL_METHODS );
162
+        $whip = new Whip( $methods, $whitelist );
163
+        do_action_ref_array( 'site-reviews/whip', [$whip] );
164
+        if( false !== ($clientAddress = $whip->getValidIpAddress()) ) {
165
+            return (string)$clientAddress;
166 166
         }
167
-        glsr_log()->error('Unable to detect IP address, please see the FAQ page for a possible solution.');
167
+        glsr_log()->error( 'Unable to detect IP address, please see the FAQ page for a possible solution.' );
168 168
         return 'unknown';
169 169
     }
170 170
 
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
      * @param string|int $max
175 175
      * @return bool
176 176
      */
177
-    public static function inRange($value, $min, $max)
177
+    public static function inRange( $value, $min, $max )
178 178
     {
179
-        $inRange = filter_var($value, FILTER_VALIDATE_INT, ['options' => [
180
-            'min_range' => intval($min),
181
-            'max_range' => intval($max),
182
-        ]]);
179
+        $inRange = filter_var( $value, FILTER_VALIDATE_INT, ['options' => [
180
+            'min_range' => intval( $min ),
181
+            'max_range' => intval( $max ),
182
+        ]] );
183 183
         return false !== $inRange;
184 184
     }
185 185
 
@@ -188,9 +188,9 @@  discard block
 block discarded – undo
188 188
      * @param int|string $compareWithValue
189 189
      * @return bool
190 190
      */
191
-    public static function isGreaterThan($value, $compareWithValue)
191
+    public static function isGreaterThan( $value, $compareWithValue )
192 192
     {
193
-        return version_compare($value, $compareWithValue, '>');
193
+        return version_compare( $value, $compareWithValue, '>' );
194 194
     }
195 195
 
196 196
     /**
@@ -198,9 +198,9 @@  discard block
 block discarded – undo
198 198
      * @param int|string $compareWithValue
199 199
      * @return bool
200 200
      */
201
-    public static function isGreaterThanOrEqual($value, $compareWithValue)
201
+    public static function isGreaterThanOrEqual( $value, $compareWithValue )
202 202
     {
203
-        return version_compare($value, $compareWithValue, '>=');
203
+        return version_compare( $value, $compareWithValue, '>=' );
204 204
     }
205 205
 
206 206
     /**
@@ -208,9 +208,9 @@  discard block
 block discarded – undo
208 208
      * @param int|string $compareWithValue
209 209
      * @return bool
210 210
      */
211
-    public static function isLessThan($value, $compareWithValue)
211
+    public static function isLessThan( $value, $compareWithValue )
212 212
     {
213
-        return version_compare($value, $compareWithValue, '<');
213
+        return version_compare( $value, $compareWithValue, '<' );
214 214
     }
215 215
 
216 216
     /**
@@ -218,8 +218,8 @@  discard block
 block discarded – undo
218 218
      * @param int|string $compareWithValue
219 219
      * @return bool
220 220
      */
221
-    public static function isLessThanOrEqual($value, $compareWithValue)
221
+    public static function isLessThanOrEqual( $value, $compareWithValue )
222 222
     {
223
-        return version_compare($value, $compareWithValue, '<=');
223
+        return version_compare( $value, $compareWithValue, '<=' );
224 224
     }
225 225
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Partials/Pagination.php 2 patches
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -10,52 +10,52 @@
 block discarded – undo
10 10
 
11 11
 class Pagination implements PartialContract
12 12
 {
13
-    /**
14
-     * @var array
15
-     */
16
-    protected $args;
13
+	/**
14
+	 * @var array
15
+	 */
16
+	protected $args;
17 17
 
18
-    /**
19
-     * {@inheritdoc}
20
-     */
21
-    public function build(array $args = [])
22
-    {
23
-        $this->args = $this->normalize($args);
24
-        if ($this->args['total'] < 2) {
25
-            return '';
26
-        }
27
-        return glsr(Template::class)->build('templates/pagination', [
28
-            'context' => [
29
-                'links' => apply_filters('site-reviews/paginate_links', $this->buildLinks(), $this->args),
30
-                'loader' => '<div class="glsr-loader"></div>',
31
-                'screen_reader_text' => __('Site Reviews navigation', 'site-reviews'),
32
-            ],
33
-        ]);
34
-    }
18
+	/**
19
+	 * {@inheritdoc}
20
+	 */
21
+	public function build(array $args = [])
22
+	{
23
+		$this->args = $this->normalize($args);
24
+		if ($this->args['total'] < 2) {
25
+			return '';
26
+		}
27
+		return glsr(Template::class)->build('templates/pagination', [
28
+			'context' => [
29
+				'links' => apply_filters('site-reviews/paginate_links', $this->buildLinks(), $this->args),
30
+				'loader' => '<div class="glsr-loader"></div>',
31
+				'screen_reader_text' => __('Site Reviews navigation', 'site-reviews'),
32
+			],
33
+		]);
34
+	}
35 35
 
36
-    /**
37
-     * @return string
38
-     */
39
-    protected function buildLinks()
40
-    {
41
-        $args = glsr(Style::class)->paginationArgs($this->args);
42
-        if ('array' == $args['type']) {
43
-            $args['type'] = 'plain';
44
-        }
45
-        return paginate_links($args);
46
-    }
36
+	/**
37
+	 * @return string
38
+	 */
39
+	protected function buildLinks()
40
+	{
41
+		$args = glsr(Style::class)->paginationArgs($this->args);
42
+		if ('array' == $args['type']) {
43
+			$args['type'] = 'plain';
44
+		}
45
+		return paginate_links($args);
46
+	}
47 47
 
48
-    /**
49
-     * @return array
50
-     */
51
-    protected function normalize(array $args)
52
-    {
53
-        if ($baseUrl = Arr::get($args, 'baseUrl')) {
54
-            $args['base'] = $baseUrl.'%_%';
55
-        }
56
-        return wp_parse_args(array_filter($args), [
57
-            'current' => glsr(QueryBuilder::class)->getPaged(),
58
-            'total' => 1,
59
-        ]);
60
-    }
48
+	/**
49
+	 * @return array
50
+	 */
51
+	protected function normalize(array $args)
52
+	{
53
+		if ($baseUrl = Arr::get($args, 'baseUrl')) {
54
+			$args['base'] = $baseUrl.'%_%';
55
+		}
56
+		return wp_parse_args(array_filter($args), [
57
+			'current' => glsr(QueryBuilder::class)->getPaged(),
58
+			'total' => 1,
59
+		]);
60
+	}
61 61
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -18,19 +18,19 @@  discard block
 block discarded – undo
18 18
     /**
19 19
      * {@inheritdoc}
20 20
      */
21
-    public function build(array $args = [])
21
+    public function build( array $args = [] )
22 22
     {
23
-        $this->args = $this->normalize($args);
24
-        if ($this->args['total'] < 2) {
23
+        $this->args = $this->normalize( $args );
24
+        if( $this->args['total'] < 2 ) {
25 25
             return '';
26 26
         }
27
-        return glsr(Template::class)->build('templates/pagination', [
27
+        return glsr( Template::class )->build( 'templates/pagination', [
28 28
             'context' => [
29
-                'links' => apply_filters('site-reviews/paginate_links', $this->buildLinks(), $this->args),
29
+                'links' => apply_filters( 'site-reviews/paginate_links', $this->buildLinks(), $this->args ),
30 30
                 'loader' => '<div class="glsr-loader"></div>',
31
-                'screen_reader_text' => __('Site Reviews navigation', 'site-reviews'),
31
+                'screen_reader_text' => __( 'Site Reviews navigation', 'site-reviews' ),
32 32
             ],
33
-        ]);
33
+        ] );
34 34
     }
35 35
 
36 36
     /**
@@ -38,24 +38,24 @@  discard block
 block discarded – undo
38 38
      */
39 39
     protected function buildLinks()
40 40
     {
41
-        $args = glsr(Style::class)->paginationArgs($this->args);
42
-        if ('array' == $args['type']) {
41
+        $args = glsr( Style::class )->paginationArgs( $this->args );
42
+        if( 'array' == $args['type'] ) {
43 43
             $args['type'] = 'plain';
44 44
         }
45
-        return paginate_links($args);
45
+        return paginate_links( $args );
46 46
     }
47 47
 
48 48
     /**
49 49
      * @return array
50 50
      */
51
-    protected function normalize(array $args)
51
+    protected function normalize( array $args )
52 52
     {
53
-        if ($baseUrl = Arr::get($args, 'baseUrl')) {
53
+        if( $baseUrl = Arr::get( $args, 'baseUrl' ) ) {
54 54
             $args['base'] = $baseUrl.'%_%';
55 55
         }
56
-        return wp_parse_args(array_filter($args), [
57
-            'current' => glsr(QueryBuilder::class)->getPaged(),
56
+        return wp_parse_args( array_filter( $args ), [
57
+            'current' => glsr( QueryBuilder::class )->getPaged(),
58 58
             'total' => 1,
59
-        ]);
59
+        ] );
60 60
     }
61 61
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Partials/SiteReviewsSummary.php 2 patches
Indentation   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -11,197 +11,197 @@
 block discarded – undo
11 11
 
12 12
 class SiteReviewsSummary implements PartialContract
13 13
 {
14
-    /**
15
-     * @var array
16
-     */
17
-    protected $args;
18
-
19
-    /**
20
-     * @var float
21
-     */
22
-    protected $averageRating;
23
-
24
-    /**
25
-     * @var array
26
-     */
27
-    protected $ratingCounts;
28
-
29
-    /**
30
-     * {@inheritdoc}
31
-     */
32
-    public function build(array $args = [])
33
-    {
34
-        $this->args = $args;
35
-        $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($args);
36
-        if (!array_sum($this->ratingCounts) && $this->isHidden('if_empty')) {
37
-            return '';
38
-        }
39
-        $this->averageRating = glsr(Rating::class)->getAverage($this->ratingCounts);
40
-        $this->generateSchema();
41
-        return glsr(Template::class)->build('templates/reviews-summary', [
42
-            'context' => [
43
-                'assigned_to' => $this->args['assigned_to'],
44
-                'category' => $this->args['category'],
45
-                'class' => $this->getClass(),
46
-                'id' => $this->args['id'],
47
-                'percentages' => $this->buildPercentage(),
48
-                'rating' => $this->buildRating(),
49
-                'stars' => $this->buildStars(),
50
-                'text' => $this->buildText(),
51
-            ],
52
-        ]);
53
-    }
54
-
55
-    /**
56
-     * @return void|string
57
-     */
58
-    protected function buildPercentage()
59
-    {
60
-        if ($this->isHidden('bars')) {
61
-            return;
62
-        }
63
-        $percentages = preg_filter('/$/', '%', glsr(Rating::class)->getPercentages($this->ratingCounts));
64
-        $bars = array_reduce(range(glsr()->constant('MAX_RATING', Rating::class), 1), function ($carry, $level) use ($percentages) {
65
-            $label = $this->buildPercentageLabel($this->args['labels'][$level]);
66
-            $background = $this->buildPercentageBackground($percentages[$level]);
67
-            $count = apply_filters('site-reviews/summary/counts',
68
-                $percentages[$level],
69
-                $this->ratingCounts[$level]
70
-            );
71
-            $percent = $this->buildPercentageCount($count);
72
-            $value = $label.$background.$percent;
73
-            $value = apply_filters('site-reviews/summary/wrap/bar', $value, $this->args, [
74
-                'percent' => wp_strip_all_tags($count, true),
75
-                'rating' => $level,
76
-            ]);
77
-            return $carry.glsr(Builder::class)->div($value, [
78
-                'class' => 'glsr-bar',
79
-            ]);
80
-        });
81
-        return $this->wrap('percentage', $bars);
82
-    }
83
-
84
-    /**
85
-     * @param string $percent
86
-     * @return string
87
-     */
88
-    protected function buildPercentageBackground($percent)
89
-    {
90
-        $backgroundPercent = glsr(Builder::class)->span([
91
-            'class' => 'glsr-bar-background-percent',
92
-            'style' => 'width:'.$percent,
93
-        ]);
94
-        return '<span class="glsr-bar-background">'.$backgroundPercent.'</span>';
95
-    }
96
-
97
-    /**
98
-     * @param string $count
99
-     * @return string
100
-     */
101
-    protected function buildPercentageCount($count)
102
-    {
103
-        return '<span class="glsr-bar-percent">'.$count.'</span>';
104
-    }
105
-
106
-    /**
107
-     * @param string $label
108
-     * @return string
109
-     */
110
-    protected function buildPercentageLabel($label)
111
-    {
112
-        return '<span class="glsr-bar-label">'.$label.'</span>';
113
-    }
114
-
115
-    /**
116
-     * @return void|string
117
-     */
118
-    protected function buildRating()
119
-    {
120
-        if ($this->isHidden('rating')) {
121
-            return;
122
-        }
123
-        return $this->wrap('rating', '<span>'.$this->averageRating.'</span>');
124
-    }
125
-
126
-    /**
127
-     * @return void|string
128
-     */
129
-    protected function buildStars()
130
-    {
131
-        if ($this->isHidden('stars')) {
132
-            return;
133
-        }
134
-        $stars = glsr_star_rating($this->averageRating);
135
-        return $this->wrap('stars', $stars);
136
-    }
137
-
138
-    /**
139
-     * @return void|string
140
-     */
141
-    protected function buildText()
142
-    {
143
-        if ($this->isHidden('summary')) {
144
-            return;
145
-        }
146
-        $count = intval(array_sum($this->ratingCounts));
147
-        if (empty($this->args['text'])) {
148
-            // @todo document this change
149
-            $this->args['text'] = _nx(
150
-                '{rating} out of {max} stars (based on {num} review)',
151
-                '{rating} out of {max} stars (based on {num} reviews)',
152
-                $count,
153
-                'Do not translate {rating}, {max}, and {num}, they are template tags.',
154
-                'site-reviews'
155
-            );
156
-        }
157
-        $summary = str_replace(
158
-            ['{rating}', '{max}', '{num}'],
159
-            [$this->averageRating, glsr()->constant('MAX_RATING', Rating::class), $count],
160
-            $this->args['text']
161
-        );
162
-        return $this->wrap('text', '<span>'.$summary.'</span>');
163
-    }
164
-
165
-    /**
166
-     * @return void
167
-     */
168
-    protected function generateSchema()
169
-    {
170
-        if (!wp_validate_boolean($this->args['schema'])) {
171
-            return;
172
-        }
173
-        glsr(Schema::class)->store(
174
-            glsr(Schema::class)->buildSummary($this->args)
175
-        );
176
-    }
177
-
178
-    /**
179
-     * @return string
180
-     */
181
-    protected function getClass()
182
-    {
183
-        return trim('glsr-summary '.$this->args['class']);
184
-    }
185
-
186
-    /**
187
-     * @param string $key
188
-     * @return bool
189
-     */
190
-    protected function isHidden($key)
191
-    {
192
-        return in_array($key, $this->args['hide']);
193
-    }
194
-
195
-    /**
196
-     * @param string $key
197
-     * @param string $value
198
-     * @return string
199
-     */
200
-    protected function wrap($key, $value)
201
-    {
202
-        $value = apply_filters('site-reviews/summary/wrap/'.$key, $value, $this->args);
203
-        return glsr(Builder::class)->div($value, [
204
-            'class' => 'glsr-summary-'.$key,
205
-        ]);
206
-    }
14
+	/**
15
+	 * @var array
16
+	 */
17
+	protected $args;
18
+
19
+	/**
20
+	 * @var float
21
+	 */
22
+	protected $averageRating;
23
+
24
+	/**
25
+	 * @var array
26
+	 */
27
+	protected $ratingCounts;
28
+
29
+	/**
30
+	 * {@inheritdoc}
31
+	 */
32
+	public function build(array $args = [])
33
+	{
34
+		$this->args = $args;
35
+		$this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($args);
36
+		if (!array_sum($this->ratingCounts) && $this->isHidden('if_empty')) {
37
+			return '';
38
+		}
39
+		$this->averageRating = glsr(Rating::class)->getAverage($this->ratingCounts);
40
+		$this->generateSchema();
41
+		return glsr(Template::class)->build('templates/reviews-summary', [
42
+			'context' => [
43
+				'assigned_to' => $this->args['assigned_to'],
44
+				'category' => $this->args['category'],
45
+				'class' => $this->getClass(),
46
+				'id' => $this->args['id'],
47
+				'percentages' => $this->buildPercentage(),
48
+				'rating' => $this->buildRating(),
49
+				'stars' => $this->buildStars(),
50
+				'text' => $this->buildText(),
51
+			],
52
+		]);
53
+	}
54
+
55
+	/**
56
+	 * @return void|string
57
+	 */
58
+	protected function buildPercentage()
59
+	{
60
+		if ($this->isHidden('bars')) {
61
+			return;
62
+		}
63
+		$percentages = preg_filter('/$/', '%', glsr(Rating::class)->getPercentages($this->ratingCounts));
64
+		$bars = array_reduce(range(glsr()->constant('MAX_RATING', Rating::class), 1), function ($carry, $level) use ($percentages) {
65
+			$label = $this->buildPercentageLabel($this->args['labels'][$level]);
66
+			$background = $this->buildPercentageBackground($percentages[$level]);
67
+			$count = apply_filters('site-reviews/summary/counts',
68
+				$percentages[$level],
69
+				$this->ratingCounts[$level]
70
+			);
71
+			$percent = $this->buildPercentageCount($count);
72
+			$value = $label.$background.$percent;
73
+			$value = apply_filters('site-reviews/summary/wrap/bar', $value, $this->args, [
74
+				'percent' => wp_strip_all_tags($count, true),
75
+				'rating' => $level,
76
+			]);
77
+			return $carry.glsr(Builder::class)->div($value, [
78
+				'class' => 'glsr-bar',
79
+			]);
80
+		});
81
+		return $this->wrap('percentage', $bars);
82
+	}
83
+
84
+	/**
85
+	 * @param string $percent
86
+	 * @return string
87
+	 */
88
+	protected function buildPercentageBackground($percent)
89
+	{
90
+		$backgroundPercent = glsr(Builder::class)->span([
91
+			'class' => 'glsr-bar-background-percent',
92
+			'style' => 'width:'.$percent,
93
+		]);
94
+		return '<span class="glsr-bar-background">'.$backgroundPercent.'</span>';
95
+	}
96
+
97
+	/**
98
+	 * @param string $count
99
+	 * @return string
100
+	 */
101
+	protected function buildPercentageCount($count)
102
+	{
103
+		return '<span class="glsr-bar-percent">'.$count.'</span>';
104
+	}
105
+
106
+	/**
107
+	 * @param string $label
108
+	 * @return string
109
+	 */
110
+	protected function buildPercentageLabel($label)
111
+	{
112
+		return '<span class="glsr-bar-label">'.$label.'</span>';
113
+	}
114
+
115
+	/**
116
+	 * @return void|string
117
+	 */
118
+	protected function buildRating()
119
+	{
120
+		if ($this->isHidden('rating')) {
121
+			return;
122
+		}
123
+		return $this->wrap('rating', '<span>'.$this->averageRating.'</span>');
124
+	}
125
+
126
+	/**
127
+	 * @return void|string
128
+	 */
129
+	protected function buildStars()
130
+	{
131
+		if ($this->isHidden('stars')) {
132
+			return;
133
+		}
134
+		$stars = glsr_star_rating($this->averageRating);
135
+		return $this->wrap('stars', $stars);
136
+	}
137
+
138
+	/**
139
+	 * @return void|string
140
+	 */
141
+	protected function buildText()
142
+	{
143
+		if ($this->isHidden('summary')) {
144
+			return;
145
+		}
146
+		$count = intval(array_sum($this->ratingCounts));
147
+		if (empty($this->args['text'])) {
148
+			// @todo document this change
149
+			$this->args['text'] = _nx(
150
+				'{rating} out of {max} stars (based on {num} review)',
151
+				'{rating} out of {max} stars (based on {num} reviews)',
152
+				$count,
153
+				'Do not translate {rating}, {max}, and {num}, they are template tags.',
154
+				'site-reviews'
155
+			);
156
+		}
157
+		$summary = str_replace(
158
+			['{rating}', '{max}', '{num}'],
159
+			[$this->averageRating, glsr()->constant('MAX_RATING', Rating::class), $count],
160
+			$this->args['text']
161
+		);
162
+		return $this->wrap('text', '<span>'.$summary.'</span>');
163
+	}
164
+
165
+	/**
166
+	 * @return void
167
+	 */
168
+	protected function generateSchema()
169
+	{
170
+		if (!wp_validate_boolean($this->args['schema'])) {
171
+			return;
172
+		}
173
+		glsr(Schema::class)->store(
174
+			glsr(Schema::class)->buildSummary($this->args)
175
+		);
176
+	}
177
+
178
+	/**
179
+	 * @return string
180
+	 */
181
+	protected function getClass()
182
+	{
183
+		return trim('glsr-summary '.$this->args['class']);
184
+	}
185
+
186
+	/**
187
+	 * @param string $key
188
+	 * @return bool
189
+	 */
190
+	protected function isHidden($key)
191
+	{
192
+		return in_array($key, $this->args['hide']);
193
+	}
194
+
195
+	/**
196
+	 * @param string $key
197
+	 * @param string $value
198
+	 * @return string
199
+	 */
200
+	protected function wrap($key, $value)
201
+	{
202
+		$value = apply_filters('site-reviews/summary/wrap/'.$key, $value, $this->args);
203
+		return glsr(Builder::class)->div($value, [
204
+			'class' => 'glsr-summary-'.$key,
205
+		]);
206
+	}
207 207
 }
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -29,16 +29,16 @@  discard block
 block discarded – undo
29 29
     /**
30 30
      * {@inheritdoc}
31 31
      */
32
-    public function build(array $args = [])
32
+    public function build( array $args = [] )
33 33
     {
34 34
         $this->args = $args;
35
-        $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($args);
36
-        if (!array_sum($this->ratingCounts) && $this->isHidden('if_empty')) {
35
+        $this->ratingCounts = glsr( ReviewManager::class )->getRatingCounts( $args );
36
+        if( !array_sum( $this->ratingCounts ) && $this->isHidden( 'if_empty' ) ) {
37 37
             return '';
38 38
         }
39
-        $this->averageRating = glsr(Rating::class)->getAverage($this->ratingCounts);
39
+        $this->averageRating = glsr( Rating::class )->getAverage( $this->ratingCounts );
40 40
         $this->generateSchema();
41
-        return glsr(Template::class)->build('templates/reviews-summary', [
41
+        return glsr( Template::class )->build( 'templates/reviews-summary', [
42 42
             'context' => [
43 43
                 'assigned_to' => $this->args['assigned_to'],
44 44
                 'category' => $this->args['category'],
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
                 'stars' => $this->buildStars(),
50 50
                 'text' => $this->buildText(),
51 51
             ],
52
-        ]);
52
+        ] );
53 53
     }
54 54
 
55 55
     /**
@@ -57,40 +57,40 @@  discard block
 block discarded – undo
57 57
      */
58 58
     protected function buildPercentage()
59 59
     {
60
-        if ($this->isHidden('bars')) {
60
+        if( $this->isHidden( 'bars' ) ) {
61 61
             return;
62 62
         }
63
-        $percentages = preg_filter('/$/', '%', glsr(Rating::class)->getPercentages($this->ratingCounts));
64
-        $bars = array_reduce(range(glsr()->constant('MAX_RATING', Rating::class), 1), function ($carry, $level) use ($percentages) {
65
-            $label = $this->buildPercentageLabel($this->args['labels'][$level]);
66
-            $background = $this->buildPercentageBackground($percentages[$level]);
67
-            $count = apply_filters('site-reviews/summary/counts',
63
+        $percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->ratingCounts ) );
64
+        $bars = array_reduce( range( glsr()->constant( 'MAX_RATING', Rating::class ), 1 ), function( $carry, $level ) use ($percentages) {
65
+            $label = $this->buildPercentageLabel( $this->args['labels'][$level] );
66
+            $background = $this->buildPercentageBackground( $percentages[$level] );
67
+            $count = apply_filters( 'site-reviews/summary/counts',
68 68
                 $percentages[$level],
69 69
                 $this->ratingCounts[$level]
70 70
             );
71
-            $percent = $this->buildPercentageCount($count);
71
+            $percent = $this->buildPercentageCount( $count );
72 72
             $value = $label.$background.$percent;
73
-            $value = apply_filters('site-reviews/summary/wrap/bar', $value, $this->args, [
74
-                'percent' => wp_strip_all_tags($count, true),
73
+            $value = apply_filters( 'site-reviews/summary/wrap/bar', $value, $this->args, [
74
+                'percent' => wp_strip_all_tags( $count, true ),
75 75
                 'rating' => $level,
76
-            ]);
77
-            return $carry.glsr(Builder::class)->div($value, [
76
+            ] );
77
+            return $carry.glsr( Builder::class )->div( $value, [
78 78
                 'class' => 'glsr-bar',
79
-            ]);
79
+            ] );
80 80
         });
81
-        return $this->wrap('percentage', $bars);
81
+        return $this->wrap( 'percentage', $bars );
82 82
     }
83 83
 
84 84
     /**
85 85
      * @param string $percent
86 86
      * @return string
87 87
      */
88
-    protected function buildPercentageBackground($percent)
88
+    protected function buildPercentageBackground( $percent )
89 89
     {
90
-        $backgroundPercent = glsr(Builder::class)->span([
90
+        $backgroundPercent = glsr( Builder::class )->span( [
91 91
             'class' => 'glsr-bar-background-percent',
92 92
             'style' => 'width:'.$percent,
93
-        ]);
93
+        ] );
94 94
         return '<span class="glsr-bar-background">'.$backgroundPercent.'</span>';
95 95
     }
96 96
 
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
      * @param string $count
99 99
      * @return string
100 100
      */
101
-    protected function buildPercentageCount($count)
101
+    protected function buildPercentageCount( $count )
102 102
     {
103 103
         return '<span class="glsr-bar-percent">'.$count.'</span>';
104 104
     }
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
      * @param string $label
108 108
      * @return string
109 109
      */
110
-    protected function buildPercentageLabel($label)
110
+    protected function buildPercentageLabel( $label )
111 111
     {
112 112
         return '<span class="glsr-bar-label">'.$label.'</span>';
113 113
     }
@@ -117,10 +117,10 @@  discard block
 block discarded – undo
117 117
      */
118 118
     protected function buildRating()
119 119
     {
120
-        if ($this->isHidden('rating')) {
120
+        if( $this->isHidden( 'rating' ) ) {
121 121
             return;
122 122
         }
123
-        return $this->wrap('rating', '<span>'.$this->averageRating.'</span>');
123
+        return $this->wrap( 'rating', '<span>'.$this->averageRating.'</span>' );
124 124
     }
125 125
 
126 126
     /**
@@ -128,11 +128,11 @@  discard block
 block discarded – undo
128 128
      */
129 129
     protected function buildStars()
130 130
     {
131
-        if ($this->isHidden('stars')) {
131
+        if( $this->isHidden( 'stars' ) ) {
132 132
             return;
133 133
         }
134
-        $stars = glsr_star_rating($this->averageRating);
135
-        return $this->wrap('stars', $stars);
134
+        $stars = glsr_star_rating( $this->averageRating );
135
+        return $this->wrap( 'stars', $stars );
136 136
     }
137 137
 
138 138
     /**
@@ -140,11 +140,11 @@  discard block
 block discarded – undo
140 140
      */
141 141
     protected function buildText()
142 142
     {
143
-        if ($this->isHidden('summary')) {
143
+        if( $this->isHidden( 'summary' ) ) {
144 144
             return;
145 145
         }
146
-        $count = intval(array_sum($this->ratingCounts));
147
-        if (empty($this->args['text'])) {
146
+        $count = intval( array_sum( $this->ratingCounts ) );
147
+        if( empty($this->args['text']) ) {
148 148
             // @todo document this change
149 149
             $this->args['text'] = _nx(
150 150
                 '{rating} out of {max} stars (based on {num} review)',
@@ -156,10 +156,10 @@  discard block
 block discarded – undo
156 156
         }
157 157
         $summary = str_replace(
158 158
             ['{rating}', '{max}', '{num}'],
159
-            [$this->averageRating, glsr()->constant('MAX_RATING', Rating::class), $count],
159
+            [$this->averageRating, glsr()->constant( 'MAX_RATING', Rating::class ), $count],
160 160
             $this->args['text']
161 161
         );
162
-        return $this->wrap('text', '<span>'.$summary.'</span>');
162
+        return $this->wrap( 'text', '<span>'.$summary.'</span>' );
163 163
     }
164 164
 
165 165
     /**
@@ -167,11 +167,11 @@  discard block
 block discarded – undo
167 167
      */
168 168
     protected function generateSchema()
169 169
     {
170
-        if (!wp_validate_boolean($this->args['schema'])) {
170
+        if( !wp_validate_boolean( $this->args['schema'] ) ) {
171 171
             return;
172 172
         }
173
-        glsr(Schema::class)->store(
174
-            glsr(Schema::class)->buildSummary($this->args)
173
+        glsr( Schema::class )->store(
174
+            glsr( Schema::class )->buildSummary( $this->args )
175 175
         );
176 176
     }
177 177
 
@@ -180,16 +180,16 @@  discard block
 block discarded – undo
180 180
      */
181 181
     protected function getClass()
182 182
     {
183
-        return trim('glsr-summary '.$this->args['class']);
183
+        return trim( 'glsr-summary '.$this->args['class'] );
184 184
     }
185 185
 
186 186
     /**
187 187
      * @param string $key
188 188
      * @return bool
189 189
      */
190
-    protected function isHidden($key)
190
+    protected function isHidden( $key )
191 191
     {
192
-        return in_array($key, $this->args['hide']);
192
+        return in_array( $key, $this->args['hide'] );
193 193
     }
194 194
 
195 195
     /**
@@ -197,11 +197,11 @@  discard block
 block discarded – undo
197 197
      * @param string $value
198 198
      * @return string
199 199
      */
200
-    protected function wrap($key, $value)
200
+    protected function wrap( $key, $value )
201 201
     {
202
-        $value = apply_filters('site-reviews/summary/wrap/'.$key, $value, $this->args);
203
-        return glsr(Builder::class)->div($value, [
202
+        $value = apply_filters( 'site-reviews/summary/wrap/'.$key, $value, $this->args );
203
+        return glsr( Builder::class )->div( $value, [
204 204
             'class' => 'glsr-summary-'.$key,
205
-        ]);
205
+        ] );
206 206
     }
207 207
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Partials/StarRating.php 2 patches
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -8,54 +8,54 @@
 block discarded – undo
8 8
 
9 9
 class StarRating implements PartialContract
10 10
 {
11
-    protected $prefix;
12
-    protected $rating;
11
+	protected $prefix;
12
+	protected $rating;
13 13
 
14
-    /**
15
-     * {@inheritdoc}
16
-     */
17
-    public function build(array $args = [])
18
-    {
19
-        $this->setProperties($args);
20
-        $fullStars = intval(floor($this->rating));
21
-        $halfStars = intval(ceil($this->rating - $fullStars));
22
-        $emptyStars = max(0, glsr()->constant('MAX_RATING', Rating::class) - $fullStars - $halfStars);
23
-        return glsr(Template::class)->build('templates/rating/stars', [
24
-            'context' => [
25
-                'empty_stars' => $this->getTemplate('empty-star', $emptyStars),
26
-                'full_stars' => $this->getTemplate('full-star', $fullStars),
27
-                'half_stars' => $this->getTemplate('half-star', $halfStars),
28
-                'prefix' => $this->prefix,
29
-                'title' => sprintf(__('%s rating', 'site-reviews'), number_format_i18n($this->rating, 1)),
30
-            ],
31
-        ]);
32
-    }
14
+	/**
15
+	 * {@inheritdoc}
16
+	 */
17
+	public function build(array $args = [])
18
+	{
19
+		$this->setProperties($args);
20
+		$fullStars = intval(floor($this->rating));
21
+		$halfStars = intval(ceil($this->rating - $fullStars));
22
+		$emptyStars = max(0, glsr()->constant('MAX_RATING', Rating::class) - $fullStars - $halfStars);
23
+		return glsr(Template::class)->build('templates/rating/stars', [
24
+			'context' => [
25
+				'empty_stars' => $this->getTemplate('empty-star', $emptyStars),
26
+				'full_stars' => $this->getTemplate('full-star', $fullStars),
27
+				'half_stars' => $this->getTemplate('half-star', $halfStars),
28
+				'prefix' => $this->prefix,
29
+				'title' => sprintf(__('%s rating', 'site-reviews'), number_format_i18n($this->rating, 1)),
30
+			],
31
+		]);
32
+	}
33 33
 
34
-    /**
35
-     * @param string $templateName
36
-     * @param int $timesRepeated
37
-     * @return string
38
-     */
39
-    protected function getTemplate($templateName, $timesRepeated)
40
-    {
41
-        $template = glsr(Template::class)->build('templates/rating/'.$templateName, [
42
-            'context' => [
43
-                'prefix' => $this->prefix,
44
-            ],
45
-        ]);
46
-        return str_repeat($template, $timesRepeated);
47
-    }
34
+	/**
35
+	 * @param string $templateName
36
+	 * @param int $timesRepeated
37
+	 * @return string
38
+	 */
39
+	protected function getTemplate($templateName, $timesRepeated)
40
+	{
41
+		$template = glsr(Template::class)->build('templates/rating/'.$templateName, [
42
+			'context' => [
43
+				'prefix' => $this->prefix,
44
+			],
45
+		]);
46
+		return str_repeat($template, $timesRepeated);
47
+	}
48 48
 
49
-    /**
50
-     * @return array
51
-     */
52
-    protected function setProperties(array $args)
53
-    {
54
-        $args = wp_parse_args($args, [
55
-            'prefix' => glsr()->isAdmin() ? '' : 'glsr-',
56
-            'rating' => 0,
57
-        ]);
58
-        $this->prefix = $args['prefix'];
59
-        $this->rating = (float) str_replace(',', '.', $args['rating']);
60
-    }
49
+	/**
50
+	 * @return array
51
+	 */
52
+	protected function setProperties(array $args)
53
+	{
54
+		$args = wp_parse_args($args, [
55
+			'prefix' => glsr()->isAdmin() ? '' : 'glsr-',
56
+			'rating' => 0,
57
+		]);
58
+		$this->prefix = $args['prefix'];
59
+		$this->rating = (float) str_replace(',', '.', $args['rating']);
60
+	}
61 61
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -14,21 +14,21 @@  discard block
 block discarded – undo
14 14
     /**
15 15
      * {@inheritdoc}
16 16
      */
17
-    public function build(array $args = [])
17
+    public function build( array $args = [] )
18 18
     {
19
-        $this->setProperties($args);
20
-        $fullStars = intval(floor($this->rating));
21
-        $halfStars = intval(ceil($this->rating - $fullStars));
22
-        $emptyStars = max(0, glsr()->constant('MAX_RATING', Rating::class) - $fullStars - $halfStars);
23
-        return glsr(Template::class)->build('templates/rating/stars', [
19
+        $this->setProperties( $args );
20
+        $fullStars = intval( floor( $this->rating ) );
21
+        $halfStars = intval( ceil( $this->rating - $fullStars ) );
22
+        $emptyStars = max( 0, glsr()->constant( 'MAX_RATING', Rating::class ) - $fullStars - $halfStars );
23
+        return glsr( Template::class )->build( 'templates/rating/stars', [
24 24
             'context' => [
25
-                'empty_stars' => $this->getTemplate('empty-star', $emptyStars),
26
-                'full_stars' => $this->getTemplate('full-star', $fullStars),
27
-                'half_stars' => $this->getTemplate('half-star', $halfStars),
25
+                'empty_stars' => $this->getTemplate( 'empty-star', $emptyStars ),
26
+                'full_stars' => $this->getTemplate( 'full-star', $fullStars ),
27
+                'half_stars' => $this->getTemplate( 'half-star', $halfStars ),
28 28
                 'prefix' => $this->prefix,
29
-                'title' => sprintf(__('%s rating', 'site-reviews'), number_format_i18n($this->rating, 1)),
29
+                'title' => sprintf( __( '%s rating', 'site-reviews' ), number_format_i18n( $this->rating, 1 ) ),
30 30
             ],
31
-        ]);
31
+        ] );
32 32
     }
33 33
 
34 34
     /**
@@ -36,26 +36,26 @@  discard block
 block discarded – undo
36 36
      * @param int $timesRepeated
37 37
      * @return string
38 38
      */
39
-    protected function getTemplate($templateName, $timesRepeated)
39
+    protected function getTemplate( $templateName, $timesRepeated )
40 40
     {
41
-        $template = glsr(Template::class)->build('templates/rating/'.$templateName, [
41
+        $template = glsr( Template::class )->build( 'templates/rating/'.$templateName, [
42 42
             'context' => [
43 43
                 'prefix' => $this->prefix,
44 44
             ],
45
-        ]);
46
-        return str_repeat($template, $timesRepeated);
45
+        ] );
46
+        return str_repeat( $template, $timesRepeated );
47 47
     }
48 48
 
49 49
     /**
50 50
      * @return array
51 51
      */
52
-    protected function setProperties(array $args)
52
+    protected function setProperties( array $args )
53 53
     {
54
-        $args = wp_parse_args($args, [
54
+        $args = wp_parse_args( $args, [
55 55
             'prefix' => glsr()->isAdmin() ? '' : 'glsr-',
56 56
             'rating' => 0,
57
-        ]);
57
+        ] );
58 58
         $this->prefix = $args['prefix'];
59
-        $this->rating = (float) str_replace(',', '.', $args['rating']);
59
+        $this->rating = (float)str_replace( ',', '.', $args['rating'] );
60 60
     }
61 61
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Partial.php 2 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -6,31 +6,31 @@
 block discarded – undo
6 6
 
7 7
 class Partial
8 8
 {
9
-    /**
10
-     * @param string $partialPath
11
-     * @return string
12
-     */
13
-    public function build($partialPath, array $args = [])
14
-    {
15
-        $className = Helper::buildClassName($partialPath, 'Modules\Html\Partials');
16
-        $className = apply_filters('site-reviews/partial/classname', $className, $partialPath);
17
-        if (!class_exists($className)) {
18
-            glsr_log()->error('Partial missing: '.$className);
19
-            return;
20
-        }
21
-        $args = apply_filters('site-reviews/partial/args/'.$partialPath, $args);
22
-        $partial = glsr($className)->build($args);
23
-        $partial = apply_filters('site-reviews/rendered/partial', $partial, $partialPath, $args);
24
-        $partial = apply_filters('site-reviews/rendered/partial/'.$partialPath, $partial, $args);
25
-        return $partial;
26
-    }
9
+	/**
10
+	 * @param string $partialPath
11
+	 * @return string
12
+	 */
13
+	public function build($partialPath, array $args = [])
14
+	{
15
+		$className = Helper::buildClassName($partialPath, 'Modules\Html\Partials');
16
+		$className = apply_filters('site-reviews/partial/classname', $className, $partialPath);
17
+		if (!class_exists($className)) {
18
+			glsr_log()->error('Partial missing: '.$className);
19
+			return;
20
+		}
21
+		$args = apply_filters('site-reviews/partial/args/'.$partialPath, $args);
22
+		$partial = glsr($className)->build($args);
23
+		$partial = apply_filters('site-reviews/rendered/partial', $partial, $partialPath, $args);
24
+		$partial = apply_filters('site-reviews/rendered/partial/'.$partialPath, $partial, $args);
25
+		return $partial;
26
+	}
27 27
 
28
-    /**
29
-     * @param string $partialPath
30
-     * @return void
31
-     */
32
-    public function render($partialPath, array $args = [])
33
-    {
34
-        echo $this->build($partialPath, $args);
35
-    }
28
+	/**
29
+	 * @param string $partialPath
30
+	 * @return void
31
+	 */
32
+	public function render($partialPath, array $args = [])
33
+	{
34
+		echo $this->build($partialPath, $args);
35
+	}
36 36
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -10,18 +10,18 @@  discard block
 block discarded – undo
10 10
      * @param string $partialPath
11 11
      * @return string
12 12
      */
13
-    public function build($partialPath, array $args = [])
13
+    public function build( $partialPath, array $args = [] )
14 14
     {
15
-        $className = Helper::buildClassName($partialPath, 'Modules\Html\Partials');
16
-        $className = apply_filters('site-reviews/partial/classname', $className, $partialPath);
17
-        if (!class_exists($className)) {
18
-            glsr_log()->error('Partial missing: '.$className);
15
+        $className = Helper::buildClassName( $partialPath, 'Modules\Html\Partials' );
16
+        $className = apply_filters( 'site-reviews/partial/classname', $className, $partialPath );
17
+        if( !class_exists( $className ) ) {
18
+            glsr_log()->error( 'Partial missing: '.$className );
19 19
             return;
20 20
         }
21
-        $args = apply_filters('site-reviews/partial/args/'.$partialPath, $args);
22
-        $partial = glsr($className)->build($args);
23
-        $partial = apply_filters('site-reviews/rendered/partial', $partial, $partialPath, $args);
24
-        $partial = apply_filters('site-reviews/rendered/partial/'.$partialPath, $partial, $args);
21
+        $args = apply_filters( 'site-reviews/partial/args/'.$partialPath, $args );
22
+        $partial = glsr( $className )->build( $args );
23
+        $partial = apply_filters( 'site-reviews/rendered/partial', $partial, $partialPath, $args );
24
+        $partial = apply_filters( 'site-reviews/rendered/partial/'.$partialPath, $partial, $args );
25 25
         return $partial;
26 26
     }
27 27
 
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
      * @param string $partialPath
30 30
      * @return void
31 31
      */
32
-    public function render($partialPath, array $args = [])
32
+    public function render( $partialPath, array $args = [] )
33 33
     {
34
-        echo $this->build($partialPath, $args);
34
+        echo $this->build( $partialPath, $args );
35 35
     }
36 36
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/ReviewsHtml.php 2 patches
Indentation   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -8,137 +8,137 @@
 block discarded – undo
8 8
 
9 9
 class ReviewsHtml extends ArrayObject
10 10
 {
11
-    /**
12
-     * @var array
13
-     */
14
-    public $args;
11
+	/**
12
+	 * @var array
13
+	 */
14
+	public $args;
15 15
 
16
-    /**
17
-     * @var int
18
-     */
19
-    public $max_num_pages;
16
+	/**
17
+	 * @var int
18
+	 */
19
+	public $max_num_pages;
20 20
 
21
-    /**
22
-     * @var string
23
-     */
24
-    public $pagination;
21
+	/**
22
+	 * @var string
23
+	 */
24
+	public $pagination;
25 25
 
26
-    /**
27
-     * @var array
28
-     */
29
-    public $reviews;
26
+	/**
27
+	 * @var array
28
+	 */
29
+	public $reviews;
30 30
 
31
-    public function __construct(array $renderedReviews, $maxPageCount, array $args)
32
-    {
33
-        $this->args = $args;
34
-        $this->max_num_pages = $maxPageCount;
35
-        $this->reviews = $renderedReviews;
36
-        $this->pagination = $this->buildPagination();
37
-        parent::__construct($renderedReviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
38
-    }
31
+	public function __construct(array $renderedReviews, $maxPageCount, array $args)
32
+	{
33
+		$this->args = $args;
34
+		$this->max_num_pages = $maxPageCount;
35
+		$this->reviews = $renderedReviews;
36
+		$this->pagination = $this->buildPagination();
37
+		parent::__construct($renderedReviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
38
+	}
39 39
 
40
-    /**
41
-     * @return string
42
-     */
43
-    public function __toString()
44
-    {
45
-        return glsr(Template::class)->build('templates/reviews', [
46
-            'args' => $this->args,
47
-            'context' => [
48
-                'assigned_to' => $this->args['assigned_to'],
49
-                'category' => $this->args['category'],
50
-                'class' => $this->getClass(),
51
-                'id' => $this->args['id'],
52
-                'pagination' => $this->getPagination(),
53
-                'reviews' => $this->getReviews(),
54
-            ],
55
-        ]);
56
-    }
40
+	/**
41
+	 * @return string
42
+	 */
43
+	public function __toString()
44
+	{
45
+		return glsr(Template::class)->build('templates/reviews', [
46
+			'args' => $this->args,
47
+			'context' => [
48
+				'assigned_to' => $this->args['assigned_to'],
49
+				'category' => $this->args['category'],
50
+				'class' => $this->getClass(),
51
+				'id' => $this->args['id'],
52
+				'pagination' => $this->getPagination(),
53
+				'reviews' => $this->getReviews(),
54
+			],
55
+		]);
56
+	}
57 57
 
58
-    /**
59
-     * @return string
60
-     */
61
-    public function getPagination()
62
-    {
63
-        return wp_validate_boolean($this->args['pagination'])
64
-            ? $this->pagination
65
-            : '';
66
-    }
58
+	/**
59
+	 * @return string
60
+	 */
61
+	public function getPagination()
62
+	{
63
+		return wp_validate_boolean($this->args['pagination'])
64
+			? $this->pagination
65
+			: '';
66
+	}
67 67
 
68
-    /**
69
-     * @return string
70
-     */
71
-    public function getReviews()
72
-    {
73
-        $html = empty($this->reviews)
74
-            ? $this->getReviewsFallback()
75
-            : implode(PHP_EOL, $this->reviews);
76
-        return glsr(Builder::class)->div($html, [
77
-            'class' => 'glsr-reviews-list',
78
-            'data-reviews' => '',
79
-        ]);
80
-    }
68
+	/**
69
+	 * @return string
70
+	 */
71
+	public function getReviews()
72
+	{
73
+		$html = empty($this->reviews)
74
+			? $this->getReviewsFallback()
75
+			: implode(PHP_EOL, $this->reviews);
76
+		return glsr(Builder::class)->div($html, [
77
+			'class' => 'glsr-reviews-list',
78
+			'data-reviews' => '',
79
+		]);
80
+	}
81 81
 
82
-    /**
83
-     * @param mixed $key
84
-     * @return mixed
85
-     */
86
-    public function offsetGet($key)
87
-    {
88
-        if ('navigation' == $key) {
89
-            glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.';
90
-            return $this->pagination;
91
-        }
92
-        if (array_key_exists($key, $this->reviews)) {
93
-            return $this->reviews[$key];
94
-        }
95
-        return property_exists($this, $key)
96
-            ? $this->$key
97
-            : null;
98
-    }
82
+	/**
83
+	 * @param mixed $key
84
+	 * @return mixed
85
+	 */
86
+	public function offsetGet($key)
87
+	{
88
+		if ('navigation' == $key) {
89
+			glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.';
90
+			return $this->pagination;
91
+		}
92
+		if (array_key_exists($key, $this->reviews)) {
93
+			return $this->reviews[$key];
94
+		}
95
+		return property_exists($this, $key)
96
+			? $this->$key
97
+			: null;
98
+	}
99 99
 
100
-    /**
101
-     * @return string
102
-     */
103
-    protected function buildPagination()
104
-    {
105
-        $html = glsr(Partial::class)->build('pagination', [
106
-            'baseUrl' => Arr::get($this->args, 'pagedUrl'),
107
-            'current' => Arr::get($this->args, 'paged'),
108
-            'total' => $this->max_num_pages,
109
-        ]);
110
-        return glsr(Builder::class)->div($html, [
111
-            'class' => 'glsr-pagination',
112
-            'data-atts' => $this->args['json'],
113
-            'data-pagination' => '',
114
-        ]);
115
-    }
100
+	/**
101
+	 * @return string
102
+	 */
103
+	protected function buildPagination()
104
+	{
105
+		$html = glsr(Partial::class)->build('pagination', [
106
+			'baseUrl' => Arr::get($this->args, 'pagedUrl'),
107
+			'current' => Arr::get($this->args, 'paged'),
108
+			'total' => $this->max_num_pages,
109
+		]);
110
+		return glsr(Builder::class)->div($html, [
111
+			'class' => 'glsr-pagination',
112
+			'data-atts' => $this->args['json'],
113
+			'data-pagination' => '',
114
+		]);
115
+	}
116 116
 
117
-    /**
118
-     * @return string
119
-     */
120
-    protected function getClass()
121
-    {
122
-        $defaults = [
123
-            'glsr-reviews',
124
-        ];
125
-        if ('ajax' == $this->args['pagination']) {
126
-            $defaults[] = 'glsr-ajax-pagination';
127
-        }
128
-        $classes = explode(' ', $this->args['class']);
129
-        $classes = array_unique(array_merge($defaults, array_filter($classes)));
130
-        return implode(' ', $classes);
131
-    }
117
+	/**
118
+	 * @return string
119
+	 */
120
+	protected function getClass()
121
+	{
122
+		$defaults = [
123
+			'glsr-reviews',
124
+		];
125
+		if ('ajax' == $this->args['pagination']) {
126
+			$defaults[] = 'glsr-ajax-pagination';
127
+		}
128
+		$classes = explode(' ', $this->args['class']);
129
+		$classes = array_unique(array_merge($defaults, array_filter($classes)));
130
+		return implode(' ', $classes);
131
+	}
132 132
 
133
-    /**
134
-     * @return string
135
-     */
136
-    protected function getReviewsFallback()
137
-    {
138
-        if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) {
139
-            $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews');
140
-        }
141
-        $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>';
142
-        return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args);
143
-    }
133
+	/**
134
+	 * @return string
135
+	 */
136
+	protected function getReviewsFallback()
137
+	{
138
+		if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) {
139
+			$this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews');
140
+		}
141
+		$fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>';
142
+		return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args);
143
+	}
144 144
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -28,13 +28,13 @@  discard block
 block discarded – undo
28 28
      */
29 29
     public $reviews;
30 30
 
31
-    public function __construct(array $renderedReviews, $maxPageCount, array $args)
31
+    public function __construct( array $renderedReviews, $maxPageCount, array $args )
32 32
     {
33 33
         $this->args = $args;
34 34
         $this->max_num_pages = $maxPageCount;
35 35
         $this->reviews = $renderedReviews;
36 36
         $this->pagination = $this->buildPagination();
37
-        parent::__construct($renderedReviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
37
+        parent::__construct( $renderedReviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS );
38 38
     }
39 39
 
40 40
     /**
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public function __toString()
44 44
     {
45
-        return glsr(Template::class)->build('templates/reviews', [
45
+        return glsr( Template::class )->build( 'templates/reviews', [
46 46
             'args' => $this->args,
47 47
             'context' => [
48 48
                 'assigned_to' => $this->args['assigned_to'],
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
                 'pagination' => $this->getPagination(),
53 53
                 'reviews' => $this->getReviews(),
54 54
             ],
55
-        ]);
55
+        ] );
56 56
     }
57 57
 
58 58
     /**
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      */
61 61
     public function getPagination()
62 62
     {
63
-        return wp_validate_boolean($this->args['pagination'])
63
+        return wp_validate_boolean( $this->args['pagination'] )
64 64
             ? $this->pagination
65 65
             : '';
66 66
     }
@@ -72,27 +72,27 @@  discard block
 block discarded – undo
72 72
     {
73 73
         $html = empty($this->reviews)
74 74
             ? $this->getReviewsFallback()
75
-            : implode(PHP_EOL, $this->reviews);
76
-        return glsr(Builder::class)->div($html, [
75
+            : implode( PHP_EOL, $this->reviews );
76
+        return glsr( Builder::class )->div( $html, [
77 77
             'class' => 'glsr-reviews-list',
78 78
             'data-reviews' => '',
79
-        ]);
79
+        ] );
80 80
     }
81 81
 
82 82
     /**
83 83
      * @param mixed $key
84 84
      * @return mixed
85 85
      */
86
-    public function offsetGet($key)
86
+    public function offsetGet( $key )
87 87
     {
88
-        if ('navigation' == $key) {
88
+        if( 'navigation' == $key ) {
89 89
             glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.';
90 90
             return $this->pagination;
91 91
         }
92
-        if (array_key_exists($key, $this->reviews)) {
92
+        if( array_key_exists( $key, $this->reviews ) ) {
93 93
             return $this->reviews[$key];
94 94
         }
95
-        return property_exists($this, $key)
95
+        return property_exists( $this, $key )
96 96
             ? $this->$key
97 97
             : null;
98 98
     }
@@ -102,16 +102,16 @@  discard block
 block discarded – undo
102 102
      */
103 103
     protected function buildPagination()
104 104
     {
105
-        $html = glsr(Partial::class)->build('pagination', [
106
-            'baseUrl' => Arr::get($this->args, 'pagedUrl'),
107
-            'current' => Arr::get($this->args, 'paged'),
105
+        $html = glsr( Partial::class )->build( 'pagination', [
106
+            'baseUrl' => Arr::get( $this->args, 'pagedUrl' ),
107
+            'current' => Arr::get( $this->args, 'paged' ),
108 108
             'total' => $this->max_num_pages,
109
-        ]);
110
-        return glsr(Builder::class)->div($html, [
109
+        ] );
110
+        return glsr( Builder::class )->div( $html, [
111 111
             'class' => 'glsr-pagination',
112 112
             'data-atts' => $this->args['json'],
113 113
             'data-pagination' => '',
114
-        ]);
114
+        ] );
115 115
     }
116 116
 
117 117
     /**
@@ -122,12 +122,12 @@  discard block
 block discarded – undo
122 122
         $defaults = [
123 123
             'glsr-reviews',
124 124
         ];
125
-        if ('ajax' == $this->args['pagination']) {
125
+        if( 'ajax' == $this->args['pagination'] ) {
126 126
             $defaults[] = 'glsr-ajax-pagination';
127 127
         }
128
-        $classes = explode(' ', $this->args['class']);
129
-        $classes = array_unique(array_merge($defaults, array_filter($classes)));
130
-        return implode(' ', $classes);
128
+        $classes = explode( ' ', $this->args['class'] );
129
+        $classes = array_unique( array_merge( $defaults, array_filter( $classes ) ) );
130
+        return implode( ' ', $classes );
131 131
     }
132 132
 
133 133
     /**
@@ -135,10 +135,10 @@  discard block
 block discarded – undo
135 135
      */
136 136
     protected function getReviewsFallback()
137 137
     {
138
-        if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) {
139
-            $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews');
138
+        if( empty($this->args['fallback']) && glsr( OptionManager::class )->getBool( 'settings.reviews.fallback' ) ) {
139
+            $this->args['fallback'] = __( 'There are no reviews yet. Be the first one to write one.', 'site-reviews' );
140 140
         }
141 141
         $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>';
142
-        return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args);
142
+        return apply_filters( 'site-reviews/reviews/fallback', $fallback, $this->args );
143 143
     }
144 144
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Builder.php 3 patches
Indentation   +339 added lines, -339 removed lines patch added patch discarded remove patch
@@ -19,343 +19,343 @@
 block discarded – undo
19 19
  */
20 20
 class Builder
21 21
 {
22
-    const INPUT_TYPES = [
23
-        'checkbox', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', 'month',
24
-        'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', 'time',
25
-        'url', 'week',
26
-    ];
27
-
28
-    const TAGS_FORM = [
29
-        'input', 'select', 'textarea',
30
-    ];
31
-
32
-    const TAGS_SINGLE = [
33
-        'img',
34
-    ];
35
-
36
-    const TAGS_STRUCTURE = [
37
-        'div', 'form', 'nav', 'ol', 'section', 'ul',
38
-    ];
39
-
40
-    const TAGS_TEXT = [
41
-        'a', 'button', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'i', 'label', 'li', 'option', 'p', 'pre',
42
-        'small', 'span',
43
-    ];
44
-
45
-    /**
46
-     * @var array
47
-     */
48
-    public $args = [];
49
-
50
-    /**
51
-     * @var bool
52
-     */
53
-    public $render = false;
54
-
55
-    /**
56
-     * @var string
57
-     */
58
-    public $tag;
59
-
60
-    /**
61
-     * @param string $method
62
-     * @param array $args
63
-     * @return string|void
64
-     */
65
-    public function __call($method, $args)
66
-    {
67
-        $instance = new static();
68
-        $instance->setTagFromMethod($method);
69
-        call_user_func_array([$instance, 'normalize'], $args);
70
-        $tags = array_merge(static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT);
71
-        do_action_ref_array('site-reviews/builder', [$instance]);
72
-        $generatedTag = in_array($instance->tag, $tags)
73
-            ? $instance->buildTag()
74
-            : $instance->buildCustomField();
75
-        $generatedTag = apply_filters('site-reviews/builder/result', $generatedTag, $instance);
76
-        if (!$this->render) {
77
-            return $generatedTag;
78
-        }
79
-        echo $generatedTag;
80
-    }
81
-
82
-    /**
83
-     * @param string $property
84
-     * @param mixed $value
85
-     * @return void
86
-     */
87
-    public function __set($property, $value)
88
-    {
89
-        $properties = [
90
-            'args' => 'is_array',
91
-            'render' => 'is_bool',
92
-            'tag' => 'is_string',
93
-        ];
94
-        if (array_key_exists($property, $properties) && !empty($value)) {
95
-            $this->$property = $value;
96
-        }
97
-    }
98
-
99
-    /**
100
-     * @return void|string
101
-     */
102
-    public function getClosingTag()
103
-    {
104
-        if (!empty($this->tag)) {
105
-            return '</'.$this->tag.'>';
106
-        }
107
-    }
108
-
109
-    /**
110
-     * @return void|string
111
-     */
112
-    public function getOpeningTag()
113
-    {
114
-        if (!empty($this->tag)) {
115
-            $attributes = glsr(Attributes::class)->{$this->tag}($this->args)->toString();
116
-            return '<'.trim($this->tag.' '.$attributes).'>';
117
-        }
118
-    }
119
-
120
-    /**
121
-     * @return void|string
122
-     */
123
-    public function getTag()
124
-    {
125
-        if (in_array($this->tag, static::TAGS_SINGLE)) {
126
-            return $this->getOpeningTag();
127
-        }
128
-        if (!in_array($this->tag, static::TAGS_FORM)) {
129
-            return $this->buildDefaultTag();
130
-        }
131
-        return call_user_func([$this, 'buildForm'.ucfirst($this->tag)]).$this->buildFieldDescription();
132
-    }
133
-
134
-    /**
135
-     * @return string
136
-     */
137
-    public function raw(array $field)
138
-    {
139
-        unset($field['label']);
140
-        return $this->{$field['type']}($field);
141
-    }
142
-
143
-    /**
144
-     * @return string|void
145
-     */
146
-    protected function buildCustomField()
147
-    {
148
-        $className = $this->getCustomFieldClassName();
149
-        if (class_exists($className)) {
150
-            return (new $className($this))->build();
151
-        }
152
-        glsr_log()->error('Field class missing: '.$className);
153
-    }
154
-
155
-    /**
156
-     * @return string|void
157
-     */
158
-    protected function buildDefaultTag($text = '')
159
-    {
160
-        if (empty($text)) {
161
-            $text = $this->args['text'];
162
-        }
163
-        return $this->getOpeningTag().$text.$this->getClosingTag();
164
-    }
165
-
166
-    /**
167
-     * @return string|void
168
-     */
169
-    protected function buildFieldDescription()
170
-    {
171
-        if (empty($this->args['description'])) {
172
-            return;
173
-        }
174
-        if ($this->args['is_widget']) {
175
-            return $this->small($this->args['description']);
176
-        }
177
-        return $this->p($this->args['description'], ['class' => 'description']);
178
-    }
179
-
180
-    /**
181
-     * @return string|void
182
-     */
183
-    protected function buildFormInput()
184
-    {
185
-        if (!in_array($this->args['type'], ['checkbox', 'radio'])) {
186
-            if (isset($this->args['multiple'])) {
187
-                $this->args['name'] .= '[]';
188
-            }
189
-            return $this->buildFormLabel().$this->getOpeningTag();
190
-        }
191
-        return empty($this->args['options'])
192
-            ? $this->buildFormInputChoice()
193
-            : $this->buildFormInputMultiChoice();
194
-    }
195
-
196
-    /**
197
-     * @return string|void
198
-     */
199
-    protected function buildFormInputChoice()
200
-    {
201
-        if (!empty($this->args['text'])) {
202
-            $this->args['label'] = $this->args['text'];
203
-        }
204
-        if (!$this->args['is_public']) {
205
-            return $this->buildFormLabel([
206
-                'class' => 'glsr-'.$this->args['type'].'-label',
207
-                'text' => $this->getOpeningTag().' '.$this->args['label'].'<span></span>',
208
-            ]);
209
-        }
210
-        return $this->getOpeningTag().$this->buildFormLabel([
211
-            'class' => 'glsr-'.$this->args['type'].'-label',
212
-            'text' => $this->args['label'].'<span></span>',
213
-        ]);
214
-    }
215
-
216
-    /**
217
-     * @return string|void
218
-     */
219
-    protected function buildFormInputMultiChoice()
220
-    {
221
-        if ('checkbox' == $this->args['type']) {
222
-            $this->args['name'] .= '[]';
223
-        }
224
-        $index = 0;
225
-        $options = array_reduce(array_keys($this->args['options']), function ($carry, $key) use (&$index) {
226
-            return $carry.$this->li($this->{$this->args['type']}([
227
-                'checked' => in_array($key, (array) $this->args['value']),
228
-                'id' => $this->args['id'].'-'.$index++,
229
-                'name' => $this->args['name'],
230
-                'text' => $this->args['options'][$key],
231
-                'value' => $key,
232
-            ]));
233
-        });
234
-        return $this->ul($options, [
235
-            'class' => $this->args['class'],
236
-            'id' => $this->args['id'],
237
-        ]);
238
-    }
239
-
240
-    /**
241
-     * @return void|string
242
-     */
243
-    protected function buildFormLabel(array $customArgs = [])
244
-    {
245
-        if (empty($this->args['label']) || 'hidden' == $this->args['type']) {
246
-            return;
247
-        }
248
-        return $this->label(wp_parse_args($customArgs, [
249
-            'for' => $this->args['id'],
250
-            'is_public' => $this->args['is_public'],
251
-            'text' => $this->args['label'],
252
-            'type' => $this->args['type'],
253
-        ]));
254
-    }
255
-
256
-    /**
257
-     * @return string|void
258
-     */
259
-    protected function buildFormSelect()
260
-    {
261
-        return $this->buildFormLabel().$this->buildDefaultTag($this->buildFormSelectOptions());
262
-    }
263
-
264
-    /**
265
-     * @return string|void
266
-     */
267
-    protected function buildFormSelectOptions()
268
-    {
269
-        return array_reduce(array_keys($this->args['options']), function ($carry, $key) {
270
-            return $carry.$this->option([
271
-                'selected' => $this->args['value'] === (string) $key,
272
-                'text' => $this->args['options'][$key],
273
-                'value' => $key,
274
-            ]);
275
-        });
276
-    }
277
-
278
-    /**
279
-     * @return string|void
280
-     */
281
-    protected function buildFormTextarea()
282
-    {
283
-        return $this->buildFormLabel().$this->buildDefaultTag($this->args['value']);
284
-    }
285
-
286
-    /**
287
-     * @return string|void
288
-     */
289
-    protected function buildTag()
290
-    {
291
-        $this->mergeArgsWithRequiredDefaults();
292
-        return $this->getTag();
293
-    }
294
-
295
-    /**
296
-     * @return string
297
-     */
298
-    protected function getCustomFieldClassName()
299
-    {
300
-        $classname = Helper::buildClassName($this->tag, __NAMESPACE__.'\Fields');
301
-        return apply_filters('site-reviews/builder/field/'.$this->tag, $classname);
302
-    }
303
-
304
-    /**
305
-     * @return void
306
-     */
307
-    protected function mergeArgsWithRequiredDefaults()
308
-    {
309
-        $className = $this->getCustomFieldClassName();
310
-        if (class_exists($className)) {
311
-            $this->args = $className::merge($this->args);
312
-        }
313
-        $this->args = glsr(BuilderDefaults::class)->merge($this->args);
314
-    }
315
-
316
-    /**
317
-     * @param string|array ...$params
318
-     * @return void
319
-     */
320
-    protected function normalize(...$params)
321
-    {
322
-        $parameter1 = Arr::get($params, 0);
323
-        $parameter2 = Arr::get($params, 1);
324
-        if (is_string($parameter1) || is_numeric($parameter1)) {
325
-            $this->setNameOrTextAttributeForTag($parameter1);
326
-        }
327
-        if (is_array($parameter1)) {
328
-            $this->args += $parameter1;
329
-        } elseif (is_array($parameter2)) {
330
-            $this->args += $parameter2;
331
-        }
332
-        if (!isset($this->args['is_public'])) {
333
-            $this->args['is_public'] = false;
334
-        }
335
-    }
336
-
337
-    /**
338
-     * @param string $value
339
-     * @return void
340
-     */
341
-    protected function setNameOrTextAttributeForTag($value)
342
-    {
343
-        $attribute = in_array($this->tag, static::TAGS_FORM)
344
-            ? 'name'
345
-            : 'text';
346
-        $this->args[$attribute] = $value;
347
-    }
348
-
349
-    /**
350
-     * @param string $method
351
-     * @return void
352
-     */
353
-    protected function setTagFromMethod($method)
354
-    {
355
-        $this->tag = strtolower($method);
356
-        if (in_array($this->tag, static::INPUT_TYPES)) {
357
-            $this->args['type'] = $this->tag;
358
-            $this->tag = 'input';
359
-        }
360
-    }
22
+	const INPUT_TYPES = [
23
+		'checkbox', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', 'month',
24
+		'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', 'time',
25
+		'url', 'week',
26
+	];
27
+
28
+	const TAGS_FORM = [
29
+		'input', 'select', 'textarea',
30
+	];
31
+
32
+	const TAGS_SINGLE = [
33
+		'img',
34
+	];
35
+
36
+	const TAGS_STRUCTURE = [
37
+		'div', 'form', 'nav', 'ol', 'section', 'ul',
38
+	];
39
+
40
+	const TAGS_TEXT = [
41
+		'a', 'button', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'i', 'label', 'li', 'option', 'p', 'pre',
42
+		'small', 'span',
43
+	];
44
+
45
+	/**
46
+	 * @var array
47
+	 */
48
+	public $args = [];
49
+
50
+	/**
51
+	 * @var bool
52
+	 */
53
+	public $render = false;
54
+
55
+	/**
56
+	 * @var string
57
+	 */
58
+	public $tag;
59
+
60
+	/**
61
+	 * @param string $method
62
+	 * @param array $args
63
+	 * @return string|void
64
+	 */
65
+	public function __call($method, $args)
66
+	{
67
+		$instance = new static();
68
+		$instance->setTagFromMethod($method);
69
+		call_user_func_array([$instance, 'normalize'], $args);
70
+		$tags = array_merge(static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT);
71
+		do_action_ref_array('site-reviews/builder', [$instance]);
72
+		$generatedTag = in_array($instance->tag, $tags)
73
+			? $instance->buildTag()
74
+			: $instance->buildCustomField();
75
+		$generatedTag = apply_filters('site-reviews/builder/result', $generatedTag, $instance);
76
+		if (!$this->render) {
77
+			return $generatedTag;
78
+		}
79
+		echo $generatedTag;
80
+	}
81
+
82
+	/**
83
+	 * @param string $property
84
+	 * @param mixed $value
85
+	 * @return void
86
+	 */
87
+	public function __set($property, $value)
88
+	{
89
+		$properties = [
90
+			'args' => 'is_array',
91
+			'render' => 'is_bool',
92
+			'tag' => 'is_string',
93
+		];
94
+		if (array_key_exists($property, $properties) && !empty($value)) {
95
+			$this->$property = $value;
96
+		}
97
+	}
98
+
99
+	/**
100
+	 * @return void|string
101
+	 */
102
+	public function getClosingTag()
103
+	{
104
+		if (!empty($this->tag)) {
105
+			return '</'.$this->tag.'>';
106
+		}
107
+	}
108
+
109
+	/**
110
+	 * @return void|string
111
+	 */
112
+	public function getOpeningTag()
113
+	{
114
+		if (!empty($this->tag)) {
115
+			$attributes = glsr(Attributes::class)->{$this->tag}($this->args)->toString();
116
+			return '<'.trim($this->tag.' '.$attributes).'>';
117
+		}
118
+	}
119
+
120
+	/**
121
+	 * @return void|string
122
+	 */
123
+	public function getTag()
124
+	{
125
+		if (in_array($this->tag, static::TAGS_SINGLE)) {
126
+			return $this->getOpeningTag();
127
+		}
128
+		if (!in_array($this->tag, static::TAGS_FORM)) {
129
+			return $this->buildDefaultTag();
130
+		}
131
+		return call_user_func([$this, 'buildForm'.ucfirst($this->tag)]).$this->buildFieldDescription();
132
+	}
133
+
134
+	/**
135
+	 * @return string
136
+	 */
137
+	public function raw(array $field)
138
+	{
139
+		unset($field['label']);
140
+		return $this->{$field['type']}($field);
141
+	}
142
+
143
+	/**
144
+	 * @return string|void
145
+	 */
146
+	protected function buildCustomField()
147
+	{
148
+		$className = $this->getCustomFieldClassName();
149
+		if (class_exists($className)) {
150
+			return (new $className($this))->build();
151
+		}
152
+		glsr_log()->error('Field class missing: '.$className);
153
+	}
154
+
155
+	/**
156
+	 * @return string|void
157
+	 */
158
+	protected function buildDefaultTag($text = '')
159
+	{
160
+		if (empty($text)) {
161
+			$text = $this->args['text'];
162
+		}
163
+		return $this->getOpeningTag().$text.$this->getClosingTag();
164
+	}
165
+
166
+	/**
167
+	 * @return string|void
168
+	 */
169
+	protected function buildFieldDescription()
170
+	{
171
+		if (empty($this->args['description'])) {
172
+			return;
173
+		}
174
+		if ($this->args['is_widget']) {
175
+			return $this->small($this->args['description']);
176
+		}
177
+		return $this->p($this->args['description'], ['class' => 'description']);
178
+	}
179
+
180
+	/**
181
+	 * @return string|void
182
+	 */
183
+	protected function buildFormInput()
184
+	{
185
+		if (!in_array($this->args['type'], ['checkbox', 'radio'])) {
186
+			if (isset($this->args['multiple'])) {
187
+				$this->args['name'] .= '[]';
188
+			}
189
+			return $this->buildFormLabel().$this->getOpeningTag();
190
+		}
191
+		return empty($this->args['options'])
192
+			? $this->buildFormInputChoice()
193
+			: $this->buildFormInputMultiChoice();
194
+	}
195
+
196
+	/**
197
+	 * @return string|void
198
+	 */
199
+	protected function buildFormInputChoice()
200
+	{
201
+		if (!empty($this->args['text'])) {
202
+			$this->args['label'] = $this->args['text'];
203
+		}
204
+		if (!$this->args['is_public']) {
205
+			return $this->buildFormLabel([
206
+				'class' => 'glsr-'.$this->args['type'].'-label',
207
+				'text' => $this->getOpeningTag().' '.$this->args['label'].'<span></span>',
208
+			]);
209
+		}
210
+		return $this->getOpeningTag().$this->buildFormLabel([
211
+			'class' => 'glsr-'.$this->args['type'].'-label',
212
+			'text' => $this->args['label'].'<span></span>',
213
+		]);
214
+	}
215
+
216
+	/**
217
+	 * @return string|void
218
+	 */
219
+	protected function buildFormInputMultiChoice()
220
+	{
221
+		if ('checkbox' == $this->args['type']) {
222
+			$this->args['name'] .= '[]';
223
+		}
224
+		$index = 0;
225
+		$options = array_reduce(array_keys($this->args['options']), function ($carry, $key) use (&$index) {
226
+			return $carry.$this->li($this->{$this->args['type']}([
227
+				'checked' => in_array($key, (array) $this->args['value']),
228
+				'id' => $this->args['id'].'-'.$index++,
229
+				'name' => $this->args['name'],
230
+				'text' => $this->args['options'][$key],
231
+				'value' => $key,
232
+			]));
233
+		});
234
+		return $this->ul($options, [
235
+			'class' => $this->args['class'],
236
+			'id' => $this->args['id'],
237
+		]);
238
+	}
239
+
240
+	/**
241
+	 * @return void|string
242
+	 */
243
+	protected function buildFormLabel(array $customArgs = [])
244
+	{
245
+		if (empty($this->args['label']) || 'hidden' == $this->args['type']) {
246
+			return;
247
+		}
248
+		return $this->label(wp_parse_args($customArgs, [
249
+			'for' => $this->args['id'],
250
+			'is_public' => $this->args['is_public'],
251
+			'text' => $this->args['label'],
252
+			'type' => $this->args['type'],
253
+		]));
254
+	}
255
+
256
+	/**
257
+	 * @return string|void
258
+	 */
259
+	protected function buildFormSelect()
260
+	{
261
+		return $this->buildFormLabel().$this->buildDefaultTag($this->buildFormSelectOptions());
262
+	}
263
+
264
+	/**
265
+	 * @return string|void
266
+	 */
267
+	protected function buildFormSelectOptions()
268
+	{
269
+		return array_reduce(array_keys($this->args['options']), function ($carry, $key) {
270
+			return $carry.$this->option([
271
+				'selected' => $this->args['value'] === (string) $key,
272
+				'text' => $this->args['options'][$key],
273
+				'value' => $key,
274
+			]);
275
+		});
276
+	}
277
+
278
+	/**
279
+	 * @return string|void
280
+	 */
281
+	protected function buildFormTextarea()
282
+	{
283
+		return $this->buildFormLabel().$this->buildDefaultTag($this->args['value']);
284
+	}
285
+
286
+	/**
287
+	 * @return string|void
288
+	 */
289
+	protected function buildTag()
290
+	{
291
+		$this->mergeArgsWithRequiredDefaults();
292
+		return $this->getTag();
293
+	}
294
+
295
+	/**
296
+	 * @return string
297
+	 */
298
+	protected function getCustomFieldClassName()
299
+	{
300
+		$classname = Helper::buildClassName($this->tag, __NAMESPACE__.'\Fields');
301
+		return apply_filters('site-reviews/builder/field/'.$this->tag, $classname);
302
+	}
303
+
304
+	/**
305
+	 * @return void
306
+	 */
307
+	protected function mergeArgsWithRequiredDefaults()
308
+	{
309
+		$className = $this->getCustomFieldClassName();
310
+		if (class_exists($className)) {
311
+			$this->args = $className::merge($this->args);
312
+		}
313
+		$this->args = glsr(BuilderDefaults::class)->merge($this->args);
314
+	}
315
+
316
+	/**
317
+	 * @param string|array ...$params
318
+	 * @return void
319
+	 */
320
+	protected function normalize(...$params)
321
+	{
322
+		$parameter1 = Arr::get($params, 0);
323
+		$parameter2 = Arr::get($params, 1);
324
+		if (is_string($parameter1) || is_numeric($parameter1)) {
325
+			$this->setNameOrTextAttributeForTag($parameter1);
326
+		}
327
+		if (is_array($parameter1)) {
328
+			$this->args += $parameter1;
329
+		} elseif (is_array($parameter2)) {
330
+			$this->args += $parameter2;
331
+		}
332
+		if (!isset($this->args['is_public'])) {
333
+			$this->args['is_public'] = false;
334
+		}
335
+	}
336
+
337
+	/**
338
+	 * @param string $value
339
+	 * @return void
340
+	 */
341
+	protected function setNameOrTextAttributeForTag($value)
342
+	{
343
+		$attribute = in_array($this->tag, static::TAGS_FORM)
344
+			? 'name'
345
+			: 'text';
346
+		$this->args[$attribute] = $value;
347
+	}
348
+
349
+	/**
350
+	 * @param string $method
351
+	 * @return void
352
+	 */
353
+	protected function setTagFromMethod($method)
354
+	{
355
+		$this->tag = strtolower($method);
356
+		if (in_array($this->tag, static::INPUT_TYPES)) {
357
+			$this->args['type'] = $this->tag;
358
+			$this->tag = 'input';
359
+		}
360
+	}
361 361
 }
Please login to merge, or discard this patch.
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -62,18 +62,18 @@  discard block
 block discarded – undo
62 62
      * @param array $args
63 63
      * @return string|void
64 64
      */
65
-    public function __call($method, $args)
65
+    public function __call( $method, $args )
66 66
     {
67 67
         $instance = new static();
68
-        $instance->setTagFromMethod($method);
69
-        call_user_func_array([$instance, 'normalize'], $args);
70
-        $tags = array_merge(static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT);
71
-        do_action_ref_array('site-reviews/builder', [$instance]);
72
-        $generatedTag = in_array($instance->tag, $tags)
68
+        $instance->setTagFromMethod( $method );
69
+        call_user_func_array( [$instance, 'normalize'], $args );
70
+        $tags = array_merge( static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT );
71
+        do_action_ref_array( 'site-reviews/builder', [$instance] );
72
+        $generatedTag = in_array( $instance->tag, $tags )
73 73
             ? $instance->buildTag()
74 74
             : $instance->buildCustomField();
75
-        $generatedTag = apply_filters('site-reviews/builder/result', $generatedTag, $instance);
76
-        if (!$this->render) {
75
+        $generatedTag = apply_filters( 'site-reviews/builder/result', $generatedTag, $instance );
76
+        if( !$this->render ) {
77 77
             return $generatedTag;
78 78
         }
79 79
         echo $generatedTag;
@@ -84,14 +84,14 @@  discard block
 block discarded – undo
84 84
      * @param mixed $value
85 85
      * @return void
86 86
      */
87
-    public function __set($property, $value)
87
+    public function __set( $property, $value )
88 88
     {
89 89
         $properties = [
90 90
             'args' => 'is_array',
91 91
             'render' => 'is_bool',
92 92
             'tag' => 'is_string',
93 93
         ];
94
-        if (array_key_exists($property, $properties) && !empty($value)) {
94
+        if( array_key_exists( $property, $properties ) && !empty($value) ) {
95 95
             $this->$property = $value;
96 96
         }
97 97
     }
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
      */
102 102
     public function getClosingTag()
103 103
     {
104
-        if (!empty($this->tag)) {
104
+        if( !empty($this->tag) ) {
105 105
             return '</'.$this->tag.'>';
106 106
         }
107 107
     }
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
      */
112 112
     public function getOpeningTag()
113 113
     {
114
-        if (!empty($this->tag)) {
115
-            $attributes = glsr(Attributes::class)->{$this->tag}($this->args)->toString();
116
-            return '<'.trim($this->tag.' '.$attributes).'>';
114
+        if( !empty($this->tag) ) {
115
+            $attributes = glsr( Attributes::class )->{$this->tag}($this->args)->toString();
116
+            return '<'.trim( $this->tag.' '.$attributes ).'>';
117 117
         }
118 118
     }
119 119
 
@@ -122,19 +122,19 @@  discard block
 block discarded – undo
122 122
      */
123 123
     public function getTag()
124 124
     {
125
-        if (in_array($this->tag, static::TAGS_SINGLE)) {
125
+        if( in_array( $this->tag, static::TAGS_SINGLE ) ) {
126 126
             return $this->getOpeningTag();
127 127
         }
128
-        if (!in_array($this->tag, static::TAGS_FORM)) {
128
+        if( !in_array( $this->tag, static::TAGS_FORM ) ) {
129 129
             return $this->buildDefaultTag();
130 130
         }
131
-        return call_user_func([$this, 'buildForm'.ucfirst($this->tag)]).$this->buildFieldDescription();
131
+        return call_user_func( [$this, 'buildForm'.ucfirst( $this->tag )] ).$this->buildFieldDescription();
132 132
     }
133 133
 
134 134
     /**
135 135
      * @return string
136 136
      */
137
-    public function raw(array $field)
137
+    public function raw( array $field )
138 138
     {
139 139
         unset($field['label']);
140 140
         return $this->{$field['type']}($field);
@@ -146,18 +146,18 @@  discard block
 block discarded – undo
146 146
     protected function buildCustomField()
147 147
     {
148 148
         $className = $this->getCustomFieldClassName();
149
-        if (class_exists($className)) {
150
-            return (new $className($this))->build();
149
+        if( class_exists( $className ) ) {
150
+            return (new $className( $this ))->build();
151 151
         }
152
-        glsr_log()->error('Field class missing: '.$className);
152
+        glsr_log()->error( 'Field class missing: '.$className );
153 153
     }
154 154
 
155 155
     /**
156 156
      * @return string|void
157 157
      */
158
-    protected function buildDefaultTag($text = '')
158
+    protected function buildDefaultTag( $text = '' )
159 159
     {
160
-        if (empty($text)) {
160
+        if( empty($text) ) {
161 161
             $text = $this->args['text'];
162 162
         }
163 163
         return $this->getOpeningTag().$text.$this->getClosingTag();
@@ -168,13 +168,13 @@  discard block
 block discarded – undo
168 168
      */
169 169
     protected function buildFieldDescription()
170 170
     {
171
-        if (empty($this->args['description'])) {
171
+        if( empty($this->args['description']) ) {
172 172
             return;
173 173
         }
174
-        if ($this->args['is_widget']) {
175
-            return $this->small($this->args['description']);
174
+        if( $this->args['is_widget'] ) {
175
+            return $this->small( $this->args['description'] );
176 176
         }
177
-        return $this->p($this->args['description'], ['class' => 'description']);
177
+        return $this->p( $this->args['description'], ['class' => 'description'] );
178 178
     }
179 179
 
180 180
     /**
@@ -182,8 +182,8 @@  discard block
 block discarded – undo
182 182
      */
183 183
     protected function buildFormInput()
184 184
     {
185
-        if (!in_array($this->args['type'], ['checkbox', 'radio'])) {
186
-            if (isset($this->args['multiple'])) {
185
+        if( !in_array( $this->args['type'], ['checkbox', 'radio'] ) ) {
186
+            if( isset($this->args['multiple']) ) {
187 187
                 $this->args['name'] .= '[]';
188 188
             }
189 189
             return $this->buildFormLabel().$this->getOpeningTag();
@@ -198,19 +198,19 @@  discard block
 block discarded – undo
198 198
      */
199 199
     protected function buildFormInputChoice()
200 200
     {
201
-        if (!empty($this->args['text'])) {
201
+        if( !empty($this->args['text']) ) {
202 202
             $this->args['label'] = $this->args['text'];
203 203
         }
204
-        if (!$this->args['is_public']) {
205
-            return $this->buildFormLabel([
204
+        if( !$this->args['is_public'] ) {
205
+            return $this->buildFormLabel( [
206 206
                 'class' => 'glsr-'.$this->args['type'].'-label',
207 207
                 'text' => $this->getOpeningTag().' '.$this->args['label'].'<span></span>',
208
-            ]);
208
+            ] );
209 209
         }
210
-        return $this->getOpeningTag().$this->buildFormLabel([
210
+        return $this->getOpeningTag().$this->buildFormLabel( [
211 211
             'class' => 'glsr-'.$this->args['type'].'-label',
212 212
             'text' => $this->args['label'].'<span></span>',
213
-        ]);
213
+        ] );
214 214
     }
215 215
 
216 216
     /**
@@ -218,39 +218,39 @@  discard block
 block discarded – undo
218 218
      */
219 219
     protected function buildFormInputMultiChoice()
220 220
     {
221
-        if ('checkbox' == $this->args['type']) {
221
+        if( 'checkbox' == $this->args['type'] ) {
222 222
             $this->args['name'] .= '[]';
223 223
         }
224 224
         $index = 0;
225
-        $options = array_reduce(array_keys($this->args['options']), function ($carry, $key) use (&$index) {
226
-            return $carry.$this->li($this->{$this->args['type']}([
227
-                'checked' => in_array($key, (array) $this->args['value']),
225
+        $options = array_reduce( array_keys( $this->args['options'] ), function( $carry, $key ) use (&$index) {
226
+            return $carry.$this->li( $this->{$this->args['type']}([
227
+                'checked' => in_array( $key, (array)$this->args['value'] ),
228 228
                 'id' => $this->args['id'].'-'.$index++,
229 229
                 'name' => $this->args['name'],
230 230
                 'text' => $this->args['options'][$key],
231 231
                 'value' => $key,
232
-            ]));
232
+            ]) );
233 233
         });
234
-        return $this->ul($options, [
234
+        return $this->ul( $options, [
235 235
             'class' => $this->args['class'],
236 236
             'id' => $this->args['id'],
237
-        ]);
237
+        ] );
238 238
     }
239 239
 
240 240
     /**
241 241
      * @return void|string
242 242
      */
243
-    protected function buildFormLabel(array $customArgs = [])
243
+    protected function buildFormLabel( array $customArgs = [] )
244 244
     {
245
-        if (empty($this->args['label']) || 'hidden' == $this->args['type']) {
245
+        if( empty($this->args['label']) || 'hidden' == $this->args['type'] ) {
246 246
             return;
247 247
         }
248
-        return $this->label(wp_parse_args($customArgs, [
248
+        return $this->label( wp_parse_args( $customArgs, [
249 249
             'for' => $this->args['id'],
250 250
             'is_public' => $this->args['is_public'],
251 251
             'text' => $this->args['label'],
252 252
             'type' => $this->args['type'],
253
-        ]));
253
+        ] ) );
254 254
     }
255 255
 
256 256
     /**
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
      */
259 259
     protected function buildFormSelect()
260 260
     {
261
-        return $this->buildFormLabel().$this->buildDefaultTag($this->buildFormSelectOptions());
261
+        return $this->buildFormLabel().$this->buildDefaultTag( $this->buildFormSelectOptions() );
262 262
     }
263 263
 
264 264
     /**
@@ -266,12 +266,12 @@  discard block
 block discarded – undo
266 266
      */
267 267
     protected function buildFormSelectOptions()
268 268
     {
269
-        return array_reduce(array_keys($this->args['options']), function ($carry, $key) {
270
-            return $carry.$this->option([
271
-                'selected' => $this->args['value'] === (string) $key,
269
+        return array_reduce( array_keys( $this->args['options'] ), function( $carry, $key ) {
270
+            return $carry.$this->option( [
271
+                'selected' => $this->args['value'] === (string)$key,
272 272
                 'text' => $this->args['options'][$key],
273 273
                 'value' => $key,
274
-            ]);
274
+            ] );
275 275
         });
276 276
     }
277 277
 
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
      */
281 281
     protected function buildFormTextarea()
282 282
     {
283
-        return $this->buildFormLabel().$this->buildDefaultTag($this->args['value']);
283
+        return $this->buildFormLabel().$this->buildDefaultTag( $this->args['value'] );
284 284
     }
285 285
 
286 286
     /**
@@ -297,8 +297,8 @@  discard block
 block discarded – undo
297 297
      */
298 298
     protected function getCustomFieldClassName()
299 299
     {
300
-        $classname = Helper::buildClassName($this->tag, __NAMESPACE__.'\Fields');
301
-        return apply_filters('site-reviews/builder/field/'.$this->tag, $classname);
300
+        $classname = Helper::buildClassName( $this->tag, __NAMESPACE__.'\Fields' );
301
+        return apply_filters( 'site-reviews/builder/field/'.$this->tag, $classname );
302 302
     }
303 303
 
304 304
     /**
@@ -307,29 +307,29 @@  discard block
 block discarded – undo
307 307
     protected function mergeArgsWithRequiredDefaults()
308 308
     {
309 309
         $className = $this->getCustomFieldClassName();
310
-        if (class_exists($className)) {
311
-            $this->args = $className::merge($this->args);
310
+        if( class_exists( $className ) ) {
311
+            $this->args = $className::merge( $this->args );
312 312
         }
313
-        $this->args = glsr(BuilderDefaults::class)->merge($this->args);
313
+        $this->args = glsr( BuilderDefaults::class )->merge( $this->args );
314 314
     }
315 315
 
316 316
     /**
317 317
      * @param string|array ...$params
318 318
      * @return void
319 319
      */
320
-    protected function normalize(...$params)
320
+    protected function normalize( ...$params )
321 321
     {
322
-        $parameter1 = Arr::get($params, 0);
323
-        $parameter2 = Arr::get($params, 1);
324
-        if (is_string($parameter1) || is_numeric($parameter1)) {
325
-            $this->setNameOrTextAttributeForTag($parameter1);
322
+        $parameter1 = Arr::get( $params, 0 );
323
+        $parameter2 = Arr::get( $params, 1 );
324
+        if( is_string( $parameter1 ) || is_numeric( $parameter1 ) ) {
325
+            $this->setNameOrTextAttributeForTag( $parameter1 );
326 326
         }
327
-        if (is_array($parameter1)) {
327
+        if( is_array( $parameter1 ) ) {
328 328
             $this->args += $parameter1;
329
-        } elseif (is_array($parameter2)) {
329
+        } elseif( is_array( $parameter2 ) ) {
330 330
             $this->args += $parameter2;
331 331
         }
332
-        if (!isset($this->args['is_public'])) {
332
+        if( !isset($this->args['is_public']) ) {
333 333
             $this->args['is_public'] = false;
334 334
         }
335 335
     }
@@ -338,9 +338,9 @@  discard block
 block discarded – undo
338 338
      * @param string $value
339 339
      * @return void
340 340
      */
341
-    protected function setNameOrTextAttributeForTag($value)
341
+    protected function setNameOrTextAttributeForTag( $value )
342 342
     {
343
-        $attribute = in_array($this->tag, static::TAGS_FORM)
343
+        $attribute = in_array( $this->tag, static::TAGS_FORM )
344 344
             ? 'name'
345 345
             : 'text';
346 346
         $this->args[$attribute] = $value;
@@ -350,10 +350,10 @@  discard block
 block discarded – undo
350 350
      * @param string $method
351 351
      * @return void
352 352
      */
353
-    protected function setTagFromMethod($method)
353
+    protected function setTagFromMethod( $method )
354 354
     {
355
-        $this->tag = strtolower($method);
356
-        if (in_array($this->tag, static::INPUT_TYPES)) {
355
+        $this->tag = strtolower( $method );
356
+        if( in_array( $this->tag, static::INPUT_TYPES ) ) {
357 357
             $this->args['type'] = $this->tag;
358 358
             $this->tag = 'input';
359 359
         }
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -326,7 +326,8 @@
 block discarded – undo
326 326
         }
327 327
         if (is_array($parameter1)) {
328 328
             $this->args += $parameter1;
329
-        } elseif (is_array($parameter2)) {
329
+        }
330
+        elseif (is_array($parameter2)) {
330 331
             $this->args += $parameter2;
331 332
         }
332 333
         if (!isset($this->args['is_public'])) {
Please login to merge, or discard this patch.
plugin/Modules/Html/Attributes.php 2 patches
Indentation   +288 added lines, -288 removed lines patch added patch discarded remove patch
@@ -7,292 +7,292 @@
 block discarded – undo
7 7
 
8 8
 class Attributes
9 9
 {
10
-    const ATTRIBUTES_A = [
11
-        'download', 'href', 'hreflang', 'ping', 'referrerpolicy', 'rel', 'target', 'type',
12
-    ];
13
-
14
-    const ATTRIBUTES_BUTTON = [
15
-        'autofocus', 'disabled', 'form', 'formaction', 'formenctype', 'formmethod',
16
-        'formnovalidate', 'formtarget', 'name', 'type', 'value',
17
-    ];
18
-
19
-    const ATTRIBUTES_FORM = [
20
-        'accept', 'accept-charset', 'action', 'autocapitalize', 'autocomplete', 'enctype', 'method',
21
-        'name', 'novalidate', 'target',
22
-    ];
23
-
24
-    const ATTRIBUTES_IMG = [
25
-        'alt', 'crossorigin', 'decoding', 'height', 'ismap', 'referrerpolicy', 'sizes', 'src',
26
-        'srcset', 'width', 'usemap',
27
-    ];
28
-
29
-    const ATTRIBUTES_INPUT = [
30
-        'accept', 'autocomplete', 'autocorrect', 'autofocus', 'capture', 'checked', 'disabled',
31
-        'form', 'formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget', 'height',
32
-        'incremental', 'inputmode', 'list', 'max', 'maxlength', 'min', 'minlength', 'multiple',
33
-        'name', 'pattern', 'placeholder', 'readonly', 'results', 'required', 'selectionDirection',
34
-        'selectionEnd', 'selectionStart', 'size', 'spellcheck', 'src', 'step', 'tabindex', 'type',
35
-        'value', 'webkitdirectory', 'width',
36
-    ];
37
-
38
-    const ATTRIBUTES_LABEL = [
39
-        'for',
40
-    ];
41
-
42
-    const ATTRIBUTES_OPTION = [
43
-        'disabled', 'label', 'selected', 'value',
44
-    ];
45
-
46
-    const ATTRIBUTES_SELECT = [
47
-        'autofocus', 'disabled', 'form', 'multiple', 'name', 'required', 'size',
48
-    ];
49
-
50
-    const ATTRIBUTES_TEXTAREA = [
51
-        'autocapitalize', 'autocomplete', 'autofocus', 'cols', 'disabled', 'form', 'maxlength',
52
-        'minlength', 'name', 'placeholder', 'readonly', 'required', 'rows', 'spellcheck', 'wrap',
53
-    ];
54
-
55
-    const BOOLEAN_ATTRIBUTES = [
56
-        'autofocus', 'capture', 'checked', 'disabled', 'draggable', 'formnovalidate', 'hidden',
57
-        'multiple', 'novalidate', 'readonly', 'required', 'selected', 'spellcheck',
58
-        'webkitdirectory',
59
-    ];
60
-
61
-    const GLOBAL_ATTRIBUTES = [
62
-        'accesskey', 'class', 'contenteditable', 'contextmenu', 'dir', 'draggable', 'dropzone',
63
-        'hidden', 'id', 'lang', 'spellcheck', 'style', 'tabindex', 'title',
64
-    ];
65
-
66
-    const GLOBAL_WILDCARD_ATTRIBUTES = [
67
-        'aria-', 'data-', 'item', 'on',
68
-    ];
69
-
70
-    const INPUT_TYPES = [
71
-        'button', 'checkbox', 'color', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image',
72
-        'month', 'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text',
73
-        'time', 'url', 'week',
74
-    ];
75
-
76
-    /**
77
-     * @var array
78
-     */
79
-    protected $attributes = [];
80
-
81
-    /**
82
-     * @param string $method
83
-     * @param array $args
84
-     * @return static
85
-     */
86
-    public function __call($method, $args)
87
-    {
88
-        $constant = 'static::ATTRIBUTES_'.strtoupper($method);
89
-        $allowedAttributeKeys = defined($constant)
90
-            ? constant($constant)
91
-            : [];
92
-        $this->normalize(Arr::consolidate(Arr::get($args, 0)), $allowedAttributeKeys);
93
-        $this->normalizeInputType($method);
94
-        return $this;
95
-    }
96
-
97
-    /**
98
-     * @return static
99
-     */
100
-    public function set(array $attributes)
101
-    {
102
-        $this->normalize($attributes);
103
-        return $this;
104
-    }
105
-
106
-    /**
107
-     * @return array
108
-     */
109
-    public function toArray()
110
-    {
111
-        return $this->attributes;
112
-    }
113
-
114
-    /**
115
-     * @return string
116
-     */
117
-    public function toString()
118
-    {
119
-        $attributes = [];
120
-        foreach ($this->attributes as $attribute => $value) {
121
-            $quote = $this->getQuoteChar($attribute);
122
-            $attributes[] = in_array($attribute, static::BOOLEAN_ATTRIBUTES)
123
-                ? $attribute
124
-                : $attribute.'='.$quote.implode(',', (array) $value).$quote;
125
-        }
126
-        return implode(' ', $attributes);
127
-    }
128
-
129
-    /**
130
-     * @return array
131
-     */
132
-    protected function filterAttributes(array $allowedAttributeKeys)
133
-    {
134
-        return array_intersect_key($this->attributes, array_flip($allowedAttributeKeys));
135
-    }
136
-
137
-    /**
138
-     * @return array
139
-     */
140
-    protected function filterGlobalAttributes()
141
-    {
142
-        $globalAttributes = $this->filterAttributes(static::GLOBAL_ATTRIBUTES);
143
-        $wildcards = [];
144
-        foreach (static::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard) {
145
-            $newWildcards = array_filter($this->attributes, function ($key) use ($wildcard) {
146
-                return Str::startsWith($wildcard, $key);
147
-            }, ARRAY_FILTER_USE_KEY);
148
-            $wildcards = array_merge($wildcards, $newWildcards);
149
-        }
150
-        return array_merge($globalAttributes, $wildcards);
151
-    }
152
-
153
-    /**
154
-     * @return array
155
-     */
156
-    protected function getPermanentAttributes()
157
-    {
158
-        $permanentAttributes = [];
159
-        if (array_key_exists('value', $this->attributes)) {
160
-            $permanentAttributes['value'] = $this->attributes['value'];
161
-        }
162
-        return $permanentAttributes;
163
-    }
164
-
165
-    /**
166
-     * @param string $attribute
167
-     * @return string
168
-     */
169
-    protected function getQuoteChar($attribute)
170
-    {
171
-        return Str::startsWith('data-', $attribute)
172
-            ? '\''
173
-            : '"';
174
-    }
175
-
176
-    /**
177
-     * @param string $key
178
-     * @param mixed $value
179
-     * @return bool
180
-     */
181
-    protected function isAttributeKeyNumeric($key, $value)
182
-    {
183
-        return is_string($value)
184
-            && is_numeric($key)
185
-            && !array_key_exists($value, $this->attributes);
186
-    }
187
-
188
-    /**
189
-     * @return void
190
-     */
191
-    protected function normalize(array $args, array $allowedAttributeKeys = [])
192
-    {
193
-        $this->attributes = array_change_key_case($args, CASE_LOWER);
194
-        $this->normalizeBooleanAttributes();
195
-        $this->normalizeDataAttributes();
196
-        $this->normalizeStringAttributes();
197
-        $this->removeEmptyAttributes();
198
-        $this->removeIndexedAttributes();
199
-        $this->attributes = array_merge(
200
-            $this->filterGlobalAttributes(),
201
-            $this->filterAttributes($allowedAttributeKeys)
202
-        );
203
-    }
204
-
205
-    /**
206
-     * @return void
207
-     */
208
-    protected function normalizeBooleanAttributes()
209
-    {
210
-        foreach ($this->attributes as $key => $value) {
211
-            if ($this->isAttributeKeyNumeric($key, $value)) {
212
-                $key = $value;
213
-                $value = true;
214
-            }
215
-            if (!in_array($key, static::BOOLEAN_ATTRIBUTES)) {
216
-                continue;
217
-            }
218
-            $this->attributes[$key] = wp_validate_boolean($value);
219
-        }
220
-    }
221
-
222
-    /**
223
-     * @return void
224
-     */
225
-    protected function normalizeDataAttributes()
226
-    {
227
-        foreach ($this->attributes as $key => $value) {
228
-            if ($this->isAttributeKeyNumeric($key, $value)) {
229
-                $key = $value;
230
-                $value = '';
231
-            }
232
-            if (!Str::startsWith('data-', $key)) {
233
-                continue;
234
-            }
235
-            if (is_array($value)) {
236
-                $value = json_encode($value, JSON_HEX_APOS | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
237
-            }
238
-            $this->attributes[$key] = $value;
239
-        }
240
-    }
241
-
242
-    /**
243
-     * @return void
244
-     */
245
-    protected function normalizeStringAttributes()
246
-    {
247
-        foreach ($this->attributes as $key => $value) {
248
-            if (is_string($value)) {
249
-                $this->attributes[$key] = trim($value);
250
-            }
251
-        }
252
-    }
253
-
254
-    /**
255
-     * @param string $method
256
-     * @return void
257
-     */
258
-    protected function normalizeInputType($method)
259
-    {
260
-        if ('input' != $method) {
261
-            return;
262
-        }
263
-        $attributes = wp_parse_args($this->attributes, ['type' => '']);
264
-        if (!in_array($attributes['type'], static::INPUT_TYPES)) {
265
-            $this->attributes['type'] = 'text';
266
-        }
267
-    }
268
-
269
-    /**
270
-     * @return void
271
-     */
272
-    protected function removeEmptyAttributes()
273
-    {
274
-        $attributes = $this->attributes;
275
-        $permanentAttributes = $this->getPermanentAttributes();
276
-        foreach ($this->attributes as $key => $value) {
277
-            if (in_array($key, static::BOOLEAN_ATTRIBUTES) && !$value) {
278
-                unset($attributes[$key]);
279
-            }
280
-            if (Str::startsWith('data-', $key)) {
281
-                $permanentAttributes[$key] = $value;
282
-                unset($attributes[$key]);
283
-            }
284
-        }
285
-        $this->attributes = array_merge(array_filter($attributes), $permanentAttributes);
286
-    }
287
-
288
-    /**
289
-     * @return void
290
-     */
291
-    protected function removeIndexedAttributes()
292
-    {
293
-        $this->attributes = array_diff_key(
294
-            $this->attributes,
295
-            array_filter($this->attributes, 'is_numeric', ARRAY_FILTER_USE_KEY)
296
-        );
297
-    }
10
+	const ATTRIBUTES_A = [
11
+		'download', 'href', 'hreflang', 'ping', 'referrerpolicy', 'rel', 'target', 'type',
12
+	];
13
+
14
+	const ATTRIBUTES_BUTTON = [
15
+		'autofocus', 'disabled', 'form', 'formaction', 'formenctype', 'formmethod',
16
+		'formnovalidate', 'formtarget', 'name', 'type', 'value',
17
+	];
18
+
19
+	const ATTRIBUTES_FORM = [
20
+		'accept', 'accept-charset', 'action', 'autocapitalize', 'autocomplete', 'enctype', 'method',
21
+		'name', 'novalidate', 'target',
22
+	];
23
+
24
+	const ATTRIBUTES_IMG = [
25
+		'alt', 'crossorigin', 'decoding', 'height', 'ismap', 'referrerpolicy', 'sizes', 'src',
26
+		'srcset', 'width', 'usemap',
27
+	];
28
+
29
+	const ATTRIBUTES_INPUT = [
30
+		'accept', 'autocomplete', 'autocorrect', 'autofocus', 'capture', 'checked', 'disabled',
31
+		'form', 'formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget', 'height',
32
+		'incremental', 'inputmode', 'list', 'max', 'maxlength', 'min', 'minlength', 'multiple',
33
+		'name', 'pattern', 'placeholder', 'readonly', 'results', 'required', 'selectionDirection',
34
+		'selectionEnd', 'selectionStart', 'size', 'spellcheck', 'src', 'step', 'tabindex', 'type',
35
+		'value', 'webkitdirectory', 'width',
36
+	];
37
+
38
+	const ATTRIBUTES_LABEL = [
39
+		'for',
40
+	];
41
+
42
+	const ATTRIBUTES_OPTION = [
43
+		'disabled', 'label', 'selected', 'value',
44
+	];
45
+
46
+	const ATTRIBUTES_SELECT = [
47
+		'autofocus', 'disabled', 'form', 'multiple', 'name', 'required', 'size',
48
+	];
49
+
50
+	const ATTRIBUTES_TEXTAREA = [
51
+		'autocapitalize', 'autocomplete', 'autofocus', 'cols', 'disabled', 'form', 'maxlength',
52
+		'minlength', 'name', 'placeholder', 'readonly', 'required', 'rows', 'spellcheck', 'wrap',
53
+	];
54
+
55
+	const BOOLEAN_ATTRIBUTES = [
56
+		'autofocus', 'capture', 'checked', 'disabled', 'draggable', 'formnovalidate', 'hidden',
57
+		'multiple', 'novalidate', 'readonly', 'required', 'selected', 'spellcheck',
58
+		'webkitdirectory',
59
+	];
60
+
61
+	const GLOBAL_ATTRIBUTES = [
62
+		'accesskey', 'class', 'contenteditable', 'contextmenu', 'dir', 'draggable', 'dropzone',
63
+		'hidden', 'id', 'lang', 'spellcheck', 'style', 'tabindex', 'title',
64
+	];
65
+
66
+	const GLOBAL_WILDCARD_ATTRIBUTES = [
67
+		'aria-', 'data-', 'item', 'on',
68
+	];
69
+
70
+	const INPUT_TYPES = [
71
+		'button', 'checkbox', 'color', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image',
72
+		'month', 'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text',
73
+		'time', 'url', 'week',
74
+	];
75
+
76
+	/**
77
+	 * @var array
78
+	 */
79
+	protected $attributes = [];
80
+
81
+	/**
82
+	 * @param string $method
83
+	 * @param array $args
84
+	 * @return static
85
+	 */
86
+	public function __call($method, $args)
87
+	{
88
+		$constant = 'static::ATTRIBUTES_'.strtoupper($method);
89
+		$allowedAttributeKeys = defined($constant)
90
+			? constant($constant)
91
+			: [];
92
+		$this->normalize(Arr::consolidate(Arr::get($args, 0)), $allowedAttributeKeys);
93
+		$this->normalizeInputType($method);
94
+		return $this;
95
+	}
96
+
97
+	/**
98
+	 * @return static
99
+	 */
100
+	public function set(array $attributes)
101
+	{
102
+		$this->normalize($attributes);
103
+		return $this;
104
+	}
105
+
106
+	/**
107
+	 * @return array
108
+	 */
109
+	public function toArray()
110
+	{
111
+		return $this->attributes;
112
+	}
113
+
114
+	/**
115
+	 * @return string
116
+	 */
117
+	public function toString()
118
+	{
119
+		$attributes = [];
120
+		foreach ($this->attributes as $attribute => $value) {
121
+			$quote = $this->getQuoteChar($attribute);
122
+			$attributes[] = in_array($attribute, static::BOOLEAN_ATTRIBUTES)
123
+				? $attribute
124
+				: $attribute.'='.$quote.implode(',', (array) $value).$quote;
125
+		}
126
+		return implode(' ', $attributes);
127
+	}
128
+
129
+	/**
130
+	 * @return array
131
+	 */
132
+	protected function filterAttributes(array $allowedAttributeKeys)
133
+	{
134
+		return array_intersect_key($this->attributes, array_flip($allowedAttributeKeys));
135
+	}
136
+
137
+	/**
138
+	 * @return array
139
+	 */
140
+	protected function filterGlobalAttributes()
141
+	{
142
+		$globalAttributes = $this->filterAttributes(static::GLOBAL_ATTRIBUTES);
143
+		$wildcards = [];
144
+		foreach (static::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard) {
145
+			$newWildcards = array_filter($this->attributes, function ($key) use ($wildcard) {
146
+				return Str::startsWith($wildcard, $key);
147
+			}, ARRAY_FILTER_USE_KEY);
148
+			$wildcards = array_merge($wildcards, $newWildcards);
149
+		}
150
+		return array_merge($globalAttributes, $wildcards);
151
+	}
152
+
153
+	/**
154
+	 * @return array
155
+	 */
156
+	protected function getPermanentAttributes()
157
+	{
158
+		$permanentAttributes = [];
159
+		if (array_key_exists('value', $this->attributes)) {
160
+			$permanentAttributes['value'] = $this->attributes['value'];
161
+		}
162
+		return $permanentAttributes;
163
+	}
164
+
165
+	/**
166
+	 * @param string $attribute
167
+	 * @return string
168
+	 */
169
+	protected function getQuoteChar($attribute)
170
+	{
171
+		return Str::startsWith('data-', $attribute)
172
+			? '\''
173
+			: '"';
174
+	}
175
+
176
+	/**
177
+	 * @param string $key
178
+	 * @param mixed $value
179
+	 * @return bool
180
+	 */
181
+	protected function isAttributeKeyNumeric($key, $value)
182
+	{
183
+		return is_string($value)
184
+			&& is_numeric($key)
185
+			&& !array_key_exists($value, $this->attributes);
186
+	}
187
+
188
+	/**
189
+	 * @return void
190
+	 */
191
+	protected function normalize(array $args, array $allowedAttributeKeys = [])
192
+	{
193
+		$this->attributes = array_change_key_case($args, CASE_LOWER);
194
+		$this->normalizeBooleanAttributes();
195
+		$this->normalizeDataAttributes();
196
+		$this->normalizeStringAttributes();
197
+		$this->removeEmptyAttributes();
198
+		$this->removeIndexedAttributes();
199
+		$this->attributes = array_merge(
200
+			$this->filterGlobalAttributes(),
201
+			$this->filterAttributes($allowedAttributeKeys)
202
+		);
203
+	}
204
+
205
+	/**
206
+	 * @return void
207
+	 */
208
+	protected function normalizeBooleanAttributes()
209
+	{
210
+		foreach ($this->attributes as $key => $value) {
211
+			if ($this->isAttributeKeyNumeric($key, $value)) {
212
+				$key = $value;
213
+				$value = true;
214
+			}
215
+			if (!in_array($key, static::BOOLEAN_ATTRIBUTES)) {
216
+				continue;
217
+			}
218
+			$this->attributes[$key] = wp_validate_boolean($value);
219
+		}
220
+	}
221
+
222
+	/**
223
+	 * @return void
224
+	 */
225
+	protected function normalizeDataAttributes()
226
+	{
227
+		foreach ($this->attributes as $key => $value) {
228
+			if ($this->isAttributeKeyNumeric($key, $value)) {
229
+				$key = $value;
230
+				$value = '';
231
+			}
232
+			if (!Str::startsWith('data-', $key)) {
233
+				continue;
234
+			}
235
+			if (is_array($value)) {
236
+				$value = json_encode($value, JSON_HEX_APOS | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
237
+			}
238
+			$this->attributes[$key] = $value;
239
+		}
240
+	}
241
+
242
+	/**
243
+	 * @return void
244
+	 */
245
+	protected function normalizeStringAttributes()
246
+	{
247
+		foreach ($this->attributes as $key => $value) {
248
+			if (is_string($value)) {
249
+				$this->attributes[$key] = trim($value);
250
+			}
251
+		}
252
+	}
253
+
254
+	/**
255
+	 * @param string $method
256
+	 * @return void
257
+	 */
258
+	protected function normalizeInputType($method)
259
+	{
260
+		if ('input' != $method) {
261
+			return;
262
+		}
263
+		$attributes = wp_parse_args($this->attributes, ['type' => '']);
264
+		if (!in_array($attributes['type'], static::INPUT_TYPES)) {
265
+			$this->attributes['type'] = 'text';
266
+		}
267
+	}
268
+
269
+	/**
270
+	 * @return void
271
+	 */
272
+	protected function removeEmptyAttributes()
273
+	{
274
+		$attributes = $this->attributes;
275
+		$permanentAttributes = $this->getPermanentAttributes();
276
+		foreach ($this->attributes as $key => $value) {
277
+			if (in_array($key, static::BOOLEAN_ATTRIBUTES) && !$value) {
278
+				unset($attributes[$key]);
279
+			}
280
+			if (Str::startsWith('data-', $key)) {
281
+				$permanentAttributes[$key] = $value;
282
+				unset($attributes[$key]);
283
+			}
284
+		}
285
+		$this->attributes = array_merge(array_filter($attributes), $permanentAttributes);
286
+	}
287
+
288
+	/**
289
+	 * @return void
290
+	 */
291
+	protected function removeIndexedAttributes()
292
+	{
293
+		$this->attributes = array_diff_key(
294
+			$this->attributes,
295
+			array_filter($this->attributes, 'is_numeric', ARRAY_FILTER_USE_KEY)
296
+		);
297
+	}
298 298
 }
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -83,23 +83,23 @@  discard block
 block discarded – undo
83 83
      * @param array $args
84 84
      * @return static
85 85
      */
86
-    public function __call($method, $args)
86
+    public function __call( $method, $args )
87 87
     {
88
-        $constant = 'static::ATTRIBUTES_'.strtoupper($method);
89
-        $allowedAttributeKeys = defined($constant)
90
-            ? constant($constant)
88
+        $constant = 'static::ATTRIBUTES_'.strtoupper( $method );
89
+        $allowedAttributeKeys = defined( $constant )
90
+            ? constant( $constant )
91 91
             : [];
92
-        $this->normalize(Arr::consolidate(Arr::get($args, 0)), $allowedAttributeKeys);
93
-        $this->normalizeInputType($method);
92
+        $this->normalize( Arr::consolidate( Arr::get( $args, 0 ) ), $allowedAttributeKeys );
93
+        $this->normalizeInputType( $method );
94 94
         return $this;
95 95
     }
96 96
 
97 97
     /**
98 98
      * @return static
99 99
      */
100
-    public function set(array $attributes)
100
+    public function set( array $attributes )
101 101
     {
102
-        $this->normalize($attributes);
102
+        $this->normalize( $attributes );
103 103
         return $this;
104 104
     }
105 105
 
@@ -117,21 +117,21 @@  discard block
 block discarded – undo
117 117
     public function toString()
118 118
     {
119 119
         $attributes = [];
120
-        foreach ($this->attributes as $attribute => $value) {
121
-            $quote = $this->getQuoteChar($attribute);
122
-            $attributes[] = in_array($attribute, static::BOOLEAN_ATTRIBUTES)
120
+        foreach( $this->attributes as $attribute => $value ) {
121
+            $quote = $this->getQuoteChar( $attribute );
122
+            $attributes[] = in_array( $attribute, static::BOOLEAN_ATTRIBUTES )
123 123
                 ? $attribute
124
-                : $attribute.'='.$quote.implode(',', (array) $value).$quote;
124
+                : $attribute.'='.$quote.implode( ',', (array)$value ).$quote;
125 125
         }
126
-        return implode(' ', $attributes);
126
+        return implode( ' ', $attributes );
127 127
     }
128 128
 
129 129
     /**
130 130
      * @return array
131 131
      */
132
-    protected function filterAttributes(array $allowedAttributeKeys)
132
+    protected function filterAttributes( array $allowedAttributeKeys )
133 133
     {
134
-        return array_intersect_key($this->attributes, array_flip($allowedAttributeKeys));
134
+        return array_intersect_key( $this->attributes, array_flip( $allowedAttributeKeys ) );
135 135
     }
136 136
 
137 137
     /**
@@ -139,15 +139,15 @@  discard block
 block discarded – undo
139 139
      */
140 140
     protected function filterGlobalAttributes()
141 141
     {
142
-        $globalAttributes = $this->filterAttributes(static::GLOBAL_ATTRIBUTES);
142
+        $globalAttributes = $this->filterAttributes( static::GLOBAL_ATTRIBUTES );
143 143
         $wildcards = [];
144
-        foreach (static::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard) {
145
-            $newWildcards = array_filter($this->attributes, function ($key) use ($wildcard) {
146
-                return Str::startsWith($wildcard, $key);
147
-            }, ARRAY_FILTER_USE_KEY);
148
-            $wildcards = array_merge($wildcards, $newWildcards);
144
+        foreach( static::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard ) {
145
+            $newWildcards = array_filter( $this->attributes, function( $key ) use ($wildcard) {
146
+                return Str::startsWith( $wildcard, $key );
147
+            }, ARRAY_FILTER_USE_KEY );
148
+            $wildcards = array_merge( $wildcards, $newWildcards );
149 149
         }
150
-        return array_merge($globalAttributes, $wildcards);
150
+        return array_merge( $globalAttributes, $wildcards );
151 151
     }
152 152
 
153 153
     /**
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
     protected function getPermanentAttributes()
157 157
     {
158 158
         $permanentAttributes = [];
159
-        if (array_key_exists('value', $this->attributes)) {
159
+        if( array_key_exists( 'value', $this->attributes ) ) {
160 160
             $permanentAttributes['value'] = $this->attributes['value'];
161 161
         }
162 162
         return $permanentAttributes;
@@ -166,9 +166,9 @@  discard block
 block discarded – undo
166 166
      * @param string $attribute
167 167
      * @return string
168 168
      */
169
-    protected function getQuoteChar($attribute)
169
+    protected function getQuoteChar( $attribute )
170 170
     {
171
-        return Str::startsWith('data-', $attribute)
171
+        return Str::startsWith( 'data-', $attribute )
172 172
             ? '\''
173 173
             : '"';
174 174
     }
@@ -178,19 +178,19 @@  discard block
 block discarded – undo
178 178
      * @param mixed $value
179 179
      * @return bool
180 180
      */
181
-    protected function isAttributeKeyNumeric($key, $value)
181
+    protected function isAttributeKeyNumeric( $key, $value )
182 182
     {
183
-        return is_string($value)
184
-            && is_numeric($key)
185
-            && !array_key_exists($value, $this->attributes);
183
+        return is_string( $value )
184
+            && is_numeric( $key )
185
+            && !array_key_exists( $value, $this->attributes );
186 186
     }
187 187
 
188 188
     /**
189 189
      * @return void
190 190
      */
191
-    protected function normalize(array $args, array $allowedAttributeKeys = [])
191
+    protected function normalize( array $args, array $allowedAttributeKeys = [] )
192 192
     {
193
-        $this->attributes = array_change_key_case($args, CASE_LOWER);
193
+        $this->attributes = array_change_key_case( $args, CASE_LOWER );
194 194
         $this->normalizeBooleanAttributes();
195 195
         $this->normalizeDataAttributes();
196 196
         $this->normalizeStringAttributes();
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
         $this->removeIndexedAttributes();
199 199
         $this->attributes = array_merge(
200 200
             $this->filterGlobalAttributes(),
201
-            $this->filterAttributes($allowedAttributeKeys)
201
+            $this->filterAttributes( $allowedAttributeKeys )
202 202
         );
203 203
     }
204 204
 
@@ -207,15 +207,15 @@  discard block
 block discarded – undo
207 207
      */
208 208
     protected function normalizeBooleanAttributes()
209 209
     {
210
-        foreach ($this->attributes as $key => $value) {
211
-            if ($this->isAttributeKeyNumeric($key, $value)) {
210
+        foreach( $this->attributes as $key => $value ) {
211
+            if( $this->isAttributeKeyNumeric( $key, $value ) ) {
212 212
                 $key = $value;
213 213
                 $value = true;
214 214
             }
215
-            if (!in_array($key, static::BOOLEAN_ATTRIBUTES)) {
215
+            if( !in_array( $key, static::BOOLEAN_ATTRIBUTES ) ) {
216 216
                 continue;
217 217
             }
218
-            $this->attributes[$key] = wp_validate_boolean($value);
218
+            $this->attributes[$key] = wp_validate_boolean( $value );
219 219
         }
220 220
     }
221 221
 
@@ -224,16 +224,16 @@  discard block
 block discarded – undo
224 224
      */
225 225
     protected function normalizeDataAttributes()
226 226
     {
227
-        foreach ($this->attributes as $key => $value) {
228
-            if ($this->isAttributeKeyNumeric($key, $value)) {
227
+        foreach( $this->attributes as $key => $value ) {
228
+            if( $this->isAttributeKeyNumeric( $key, $value ) ) {
229 229
                 $key = $value;
230 230
                 $value = '';
231 231
             }
232
-            if (!Str::startsWith('data-', $key)) {
232
+            if( !Str::startsWith( 'data-', $key ) ) {
233 233
                 continue;
234 234
             }
235
-            if (is_array($value)) {
236
-                $value = json_encode($value, JSON_HEX_APOS | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
235
+            if( is_array( $value ) ) {
236
+                $value = json_encode( $value, JSON_HEX_APOS | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
237 237
             }
238 238
             $this->attributes[$key] = $value;
239 239
         }
@@ -244,9 +244,9 @@  discard block
 block discarded – undo
244 244
      */
245 245
     protected function normalizeStringAttributes()
246 246
     {
247
-        foreach ($this->attributes as $key => $value) {
248
-            if (is_string($value)) {
249
-                $this->attributes[$key] = trim($value);
247
+        foreach( $this->attributes as $key => $value ) {
248
+            if( is_string( $value ) ) {
249
+                $this->attributes[$key] = trim( $value );
250 250
             }
251 251
         }
252 252
     }
@@ -255,13 +255,13 @@  discard block
 block discarded – undo
255 255
      * @param string $method
256 256
      * @return void
257 257
      */
258
-    protected function normalizeInputType($method)
258
+    protected function normalizeInputType( $method )
259 259
     {
260
-        if ('input' != $method) {
260
+        if( 'input' != $method ) {
261 261
             return;
262 262
         }
263
-        $attributes = wp_parse_args($this->attributes, ['type' => '']);
264
-        if (!in_array($attributes['type'], static::INPUT_TYPES)) {
263
+        $attributes = wp_parse_args( $this->attributes, ['type' => ''] );
264
+        if( !in_array( $attributes['type'], static::INPUT_TYPES ) ) {
265 265
             $this->attributes['type'] = 'text';
266 266
         }
267 267
     }
@@ -273,16 +273,16 @@  discard block
 block discarded – undo
273 273
     {
274 274
         $attributes = $this->attributes;
275 275
         $permanentAttributes = $this->getPermanentAttributes();
276
-        foreach ($this->attributes as $key => $value) {
277
-            if (in_array($key, static::BOOLEAN_ATTRIBUTES) && !$value) {
276
+        foreach( $this->attributes as $key => $value ) {
277
+            if( in_array( $key, static::BOOLEAN_ATTRIBUTES ) && !$value ) {
278 278
                 unset($attributes[$key]);
279 279
             }
280
-            if (Str::startsWith('data-', $key)) {
280
+            if( Str::startsWith( 'data-', $key ) ) {
281 281
                 $permanentAttributes[$key] = $value;
282 282
                 unset($attributes[$key]);
283 283
             }
284 284
         }
285
-        $this->attributes = array_merge(array_filter($attributes), $permanentAttributes);
285
+        $this->attributes = array_merge( array_filter( $attributes ), $permanentAttributes );
286 286
     }
287 287
 
288 288
     /**
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
     {
293 293
         $this->attributes = array_diff_key(
294 294
             $this->attributes,
295
-            array_filter($this->attributes, 'is_numeric', ARRAY_FILTER_USE_KEY)
295
+            array_filter( $this->attributes, 'is_numeric', ARRAY_FILTER_USE_KEY )
296 296
         );
297 297
     }
298 298
 }
Please login to merge, or discard this patch.
plugin/Modules/System.php 2 patches
Indentation   +352 added lines, -352 removed lines patch added patch discarded remove patch
@@ -13,378 +13,378 @@
 block discarded – undo
13 13
 
14 14
 class System
15 15
 {
16
-    const PAD = 40;
16
+	const PAD = 40;
17 17
 
18
-    /**
19
-     * @return string
20
-     */
21
-    public function __toString()
22
-    {
23
-        return $this->get();
24
-    }
18
+	/**
19
+	 * @return string
20
+	 */
21
+	public function __toString()
22
+	{
23
+		return $this->get();
24
+	}
25 25
 
26
-    /**
27
-     * @return string
28
-     */
29
-    public function get()
30
-    {
31
-        $details = [
32
-            'plugin' => 'Plugin Details',
33
-            'addon' => 'Addon Details',
34
-            'browser' => 'Browser Details',
35
-            'server' => 'Server Details',
36
-            'php' => 'PHP Configuration',
37
-            'wordpress' => 'WordPress Configuration',
38
-            'mu-plugin' => 'Must-Use Plugins',
39
-            'multisite-plugin' => 'Network Active Plugins',
40
-            'active-plugin' => 'Active Plugins',
41
-            'inactive-plugin' => 'Inactive Plugins',
42
-            'setting' => 'Plugin Settings',
43
-            'reviews' => 'Review Counts',
44
-        ];
45
-        $systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) {
46
-            $methodName = Helper::buildMethodName('get-'.$key.'-details');
47
-            if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) {
48
-                return $carry.$this->implode(
49
-                    strtoupper($details[$key]),
50
-                    apply_filters('site-reviews/system/'.$key, $systemDetails)
51
-                );
52
-            }
53
-            return $carry;
54
-        });
55
-        return trim($systemInfo);
56
-    }
26
+	/**
27
+	 * @return string
28
+	 */
29
+	public function get()
30
+	{
31
+		$details = [
32
+			'plugin' => 'Plugin Details',
33
+			'addon' => 'Addon Details',
34
+			'browser' => 'Browser Details',
35
+			'server' => 'Server Details',
36
+			'php' => 'PHP Configuration',
37
+			'wordpress' => 'WordPress Configuration',
38
+			'mu-plugin' => 'Must-Use Plugins',
39
+			'multisite-plugin' => 'Network Active Plugins',
40
+			'active-plugin' => 'Active Plugins',
41
+			'inactive-plugin' => 'Inactive Plugins',
42
+			'setting' => 'Plugin Settings',
43
+			'reviews' => 'Review Counts',
44
+		];
45
+		$systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) {
46
+			$methodName = Helper::buildMethodName('get-'.$key.'-details');
47
+			if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) {
48
+				return $carry.$this->implode(
49
+					strtoupper($details[$key]),
50
+					apply_filters('site-reviews/system/'.$key, $systemDetails)
51
+				);
52
+			}
53
+			return $carry;
54
+		});
55
+		return trim($systemInfo);
56
+	}
57 57
 
58
-    /**
59
-     * @return array
60
-     */
61
-    public function getActivePluginDetails()
62
-    {
63
-        $plugins = get_plugins();
64
-        $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
65
-        $inactive = array_diff_key($plugins, array_flip($activePlugins));
66
-        return $this->normalizePluginList(array_diff_key($plugins, $inactive));
67
-    }
58
+	/**
59
+	 * @return array
60
+	 */
61
+	public function getActivePluginDetails()
62
+	{
63
+		$plugins = get_plugins();
64
+		$activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
65
+		$inactive = array_diff_key($plugins, array_flip($activePlugins));
66
+		return $this->normalizePluginList(array_diff_key($plugins, $inactive));
67
+	}
68 68
 
69
-    /**
70
-     * @return array
71
-     */
72
-    public function getAddonDetails()
73
-    {
74
-        $details = apply_filters('site-reviews/addon/system-info', []);
75
-        ksort($details);
76
-        return $details;
77
-    }
69
+	/**
70
+	 * @return array
71
+	 */
72
+	public function getAddonDetails()
73
+	{
74
+		$details = apply_filters('site-reviews/addon/system-info', []);
75
+		ksort($details);
76
+		return $details;
77
+	}
78 78
 
79
-    /**
80
-     * @return array
81
-     */
82
-    public function getBrowserDetails()
83
-    {
84
-        $browser = new Browser();
85
-        $name = esc_attr($browser->getName());
86
-        $userAgent = esc_attr($browser->getUserAgent()->getUserAgentString());
87
-        $version = esc_attr($browser->getVersion());
88
-        return [
89
-            'Browser Name' => sprintf('%s %s', $name, $version),
90
-            'Browser UA' => $userAgent,
91
-        ];
92
-    }
79
+	/**
80
+	 * @return array
81
+	 */
82
+	public function getBrowserDetails()
83
+	{
84
+		$browser = new Browser();
85
+		$name = esc_attr($browser->getName());
86
+		$userAgent = esc_attr($browser->getUserAgent()->getUserAgentString());
87
+		$version = esc_attr($browser->getVersion());
88
+		return [
89
+			'Browser Name' => sprintf('%s %s', $name, $version),
90
+			'Browser UA' => $userAgent,
91
+		];
92
+	}
93 93
 
94
-    /**
95
-     * @return array
96
-     */
97
-    public function getInactivePluginDetails()
98
-    {
99
-        $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
100
-        $inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins)));
101
-        $multisitePlugins = $this->getMultisitePluginDetails();
102
-        return empty($multisitePlugins)
103
-            ? $inactivePlugins
104
-            : array_diff($inactivePlugins, $multisitePlugins);
105
-    }
94
+	/**
95
+	 * @return array
96
+	 */
97
+	public function getInactivePluginDetails()
98
+	{
99
+		$activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
100
+		$inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins)));
101
+		$multisitePlugins = $this->getMultisitePluginDetails();
102
+		return empty($multisitePlugins)
103
+			? $inactivePlugins
104
+			: array_diff($inactivePlugins, $multisitePlugins);
105
+	}
106 106
 
107
-    /**
108
-     * @return array
109
-     */
110
-    public function getMuPluginDetails()
111
-    {
112
-        if (empty($plugins = get_mu_plugins())) {
113
-            return [];
114
-        }
115
-        return $this->normalizePluginList($plugins);
116
-    }
107
+	/**
108
+	 * @return array
109
+	 */
110
+	public function getMuPluginDetails()
111
+	{
112
+		if (empty($plugins = get_mu_plugins())) {
113
+			return [];
114
+		}
115
+		return $this->normalizePluginList($plugins);
116
+	}
117 117
 
118
-    /**
119
-     * @return array
120
-     */
121
-    public function getMultisitePluginDetails()
122
-    {
123
-        $activePlugins = (array) get_site_option('active_sitewide_plugins', []);
124
-        if (!is_multisite() || empty($activePlugins)) {
125
-            return [];
126
-        }
127
-        return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins));
128
-    }
118
+	/**
119
+	 * @return array
120
+	 */
121
+	public function getMultisitePluginDetails()
122
+	{
123
+		$activePlugins = (array) get_site_option('active_sitewide_plugins', []);
124
+		if (!is_multisite() || empty($activePlugins)) {
125
+			return [];
126
+		}
127
+		return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins));
128
+	}
129 129
 
130
-    /**
131
-     * @return array
132
-     */
133
-    public function getPhpDetails()
134
-    {
135
-        $displayErrors = $this->getINI('display_errors', null)
136
-            ? 'On ('.$this->getINI('display_errors').')'
137
-            : 'N/A';
138
-        $intlSupport = extension_loaded('intl')
139
-            ? phpversion('intl')
140
-            : 'false';
141
-        return [
142
-            'cURL' => var_export(function_exists('curl_init'), true),
143
-            'Default Charset' => $this->getINI('default_charset'),
144
-            'Display Errors' => $displayErrors,
145
-            'fsockopen' => var_export(function_exists('fsockopen'), true),
146
-            'Intl' => $intlSupport,
147
-            'IPv6' => var_export(defined('AF_INET6'), true),
148
-            'Max Execution Time' => $this->getINI('max_execution_time'),
149
-            'Max Input Nesting Level' => $this->getINI('max_input_nesting_level'),
150
-            'Max Input Vars' => $this->getINI('max_input_vars'),
151
-            'Memory Limit' => $this->getINI('memory_limit'),
152
-            'Post Max Size' => $this->getINI('post_max_size'),
153
-            'Sendmail Path' => $this->getINI('sendmail_path'),
154
-            'Session Cookie Path' => esc_html($this->getINI('session.cookie_path')),
155
-            'Session Name' => esc_html($this->getINI('session.name')),
156
-            'Session Save Path' => esc_html($this->getINI('session.save_path')),
157
-            'Session Use Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_cookies', false)), true),
158
-            'Session Use Only Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_only_cookies', false)), true),
159
-            'Upload Max Filesize' => $this->getINI('upload_max_filesize'),
160
-        ];
161
-    }
130
+	/**
131
+	 * @return array
132
+	 */
133
+	public function getPhpDetails()
134
+	{
135
+		$displayErrors = $this->getINI('display_errors', null)
136
+			? 'On ('.$this->getINI('display_errors').')'
137
+			: 'N/A';
138
+		$intlSupport = extension_loaded('intl')
139
+			? phpversion('intl')
140
+			: 'false';
141
+		return [
142
+			'cURL' => var_export(function_exists('curl_init'), true),
143
+			'Default Charset' => $this->getINI('default_charset'),
144
+			'Display Errors' => $displayErrors,
145
+			'fsockopen' => var_export(function_exists('fsockopen'), true),
146
+			'Intl' => $intlSupport,
147
+			'IPv6' => var_export(defined('AF_INET6'), true),
148
+			'Max Execution Time' => $this->getINI('max_execution_time'),
149
+			'Max Input Nesting Level' => $this->getINI('max_input_nesting_level'),
150
+			'Max Input Vars' => $this->getINI('max_input_vars'),
151
+			'Memory Limit' => $this->getINI('memory_limit'),
152
+			'Post Max Size' => $this->getINI('post_max_size'),
153
+			'Sendmail Path' => $this->getINI('sendmail_path'),
154
+			'Session Cookie Path' => esc_html($this->getINI('session.cookie_path')),
155
+			'Session Name' => esc_html($this->getINI('session.name')),
156
+			'Session Save Path' => esc_html($this->getINI('session.save_path')),
157
+			'Session Use Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_cookies', false)), true),
158
+			'Session Use Only Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_only_cookies', false)), true),
159
+			'Upload Max Filesize' => $this->getINI('upload_max_filesize'),
160
+		];
161
+	}
162 162
 
163
-    /**
164
-     * @return array
165
-     */
166
-    public function getReviewsDetails()
167
-    {
168
-        $counts = glsr(CountsManager::class)->getCounts();
169
-        $counts = Arr::flatten($counts);
170
-        array_walk($counts, function (&$ratings) use ($counts) {
171
-            if (is_array($ratings)) {
172
-                $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')';
173
-                return;
174
-            }
175
-            glsr_log()
176
-                ->error('$ratings is not an array, possibly due to incorrectly imported reviews.')
177
-                ->debug($ratings)
178
-                ->debug($counts);
179
-        });
180
-        ksort($counts);
181
-        return $counts;
182
-    }
163
+	/**
164
+	 * @return array
165
+	 */
166
+	public function getReviewsDetails()
167
+	{
168
+		$counts = glsr(CountsManager::class)->getCounts();
169
+		$counts = Arr::flatten($counts);
170
+		array_walk($counts, function (&$ratings) use ($counts) {
171
+			if (is_array($ratings)) {
172
+				$ratings = array_sum($ratings).' ('.implode(', ', $ratings).')';
173
+				return;
174
+			}
175
+			glsr_log()
176
+				->error('$ratings is not an array, possibly due to incorrectly imported reviews.')
177
+				->debug($ratings)
178
+				->debug($counts);
179
+		});
180
+		ksort($counts);
181
+		return $counts;
182
+	}
183 183
 
184
-    /**
185
-     * @return array
186
-     */
187
-    public function getServerDetails()
188
-    {
189
-        global $wpdb;
190
-        return [
191
-            'Host Name' => $this->getHostName(),
192
-            'MySQL Version' => $wpdb->db_version(),
193
-            'PHP Version' => PHP_VERSION,
194
-            'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'),
195
-        ];
196
-    }
184
+	/**
185
+	 * @return array
186
+	 */
187
+	public function getServerDetails()
188
+	{
189
+		global $wpdb;
190
+		return [
191
+			'Host Name' => $this->getHostName(),
192
+			'MySQL Version' => $wpdb->db_version(),
193
+			'PHP Version' => PHP_VERSION,
194
+			'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'),
195
+		];
196
+	}
197 197
 
198
-    /**
199
-     * @return array
200
-     */
201
-    public function getSettingDetails()
202
-    {
203
-        $settings = glsr(OptionManager::class)->get('settings', []);
204
-        $settings = Arr::flatten($settings, true);
205
-        $settings = $this->purgeSensitiveData($settings);
206
-        ksort($settings);
207
-        $details = [];
208
-        foreach ($settings as $key => $value) {
209
-            if (Str::startsWith('strings', $key) && Str::endsWith('id', $key)) {
210
-                continue;
211
-            }
212
-            $value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8');
213
-            $details[$key] = $value;
214
-        }
215
-        return $details;
216
-    }
198
+	/**
199
+	 * @return array
200
+	 */
201
+	public function getSettingDetails()
202
+	{
203
+		$settings = glsr(OptionManager::class)->get('settings', []);
204
+		$settings = Arr::flatten($settings, true);
205
+		$settings = $this->purgeSensitiveData($settings);
206
+		ksort($settings);
207
+		$details = [];
208
+		foreach ($settings as $key => $value) {
209
+			if (Str::startsWith('strings', $key) && Str::endsWith('id', $key)) {
210
+				continue;
211
+			}
212
+			$value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8');
213
+			$details[$key] = $value;
214
+		}
215
+		return $details;
216
+	}
217 217
 
218
-    /**
219
-     * @return array
220
-     */
221
-    public function getPluginDetails()
222
-    {
223
-        return [
224
-            'Console level' => glsr(Console::class)->humanLevel(),
225
-            'Console size' => glsr(Console::class)->humanSize('0'),
226
-            'Last Migration Run' => glsr(Date::class)->localized(glsr(OptionManager::class)->get('last_migration_run'), 'unknown'),
227
-            'Last Rating Count' => glsr(Date::class)->localized(glsr(OptionManager::class)->get('last_review_count'), 'unknown'),
228
-            'Version (current)' => glsr()->version,
229
-            'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'),
230
-        ];
231
-    }
218
+	/**
219
+	 * @return array
220
+	 */
221
+	public function getPluginDetails()
222
+	{
223
+		return [
224
+			'Console level' => glsr(Console::class)->humanLevel(),
225
+			'Console size' => glsr(Console::class)->humanSize('0'),
226
+			'Last Migration Run' => glsr(Date::class)->localized(glsr(OptionManager::class)->get('last_migration_run'), 'unknown'),
227
+			'Last Rating Count' => glsr(Date::class)->localized(glsr(OptionManager::class)->get('last_review_count'), 'unknown'),
228
+			'Version (current)' => glsr()->version,
229
+			'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'),
230
+		];
231
+	}
232 232
 
233
-    /**
234
-     * @return array
235
-     */
236
-    public function getWordpressDetails()
237
-    {
238
-        global $wpdb;
239
-        $theme = wp_get_theme();
240
-        return [
241
-            'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version),
242
-            'Email Domain' => substr(strrchr(glsr(OptionManager::class)->getWP('admin_email'), '@'), 1),
243
-            'Home URL' => home_url(),
244
-            'Language' => get_locale(),
245
-            'Memory Limit' => WP_MEMORY_LIMIT,
246
-            'Multisite' => var_export(is_multisite(), true),
247
-            'Page For Posts ID' => glsr(OptionManager::class)->getWP('page_for_posts'),
248
-            'Page On Front ID' => glsr(OptionManager::class)->getWP('page_on_front'),
249
-            'Permalink Structure' => glsr(OptionManager::class)->getWP('permalink_structure', 'default'),
250
-            'Post Stati' => implode(', ', get_post_stati()),
251
-            'Remote Post' => glsr(Cache::class)->getRemotePostTest(),
252
-            'Show On Front' => glsr(OptionManager::class)->getWP('show_on_front'),
253
-            'Site URL' => site_url(),
254
-            'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', $this->getINI('date.timezone').' (PHP)'),
255
-            'Version' => get_bloginfo('version'),
256
-            'WP Debug' => var_export(defined('WP_DEBUG'), true),
257
-            'WP Max Upload Size' => size_format(wp_max_upload_size()),
258
-            'WP Memory Limit' => WP_MEMORY_LIMIT,
259
-        ];
260
-    }
233
+	/**
234
+	 * @return array
235
+	 */
236
+	public function getWordpressDetails()
237
+	{
238
+		global $wpdb;
239
+		$theme = wp_get_theme();
240
+		return [
241
+			'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version),
242
+			'Email Domain' => substr(strrchr(glsr(OptionManager::class)->getWP('admin_email'), '@'), 1),
243
+			'Home URL' => home_url(),
244
+			'Language' => get_locale(),
245
+			'Memory Limit' => WP_MEMORY_LIMIT,
246
+			'Multisite' => var_export(is_multisite(), true),
247
+			'Page For Posts ID' => glsr(OptionManager::class)->getWP('page_for_posts'),
248
+			'Page On Front ID' => glsr(OptionManager::class)->getWP('page_on_front'),
249
+			'Permalink Structure' => glsr(OptionManager::class)->getWP('permalink_structure', 'default'),
250
+			'Post Stati' => implode(', ', get_post_stati()),
251
+			'Remote Post' => glsr(Cache::class)->getRemotePostTest(),
252
+			'Show On Front' => glsr(OptionManager::class)->getWP('show_on_front'),
253
+			'Site URL' => site_url(),
254
+			'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', $this->getINI('date.timezone').' (PHP)'),
255
+			'Version' => get_bloginfo('version'),
256
+			'WP Debug' => var_export(defined('WP_DEBUG'), true),
257
+			'WP Max Upload Size' => size_format(wp_max_upload_size()),
258
+			'WP Memory Limit' => WP_MEMORY_LIMIT,
259
+		];
260
+	}
261 261
 
262
-    /**
263
-     * @return string
264
-     */
265
-    protected function detectWebhostProvider()
266
-    {
267
-        $checks = [
268
-            '.accountservergroup.com' => 'Site5',
269
-            '.gridserver.com' => 'MediaTemple Grid',
270
-            '.inmotionhosting.com' => 'InMotion Hosting',
271
-            '.ovh.net' => 'OVH',
272
-            '.pair.com' => 'pair Networks',
273
-            '.stabletransit.com' => 'Rackspace Cloud',
274
-            '.stratoserver.net' => 'STRATO',
275
-            '.sysfix.eu' => 'SysFix.eu Power Hosting',
276
-            'bluehost.com' => 'Bluehost',
277
-            'DH_USER' => 'DreamHost',
278
-            'Flywheel' => 'Flywheel',
279
-            'ipagemysql.com' => 'iPage',
280
-            'ipowermysql.com' => 'IPower',
281
-            'localhost:/tmp/mysql5.sock' => 'ICDSoft',
282
-            'mysqlv5' => 'NetworkSolutions',
283
-            'PAGELYBIN' => 'Pagely',
284
-            'secureserver.net' => 'GoDaddy',
285
-            'WPE_APIKEY' => 'WP Engine',
286
-        ];
287
-        foreach ($checks as $key => $value) {
288
-            if (!$this->isWebhostCheckValid($key)) {
289
-                continue;
290
-            }
291
-            return $value;
292
-        }
293
-        return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')]));
294
-    }
262
+	/**
263
+	 * @return string
264
+	 */
265
+	protected function detectWebhostProvider()
266
+	{
267
+		$checks = [
268
+			'.accountservergroup.com' => 'Site5',
269
+			'.gridserver.com' => 'MediaTemple Grid',
270
+			'.inmotionhosting.com' => 'InMotion Hosting',
271
+			'.ovh.net' => 'OVH',
272
+			'.pair.com' => 'pair Networks',
273
+			'.stabletransit.com' => 'Rackspace Cloud',
274
+			'.stratoserver.net' => 'STRATO',
275
+			'.sysfix.eu' => 'SysFix.eu Power Hosting',
276
+			'bluehost.com' => 'Bluehost',
277
+			'DH_USER' => 'DreamHost',
278
+			'Flywheel' => 'Flywheel',
279
+			'ipagemysql.com' => 'iPage',
280
+			'ipowermysql.com' => 'IPower',
281
+			'localhost:/tmp/mysql5.sock' => 'ICDSoft',
282
+			'mysqlv5' => 'NetworkSolutions',
283
+			'PAGELYBIN' => 'Pagely',
284
+			'secureserver.net' => 'GoDaddy',
285
+			'WPE_APIKEY' => 'WP Engine',
286
+		];
287
+		foreach ($checks as $key => $value) {
288
+			if (!$this->isWebhostCheckValid($key)) {
289
+				continue;
290
+			}
291
+			return $value;
292
+		}
293
+		return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')]));
294
+	}
295 295
 
296
-    /**
297
-     * @return string
298
-     */
299
-    protected function getHostName()
300
-    {
301
-        return sprintf('%s (%s)',
302
-            $this->detectWebhostProvider(),
303
-            Helper::getIpAddress()
304
-        );
305
-    }
296
+	/**
297
+	 * @return string
298
+	 */
299
+	protected function getHostName()
300
+	{
301
+		return sprintf('%s (%s)',
302
+			$this->detectWebhostProvider(),
303
+			Helper::getIpAddress()
304
+		);
305
+	}
306 306
 
307
-    protected function getINI($name, $disabledValue = 'ini_get() is disabled.')
308
-    {
309
-        return function_exists('ini_get')
310
-            ? ini_get($name)
311
-            : $disabledValue;
312
-    }
307
+	protected function getINI($name, $disabledValue = 'ini_get() is disabled.')
308
+	{
309
+		return function_exists('ini_get')
310
+			? ini_get($name)
311
+			: $disabledValue;
312
+	}
313 313
 
314
-    /**
315
-     * @return array
316
-     */
317
-    protected function getWordpressPlugins()
318
-    {
319
-        $plugins = get_plugins();
320
-        $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
321
-        $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins)));
322
-        $active = $this->normalizePluginList(array_diff_key($plugins, $inactive));
323
-        return $active + $inactive;
324
-    }
314
+	/**
315
+	 * @return array
316
+	 */
317
+	protected function getWordpressPlugins()
318
+	{
319
+		$plugins = get_plugins();
320
+		$activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
321
+		$inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins)));
322
+		$active = $this->normalizePluginList(array_diff_key($plugins, $inactive));
323
+		return $active + $inactive;
324
+	}
325 325
 
326
-    /**
327
-     * @param string $title
328
-     * @return string
329
-     */
330
-    protected function implode($title, array $details)
331
-    {
332
-        $strings = ['['.$title.']'];
333
-        $padding = max(array_map('strlen', array_keys($details)));
334
-        $padding = max([$padding, static::PAD]);
335
-        foreach ($details as $key => $value) {
336
-            $strings[] = is_string($key)
337
-                ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value)
338
-                : ' - '.$value;
339
-        }
340
-        return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL;
341
-    }
326
+	/**
327
+	 * @param string $title
328
+	 * @return string
329
+	 */
330
+	protected function implode($title, array $details)
331
+	{
332
+		$strings = ['['.$title.']'];
333
+		$padding = max(array_map('strlen', array_keys($details)));
334
+		$padding = max([$padding, static::PAD]);
335
+		foreach ($details as $key => $value) {
336
+			$strings[] = is_string($key)
337
+				? sprintf('%s : %s', str_pad($key, $padding, '.'), $value)
338
+				: ' - '.$value;
339
+		}
340
+		return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL;
341
+	}
342 342
 
343
-    /**
344
-     * @param string $key
345
-     * @return bool
346
-     */
347
-    protected function isWebhostCheckValid($key)
348
-    {
349
-        return defined($key)
350
-            || filter_input(INPUT_SERVER, $key)
351
-            || Str::contains(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key)
352
-            || Str::contains(DB_HOST, $key)
353
-            || Str::contains(php_uname(), $key);
354
-    }
343
+	/**
344
+	 * @param string $key
345
+	 * @return bool
346
+	 */
347
+	protected function isWebhostCheckValid($key)
348
+	{
349
+		return defined($key)
350
+			|| filter_input(INPUT_SERVER, $key)
351
+			|| Str::contains(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key)
352
+			|| Str::contains(DB_HOST, $key)
353
+			|| Str::contains(php_uname(), $key);
354
+	}
355 355
 
356
-    /**
357
-     * @return array
358
-     */
359
-    protected function normalizePluginList(array $plugins)
360
-    {
361
-        $plugins = array_map(function ($plugin) {
362
-            return sprintf('%s v%s', Arr::get($plugin, 'Name'), Arr::get($plugin, 'Version'));
363
-        }, $plugins);
364
-        natcasesort($plugins);
365
-        return array_flip($plugins);
366
-    }
356
+	/**
357
+	 * @return array
358
+	 */
359
+	protected function normalizePluginList(array $plugins)
360
+	{
361
+		$plugins = array_map(function ($plugin) {
362
+			return sprintf('%s v%s', Arr::get($plugin, 'Name'), Arr::get($plugin, 'Version'));
363
+		}, $plugins);
364
+		natcasesort($plugins);
365
+		return array_flip($plugins);
366
+	}
367 367
 
368
-    /**
369
-     * @return array
370
-     */
371
-    protected function purgeSensitiveData(array $settings)
372
-    {
373
-        $keys = [
374
-            'general.trustalyze_serial',
375
-            'licenses.',
376
-            'submissions.recaptcha.key',
377
-            'submissions.recaptcha.secret',
378
-        ];
379
-        array_walk($settings, function (&$value, $setting) use ($keys) {
380
-            foreach ($keys as $key) {
381
-                if (!Str::startsWith($key, $setting) || empty($value)) {
382
-                    continue;
383
-                }
384
-                $value = str_repeat('•', 13);
385
-                return;
386
-            }
387
-        });
388
-        return $settings;
389
-    }
368
+	/**
369
+	 * @return array
370
+	 */
371
+	protected function purgeSensitiveData(array $settings)
372
+	{
373
+		$keys = [
374
+			'general.trustalyze_serial',
375
+			'licenses.',
376
+			'submissions.recaptcha.key',
377
+			'submissions.recaptcha.secret',
378
+		];
379
+		array_walk($settings, function (&$value, $setting) use ($keys) {
380
+			foreach ($keys as $key) {
381
+				if (!Str::startsWith($key, $setting) || empty($value)) {
382
+					continue;
383
+				}
384
+				$value = str_repeat('•', 13);
385
+				return;
386
+			}
387
+		});
388
+		return $settings;
389
+	}
390 390
 }
Please login to merge, or discard this patch.
Spacing   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -42,17 +42,17 @@  discard block
 block discarded – undo
42 42
             'setting' => 'Plugin Settings',
43 43
             'reviews' => 'Review Counts',
44 44
         ];
45
-        $systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) {
46
-            $methodName = Helper::buildMethodName('get-'.$key.'-details');
47
-            if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) {
45
+        $systemInfo = array_reduce( array_keys( $details ), function( $carry, $key ) use ($details) {
46
+            $methodName = Helper::buildMethodName( 'get-'.$key.'-details' );
47
+            if( method_exists( $this, $methodName ) && $systemDetails = $this->$methodName() ) {
48 48
                 return $carry.$this->implode(
49
-                    strtoupper($details[$key]),
50
-                    apply_filters('site-reviews/system/'.$key, $systemDetails)
49
+                    strtoupper( $details[$key] ),
50
+                    apply_filters( 'site-reviews/system/'.$key, $systemDetails )
51 51
                 );
52 52
             }
53 53
             return $carry;
54 54
         });
55
-        return trim($systemInfo);
55
+        return trim( $systemInfo );
56 56
     }
57 57
 
58 58
     /**
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
     public function getActivePluginDetails()
62 62
     {
63 63
         $plugins = get_plugins();
64
-        $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
65
-        $inactive = array_diff_key($plugins, array_flip($activePlugins));
66
-        return $this->normalizePluginList(array_diff_key($plugins, $inactive));
64
+        $activePlugins = glsr( OptionManager::class )->getWP( 'active_plugins', [], 'array' );
65
+        $inactive = array_diff_key( $plugins, array_flip( $activePlugins ) );
66
+        return $this->normalizePluginList( array_diff_key( $plugins, $inactive ) );
67 67
     }
68 68
 
69 69
     /**
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
      */
72 72
     public function getAddonDetails()
73 73
     {
74
-        $details = apply_filters('site-reviews/addon/system-info', []);
75
-        ksort($details);
74
+        $details = apply_filters( 'site-reviews/addon/system-info', [] );
75
+        ksort( $details );
76 76
         return $details;
77 77
     }
78 78
 
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
     public function getBrowserDetails()
83 83
     {
84 84
         $browser = new Browser();
85
-        $name = esc_attr($browser->getName());
86
-        $userAgent = esc_attr($browser->getUserAgent()->getUserAgentString());
87
-        $version = esc_attr($browser->getVersion());
85
+        $name = esc_attr( $browser->getName() );
86
+        $userAgent = esc_attr( $browser->getUserAgent()->getUserAgentString() );
87
+        $version = esc_attr( $browser->getVersion() );
88 88
         return [
89
-            'Browser Name' => sprintf('%s %s', $name, $version),
89
+            'Browser Name' => sprintf( '%s %s', $name, $version ),
90 90
             'Browser UA' => $userAgent,
91 91
         ];
92 92
     }
@@ -96,12 +96,12 @@  discard block
 block discarded – undo
96 96
      */
97 97
     public function getInactivePluginDetails()
98 98
     {
99
-        $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
100
-        $inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins)));
99
+        $activePlugins = glsr( OptionManager::class )->getWP( 'active_plugins', [], 'array' );
100
+        $inactivePlugins = $this->normalizePluginList( array_diff_key( get_plugins(), array_flip( $activePlugins ) ) );
101 101
         $multisitePlugins = $this->getMultisitePluginDetails();
102 102
         return empty($multisitePlugins)
103 103
             ? $inactivePlugins
104
-            : array_diff($inactivePlugins, $multisitePlugins);
104
+            : array_diff( $inactivePlugins, $multisitePlugins );
105 105
     }
106 106
 
107 107
     /**
@@ -109,10 +109,10 @@  discard block
 block discarded – undo
109 109
      */
110 110
     public function getMuPluginDetails()
111 111
     {
112
-        if (empty($plugins = get_mu_plugins())) {
112
+        if( empty($plugins = get_mu_plugins()) ) {
113 113
             return [];
114 114
         }
115
-        return $this->normalizePluginList($plugins);
115
+        return $this->normalizePluginList( $plugins );
116 116
     }
117 117
 
118 118
     /**
@@ -120,11 +120,11 @@  discard block
 block discarded – undo
120 120
      */
121 121
     public function getMultisitePluginDetails()
122 122
     {
123
-        $activePlugins = (array) get_site_option('active_sitewide_plugins', []);
124
-        if (!is_multisite() || empty($activePlugins)) {
123
+        $activePlugins = (array)get_site_option( 'active_sitewide_plugins', [] );
124
+        if( !is_multisite() || empty($activePlugins) ) {
125 125
             return [];
126 126
         }
127
-        return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins));
127
+        return $this->normalizePluginList( array_intersect_key( get_plugins(), $activePlugins ) );
128 128
     }
129 129
 
130 130
     /**
@@ -132,31 +132,31 @@  discard block
 block discarded – undo
132 132
      */
133 133
     public function getPhpDetails()
134 134
     {
135
-        $displayErrors = $this->getINI('display_errors', null)
136
-            ? 'On ('.$this->getINI('display_errors').')'
135
+        $displayErrors = $this->getINI( 'display_errors', null )
136
+            ? 'On ('.$this->getINI( 'display_errors' ).')'
137 137
             : 'N/A';
138
-        $intlSupport = extension_loaded('intl')
139
-            ? phpversion('intl')
138
+        $intlSupport = extension_loaded( 'intl' )
139
+            ? phpversion( 'intl' )
140 140
             : 'false';
141 141
         return [
142
-            'cURL' => var_export(function_exists('curl_init'), true),
143
-            'Default Charset' => $this->getINI('default_charset'),
142
+            'cURL' => var_export( function_exists( 'curl_init' ), true ),
143
+            'Default Charset' => $this->getINI( 'default_charset' ),
144 144
             'Display Errors' => $displayErrors,
145
-            'fsockopen' => var_export(function_exists('fsockopen'), true),
145
+            'fsockopen' => var_export( function_exists( 'fsockopen' ), true ),
146 146
             'Intl' => $intlSupport,
147
-            'IPv6' => var_export(defined('AF_INET6'), true),
148
-            'Max Execution Time' => $this->getINI('max_execution_time'),
149
-            'Max Input Nesting Level' => $this->getINI('max_input_nesting_level'),
150
-            'Max Input Vars' => $this->getINI('max_input_vars'),
151
-            'Memory Limit' => $this->getINI('memory_limit'),
152
-            'Post Max Size' => $this->getINI('post_max_size'),
153
-            'Sendmail Path' => $this->getINI('sendmail_path'),
154
-            'Session Cookie Path' => esc_html($this->getINI('session.cookie_path')),
155
-            'Session Name' => esc_html($this->getINI('session.name')),
156
-            'Session Save Path' => esc_html($this->getINI('session.save_path')),
157
-            'Session Use Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_cookies', false)), true),
158
-            'Session Use Only Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_only_cookies', false)), true),
159
-            'Upload Max Filesize' => $this->getINI('upload_max_filesize'),
147
+            'IPv6' => var_export( defined( 'AF_INET6' ), true ),
148
+            'Max Execution Time' => $this->getINI( 'max_execution_time' ),
149
+            'Max Input Nesting Level' => $this->getINI( 'max_input_nesting_level' ),
150
+            'Max Input Vars' => $this->getINI( 'max_input_vars' ),
151
+            'Memory Limit' => $this->getINI( 'memory_limit' ),
152
+            'Post Max Size' => $this->getINI( 'post_max_size' ),
153
+            'Sendmail Path' => $this->getINI( 'sendmail_path' ),
154
+            'Session Cookie Path' => esc_html( $this->getINI( 'session.cookie_path' ) ),
155
+            'Session Name' => esc_html( $this->getINI( 'session.name' ) ),
156
+            'Session Save Path' => esc_html( $this->getINI( 'session.save_path' ) ),
157
+            'Session Use Cookies' => var_export( wp_validate_boolean( $this->getINI( 'session.use_cookies', false ) ), true ),
158
+            'Session Use Only Cookies' => var_export( wp_validate_boolean( $this->getINI( 'session.use_only_cookies', false ) ), true ),
159
+            'Upload Max Filesize' => $this->getINI( 'upload_max_filesize' ),
160 160
         ];
161 161
     }
162 162
 
@@ -165,19 +165,19 @@  discard block
 block discarded – undo
165 165
      */
166 166
     public function getReviewsDetails()
167 167
     {
168
-        $counts = glsr(CountsManager::class)->getCounts();
169
-        $counts = Arr::flatten($counts);
170
-        array_walk($counts, function (&$ratings) use ($counts) {
171
-            if (is_array($ratings)) {
172
-                $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')';
168
+        $counts = glsr( CountsManager::class )->getCounts();
169
+        $counts = Arr::flatten( $counts );
170
+        array_walk( $counts, function( &$ratings ) use ($counts) {
171
+            if( is_array( $ratings ) ) {
172
+                $ratings = array_sum( $ratings ).' ('.implode( ', ', $ratings ).')';
173 173
                 return;
174 174
             }
175 175
             glsr_log()
176
-                ->error('$ratings is not an array, possibly due to incorrectly imported reviews.')
177
-                ->debug($ratings)
178
-                ->debug($counts);
176
+                ->error( '$ratings is not an array, possibly due to incorrectly imported reviews.' )
177
+                ->debug( $ratings )
178
+                ->debug( $counts );
179 179
         });
180
-        ksort($counts);
180
+        ksort( $counts );
181 181
         return $counts;
182 182
     }
183 183
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
             'Host Name' => $this->getHostName(),
192 192
             'MySQL Version' => $wpdb->db_version(),
193 193
             'PHP Version' => PHP_VERSION,
194
-            'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'),
194
+            'Server Software' => filter_input( INPUT_SERVER, 'SERVER_SOFTWARE' ),
195 195
         ];
196 196
     }
197 197
 
@@ -200,16 +200,16 @@  discard block
 block discarded – undo
200 200
      */
201 201
     public function getSettingDetails()
202 202
     {
203
-        $settings = glsr(OptionManager::class)->get('settings', []);
204
-        $settings = Arr::flatten($settings, true);
205
-        $settings = $this->purgeSensitiveData($settings);
206
-        ksort($settings);
203
+        $settings = glsr( OptionManager::class )->get( 'settings', [] );
204
+        $settings = Arr::flatten( $settings, true );
205
+        $settings = $this->purgeSensitiveData( $settings );
206
+        ksort( $settings );
207 207
         $details = [];
208
-        foreach ($settings as $key => $value) {
209
-            if (Str::startsWith('strings', $key) && Str::endsWith('id', $key)) {
208
+        foreach( $settings as $key => $value ) {
209
+            if( Str::startsWith( 'strings', $key ) && Str::endsWith( 'id', $key ) ) {
210 210
                 continue;
211 211
             }
212
-            $value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8');
212
+            $value = htmlspecialchars( trim( preg_replace( '/\s\s+/', '\\n', $value ) ), ENT_QUOTES, 'UTF-8' );
213 213
             $details[$key] = $value;
214 214
         }
215 215
         return $details;
@@ -221,12 +221,12 @@  discard block
 block discarded – undo
221 221
     public function getPluginDetails()
222 222
     {
223 223
         return [
224
-            'Console level' => glsr(Console::class)->humanLevel(),
225
-            'Console size' => glsr(Console::class)->humanSize('0'),
226
-            'Last Migration Run' => glsr(Date::class)->localized(glsr(OptionManager::class)->get('last_migration_run'), 'unknown'),
227
-            'Last Rating Count' => glsr(Date::class)->localized(glsr(OptionManager::class)->get('last_review_count'), 'unknown'),
224
+            'Console level' => glsr( Console::class )->humanLevel(),
225
+            'Console size' => glsr( Console::class )->humanSize( '0' ),
226
+            'Last Migration Run' => glsr( Date::class )->localized( glsr( OptionManager::class )->get( 'last_migration_run' ), 'unknown' ),
227
+            'Last Rating Count' => glsr( Date::class )->localized( glsr( OptionManager::class )->get( 'last_review_count' ), 'unknown' ),
228 228
             'Version (current)' => glsr()->version,
229
-            'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'),
229
+            'Version (previous)' => glsr( OptionManager::class )->get( 'version_upgraded_from' ),
230 230
         ];
231 231
     }
232 232
 
@@ -238,23 +238,23 @@  discard block
 block discarded – undo
238 238
         global $wpdb;
239 239
         $theme = wp_get_theme();
240 240
         return [
241
-            'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version),
242
-            'Email Domain' => substr(strrchr(glsr(OptionManager::class)->getWP('admin_email'), '@'), 1),
241
+            'Active Theme' => sprintf( '%s v%s', (string)$theme->Name, (string)$theme->Version ),
242
+            'Email Domain' => substr( strrchr( glsr( OptionManager::class )->getWP( 'admin_email' ), '@' ), 1 ),
243 243
             'Home URL' => home_url(),
244 244
             'Language' => get_locale(),
245 245
             'Memory Limit' => WP_MEMORY_LIMIT,
246
-            'Multisite' => var_export(is_multisite(), true),
247
-            'Page For Posts ID' => glsr(OptionManager::class)->getWP('page_for_posts'),
248
-            'Page On Front ID' => glsr(OptionManager::class)->getWP('page_on_front'),
249
-            'Permalink Structure' => glsr(OptionManager::class)->getWP('permalink_structure', 'default'),
250
-            'Post Stati' => implode(', ', get_post_stati()),
251
-            'Remote Post' => glsr(Cache::class)->getRemotePostTest(),
252
-            'Show On Front' => glsr(OptionManager::class)->getWP('show_on_front'),
246
+            'Multisite' => var_export( is_multisite(), true ),
247
+            'Page For Posts ID' => glsr( OptionManager::class )->getWP( 'page_for_posts' ),
248
+            'Page On Front ID' => glsr( OptionManager::class )->getWP( 'page_on_front' ),
249
+            'Permalink Structure' => glsr( OptionManager::class )->getWP( 'permalink_structure', 'default' ),
250
+            'Post Stati' => implode( ', ', get_post_stati() ),
251
+            'Remote Post' => glsr( Cache::class )->getRemotePostTest(),
252
+            'Show On Front' => glsr( OptionManager::class )->getWP( 'show_on_front' ),
253 253
             'Site URL' => site_url(),
254
-            'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', $this->getINI('date.timezone').' (PHP)'),
255
-            'Version' => get_bloginfo('version'),
256
-            'WP Debug' => var_export(defined('WP_DEBUG'), true),
257
-            'WP Max Upload Size' => size_format(wp_max_upload_size()),
254
+            'Timezone' => glsr( OptionManager::class )->getWP( 'timezone_string', $this->getINI( 'date.timezone' ).' (PHP)' ),
255
+            'Version' => get_bloginfo( 'version' ),
256
+            'WP Debug' => var_export( defined( 'WP_DEBUG' ), true ),
257
+            'WP Max Upload Size' => size_format( wp_max_upload_size() ),
258 258
             'WP Memory Limit' => WP_MEMORY_LIMIT,
259 259
         ];
260 260
     }
@@ -284,13 +284,13 @@  discard block
 block discarded – undo
284 284
             'secureserver.net' => 'GoDaddy',
285 285
             'WPE_APIKEY' => 'WP Engine',
286 286
         ];
287
-        foreach ($checks as $key => $value) {
288
-            if (!$this->isWebhostCheckValid($key)) {
287
+        foreach( $checks as $key => $value ) {
288
+            if( !$this->isWebhostCheckValid( $key ) ) {
289 289
                 continue;
290 290
             }
291 291
             return $value;
292 292
         }
293
-        return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')]));
293
+        return implode( ',', array_filter( [DB_HOST, filter_input( INPUT_SERVER, 'SERVER_NAME' )] ) );
294 294
     }
295 295
 
296 296
     /**
@@ -298,16 +298,16 @@  discard block
 block discarded – undo
298 298
      */
299 299
     protected function getHostName()
300 300
     {
301
-        return sprintf('%s (%s)',
301
+        return sprintf( '%s (%s)',
302 302
             $this->detectWebhostProvider(),
303 303
             Helper::getIpAddress()
304 304
         );
305 305
     }
306 306
 
307
-    protected function getINI($name, $disabledValue = 'ini_get() is disabled.')
307
+    protected function getINI( $name, $disabledValue = 'ini_get() is disabled.' )
308 308
     {
309
-        return function_exists('ini_get')
310
-            ? ini_get($name)
309
+        return function_exists( 'ini_get' )
310
+            ? ini_get( $name )
311 311
             : $disabledValue;
312 312
     }
313 313
 
@@ -317,9 +317,9 @@  discard block
 block discarded – undo
317 317
     protected function getWordpressPlugins()
318 318
     {
319 319
         $plugins = get_plugins();
320
-        $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
321
-        $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins)));
322
-        $active = $this->normalizePluginList(array_diff_key($plugins, $inactive));
320
+        $activePlugins = glsr( OptionManager::class )->getWP( 'active_plugins', [], 'array' );
321
+        $inactive = $this->normalizePluginList( array_diff_key( $plugins, array_flip( $activePlugins ) ) );
322
+        $active = $this->normalizePluginList( array_diff_key( $plugins, $inactive ) );
323 323
         return $active + $inactive;
324 324
     }
325 325
 
@@ -327,48 +327,48 @@  discard block
 block discarded – undo
327 327
      * @param string $title
328 328
      * @return string
329 329
      */
330
-    protected function implode($title, array $details)
330
+    protected function implode( $title, array $details )
331 331
     {
332 332
         $strings = ['['.$title.']'];
333
-        $padding = max(array_map('strlen', array_keys($details)));
334
-        $padding = max([$padding, static::PAD]);
335
-        foreach ($details as $key => $value) {
336
-            $strings[] = is_string($key)
337
-                ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value)
333
+        $padding = max( array_map( 'strlen', array_keys( $details ) ) );
334
+        $padding = max( [$padding, static::PAD] );
335
+        foreach( $details as $key => $value ) {
336
+            $strings[] = is_string( $key )
337
+                ? sprintf( '%s : %s', str_pad( $key, $padding, '.' ), $value )
338 338
                 : ' - '.$value;
339 339
         }
340
-        return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL;
340
+        return implode( PHP_EOL, $strings ).PHP_EOL.PHP_EOL;
341 341
     }
342 342
 
343 343
     /**
344 344
      * @param string $key
345 345
      * @return bool
346 346
      */
347
-    protected function isWebhostCheckValid($key)
347
+    protected function isWebhostCheckValid( $key )
348 348
     {
349
-        return defined($key)
350
-            || filter_input(INPUT_SERVER, $key)
351
-            || Str::contains(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key)
352
-            || Str::contains(DB_HOST, $key)
353
-            || Str::contains(php_uname(), $key);
349
+        return defined( $key )
350
+            || filter_input( INPUT_SERVER, $key )
351
+            || Str::contains( filter_input( INPUT_SERVER, 'SERVER_NAME' ), $key )
352
+            || Str::contains( DB_HOST, $key )
353
+            || Str::contains( php_uname(), $key );
354 354
     }
355 355
 
356 356
     /**
357 357
      * @return array
358 358
      */
359
-    protected function normalizePluginList(array $plugins)
359
+    protected function normalizePluginList( array $plugins )
360 360
     {
361
-        $plugins = array_map(function ($plugin) {
362
-            return sprintf('%s v%s', Arr::get($plugin, 'Name'), Arr::get($plugin, 'Version'));
363
-        }, $plugins);
364
-        natcasesort($plugins);
365
-        return array_flip($plugins);
361
+        $plugins = array_map( function( $plugin ) {
362
+            return sprintf( '%s v%s', Arr::get( $plugin, 'Name' ), Arr::get( $plugin, 'Version' ) );
363
+        }, $plugins );
364
+        natcasesort( $plugins );
365
+        return array_flip( $plugins );
366 366
     }
367 367
 
368 368
     /**
369 369
      * @return array
370 370
      */
371
-    protected function purgeSensitiveData(array $settings)
371
+    protected function purgeSensitiveData( array $settings )
372 372
     {
373 373
         $keys = [
374 374
             'general.trustalyze_serial',
@@ -376,12 +376,12 @@  discard block
 block discarded – undo
376 376
             'submissions.recaptcha.key',
377 377
             'submissions.recaptcha.secret',
378 378
         ];
379
-        array_walk($settings, function (&$value, $setting) use ($keys) {
380
-            foreach ($keys as $key) {
381
-                if (!Str::startsWith($key, $setting) || empty($value)) {
379
+        array_walk( $settings, function( &$value, $setting ) use ($keys) {
380
+            foreach( $keys as $key ) {
381
+                if( !Str::startsWith( $key, $setting ) || empty($value) ) {
382 382
                     continue;
383 383
                 }
384
-                $value = str_repeat('•', 13);
384
+                $value = str_repeat( '•', 13 );
385 385
                 return;
386 386
             }
387 387
         });
Please login to merge, or discard this patch.