@@ -10,13 +10,13 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | class Console |
| 12 | 12 | { |
| 13 | - const DEBUG = 0; // Detailed debug information |
|
| 14 | - const INFO = 1; // Interesting events |
|
| 15 | - const NOTICE = 2; // Normal but significant events |
|
| 16 | - const WARNING = 4; // Exceptional occurrences that are not errors |
|
| 17 | - const ERROR = 8; // Runtime errors that do not require immediate action |
|
| 18 | - const CRITICAL = 16; // Critical conditions |
|
| 19 | - const ALERT = 32; // Action must be taken immediately |
|
| 13 | + const DEBUG = 0; // Detailed debug information |
|
| 14 | + const INFO = 1; // Interesting events |
|
| 15 | + const NOTICE = 2; // Normal but significant events |
|
| 16 | + const WARNING = 4; // Exceptional occurrences that are not errors |
|
| 17 | + const ERROR = 8; // Runtime errors that do not require immediate action |
|
| 18 | + const CRITICAL = 16; // Critical conditions |
|
| 19 | + const ALERT = 32; // Action must be taken immediately |
|
| 20 | 20 | const EMERGENCY = 64; // System is unusable |
| 21 | 21 | |
| 22 | 22 | protected $file; |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | public function get() |
| 113 | 113 | { |
| 114 | - return empty( $this->log ) |
|
| 114 | + return empty($this->log) |
|
| 115 | 115 | ? __( 'Console is empty', 'site-reviews' ) |
| 116 | 116 | : $this->log; |
| 117 | 117 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | public function getLevel() |
| 123 | 123 | { |
| 124 | - return intval( apply_filters( 'site-reviews/console/level', static::INFO )); |
|
| 124 | + return intval( apply_filters( 'site-reviews/console/level', static::INFO ) ); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -129,8 +129,8 @@ discard block |
||
| 129 | 129 | */ |
| 130 | 130 | public function getLevels() |
| 131 | 131 | { |
| 132 | - $constants = ( new ReflectionClass( __CLASS__ ))->getConstants(); |
|
| 133 | - return array_map( 'strtolower', array_flip( $constants )); |
|
| 132 | + $constants = (new ReflectionClass( __CLASS__ ))->getConstants(); |
|
| 133 | + return array_map( 'strtolower', array_flip( $constants ) ); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | public function humanLevel() |
| 140 | 140 | { |
| 141 | 141 | $level = $this->getLevel(); |
| 142 | - return sprintf( '%s (%d)', strtoupper( glsr_get( $this->getLevels(), $level, 'unknown' )), $level ); |
|
| 142 | + return sprintf( '%s (%d)', strtoupper( glsr_get( $this->getLevels(), $level, 'unknown' ) ), $level ); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
@@ -149,11 +149,11 @@ discard block |
||
| 149 | 149 | public function humanSize( $valueIfEmpty = null ) |
| 150 | 150 | { |
| 151 | 151 | $bytes = $this->size(); |
| 152 | - if( empty( $bytes ) && is_string( $valueIfEmpty )) { |
|
| 152 | + if( empty($bytes) && is_string( $valueIfEmpty ) ) { |
|
| 153 | 153 | return $valueIfEmpty; |
| 154 | 154 | } |
| 155 | - $exponent = floor( log( max( $bytes, 1 ), 1024 )); |
|
| 156 | - return round( $bytes / pow( 1024, $exponent ), 2 ).' '.['bytes','KB','MB','GB'][$exponent]; |
|
| 155 | + $exponent = floor( log( max( $bytes, 1 ), 1024 ) ); |
|
| 156 | + return round( $bytes / pow( 1024, $exponent ), 2 ).' '.['bytes', 'KB', 'MB', 'GB'][$exponent]; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -177,16 +177,16 @@ discard block |
||
| 177 | 177 | */ |
| 178 | 178 | public function log( $level, $message, $context = [], $backtraceLine = '' ) |
| 179 | 179 | { |
| 180 | - if( empty( $backtraceLine )) { |
|
| 180 | + if( empty($backtraceLine) ) { |
|
| 181 | 181 | $backtraceLine = $this->getBacktraceLine(); |
| 182 | 182 | } |
| 183 | - if( $this->canLogEntry( $level, $backtraceLine )) { |
|
| 183 | + if( $this->canLogEntry( $level, $backtraceLine ) ) { |
|
| 184 | 184 | $levelName = glsr_get( $this->getLevels(), $level ); |
| 185 | 185 | $context = glsr( Helper::class )->consolidateArray( $context ); |
| 186 | 186 | $backtraceLine = $this->normalizeBacktraceLine( $backtraceLine ); |
| 187 | 187 | $message = $this->interpolate( $message, $context ); |
| 188 | 188 | $entry = $this->buildLogEntry( $levelName, $message, $backtraceLine ); |
| 189 | - file_put_contents( $this->file, $entry.PHP_EOL, FILE_APPEND|LOCK_EX ); |
|
| 189 | + file_put_contents( $this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX ); |
|
| 190 | 190 | apply_filters( 'console', $message, $levelName, $backtraceLine ); // Show in Blackbar plugin if installed |
| 191 | 191 | $this->reset(); |
| 192 | 192 | } |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | $levels = $this->getLevels(); |
| 203 | 203 | foreach( $once as $entry ) { |
| 204 | 204 | $levelName = glsr_get( $entry, 'level' ); |
| 205 | - if( !in_array( $levelName, $levels ))continue; |
|
| 205 | + if( !in_array( $levelName, $levels ) )continue; |
|
| 206 | 206 | $level = glsr_get( array_flip( $levels ), $levelName ); |
| 207 | 207 | $message = glsr_get( $entry, 'message' ); |
| 208 | 208 | $backtraceLine = glsr_get( $entry, 'backtrace' ); |
@@ -231,11 +231,11 @@ discard block |
||
| 231 | 231 | public function once( $levelName, $handle, $data ) |
| 232 | 232 | { |
| 233 | 233 | $once = glsr( Helper::class )->consolidateArray( glsr()->{$this->logOnceKey} ); |
| 234 | - $filtered = array_filter( $once, function( $entry ) use( $levelName, $handle ) { |
|
| 234 | + $filtered = array_filter( $once, function( $entry ) use($levelName, $handle) { |
|
| 235 | 235 | return glsr_get( $entry, 'level' ) == $levelName |
| 236 | 236 | && glsr_get( $entry, 'handle' ) == $handle; |
| 237 | 237 | }); |
| 238 | - if( !empty( $filtered ))return; |
|
| 238 | + if( !empty($filtered) )return; |
|
| 239 | 239 | $once[] = [ |
| 240 | 240 | 'backtrace' => $this->getBacktraceLineFromData( $data ), |
| 241 | 241 | 'handle' => $handle, |
@@ -315,9 +315,9 @@ discard block |
||
| 315 | 315 | protected function getBacktraceLine() |
| 316 | 316 | { |
| 317 | 317 | $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 6 ); |
| 318 | - $search = array_search( 'log', glsr_array_column( $backtrace, 'function' )); |
|
| 318 | + $search = array_search( 'log', glsr_array_column( $backtrace, 'function' ) ); |
|
| 319 | 319 | if( $search !== false ) { |
| 320 | - $index = glsr_get( $backtrace, ( $search + 2 ).'.function' ) == '{closure}' |
|
| 320 | + $index = glsr_get( $backtrace, ($search + 2).'.function' ) == '{closure}' |
|
| 321 | 321 | ? $search + 4 |
| 322 | 322 | : $search + 1; |
| 323 | 323 | return $this->buildBacktraceLine( $backtrace, $index ); |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | */ |
| 357 | 357 | protected function interpolate( $message, $context = [] ) |
| 358 | 358 | { |
| 359 | - if( $this->isObjectOrArray( $message ) || !is_array( $context )) { |
|
| 359 | + if( $this->isObjectOrArray( $message ) || !is_array( $context ) ) { |
|
| 360 | 360 | return print_r( $message, true ); |
| 361 | 361 | } |
| 362 | 362 | $replace = []; |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | glsr()->path( 'plugin/' ), |
| 386 | 386 | glsr()->path( 'plugin/', false ), |
| 387 | 387 | trailingslashit( glsr()->path() ), |
| 388 | - trailingslashit( glsr()->path( '', false )), |
|
| 388 | + trailingslashit( glsr()->path( '', false ) ), |
|
| 389 | 389 | WP_CONTENT_DIR, |
| 390 | 390 | ABSPATH |
| 391 | 391 | ]; |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | if( $value instanceof DateTime ) { |
| 414 | 414 | $value = $value->format( 'Y-m-d H:i:s' ); |
| 415 | 415 | } |
| 416 | - else if( $this->isObjectOrArray( $value )) { |
|
| 416 | + else if( $this->isObjectOrArray( $value ) ) { |
|
| 417 | 417 | $value = json_encode( $value ); |
| 418 | 418 | } |
| 419 | 419 | return (string)$value; |