@@ -11,138 +11,138 @@ |
||
| 11 | 11 | public $ignore; |
| 12 | 12 | |
| 13 | 13 | protected $level = 0; |
| 14 | - protected $result = []; |
|
| 15 | - protected $stack = []; |
|
| 14 | + protected $result = [ ]; |
|
| 15 | + protected $stack = [ ]; |
|
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * @param mixed $value |
| 19 | 19 | */ |
| 20 | - public function dump($value, int $depth = 3, array $ignore = []): string |
|
| 20 | + public function dump( $value, int $depth = 3, array $ignore = [ ] ): string |
|
| 21 | 21 | { |
| 22 | 22 | $this->depth = $depth; |
| 23 | 23 | $this->ignore = $ignore; |
| 24 | 24 | $this->reset(); |
| 25 | - $this->inspect($value); |
|
| 26 | - $result = implode('', $this->result); |
|
| 27 | - $result = rtrim($result, "\n"); |
|
| 25 | + $this->inspect( $value ); |
|
| 26 | + $result = implode( '', $this->result ); |
|
| 27 | + $result = rtrim( $result, "\n" ); |
|
| 28 | 28 | $this->reset(); |
| 29 | 29 | return $result; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - protected function formatKey(string $key): string |
|
| 32 | + protected function formatKey( string $key ): string |
|
| 33 | 33 | { |
| 34 | - $result = []; |
|
| 35 | - $result[] = str_repeat(' ', $this->level * 4).'['; |
|
| 36 | - if (is_string($key) && "\0" === $key[0]) { |
|
| 37 | - $keyParts = explode("\0", $key); |
|
| 38 | - $result[] = $keyParts[2].(('*' === $keyParts[1]) ? ':protected' : ':private'); |
|
| 34 | + $result = [ ]; |
|
| 35 | + $result[ ] = str_repeat( ' ', $this->level * 4 ) . '['; |
|
| 36 | + if( is_string( $key ) && "\0" === $key[ 0 ] ) { |
|
| 37 | + $keyParts = explode( "\0", $key ); |
|
| 38 | + $result[ ] = $keyParts[ 2 ] . ( ( '*' === $keyParts[ 1 ] ) ? ':protected' : ':private' ); |
|
| 39 | 39 | } else { |
| 40 | - $result[] = $key; |
|
| 40 | + $result[ ] = $key; |
|
| 41 | 41 | } |
| 42 | - $result[] = '] => '; |
|
| 43 | - return implode('', $result); |
|
| 42 | + $result[ ] = '] => '; |
|
| 43 | + return implode( '', $result ); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * @param mixed $subject |
| 48 | 48 | */ |
| 49 | - protected function inspect($subject): void |
|
| 49 | + protected function inspect( $subject ): void |
|
| 50 | 50 | { |
| 51 | 51 | ++$this->level; |
| 52 | - if ($subject instanceof \Closure) { |
|
| 53 | - $this->inspectClosure($subject); |
|
| 54 | - } elseif (is_object($subject)) { |
|
| 55 | - $this->inspectObject($subject); |
|
| 56 | - } elseif (is_array($subject)) { |
|
| 57 | - $this->inspectArray($subject); |
|
| 52 | + if( $subject instanceof \Closure ) { |
|
| 53 | + $this->inspectClosure( $subject ); |
|
| 54 | + } elseif( is_object( $subject ) ) { |
|
| 55 | + $this->inspectObject( $subject ); |
|
| 56 | + } elseif( is_array( $subject ) ) { |
|
| 57 | + $this->inspectArray( $subject ); |
|
| 58 | 58 | } else { |
| 59 | - $this->inspectPrimitive($subject); |
|
| 59 | + $this->inspectPrimitive( $subject ); |
|
| 60 | 60 | } |
| 61 | 61 | --$this->level; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - protected function inspectArray(array $subject): void |
|
| 64 | + protected function inspectArray( array $subject ): void |
|
| 65 | 65 | { |
| 66 | - if ($this->level > $this->depth) { |
|
| 67 | - $this->result[] = "Nested Array\n"; |
|
| 66 | + if( $this->level > $this->depth ) { |
|
| 67 | + $this->result[ ] = "Nested Array\n"; |
|
| 68 | 68 | return; |
| 69 | 69 | } |
| 70 | - if (empty($subject)) { |
|
| 71 | - $this->result[] = "Array ()\n"; |
|
| 70 | + if( empty( $subject ) ) { |
|
| 71 | + $this->result[ ] = "Array ()\n"; |
|
| 72 | 72 | return; |
| 73 | 73 | } |
| 74 | - $this->result[] = "Array (\n"; |
|
| 75 | - foreach ($subject as $key => $val) { |
|
| 76 | - if (false === $this->isIgnoredKey($key)) { |
|
| 77 | - $this->result[] = str_repeat(' ', $this->level * 4).'['.$key.'] => '; |
|
| 78 | - $this->inspect($val); |
|
| 74 | + $this->result[ ] = "Array (\n"; |
|
| 75 | + foreach( $subject as $key => $val ) { |
|
| 76 | + if( false === $this->isIgnoredKey( $key ) ) { |
|
| 77 | + $this->result[ ] = str_repeat( ' ', $this->level * 4 ) . '[' . $key . '] => '; |
|
| 78 | + $this->inspect( $val ); |
|
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | - $this->result[] = str_repeat(' ', ($this->level - 1) * 4).")\n"; |
|
| 81 | + $this->result[ ] = str_repeat( ' ', ( $this->level - 1 ) * 4 ) . ")\n"; |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - protected function inspectClosure(\Closure $subject): void |
|
| 84 | + protected function inspectClosure( \Closure $subject ): void |
|
| 85 | 85 | { |
| 86 | - $reflection = new \ReflectionFunction($subject); |
|
| 87 | - $params = array_map(function ($param) { |
|
| 88 | - return ($param->isPassedByReference() ? '&$' : '$').$param->name; |
|
| 89 | - }, $reflection->getParameters()); |
|
| 90 | - $this->result[] = 'Closure ('.implode(', ', $params).') { ... }'."\n"; |
|
| 86 | + $reflection = new \ReflectionFunction( $subject ); |
|
| 87 | + $params = array_map( function( $param ) { |
|
| 88 | + return ( $param->isPassedByReference() ? '&$' : '$' ) . $param->name; |
|
| 89 | + }, $reflection->getParameters() ); |
|
| 90 | + $this->result[ ] = 'Closure (' . implode( ', ', $params ) . ') { ... }' . "\n"; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
| 94 | 94 | * @param object $subject |
| 95 | 95 | */ |
| 96 | - protected function inspectObject($subject): void |
|
| 96 | + protected function inspectObject( $subject ): void |
|
| 97 | 97 | { |
| 98 | - $classname = get_class($subject); |
|
| 99 | - if ($this->level > $this->depth) { |
|
| 100 | - $this->result[] = 'Nested '.$classname." Object\n"; |
|
| 98 | + $classname = get_class( $subject ); |
|
| 99 | + if( $this->level > $this->depth ) { |
|
| 100 | + $this->result[ ] = 'Nested ' . $classname . " Object\n"; |
|
| 101 | 101 | return; |
| 102 | 102 | } |
| 103 | - if ($subject instanceof \ArrayObject) { |
|
| 104 | - $this->result[] = $classname." ArrayObject (\n"; |
|
| 103 | + if( $subject instanceof \ArrayObject ) { |
|
| 104 | + $this->result[ ] = $classname . " ArrayObject (\n"; |
|
| 105 | 105 | } else { |
| 106 | - $this->result[] = $classname." Object (\n"; |
|
| 106 | + $this->result[ ] = $classname . " Object (\n"; |
|
| 107 | 107 | $subject = (array) $subject; |
| 108 | 108 | } |
| 109 | - foreach ($subject as $key => $val) { |
|
| 110 | - if (false === $this->isIgnoredKey($key)) { |
|
| 111 | - $this->result[] = $this->formatKey($key); |
|
| 112 | - $this->inspect($val); |
|
| 109 | + foreach( $subject as $key => $val ) { |
|
| 110 | + if( false === $this->isIgnoredKey( $key ) ) { |
|
| 111 | + $this->result[ ] = $this->formatKey( $key ); |
|
| 112 | + $this->inspect( $val ); |
|
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | - $this->result[] = str_repeat(' ', ($this->level - 1) * 4).")\n"; |
|
| 115 | + $this->result[ ] = str_repeat( ' ', ( $this->level - 1 ) * 4 ) . ")\n"; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
| 119 | 119 | * @param mixed $subject |
| 120 | 120 | */ |
| 121 | - protected function inspectPrimitive($subject): void |
|
| 121 | + protected function inspectPrimitive( $subject ): void |
|
| 122 | 122 | { |
| 123 | - if (true === $subject) { |
|
| 123 | + if( true === $subject ) { |
|
| 124 | 124 | $subject = '(bool) true'; |
| 125 | - } elseif (false === $subject) { |
|
| 125 | + } elseif( false === $subject ) { |
|
| 126 | 126 | $subject = '(bool) false'; |
| 127 | - } elseif (null === $subject) { |
|
| 127 | + } elseif( null === $subject ) { |
|
| 128 | 128 | $subject = '(null)'; |
| 129 | 129 | } |
| 130 | - $this->result[] = $subject."\n"; |
|
| 130 | + $this->result[ ] = $subject . "\n"; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
| 134 | 134 | * @param string $key |
| 135 | 135 | */ |
| 136 | - protected function isIgnoredKey($key): bool |
|
| 136 | + protected function isIgnoredKey( $key ): bool |
|
| 137 | 137 | { |
| 138 | - return in_array($key, $this->ignore); |
|
| 138 | + return in_array( $key, $this->ignore ); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | protected function reset(): void |
| 142 | 142 | { |
| 143 | 143 | $this->level = 0; |
| 144 | - $this->result = []; |
|
| 145 | - $this->stack = []; |
|
| 144 | + $this->result = [ ]; |
|
| 145 | + $this->stack = [ ]; |
|
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | protected $app; |
| 11 | 11 | |
| 12 | - public function __construct(Application $app) |
|
| 12 | + public function __construct( Application $app ) |
|
| 13 | 13 | { |
| 14 | 14 | $this->app = $app; |
| 15 | 15 | } |
@@ -20,18 +20,18 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | public function enqueueAssets(): void |
| 22 | 22 | { |
| 23 | - wp_enqueue_script(Application::ID, $this->app->url('assets/main.js')); |
|
| 24 | - wp_enqueue_style(Application::ID, $this->app->url('assets/main.css'), ['dashicons']); |
|
| 25 | - wp_enqueue_style(Application::ID.'-syntax', $this->app->url('assets/syntax.css')); |
|
| 23 | + wp_enqueue_script( Application::ID, $this->app->url( 'assets/main.js' ) ); |
|
| 24 | + wp_enqueue_style( Application::ID, $this->app->url( 'assets/main.css' ), [ 'dashicons' ] ); |
|
| 25 | + wp_enqueue_style( Application::ID . '-syntax', $this->app->url( 'assets/syntax.css' ) ); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * @param string $classes |
| 30 | 30 | * @action admin_body_class |
| 31 | 31 | */ |
| 32 | - public function filterBodyClasses($classes): string |
|
| 32 | + public function filterBodyClasses( $classes ): string |
|
| 33 | 33 | { |
| 34 | - return trim((string) $classes.' '.Application::ID); |
|
| 34 | + return trim( (string) $classes . ' ' . Application::ID ); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
@@ -39,19 +39,19 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function initConsole(): void |
| 41 | 41 | { |
| 42 | - if (Application::CONSOLE_HOOK !== func_get_arg(0)) { |
|
| 42 | + if( Application::CONSOLE_HOOK !== func_get_arg( 0 ) ) { |
|
| 43 | 43 | return; |
| 44 | 44 | } |
| 45 | - $args = array_pad(func_get_args(), 4, ''); |
|
| 46 | - $args = array_combine(['hook', 'message', 'errno', 'location'], $args); |
|
| 47 | - $args = array_map('sanitize_textarea_field', $args); |
|
| 48 | - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 4); |
|
| 49 | - $entry = array_pop($backtrace); // get the fourth backtrace entry |
|
| 50 | - if (empty(trim($args['location'])) && array_key_exists('file', $entry)) { |
|
| 51 | - $path = explode(ABSPATH, $entry['file']); |
|
| 52 | - $args['location'] = sprintf('%s:%s', array_pop($path), $entry['line']); |
|
| 45 | + $args = array_pad( func_get_args(), 4, '' ); |
|
| 46 | + $args = array_combine( [ 'hook', 'message', 'errno', 'location' ], $args ); |
|
| 47 | + $args = array_map( 'sanitize_textarea_field', $args ); |
|
| 48 | + $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 4 ); |
|
| 49 | + $entry = array_pop( $backtrace ); // get the fourth backtrace entry |
|
| 50 | + if( empty( trim( $args[ 'location' ] ) ) && array_key_exists( 'file', $entry ) ) { |
|
| 51 | + $path = explode( ABSPATH, $entry[ 'file' ] ); |
|
| 52 | + $args[ 'location' ] = sprintf( '%s:%s', array_pop( $path ), $entry[ 'line' ] ); |
|
| 53 | 53 | } |
| 54 | - $this->app->console->store($args['message'], $args['errno'], $args['location']); |
|
| 54 | + $this->app->console->store( $args[ 'message' ], $args[ 'errno' ], $args[ 'location' ] ); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -67,25 +67,25 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | public function initProfiler(): void |
| 69 | 69 | { |
| 70 | - $hook = func_get_arg(0); |
|
| 71 | - if ('blackbar/profiler/start' === $hook) { // time when the profiler started |
|
| 72 | - $this->app->profiler->setStart((int) hrtime(true)); |
|
| 70 | + $hook = func_get_arg( 0 ); |
|
| 71 | + if( 'blackbar/profiler/start' === $hook ) { // time when the profiler started |
|
| 72 | + $this->app->profiler->setStart( (int) hrtime( true ) ); |
|
| 73 | 73 | return; |
| 74 | 74 | } |
| 75 | - if ('blackbar/profiler/noise' === $hook) { // measure the profiler noise |
|
| 76 | - $this->app->profiler->setNoise((int) hrtime(true)); |
|
| 75 | + if( 'blackbar/profiler/noise' === $hook ) { // measure the profiler noise |
|
| 76 | + $this->app->profiler->setNoise( (int) hrtime( true ) ); |
|
| 77 | 77 | return; |
| 78 | 78 | } |
| 79 | - if ('blackbar/profiler/stop' === $hook) { // time when the profiler stopped |
|
| 80 | - $this->app->profiler->setStop((int) hrtime(true)); |
|
| 79 | + if( 'blackbar/profiler/stop' === $hook ) { // time when the profiler stopped |
|
| 80 | + $this->app->profiler->setStop( (int) hrtime( true ) ); |
|
| 81 | 81 | return; |
| 82 | 82 | } |
| 83 | - if ('timer:start' === $hook) { |
|
| 84 | - $name = func_num_args() > 1 ? func_get_arg(1) : 'Timer'; |
|
| 85 | - $this->app->profiler->start($name); |
|
| 83 | + if( 'timer:start' === $hook ) { |
|
| 84 | + $name = func_num_args() > 1 ? func_get_arg( 1 ) : 'Timer'; |
|
| 85 | + $this->app->profiler->start( $name ); |
|
| 86 | 86 | return; |
| 87 | 87 | } |
| 88 | - if ('timer:stop' === $hook) { |
|
| 88 | + if( 'timer:stop' === $hook ) { |
|
| 89 | 89 | $this->app->profiler->stop(); |
| 90 | 90 | } |
| 91 | 91 | } |
@@ -95,8 +95,8 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | public function registerLanguages(): void |
| 97 | 97 | { |
| 98 | - load_plugin_textdomain(Application::ID, false, |
|
| 99 | - plugin_basename($this->app->path()).'/languages/' |
|
| 98 | + load_plugin_textdomain( Application::ID, false, |
|
| 99 | + plugin_basename( $this->app->path() ) . '/languages/' |
|
| 100 | 100 | ); |
| 101 | 101 | } |
| 102 | 102 | |
@@ -106,8 +106,8 @@ discard block |
||
| 106 | 106 | */ |
| 107 | 107 | public function renderBar(): void |
| 108 | 108 | { |
| 109 | - do_action('blackbar/profiler/stop'); // stop profiler |
|
| 110 | - $this->app->render('debug-bar', [ |
|
| 109 | + do_action( 'blackbar/profiler/stop' ); // stop profiler |
|
| 110 | + $this->app->render( 'debug-bar', [ |
|
| 111 | 111 | 'modules' => [ // order is intentional |
| 112 | 112 | $this->app->console, |
| 113 | 113 | $this->app->profiler, |
@@ -116,6 +116,6 @@ discard block |
||
| 116 | 116 | $this->app->templates, |
| 117 | 117 | $this->app->globals, |
| 118 | 118 | ], |
| 119 | - ]); |
|
| 119 | + ] ); |
|
| 120 | 120 | } |
| 121 | 121 | } |
@@ -30,85 +30,85 @@ |
||
| 30 | 30 | |
| 31 | 31 | public function classes(): string |
| 32 | 32 | { |
| 33 | - $errno = array_unique(wp_list_pluck($this->entries, 'errno')); |
|
| 34 | - if (in_array(E_ERROR, $errno)) { |
|
| 35 | - return sprintf('%s glbb-error', $this->id()); |
|
| 33 | + $errno = array_unique( wp_list_pluck( $this->entries, 'errno' ) ); |
|
| 34 | + if( in_array( E_ERROR, $errno ) ) { |
|
| 35 | + return sprintf( '%s glbb-error', $this->id() ); |
|
| 36 | 36 | } |
| 37 | - if (in_array(E_WARNING, $errno)) { |
|
| 38 | - return sprintf('%s glbb-warning', $this->id()); |
|
| 37 | + if( in_array( E_WARNING, $errno ) ) { |
|
| 38 | + return sprintf( '%s glbb-warning', $this->id() ); |
|
| 39 | 39 | } |
| 40 | 40 | return $this->id(); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | public function entries(): array |
| 44 | 44 | { |
| 45 | - $entries = []; |
|
| 46 | - foreach ($this->entries as $entry) { |
|
| 47 | - $entry['name'] = ucfirst($entry['errname']); |
|
| 48 | - if ($entry['count'] > 1) { |
|
| 49 | - $entry['name'] = sprintf('%s (%s)', $entry['name'], $entry['count']); |
|
| 45 | + $entries = [ ]; |
|
| 46 | + foreach( $this->entries as $entry ) { |
|
| 47 | + $entry[ 'name' ] = ucfirst( $entry[ 'errname' ] ); |
|
| 48 | + if( $entry[ 'count' ] > 1 ) { |
|
| 49 | + $entry[ 'name' ] = sprintf( '%s (%s)', $entry[ 'name' ], $entry[ 'count' ] ); |
|
| 50 | 50 | } |
| 51 | - $entries[] = $entry; |
|
| 51 | + $entries[ ] = $entry; |
|
| 52 | 52 | } |
| 53 | 53 | return $entries; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | public function label(): string |
| 57 | 57 | { |
| 58 | - $counts = array_count_values(wp_list_pluck($this->entries, 'errno')); |
|
| 59 | - $entryCount = count($this->entries); |
|
| 60 | - $label = __('Console', 'blackbar'); |
|
| 61 | - if (!empty($counts[E_ERROR])) { |
|
| 62 | - return sprintf('%s <span class="glbb-link-info">%d, %d!</span>', $label, $entryCount, $counts[E_ERROR]); |
|
| 58 | + $counts = array_count_values( wp_list_pluck( $this->entries, 'errno' ) ); |
|
| 59 | + $entryCount = count( $this->entries ); |
|
| 60 | + $label = __( 'Console', 'blackbar' ); |
|
| 61 | + if( !empty( $counts[ E_ERROR ] ) ) { |
|
| 62 | + return sprintf( '%s <span class="glbb-link-info">%d, %d!</span>', $label, $entryCount, $counts[ E_ERROR ] ); |
|
| 63 | 63 | } |
| 64 | - if ($entryCount > 0) { |
|
| 65 | - return sprintf('%s <span class="glbb-link-info">%d</span>', $label, $entryCount); |
|
| 64 | + if( $entryCount > 0 ) { |
|
| 65 | + return sprintf( '%s <span class="glbb-link-info">%d</span>', $label, $entryCount ); |
|
| 66 | 66 | } |
| 67 | 67 | return $label; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - public function store(string $message, string $errno = '', string $location = ''): void |
|
| 70 | + public function store( string $message, string $errno = '', string $location = '' ): void |
|
| 71 | 71 | { |
| 72 | - if (is_numeric($errno)) { // entry likely stored by set_error_handler() |
|
| 72 | + if( is_numeric( $errno ) ) { // entry likely stored by set_error_handler() |
|
| 73 | 73 | $errname = 'Unknown'; |
| 74 | - if (array_key_exists((int) $errno, static::ERROR_CODES)) { |
|
| 75 | - $errname = static::ERROR_CODES[$errno]; |
|
| 74 | + if( array_key_exists( (int) $errno, static::ERROR_CODES ) ) { |
|
| 75 | + $errname = static::ERROR_CODES[ $errno ]; |
|
| 76 | 76 | } |
| 77 | 77 | } else { // entry likely stored by filter hook |
| 78 | 78 | $errname = 'Debug'; |
| 79 | - if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { |
|
| 79 | + if( array_key_exists( $errno, static::MAPPED_ERROR_CODES ) ) { |
|
| 80 | 80 | $errname = $errno; |
| 81 | - $errno = static::MAPPED_ERROR_CODES[$errno]; |
|
| 81 | + $errno = static::MAPPED_ERROR_CODES[ $errno ]; |
|
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | - $errname = strtolower($errname); |
|
| 85 | - $hash = md5($errno.$errname.$message.$location); |
|
| 86 | - if (array_key_exists($hash, $this->entries)) { |
|
| 87 | - ++$this->entries[$hash]['count']; |
|
| 84 | + $errname = strtolower( $errname ); |
|
| 85 | + $hash = md5( $errno . $errname . $message . $location ); |
|
| 86 | + if( array_key_exists( $hash, $this->entries ) ) { |
|
| 87 | + ++$this->entries[ $hash ][ 'count' ]; |
|
| 88 | 88 | } else { |
| 89 | - $this->entries[$hash] = [ |
|
| 89 | + $this->entries[ $hash ] = [ |
|
| 90 | 90 | 'count' => 0, |
| 91 | 91 | 'errname' => $errname, |
| 92 | 92 | 'errno' => (int) $errno, |
| 93 | - 'message' => $this->normalizeMessage($message, $location), |
|
| 93 | + 'message' => $this->normalizeMessage( $message, $location ), |
|
| 94 | 94 | ]; |
| 95 | 95 | }; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - protected function normalizeMessage($message, string $location): string |
|
| 98 | + protected function normalizeMessage( $message, string $location ): string |
|
| 99 | 99 | { |
| 100 | - if ($message instanceof \DateTime) { |
|
| 101 | - $message = $message->format('Y-m-d H:i:s'); |
|
| 102 | - } elseif (is_object($message) || is_array($message)) { |
|
| 103 | - $message = (new Dump())->dump($message); |
|
| 100 | + if( $message instanceof \DateTime ) { |
|
| 101 | + $message = $message->format( 'Y-m-d H:i:s' ); |
|
| 102 | + } elseif( is_object( $message ) || is_array( $message ) ) { |
|
| 103 | + $message = ( new Dump() )->dump( $message ); |
|
| 104 | 104 | } else { |
| 105 | - $message = esc_html(trim((string) $message)); |
|
| 105 | + $message = esc_html( trim( (string) $message ) ); |
|
| 106 | 106 | } |
| 107 | - $location = trim($location); |
|
| 108 | - if (!empty($location)) { |
|
| 109 | - $location = str_replace([WP_CONTENT_DIR, ABSPATH], '', $location); |
|
| 110 | - $location = sprintf('[%s]', $location); |
|
| 107 | + $location = trim( $location ); |
|
| 108 | + if( !empty( $location ) ) { |
|
| 109 | + $location = str_replace( [ WP_CONTENT_DIR, ABSPATH ], '', $location ); |
|
| 110 | + $location = sprintf( '[%s]', $location ); |
|
| 111 | 111 | } |
| 112 | - return trim(sprintf('%s %s', $location, $message)); |
|
| 112 | + return trim( sprintf( '%s %s', $location, $message ) ); |
|
| 113 | 113 | } |
| 114 | 114 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | { |
| 9 | 9 | public function entries(): array |
| 10 | 10 | { |
| 11 | - if (!empty($this->entries)) { |
|
| 11 | + if( !empty( $this->entries ) ) { |
|
| 12 | 12 | return $this->entries; |
| 13 | 13 | } |
| 14 | 14 | $globals = [ |
@@ -18,21 +18,21 @@ discard block |
||
| 18 | 18 | 'INPUT_POST' => $_POST, |
| 19 | 19 | 'INPUT_SERVER' => $_SERVER, |
| 20 | 20 | ]; |
| 21 | - if (is_admin() && $screen = get_current_screen()) { |
|
| 22 | - $reflection = new \ReflectionClass($screen); |
|
| 23 | - $properties = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC); |
|
| 24 | - $values = []; |
|
| 25 | - foreach ($properties as $property) { |
|
| 26 | - $values[$property->getName()] = $property->getValue($screen); |
|
| 21 | + if( is_admin() && $screen = get_current_screen() ) { |
|
| 22 | + $reflection = new \ReflectionClass( $screen ); |
|
| 23 | + $properties = $reflection->getProperties( \ReflectionProperty::IS_PUBLIC ); |
|
| 24 | + $values = [ ]; |
|
| 25 | + foreach( $properties as $property ) { |
|
| 26 | + $values[ $property->getName() ] = $property->getValue( $screen ); |
|
| 27 | 27 | } |
| 28 | - $globals['WP_Screen'] = $values; |
|
| 28 | + $globals[ 'WP_Screen' ] = $values; |
|
| 29 | 29 | } |
| 30 | - $globals = apply_filters('blackbar/globals', $globals); |
|
| 31 | - $globals = array_filter($globals); |
|
| 32 | - foreach ($globals as $key => $values) { |
|
| 33 | - $this->entries[] = [ |
|
| 30 | + $globals = apply_filters( 'blackbar/globals', $globals ); |
|
| 31 | + $globals = array_filter( $globals ); |
|
| 32 | + foreach( $globals as $key => $values ) { |
|
| 33 | + $this->entries[ ] = [ |
|
| 34 | 34 | 'name' => $key, |
| 35 | - 'value' => var_export($values, true), |
|
| 35 | + 'value' => var_export( $values, true ), |
|
| 36 | 36 | ]; |
| 37 | 37 | } |
| 38 | 38 | return $this->entries; |
@@ -40,11 +40,11 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | public function hasEntries(): bool |
| 42 | 42 | { |
| 43 | - return !empty($this->entries()); |
|
| 43 | + return !empty( $this->entries() ); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | public function label(): string |
| 47 | 47 | { |
| 48 | - return __('Globals', 'blackbar'); |
|
| 48 | + return __( 'Globals', 'blackbar' ); |
|
| 49 | 49 | } |
| 50 | 50 | } |
@@ -15,10 +15,10 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | protected $entries; |
| 17 | 17 | |
| 18 | - public function __construct(Application $app) |
|
| 18 | + public function __construct( Application $app ) |
|
| 19 | 19 | { |
| 20 | 20 | $this->app = $app; |
| 21 | - $this->entries = []; |
|
| 21 | + $this->entries = [ ]; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public function classes(): string |
@@ -30,12 +30,12 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | public function hasEntries(): bool |
| 32 | 32 | { |
| 33 | - return !empty($this->entries); |
|
| 33 | + return !empty( $this->entries ); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | public function id(): string |
| 37 | 37 | { |
| 38 | - return sprintf('glbb-%s', $this->slug()); |
|
| 38 | + return sprintf( 'glbb-%s', $this->slug() ); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | public function isVisible(): bool |
@@ -47,11 +47,11 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | public function render(): void |
| 49 | 49 | { |
| 50 | - $this->app->render('panels/'.$this->slug(), ['module' => $this]); |
|
| 50 | + $this->app->render( 'panels/' . $this->slug(), [ 'module' => $this ] ); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | public function slug(): string |
| 54 | 54 | { |
| 55 | - return strtolower((new \ReflectionClass($this))->getShortName()); |
|
| 55 | + return strtolower( ( new \ReflectionClass( $this ) )->getShortName() ); |
|
| 56 | 56 | } |
| 57 | 57 | } |
@@ -9,70 +9,70 @@ |
||
| 9 | 9 | public function entries(): array |
| 10 | 10 | { |
| 11 | 11 | global $wpdb; |
| 12 | - $entries = []; |
|
| 12 | + $entries = [ ]; |
|
| 13 | 13 | $index = 0; |
| 14 | 14 | $search = [ |
| 15 | 15 | 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT', |
| 16 | 16 | 'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE', |
| 17 | 17 | ]; |
| 18 | - $replace = array_map(function ($value) { |
|
| 19 | - return PHP_EOL.$value; |
|
| 20 | - }, $search); |
|
| 21 | - foreach ($wpdb->queries as $query) { |
|
| 22 | - $miliseconds = number_format(round($query[1] * 1000, 4), 4); |
|
| 23 | - $sql = preg_replace('/\s\s+/', ' ', trim($query[0])); |
|
| 24 | - $sql = str_replace(PHP_EOL, ' ', $sql); |
|
| 25 | - $sql = str_replace(['( ',' )',' ,'], ['(',')',','], $sql); |
|
| 26 | - $sql = str_replace($search, $replace, $sql); |
|
| 27 | - $parts = explode(PHP_EOL, $sql); |
|
| 28 | - $sql = array_reduce($parts, function ($carry, $part) { |
|
| 29 | - if (str_starts_with($part, 'SELECT') && strlen($part) > 100) { |
|
| 30 | - $part = preg_replace('/\s*(,)\s*/', ','.PHP_EOL.' ', $part); |
|
| 18 | + $replace = array_map( function( $value ) { |
|
| 19 | + return PHP_EOL . $value; |
|
| 20 | + }, $search ); |
|
| 21 | + foreach( $wpdb->queries as $query ) { |
|
| 22 | + $miliseconds = number_format( round( $query[ 1 ] * 1000, 4 ), 4 ); |
|
| 23 | + $sql = preg_replace( '/\s\s+/', ' ', trim( $query[ 0 ] ) ); |
|
| 24 | + $sql = str_replace( PHP_EOL, ' ', $sql ); |
|
| 25 | + $sql = str_replace( [ '( ', ' )', ' ,' ], [ '(', ')', ',' ], $sql ); |
|
| 26 | + $sql = str_replace( $search, $replace, $sql ); |
|
| 27 | + $parts = explode( PHP_EOL, $sql ); |
|
| 28 | + $sql = array_reduce( $parts, function( $carry, $part ) { |
|
| 29 | + if( str_starts_with( $part, 'SELECT' ) && strlen( $part ) > 100 ) { |
|
| 30 | + $part = preg_replace( '/\s*(,)\s*/', ',' . PHP_EOL . ' ', $part ); |
|
| 31 | 31 | } |
| 32 | - if (str_starts_with($part, 'WHERE')) { |
|
| 33 | - $part = str_replace('AND', PHP_EOL.' AND', $part); |
|
| 32 | + if( str_starts_with( $part, 'WHERE' ) ) { |
|
| 33 | + $part = str_replace( 'AND', PHP_EOL . ' AND', $part ); |
|
| 34 | 34 | } |
| 35 | - return $carry.$part.PHP_EOL; |
|
| 35 | + return $carry . $part . PHP_EOL; |
|
| 36 | 36 | }); |
| 37 | - $trace = explode(', ', $query[2]); |
|
| 38 | - $entries[] = [ |
|
| 37 | + $trace = explode( ', ', $query[ 2 ] ); |
|
| 38 | + $entries[ ] = [ |
|
| 39 | 39 | 'index' => $index++, |
| 40 | 40 | 'sql' => $sql, |
| 41 | 41 | 'time' => $miliseconds, |
| 42 | - 'trace' => array_reverse($trace, true), |
|
| 42 | + 'trace' => array_reverse( $trace, true ), |
|
| 43 | 43 | ]; |
| 44 | 44 | } |
| 45 | - uasort($entries, [$this, 'sortByTime']); |
|
| 45 | + uasort( $entries, [ $this, 'sortByTime' ] ); |
|
| 46 | 46 | return $entries; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | public function hasEntries(): bool |
| 50 | 50 | { |
| 51 | 51 | global $wpdb; |
| 52 | - return !empty($wpdb->queries); |
|
| 52 | + return !empty( $wpdb->queries ); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | public function label(): string |
| 56 | 56 | { |
| 57 | - $label = __('SQL', 'blackbar'); |
|
| 58 | - if (!defined('SAVEQUERIES') || !SAVEQUERIES) { |
|
| 57 | + $label = __( 'SQL', 'blackbar' ); |
|
| 58 | + if( !defined( 'SAVEQUERIES' ) || !SAVEQUERIES ) { |
|
| 59 | 59 | return $label; |
| 60 | 60 | } |
| 61 | 61 | global $wpdb; |
| 62 | 62 | $queryTime = 0; |
| 63 | - foreach ($wpdb->queries as $query) { |
|
| 64 | - $queryTime += $query[1]; |
|
| 63 | + foreach( $wpdb->queries as $query ) { |
|
| 64 | + $queryTime += $query[ 1 ]; |
|
| 65 | 65 | } |
| 66 | - $queryTime = number_format($queryTime * 1000, 2); |
|
| 67 | - $count = sprintf('<span class="glbb-queries-count">%s</span>', count($wpdb->queries)); |
|
| 68 | - $time = sprintf('<span class="glbb-queries-time">%s</span>', $queryTime); |
|
| 69 | - return sprintf('%s <span class="glbb-link-info">%s / %s ms</span>', $label, $count, $time); |
|
| 66 | + $queryTime = number_format( $queryTime * 1000, 2 ); |
|
| 67 | + $count = sprintf( '<span class="glbb-queries-count">%s</span>', count( $wpdb->queries ) ); |
|
| 68 | + $time = sprintf( '<span class="glbb-queries-time">%s</span>', $queryTime ); |
|
| 69 | + return sprintf( '%s <span class="glbb-link-info">%s / %s ms</span>', $label, $count, $time ); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - protected function sortByTime(array $a, array $b): int |
|
| 72 | + protected function sortByTime( array $a, array $b ): int |
|
| 73 | 73 | { |
| 74 | - if ($a['time'] !== $b['time']) { |
|
| 75 | - return ($a['time'] > $b['time']) ? -1 : 1; |
|
| 74 | + if( $a[ 'time' ] !== $b[ 'time' ] ) { |
|
| 75 | + return ( $a[ 'time' ] > $b[ 'time' ] ) ? -1 : 1; |
|
| 76 | 76 | } |
| 77 | 77 | return 0; |
| 78 | 78 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | /** |
| 8 | 8 | * @var array |
| 9 | 9 | */ |
| 10 | - protected $hooks = []; |
|
| 10 | + protected $hooks = [ ]; |
|
| 11 | 11 | /** |
| 12 | 12 | * @var int |
| 13 | 13 | */ |
@@ -19,120 +19,120 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | public function entries(): array |
| 21 | 21 | { |
| 22 | - if (!$this->hasEntries()) { |
|
| 23 | - return []; |
|
| 22 | + if( !$this->hasEntries() ) { |
|
| 23 | + return [ ]; |
|
| 24 | 24 | } |
| 25 | - if (!empty($this->hooks)) { |
|
| 25 | + if( !empty( $this->hooks ) ) { |
|
| 26 | 26 | return $this->hooks; |
| 27 | 27 | } |
| 28 | - array_walk($this->entries, function (&$data) { |
|
| 29 | - $total = $this->totalTimeForHook($data); |
|
| 30 | - $data['per_call'] = $total / $data['count']; |
|
| 31 | - $data['total'] = $total; |
|
| 28 | + array_walk( $this->entries, function( &$data ) { |
|
| 29 | + $total = $this->totalTimeForHook( $data ); |
|
| 30 | + $data[ 'per_call' ] = $total / $data[ 'count' ]; |
|
| 31 | + $data[ 'total' ] = $total; |
|
| 32 | 32 | }); |
| 33 | 33 | $entries = $this->entries; |
| 34 | - $executionOrder = array_keys($entries); |
|
| 35 | - uasort($entries, [$this, 'sortByTime']); |
|
| 36 | - $this->hooks = array_slice($entries, 0, 50); // Keep the 50 slowest hooks |
|
| 37 | - $this->totalHooks = array_sum(wp_list_pluck($this->entries, 'count')); |
|
| 38 | - $this->totalTime = array_sum(wp_list_pluck($this->entries, 'total')); |
|
| 39 | - $order = array_intersect($executionOrder, array_keys($this->hooks)); |
|
| 40 | - foreach ($order as $index => $hook) { |
|
| 41 | - $this->hooks[$hook]['index'] = $index; |
|
| 34 | + $executionOrder = array_keys( $entries ); |
|
| 35 | + uasort( $entries, [ $this, 'sortByTime' ] ); |
|
| 36 | + $this->hooks = array_slice( $entries, 0, 50 ); // Keep the 50 slowest hooks |
|
| 37 | + $this->totalHooks = array_sum( wp_list_pluck( $this->entries, 'count' ) ); |
|
| 38 | + $this->totalTime = array_sum( wp_list_pluck( $this->entries, 'total' ) ); |
|
| 39 | + $order = array_intersect( $executionOrder, array_keys( $this->hooks ) ); |
|
| 40 | + foreach( $order as $index => $hook ) { |
|
| 41 | + $this->hooks[ $hook ][ 'index' ] = $index; |
|
| 42 | 42 | } |
| 43 | 43 | return $this->hooks; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | public function label(): string |
| 47 | 47 | { |
| 48 | - $label = __('Hooks', 'blackbar'); |
|
| 48 | + $label = __( 'Hooks', 'blackbar' ); |
|
| 49 | 49 | $this->entries(); // calculate the totalTime |
| 50 | - if ($this->totalTime > 0) { |
|
| 51 | - $time = sprintf('<span class="glbb-hooks-time">%.2f</span> ms', $this->totalTime); |
|
| 52 | - return sprintf('%s <span class="glbb-link-info">%s</span>', $label, $time); |
|
| 50 | + if( $this->totalTime > 0 ) { |
|
| 51 | + $time = sprintf( '<span class="glbb-hooks-time">%.2f</span> ms', $this->totalTime ); |
|
| 52 | + return sprintf( '%s <span class="glbb-link-info">%s</span>', $label, $time ); |
|
| 53 | 53 | } |
| 54 | 54 | return $label; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | public function startTimer(): void |
| 58 | 58 | { |
| 59 | - if (class_exists('Debug_Bar_Slow_Actions')) { |
|
| 59 | + if( class_exists( 'Debug_Bar_Slow_Actions' ) ) { |
|
| 60 | 60 | return; |
| 61 | 61 | } |
| 62 | 62 | $hook = current_filter(); |
| 63 | - if (!isset($this->entries[$hook])) { |
|
| 64 | - $callbacks = $this->callbacksForHook($hook); |
|
| 65 | - if (empty($callbacks)) { |
|
| 63 | + if( !isset( $this->entries[ $hook ] ) ) { |
|
| 64 | + $callbacks = $this->callbacksForHook( $hook ); |
|
| 65 | + if( empty( $callbacks ) ) { |
|
| 66 | 66 | return; // We skipped Blackbar callbacks |
| 67 | 67 | } |
| 68 | - $this->entries[$hook] = [ |
|
| 68 | + $this->entries[ $hook ] = [ |
|
| 69 | 69 | 'callbacks' => $callbacks, |
| 70 | - 'callbacks_count' => count(array_merge(...$callbacks)), |
|
| 70 | + 'callbacks_count' => count( array_merge( ...$callbacks ) ), |
|
| 71 | 71 | 'count' => 0, |
| 72 | - 'stack' => [], |
|
| 73 | - 'time' => [], |
|
| 72 | + 'stack' => [ ], |
|
| 73 | + 'time' => [ ], |
|
| 74 | 74 | ]; |
| 75 | - add_action($hook, [$this, 'stopTimer'], 9999); // @phpstan-ignore-line |
|
| 75 | + add_action( $hook, [ $this, 'stopTimer' ], 9999 ); // @phpstan-ignore-line |
|
| 76 | 76 | } |
| 77 | - ++$this->entries[$hook]['count']; |
|
| 78 | - array_push($this->entries[$hook]['stack'], ['start' => microtime(true)]); |
|
| 77 | + ++$this->entries[ $hook ][ 'count' ]; |
|
| 78 | + array_push( $this->entries[ $hook ][ 'stack' ], [ 'start' => microtime( true ) ] ); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | 82 | * @param mixed $filteredValue |
| 83 | 83 | * @return mixed |
| 84 | 84 | */ |
| 85 | - public function stopTimer($filteredValue = null) |
|
| 85 | + public function stopTimer( $filteredValue = null ) |
|
| 86 | 86 | { |
| 87 | - $time = array_pop($this->entries[current_filter()]['stack']); |
|
| 88 | - $time['stop'] = microtime(true); |
|
| 89 | - array_push($this->entries[current_filter()]['time'], $time); |
|
| 87 | + $time = array_pop( $this->entries[ current_filter() ][ 'stack' ] ); |
|
| 88 | + $time[ 'stop' ] = microtime( true ); |
|
| 89 | + array_push( $this->entries[ current_filter() ][ 'time' ], $time ); |
|
| 90 | 90 | return $filteredValue; // In case this was a filter. |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - protected function callbacksForHook(string $hook): array |
|
| 93 | + protected function callbacksForHook( string $hook ): array |
|
| 94 | 94 | { |
| 95 | 95 | global $wp_filter; |
| 96 | - $results = []; |
|
| 97 | - if (!isset($wp_filter[$hook])) { |
|
| 96 | + $results = [ ]; |
|
| 97 | + if( !isset( $wp_filter[ $hook ] ) ) { |
|
| 98 | 98 | return $results; |
| 99 | 99 | } |
| 100 | - foreach ($wp_filter[$hook] as $priority => $callbacks) { |
|
| 101 | - $results[$priority] = $results[$priority] ?? []; |
|
| 102 | - foreach ($callbacks as $callback) { |
|
| 103 | - if (is_array($callback['function']) && 2 === count($callback['function'])) { |
|
| 104 | - list($object, $method) = $callback['function']; |
|
| 105 | - if (is_object($object)) { |
|
| 106 | - $object = get_class($object); |
|
| 107 | - $reflection = new \ReflectionClass($object); |
|
| 108 | - if (str_starts_with($reflection->getNamespaceName(), 'GeminiLabs\BlackBar')) { |
|
| 100 | + foreach( $wp_filter[ $hook ] as $priority => $callbacks ) { |
|
| 101 | + $results[ $priority ] = $results[ $priority ] ?? [ ]; |
|
| 102 | + foreach( $callbacks as $callback ) { |
|
| 103 | + if( is_array( $callback[ 'function' ] ) && 2 === count( $callback[ 'function' ] ) ) { |
|
| 104 | + list( $object, $method ) = $callback[ 'function' ]; |
|
| 105 | + if( is_object( $object ) ) { |
|
| 106 | + $object = get_class( $object ); |
|
| 107 | + $reflection = new \ReflectionClass( $object ); |
|
| 108 | + if( str_starts_with( $reflection->getNamespaceName(), 'GeminiLabs\BlackBar' ) ) { |
|
| 109 | 109 | continue; // skip Blackbar callbacks |
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | - $results[$priority][] = sprintf('%s::%s', $object, $method); |
|
| 113 | - } elseif (is_object($callback['function'])) { |
|
| 114 | - $results[$priority][] = get_class($callback['function']); |
|
| 112 | + $results[ $priority ][ ] = sprintf( '%s::%s', $object, $method ); |
|
| 113 | + } elseif( is_object( $callback[ 'function' ] ) ) { |
|
| 114 | + $results[ $priority ][ ] = get_class( $callback[ 'function' ] ); |
|
| 115 | 115 | } else { |
| 116 | - $results[$priority][] = $callback['function']; |
|
| 116 | + $results[ $priority ][ ] = $callback[ 'function' ]; |
|
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | 120 | return $results; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - protected function sortByTime(array $a, array $b): int |
|
| 123 | + protected function sortByTime( array $a, array $b ): int |
|
| 124 | 124 | { |
| 125 | - if ($a['total'] !== $b['total']) { |
|
| 126 | - return ($a['total'] > $b['total']) ? -1 : 1; |
|
| 125 | + if( $a[ 'total' ] !== $b[ 'total' ] ) { |
|
| 126 | + return ( $a[ 'total' ] > $b[ 'total' ] ) ? -1 : 1; |
|
| 127 | 127 | } |
| 128 | 128 | return 0; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - protected function totalTimeForHook(array $data): float |
|
| 131 | + protected function totalTimeForHook( array $data ): float |
|
| 132 | 132 | { |
| 133 | 133 | $total = 0; |
| 134 | - foreach ($data['time'] as $time) { |
|
| 135 | - $total += ($time['stop'] - $time['start']) * 1000; |
|
| 134 | + foreach( $data[ 'time' ] as $time ) { |
|
| 135 | + $total += ( $time[ 'stop' ] - $time[ 'start' ] ) * 1000; |
|
| 136 | 136 | } |
| 137 | 137 | return (float) $total; |
| 138 | 138 | } |
@@ -8,28 +8,28 @@ discard block |
||
| 8 | 8 | { |
| 9 | 9 | public function entries(): array |
| 10 | 10 | { |
| 11 | - if (!empty($this->entries)) { |
|
| 11 | + if( !empty( $this->entries ) ) { |
|
| 12 | 12 | return $this->entries; |
| 13 | 13 | } |
| 14 | - if (class_exists('\GeminiLabs\Castor\Facades\Development') |
|
| 15 | - && class_exists('\GeminiLabs\Castor\Helpers\Development') |
|
| 16 | - && method_exists('\GeminiLabs\Castor\Helpers\Development', 'templatePaths')) { // @phpstan-ignore-line |
|
| 14 | + if( class_exists( '\GeminiLabs\Castor\Facades\Development' ) |
|
| 15 | + && class_exists( '\GeminiLabs\Castor\Helpers\Development' ) |
|
| 16 | + && method_exists( '\GeminiLabs\Castor\Helpers\Development', 'templatePaths' ) ) { // @phpstan-ignore-line |
|
| 17 | 17 | $this->entries = \GeminiLabs\Castor\Facades\Development::templatePaths(); |
| 18 | 18 | } else { |
| 19 | - $files = array_values(array_filter(get_included_files(), function ($file) { |
|
| 20 | - $bool = false !== strpos($file, '/themes/') && false === strpos($file, '/functions.php'); |
|
| 21 | - return (bool) apply_filters('blackbar/templates/file', $bool, $file); |
|
| 22 | - })); |
|
| 23 | - $this->entries = array_map(function ($file) { |
|
| 24 | - return str_replace(trailingslashit(WP_CONTENT_DIR), '', $file); |
|
| 25 | - }, $files); |
|
| 19 | + $files = array_values( array_filter( get_included_files(), function( $file ) { |
|
| 20 | + $bool = false !== strpos( $file, '/themes/' ) && false === strpos( $file, '/functions.php' ); |
|
| 21 | + return (bool) apply_filters( 'blackbar/templates/file', $bool, $file ); |
|
| 22 | + }) ); |
|
| 23 | + $this->entries = array_map( function( $file ) { |
|
| 24 | + return str_replace( trailingslashit( WP_CONTENT_DIR ), '', $file ); |
|
| 25 | + }, $files ); |
|
| 26 | 26 | } |
| 27 | 27 | return $this->entries; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | public function hasEntries(): bool |
| 31 | 31 | { |
| 32 | - return !empty($this->entries()); |
|
| 32 | + return !empty( $this->entries() ); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public function isVisible(): bool |
@@ -39,6 +39,6 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | public function label(): string |
| 41 | 41 | { |
| 42 | - return __('Templates', 'blackbar'); |
|
| 42 | + return __( 'Templates', 'blackbar' ); |
|
| 43 | 43 | } |
| 44 | 44 | } |
@@ -30,14 +30,14 @@ discard block |
||
| 30 | 30 | /** |
| 31 | 31 | * @var array |
| 32 | 32 | */ |
| 33 | - protected $timer = []; |
|
| 33 | + protected $timer = [ ]; |
|
| 34 | 34 | |
| 35 | 35 | public function entries(): array |
| 36 | 36 | { |
| 37 | - $entries = []; |
|
| 38 | - foreach ($this->entries as $entry) { |
|
| 39 | - $entry['time'] = $this->formatTime($entry['time']); |
|
| 40 | - $entries[] = $entry; |
|
| 37 | + $entries = [ ]; |
|
| 38 | + foreach( $this->entries as $entry ) { |
|
| 39 | + $entry[ 'time' ] = $this->formatTime( $entry[ 'time' ] ); |
|
| 40 | + $entries[ ] = $entry; |
|
| 41 | 41 | } |
| 42 | 42 | return $entries; |
| 43 | 43 | } |
@@ -49,32 +49,32 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | public function label(): string |
| 51 | 51 | { |
| 52 | - return __('Profiler', 'blackbar'); |
|
| 52 | + return __( 'Profiler', 'blackbar' ); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - public function setNoise(int $nanoseconds): void |
|
| 55 | + public function setNoise( int $nanoseconds ): void |
|
| 56 | 56 | { |
| 57 | 57 | $this->noise = $nanoseconds - $this->start; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - public function setStart(int $nanoseconds): void |
|
| 60 | + public function setStart( int $nanoseconds ): void |
|
| 61 | 61 | { |
| 62 | 62 | $this->start = $nanoseconds; |
| 63 | 63 | $this->memory_start = memory_get_peak_usage(); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - public function setStop(int $nanoseconds): void |
|
| 66 | + public function setStop( int $nanoseconds ): void |
|
| 67 | 67 | { |
| 68 | 68 | $this->stop = $nanoseconds; |
| 69 | 69 | $this->memory_stop = memory_get_peak_usage(); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - public function start(string $name): void |
|
| 72 | + public function start( string $name ): void |
|
| 73 | 73 | { |
| 74 | 74 | $this->timer = [ |
| 75 | 75 | 'memory' => memory_get_peak_usage(), |
| 76 | 76 | 'name' => $name, |
| 77 | - 'start' => (int) hrtime(true), |
|
| 77 | + 'start' => (int) hrtime( true ), |
|
| 78 | 78 | 'stop' => 0, |
| 79 | 79 | 'time' => 0, |
| 80 | 80 | ]; |
@@ -82,35 +82,35 @@ discard block |
||
| 82 | 82 | |
| 83 | 83 | public function stop(): void |
| 84 | 84 | { |
| 85 | - if (!empty($this->timer)) { |
|
| 86 | - $nanoseconds = (int) hrtime(true); |
|
| 87 | - $this->timer['memory'] = max(0, memory_get_peak_usage() - $this->timer['memory']); |
|
| 88 | - $this->timer['stop'] = $nanoseconds; |
|
| 89 | - $this->timer['time'] = max(0, $nanoseconds - $this->timer['start'] - $this->noise); |
|
| 90 | - $this->entries[] = $this->timer; |
|
| 91 | - $this->timer = []; // reset timer |
|
| 85 | + if( !empty( $this->timer ) ) { |
|
| 86 | + $nanoseconds = (int) hrtime( true ); |
|
| 87 | + $this->timer[ 'memory' ] = max( 0, memory_get_peak_usage() - $this->timer[ 'memory' ] ); |
|
| 88 | + $this->timer[ 'stop' ] = $nanoseconds; |
|
| 89 | + $this->timer[ 'time' ] = max( 0, $nanoseconds - $this->timer[ 'start' ] - $this->noise ); |
|
| 90 | + $this->entries[ ] = $this->timer; |
|
| 91 | + $this->timer = [ ]; // reset timer |
|
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - protected function formatTime(int $nanoseconds): string |
|
| 95 | + protected function formatTime( int $nanoseconds ): string |
|
| 96 | 96 | { |
| 97 | - if ($nanoseconds >= 1e9) { |
|
| 98 | - return sprintf('%s s', $this->toDecimal(round($nanoseconds / 1e9, 2))); |
|
| 97 | + if( $nanoseconds >= 1e9 ) { |
|
| 98 | + return sprintf( '%s s', $this->toDecimal( round( $nanoseconds / 1e9, 2 ) ) ); |
|
| 99 | 99 | } |
| 100 | - if ($nanoseconds >= 1e6) { |
|
| 101 | - return sprintf('%s ms', $this->toDecimal(round($nanoseconds / 1e6, 2))); |
|
| 100 | + if( $nanoseconds >= 1e6 ) { |
|
| 101 | + return sprintf( '%s ms', $this->toDecimal( round( $nanoseconds / 1e6, 2 ) ) ); |
|
| 102 | 102 | } |
| 103 | - if ($nanoseconds >= 1e3) { |
|
| 104 | - return sprintf('%s µs', round($nanoseconds / 1e3)); |
|
| 103 | + if( $nanoseconds >= 1e3 ) { |
|
| 104 | + return sprintf( '%s µs', round( $nanoseconds / 1e3 ) ); |
|
| 105 | 105 | } |
| 106 | - return sprintf('%s ns', $nanoseconds); |
|
| 106 | + return sprintf( '%s ns', $nanoseconds ); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - protected function toDecimal(float $number): string |
|
| 109 | + protected function toDecimal( float $number ): string |
|
| 110 | 110 | { |
| 111 | 111 | $number = (string) $number; |
| 112 | - if (false !== strpos($number, '.')) { |
|
| 113 | - $number = rtrim(rtrim($number, '0'), '.'); |
|
| 112 | + if( false !== strpos( $number, '.' ) ) { |
|
| 113 | + $number = rtrim( rtrim( $number, '0' ), '.' ); |
|
| 114 | 114 | } |
| 115 | 115 | return $number; |
| 116 | 116 | } |