Passed
Branch master (51607c)
by Paul
05:13
created
plugin/Modules/Email.php 1 patch
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -34,26 +34,26 @@  discard block
 block discarded – undo
34 34
 	/**
35 35
 	 * @return Email
36 36
 	 */
37
-	public function compose( array $email )
37
+	public function compose(array $email)
38 38
 	{
39
-		$email = $this->normalize( $email );
39
+		$email = $this->normalize($email);
40 40
 		$this->attachments = $email['attachments'];
41
-		$this->headers = $this->buildHeaders( $email );
42
-		$this->message = $this->buildHtmlMessage( $email );
41
+		$this->headers = $this->buildHeaders($email);
42
+		$this->message = $this->buildHtmlMessage($email);
43 43
 		$this->subject = $email['subject'];
44 44
 		$this->to = $email['to'];
45
-		add_action( 'phpmailer_init', [ $this, 'buildPlainTextMessage'] );
45
+		add_action('phpmailer_init', [$this, 'buildPlainTextMessage']);
46 46
 		return $this;
47 47
 	}
48 48
 
49 49
 	/**
50 50
 	 * @return string|null
51 51
 	 */
52
-	public function read( $plaintext = false )
52
+	public function read($plaintext = false)
53 53
 	{
54
-		if( !!$plaintext ) {
55
-			$message = $this->stripHtmlTags( $this->message );
56
-			return apply_filters( 'site-reviews/email/message', $message, 'text', $this );
54
+		if (!!$plaintext) {
55
+			$message = $this->stripHtmlTags($this->message);
56
+			return apply_filters('site-reviews/email/message', $message, 'text', $this);
57 57
 		}
58 58
 		return $this->message;
59 59
 	}
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	 */
64 64
 	public function send()
65 65
 	{
66
-		if( !$this->message || !$this->subject || !$this->to )return;
66
+		if (!$this->message || !$this->subject || !$this->to)return;
67 67
 		$sent = wp_mail(
68 68
 			$this->to,
69 69
 			$this->subject,
@@ -80,17 +80,17 @@  discard block
 block discarded – undo
80 80
 	 *
81 81
 	 * @action phpmailer_init
82 82
 	 */
83
-	public function buildPlainTextMessage( $phpmailer )
83
+	public function buildPlainTextMessage($phpmailer)
84 84
 	{
85
-		if( $phpmailer->ContentType === 'text/plain' || !empty( $phpmailer->AltBody ))return;
86
-		$message = $this->stripHtmlTags( $phpmailer->Body );
87
-		$phpmailer->AltBody = apply_filters( 'site-reviews/email/message', $message, 'text', $this );
85
+		if ($phpmailer->ContentType === 'text/plain' || !empty($phpmailer->AltBody))return;
86
+		$message = $this->stripHtmlTags($phpmailer->Body);
87
+		$phpmailer->AltBody = apply_filters('site-reviews/email/message', $message, 'text', $this);
88 88
 	}
89 89
 
90 90
 	/**
91 91
 	 * @return array
92 92
 	 */
93
-	protected function buildHeaders( $email )
93
+	protected function buildHeaders($email)
94 94
 	{
95 95
 		$allowed = [
96 96
 			'bcc',
@@ -98,52 +98,52 @@  discard block
 block discarded – undo
98 98
 			'from',
99 99
 			'reply-to',
100 100
 		];
101
-		$headers = array_intersect_key( $email, array_flip( $allowed ));
102
-		$headers = array_filter( $headers );
103
-		foreach( $headers as $key => $value ) {
104
-			unset( $headers[ $key ] );
101
+		$headers = array_intersect_key($email, array_flip($allowed));
102
+		$headers = array_filter($headers);
103
+		foreach ($headers as $key => $value) {
104
+			unset($headers[$key]);
105 105
 			$headers[] = "{$key}: {$value}";
106 106
 		}
107 107
 		$headers[] = 'Content-Type: text/html';
108
-		return apply_filters( 'site-reviews/email/headers', $headers, $this );
108
+		return apply_filters('site-reviews/email/headers', $headers, $this);
109 109
 	}
110 110
 
111 111
 	/**
112 112
 	 * @return string
113 113
 	 */
114
-	protected function buildHtmlMessage( $email )
114
+	protected function buildHtmlMessage($email)
115 115
 	{
116
-		$template = trim( glsr_get_option( 'general.notification_message' ));
117
-		if( !empty( $template )) {
118
-			$message = glsr( Template::class )->interpolate( $template, $email['template-tags'] );
116
+		$template = trim(glsr_get_option('general.notification_message'));
117
+		if (!empty($template)) {
118
+			$message = glsr(Template::class)->interpolate($template, $email['template-tags']);
119 119
 		}
120
-		else if( $email['template'] ) {
121
-			$message = glsr( Template::class )->build( 'templates/'.$email['template'], [
120
+		else if ($email['template']) {
121
+			$message = glsr(Template::class)->build('templates/'.$email['template'], [
122 122
 				'context' => $email['template-tags'],
123 123
 			]);
124 124
 		}
125
-		if( !isset( $message )) {
125
+		if (!isset($message)) {
126 126
 			$message = $email['message'];
127 127
 		}
128 128
 		$message = $email['before'].$message.$email['after'];
129
-		$message = strip_shortcodes( $message );
130
-		$message = wptexturize( $message );
131
-		$message = wpautop( $message );
132
-		$message = str_replace( '<> ', '', $message );
133
-		$message = str_replace( ']]>', ']]>', $message );
134
-		$message = glsr( Template::class )->build( 'email/index', [
129
+		$message = strip_shortcodes($message);
130
+		$message = wptexturize($message);
131
+		$message = wpautop($message);
132
+		$message = str_replace('<> ', '', $message);
133
+		$message = str_replace(']]>', ']]>', $message);
134
+		$message = glsr(Template::class)->build('email/index', [
135 135
 			'context' => ['message' => $message],
136 136
 		]);
137
-		return apply_filters( 'site-reviews/email/message', stripslashes( $message ), 'html', $this );
137
+		return apply_filters('site-reviews/email/message', stripslashes($message), 'html', $this);
138 138
 	}
139 139
 
140 140
 	/**
141 141
 	 * @return array
142 142
 	 */
143
-	protected function normalize( $email )
143
+	protected function normalize($email)
144 144
 	{
145
-		$fromName  = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
146
-		$fromEmail = get_option( 'admin_email' );
145
+		$fromName  = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
146
+		$fromEmail = get_option('admin_email');
147 147
 		$defaults = [
148 148
 			'after' => '',
149 149
 			'attachments' => [],
@@ -158,11 +158,11 @@  discard block
 block discarded – undo
158 158
 			'template-tags' => [],
159 159
 			'to' => '',
160 160
 		];
161
-		$email = shortcode_atts( $defaults, $email );
162
-		if( empty( $email['reply-to'] )) {
161
+		$email = shortcode_atts($defaults, $email);
162
+		if (empty($email['reply-to'])) {
163 163
 			$email['reply-to'] = $email['from'];
164 164
 		}
165
-		return apply_filters( 'site-reviews/email/compose', $email, $this );
165
+		return apply_filters('site-reviews/email/compose', $email, $this);
166 166
 	}
167 167
 
168 168
 	/**
@@ -180,21 +180,21 @@  discard block
 block discarded – undo
180 180
 	/**
181 181
 	 * @return string
182 182
 	 */
183
-	protected function stripHtmlTags( $string )
183
+	protected function stripHtmlTags($string)
184 184
 	{
185 185
 		// remove invisible elements
186
-		$string = preg_replace( '@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string );
186
+		$string = preg_replace('@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string);
187 187
 		// replace certain elements with a line-break
188
-		$string = preg_replace( '@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string );
188
+		$string = preg_replace('@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string);
189 189
 		// replace other elements with a space
190
-		$string = preg_replace( '@</(td|th)@iu', " \$0", $string );
190
+		$string = preg_replace('@</(td|th)@iu', " \$0", $string);
191 191
 		// add a placeholder for plain-text bullets to list elements
192
-		$string = preg_replace( '@<(li)[^>]*?>@siu', "\$0-o-^-o-", $string );
192
+		$string = preg_replace('@<(li)[^>]*?>@siu', "\$0-o-^-o-", $string);
193 193
 		// strip all remaining HTML tags
194
-		$string = wp_strip_all_tags( $string );
195
-		$string = wp_specialchars_decode( $string, ENT_QUOTES );
196
-		$string = preg_replace( '/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string );
197
-		$string = str_replace( '-o-^-o-', ' - ', $string );
198
-		return html_entity_decode( $string, ENT_QUOTES, 'UTF-8' );
194
+		$string = wp_strip_all_tags($string);
195
+		$string = wp_specialchars_decode($string, ENT_QUOTES);
196
+		$string = preg_replace('/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string);
197
+		$string = str_replace('-o-^-o-', ' - ', $string);
198
+		return html_entity_decode($string, ENT_QUOTES, 'UTF-8');
199 199
 	}
200 200
 }
Please login to merge, or discard this patch.
plugin/Modules/Logger.php 1 patch
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -20,11 +20,11 @@  discard block
 block discarded – undo
20 20
 	protected $file;
21 21
 	protected $log;
22 22
 
23
-	public function __construct( Application $app )
23
+	public function __construct(Application $app)
24 24
 	{
25
-		$this->file = $app->path( 'debug.log' );
26
-		$this->log = file_exists( $this->file )
27
-			? file_get_contents( $this->file )
25
+		$this->file = $app->path('debug.log');
26
+		$this->log = file_exists($this->file)
27
+			? file_get_contents($this->file)
28 28
 			: '';
29 29
 		$this->reset();
30 30
 	}
@@ -44,9 +44,9 @@  discard block
 block discarded – undo
44 44
 	 * @param array $context
45 45
 	 * @return static
46 46
 	 */
47
-	public function alert( $message, array $context = [] )
47
+	public function alert($message, array $context = [])
48 48
 	{
49
-		return $this->log( static::ALERT, $message, $context );
49
+		return $this->log(static::ALERT, $message, $context);
50 50
 	}
51 51
 
52 52
 	/**
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	public function clear()
56 56
 	{
57 57
 		$this->log = '';
58
-		file_put_contents( $this->file, $this->log );
58
+		file_put_contents($this->file, $this->log);
59 59
 	}
60 60
 
61 61
 	/**
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
 	 * @param array $context
66 66
 	 * @return static
67 67
 	 */
68
-	public function critical( $message, array $context = [] )
68
+	public function critical($message, array $context = [])
69 69
 	{
70
-		return $this->log( static::CRITICAL, $message, $context );
70
+		return $this->log(static::CRITICAL, $message, $context);
71 71
 	}
72 72
 
73 73
 	/**
@@ -76,9 +76,9 @@  discard block
 block discarded – undo
76 76
 	 * @param array $context
77 77
 	 * @return static
78 78
 	 */
79
-	public function debug( $message, array $context = [] )
79
+	public function debug($message, array $context = [])
80 80
 	{
81
-		return $this->log( static::DEBUG, $message, $context );
81
+		return $this->log(static::DEBUG, $message, $context);
82 82
 	}
83 83
 
84 84
 	/**
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
 	 * @param array $context
88 88
 	 * @return static
89 89
 	 */
90
-	public function emergency( $message, array $context = [] )
90
+	public function emergency($message, array $context = [])
91 91
 	{
92
-		return $this->log( static::EMERGENCY, $message, $context );
92
+		return $this->log(static::EMERGENCY, $message, $context);
93 93
 	}
94 94
 
95 95
 	/**
@@ -98,9 +98,9 @@  discard block
 block discarded – undo
98 98
 	 * @param array $context
99 99
 	 * @return static
100 100
 	 */
101
-	public function error( $message, array $context = [] )
101
+	public function error($message, array $context = [])
102 102
 	{
103
-		return $this->log( static::ERROR, $message, $context );
103
+		return $this->log(static::ERROR, $message, $context);
104 104
 	}
105 105
 
106 106
 	/**
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 	 */
109 109
 	public function get()
110 110
 	{
111
-		return empty( $this->log )
112
-			? __( 'Log is empty', 'site-reviews' )
111
+		return empty($this->log)
112
+			? __('Log is empty', 'site-reviews')
113 113
 			: $this->log;
114 114
 	}
115 115
 
@@ -120,9 +120,9 @@  discard block
 block discarded – undo
120 120
 	 * @param array $context
121 121
 	 * @return static
122 122
 	 */
123
-	public function info( $message, array $context = [] )
123
+	public function info($message, array $context = [])
124 124
 	{
125
-		return $this->log( static::INFO, $message, $context );
125
+		return $this->log(static::INFO, $message, $context);
126 126
 	}
127 127
 
128 128
 	/**
@@ -130,13 +130,13 @@  discard block
 block discarded – undo
130 130
 	 * @param string $message
131 131
 	 * @return static
132 132
 	 */
133
-	public function log( $level, $message, array $context = [] )
133
+	public function log($level, $message, array $context = [])
134 134
 	{
135
-		$constants = (new ReflectionClass( __CLASS__ ))->getConstants();
136
-		$constants = (array)apply_filters( Application::ID.'/log-levels', $constants );
137
-		if( in_array( $level, $constants, true )) {
138
-			$entry = $this->buildLogEntry( $level, $message, $context );
139
-			file_put_contents( $this->file, $entry, FILE_APPEND|LOCK_EX );
135
+		$constants = (new ReflectionClass(__CLASS__))->getConstants();
136
+		$constants = (array)apply_filters(Application::ID.'/log-levels', $constants);
137
+		if (in_array($level, $constants, true)) {
138
+			$entry = $this->buildLogEntry($level, $message, $context);
139
+			file_put_contents($this->file, $entry, FILE_APPEND | LOCK_EX);
140 140
 			$this->reset();
141 141
 		}
142 142
 		return $this;
@@ -148,9 +148,9 @@  discard block
 block discarded – undo
148 148
 	 * @param array $context
149 149
 	 * @return static
150 150
 	 */
151
-	public function notice( $message, array $context = [] )
151
+	public function notice($message, array $context = [])
152 152
 	{
153
-		return $this->log( static::NOTICE, $message, $context );
153
+		return $this->log(static::NOTICE, $message, $context);
154 154
 	}
155 155
 
156 156
 	/**
@@ -160,9 +160,9 @@  discard block
 block discarded – undo
160 160
 	 * @param array $context
161 161
 	 * @return static
162 162
 	 */
163
-	public function warning( $message, array $context = [] )
163
+	public function warning($message, array $context = [])
164 164
 	{
165
-		return $this->log( static::WARNING, $message, $context );
165
+		return $this->log(static::WARNING, $message, $context);
166 166
 	}
167 167
 
168 168
 	/**
@@ -170,13 +170,13 @@  discard block
 block discarded – undo
170 170
 	 * @param string $message
171 171
 	 * @return string
172 172
 	 */
173
-	protected function buildLogEntry( $level, $message, array $context = [] )
173
+	protected function buildLogEntry($level, $message, array $context = [])
174 174
 	{
175
-		return sprintf( '[%s] %s: %s%s'.PHP_EOL,
176
-			current_time( 'mysql' ),
177
-			strtoupper( $level ),
175
+		return sprintf('[%s] %s: %s%s'.PHP_EOL,
176
+			current_time('mysql'),
177
+			strtoupper($level),
178 178
 			$this->getDebugInformation(),
179
-			$this->interpolate( $message, $context )
179
+			$this->interpolate($message, $context)
180 180
 		);
181 181
 	}
182 182
 
@@ -185,16 +185,16 @@  discard block
 block discarded – undo
185 185
 	 */
186 186
 	protected function getDebugInformation()
187 187
 	{
188
-		$caller = debug_backtrace( false, 6 );
189
-		$index = array_search( 'log', array_column( $caller, 'function' ));
190
-		if( $index === false
191
-			|| !isset( $caller[$index+2]['class'] )
192
-			|| !isset( $caller[$index+2]['function'] )
188
+		$caller = debug_backtrace(false, 6);
189
+		$index = array_search('log', array_column($caller, 'function'));
190
+		if ($index === false
191
+			|| !isset($caller[$index + 2]['class'])
192
+			|| !isset($caller[$index + 2]['function'])
193 193
 		)return;
194
-		return sprintf( '[%s()->%s:%s] ',
195
-			$caller[$index+2]['class'],
196
-			$caller[$index+2]['function'],
197
-			$caller[$index+1]['line']
194
+		return sprintf('[%s()->%s:%s] ',
195
+			$caller[$index + 2]['class'],
196
+			$caller[$index + 2]['function'],
197
+			$caller[$index + 1]['line']
198 198
 		);
199 199
 	}
200 200
 
@@ -204,38 +204,38 @@  discard block
 block discarded – undo
204 204
 	 * @param array $context
205 205
 	 * @return array|string
206 206
 	 */
207
-	protected function interpolate( $message, $context = [] )
207
+	protected function interpolate($message, $context = [])
208 208
 	{
209
-		if( $this->isObjectOrArray( $message ) || !is_array( $context )) {
210
-			return print_r( $message, true );
209
+		if ($this->isObjectOrArray($message) || !is_array($context)) {
210
+			return print_r($message, true);
211 211
 		}
212 212
 		$replace = [];
213
-		foreach( $context as $key => $value ) {
214
-			$replace['{'.$key.'}'] = $this->normalizeValue( $value );
213
+		foreach ($context as $key => $value) {
214
+			$replace['{'.$key.'}'] = $this->normalizeValue($value);
215 215
 		}
216
-		return strtr( $message, $replace );
216
+		return strtr($message, $replace);
217 217
 	}
218 218
 
219 219
 	/**
220 220
 	 * @param mixed $value
221 221
 	 * @return bool
222 222
 	 */
223
-	protected function isObjectOrArray( $value )
223
+	protected function isObjectOrArray($value)
224 224
 	{
225
-		return is_object( $value ) || is_array( $value );
225
+		return is_object($value) || is_array($value);
226 226
 	}
227 227
 
228 228
 	/**
229 229
 	 * @param mixed $value
230 230
 	 * @return string
231 231
 	 */
232
-	protected function normalizeValue( $value )
232
+	protected function normalizeValue($value)
233 233
 	{
234
-		if( $value instanceof DateTime ) {
235
-			$value = $value->format( 'Y-m-d H:i:s' );
234
+		if ($value instanceof DateTime) {
235
+			$value = $value->format('Y-m-d H:i:s');
236 236
 		}
237
-		else if( $this->isObjectOrArray( $value )) {
238
-			$value = json_encode( $value );
237
+		else if ($this->isObjectOrArray($value)) {
238
+			$value = json_encode($value);
239 239
 		}
240 240
 		return (string)$value;
241 241
 	}
@@ -245,12 +245,12 @@  discard block
 block discarded – undo
245 245
 	 */
246 246
 	protected function reset()
247 247
 	{
248
-		if( file_exists( $this->file )
249
-			&& filesize( $this->file ) > pow( 1024, 2 ) / 2 ) {
248
+		if (file_exists($this->file)
249
+			&& filesize($this->file) > pow(1024, 2) / 2) {
250 250
 			$this->clear();
251 251
 			file_put_contents(
252 252
 				$this->file,
253
-				$this->buildLogEntry( 'info', __( 'Log has been automatically reset (512 KB max size)', 'site-reviews' ))
253
+				$this->buildLogEntry('info', __('Log has been automatically reset (512 KB max size)', 'site-reviews'))
254 254
 			);
255 255
 		}
256 256
 	}
Please login to merge, or discard this patch.
plugin/Modules/Notice.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -13,39 +13,39 @@  discard block
 block discarded – undo
13 13
 	 * @param string|array|WP_Error $message
14 14
 	 * @return void
15 15
 	 */
16
-	public function add( $type, $message, array $args = [] )
16
+	public function add($type, $message, array $args = [])
17 17
 	{
18
-		if( empty( array_filter( [$message, $type] )))return;
18
+		if (empty(array_filter([$message, $type])))return;
19 19
 		$args['message'] = $message;
20 20
 		$args['type'] = $type;
21
-		add_settings_error( Application::ID, '', json_encode( $this->normalize( $args )));
21
+		add_settings_error(Application::ID, '', json_encode($this->normalize($args)));
22 22
 	}
23 23
 
24 24
 	/**
25 25
 	 * @param string|array|WP_Error $message
26 26
 	 * @return void
27 27
 	 */
28
-	public function addError( $message, array $args = [] )
28
+	public function addError($message, array $args = [])
29 29
 	{
30
-		$this->add( 'error', $message, $args );
30
+		$this->add('error', $message, $args);
31 31
 	}
32 32
 
33 33
 	/**
34 34
 	 * @param string|array|WP_Error $message
35 35
 	 * @return void
36 36
 	 */
37
-	public function addSuccess( $message, array $args = [] )
37
+	public function addSuccess($message, array $args = [])
38 38
 	{
39
-		$this->add( 'success', $message, $args );
39
+		$this->add('success', $message, $args);
40 40
 	}
41 41
 
42 42
 	/**
43 43
 	 * @param string|array|WP_Error $message
44 44
 	 * @return void
45 45
 	 */
46
-	public function addWarning( $message, array $args = [] )
46
+	public function addWarning($message, array $args = [])
47 47
 	{
48
-		$this->add( 'warning', $message, $args );
48
+		$this->add('warning', $message, $args);
49 49
 	}
50 50
 
51 51
 	/**
@@ -53,31 +53,31 @@  discard block
 block discarded – undo
53 53
 	 */
54 54
 	public function get()
55 55
 	{
56
-		$notices = array_map( 'unserialize',
57
-			array_unique( array_map( 'serialize', get_settings_errors( Application::ID )))
56
+		$notices = array_map('unserialize',
57
+			array_unique(array_map('serialize', get_settings_errors(Application::ID)))
58 58
 		);
59
-		if( empty( $notices ))return;
60
-		return array_reduce( $notices, function( $carry, $notice ) {
61
-			return $carry.$this->buildNotice( json_decode( $notice['message'], true ));
59
+		if (empty($notices))return;
60
+		return array_reduce($notices, function($carry, $notice) {
61
+			return $carry.$this->buildNotice(json_decode($notice['message'], true));
62 62
 		});
63 63
 	}
64 64
 
65 65
 	/**
66 66
 	 * @return string
67 67
 	 */
68
-	protected function buildNotice( array $args )
68
+	protected function buildNotice(array $args)
69 69
 	{
70
-		$messages = array_reduce( $args['messages'], function( $carry, $message ) {
71
-			return $carry.glsr( Builder::class )->p( $message );
70
+		$messages = array_reduce($args['messages'], function($carry, $message) {
71
+			return $carry.glsr(Builder::class)->p($message);
72 72
 		});
73 73
 		$class = 'notice notice-'.$args['type'];
74
-		if( $args['inline'] ) {
74
+		if ($args['inline']) {
75 75
 			$class .= ' inline';
76 76
 		}
77
-		if( $args['dismissible'] ) {
77
+		if ($args['dismissible']) {
78 78
 			$class .= ' is-dismissible';
79 79
 		}
80
-		return glsr( Builder::class )->div( $messages, [
80
+		return glsr(Builder::class)->div($messages, [
81 81
 			'class' => $class,
82 82
 		]);
83 83
 	}
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 	/**
86 86
 	 * @return array
87 87
 	 */
88
-	protected function normalize( array $args )
88
+	protected function normalize(array $args)
89 89
 	{
90 90
 		$defaults = [
91 91
 			'dismissible' => true,
@@ -93,14 +93,14 @@  discard block
 block discarded – undo
93 93
 			'message' => '',
94 94
 			'type' => '',
95 95
 		];
96
-		$args = shortcode_atts( $defaults, $args );
97
-		if( !in_array( $args['type'], ['error', 'warning', 'success'] )) {
96
+		$args = shortcode_atts($defaults, $args);
97
+		if (!in_array($args['type'], ['error', 'warning', 'success'])) {
98 98
 			$args['type'] = 'success';
99 99
 		}
100
-		$args['messages'] = is_wp_error( $args['message'] )
100
+		$args['messages'] = is_wp_error($args['message'])
101 101
 			? (array)$args['message']->get_error_message()
102 102
 			: (array)$args['message'];
103
-		unset( $args['message'] );
103
+		unset($args['message']);
104 104
 		return $args;
105 105
 	}
106 106
 }
Please login to merge, or discard this patch.
plugin/Modules/Date.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -26,24 +26,24 @@
 block discarded – undo
26 26
 	/**
27 27
 	 * @return string
28 28
 	 */
29
-	public function relative( $date )
29
+	public function relative($date)
30 30
 	{
31
-		$diff = time() - strtotime( $date );
32
-		foreach( static::$TIME_PERIODS as $i => $timePeriod ) {
33
-			if( $diff > $timePeriod[0] )continue;
34
-			$unit = floor( $diff / $timePeriod[1] );
31
+		$diff = time() - strtotime($date);
32
+		foreach (static::$TIME_PERIODS as $i => $timePeriod) {
33
+			if ($diff > $timePeriod[0])continue;
34
+			$unit = floor($diff / $timePeriod[1]);
35 35
 			$relativeDates = [
36
-				_n( '%s second ago', '%s seconds ago', $unit, 'site-reviews' ),
37
-				_n( '%s minute ago', '%s minutes ago', $unit, 'site-reviews' ),
38
-				_n( 'an hour ago', '%s hours ago', $unit, 'site-reviews' ),
39
-				_n( 'yesterday', '%s days ago', $unit, 'site-reviews' ),
40
-				_n( 'a week ago', '%s weeks ago', $unit, 'site-reviews' ),
41
-				_n( '%s month ago', '%s months ago', $unit, 'site-reviews' ),
42
-				_n( '%s year ago', '%s years ago', $unit, 'site-reviews' ),
36
+				_n('%s second ago', '%s seconds ago', $unit, 'site-reviews'),
37
+				_n('%s minute ago', '%s minutes ago', $unit, 'site-reviews'),
38
+				_n('an hour ago', '%s hours ago', $unit, 'site-reviews'),
39
+				_n('yesterday', '%s days ago', $unit, 'site-reviews'),
40
+				_n('a week ago', '%s weeks ago', $unit, 'site-reviews'),
41
+				_n('%s month ago', '%s months ago', $unit, 'site-reviews'),
42
+				_n('%s year ago', '%s years ago', $unit, 'site-reviews'),
43 43
 			];
44 44
 			$relativeDate = $relativeDates[$i];
45
-			return strpos( $relativeDate, '%s' ) !== false
46
-				? sprintf( $relativeDate, $unit )
45
+			return strpos($relativeDate, '%s') !== false
46
+				? sprintf($relativeDate, $unit)
47 47
 				: $relativeDate;
48 48
 		}
49 49
 	}
Please login to merge, or discard this patch.
plugin/Modules/System.php 1 patch
Spacing   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -29,14 +29,14 @@  discard block
 block discarded – undo
29 29
 			'inactive-plugin' => 'Inactive Plugins',
30 30
 			'setting' => 'Plugin Settings',
31 31
 		];
32
-		$systemInfo = array_reduce( array_keys( $details ), function( $carry, $key ) use( $details ) {
33
-			$methodName = glsr( Helper::class )->buildMethodName( 'get-'.$key.'-details' );
34
-			if( method_exists( $this, $methodName ) && $systemDetails = $this->$methodName() ) {
35
-				return $carry.$this->implode( $details[$key], $systemDetails );
32
+		$systemInfo = array_reduce(array_keys($details), function($carry, $key) use($details) {
33
+			$methodName = glsr(Helper::class)->buildMethodName('get-'.$key.'-details');
34
+			if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) {
35
+				return $carry.$this->implode($details[$key], $systemDetails);
36 36
 			}
37 37
 			return $carry;
38 38
 		});
39
-		return trim( $systemInfo );
39
+		return trim($systemInfo);
40 40
 	}
41 41
 
42 42
 	/**
@@ -45,9 +45,9 @@  discard block
 block discarded – undo
45 45
 	public function getActivePluginDetails()
46 46
 	{
47 47
 		$plugins = get_plugins();
48
-		$activePlugins = (array)get_option( 'active_plugins', [] );
49
-		$inactive = array_diff_key( $plugins, array_flip( $activePlugins ));
50
-		return $this->normalizePluginList( array_diff_key( $plugins, $inactive ));
48
+		$activePlugins = (array)get_option('active_plugins', []);
49
+		$inactive = array_diff_key($plugins, array_flip($activePlugins));
50
+		return $this->normalizePluginList(array_diff_key($plugins, $inactive));
51 51
 	}
52 52
 
53 53
 	/**
@@ -56,11 +56,11 @@  discard block
 block discarded – undo
56 56
 	public function getBrowserDetails()
57 57
 	{
58 58
 		$browser = new Browser;
59
-		$name = esc_attr( $browser->getName() );
60
-		$userAgent = esc_attr( $browser->getUserAgent()->getUserAgentString() );
61
-		$version = esc_attr( $browser->getVersion() );
59
+		$name = esc_attr($browser->getName());
60
+		$userAgent = esc_attr($browser->getUserAgent()->getUserAgentString());
61
+		$version = esc_attr($browser->getVersion());
62 62
 		return [
63
-			'Browser Name' => sprintf( '%s %s', $name, $version ),
63
+			'Browser Name' => sprintf('%s %s', $name, $version),
64 64
 			'Browser UA' => $userAgent,
65 65
 		];
66 66
 	}
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
 	 */
71 71
 	public function getInactivePluginDetails()
72 72
 	{
73
-		$activePlugins = (array)get_option( 'active_plugins', [] );
74
-		return $this->normalizePluginList( array_diff_key( get_plugins(), array_flip( $activePlugins )));
73
+		$activePlugins = (array)get_option('active_plugins', []);
74
+		return $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins)));
75 75
 	}
76 76
 
77 77
 	/**
@@ -81,10 +81,10 @@  discard block
 block discarded – undo
81 81
 	{
82 82
 		$plugins = array_merge(
83 83
 			get_mu_plugins(),
84
-			get_plugins( '/../'.basename( WPMU_PLUGIN_DIR ))
84
+			get_plugins('/../'.basename(WPMU_PLUGIN_DIR))
85 85
 		);
86
-		if( empty( $plugins ))return;
87
-		return $this->normalizePluginList( $plugins );
86
+		if (empty($plugins))return;
87
+		return $this->normalizePluginList($plugins);
88 88
 	}
89 89
 
90 90
 	/**
@@ -92,8 +92,8 @@  discard block
 block discarded – undo
92 92
 	 */
93 93
 	public function getMultisitePluginDetails()
94 94
 	{
95
-		if( !is_multisite() || empty( get_site_option( 'active_sitewide_plugins', [] )))return;
96
-		return $this->normalizePluginList( wp_get_active_network_plugins() );
95
+		if (!is_multisite() || empty(get_site_option('active_sitewide_plugins', [])))return;
96
+		return $this->normalizePluginList(wp_get_active_network_plugins());
97 97
 	}
98 98
 
99 99
 	/**
@@ -101,25 +101,25 @@  discard block
 block discarded – undo
101 101
 	 */
102 102
 	public function getPhpDetails()
103 103
 	{
104
-		$displayErrors = ini_get( 'display_errors' )
105
-			? 'On ('.ini_get( 'display_errors' ).')'
104
+		$displayErrors = ini_get('display_errors')
105
+			? 'On ('.ini_get('display_errors').')'
106 106
 			: 'N/A';
107 107
 		return [
108
-			'cURL' => var_export( function_exists( 'curl_init' ), 1 ),
109
-			'Default Charset' => ini_get( 'default_charset' ),
108
+			'cURL' => var_export(function_exists('curl_init'), 1),
109
+			'Default Charset' => ini_get('default_charset'),
110 110
 			'Display Errors' => $displayErrors,
111
-			'fsockopen' => var_export( function_exists( 'fsockopen' ), 1 ),
112
-			'Max Execution Time' => ini_get( 'max_execution_time' ),
113
-			'Max Input Nesting Level' => ini_get( 'max_input_nesting_level' ),
114
-			'Max Input Vars' => ini_get( 'max_input_vars' ),
115
-			'Memory Limit' => ini_get( 'memory_limit' ),
116
-			'Post Max Size' => ini_get( 'post_max_size' ),
117
-			'Session Cookie Path' => esc_html( ini_get( 'session.cookie_path' )),
118
-			'Session Name' => esc_html( ini_get( 'session.name' )),
119
-			'Session Save Path' => esc_html( ini_get( 'session.save_path' )),
120
-			'Session Use Cookies' => var_export( wp_validate_boolean( ini_get( 'session.use_cookies' )), 1 ),
121
-			'Session Use Only Cookies' => var_export( wp_validate_boolean( ini_get( 'session.use_only_cookies' )), 1 ),
122
-			'Upload Max Filesize' => ini_get( 'upload_max_filesize' ),
111
+			'fsockopen' => var_export(function_exists('fsockopen'), 1),
112
+			'Max Execution Time' => ini_get('max_execution_time'),
113
+			'Max Input Nesting Level' => ini_get('max_input_nesting_level'),
114
+			'Max Input Vars' => ini_get('max_input_vars'),
115
+			'Memory Limit' => ini_get('memory_limit'),
116
+			'Post Max Size' => ini_get('post_max_size'),
117
+			'Session Cookie Path' => esc_html(ini_get('session.cookie_path')),
118
+			'Session Name' => esc_html(ini_get('session.name')),
119
+			'Session Save Path' => esc_html(ini_get('session.save_path')),
120
+			'Session Use Cookies' => var_export(wp_validate_boolean(ini_get('session.use_cookies')), 1),
121
+			'Session Use Only Cookies' => var_export(wp_validate_boolean(ini_get('session.use_only_cookies')), 1),
122
+			'Upload Max Filesize' => ini_get('upload_max_filesize'),
123 123
 		];
124 124
 	}
125 125
 
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 			'Host Name' => $this->getHostName(),
134 134
 			'MySQL Version' => $wpdb->db_version(),
135 135
 			'PHP Version' => PHP_VERSION,
136
-			'Server Software' => filter_input( INPUT_SERVER, 'SERVER_SOFTWARE' ),
136
+			'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'),
137 137
 		];
138 138
 	}
139 139
 
@@ -142,17 +142,17 @@  discard block
 block discarded – undo
142 142
 	 */
143 143
 	public function getSettingDetails()
144 144
 	{
145
-		$helper = glsr( Helper::class );
146
-		$settings = glsr( OptionManager::class )->get( 'settings' );
147
-		$settings = $helper->flattenArray( $settings );
148
-		foreach( ['submissions.recaptcha.key', 'submissions.recaptcha.secret'] as $key ) {
149
-			if( empty( $settings[$key] ))continue;
150
-			$settings[$key] = str_repeat( '*', 10 );
145
+		$helper = glsr(Helper::class);
146
+		$settings = glsr(OptionManager::class)->get('settings');
147
+		$settings = $helper->flattenArray($settings);
148
+		foreach (['submissions.recaptcha.key', 'submissions.recaptcha.secret'] as $key) {
149
+			if (empty($settings[$key]))continue;
150
+			$settings[$key] = str_repeat('*', 10);
151 151
 		}
152 152
 		$details = [];
153
-		foreach( $settings as $key => $value ) {
154
-			if( $helper->startsWith( 'translations', $key ) && $helper->endsWith( 'id', $key ))continue;
155
-			$value = htmlspecialchars( trim( preg_replace('/\s\s+/', '\\n', $value )), ENT_QUOTES, 'UTF-8' );
153
+		foreach ($settings as $key => $value) {
154
+			if ($helper->startsWith('translations', $key) && $helper->endsWith('id', $key))continue;
155
+			$value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8');
156 156
 			$details[$key] = $value;
157 157
 		}
158 158
 		return $details;
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	{
166 166
 		return [
167 167
 			'Current version' => glsr()->version,
168
-			'Previous version' => glsr( OptionManager::class )->get( 'version_upgraded_from' ),
168
+			'Previous version' => glsr(OptionManager::class)->get('version_upgraded_from'),
169 169
 		];
170 170
 	}
171 171
 
@@ -177,22 +177,22 @@  discard block
 block discarded – undo
177 177
 		global $wpdb;
178 178
 		$theme = wp_get_theme();
179 179
 		return [
180
-			'Active Theme' => sprintf( '%s v%s', $theme->Name, $theme->Version ),
180
+			'Active Theme' => sprintf('%s v%s', $theme->Name, $theme->Version),
181 181
 			'Home URL' => home_url(),
182
-			'Language' => get_option( 'WPLANG', 'en_US' ),
182
+			'Language' => get_option('WPLANG', 'en_US'),
183 183
 			'Memory Limit' => WP_MEMORY_LIMIT,
184
-			'Multisite' => var_export( is_multisite(), 1 ),
185
-			'Page For Posts ID' => get_option( 'page_for_posts' ),
186
-			'Page On Front ID' => get_option( 'page_on_front' ),
187
-			'Permalink Structure' => get_option( 'permalink_structure', 'default' ),
188
-			'Post Stati' => implode( ', ', get_post_stati() ),
184
+			'Multisite' => var_export(is_multisite(), 1),
185
+			'Page For Posts ID' => get_option('page_for_posts'),
186
+			'Page On Front ID' => get_option('page_on_front'),
187
+			'Permalink Structure' => get_option('permalink_structure', 'default'),
188
+			'Post Stati' => implode(', ', get_post_stati()),
189 189
 			'Remote Post' => $this->testRemotePost(),
190
-			'Show On Front' => get_option( 'show_on_front' ),
190
+			'Show On Front' => get_option('show_on_front'),
191 191
 			'Site URL' => site_url(),
192
-			'Timezone' => get_option( 'timezone_string' ),
193
-			'Version' => get_bloginfo( 'version' ),
194
-			'WP Debug' => var_export( defined( 'WP_DEBUG' ), 1 ),
195
-			'WP Max Upload Size' => size_format( wp_max_upload_size() ),
192
+			'Timezone' => get_option('timezone_string'),
193
+			'Version' => get_bloginfo('version'),
194
+			'WP Debug' => var_export(defined('WP_DEBUG'), 1),
195
+			'WP Max Upload Size' => size_format(wp_max_upload_size()),
196 196
 			'WP Memory Limit' => WP_MEMORY_LIMIT,
197 197
 		];
198 198
 	}
@@ -222,17 +222,17 @@  discard block
 block discarded – undo
222 222
 			'secureserver.net' => 'GoDaddy',
223 223
 			'WPE_APIKEY' => 'WP Engine',
224 224
 		];
225
-		$serverName = filter_input( INPUT_SERVER, 'SERVER_NAME' );
226
-		foreach( $checks as $key => $value ) {
227
-			if( defined( $key )
228
-				|| filter_input( INPUT_SERVER, $key )
229
-				|| strpos( $serverName, $key ) !== false
230
-				|| strpos( DB_HOST, $key ) !== false
231
-				|| strpos( php_uname(), $key ) !== false ) {
225
+		$serverName = filter_input(INPUT_SERVER, 'SERVER_NAME');
226
+		foreach ($checks as $key => $value) {
227
+			if (defined($key)
228
+				|| filter_input(INPUT_SERVER, $key)
229
+				|| strpos($serverName, $key) !== false
230
+				|| strpos(DB_HOST, $key) !== false
231
+				|| strpos(php_uname(), $key) !== false) {
232 232
 				return $host;
233 233
 			}
234 234
 		}
235
-		return implode( ',', array_filter( [DB_HOST, $serverName] ));
235
+		return implode(',', array_filter([DB_HOST, $serverName]));
236 236
 	}
237 237
 
238 238
 	/**
@@ -240,9 +240,9 @@  discard block
 block discarded – undo
240 240
 	 */
241 241
 	protected function getHostName()
242 242
 	{
243
-		return sprintf( '%s (%s)',
243
+		return sprintf('%s (%s)',
244 244
 			$this->detectWebhostProvider(),
245
-			glsr( Helper::class )->getIpAddress()
245
+			glsr(Helper::class)->getIpAddress()
246 246
 		);
247 247
 	}
248 248
 
@@ -252,9 +252,9 @@  discard block
 block discarded – undo
252 252
 	protected function getWordpressPlugins()
253 253
 	{
254 254
 		$plugins = get_plugins();
255
-		$activePlugins = (array)get_option( 'active_plugins', [] );
256
-		$inactive = $this->normalizePluginList( array_diff_key( $plugins, array_flip( $activePlugins )));
257
-		$active = $this->normalizePluginList( array_diff_key( $plugins, $inactive ));
255
+		$activePlugins = (array)get_option('active_plugins', []);
256
+		$inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins)));
257
+		$active = $this->normalizePluginList(array_diff_key($plugins, $inactive));
258 258
 		return $active + $inactive;
259 259
 	}
260 260
 
@@ -262,29 +262,29 @@  discard block
 block discarded – undo
262 262
 	 * @param string $title
263 263
 	 * @return string
264 264
 	 */
265
-	protected function implode( $title, array $details )
265
+	protected function implode($title, array $details)
266 266
 	{
267 267
 		$strings = ['['.$title.']'];
268
-		$padding = max( array_map( 'strlen', array_keys( $details )) );
269
-		$padding = max( [$padding, static::PAD] );
270
-		foreach( $details as $key => $value ) {
271
-			$strings[] = is_string( $key )
272
-				? sprintf( '%s : %s', str_pad( $key.' ', $padding, '.' ), $value )
268
+		$padding = max(array_map('strlen', array_keys($details)));
269
+		$padding = max([$padding, static::PAD]);
270
+		foreach ($details as $key => $value) {
271
+			$strings[] = is_string($key)
272
+				? sprintf('%s : %s', str_pad($key.' ', $padding, '.'), $value)
273 273
 				: ' - '.$value;
274 274
 		}
275
-		return implode( PHP_EOL, $strings ).PHP_EOL.PHP_EOL;
275
+		return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL;
276 276
 	}
277 277
 
278 278
 	/**
279 279
 	 * @return array
280 280
 	 */
281
-	protected function normalizePluginList( array $plugins )
281
+	protected function normalizePluginList(array $plugins)
282 282
 	{
283
-		$plugins = array_map( function( $plugin ) {
284
-			return sprintf( '%s v%s', $plugin['Name'], $plugin['Version'] );
285
-		}, $plugins );
286
-		natcasesort( $plugins );
287
-		return array_flip( $plugins );
283
+		$plugins = array_map(function($plugin) {
284
+			return sprintf('%s v%s', $plugin['Name'], $plugin['Version']);
285
+		}, $plugins);
286
+		natcasesort($plugins);
287
+		return array_flip($plugins);
288 288
 	}
289 289
 
290 290
 	/**
@@ -292,10 +292,10 @@  discard block
 block discarded – undo
292 292
 	 */
293 293
 	protected function testRemotePost()
294 294
 	{
295
-		$response = wp_remote_post( static::WP_API_URL );
296
-		return !is_wp_error( $response )
297
-			&& !empty( $response['response']['code'] )
298
-			&& in_array( $response['response']['code'], range( 200, 299 ))
295
+		$response = wp_remote_post(static::WP_API_URL);
296
+		return !is_wp_error($response)
297
+			&& !empty($response['response']['code'])
298
+			&& in_array($response['response']['code'], range(200, 299))
299 299
 			? 'Works'
300 300
 			: 'Does not work';
301 301
 	}
Please login to merge, or discard this patch.
plugin/Modules/Session.php 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -33,12 +33,12 @@  discard block
 block discarded – undo
33 33
 
34 34
 	public function __construct()
35 35
 	{
36
-		if( $cookieId = filter_input( INPUT_COOKIE, static::SESSION_COOKIE )) {
37
-			$cookie = explode( '||', stripslashes( $cookieId ));
38
-			$this->sessionId = preg_replace( '/[^A-Za-z0-9_]/', '', $cookie[0] );
39
-			$this->expiryTimestamp = absint( $cookie[1] );
40
-			$this->expiryTimestampReset = absint( $cookie[2] );
41
-			if( time() > $this->expiryTimestampReset ) {
36
+		if ($cookieId = filter_input(INPUT_COOKIE, static::SESSION_COOKIE)) {
37
+			$cookie = explode('||', stripslashes($cookieId));
38
+			$this->sessionId = preg_replace('/[^A-Za-z0-9_]/', '', $cookie[0]);
39
+			$this->expiryTimestamp = absint($cookie[1]);
40
+			$this->expiryTimestampReset = absint($cookie[2]);
41
+			if (time() > $this->expiryTimestampReset) {
42 42
 				$this->setCookieExpiration();
43 43
 			}
44 44
 		}
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 		}
49 49
 		$this->getSessionData();
50 50
 		$this->setCookie();
51
-		add_action( 'site-reviews/schedule/session/purge', [$this, 'deleteExpiredSessions'] );
51
+		add_action('site-reviews/schedule/session/purge', [$this, 'deleteExpiredSessions']);
52 52
 	}
53 53
 
54 54
 	/**
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 	public function clear()
58 58
 	{
59 59
 		$this->setCookieExpiration();
60
-		$this->regenerateSessionId( 'and delete session!' );
60
+		$this->regenerateSessionId('and delete session!');
61 61
 	}
62 62
 
63 63
 	/**
@@ -75,10 +75,10 @@  discard block
 block discarded – undo
75 75
 	 * @param int $limit
76 76
 	 * @return void
77 77
 	 */
78
-	public function deleteExpiredSessions( $limit = 1000 )
78
+	public function deleteExpiredSessions($limit = 1000)
79 79
 	{
80 80
 		global $wpdb;
81
-		if( $expiredSessions = implode( "','", $this->getExpiredSessions( $limit ))) {
81
+		if ($expiredSessions = implode("','", $this->getExpiredSessions($limit))) {
82 82
 			$wpdb->query(
83 83
 				"DELETE FROM {$wpdb->options} WHERE option_name IN ('{$expiredSessions}')"
84 84
 			);
@@ -91,14 +91,14 @@  discard block
 block discarded – undo
91 91
 	 * @param bool|string $unset
92 92
 	 * @return string
93 93
 	 */
94
-	public function get( $key, $fallback = '', $unset = false )
94
+	public function get($key, $fallback = '', $unset = false)
95 95
 	{
96
-		$key = sanitize_key( $key );
97
-		$value = isset( $this->sessionData[$key] )
98
-			? maybe_unserialize( $this->sessionData[$key] )
96
+		$key = sanitize_key($key);
97
+		$value = isset($this->sessionData[$key])
98
+			? maybe_unserialize($this->sessionData[$key])
99 99
 			: $fallback;
100
-		if( isset( $this->sessionData[$key] ) && $unset ) {
101
-			unset( $this->sessionData[$key] );
100
+		if (isset($this->sessionData[$key]) && $unset) {
101
+			unset($this->sessionData[$key]);
102 102
 			$this->updateSession();
103 103
 		}
104 104
 		return $value;
@@ -109,10 +109,10 @@  discard block
 block discarded – undo
109 109
 	 * @param mixed $value
110 110
 	 * @return mixed
111 111
 	 */
112
-	public function set( $key, $value )
112
+	public function set($key, $value)
113 113
 	{
114
-		$key = sanitize_key( $key );
115
-		$this->sessionData[$key] = maybe_serialize( $value );
114
+		$key = sanitize_key($key);
115
+		$this->sessionData[$key] = maybe_serialize($value);
116 116
 		$this->updateSession();
117 117
 		return $this->sessionData[$key];
118 118
 	}
@@ -122,8 +122,8 @@  discard block
 block discarded – undo
122 122
 	 */
123 123
 	protected function createSession()
124 124
 	{
125
-		add_option( $this->getSessionId(), $this->sessionData, '', false );
126
-		add_option( $this->getSessionId( 'expires' ), $this->expiryTimestamp, '', false );
125
+		add_option($this->getSessionId(), $this->sessionData, '', false);
126
+		add_option($this->getSessionId('expires'), $this->expiryTimestamp, '', false);
127 127
 	}
128 128
 
129 129
 	/**
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
 	 */
132 132
 	protected function deleteSession()
133 133
 	{
134
-		delete_option( $this->getSessionId() );
135
-		delete_option( $this->getSessionId( 'expires' ));
134
+		delete_option($this->getSessionId());
135
+		delete_option($this->getSessionId('expires'));
136 136
 	}
137 137
 
138 138
 	/**
@@ -140,30 +140,30 @@  discard block
 block discarded – undo
140 140
 	 */
141 141
 	protected function generateSessionId()
142 142
 	{
143
-		return md5(( new PasswordHash( 8, false ))->get_random_bytes( 32 ));
143
+		return md5((new PasswordHash(8, false))->get_random_bytes(32));
144 144
 	}
145 145
 
146 146
 	/**
147 147
 	 * @param int $limit
148 148
 	 * @return array
149 149
 	 */
150
-	protected function getExpiredSessions( $limit )
150
+	protected function getExpiredSessions($limit)
151 151
 	{
152 152
 		global $wpdb;
153 153
 		$expiredSessions = [];
154 154
 		$sessions = $wpdb->get_results(
155
-			"SELECT option_name AS name, option_value AS expiration " .
156
-			"FROM {$wpdb->options} " .
157
-			"WHERE option_name LIKE '".static::SESSION_COOKIE."_expires_%' " .
158
-			"ORDER BY option_value ASC " .
159
-			"LIMIT 0, ".absint( $limit )
155
+			"SELECT option_name AS name, option_value AS expiration ".
156
+			"FROM {$wpdb->options} ".
157
+			"WHERE option_name LIKE '".static::SESSION_COOKIE."_expires_%' ".
158
+			"ORDER BY option_value ASC ".
159
+			"LIMIT 0, ".absint($limit)
160 160
 		);
161
-		if( !empty( $sessions )) {
161
+		if (!empty($sessions)) {
162 162
 			$now = time();
163
-			foreach( $sessions as $session ) {
164
-				if( $now <= $session->expiration )continue;
163
+			foreach ($sessions as $session) {
164
+				if ($now <= $session->expiration)continue;
165 165
 				$expiredSessions[] = $session->name;
166
-				$expiredSessions[] = str_replace( '_expires_', '_', $session->name );
166
+				$expiredSessions[] = str_replace('_expires_', '_', $session->name);
167 167
 			}
168 168
 		}
169 169
 		return $expiredSessions;
@@ -173,9 +173,9 @@  discard block
 block discarded – undo
173 173
 	 * @param string $separator
174 174
 	 * @return string
175 175
 	 */
176
-	protected function getSessionId( $separator = '' )
176
+	protected function getSessionId($separator = '')
177 177
 	{
178
-		return implode( '_', array_filter( [static::SESSION_COOKIE, $separator, $this->sessionId] ));
178
+		return implode('_', array_filter([static::SESSION_COOKIE, $separator, $this->sessionId]));
179 179
 	}
180 180
 
181 181
 	/**
@@ -183,16 +183,16 @@  discard block
 block discarded – undo
183 183
 	 */
184 184
 	protected function getSessionData()
185 185
 	{
186
-		return $this->sessionData = (array) get_option( $this->getSessionId(), [] );
186
+		return $this->sessionData = (array)get_option($this->getSessionId(), []);
187 187
 	}
188 188
 
189 189
 	/**
190 190
 	 * @param bool|string $deleteOld
191 191
 	 * @return void
192 192
 	 */
193
-	protected function regenerateSessionId( $deleteOld = false )
193
+	protected function regenerateSessionId($deleteOld = false)
194 194
 	{
195
-		if( $deleteOld ) {
195
+		if ($deleteOld) {
196 196
 			$this->deleteSession();
197 197
 		}
198 198
 		$this->sessionId = $this->generateSessionId();
@@ -204,10 +204,10 @@  discard block
 block discarded – undo
204 204
 	 */
205 205
 	protected function setCookie()
206 206
 	{
207
-		if( headers_sent() )return;
207
+		if (headers_sent())return;
208 208
 		$cookie = $this->sessionId.'||'.$this->expiryTimestamp.'||'.$this->expiryTimestampReset;
209
-		$cookiePath = preg_replace( '|https?://[^/]+|i', '', trailingslashit( get_option( 'home' )));
210
-		setcookie( static::SESSION_COOKIE, $cookie, $this->expiryTimestamp, $cookiePath );
209
+		$cookiePath = preg_replace('|https?://[^/]+|i', '', trailingslashit(get_option('home')));
210
+		setcookie(static::SESSION_COOKIE, $cookie, $this->expiryTimestamp, $cookiePath);
211 211
 	}
212 212
 
213 213
 	/**
@@ -224,11 +224,11 @@  discard block
 block discarded – undo
224 224
 	 */
225 225
 	protected function updateSession()
226 226
 	{
227
-		if( false === get_option( $this->getSessionId() )) {
227
+		if (false === get_option($this->getSessionId())) {
228 228
 			$this->createSession();
229 229
 		}
230 230
 		else {
231
-			update_option( $this->getSessionId(), $this->sessionData, false );
231
+			update_option($this->getSessionId(), $this->sessionData, false);
232 232
 		}
233 233
 	}
234 234
 }
Please login to merge, or discard this patch.
plugin/Modules/Html.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 	 */
16 16
 	protected $builder;
17 17
 
18
-	public function __construct( Builder $builder )
18
+	public function __construct(Builder $builder)
19 19
 	{
20 20
 		$this->builder = $builder;
21 21
 	}
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	/**
24 24
 	 * @return Builder
25 25
 	 */
26
-	public function build( array $globals = [] )
26
+	public function build(array $globals = [])
27 27
 	{
28 28
 		$this->builder->globals = $globals;
29 29
 		$this->builder->render = false;
@@ -34,33 +34,33 @@  discard block
 block discarded – undo
34 34
 	 * @param string $path
35 35
 	 * @return void|string
36 36
 	 */
37
-	public function buildForm( $path, array $args = [] )
37
+	public function buildForm($path, array $args = [])
38 38
 	{
39
-		return glsr( Form::class )->build( $path, $args );
39
+		return glsr(Form::class)->build($path, $args);
40 40
 	}
41 41
 
42 42
 	/**
43 43
 	 * @param string $partialPath
44 44
 	 * @return string
45 45
 	 */
46
-	public function buildPartial( $partialPath, array $args = [] )
46
+	public function buildPartial($partialPath, array $args = [])
47 47
 	{
48
-		return glsr( Partial::class )->build( $partialPath, $args );
48
+		return glsr(Partial::class)->build($partialPath, $args);
49 49
 	}
50 50
 
51 51
 	/**
52 52
 	 * @param string $templatePath
53 53
 	 * @return void|string
54 54
 	 */
55
-	public function buildTemplate( $templatePath, array $args = [] )
55
+	public function buildTemplate($templatePath, array $args = [])
56 56
 	{
57
-		return glsr( Template::class )->build( $templatePath, $args );
57
+		return glsr(Template::class)->build($templatePath, $args);
58 58
 	}
59 59
 
60 60
 	/**
61 61
 	 * @return void
62 62
 	 */
63
-	public function render( array $globals = [] )
63
+	public function render(array $globals = [])
64 64
 	{
65 65
 		$this->builder->globals = $globals;
66 66
 		$this->builder->render = true;
@@ -70,9 +70,9 @@  discard block
 block discarded – undo
70 70
 	/**
71 71
 	 * @return void
72 72
 	 */
73
-	public function renderForm( $path, array $args = [] )
73
+	public function renderForm($path, array $args = [])
74 74
 	{
75
-		echo $this->buildForm( $path, $args );
75
+		echo $this->buildForm($path, $args);
76 76
 	}
77 77
 
78 78
 	/**
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	 */
81 81
 	public function renderNotices()
82 82
 	{
83
-		$this->render()->div( glsr( Notice::class )->get(), [
83
+		$this->render()->div(glsr(Notice::class)->get(), [
84 84
 			'id' => 'glsr-notices',
85 85
 		]);
86 86
 	}
@@ -89,17 +89,17 @@  discard block
 block discarded – undo
89 89
 	 * @param string $partialPath
90 90
 	 * @return void
91 91
 	 */
92
-	public function renderPartial( $partialPath, array $args = [] )
92
+	public function renderPartial($partialPath, array $args = [])
93 93
 	{
94
-		echo $this->buildPartial( $partialPath, $args );
94
+		echo $this->buildPartial($partialPath, $args);
95 95
 	}
96 96
 
97 97
 	/**
98 98
 	 * @param string $templatePath
99 99
 	 * @return void
100 100
 	 */
101
-	public function renderTemplate( $templatePath, array $args = [] )
101
+	public function renderTemplate($templatePath, array $args = [])
102 102
 	{
103
-		echo $this->buildTemplate( $templatePath, $args );
103
+		echo $this->buildTemplate($templatePath, $args);
104 104
 	}
105 105
 }
Please login to merge, or discard this patch.
plugin/Modules/Translator.php 1 patch
Spacing   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -27,10 +27,10 @@  discard block
 block discarded – undo
27 27
 	public function all()
28 28
 	{
29 29
 		$translations = $this->getSettings();
30
-		$entries = $this->filter( $translations, $this->entries() )->results();
31
-		array_walk( $translations, function( &$entry ) use( $entries ) {
32
-			$entry['desc'] = array_key_exists( $entry['id'], $entries )
33
-				? $this->getEntryString( $entries[$entry['id']], 'msgctxt' )
30
+		$entries = $this->filter($translations, $this->entries())->results();
31
+		array_walk($translations, function(&$entry) use($entries) {
32
+			$entry['desc'] = array_key_exists($entry['id'], $entries)
33
+				? $this->getEntryString($entries[$entry['id']], 'msgctxt')
34 34
 				: '';
35 35
 		});
36 36
 		return $translations;
@@ -41,17 +41,17 @@  discard block
 block discarded – undo
41 41
 	 */
42 42
 	public function entries()
43 43
 	{
44
-		if( !is_array( $this->entries )) {
44
+		if (!is_array($this->entries)) {
45 45
 			try {
46 46
 				$entries = $this->normalize(
47
-					Parser::parseFile( glsr()->path( 'languages/site-reviews.pot' ))->getEntries()
47
+					Parser::parseFile(glsr()->path('languages/site-reviews.pot'))->getEntries()
48 48
 				);
49 49
 			}
50
-			catch( Exception $e ) {
51
-				glsr_log()->error( $e->getMessage() );
50
+			catch (Exception $e) {
51
+				glsr_log()->error($e->getMessage());
52 52
 			}
53
-			foreach( $entries as $key => $entry ) {
54
-				$this->entries[html_entity_decode( $key, ENT_COMPAT, 'UTF-8' )] = $entry;
53
+			foreach ($entries as $key => $entry) {
54
+				$this->entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry;
55 55
 			}
56 56
 		}
57 57
 		return $this->entries;
@@ -62,9 +62,9 @@  discard block
 block discarded – undo
62 62
 	 * @param null|array $entries
63 63
 	 * @return self
64 64
 	 */
65
-	public function exclude( $entriesToExclude = null, $entries = null )
65
+	public function exclude($entriesToExclude = null, $entries = null)
66 66
 	{
67
-		return $this->filter( $entriesToExclude, $entries, false );
67
+		return $this->filter($entriesToExclude, $entries, false);
68 68
 	}
69 69
 
70 70
 	/**
@@ -73,18 +73,18 @@  discard block
 block discarded – undo
73 73
 	 * @param bool $intersect
74 74
 	 * @return self
75 75
 	 */
76
-	public function filter( $filterWith = null, $entries = null, $intersect = true )
76
+	public function filter($filterWith = null, $entries = null, $intersect = true)
77 77
 	{
78
-		if( !is_array( $entries )) {
78
+		if (!is_array($entries)) {
79 79
 			$entries = $this->results;
80 80
 		}
81
-		if( !is_array( $filterWith )) {
81
+		if (!is_array($filterWith)) {
82 82
 			$filterWith = $this->getSettings();
83 83
 		}
84
-		$keys = array_flip( array_column( $filterWith, 'id' ));
84
+		$keys = array_flip(array_column($filterWith, 'id'));
85 85
 		$this->results = $intersect
86
-			? array_intersect_key( $entries, $keys )
87
-			: array_diff_key( $entries, $keys );
86
+			? array_intersect_key($entries, $keys)
87
+			: array_diff_key($entries, $keys);
88 88
 		return $this;
89 89
 	}
90 90
 
@@ -94,9 +94,9 @@  discard block
 block discarded – undo
94 94
 	 * @param string $domain
95 95
 	 * @return string
96 96
 	 */
97
-	public function filterGettext( $translation, $text, $domain )
97
+	public function filterGettext($translation, $text, $domain)
98 98
 	{
99
-		return $this->translate( $translation, $domain, [
99
+		return $this->translate($translation, $domain, [
100 100
 			'single' => $text,
101 101
 		]);
102 102
 	}
@@ -108,9 +108,9 @@  discard block
 block discarded – undo
108 108
 	 * @param string $domain
109 109
 	 * @return string
110 110
 	 */
111
-	public function filterGettextWithContext( $translation, $text, $context, $domain )
111
+	public function filterGettextWithContext($translation, $text, $context, $domain)
112 112
 	{
113
-		return $this->translate( $translation, $domain, [
113
+		return $this->translate($translation, $domain, [
114 114
 			'context' => $context,
115 115
 			'single' => $text,
116 116
 		]);
@@ -124,9 +124,9 @@  discard block
 block discarded – undo
124 124
 	 * @param string $domain
125 125
 	 * @return string
126 126
 	 */
127
-	public function filterNgettext( $translation, $single, $plural, $number, $domain )
127
+	public function filterNgettext($translation, $single, $plural, $number, $domain)
128 128
 	{
129
-		return $this->translate( $translation, $domain, [
129
+		return $this->translate($translation, $domain, [
130 130
 			'number' => $number,
131 131
 			'plural' => $plural,
132 132
 			'single' => $single,
@@ -142,9 +142,9 @@  discard block
 block discarded – undo
142 142
 	 * @param string $domain
143 143
 	 * @return string
144 144
 	 */
145
-	public function filterNgettextWithContext( $translation, $single, $plural, $number, $context, $domain )
145
+	public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain)
146 146
 	{
147
-		return $this->translate( $translation, $domain, [
147
+		return $this->translate($translation, $domain, [
148 148
 			'context' => $context,
149 149
 			'number' => $number,
150 150
 			'plural' => $plural,
@@ -156,14 +156,14 @@  discard block
 block discarded – undo
156 156
 	 * @param string $template
157 157
 	 * @return string
158 158
 	 */
159
-	public function render( $template, array $entry )
159
+	public function render($template, array $entry)
160 160
 	{
161 161
 		$data = array_combine(
162
-			array_map( function( $key ) { return 'data.'.$key; }, array_keys( $entry )),
162
+			array_map(function($key) { return 'data.'.$key; }, array_keys($entry)),
163 163
 			$entry
164 164
 		);
165 165
 		ob_start();
166
-		glsr( Html::class )->renderTemplate( 'translations/'.$template, $data );
166
+		glsr(Html::class)->renderTemplate('translations/'.$template, $data);
167 167
 		return ob_get_clean();
168 168
 	}
169 169
 
@@ -174,10 +174,10 @@  discard block
 block discarded – undo
174 174
 	public function renderAll()
175 175
 	{
176 176
 		$rendered = '';
177
-		foreach( $this->all() as $index => $entry ) {
177
+		foreach ($this->all() as $index => $entry) {
178 178
 			$entry['index'] = $index;
179 179
 			$entry['prefix'] = OptionManager::databaseKey();
180
-			$rendered .= $this->render( $entry['type'], $entry );
180
+			$rendered .= $this->render($entry['type'], $entry);
181 181
 		}
182 182
 		return $rendered;
183 183
 	}
@@ -186,25 +186,25 @@  discard block
 block discarded – undo
186 186
 	 * @param bool $resetAfterRender
187 187
 	 * @return string
188 188
 	 */
189
-	public function renderResults( $resetAfterRender = true )
189
+	public function renderResults($resetAfterRender = true)
190 190
 	{
191 191
 		$rendered = '';
192
-		foreach( $this->results as $id => $entry ) {
192
+		foreach ($this->results as $id => $entry) {
193 193
 			$data = [
194
-				'desc' => $this->getEntryString( $entry, 'msgctxt' ),
194
+				'desc' => $this->getEntryString($entry, 'msgctxt'),
195 195
 				'id' => $id,
196
-				'p1' => $this->getEntryString( $entry, 'msgid_plural' ),
197
-				's1' => $this->getEntryString( $entry, 'msgid' ),
196
+				'p1' => $this->getEntryString($entry, 'msgid_plural'),
197
+				's1' => $this->getEntryString($entry, 'msgid'),
198 198
 			];
199
-			$text = !empty( $data['p1'] )
200
-				? sprintf( '%s | %s', $data['s1'], $data['p1'] )
199
+			$text = !empty($data['p1'])
200
+				? sprintf('%s | %s', $data['s1'], $data['p1'])
201 201
 				: $data['s1'];
202
-			$rendered .= $this->render( 'result', [
203
-				'entry' => wp_json_encode( $data ),
204
-				'text' => wp_strip_all_tags( $text ),
202
+			$rendered .= $this->render('result', [
203
+				'entry' => wp_json_encode($data),
204
+				'text' => wp_strip_all_tags($text),
205 205
 			]);
206 206
 		}
207
-		if( $resetAfterRender ) {
207
+		if ($resetAfterRender) {
208 208
 			$this->reset();
209 209
 		}
210 210
 		return $rendered;
@@ -234,24 +234,24 @@  discard block
 block discarded – undo
234 234
 	 * @param bool $caseSensitive
235 235
 	 * @return self
236 236
 	 */
237
-	public function search( $needle = '', $threshold = 3, $caseSensitive = false )
237
+	public function search($needle = '', $threshold = 3, $caseSensitive = false)
238 238
 	{
239 239
 		$this->reset();
240
-		$needle = trim( $needle );
241
-		foreach( $this->entries() as $key => $entry ) {
242
-			$single = $this->getEntryString( $entry, 'msgid' );
243
-			$plural = $this->getEntryString( $entry, 'msgid_plural' );
244
-			if( !$caseSensitive ) {
245
-				$needle = strtolower( $needle );
246
-				$single = strtolower( $single );
247
-				$plural = strtolower( $plural );
240
+		$needle = trim($needle);
241
+		foreach ($this->entries() as $key => $entry) {
242
+			$single = $this->getEntryString($entry, 'msgid');
243
+			$plural = $this->getEntryString($entry, 'msgid_plural');
244
+			if (!$caseSensitive) {
245
+				$needle = strtolower($needle);
246
+				$single = strtolower($single);
247
+				$plural = strtolower($plural);
248 248
 			}
249
-			if( strlen( $needle ) < $threshold ) {
250
-				if( in_array( $needle, [$single, $plural] )) {
249
+			if (strlen($needle) < $threshold) {
250
+				if (in_array($needle, [$single, $plural])) {
251 251
 					$this->results[$key] = $entry;
252 252
 				}
253 253
 			}
254
-			else if( strpos( sprintf( '%s %s', $single, $plural ), $needle ) !== false ) {
254
+			else if (strpos(sprintf('%s %s', $single, $plural), $needle) !== false) {
255 255
 				$this->results[$key] = $entry;
256 256
 			}
257 257
 		}
@@ -263,42 +263,42 @@  discard block
 block discarded – undo
263 263
 	 * @param string $domain
264 264
 	 * @return string
265 265
 	 */
266
-	public function translate( $original, $domain, array $args )
266
+	public function translate($original, $domain, array $args)
267 267
 	{
268
-		if( $domain != glsr()->id ) {
268
+		if ($domain != glsr()->id) {
269 269
 			return $original;
270 270
 		}
271
-		$args = $this->normalizeTranslationArgs( $args );
272
-		extract( $args );
271
+		$args = $this->normalizeTranslationArgs($args);
272
+		extract($args);
273 273
 		$strings = $this->getSettings();
274
-		$strings = array_filter( $strings, function( $string ) use( $single, $plural ) {
275
-			return $string['s1'] == html_entity_decode( $single, ENT_COMPAT, 'UTF-8' )
276
-				&& $string['p1'] == html_entity_decode( $plural, ENT_COMPAT, 'UTF-8' );
274
+		$strings = array_filter($strings, function($string) use($single, $plural) {
275
+			return $string['s1'] == html_entity_decode($single, ENT_COMPAT, 'UTF-8')
276
+				&& $string['p1'] == html_entity_decode($plural, ENT_COMPAT, 'UTF-8');
277 277
 		});
278
-		if( empty( $strings )) {
278
+		if (empty($strings)) {
279 279
 			return $original;
280 280
 		}
281
-		$string = current( $strings );
282
-		if( !empty( $string['s2'] )) {
281
+		$string = current($strings);
282
+		if (!empty($string['s2'])) {
283 283
 			$single = $string['s2'];
284 284
 		}
285
-		if( !empty( $string['p2'] )) {
285
+		if (!empty($string['p2'])) {
286 286
 			$plural = $string['p2'];
287 287
 		}
288
-		$translations = get_translations_for_domain( $domain );
288
+		$translations = get_translations_for_domain($domain);
289 289
 		return $string['type'] == 'plural'
290
-			? $translations->translate_plural( $single, $plural, $number, $context )
291
-			: $translations->translate( $single, $context );
290
+			? $translations->translate_plural($single, $plural, $number, $context)
291
+			: $translations->translate($single, $context);
292 292
 	}
293 293
 
294 294
 	/**
295 295
 	 * @param string $key
296 296
 	 * @return string
297 297
 	 */
298
-	protected function getEntryString( array $entry, $key )
298
+	protected function getEntryString(array $entry, $key)
299 299
 	{
300
-		return isset( $entry[$key] )
301
-			? implode( '', (array) $entry[$key] )
300
+		return isset($entry[$key])
301
+			? implode('', (array)$entry[$key])
302 302
 			: '';
303 303
 	}
304 304
 
@@ -307,23 +307,23 @@  discard block
 block discarded – undo
307 307
 	 */
308 308
 	protected function getSettings()
309 309
 	{
310
-		$settings = glsr( OptionManager::class )->get( 'settings' );
311
-		return isset( $settings['strings'] )
312
-			? $this->normalizeSettings( (array) $settings['strings'] )
310
+		$settings = glsr(OptionManager::class)->get('settings');
311
+		return isset($settings['strings'])
312
+			? $this->normalizeSettings((array)$settings['strings'])
313 313
 			: [];
314 314
 	}
315 315
 
316 316
 	/**
317 317
 	 * @return array
318 318
 	 */
319
-	protected function normalize( array $entries )
319
+	protected function normalize(array $entries)
320 320
 	{
321 321
 		$keys = [
322 322
 			'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]',
323 323
 		];
324
-		array_walk( $entries, function( &$entry ) use( $keys ) {
325
-			foreach( $keys as $key ) {
326
-				$entry = $this->normalizeEntryString( $entry, $key );
324
+		array_walk($entries, function(&$entry) use($keys) {
325
+			foreach ($keys as $key) {
326
+				$entry = $this->normalizeEntryString($entry, $key);
327 327
 			}
328 328
 		});
329 329
 		return $entries;
@@ -333,10 +333,10 @@  discard block
 block discarded – undo
333 333
 	 * @param string $key
334 334
 	 * @return array
335 335
 	 */
336
-	protected function normalizeEntryString( array $entry, $key )
336
+	protected function normalizeEntryString(array $entry, $key)
337 337
 	{
338
-		if( isset( $entry[$key] )) {
339
-			$entry[$key] = $this->getEntryString( $entry, $key );
338
+		if (isset($entry[$key])) {
339
+			$entry[$key] = $this->getEntryString($entry, $key);
340 340
 		}
341 341
 		return $entry;
342 342
 	}
@@ -344,23 +344,23 @@  discard block
 block discarded – undo
344 344
 	/**
345 345
 	 * @return array
346 346
 	 */
347
-	protected function normalizeSettings( array $strings )
347
+	protected function normalizeSettings(array $strings)
348 348
 	{
349
-		$defaultString = array_fill_keys( ['id', 's1', 's2', 'p1', 'p2'], '' );
350
-		$strings = array_filter( $strings, 'is_array' );
351
-		foreach( $strings as &$string ) {
352
-			$string['type'] = isset( $string['p1'] ) ? 'plural' : 'single';
353
-			$string = wp_parse_args( $string, $defaultString );
349
+		$defaultString = array_fill_keys(['id', 's1', 's2', 'p1', 'p2'], '');
350
+		$strings = array_filter($strings, 'is_array');
351
+		foreach ($strings as &$string) {
352
+			$string['type'] = isset($string['p1']) ? 'plural' : 'single';
353
+			$string = wp_parse_args($string, $defaultString);
354 354
 		}
355
-		return array_filter( $strings, function( $string ) {
356
-			return !empty( $string['id'] );
355
+		return array_filter($strings, function($string) {
356
+			return !empty($string['id']);
357 357
 		});
358 358
 	}
359 359
 
360 360
 	/**
361 361
 	 * @return array
362 362
 	 */
363
-	protected function normalizeTranslationArgs( array $args )
363
+	protected function normalizeTranslationArgs(array $args)
364 364
 	{
365 365
 		$defaults = [
366 366
 			'context' => '',
@@ -368,6 +368,6 @@  discard block
 block discarded – undo
368 368
 			'plural' => '',
369 369
 			'single' => '',
370 370
 		];
371
-		return shortcode_atts( $defaults, $args );
371
+		return shortcode_atts($defaults, $args);
372 372
 	}
373 373
 }
Please login to merge, or discard this patch.
plugin/Modules/Schema.php 1 patch
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -24,18 +24,18 @@  discard block
 block discarded – undo
24 24
 	/**
25 25
 	 * @return array
26 26
 	 */
27
-	public function build( array $args = [] )
27
+	public function build(array $args = [])
28 28
 	{
29 29
 		$this->args = $args;
30
-		$schema = $this->buildSummary( $args );
30
+		$schema = $this->buildSummary($args);
31 31
 		$reviews = [];
32
-		foreach( glsr( Database::class )->getReviews( $this->args )->reviews as $review ) {
33
-			$reviews[] = $this->buildReview( $review );
32
+		foreach (glsr(Database::class)->getReviews($this->args)->reviews as $review) {
33
+			$reviews[] = $this->buildReview($review);
34 34
 		}
35
-		if( !empty( $reviews )) {
36
-			array_walk( $reviews, function( &$review ) {
37
-				unset( $review['@context'] );
38
-				unset( $review['itemReviewed'] );
35
+		if (!empty($reviews)) {
36
+			array_walk($reviews, function(&$review) {
37
+				unset($review['@context']);
38
+				unset($review['itemReviewed']);
39 39
 			});
40 40
 			$schema['review'] = $reviews;
41 41
 		}
@@ -46,61 +46,61 @@  discard block
 block discarded – undo
46 46
 	 * @param object $review
47 47
 	 * @return array
48 48
 	 */
49
-	public function buildReview( $review )
49
+	public function buildReview($review)
50 50
 	{
51 51
 		$schema = SchemaOrg::Review()
52
-			->doIf( !in_array( 'title', $this->args['hide'] ), function( ReviewSchema $schema ) use( $review ) {
53
-				$schema->name( $review->title );
52
+			->doIf(!in_array('title', $this->args['hide']), function(ReviewSchema $schema) use($review) {
53
+				$schema->name($review->title);
54 54
 			})
55
-			->doIf( !in_array( 'excerpt', $this->args['hide'] ), function( ReviewSchema $schema ) use( $review ) {
56
-				$schema->reviewBody( $review->content );
55
+			->doIf(!in_array('excerpt', $this->args['hide']), function(ReviewSchema $schema) use($review) {
56
+				$schema->reviewBody($review->content);
57 57
 			})
58
-			->datePublished(( new DateTime( $review->date ))->format( DateTime::ISO8601 ))
59
-			->author( SchemaOrg::Person()
60
-				->name( $review->author )
58
+			->datePublished((new DateTime($review->date))->format(DateTime::ISO8601))
59
+			->author(SchemaOrg::Person()
60
+				->name($review->author)
61 61
 			)
62
-			->itemReviewed( $this->getSchemaType()
63
-				->name( $this->getThingName() )
62
+			->itemReviewed($this->getSchemaType()
63
+				->name($this->getThingName())
64 64
 			);
65
-		if( !empty( $review->rating )) {
66
-			$schema->reviewRating( SchemaOrg::Rating()
67
-				->ratingValue( $review->rating )
68
-				->bestRating( Rating::MAX_RATING )
69
-				->worstRating( Rating::MIN_RATING )
65
+		if (!empty($review->rating)) {
66
+			$schema->reviewRating(SchemaOrg::Rating()
67
+				->ratingValue($review->rating)
68
+				->bestRating(Rating::MAX_RATING)
69
+				->worstRating(Rating::MIN_RATING)
70 70
 			);
71 71
 		}
72
-		return apply_filters( 'site-reviews/schema/Review', $schema->toArray(), $review, $this->args );
72
+		return apply_filters('site-reviews/schema/Review', $schema->toArray(), $review, $this->args);
73 73
 	}
74 74
 
75 75
 	/**
76 76
 	 * @param null|array $args
77 77
 	 * @return array
78 78
 	 */
79
-	public function buildSummary( $args = null )
79
+	public function buildSummary($args = null)
80 80
 	{
81
-		if( is_array( $args )) {
81
+		if (is_array($args)) {
82 82
 			$this->args = $args;
83 83
 		}
84 84
 		$schema = $this->getSchemaType()
85
-			->doIf( $this->getSchemaOption( 'type' ) == 'Product', function( $schema ) {
86
-				$schema->setProperty( '@id', $this->getThingUrl() );
85
+			->doIf($this->getSchemaOption('type') == 'Product', function($schema) {
86
+				$schema->setProperty('@id', $this->getThingUrl());
87 87
 			})
88
-			->name( $this->getThingName() )
89
-			->description( $this->getThingDescription() )
90
-			->image( $this->getThingImage() )
91
-			->url( $this->getThingUrl() );
88
+			->name($this->getThingName())
89
+			->description($this->getThingDescription())
90
+			->image($this->getThingImage())
91
+			->url($this->getThingUrl());
92 92
 		$count = $this->getReviewCount();
93
-		if( !empty( $count )) {
94
-			$schema->aggregateRating( SchemaOrg::AggregateRating()
95
-				->ratingValue( $this->getRatingValue() )
96
-				->reviewCount( $count )
97
-				->bestRating( Rating::MAX_RATING )
98
-				->worstRating( Rating::MIN_RATING )
93
+		if (!empty($count)) {
94
+			$schema->aggregateRating(SchemaOrg::AggregateRating()
95
+				->ratingValue($this->getRatingValue())
96
+				->reviewCount($count)
97
+				->bestRating(Rating::MAX_RATING)
98
+				->worstRating(Rating::MIN_RATING)
99 99
 			);
100 100
 		}
101 101
 		$schema = $schema->toArray();
102
-		$args = wp_parse_args( ['count' => -1], $this->args );
103
-		return apply_filters( sprintf( 'site-reviews/schema/%s', $schema['@type'] ), $schema, $args );
102
+		$args = wp_parse_args(['count' => -1], $this->args);
103
+		return apply_filters(sprintf('site-reviews/schema/%s', $schema['@type']), $schema, $args);
104 104
 	}
105 105
 
106 106
 	/**
@@ -108,9 +108,9 @@  discard block
 block discarded – undo
108 108
 	 */
109 109
 	public function render()
110 110
 	{
111
-		if( is_null( glsr()->schemas ))return;
112
-		printf( '<script type="application/ld+json">%s</script>', json_encode(
113
-			apply_filters( 'site-reviews/schema/all', glsr()->schemas ),
111
+		if (is_null(glsr()->schemas))return;
112
+		printf('<script type="application/ld+json">%s</script>', json_encode(
113
+			apply_filters('site-reviews/schema/all', glsr()->schemas),
114 114
 			JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
115 115
 		));
116 116
 	}
@@ -118,11 +118,11 @@  discard block
 block discarded – undo
118 118
 	/**
119 119
 	 * @return void
120 120
 	 */
121
-	public function store( array $schema )
121
+	public function store(array $schema)
122 122
 	{
123
-		$schemas = (array) glsr()->schemas;
123
+		$schemas = (array)glsr()->schemas;
124 124
 		$schemas[] = $schema;
125
-		glsr()->schemas = array_map( 'unserialize', array_unique( array_map( 'serialize', $schemas )));
125
+		glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas)));
126 126
 	}
127 127
 
128 128
 	/**
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 	 */
131 131
 	protected function getRatingValue()
132 132
 	{
133
-		return glsr( Rating::class )->getAverage( $this->getReviews() );
133
+		return glsr(Rating::class)->getAverage($this->getReviews());
134 134
 	}
135 135
 
136 136
 	/**
@@ -138,18 +138,18 @@  discard block
 block discarded – undo
138 138
 	 */
139 139
 	protected function getReviewCount()
140 140
 	{
141
-		return count( $this->getReviews() );
141
+		return count($this->getReviews());
142 142
 	}
143 143
 
144 144
 	/**
145 145
 	 * Get all reviews possible for given args
146 146
 	 * @return array
147 147
 	 */
148
-	protected function getReviews( $force = false )
148
+	protected function getReviews($force = false)
149 149
 	{
150
-		if( !is_array( $this->reviews ) || $force ) {
151
-			$args = wp_parse_args( ['count' => -1], $this->args );
152
-			$this->reviews = glsr( Database::class )->getReviews( $args )->reviews;
150
+		if (!is_array($this->reviews) || $force) {
151
+			$args = wp_parse_args(['count' => -1], $this->args);
152
+			$this->reviews = glsr(Database::class)->getReviews($args)->reviews;
153 153
 		}
154 154
 		return $this->reviews;
155 155
 	}
@@ -159,14 +159,14 @@  discard block
 block discarded – undo
159 159
 	 * @param string $fallback
160 160
 	 * @return string
161 161
 	 */
162
-	protected function getSchemaOption( $option, $fallback )
162
+	protected function getSchemaOption($option, $fallback)
163 163
 	{
164
-		if( $schemaOption = trim( get_post_meta( get_the_ID(), 'schema_'.$option, true ))) {
164
+		if ($schemaOption = trim(get_post_meta(get_the_ID(), 'schema_'.$option, true))) {
165 165
 			return $schemaOption;
166 166
 		}
167
-		$default = glsr( OptionManager::class )->get( 'settings.reviews.schema.'.$option.'.default', $fallback );
167
+		$default = glsr(OptionManager::class)->get('settings.reviews.schema.'.$option.'.default', $fallback);
168 168
 		return $default == 'custom'
169
-			? glsr( OptionManager::class )->get( 'settings.reviews.schema.'.$option.'.custom', $fallback )
169
+			? glsr(OptionManager::class)->get('settings.reviews.schema.'.$option.'.custom', $fallback)
170 170
 			: $default;
171 171
 	}
172 172
 
@@ -175,18 +175,18 @@  discard block
 block discarded – undo
175 175
 	 * @param string $fallback
176 176
 	 * @return null|string
177 177
 	 */
178
-	protected function getSchemaOptionValue( $option, $fallback = 'post' )
178
+	protected function getSchemaOptionValue($option, $fallback = 'post')
179 179
 	{
180
-		$value = $this->getSchemaOption( $option, $fallback );
181
-		if( $value != $fallback ) {
180
+		$value = $this->getSchemaOption($option, $fallback);
181
+		if ($value != $fallback) {
182 182
 			return $value;
183 183
 		}
184
-		if( !is_single() && !is_page() )return;
185
-		switch( $option ) {
184
+		if (!is_single() && !is_page())return;
185
+		switch ($option) {
186 186
 			case 'description':
187 187
 				return get_the_excerpt();
188 188
 			case 'image':
189
-				return (string)get_the_post_thumbnail_url( null, 'large' );
189
+				return (string)get_the_post_thumbnail_url(null, 'large');
190 190
 			case 'name':
191 191
 				return get_the_title();
192 192
 			case 'url':
@@ -199,8 +199,8 @@  discard block
 block discarded – undo
199 199
 	 */
200 200
 	protected function getSchemaType()
201 201
 	{
202
-		$type = $this->getSchemaOption( 'type', 'LocalBusiness' );
203
-		return SchemaOrg::$type( $type );
202
+		$type = $this->getSchemaOption('type', 'LocalBusiness');
203
+		return SchemaOrg::$type($type);
204 204
 	}
205 205
 
206 206
 	/**
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 	 */
209 209
 	protected function getThingDescription()
210 210
 	{
211
-		return $this->getSchemaOptionValue( 'description' );
211
+		return $this->getSchemaOptionValue('description');
212 212
 	}
213 213
 
214 214
 	/**
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 	 */
217 217
 	protected function getThingImage()
218 218
 	{
219
-		return $this->getSchemaOptionValue( 'image' );
219
+		return $this->getSchemaOptionValue('image');
220 220
 	}
221 221
 
222 222
 	/**
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 	 */
225 225
 	protected function getThingName()
226 226
 	{
227
-		return $this->getSchemaOptionValue( 'name' );
227
+		return $this->getSchemaOptionValue('name');
228 228
 	}
229 229
 
230 230
 	/**
@@ -232,6 +232,6 @@  discard block
 block discarded – undo
232 232
 	 */
233 233
 	protected function getThingUrl()
234 234
 	{
235
-		return $this->getSchemaOptionValue( 'url' );
235
+		return $this->getSchemaOptionValue('url');
236 236
 	}
237 237
 }
Please login to merge, or discard this patch.