Completed
Push — develop ( bf233d...52fa37 )
by Zack
18:25
created
trustedlogin/autoload-classmap.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@
 block discarded – undo
2 2
 
3 3
 // autoload-classmap.php @generated by Strauss
4 4
 
5
-$trustedlogin = dirname(__FILE__);
5
+$trustedlogin = dirname( __FILE__ );
6 6
 
7 7
 return array(
8 8
    'GravityView\Katzgrau\KLogger\Logger' => $trustedlogin . '/katzgrau/klogger/src/Logger.php',
Please login to merge, or discard this patch.
trustedlogin/trustedlogin/client/src/SiteAccess.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@
 block discarded – undo
89 89
 			return $response_json;
90 90
 		}
91 91
 
92
-		if ( empty( $response_json['success'] ) ) {
92
+		if ( empty( $response_json[ 'success' ] ) ) {
93 93
 			return new WP_Error( 'sync_error', __( 'Could not sync to TrustedLogin server', 'trustedlogin' ) );
94 94
 		}
95 95
 
Please login to merge, or discard this patch.
trustedlogin/trustedlogin/client/src/Remote.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 namespace GravityView\TrustedLogin;
14 14
 
15 15
 // Exit if accessed directly
16
-if ( ! defined('ABSPATH') ) {
16
+if ( ! defined( 'ABSPATH' ) ) {
17 17
 	exit;
18 18
 }
19 19
 
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 		);
150 150
 
151 151
 		if ( ! empty( $data ) && ! in_array( $method, array( 'GET', 'HEAD' ), true ) ) {
152
-			$request_options['body'] = wp_json_encode( $data );
152
+			$request_options[ 'body' ] = wp_json_encode( $data );
153 153
 		}
154 154
 
155 155
 		try {
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 				return new WP_Error( 'invalid_response', esc_html__( 'Invalid response.', 'trustedlogin' ), $api_response );
262 262
 
263 263
 			default:
264
-				return (int) $response_code;
264
+				return (int)$response_code;
265 265
 		}
266 266
 	}
267 267
 
@@ -304,20 +304,20 @@  discard block
 block discarded – undo
304 304
 			return new WP_Error( 'invalid_response', esc_html__( 'Invalid response.', 'trustedlogin' ), $response_body );
305 305
 		}
306 306
 
307
-		if ( isset( $response_json['errors'] ) ) {
307
+		if ( isset( $response_json[ 'errors' ] ) ) {
308 308
 
309 309
 			$errors = '';
310 310
 
311 311
 			// Multi-dimensional; we flatten.
312
-			foreach ( $response_json['errors'] as $key => $error ) {
313
-				$error  = is_array( $error ) ? reset( $error ) : $error;
312
+			foreach ( $response_json[ 'errors' ] as $key => $error ) {
313
+				$error = is_array( $error ) ? reset( $error ) : $error;
314 314
 				$errors .= $error;
315 315
 			}
316 316
 
317 317
 			return new WP_Error( 'errors_in_response', esc_html( $errors ), $response_body );
318 318
 		}
319 319
 
320
-		foreach ( (array) $required_keys as $required_key ) {
320
+		foreach ( (array)$required_keys as $required_key ) {
321 321
 			if ( ! isset( $response_json[ $required_key ] ) ) {
322 322
 				return new WP_Error( 'missing_required_key', sprintf( esc_html__( 'Invalid response. Missing key: %s', 'trustedlogin' ), $required_key ), $response_body );
323 323
 			}
Please login to merge, or discard this patch.
trustedlogin/trustedlogin/client/src/Encryption.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 namespace GravityView\TrustedLogin;
14 14
 
15 15
 // Exit if accessed directly
16
-if ( ! defined('ABSPATH') ) {
16
+if ( ! defined( 'ABSPATH' ) ) {
17 17
 	exit;
18 18
 }
19 19
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 		}
144 144
 
145 145
 		try {
146
-			$hash_bin = sodium_crypto_generichash( $string, '', (int) $length );
146
+			$hash_bin = sodium_crypto_generichash( $string, '', (int)$length );
147 147
 			$hash     = sodium_bin2hex( $hash_bin );
148 148
 		} catch ( \TypeError $e ) {
149 149
 			return new WP_Error(
@@ -251,14 +251,14 @@  discard block
 block discarded – undo
251 251
 
252 252
 		if ( is_wp_error( $response_json ) ) {
253 253
 
254
-			if ( 'not_found' == $response_json->get_error_code() ){
254
+			if ( 'not_found' == $response_json->get_error_code() ) {
255 255
 				return new WP_Error( 'not_found', __( 'Encryption key could not be fetched, Vendor site returned 404.', 'trustedlogin' ) );
256 256
 			}
257 257
 
258 258
 			return $response_json;
259 259
 		}
260 260
 
261
-		return $response_json['publicKey'];
261
+		return $response_json[ 'publicKey' ];
262 262
 	}
263 263
 
264 264
 	/**
@@ -366,6 +366,6 @@  discard block
 block discarded – undo
366 366
 			'privateKey' => sodium_crypto_box_secretkey( $aliceKeypair )
367 367
 		);
368 368
 
369
-		return (object) $alice_keys;
369
+		return (object)$alice_keys;
370 370
 	}
371 371
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -251,7 +251,7 @@
 block discarded – undo
251 251
 
252 252
 		if ( is_wp_error( $response_json ) ) {
253 253
 
254
-			if ( 'not_found' == $response_json->get_error_code() ){
254
+			if ( 'not_found' == $response_json->get_error_code() ) {
255 255
 				return new WP_Error( 'not_found', __( 'Encryption key could not be fetched, Vendor site returned 404.', 'trustedlogin' ) );
256 256
 			}
257 257
 
Please login to merge, or discard this patch.
trustedlogin/trustedlogin/client/src/SecurityChecks.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
 
84 84
 		$user_identifier = $passed_user_identifier;
85 85
 
86
-		if ( $this->in_lockdown() ){
86
+		if ( $this->in_lockdown() ) {
87 87
 
88 88
 			$this->logging->log( 'Site is in lockdown mode, aborting login.', __METHOD__, 'error' );
89 89
 
90
-			return new WP_Error( 'in_lockdown', __( 'TrustedLogin temporarily disabled.' , 'trustedlogin') );
90
+			return new WP_Error( 'in_lockdown', __( 'TrustedLogin temporarily disabled.', 'trustedlogin' ) );
91 91
 		}
92 92
 
93 93
 		// When passed in the endpoint URL, the unique ID will be the raw value, not the hash.
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 		$approved = $this->check_approved_identifier( $secret_id );
112 112
 
113 113
 		// Don't lock-down the site, since there could have been errors related to remote validation
114
-		if ( is_wp_error( $approved ) ){
114
+		if ( is_wp_error( $approved ) ) {
115 115
 
116 116
 			$this->logging->log(
117 117
 				sprintf(
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 				'notice'
153 153
 			);
154 154
 
155
-			return new WP_Error( 'brute_force_detected', 'Login aborted due to potential brute force detection.');
155
+			return new WP_Error( 'brute_force_detected', 'Login aborted due to potential brute force detection.' );
156 156
 		}
157 157
 
158 158
 		return true;
@@ -165,12 +165,12 @@  discard block
 block discarded – undo
165 165
 	 */
166 166
 	private function maybe_add_used_accesskey( $user_identifier = '' ) {
167 167
 
168
-		$used_accesskeys = (array) get_site_transient( $this->used_accesskey_transient );
168
+		$used_accesskeys = (array)get_site_transient( $this->used_accesskey_transient );
169 169
 
170 170
 		// This is a new access key
171 171
 		if ( ! in_array( $user_identifier, $used_accesskeys, true ) ) {
172 172
 
173
-			$used_accesskeys[] = $user_identifier;
173
+			$used_accesskeys[ ] = $user_identifier;
174 174
 
175 175
 			$transient_set = set_site_transient( $this->used_accesskey_transient, $used_accesskeys, self::ACCESSKEY_LIMIT_EXPIRY );
176 176
 
@@ -190,19 +190,19 @@  discard block
 block discarded – undo
190 190
 	 */
191 191
 	private function get_ip() {
192 192
 
193
-		if ( ! isset( $_SERVER['REMOTE_ADDR'] ) ) {
193
+		if ( ! isset( $_SERVER[ 'REMOTE_ADDR' ] ) ) {
194 194
 			return null;
195 195
 		}
196 196
 
197
-		$ip = wp_unslash( $_SERVER['REMOTE_ADDR'] );
197
+		$ip = wp_unslash( $_SERVER[ 'REMOTE_ADDR' ] );
198 198
 
199 199
 		$ip = trim( $ip );
200 200
 
201
-		if ( ! defined('TL_DOING_TESTS') ) {
201
+		if ( ! defined( 'TL_DOING_TESTS' ) ) {
202 202
 			$ip = filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE | FILTER_FLAG_NO_PRIV_RANGE );
203 203
 		}
204 204
 
205
-		return (string) $ip;
205
+		return (string)$ip;
206 206
 	}
207 207
 
208 208
 	/**
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 		 */
227 227
 		$body = array(
228 228
 			'timestamp'  => time(),
229
-			'user_agent' => isset( $_SERVER['HTTP_USER_AGENT'] ) ? substr( $_SERVER['HTTP_USER_AGENT'], 0, 255 ) : '',
229
+			'user_agent' => isset( $_SERVER[ 'HTTP_USER_AGENT' ] ) ? substr( $_SERVER[ 'HTTP_USER_AGENT' ], 0, 255 ) : '',
230 230
 			'user_ip'    => $this->get_ip(),
231 231
 			'site_url'   => get_site_url(),
232 232
 		);
@@ -265,13 +265,13 @@  discard block
 block discarded – undo
265 265
 		 */
266 266
 		$body = array(
267 267
 			'timestamp'  => time(),
268
-			'user_agent' => isset( $_SERVER['HTTP_USER_AGENT'] ) ? substr( $_SERVER['HTTP_USER_AGENT'], 0, 255 ) : '',
268
+			'user_agent' => isset( $_SERVER[ 'HTTP_USER_AGENT' ] ) ? substr( $_SERVER[ 'HTTP_USER_AGENT' ], 0, 255 ) : '',
269 269
 			'user_ip'	 => $this->get_ip(),
270 270
 			'site_url'	 => get_site_url(),
271 271
 		);
272 272
 
273 273
 		$remote = new Remote( $this->config, $this->logging );
274
-		$api_response = $remote->send( self::BRUTE_FORCE_ENDPOINT , $body, 'POST' );
274
+		$api_response = $remote->send( self::BRUTE_FORCE_ENDPOINT, $body, 'POST' );
275 275
 
276 276
 		if ( is_wp_error( $api_response ) ) {
277 277
 			return $api_response;
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 
303 303
 		$notified = $this->report_lockdown();
304 304
 
305
-		if ( is_wp_error( $notified ) ){
305
+		if ( is_wp_error( $notified ) ) {
306 306
 			$this->logging->log( sprintf( 'Could not notify TrustedLogin (%s)', $notified->get_error_message() ), __METHOD__, 'error' );
307 307
 		}
308 308
 
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
 	 *
356 356
 	 * @return int|false Int: in lockdown. The value returned is the timestamp when lockdown ends. False: not in lockdown, or overridden by a constant.
357 357
 	 */
358
-	public function in_lockdown(){
358
+	public function in_lockdown() {
359 359
 
360 360
 		if ( $this->in_local_development() ) {
361 361
 			return false;
Please login to merge, or discard this patch.
trustedlogin/trustedlogin/client/src/Config.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 namespace GravityView\TrustedLogin;
14 14
 
15 15
 // Exit if accessed directly
16
-if ( ! defined('ABSPATH') ) {
16
+if ( ! defined( 'ABSPATH' ) ) {
17 17
 	exit;
18 18
 }
19 19
 
@@ -113,51 +113,51 @@  discard block
 block discarded – undo
113 113
 	 */
114 114
 	public function validate() {
115 115
 
116
-		if ( in_array( __NAMESPACE__, array( 'ReplaceMe', 'ReplaceMe\GravityView\GravityView\TrustedLogin' ) ) && ! defined('TL_DOING_TESTS') ) {
116
+		if ( in_array( __NAMESPACE__, array( 'ReplaceMe', 'ReplaceMe\GravityView\GravityView\TrustedLogin' ) ) && ! defined( 'TL_DOING_TESTS' ) ) {
117 117
 			throw new Exception( 'Developer: make sure to change the namespace for the TrustedLogin class. See https://trustedlogin.com/configuration/ for more information.', 501 );
118 118
 		}
119 119
 
120 120
 		$errors = array();
121 121
 
122
-		if ( ! isset( $this->settings['auth']['api_key'] ) ) {
123
-			$errors[] = new WP_Error( 'missing_configuration', 'You need to set an API key. Get yours at https://app.trustedlogin.com' );
122
+		if ( ! isset( $this->settings[ 'auth' ][ 'api_key' ] ) ) {
123
+			$errors[ ] = new WP_Error( 'missing_configuration', 'You need to set an API key. Get yours at https://app.trustedlogin.com' );
124 124
 		}
125 125
 
126
-		if ( isset( $this->settings['vendor']['website'] ) && 'https://www.example.com' === $this->settings['vendor']['website'] && ! defined('TL_DOING_TESTS') ) {
127
-			$errors[] = new WP_Error( 'missing_configuration', 'You need to configure the "website" URL to point to the URL where the Vendor plugin is installed.' );
126
+		if ( isset( $this->settings[ 'vendor' ][ 'website' ] ) && 'https://www.example.com' === $this->settings[ 'vendor' ][ 'website' ] && ! defined( 'TL_DOING_TESTS' ) ) {
127
+			$errors[ ] = new WP_Error( 'missing_configuration', 'You need to configure the "website" URL to point to the URL where the Vendor plugin is installed.' );
128 128
 		}
129 129
 
130 130
 		foreach ( array( 'namespace', 'title', 'website', 'support_url', 'email' ) as $required_vendor_field ) {
131
-			if ( ! isset( $this->settings['vendor'][ $required_vendor_field ] ) ) {
132
-				$errors[] = new WP_Error( 'missing_configuration', sprintf( 'Missing required configuration: `vendor/%s`', $required_vendor_field ) );
131
+			if ( ! isset( $this->settings[ 'vendor' ][ $required_vendor_field ] ) ) {
132
+				$errors[ ] = new WP_Error( 'missing_configuration', sprintf( 'Missing required configuration: `vendor/%s`', $required_vendor_field ) );
133 133
 			}
134 134
 		}
135 135
 
136
-		if ( isset( $this->settings['decay'] ) ) {
137
-			if ( ! is_int( $this->settings['decay'] ) ) {
138
-				$errors[] = new WP_Error( 'invalid_configuration', 'Decay must be an integer (number of seconds).' );
139
-			} elseif ( $this->settings['decay'] > MONTH_IN_SECONDS ) {
140
-				$errors[] = new WP_Error( 'invalid_configuration', 'Decay must be less than or equal to 30 days.' );
141
-			} elseif ( $this->settings['decay'] < DAY_IN_SECONDS ) {
142
-				$errors[] = new WP_Error( 'invalid_configuration', 'Decay must be greater than 1 day.' );
136
+		if ( isset( $this->settings[ 'decay' ] ) ) {
137
+			if ( ! is_int( $this->settings[ 'decay' ] ) ) {
138
+				$errors[ ] = new WP_Error( 'invalid_configuration', 'Decay must be an integer (number of seconds).' );
139
+			} elseif ( $this->settings[ 'decay' ] > MONTH_IN_SECONDS ) {
140
+				$errors[ ] = new WP_Error( 'invalid_configuration', 'Decay must be less than or equal to 30 days.' );
141
+			} elseif ( $this->settings[ 'decay' ] < DAY_IN_SECONDS ) {
142
+				$errors[ ] = new WP_Error( 'invalid_configuration', 'Decay must be greater than 1 day.' );
143 143
 			}
144 144
 		}
145 145
 
146
-		if ( isset( $this->settings['vendor']['namespace'] ) ) {
146
+		if ( isset( $this->settings[ 'vendor' ][ 'namespace' ] ) ) {
147 147
 
148 148
 			// This seems like a reasonable max limit on namespace length.
149 149
 			// @see https://developer.wordpress.org/reference/functions/set_transient/#more-information
150
-			if ( strlen( $this->settings['vendor']['namespace'] ) > 96 ) {
151
-				$errors[] = new WP_Error( 'invalid_configuration', 'Namespace length must be shorter than 96 characters.' );
150
+			if ( strlen( $this->settings[ 'vendor' ][ 'namespace' ] ) > 96 ) {
151
+				$errors[ ] = new WP_Error( 'invalid_configuration', 'Namespace length must be shorter than 96 characters.' );
152 152
 			}
153 153
 
154
-			if ( in_array( strtolower( $this->settings['vendor']['namespace'] ), self::$reserved_namespaces, true ) ) {
155
-				$errors[] = new WP_Error( 'invalid_configuration', 'The defined namespace is reserved.' );
154
+			if ( in_array( strtolower( $this->settings[ 'vendor' ][ 'namespace' ] ), self::$reserved_namespaces, true ) ) {
155
+				$errors[ ] = new WP_Error( 'invalid_configuration', 'The defined namespace is reserved.' );
156 156
 			}
157 157
 		}
158 158
 
159
-		if ( isset( $this->settings['vendor'][ 'email' ] ) && ! filter_var( $this->settings['vendor'][ 'email' ], FILTER_VALIDATE_EMAIL ) ) {
160
-			$errors[] = new WP_Error( 'invalid_configuration', 'An invalid `vendor/email` setting was passed to the TrustedLogin Client.' );
159
+		if ( isset( $this->settings[ 'vendor' ][ 'email' ] ) && ! filter_var( $this->settings[ 'vendor' ][ 'email' ], FILTER_VALIDATE_EMAIL ) ) {
160
+			$errors[ ] = new WP_Error( 'invalid_configuration', 'An invalid `vendor/email` setting was passed to the TrustedLogin Client.' );
161 161
 		}
162 162
 
163 163
 		// TODO: Add namespace collision check?
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 			$value = $this->get_setting( $settings_key, '', $this->settings );
166 166
 			$url   = wp_kses_bad_protocol( $value, array( 'http', 'https' ) );
167 167
 			if ( $value && ! filter_var( $url, FILTER_VALIDATE_URL ) ) {
168
-				$errors[] = new WP_Error(
168
+				$errors[ ] = new WP_Error(
169 169
 					'invalid_configuration',
170 170
 					sprintf( 'An invalid `%s` setting was passed to the TrustedLogin Client: %s',
171 171
 						$settings_key,
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 
180 180
 		foreach ( SupportRole::$prevented_caps as $invalid_cap ) {
181 181
 			if ( array_key_exists( $invalid_cap, $added_caps ) ) {
182
-				$errors[] = new WP_Error( 'invalid_configuration', 'TrustedLogin users cannot be allowed to: ' . $invalid_cap );
182
+				$errors[ ] = new WP_Error( 'invalid_configuration', 'TrustedLogin users cannot be allowed to: ' . $invalid_cap );
183 183
 			}
184 184
 		}
185 185
 
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 			$error_text = array();
188 188
 			foreach ( $errors as $error ) {
189 189
 				if ( is_wp_error( $error ) ) {
190
-					$error_text[] = $error->get_error_message();
190
+					$error_text[ ] = $error->get_error_message();
191 191
 				}
192 192
 			}
193 193
 
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 
223 223
 		$time = current_time( 'timestamp', $gmt );
224 224
 
225
-		return $time + (int) $decay_time;
225
+		return $time + (int)$decay_time;
226 226
 	}
227 227
 
228 228
 	/**
@@ -282,8 +282,8 @@  discard block
 block discarded – undo
282 282
 
283 283
 		$default_settings = $this->default_settings;
284 284
 
285
-		$default_settings['paths']['css'] = plugin_dir_url( __FILE__ ) . 'assets/trustedlogin.css';
286
-		$default_settings['paths']['js']  = plugin_dir_url( __FILE__ ) . 'assets/trustedlogin.js';
285
+		$default_settings[ 'paths' ][ 'css' ] = plugin_dir_url( __FILE__ ) . 'assets/trustedlogin.css';
286
+		$default_settings[ 'paths' ][ 'js' ]  = plugin_dir_url( __FILE__ ) . 'assets/trustedlogin.js';
287 287
 
288 288
 		return $default_settings;
289 289
 	}
Please login to merge, or discard this patch.
trustedlogin/trustedlogin/client/src/Admin.php 2 patches
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 
125 125
 		$registered = array();
126 126
 
127
-		$registered['trustedlogin-js'] = wp_register_script(
127
+		$registered[ 'trustedlogin-js' ] = wp_register_script(
128 128
 			'trustedlogin-' . $this->config->ns(),
129 129
 			$this->config->get_setting( 'paths/js' ),
130 130
 			array( 'jquery', 'wp-a11y' ),
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 			true
133 133
 		);
134 134
 
135
-		$registered['trustedlogin-css'] = wp_register_style(
135
+		$registered[ 'trustedlogin-css' ] = wp_register_style(
136 136
 			'trustedlogin-' . $this->config->ns(),
137 137
 			$this->config->get_setting( 'paths/css' ),
138 138
 			array(),
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 	 * @return bool
249 249
 	 */
250 250
 	private function is_login_screen() {
251
-		return did_action( 'login_init' ) && isset( $_GET['ns'] ) && $_GET['ns'] === $this->config->ns();
251
+		return did_action( 'login_init' ) && isset( $_GET[ 'ns' ] ) && $_GET[ 'ns' ] === $this->config->ns();
252 252
 	}
253 253
 
254 254
 	/**
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
 
265 265
 		// Once logged-in, take user back to auth request screen.
266 266
 		if ( ! is_user_logged_in() ) {
267
-			$_REQUEST['redirect_to'] = site_url( add_query_arg( array() ) );
267
+			$_REQUEST[ 'redirect_to' ] = site_url( add_query_arg( array() ) );
268 268
 			return;
269 269
 		}
270 270
 
@@ -282,19 +282,19 @@  discard block
 block discarded – undo
282 282
 		$interim_login = true;
283 283
 
284 284
 		// The login_headertitle filter was deprecated in WP 5.2.0 for login_headertext
285
-		if( version_compare( $wp_version, '5.2.0', '<' ) ) {
285
+		if ( version_compare( $wp_version, '5.2.0', '<' ) ) {
286 286
 			add_filter( 'login_headertitle', '__return_empty_string' );
287 287
 		} else {
288 288
 			add_filter( 'login_headertext', '__return_empty_string' );
289 289
 		}
290 290
 
291
-		add_filter( 'login_headerurl', function () {
291
+		add_filter( 'login_headerurl', function() {
292 292
 			return $this->config->get_setting( 'vendor/website' );
293 293
 		});
294 294
 
295 295
 		login_header();
296 296
 
297
-		wp_enqueue_style( 'common');
297
+		wp_enqueue_style( 'common' );
298 298
 
299 299
 		wp_add_inline_style( 'common', $this->get_login_inline_css() );
300 300
 
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 	margin-top: 36px;
325 325
 }
326 326
 .login h1 a {
327
-	background-image: url("' . $this->config->get_setting( 'vendor/logo_url' ). '")!important;
327
+	background-image: url("' . $this->config->get_setting( 'vendor/logo_url' ) . '")!important;
328 328
 	background-size: contain!important;
329 329
 }
330 330
 ';
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 			return '';
349 349
 		}
350 350
 
351
-		$support_user = $support_users[0];
351
+		$support_user = $support_users[ 0 ];
352 352
 
353 353
 		$_user_creator_id = get_user_option( $this->support_user->created_by_meta_key, $support_user->ID );
354 354
 		$_user_creator    = $_user_creator_id ? get_user_by( 'id', $_user_creator_id ) : false;
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 			return '';
486 486
 		}
487 487
 
488
-		$template =  '<div class="tl-{{ns}}-auth__ref"><p><span class="tl-{{ns}}-auth_ref__id">{{reference_text}}</span></p></div>';
488
+		$template = '<div class="tl-{{ns}}-auth__ref"><p><span class="tl-{{ns}}-auth_ref__id">{{reference_text}}</span></p></div>';
489 489
 
490 490
 		$content = array(
491 491
 			'reference_text' => sprintf( esc_html__( 'Reference #%s', 'trustedlogin' ), $reference_id ),
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
 		if ( $has_access ) {
504 504
 			foreach ( $has_access as $access ) {
505 505
 				// translators: %1$s is replaced with the name of the software developer (e.g. "Acme Widgets"). %2$s is the amount of time remaining for access ("1 week")
506
-				$intro = sprintf( esc_html__( '%1$s has site access that expires in %2$s.', 'trustedlogin' ), '<a href="' . esc_url( $this->config->get_setting('vendor/website') ) . '" target="_blank" rel="noopener noreferrer">' . $this->config->get_setting( 'vendor/title' ) . '</a>', str_replace( ' ', '&nbsp;', $this->support_user->get_expiration( $access, true, false ) ) );
506
+				$intro = sprintf( esc_html__( '%1$s has site access that expires in %2$s.', 'trustedlogin' ), '<a href="' . esc_url( $this->config->get_setting( 'vendor/website' ) ) . '" target="_blank" rel="noopener noreferrer">' . $this->config->get_setting( 'vendor/title' ) . '</a>', str_replace( ' ', '&nbsp;', $this->support_user->get_expiration( $access, true, false ) ) );
507 507
 			}
508 508
 
509 509
 			return $intro;
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
 
512 512
 		if ( $this->is_login_screen() ) {
513 513
 			// translators: %1$s is replaced with the name of the software developer (e.g. "Acme Widgets")
514
-			$intro = sprintf( esc_html__( '%1$s would like support access to this site.', 'trustedlogin' ), '<a href="'. esc_url( $this->config->get_setting( 'vendor/website' ) ) . '">' . $this->config->get_display_name() . '</a>' );
514
+			$intro = sprintf( esc_html__( '%1$s would like support access to this site.', 'trustedlogin' ), '<a href="' . esc_url( $this->config->get_setting( 'vendor/website' ) ) . '">' . $this->config->get_display_name() . '</a>' );
515 515
 		} else {
516 516
 			// translators: %1$s is replaced with the name of the software developer (e.g. "Acme Widgets")
517 517
 			$intro = sprintf( esc_html__( 'Grant %1$s access to this site.', 'trustedlogin' ), '<a href="' . esc_url( $this->config->get_setting( 'vendor/website' ) ) . '">' . $this->config->get_display_name() . '</a>' );
@@ -604,7 +604,7 @@  discard block
 block discarded – undo
604 604
 	 */
605 605
 	private function get_caps_section( $caps_array, $heading = '', $dashicon = '' ) {
606 606
 
607
-		$caps_array = array_filter( (array) $caps_array, array( $this->config, 'is_not_null' ) );
607
+		$caps_array = array_filter( (array)$caps_array, array( $this->config, 'is_not_null' ) );
608 608
 
609 609
 		if ( empty( $caps_array ) ) {
610 610
 			return '';
@@ -615,10 +615,10 @@  discard block
 block discarded – undo
615 615
 		$output .= '<h3>' . esc_html( $heading ) . '</h3>';
616 616
 		$output .= '<ul>';
617 617
 
618
-		foreach ( (array) $caps_array as $cap => $reason ) {
618
+		foreach ( (array)$caps_array as $cap => $reason ) {
619 619
 			$dashicon = '<span class="dashicons ' . esc_attr( $dashicon ) . ' dashicons--small"></span>';
620 620
 			$reason   = empty( $reason ) ? '' : '<small>' . esc_html( $reason ) . '</small>';
621
-			$output   .= sprintf( '<li>%s<span class="code">%s</span>%s</li>', $dashicon, esc_html( $cap ), $reason );
621
+			$output .= sprintf( '<li>%s<span class="code">%s</span>%s</li>', $dashicon, esc_html( $cap ), $reason );
622 622
 		}
623 623
 
624 624
 		$output .= '</ul>';
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
 
749 749
 			// Allow SVGs for logos
750 750
 			$allowed_protocols   = wp_allowed_protocols();
751
-			$allowed_protocols[] = 'data';
751
+			$allowed_protocols[ ] = 'data';
752 752
 
753 753
 			$output_html = wp_kses( $output_html, array(
754 754
 				'a'       => array(
@@ -790,10 +790,10 @@  discard block
 block discarded – undo
790 790
 				'p'       => array( 'class' => array(), 'id' => array() ),
791 791
 				'h1'      => array( 'class' => array(), 'id' => array() ),
792 792
 				'h2'      => array( 'class' => array(), 'id' => array() ),
793
-				'h3'      => array( 'class' => array(), 'id' => array(), 'style'       => array(), ),
793
+				'h3'      => array( 'class' => array(), 'id' => array(), 'style'       => array(),),
794 794
 				'h4'      => array( 'class' => array(), 'id' => array() ),
795 795
 				'h5'      => array( 'class' => array(), 'id' => array() ),
796
-				'div'     => array( 'class' => array(), 'id' => array(), 'aria-live' => array(), 'style' => array(), ),
796
+				'div'     => array( 'class' => array(), 'id' => array(), 'aria-live' => array(), 'style' => array(),),
797 797
 				'small'   => array( 'class' => array(), 'id' => array(), 'data-toggle' => array() ),
798 798
 				'header'  => array( 'class' => array(), 'id' => array() ),
799 799
 				'footer'  => array( 'class' => array(), 'id' => array() ),
@@ -914,7 +914,7 @@  discard block
 block discarded – undo
914 914
 
915 915
 		$atts = wp_parse_args( $atts, $defaults );
916 916
 
917
-		switch ( $atts['size'] ) {
917
+		switch ( $atts[ 'size' ] ) {
918 918
 			case '':
919 919
 				$css_class = '';
920 920
 				break;
@@ -922,17 +922,17 @@  discard block
 block discarded – undo
922 922
 				$css_class = 'button';
923 923
 				break;
924 924
 			default:
925
-				if ( ! in_array( $atts['size'], $sizes ) ) {
926
-					$atts['size'] = 'hero';
925
+				if ( ! in_array( $atts[ 'size' ], $sizes ) ) {
926
+					$atts[ 'size' ] = 'hero';
927 927
 				}
928 928
 
929
-				$css_class = 'button button-' . $atts['size'];
929
+				$css_class = 'button button-' . $atts[ 'size' ];
930 930
 		}
931 931
 
932 932
 		$_valid_tags = array( 'a', 'button', 'span' );
933 933
 
934
-		if ( ! empty( $atts['tag'] ) && in_array( strtolower( $atts['tag'] ), $_valid_tags, true ) ) {
935
-			$tag = $atts['tag'];
934
+		if ( ! empty( $atts[ 'tag' ] ) && in_array( strtolower( $atts[ 'tag' ] ), $_valid_tags, true ) ) {
935
+			$tag = $atts[ 'tag' ];
936 936
 		} else {
937 937
 			$tag = 'a';
938 938
 		}
@@ -940,16 +940,16 @@  discard block
 block discarded – undo
940 940
 		$data_atts = array();
941 941
 
942 942
 		if ( $this->support_user->get_all() ) {
943
-			$text                = '<span class="dashicons dashicons-update-alt"></span>' . esc_html( $atts['exists_text'] );
943
+			$text                = '<span class="dashicons dashicons-update-alt"></span>' . esc_html( $atts[ 'exists_text' ] );
944 944
 			$href                = admin_url( 'users.php?role=' . $this->support_user->role->get_name() );
945
-			$data_atts['access'] = 'extend';
945
+			$data_atts[ 'access' ] = 'extend';
946 946
 		} else {
947
-			$text                = esc_html( $atts['text'] );
948
-			$href                = $atts['support_url'];
949
-			$data_atts['access'] = 'grant';
947
+			$text                = esc_html( $atts[ 'text' ] );
948
+			$href                = $atts[ 'support_url' ];
949
+			$data_atts[ 'access' ] = 'grant';
950 950
 		}
951 951
 
952
-		$css_class = implode( ' ', array( $css_class, $atts['class'] ) );
952
+		$css_class = implode( ' ', array( $css_class, $atts[ 'class' ] ) );
953 953
 		$css_class = trim( $css_class );
954 954
 
955 955
 		$data_string = '';
@@ -958,7 +958,7 @@  discard block
 block discarded – undo
958 958
 		}
959 959
 
960 960
 		$powered_by = '';
961
-		if ( $atts['powered_by'] ) {
961
+		if ( $atts[ 'powered_by' ] ) {
962 962
 			$powered_by = sprintf( '<small><span class="trustedlogin-logo"></span>%s</small>',
963 963
 				esc_html__( 'Secured by TrustedLogin', 'trustedlogin' )
964 964
 			);
@@ -1159,7 +1159,7 @@  discard block
 block discarded – undo
1159 1159
 	<p>%4\$s <samp>%5\$s</samp></p>
1160 1160
 </%3\$s>
1161 1161
 EOD;
1162
-			$access_key_output   = sprintf(
1162
+			$access_key_output = sprintf(
1163 1163
 				$access_key_template,
1164 1164
 				/* %1$s */ sanitize_title( $this->config->ns() ),
1165 1165
 				/* %2$s */ esc_html__( 'Error', 'trustedlogin' ),
@@ -1181,7 +1181,7 @@  discard block
 block discarded – undo
1181 1181
 	</div>
1182 1182
 </%6\$s>
1183 1183
 EOD;
1184
-			$access_key_output   = sprintf(
1184
+			$access_key_output = sprintf(
1185 1185
 				$access_key_template,
1186 1186
 				/* %1$s */ sanitize_title( $this->config->ns() ),
1187 1187
 				/* %2$s */ esc_html__( 'Site access key:', 'trustedlogin' ),
Please login to merge, or discard this patch.
Upper-Lower-Casing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1158,7 +1158,7 @@  discard block
 block discarded – undo
1158 1158
 	<h3>%2\$s</h3>
1159 1159
 	<p>%4\$s <samp>%5\$s</samp></p>
1160 1160
 </%3\$s>
1161
-EOD;
1161
+eod;
1162 1162
 			$access_key_output   = sprintf(
1163 1163
 				$access_key_template,
1164 1164
 				/* %1$s */ sanitize_title( $this->config->ns() ),
@@ -1180,7 +1180,7 @@  discard block
 block discarded – undo
1180 1180
 		<button id="tl-%1\$s-copy" class="tl-%1\$s-auth__accesskey_copy button" aria-live="off" title="%7\$s"><span class="screen-reader-text">%5\$s</span></button>
1181 1181
 	</div>
1182 1182
 </%6\$s>
1183
-EOD;
1183
+eod;
1184 1184
 			$access_key_output   = sprintf(
1185 1185
 				$access_key_template,
1186 1186
 				/* %1$s */ sanitize_title( $this->config->ns() ),
Please login to merge, or discard this patch.
trustedlogin/katzgrau/klogger/src/Logger.php 3 patches
Indentation   +318 added lines, -318 removed lines patch added patch discarded remove patch
@@ -34,322 +34,322 @@
 block discarded – undo
34 34
  */
35 35
 class Logger extends AbstractLogger
36 36
 {
37
-    /**
38
-     * KLogger options
39
-     *  Anything options not considered 'core' to the logging library should be
40
-     *  settable view the third parameter in the constructor
41
-     *
42
-     *  Core options include the log file path and the log threshold
43
-     *
44
-     * @var array
45
-     */
46
-    protected $options = array (
47
-        'extension'      => 'txt',
48
-        'dateFormat'     => 'Y-m-d G:i:s.u',
49
-        'filename'       => false,
50
-        'flushFrequency' => false,
51
-        'prefix'         => 'log_',
52
-        'logFormat'      => false,
53
-        'appendContext'  => true,
54
-    );
55
-
56
-    /**
57
-     * Path to the log file
58
-     * @var string
59
-     */
60
-    private $logFilePath;
61
-
62
-    /**
63
-     * Current minimum logging threshold
64
-     * @var integer
65
-     */
66
-    protected $logLevelThreshold = LogLevel::DEBUG;
67
-
68
-    /**
69
-     * The number of lines logged in this instance's lifetime
70
-     * @var int
71
-     */
72
-    private $logLineCount = 0;
73
-
74
-    /**
75
-     * Log Levels
76
-     * @var array
77
-     */
78
-    protected $logLevels = array(
79
-        LogLevel::EMERGENCY => 0,
80
-        LogLevel::ALERT     => 1,
81
-        LogLevel::CRITICAL  => 2,
82
-        LogLevel::ERROR     => 3,
83
-        LogLevel::WARNING   => 4,
84
-        LogLevel::NOTICE    => 5,
85
-        LogLevel::INFO      => 6,
86
-        LogLevel::DEBUG     => 7
87
-    );
88
-
89
-    /**
90
-     * This holds the file handle for this instance's log file
91
-     * @var resource
92
-     */
93
-    private $fileHandle;
94
-
95
-    /**
96
-     * This holds the last line logged to the logger
97
-     *  Used for unit tests
98
-     * @var string
99
-     */
100
-    private $lastLine = '';
101
-
102
-    /**
103
-     * Octal notation for default permissions of the log file
104
-     * @var integer
105
-     */
106
-    private $defaultPermissions = 0777;
107
-
108
-    /**
109
-     * Class constructor
110
-     *
111
-     * @param string $logDirectory      File path to the logging directory
112
-     * @param string $logLevelThreshold The LogLevel Threshold
113
-     * @param array  $options
114
-     *
115
-     * @internal param string $logFilePrefix The prefix for the log file name
116
-     * @internal param string $logFileExt The extension for the log file
117
-     */
118
-    public function __construct($logDirectory, $logLevelThreshold = LogLevel::DEBUG, array $options = array())
119
-    {
120
-        $this->logLevelThreshold = $logLevelThreshold;
121
-        $this->options = array_merge($this->options, $options);
122
-
123
-        $logDirectory = rtrim($logDirectory, DIRECTORY_SEPARATOR);
124
-        if ( ! file_exists($logDirectory)) {
125
-            mkdir($logDirectory, $this->defaultPermissions, true);
126
-        }
127
-
128
-        if(strpos($logDirectory, 'php://') === 0) {
129
-            $this->setLogToStdOut($logDirectory);
130
-            $this->setFileHandle('w+');
131
-        } else {
132
-            $this->setLogFilePath($logDirectory);
133
-            if(file_exists($this->logFilePath) && !is_writable($this->logFilePath)) {
134
-                throw new RuntimeException('The file could not be written to. Check that appropriate permissions have been set.');
135
-            }
136
-            $this->setFileHandle('a');
137
-        }
138
-
139
-        if ( ! $this->fileHandle) {
140
-            throw new RuntimeException('The file could not be opened. Check permissions.');
141
-        }
142
-    }
143
-
144
-    /**
145
-     * @param string $stdOutPath
146
-     */
147
-    public function setLogToStdOut($stdOutPath) {
148
-        $this->logFilePath = $stdOutPath;
149
-    }
150
-
151
-    /**
152
-     * @param string $logDirectory
153
-     */
154
-    public function setLogFilePath($logDirectory) {
155
-        if ($this->options['filename']) {
156
-            if (strpos($this->options['filename'], '.log') !== false || strpos($this->options['filename'], '.txt') !== false) {
157
-                $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['filename'];
158
-            }
159
-            else {
160
-                $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['filename'].'.'.$this->options['extension'];
161
-            }
162
-        } else {
163
-            $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['prefix'].date('Y-m-d').'.'.$this->options['extension'];
164
-        }
165
-    }
166
-
167
-    /**
168
-     * @param $writeMode
169
-     *
170
-     * @internal param resource $fileHandle
171
-     */
172
-    public function setFileHandle($writeMode) {
173
-        $this->fileHandle = fopen($this->logFilePath, $writeMode);
174
-    }
175
-
176
-
177
-    /**
178
-     * Class destructor
179
-     */
180
-    public function __destruct()
181
-    {
182
-        if ($this->fileHandle) {
183
-            fclose($this->fileHandle);
184
-        }
185
-    }
186
-
187
-    /**
188
-     * Sets the date format used by all instances of KLogger
189
-     *
190
-     * @param string $dateFormat Valid format string for date()
191
-     */
192
-    public function setDateFormat($dateFormat)
193
-    {
194
-        $this->options['dateFormat'] = $dateFormat;
195
-    }
196
-
197
-    /**
198
-     * Sets the Log Level Threshold
199
-     *
200
-     * @param string $logLevelThreshold The log level threshold
201
-     */
202
-    public function setLogLevelThreshold($logLevelThreshold)
203
-    {
204
-        $this->logLevelThreshold = $logLevelThreshold;
205
-    }
206
-
207
-    /**
208
-     * Logs with an arbitrary level.
209
-     *
210
-     * @param mixed $level
211
-     * @param string $message
212
-     * @param array $context
213
-     * @return null
214
-     */
215
-    public function log($level, $message, array $context = array())
216
-    {
217
-        if ($this->logLevels[$this->logLevelThreshold] < $this->logLevels[$level]) {
218
-            return;
219
-        }
220
-        $message = $this->formatMessage($level, $message, $context);
221
-        $this->write($message);
222
-    }
223
-
224
-    /**
225
-     * Writes a line to the log without prepending a status or timestamp
226
-     *
227
-     * @param string $message Line to write to the log
228
-     * @return void
229
-     */
230
-    public function write($message)
231
-    {
232
-        if (null !== $this->fileHandle) {
233
-            if (fwrite($this->fileHandle, $message) === false) {
234
-                throw new RuntimeException('The file could not be written to. Check that appropriate permissions have been set.');
235
-            } else {
236
-                $this->lastLine = trim($message);
237
-                $this->logLineCount++;
238
-
239
-                if ($this->options['flushFrequency'] && $this->logLineCount % $this->options['flushFrequency'] === 0) {
240
-                    fflush($this->fileHandle);
241
-                }
242
-            }
243
-        }
244
-    }
245
-
246
-    /**
247
-     * Get the file path that the log is currently writing to
248
-     *
249
-     * @return string
250
-     */
251
-    public function getLogFilePath()
252
-    {
253
-        return $this->logFilePath;
254
-    }
255
-
256
-    /**
257
-     * Get the last line logged to the log file
258
-     *
259
-     * @return string
260
-     */
261
-    public function getLastLogLine()
262
-    {
263
-        return $this->lastLine;
264
-    }
265
-
266
-    /**
267
-     * Formats the message for logging.
268
-     *
269
-     * @param  string $level   The Log Level of the message
270
-     * @param  string $message The message to log
271
-     * @param  array  $context The context
272
-     * @return string
273
-     */
274
-    protected function formatMessage($level, $message, $context)
275
-    {
276
-        if ($this->options['logFormat']) {
277
-            $parts = array(
278
-                'date'          => $this->getTimestamp(),
279
-                'level'         => strtoupper($level),
280
-                'level-padding' => str_repeat(' ', 9 - strlen($level)),
281
-                'priority'      => $this->logLevels[$level],
282
-                'message'       => $message,
283
-                'context'       => json_encode($context),
284
-            );
285
-            $message = $this->options['logFormat'];
286
-            foreach ($parts as $part => $value) {
287
-                $message = str_replace('{'.$part.'}', $value, $message);
288
-            }
289
-
290
-        } else {
291
-            $message = "[{$this->getTimestamp()}] [{$level}] {$message}";
292
-        }
293
-
294
-        if ($this->options['appendContext'] && ! empty($context)) {
295
-            $message .= PHP_EOL.$this->indent($this->contextToString($context));
296
-        }
297
-
298
-        return $message.PHP_EOL;
299
-
300
-    }
301
-
302
-    /**
303
-     * Gets the correctly formatted Date/Time for the log entry.
304
-     *
305
-     * PHP DateTime is dump, and you have to resort to trickery to get microseconds
306
-     * to work correctly, so here it is.
307
-     *
308
-     * @return string
309
-     */
310
-    private function getTimestamp()
311
-    {
312
-        $originalTime = microtime(true);
313
-        $micro = sprintf("%06d", ($originalTime - floor($originalTime)) * 1000000);
314
-        $date = new DateTime(date('Y-m-d H:i:s.'.$micro, (int)$originalTime));
315
-
316
-        return $date->format($this->options['dateFormat']);
317
-    }
318
-
319
-    /**
320
-     * Takes the given context and coverts it to a string.
321
-     *
322
-     * @param  array $context The Context
323
-     * @return string
324
-     */
325
-    protected function contextToString($context)
326
-    {
327
-        $export = '';
328
-        foreach ($context as $key => $value) {
329
-            $export .= "{$key}: ";
330
-            $export .= preg_replace(array(
331
-                '/=>\s+([a-zA-Z])/im',
332
-                '/array\(\s+\)/im',
333
-                '/^  |\G  /m'
334
-            ), array(
335
-                '=> $1',
336
-                'array()',
337
-                '    '
338
-            ), str_replace('array (', 'array(', var_export($value, true)));
339
-            $export .= PHP_EOL;
340
-        }
341
-        return str_replace(array('\\\\', '\\\''), array('\\', '\''), rtrim($export));
342
-    }
343
-
344
-    /**
345
-     * Indents the given string with the given indent.
346
-     *
347
-     * @param  string $string The string to indent
348
-     * @param  string $indent What to use as the indent.
349
-     * @return string
350
-     */
351
-    protected function indent($string, $indent = '    ')
352
-    {
353
-        return $indent.str_replace("\n", "\n".$indent, $string);
354
-    }
37
+	/**
38
+	 * KLogger options
39
+	 *  Anything options not considered 'core' to the logging library should be
40
+	 *  settable view the third parameter in the constructor
41
+	 *
42
+	 *  Core options include the log file path and the log threshold
43
+	 *
44
+	 * @var array
45
+	 */
46
+	protected $options = array (
47
+		'extension'      => 'txt',
48
+		'dateFormat'     => 'Y-m-d G:i:s.u',
49
+		'filename'       => false,
50
+		'flushFrequency' => false,
51
+		'prefix'         => 'log_',
52
+		'logFormat'      => false,
53
+		'appendContext'  => true,
54
+	);
55
+
56
+	/**
57
+	 * Path to the log file
58
+	 * @var string
59
+	 */
60
+	private $logFilePath;
61
+
62
+	/**
63
+	 * Current minimum logging threshold
64
+	 * @var integer
65
+	 */
66
+	protected $logLevelThreshold = LogLevel::DEBUG;
67
+
68
+	/**
69
+	 * The number of lines logged in this instance's lifetime
70
+	 * @var int
71
+	 */
72
+	private $logLineCount = 0;
73
+
74
+	/**
75
+	 * Log Levels
76
+	 * @var array
77
+	 */
78
+	protected $logLevels = array(
79
+		LogLevel::EMERGENCY => 0,
80
+		LogLevel::ALERT     => 1,
81
+		LogLevel::CRITICAL  => 2,
82
+		LogLevel::ERROR     => 3,
83
+		LogLevel::WARNING   => 4,
84
+		LogLevel::NOTICE    => 5,
85
+		LogLevel::INFO      => 6,
86
+		LogLevel::DEBUG     => 7
87
+	);
88
+
89
+	/**
90
+	 * This holds the file handle for this instance's log file
91
+	 * @var resource
92
+	 */
93
+	private $fileHandle;
94
+
95
+	/**
96
+	 * This holds the last line logged to the logger
97
+	 *  Used for unit tests
98
+	 * @var string
99
+	 */
100
+	private $lastLine = '';
101
+
102
+	/**
103
+	 * Octal notation for default permissions of the log file
104
+	 * @var integer
105
+	 */
106
+	private $defaultPermissions = 0777;
107
+
108
+	/**
109
+	 * Class constructor
110
+	 *
111
+	 * @param string $logDirectory      File path to the logging directory
112
+	 * @param string $logLevelThreshold The LogLevel Threshold
113
+	 * @param array  $options
114
+	 *
115
+	 * @internal param string $logFilePrefix The prefix for the log file name
116
+	 * @internal param string $logFileExt The extension for the log file
117
+	 */
118
+	public function __construct($logDirectory, $logLevelThreshold = LogLevel::DEBUG, array $options = array())
119
+	{
120
+		$this->logLevelThreshold = $logLevelThreshold;
121
+		$this->options = array_merge($this->options, $options);
122
+
123
+		$logDirectory = rtrim($logDirectory, DIRECTORY_SEPARATOR);
124
+		if ( ! file_exists($logDirectory)) {
125
+			mkdir($logDirectory, $this->defaultPermissions, true);
126
+		}
127
+
128
+		if(strpos($logDirectory, 'php://') === 0) {
129
+			$this->setLogToStdOut($logDirectory);
130
+			$this->setFileHandle('w+');
131
+		} else {
132
+			$this->setLogFilePath($logDirectory);
133
+			if(file_exists($this->logFilePath) && !is_writable($this->logFilePath)) {
134
+				throw new RuntimeException('The file could not be written to. Check that appropriate permissions have been set.');
135
+			}
136
+			$this->setFileHandle('a');
137
+		}
138
+
139
+		if ( ! $this->fileHandle) {
140
+			throw new RuntimeException('The file could not be opened. Check permissions.');
141
+		}
142
+	}
143
+
144
+	/**
145
+	 * @param string $stdOutPath
146
+	 */
147
+	public function setLogToStdOut($stdOutPath) {
148
+		$this->logFilePath = $stdOutPath;
149
+	}
150
+
151
+	/**
152
+	 * @param string $logDirectory
153
+	 */
154
+	public function setLogFilePath($logDirectory) {
155
+		if ($this->options['filename']) {
156
+			if (strpos($this->options['filename'], '.log') !== false || strpos($this->options['filename'], '.txt') !== false) {
157
+				$this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['filename'];
158
+			}
159
+			else {
160
+				$this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['filename'].'.'.$this->options['extension'];
161
+			}
162
+		} else {
163
+			$this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['prefix'].date('Y-m-d').'.'.$this->options['extension'];
164
+		}
165
+	}
166
+
167
+	/**
168
+	 * @param $writeMode
169
+	 *
170
+	 * @internal param resource $fileHandle
171
+	 */
172
+	public function setFileHandle($writeMode) {
173
+		$this->fileHandle = fopen($this->logFilePath, $writeMode);
174
+	}
175
+
176
+
177
+	/**
178
+	 * Class destructor
179
+	 */
180
+	public function __destruct()
181
+	{
182
+		if ($this->fileHandle) {
183
+			fclose($this->fileHandle);
184
+		}
185
+	}
186
+
187
+	/**
188
+	 * Sets the date format used by all instances of KLogger
189
+	 *
190
+	 * @param string $dateFormat Valid format string for date()
191
+	 */
192
+	public function setDateFormat($dateFormat)
193
+	{
194
+		$this->options['dateFormat'] = $dateFormat;
195
+	}
196
+
197
+	/**
198
+	 * Sets the Log Level Threshold
199
+	 *
200
+	 * @param string $logLevelThreshold The log level threshold
201
+	 */
202
+	public function setLogLevelThreshold($logLevelThreshold)
203
+	{
204
+		$this->logLevelThreshold = $logLevelThreshold;
205
+	}
206
+
207
+	/**
208
+	 * Logs with an arbitrary level.
209
+	 *
210
+	 * @param mixed $level
211
+	 * @param string $message
212
+	 * @param array $context
213
+	 * @return null
214
+	 */
215
+	public function log($level, $message, array $context = array())
216
+	{
217
+		if ($this->logLevels[$this->logLevelThreshold] < $this->logLevels[$level]) {
218
+			return;
219
+		}
220
+		$message = $this->formatMessage($level, $message, $context);
221
+		$this->write($message);
222
+	}
223
+
224
+	/**
225
+	 * Writes a line to the log without prepending a status or timestamp
226
+	 *
227
+	 * @param string $message Line to write to the log
228
+	 * @return void
229
+	 */
230
+	public function write($message)
231
+	{
232
+		if (null !== $this->fileHandle) {
233
+			if (fwrite($this->fileHandle, $message) === false) {
234
+				throw new RuntimeException('The file could not be written to. Check that appropriate permissions have been set.');
235
+			} else {
236
+				$this->lastLine = trim($message);
237
+				$this->logLineCount++;
238
+
239
+				if ($this->options['flushFrequency'] && $this->logLineCount % $this->options['flushFrequency'] === 0) {
240
+					fflush($this->fileHandle);
241
+				}
242
+			}
243
+		}
244
+	}
245
+
246
+	/**
247
+	 * Get the file path that the log is currently writing to
248
+	 *
249
+	 * @return string
250
+	 */
251
+	public function getLogFilePath()
252
+	{
253
+		return $this->logFilePath;
254
+	}
255
+
256
+	/**
257
+	 * Get the last line logged to the log file
258
+	 *
259
+	 * @return string
260
+	 */
261
+	public function getLastLogLine()
262
+	{
263
+		return $this->lastLine;
264
+	}
265
+
266
+	/**
267
+	 * Formats the message for logging.
268
+	 *
269
+	 * @param  string $level   The Log Level of the message
270
+	 * @param  string $message The message to log
271
+	 * @param  array  $context The context
272
+	 * @return string
273
+	 */
274
+	protected function formatMessage($level, $message, $context)
275
+	{
276
+		if ($this->options['logFormat']) {
277
+			$parts = array(
278
+				'date'          => $this->getTimestamp(),
279
+				'level'         => strtoupper($level),
280
+				'level-padding' => str_repeat(' ', 9 - strlen($level)),
281
+				'priority'      => $this->logLevels[$level],
282
+				'message'       => $message,
283
+				'context'       => json_encode($context),
284
+			);
285
+			$message = $this->options['logFormat'];
286
+			foreach ($parts as $part => $value) {
287
+				$message = str_replace('{'.$part.'}', $value, $message);
288
+			}
289
+
290
+		} else {
291
+			$message = "[{$this->getTimestamp()}] [{$level}] {$message}";
292
+		}
293
+
294
+		if ($this->options['appendContext'] && ! empty($context)) {
295
+			$message .= PHP_EOL.$this->indent($this->contextToString($context));
296
+		}
297
+
298
+		return $message.PHP_EOL;
299
+
300
+	}
301
+
302
+	/**
303
+	 * Gets the correctly formatted Date/Time for the log entry.
304
+	 *
305
+	 * PHP DateTime is dump, and you have to resort to trickery to get microseconds
306
+	 * to work correctly, so here it is.
307
+	 *
308
+	 * @return string
309
+	 */
310
+	private function getTimestamp()
311
+	{
312
+		$originalTime = microtime(true);
313
+		$micro = sprintf("%06d", ($originalTime - floor($originalTime)) * 1000000);
314
+		$date = new DateTime(date('Y-m-d H:i:s.'.$micro, (int)$originalTime));
315
+
316
+		return $date->format($this->options['dateFormat']);
317
+	}
318
+
319
+	/**
320
+	 * Takes the given context and coverts it to a string.
321
+	 *
322
+	 * @param  array $context The Context
323
+	 * @return string
324
+	 */
325
+	protected function contextToString($context)
326
+	{
327
+		$export = '';
328
+		foreach ($context as $key => $value) {
329
+			$export .= "{$key}: ";
330
+			$export .= preg_replace(array(
331
+				'/=>\s+([a-zA-Z])/im',
332
+				'/array\(\s+\)/im',
333
+				'/^  |\G  /m'
334
+			), array(
335
+				'=> $1',
336
+				'array()',
337
+				'    '
338
+			), str_replace('array (', 'array(', var_export($value, true)));
339
+			$export .= PHP_EOL;
340
+		}
341
+		return str_replace(array('\\\\', '\\\''), array('\\', '\''), rtrim($export));
342
+	}
343
+
344
+	/**
345
+	 * Indents the given string with the given indent.
346
+	 *
347
+	 * @param  string $string The string to indent
348
+	 * @param  string $indent What to use as the indent.
349
+	 * @return string
350
+	 */
351
+	protected function indent($string, $indent = '    ')
352
+	{
353
+		return $indent.str_replace("\n", "\n".$indent, $string);
354
+	}
355 355
 }
Please login to merge, or discard this patch.
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
      *
44 44
      * @var array
45 45
      */
46
-    protected $options = array (
46
+    protected $options = array(
47 47
         'extension'      => 'txt',
48 48
         'dateFormat'     => 'Y-m-d G:i:s.u',
49 49
         'filename'       => false,
@@ -115,52 +115,52 @@  discard block
 block discarded – undo
115 115
      * @internal param string $logFilePrefix The prefix for the log file name
116 116
      * @internal param string $logFileExt The extension for the log file
117 117
      */
118
-    public function __construct($logDirectory, $logLevelThreshold = LogLevel::DEBUG, array $options = array())
118
+    public function __construct( $logDirectory, $logLevelThreshold = LogLevel::DEBUG, array $options = array() )
119 119
     {
120 120
         $this->logLevelThreshold = $logLevelThreshold;
121
-        $this->options = array_merge($this->options, $options);
121
+        $this->options = array_merge( $this->options, $options );
122 122
 
123
-        $logDirectory = rtrim($logDirectory, DIRECTORY_SEPARATOR);
124
-        if ( ! file_exists($logDirectory)) {
125
-            mkdir($logDirectory, $this->defaultPermissions, true);
123
+        $logDirectory = rtrim( $logDirectory, DIRECTORY_SEPARATOR );
124
+        if ( ! file_exists( $logDirectory ) ) {
125
+            mkdir( $logDirectory, $this->defaultPermissions, true );
126 126
         }
127 127
 
128
-        if(strpos($logDirectory, 'php://') === 0) {
129
-            $this->setLogToStdOut($logDirectory);
130
-            $this->setFileHandle('w+');
128
+        if ( strpos( $logDirectory, 'php://' ) === 0 ) {
129
+            $this->setLogToStdOut( $logDirectory );
130
+            $this->setFileHandle( 'w+' );
131 131
         } else {
132
-            $this->setLogFilePath($logDirectory);
133
-            if(file_exists($this->logFilePath) && !is_writable($this->logFilePath)) {
134
-                throw new RuntimeException('The file could not be written to. Check that appropriate permissions have been set.');
132
+            $this->setLogFilePath( $logDirectory );
133
+            if ( file_exists( $this->logFilePath ) && ! is_writable( $this->logFilePath ) ) {
134
+                throw new RuntimeException( 'The file could not be written to. Check that appropriate permissions have been set.' );
135 135
             }
136
-            $this->setFileHandle('a');
136
+            $this->setFileHandle( 'a' );
137 137
         }
138 138
 
139
-        if ( ! $this->fileHandle) {
140
-            throw new RuntimeException('The file could not be opened. Check permissions.');
139
+        if ( ! $this->fileHandle ) {
140
+            throw new RuntimeException( 'The file could not be opened. Check permissions.' );
141 141
         }
142 142
     }
143 143
 
144 144
     /**
145 145
      * @param string $stdOutPath
146 146
      */
147
-    public function setLogToStdOut($stdOutPath) {
147
+    public function setLogToStdOut( $stdOutPath ) {
148 148
         $this->logFilePath = $stdOutPath;
149 149
     }
150 150
 
151 151
     /**
152 152
      * @param string $logDirectory
153 153
      */
154
-    public function setLogFilePath($logDirectory) {
155
-        if ($this->options['filename']) {
156
-            if (strpos($this->options['filename'], '.log') !== false || strpos($this->options['filename'], '.txt') !== false) {
157
-                $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['filename'];
154
+    public function setLogFilePath( $logDirectory ) {
155
+        if ( $this->options[ 'filename' ] ) {
156
+            if ( strpos( $this->options[ 'filename' ], '.log' ) !== false || strpos( $this->options[ 'filename' ], '.txt' ) !== false ) {
157
+                $this->logFilePath = $logDirectory . DIRECTORY_SEPARATOR . $this->options[ 'filename' ];
158 158
             }
159 159
             else {
160
-                $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['filename'].'.'.$this->options['extension'];
160
+                $this->logFilePath = $logDirectory . DIRECTORY_SEPARATOR . $this->options[ 'filename' ] . '.' . $this->options[ 'extension' ];
161 161
             }
162 162
         } else {
163
-            $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['prefix'].date('Y-m-d').'.'.$this->options['extension'];
163
+            $this->logFilePath = $logDirectory . DIRECTORY_SEPARATOR . $this->options[ 'prefix' ] . date( 'Y-m-d' ) . '.' . $this->options[ 'extension' ];
164 164
         }
165 165
     }
166 166
 
@@ -169,8 +169,8 @@  discard block
 block discarded – undo
169 169
      *
170 170
      * @internal param resource $fileHandle
171 171
      */
172
-    public function setFileHandle($writeMode) {
173
-        $this->fileHandle = fopen($this->logFilePath, $writeMode);
172
+    public function setFileHandle( $writeMode ) {
173
+        $this->fileHandle = fopen( $this->logFilePath, $writeMode );
174 174
     }
175 175
 
176 176
 
@@ -179,8 +179,8 @@  discard block
 block discarded – undo
179 179
      */
180 180
     public function __destruct()
181 181
     {
182
-        if ($this->fileHandle) {
183
-            fclose($this->fileHandle);
182
+        if ( $this->fileHandle ) {
183
+            fclose( $this->fileHandle );
184 184
         }
185 185
     }
186 186
 
@@ -189,9 +189,9 @@  discard block
 block discarded – undo
189 189
      *
190 190
      * @param string $dateFormat Valid format string for date()
191 191
      */
192
-    public function setDateFormat($dateFormat)
192
+    public function setDateFormat( $dateFormat )
193 193
     {
194
-        $this->options['dateFormat'] = $dateFormat;
194
+        $this->options[ 'dateFormat' ] = $dateFormat;
195 195
     }
196 196
 
197 197
     /**
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
      *
200 200
      * @param string $logLevelThreshold The log level threshold
201 201
      */
202
-    public function setLogLevelThreshold($logLevelThreshold)
202
+    public function setLogLevelThreshold( $logLevelThreshold )
203 203
     {
204 204
         $this->logLevelThreshold = $logLevelThreshold;
205 205
     }
@@ -212,13 +212,13 @@  discard block
 block discarded – undo
212 212
      * @param array $context
213 213
      * @return null
214 214
      */
215
-    public function log($level, $message, array $context = array())
215
+    public function log( $level, $message, array $context = array() )
216 216
     {
217
-        if ($this->logLevels[$this->logLevelThreshold] < $this->logLevels[$level]) {
217
+        if ( $this->logLevels[ $this->logLevelThreshold ] < $this->logLevels[ $level ] ) {
218 218
             return;
219 219
         }
220
-        $message = $this->formatMessage($level, $message, $context);
221
-        $this->write($message);
220
+        $message = $this->formatMessage( $level, $message, $context );
221
+        $this->write( $message );
222 222
     }
223 223
 
224 224
     /**
@@ -227,17 +227,17 @@  discard block
 block discarded – undo
227 227
      * @param string $message Line to write to the log
228 228
      * @return void
229 229
      */
230
-    public function write($message)
230
+    public function write( $message )
231 231
     {
232
-        if (null !== $this->fileHandle) {
233
-            if (fwrite($this->fileHandle, $message) === false) {
234
-                throw new RuntimeException('The file could not be written to. Check that appropriate permissions have been set.');
232
+        if ( null !== $this->fileHandle ) {
233
+            if ( fwrite( $this->fileHandle, $message ) === false ) {
234
+                throw new RuntimeException( 'The file could not be written to. Check that appropriate permissions have been set.' );
235 235
             } else {
236
-                $this->lastLine = trim($message);
236
+                $this->lastLine = trim( $message );
237 237
                 $this->logLineCount++;
238 238
 
239
-                if ($this->options['flushFrequency'] && $this->logLineCount % $this->options['flushFrequency'] === 0) {
240
-                    fflush($this->fileHandle);
239
+                if ( $this->options[ 'flushFrequency' ] && $this->logLineCount % $this->options[ 'flushFrequency' ] === 0 ) {
240
+                    fflush( $this->fileHandle );
241 241
                 }
242 242
             }
243 243
         }
@@ -271,31 +271,31 @@  discard block
 block discarded – undo
271 271
      * @param  array  $context The context
272 272
      * @return string
273 273
      */
274
-    protected function formatMessage($level, $message, $context)
274
+    protected function formatMessage( $level, $message, $context )
275 275
     {
276
-        if ($this->options['logFormat']) {
276
+        if ( $this->options[ 'logFormat' ] ) {
277 277
             $parts = array(
278 278
                 'date'          => $this->getTimestamp(),
279
-                'level'         => strtoupper($level),
280
-                'level-padding' => str_repeat(' ', 9 - strlen($level)),
281
-                'priority'      => $this->logLevels[$level],
279
+                'level'         => strtoupper( $level ),
280
+                'level-padding' => str_repeat( ' ', 9 - strlen( $level ) ),
281
+                'priority'      => $this->logLevels[ $level ],
282 282
                 'message'       => $message,
283
-                'context'       => json_encode($context),
283
+                'context'       => json_encode( $context ),
284 284
             );
285
-            $message = $this->options['logFormat'];
286
-            foreach ($parts as $part => $value) {
287
-                $message = str_replace('{'.$part.'}', $value, $message);
285
+            $message = $this->options[ 'logFormat' ];
286
+            foreach ( $parts as $part => $value ) {
287
+                $message = str_replace( '{' . $part . '}', $value, $message );
288 288
             }
289 289
 
290 290
         } else {
291 291
             $message = "[{$this->getTimestamp()}] [{$level}] {$message}";
292 292
         }
293 293
 
294
-        if ($this->options['appendContext'] && ! empty($context)) {
295
-            $message .= PHP_EOL.$this->indent($this->contextToString($context));
294
+        if ( $this->options[ 'appendContext' ] && ! empty( $context ) ) {
295
+            $message .= PHP_EOL . $this->indent( $this->contextToString( $context ) );
296 296
         }
297 297
 
298
-        return $message.PHP_EOL;
298
+        return $message . PHP_EOL;
299 299
 
300 300
     }
301 301
 
@@ -309,11 +309,11 @@  discard block
 block discarded – undo
309 309
      */
310 310
     private function getTimestamp()
311 311
     {
312
-        $originalTime = microtime(true);
313
-        $micro = sprintf("%06d", ($originalTime - floor($originalTime)) * 1000000);
314
-        $date = new DateTime(date('Y-m-d H:i:s.'.$micro, (int)$originalTime));
312
+        $originalTime = microtime( true );
313
+        $micro = sprintf( "%06d", ( $originalTime - floor( $originalTime ) ) * 1000000 );
314
+        $date = new DateTime( date( 'Y-m-d H:i:s.' . $micro, (int)$originalTime ) );
315 315
 
316
-        return $date->format($this->options['dateFormat']);
316
+        return $date->format( $this->options[ 'dateFormat' ] );
317 317
     }
318 318
 
319 319
     /**
@@ -322,12 +322,12 @@  discard block
 block discarded – undo
322 322
      * @param  array $context The Context
323 323
      * @return string
324 324
      */
325
-    protected function contextToString($context)
325
+    protected function contextToString( $context )
326 326
     {
327 327
         $export = '';
328
-        foreach ($context as $key => $value) {
328
+        foreach ( $context as $key => $value ) {
329 329
             $export .= "{$key}: ";
330
-            $export .= preg_replace(array(
330
+            $export .= preg_replace( array(
331 331
                 '/=>\s+([a-zA-Z])/im',
332 332
                 '/array\(\s+\)/im',
333 333
                 '/^  |\G  /m'
@@ -335,10 +335,10 @@  discard block
 block discarded – undo
335 335
                 '=> $1',
336 336
                 'array()',
337 337
                 '    '
338
-            ), str_replace('array (', 'array(', var_export($value, true)));
338
+            ), str_replace( 'array (', 'array(', var_export( $value, true ) ) );
339 339
             $export .= PHP_EOL;
340 340
         }
341
-        return str_replace(array('\\\\', '\\\''), array('\\', '\''), rtrim($export));
341
+        return str_replace( array( '\\\\', '\\\'' ), array( '\\', '\'' ), rtrim( $export ) );
342 342
     }
343 343
 
344 344
     /**
@@ -348,8 +348,8 @@  discard block
 block discarded – undo
348 348
      * @param  string $indent What to use as the indent.
349 349
      * @return string
350 350
      */
351
-    protected function indent($string, $indent = '    ')
351
+    protected function indent( $string, $indent = '    ' )
352 352
     {
353
-        return $indent.str_replace("\n", "\n".$indent, $string);
353
+        return $indent . str_replace( "\n", "\n" . $indent, $string );
354 354
     }
355 355
 }
Please login to merge, or discard this patch.
Braces   +36 added lines, -50 removed lines patch added patch discarded remove patch
@@ -32,8 +32,7 @@  discard block
 block discarded – undo
32 32
 /**
33 33
  * Class documentation
34 34
  */
35
-class Logger extends AbstractLogger
36
-{
35
+class Logger extends AbstractLogger {
37 36
     /**
38 37
      * KLogger options
39 38
      *  Anything options not considered 'core' to the logging library should be
@@ -115,28 +114,27 @@  discard block
 block discarded – undo
115 114
      * @internal param string $logFilePrefix The prefix for the log file name
116 115
      * @internal param string $logFileExt The extension for the log file
117 116
      */
118
-    public function __construct($logDirectory, $logLevelThreshold = LogLevel::DEBUG, array $options = array())
119
-    {
117
+    public function __construct($logDirectory, $logLevelThreshold = LogLevel::DEBUG, array $options = array()) {
120 118
         $this->logLevelThreshold = $logLevelThreshold;
121 119
         $this->options = array_merge($this->options, $options);
122 120
 
123 121
         $logDirectory = rtrim($logDirectory, DIRECTORY_SEPARATOR);
124
-        if ( ! file_exists($logDirectory)) {
122
+        if ( ! file_exists($logDirectory)) {
125 123
             mkdir($logDirectory, $this->defaultPermissions, true);
126 124
         }
127 125
 
128
-        if(strpos($logDirectory, 'php://') === 0) {
126
+        if(strpos($logDirectory, 'php://') === 0) {
129 127
             $this->setLogToStdOut($logDirectory);
130 128
             $this->setFileHandle('w+');
131
-        } else {
129
+        } else {
132 130
             $this->setLogFilePath($logDirectory);
133
-            if(file_exists($this->logFilePath) && !is_writable($this->logFilePath)) {
131
+            if(file_exists($this->logFilePath) && !is_writable($this->logFilePath)) {
134 132
                 throw new RuntimeException('The file could not be written to. Check that appropriate permissions have been set.');
135 133
             }
136 134
             $this->setFileHandle('a');
137 135
         }
138 136
 
139
-        if ( ! $this->fileHandle) {
137
+        if ( ! $this->fileHandle) {
140 138
             throw new RuntimeException('The file could not be opened. Check permissions.');
141 139
         }
142 140
     }
@@ -144,22 +142,21 @@  discard block
 block discarded – undo
144 142
     /**
145 143
      * @param string $stdOutPath
146 144
      */
147
-    public function setLogToStdOut($stdOutPath) {
145
+    public function setLogToStdOut($stdOutPath) {
148 146
         $this->logFilePath = $stdOutPath;
149 147
     }
150 148
 
151 149
     /**
152 150
      * @param string $logDirectory
153 151
      */
154
-    public function setLogFilePath($logDirectory) {
155
-        if ($this->options['filename']) {
156
-            if (strpos($this->options['filename'], '.log') !== false || strpos($this->options['filename'], '.txt') !== false) {
152
+    public function setLogFilePath($logDirectory) {
153
+        if ($this->options['filename']) {
154
+            if (strpos($this->options['filename'], '.log') !== false || strpos($this->options['filename'], '.txt') !== false) {
157 155
                 $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['filename'];
158
-            }
159
-            else {
156
+            } else {
160 157
                 $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['filename'].'.'.$this->options['extension'];
161 158
             }
162
-        } else {
159
+        } else {
163 160
             $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['prefix'].date('Y-m-d').'.'.$this->options['extension'];
164 161
         }
165 162
     }
@@ -169,7 +166,7 @@  discard block
 block discarded – undo
169 166
      *
170 167
      * @internal param resource $fileHandle
171 168
      */
172
-    public function setFileHandle($writeMode) {
169
+    public function setFileHandle($writeMode) {
173 170
         $this->fileHandle = fopen($this->logFilePath, $writeMode);
174 171
     }
175 172
 
@@ -177,9 +174,8 @@  discard block
 block discarded – undo
177 174
     /**
178 175
      * Class destructor
179 176
      */
180
-    public function __destruct()
181
-    {
182
-        if ($this->fileHandle) {
177
+    public function __destruct() {
178
+        if ($this->fileHandle) {
183 179
             fclose($this->fileHandle);
184 180
         }
185 181
     }
@@ -189,8 +185,7 @@  discard block
 block discarded – undo
189 185
      *
190 186
      * @param string $dateFormat Valid format string for date()
191 187
      */
192
-    public function setDateFormat($dateFormat)
193
-    {
188
+    public function setDateFormat($dateFormat) {
194 189
         $this->options['dateFormat'] = $dateFormat;
195 190
     }
196 191
 
@@ -199,8 +194,7 @@  discard block
 block discarded – undo
199 194
      *
200 195
      * @param string $logLevelThreshold The log level threshold
201 196
      */
202
-    public function setLogLevelThreshold($logLevelThreshold)
203
-    {
197
+    public function setLogLevelThreshold($logLevelThreshold) {
204 198
         $this->logLevelThreshold = $logLevelThreshold;
205 199
     }
206 200
 
@@ -212,9 +206,8 @@  discard block
 block discarded – undo
212 206
      * @param array $context
213 207
      * @return null
214 208
      */
215
-    public function log($level, $message, array $context = array())
216
-    {
217
-        if ($this->logLevels[$this->logLevelThreshold] < $this->logLevels[$level]) {
209
+    public function log($level, $message, array $context = array()) {
210
+        if ($this->logLevels[$this->logLevelThreshold] < $this->logLevels[$level]) {
218 211
             return;
219 212
         }
220 213
         $message = $this->formatMessage($level, $message, $context);
@@ -227,16 +220,15 @@  discard block
 block discarded – undo
227 220
      * @param string $message Line to write to the log
228 221
      * @return void
229 222
      */
230
-    public function write($message)
231
-    {
232
-        if (null !== $this->fileHandle) {
233
-            if (fwrite($this->fileHandle, $message) === false) {
223
+    public function write($message) {
224
+        if (null !== $this->fileHandle) {
225
+            if (fwrite($this->fileHandle, $message) === false) {
234 226
                 throw new RuntimeException('The file could not be written to. Check that appropriate permissions have been set.');
235
-            } else {
227
+            } else {
236 228
                 $this->lastLine = trim($message);
237 229
                 $this->logLineCount++;
238 230
 
239
-                if ($this->options['flushFrequency'] && $this->logLineCount % $this->options['flushFrequency'] === 0) {
231
+                if ($this->options['flushFrequency'] && $this->logLineCount % $this->options['flushFrequency'] === 0) {
240 232
                     fflush($this->fileHandle);
241 233
                 }
242 234
             }
@@ -248,8 +240,7 @@  discard block
 block discarded – undo
248 240
      *
249 241
      * @return string
250 242
      */
251
-    public function getLogFilePath()
252
-    {
243
+    public function getLogFilePath() {
253 244
         return $this->logFilePath;
254 245
     }
255 246
 
@@ -258,8 +249,7 @@  discard block
 block discarded – undo
258 249
      *
259 250
      * @return string
260 251
      */
261
-    public function getLastLogLine()
262
-    {
252
+    public function getLastLogLine() {
263 253
         return $this->lastLine;
264 254
     }
265 255
 
@@ -271,9 +261,8 @@  discard block
 block discarded – undo
271 261
      * @param  array  $context The context
272 262
      * @return string
273 263
      */
274
-    protected function formatMessage($level, $message, $context)
275
-    {
276
-        if ($this->options['logFormat']) {
264
+    protected function formatMessage($level, $message, $context) {
265
+        if ($this->options['logFormat']) {
277 266
             $parts = array(
278 267
                 'date'          => $this->getTimestamp(),
279 268
                 'level'         => strtoupper($level),
@@ -283,15 +272,15 @@  discard block
 block discarded – undo
283 272
                 'context'       => json_encode($context),
284 273
             );
285 274
             $message = $this->options['logFormat'];
286
-            foreach ($parts as $part => $value) {
275
+            foreach ($parts as $part => $value) {
287 276
                 $message = str_replace('{'.$part.'}', $value, $message);
288 277
             }
289 278
 
290
-        } else {
279
+        } else {
291 280
             $message = "[{$this->getTimestamp()}] [{$level}] {$message}";
292 281
         }
293 282
 
294
-        if ($this->options['appendContext'] && ! empty($context)) {
283
+        if ($this->options['appendContext'] && ! empty($context)) {
295 284
             $message .= PHP_EOL.$this->indent($this->contextToString($context));
296 285
         }
297 286
 
@@ -307,8 +296,7 @@  discard block
 block discarded – undo
307 296
      *
308 297
      * @return string
309 298
      */
310
-    private function getTimestamp()
311
-    {
299
+    private function getTimestamp() {
312 300
         $originalTime = microtime(true);
313 301
         $micro = sprintf("%06d", ($originalTime - floor($originalTime)) * 1000000);
314 302
         $date = new DateTime(date('Y-m-d H:i:s.'.$micro, (int)$originalTime));
@@ -322,10 +310,9 @@  discard block
 block discarded – undo
322 310
      * @param  array $context The Context
323 311
      * @return string
324 312
      */
325
-    protected function contextToString($context)
326
-    {
313
+    protected function contextToString($context) {
327 314
         $export = '';
328
-        foreach ($context as $key => $value) {
315
+        foreach ($context as $key => $value) {
329 316
             $export .= "{$key}: ";
330 317
             $export .= preg_replace(array(
331 318
                 '/=>\s+([a-zA-Z])/im',
@@ -348,8 +335,7 @@  discard block
 block discarded – undo
348 335
      * @param  string $indent What to use as the indent.
349 336
      * @return string
350 337
      */
351
-    protected function indent($string, $indent = '    ')
352
-    {
338
+    protected function indent($string, $indent = '    ') {
353 339
         return $indent.str_replace("\n", "\n".$indent, $string);
354 340
     }
355 341
 }
Please login to merge, or discard this patch.