Cancelled
Push — master ( 706ba7...b281b4 )
by Paul
02:38
created
views/panels/hooks.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -1,45 +1,45 @@
 block discarded – undo
1
-<?php defined('WPINC') || die; ?>
1
+<?php defined( 'WPINC' ) || die; ?>
2 2
 
3
-<?php if (!$module->hasEntries()) : ?>
3
+<?php if( !$module->hasEntries() ) : ?>
4 4
     <table>
5 5
         <tbody>
6 6
             <tr>
7
-                <td><?= esc_html__('Please deactivate the Debug Bar Slow Actions plugin.', 'blackbar'); ?></td>
7
+                <td><?= esc_html__( 'Please deactivate the Debug Bar Slow Actions plugin.', 'blackbar' ); ?></td>
8 8
             </tr>
9 9
         </tbody>
10 10
     </table>
11 11
 <?php else : ?>
12 12
     <form>
13
-        <input type="text" id="glbb_hooks_callback" placeholder="<?= esc_attr__('Find callbacks containing', 'blackbar'); ?>">
14
-        <input type="text" id="glbb_hooks_min_time" placeholder="<?= esc_attr__('Minimum total time', 'blackbar'); ?>">
13
+        <input type="text" id="glbb_hooks_callback" placeholder="<?= esc_attr__( 'Find callbacks containing', 'blackbar' ); ?>">
14
+        <input type="text" id="glbb_hooks_min_time" placeholder="<?= esc_attr__( 'Minimum total time', 'blackbar' ); ?>">
15 15
         <select id="glbb_hooks_sort_by">
16
-            <option value><?= esc_html__('Sort by total time', 'blackbar'); ?></option>
17
-            <option value="order"><?= esc_html__('Sort by execution order', 'blackbar'); ?></option>
16
+            <option value><?= esc_html__( 'Sort by total time', 'blackbar' ); ?></option>
17
+            <option value="order"><?= esc_html__( 'Sort by execution order', 'blackbar' ); ?></option>
18 18
         </select>
19 19
     </form>
20 20
     <table class="glbb-grid">
21 21
         <thead>
22 22
             <tr>
23
-                <th><?= esc_html__('Action or Filter (Slowest 50)', 'blackbar'); ?></th>
24
-                <th><?= esc_html__('Callbacks', 'blackbar'); ?></th>
25
-                <th><?= esc_html__('Calls', 'blackbar'); ?></th>
26
-                <th><?= esc_html__('Per Call', 'blackbar'); ?></th>
27
-                <th><?= esc_html__('Total', 'blackbar'); ?></th>
23
+                <th><?= esc_html__( 'Action or Filter (Slowest 50)', 'blackbar' ); ?></th>
24
+                <th><?= esc_html__( 'Callbacks', 'blackbar' ); ?></th>
25
+                <th><?= esc_html__( 'Calls', 'blackbar' ); ?></th>
26
+                <th><?= esc_html__( 'Per Call', 'blackbar' ); ?></th>
27
+                <th><?= esc_html__( 'Total', 'blackbar' ); ?></th>
28 28
             </tr>
29 29
         </thead>
30 30
         <tbody>
31
-            <?php foreach ($module->entries() as $hook => $data) : ?>
32
-                <tr class="glbb-row-collapsed" data-index="<?= esc_attr($data['index']); ?>" data-time="<?= esc_attr($data['total']); ?>">
33
-                    <td><div class="glbb-row-toggle dashicons-before dashicons-arrow-right"><?= esc_html($hook); ?></div></td>
34
-                    <td data-callbacks="<?= esc_attr($data['callbacks_count']); ?>"><?= esc_html($data['callbacks_count']); ?></td>
35
-                    <td data-calls="<?= esc_attr($data['count']); ?>"><?= esc_html($data['count']); ?></td>
36
-                    <td data-percall="<?= esc_attr($data['per_call']); ?>"><?= esc_html($data['per_call']); ?></td>
37
-                    <td data-total="<?= esc_attr($data['total']); ?>"><?= esc_html($data['total_formatted']); ?></td>
31
+            <?php foreach( $module->entries() as $hook => $data ) : ?>
32
+                <tr class="glbb-row-collapsed" data-index="<?= esc_attr( $data[ 'index' ] ); ?>" data-time="<?= esc_attr( $data[ 'total' ] ); ?>">
33
+                    <td><div class="glbb-row-toggle dashicons-before dashicons-arrow-right"><?= esc_html( $hook ); ?></div></td>
34
+                    <td data-callbacks="<?= esc_attr( $data[ 'callbacks_count' ] ); ?>"><?= esc_html( $data[ 'callbacks_count' ] ); ?></td>
35
+                    <td data-calls="<?= esc_attr( $data[ 'count' ] ); ?>"><?= esc_html( $data[ 'count' ] ); ?></td>
36
+                    <td data-percall="<?= esc_attr( $data[ 'per_call' ] ); ?>"><?= esc_html( $data[ 'per_call' ] ); ?></td>
37
+                    <td data-total="<?= esc_attr( $data[ 'total' ] ); ?>"><?= esc_html( $data[ 'total_formatted' ] ); ?></td>
38 38
                     <td class="glbb-row-details">
39 39
                         <ol>
40
-                            <?php foreach ($data['callbacks'] as $priority => $callbacks) : ?>
41
-                                <?php foreach ($callbacks as $callback) : ?>
42
-                                    <li value="<?= esc_attr($priority); ?>"><?= esc_html($callback); ?></li>
40
+                            <?php foreach( $data[ 'callbacks' ] as $priority => $callbacks ) : ?>
41
+                                <?php foreach( $callbacks as $callback ) : ?>
42
+                                    <li value="<?= esc_attr( $priority ); ?>"><?= esc_html( $callback ); ?></li>
43 43
                                 <?php endforeach; ?>
44 44
                             <?php endforeach; ?>
45 45
                         </ol>
Please login to merge, or discard this patch.
views/debug-bar.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -1,14 +1,14 @@  discard block
 block discarded – undo
1
-<?php defined('WPINC') || die; ?>
1
+<?php defined( 'WPINC' ) || die; ?>
2 2
 
3 3
 <div id="glbb">
4
-    <?php foreach ($modules as $module) : /* Ensure that the console entries are loaded last */ ?>
5
-        <?php if (!$module->isVisible() || 'glbb-console' === $module->id()) continue; ?>
4
+    <?php foreach( $modules as $module ) : /* Ensure that the console entries are loaded last */ ?>
5
+        <?php if( !$module->isVisible() || 'glbb-console' === $module->id() ) continue; ?>
6 6
         <div id="<?= $module->id(); ?>" class="glbb-panel glbb-hidden">
7 7
             <?php $module->render(); ?>
8 8
         </div>
9 9
     <?php endforeach; ?>
10
-    <?php foreach ($modules as $module) : /* Ensure that the console entries are loaded last */ ?>
11
-        <?php if (!$module->isVisible() || 'glbb-console' !== $module->id()) continue; ?>
10
+    <?php foreach( $modules as $module ) : /* Ensure that the console entries are loaded last */ ?>
11
+        <?php if( !$module->isVisible() || 'glbb-console' !== $module->id() ) continue; ?>
12 12
         <div id="<?= $module->id(); ?>" class="glbb-panel glbb-hidden">
13 13
             <?php $module->render(); ?>
14 14
         </div>
@@ -16,19 +16,19 @@  discard block
 block discarded – undo
16 16
     <div class="glbb-panel-links">
17 17
         <a href="#" class="dashicons-before glbb-toggle">
18 18
             <span class="screen-reader-text">
19
-                <?= esc_html__('Toggle', 'blackbar'); ?>
19
+                <?= esc_html__( 'Toggle', 'blackbar' ); ?>
20 20
             </span>
21 21
         </a>
22
-        <?php foreach ($modules as $module) : ?>
23
-            <?php if (!$module->isVisible()) continue; ?>
24
-            <a href="#" data-panel="<?= esc_attr($module->id()); ?>" data-info="<?= esc_attr($module->info()); ?>" class="dashicons-before <?= $module->classes(); ?>">
22
+        <?php foreach( $modules as $module ) : ?>
23
+            <?php if( !$module->isVisible() ) continue; ?>
24
+            <a href="#" data-panel="<?= esc_attr( $module->id() ); ?>" data-info="<?= esc_attr( $module->info() ); ?>" class="dashicons-before <?= $module->classes(); ?>">
25 25
                 <span><?= $module->label(); ?></span>
26 26
             </a>
27 27
         <?php endforeach; ?>
28 28
         <div>
29 29
             <a href="#" class="dashicons-before glbb-close">
30 30
                 <span class="screen-reader-text">
31
-                    <?= esc_html__('Close', 'blackbar'); ?>
31
+                    <?= esc_html__( 'Close', 'blackbar' ); ?>
32 32
                 </span>
33 33
             </a>
34 34
         </div>
Please login to merge, or discard this patch.
views/panels/profiler.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,19 +1,19 @@
 block discarded – undo
1
-<?php defined('WPINC') || die; ?>
1
+<?php defined( 'WPINC' ) || die; ?>
2 2
 
3 3
 <table class="glbb-grid">
4 4
     <thead>
5 5
         <tr>
6
-            <th><?= esc_html__('Timer Name', 'blackbar'); ?></th>
7
-            <th><?= esc_html__('Memory Used', 'blackbar'); ?></th>
8
-            <th><?= esc_html__('Total Time', 'blackbar'); ?></th>
6
+            <th><?= esc_html__( 'Timer Name', 'blackbar' ); ?></th>
7
+            <th><?= esc_html__( 'Memory Used', 'blackbar' ); ?></th>
8
+            <th><?= esc_html__( 'Total Time', 'blackbar' ); ?></th>
9 9
         </tr>
10 10
     </thead>
11 11
     <tbody>
12
-        <?php foreach ($module->entries() as $entry) : ?>
12
+        <?php foreach( $module->entries() as $entry ) : ?>
13 13
             <tr>
14
-                <td><?= esc_html($entry['name']); ?></td>
15
-                <td><?= (string) size_format($entry['memory'], 2); ?></td>
16
-                <td><?= esc_html($entry['time']); ?></td>
14
+                <td><?= esc_html( $entry[ 'name' ] ); ?></td>
15
+                <td><?= (string) size_format( $entry[ 'memory' ], 2 ); ?></td>
16
+                <td><?= esc_html( $entry[ 'time' ] ); ?></td>
17 17
             </tr>
18 18
         <?php endforeach; ?>
19 19
     </tbody>
Please login to merge, or discard this patch.
plugin/Modules/Globals.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -6,22 +6,22 @@  discard block
 block discarded – undo
6 6
 {
7 7
     public function entries(): array
8 8
     {
9
-        if (!empty($this->entries)) {
9
+        if( !empty( $this->entries ) ) {
10 10
             return $this->entries;
11 11
         }
12
-        $globals = apply_filters('blackbar/globals', [
12
+        $globals = apply_filters( 'blackbar/globals', [
13 13
             'INPUT_COOKIE' => $_COOKIE,
14 14
             'INPUT_ENV' => $_ENV,
15 15
             'INPUT_GET' => $_GET,
16 16
             'INPUT_POST' => $_POST,
17 17
             'INPUT_SERVER' => $_SERVER,
18 18
             'WP_Screen' => $this->wpscreen(),
19
-        ]);
20
-        $globals = array_filter($globals);
21
-        foreach ($globals as $key => $values) {
22
-            $this->entries[] = [
19
+        ] );
20
+        $globals = array_filter( $globals );
21
+        foreach( $globals as $key => $values ) {
22
+            $this->entries[ ] = [
23 23
                 'name' => $key,
24
-                'value' => var_export($values, true),
24
+                'value' => var_export( $values, true ),
25 25
             ];
26 26
         }
27 27
         return $this->entries;
@@ -29,22 +29,22 @@  discard block
 block discarded – undo
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 label(): string
36 36
     {
37
-        return __('Globals', 'blackbar');
37
+        return __( 'Globals', 'blackbar' );
38 38
     }
39 39
 
40 40
     protected function wpscreen(): array
41 41
     {
42
-        $values = [];
43
-        if (is_admin() && $screen = get_current_screen()) {
44
-            $reflection = new \ReflectionClass($screen);
45
-            $properties = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC);
46
-            foreach ($properties as $property) {
47
-                $values[$property->getName()] = $property->getValue($screen);
42
+        $values = [ ];
43
+        if( is_admin() && $screen = get_current_screen() ) {
44
+            $reflection = new \ReflectionClass( $screen );
45
+            $properties = $reflection->getProperties( \ReflectionProperty::IS_PUBLIC );
46
+            foreach( $properties as $property ) {
47
+                $values[ $property->getName() ] = $property->getValue( $screen );
48 48
             }
49 49
         }
50 50
         return $values;
Please login to merge, or discard this patch.
plugin/Modules/Hooks.php 1 patch
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
     /**
8 8
      * @var array
9 9
      */
10
-    protected $hooks = [];
10
+    protected $hooks = [ ];
11 11
     /**
12 12
      * @var int
13 13
      */
@@ -20,28 +20,28 @@  discard block
 block discarded – undo
20 20
 
21 21
     public function entries(): array
22 22
     {
23
-        if (!$this->hasEntries()) {
24
-            return [];
23
+        if( !$this->hasEntries() ) {
24
+            return [ ];
25 25
         }
26
-        if (!empty($this->hooks)) {
26
+        if( !empty( $this->hooks ) ) {
27 27
             return $this->hooks;
28 28
         }
29
-        array_walk($this->entries, function (&$data) {
30
-            $total = $this->totalTimeForHook($data);
31
-            $perCall = (int) round($total / $data['count']);
32
-            $data['per_call'] = $this->formatTime($perCall);
33
-            $data['total'] = $total;
34
-            $data['total_formatted'] = $this->formatTime($total);
29
+        array_walk( $this->entries, function( &$data ) {
30
+            $total = $this->totalTimeForHook( $data );
31
+            $perCall = (int) round( $total / $data[ 'count' ] );
32
+            $data[ 'per_call' ] = $this->formatTime( $perCall );
33
+            $data[ 'total' ] = $total;
34
+            $data[ 'total_formatted' ] = $this->formatTime( $total );
35 35
         });
36 36
         $entries = $this->entries;
37
-        $executionOrder = array_keys($entries);
38
-        uasort($entries, [$this, 'sortByTime']);
39
-        $this->hooks = array_slice($entries, 0, 50); // Keep the 50 slowest hooks
40
-        $this->totalHooks = array_sum(wp_list_pluck($this->entries, 'count'));
41
-        $this->totalTime = array_sum(wp_list_pluck($this->entries, 'total'));
42
-        $order = array_intersect($executionOrder, array_keys($this->hooks));
43
-        foreach ($order as $index => $hook) {
44
-            $this->hooks[$hook]['index'] = $index;
37
+        $executionOrder = array_keys( $entries );
38
+        uasort( $entries, [ $this, 'sortByTime' ] );
39
+        $this->hooks = array_slice( $entries, 0, 50 ); // Keep the 50 slowest hooks
40
+        $this->totalHooks = array_sum( wp_list_pluck( $this->entries, 'count' ) );
41
+        $this->totalTime = array_sum( wp_list_pluck( $this->entries, 'total' ) );
42
+        $order = array_intersect( $executionOrder, array_keys( $this->hooks ) );
43
+        foreach( $order as $index => $hook ) {
44
+            $this->hooks[ $hook ][ 'index' ] = $index;
45 45
         }
46 46
         return $this->hooks;
47 47
     }
@@ -49,92 +49,92 @@  discard block
 block discarded – undo
49 49
     public function info(): string
50 50
     {
51 51
         $this->entries(); // calculate the totalTime
52
-        return $this->formatTime($this->totalTime);
52
+        return $this->formatTime( $this->totalTime );
53 53
     }
54 54
 
55 55
     public function label(): string
56 56
     {
57
-        return __('Hooks', 'blackbar');
57
+        return __( 'Hooks', 'blackbar' );
58 58
     }
59 59
 
60 60
     public function startTimer(): void
61 61
     {
62
-        if (class_exists('Debug_Bar_Slow_Actions')) {
62
+        if( class_exists( 'Debug_Bar_Slow_Actions' ) ) {
63 63
             return;
64 64
         }
65 65
         $hook = current_filter();
66
-        if (!isset($this->entries[$hook])) {
67
-            $callbacks = $this->callbacksForHook($hook);
68
-            if (empty($callbacks)) {
66
+        if( !isset( $this->entries[ $hook ] ) ) {
67
+            $callbacks = $this->callbacksForHook( $hook );
68
+            if( empty( $callbacks ) ) {
69 69
                 return; // We skipped Blackbar callbacks
70 70
             }
71
-            $this->entries[$hook] = [
71
+            $this->entries[ $hook ] = [
72 72
                 'callbacks' => $callbacks,
73
-                'callbacks_count' => count(array_merge(...$callbacks)),
73
+                'callbacks_count' => count( array_merge( ...$callbacks ) ),
74 74
                 'count' => 0,
75
-                'stack' => [],
76
-                'time' => [],
75
+                'stack' => [ ],
76
+                'time' => [ ],
77 77
             ];
78
-            add_action($hook, [$this, 'stopTimer'], 9999); // @phpstan-ignore-line
78
+            add_action( $hook, [ $this, 'stopTimer' ], 9999 ); // @phpstan-ignore-line
79 79
         }
80
-        ++$this->entries[$hook]['count'];
81
-        array_push($this->entries[$hook]['stack'], ['start' => (int) hrtime(true)]);
80
+        ++$this->entries[ $hook ][ 'count' ];
81
+        array_push( $this->entries[ $hook ][ 'stack' ], [ 'start' => (int) hrtime( true ) ] );
82 82
     }
83 83
 
84 84
     /**
85 85
      * @param mixed $filteredValue
86 86
      * @return mixed
87 87
      */
88
-    public function stopTimer($filteredValue = null)
88
+    public function stopTimer( $filteredValue = null )
89 89
     {
90
-        $time = array_pop($this->entries[current_filter()]['stack']);
91
-        $time['stop'] = (int) hrtime(true);
92
-        array_push($this->entries[current_filter()]['time'], $time);
90
+        $time = array_pop( $this->entries[ current_filter() ][ 'stack' ] );
91
+        $time[ 'stop' ] = (int) hrtime( true );
92
+        array_push( $this->entries[ current_filter() ][ 'time' ], $time );
93 93
         return $filteredValue; // In case this was a filter.
94 94
     }
95 95
 
96 96
     /**
97 97
      * @param mixed $function
98 98
      */
99
-    protected function callbackFunction($function): string
99
+    protected function callbackFunction( $function ): string
100 100
     {
101
-        if (is_array($function)) {
102
-            list($object, $method) = $function;
103
-            if (is_object($object)) {
104
-                $object = get_class($object);
101
+        if( is_array( $function ) ) {
102
+            list( $object, $method ) = $function;
103
+            if( is_object( $object ) ) {
104
+                $object = get_class( $object );
105 105
             }
106
-            if (str_starts_with($object, 'GeminiLabs\BlackBar')) {
106
+            if( str_starts_with( $object, 'GeminiLabs\BlackBar' ) ) {
107 107
                 return ''; // skip Blackbar callbacks
108 108
             }
109
-            return rtrim(sprintf('%s::%s', $object, $method), ':');
109
+            return rtrim( sprintf( '%s::%s', $object, $method ), ':' );
110 110
         }
111
-        if (is_object($function)) {
112
-            return get_class($function);
111
+        if( is_object( $function ) ) {
112
+            return get_class( $function );
113 113
         }
114 114
         return (string) $function;
115 115
     }
116 116
 
117
-    protected function callbacksForHook(string $hook): array
117
+    protected function callbacksForHook( string $hook ): array
118 118
     {
119 119
         global $wp_filter;
120
-        $data = $wp_filter[$hook] ?? [];
121
-        $results = [];
122
-        foreach ($data as $priority => $callbacks) {
123
-            $results[$priority] = $results[$priority] ?? [];
124
-            foreach ($callbacks as $callback) {
125
-                $function = $this->callbackFunction($callback['function']);
126
-                if (!empty($function)) {
127
-                    $results[$priority][] = $function;
120
+        $data = $wp_filter[ $hook ] ?? [ ];
121
+        $results = [ ];
122
+        foreach( $data as $priority => $callbacks ) {
123
+            $results[ $priority ] = $results[ $priority ] ?? [ ];
124
+            foreach( $callbacks as $callback ) {
125
+                $function = $this->callbackFunction( $callback[ 'function' ] );
126
+                if( !empty( $function ) ) {
127
+                    $results[ $priority ][ ] = $function;
128 128
                 }
129 129
             }
130 130
         }
131 131
         return $results;
132 132
     }
133 133
 
134
-    protected function sortByTime(array $a, array $b): int
134
+    protected function sortByTime( array $a, array $b ): int
135 135
     {
136
-        if ($a['total'] !== $b['total']) {
137
-            return ($a['total'] > $b['total']) ? -1 : 1;
136
+        if( $a[ 'total' ] !== $b[ 'total' ] ) {
137
+            return ( $a[ 'total' ] > $b[ 'total' ] ) ? -1 : 1;
138 138
         }
139 139
         return 0;
140 140
     }
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
     /**
143 143
      * Total elapsed time in nanoseconds.
144 144
      */
145
-    protected function totalTimeForHook(array $data): int
145
+    protected function totalTimeForHook( array $data ): int
146 146
     {
147 147
         $total = 0;
148
-        foreach ($data['time'] as $time) {
149
-            $total += ($time['stop'] - $time['start']);
148
+        foreach( $data[ 'time' ] as $time ) {
149
+            $total += ( $time[ 'stop' ] - $time[ 'start' ] );
150 150
         }
151 151
         return $total;
152 152
     }
Please login to merge, or discard this patch.
plugin/Modules/Queries.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -7,70 +7,70 @@
 block discarded – undo
7 7
     public function entries(): array
8 8
     {
9 9
         global $wpdb;
10
-        $entries = [];
10
+        $entries = [ ];
11 11
         $index = 0;
12 12
         $search = [
13 13
             'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT',
14 14
             'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE',
15 15
         ];
16
-        $replace = array_map(function ($value) {
17
-            return PHP_EOL.$value;
18
-        }, $search);
19
-        foreach ($wpdb->queries as $query) {
20
-            $sql = preg_replace('/\s\s+/', ' ', trim($query[0]));
21
-            $sql = str_replace(PHP_EOL, ' ', $sql);
22
-            $sql = str_replace(['( ', ' )', ' ,'], ['(', ')', ','], $sql);
23
-            $sql = str_replace($search, $replace, $sql);
24
-            $parts = explode(PHP_EOL, $sql);
25
-            $sql = array_reduce($parts, function ($carry, $part) {
26
-                if (str_starts_with($part, 'SELECT') && strlen($part) > 100) {
27
-                    $part = preg_replace('/\s*(,)\s*/', ','.PHP_EOL.'  ', $part);
16
+        $replace = array_map( function( $value ) {
17
+            return PHP_EOL . $value;
18
+        }, $search );
19
+        foreach( $wpdb->queries as $query ) {
20
+            $sql = preg_replace( '/\s\s+/', ' ', trim( $query[ 0 ] ) );
21
+            $sql = str_replace( PHP_EOL, ' ', $sql );
22
+            $sql = str_replace( [ '( ', ' )', ' ,' ], [ '(', ')', ',' ], $sql );
23
+            $sql = str_replace( $search, $replace, $sql );
24
+            $parts = explode( PHP_EOL, $sql );
25
+            $sql = array_reduce( $parts, function( $carry, $part ) {
26
+                if( str_starts_with( $part, 'SELECT' ) && strlen( $part ) > 100 ) {
27
+                    $part = preg_replace( '/\s*(,)\s*/', ',' . PHP_EOL . '  ', $part );
28 28
                 }
29
-                if (str_starts_with($part, 'WHERE')) {
30
-                    $part = str_replace('AND', PHP_EOL.'  AND', $part);
29
+                if( str_starts_with( $part, 'WHERE' ) ) {
30
+                    $part = str_replace( 'AND', PHP_EOL . '  AND', $part );
31 31
                 }
32
-                return $carry.$part.PHP_EOL;
32
+                return $carry . $part . PHP_EOL;
33 33
             });
34
-            $trace = explode(', ', $query[2]);
35
-            $nanoseconds = (int) round($query[1] * 1e9);
36
-            $entries[] = [
34
+            $trace = explode( ', ', $query[ 2 ] );
35
+            $nanoseconds = (int) round( $query[ 1 ] * 1e9 );
36
+            $entries[ ] = [
37 37
                 'index' => $index++,
38 38
                 'sql' => $sql,
39 39
                 'time' => $nanoseconds,
40
-                'time_formatted' => $this->formatTime($nanoseconds),
41
-                'trace' => array_reverse($trace, true),
40
+                'time_formatted' => $this->formatTime( $nanoseconds ),
41
+                'trace' => array_reverse( $trace, true ),
42 42
             ];
43 43
         }
44
-        uasort($entries, [$this, 'sortByTime']);
44
+        uasort( $entries, [ $this, 'sortByTime' ] );
45 45
         return $entries;
46 46
     }
47 47
 
48 48
     public function hasEntries(): bool
49 49
     {
50 50
         global $wpdb;
51
-        return !empty($wpdb->queries);
51
+        return !empty( $wpdb->queries );
52 52
     }
53 53
 
54 54
     public function info(): string
55 55
     {
56
-        if (!defined('SAVEQUERIES') || !SAVEQUERIES) {
56
+        if( !defined( 'SAVEQUERIES' ) || !SAVEQUERIES ) {
57 57
             return '';
58 58
         }
59 59
         global $wpdb;
60
-        $seconds = (float) array_sum(wp_list_pluck($wpdb->queries, 1));
61
-        $nanoseconds = (int) round($seconds * 1e9);
62
-        return $this->formatTime($nanoseconds);
60
+        $seconds = (float) array_sum( wp_list_pluck( $wpdb->queries, 1 ) );
61
+        $nanoseconds = (int) round( $seconds * 1e9 );
62
+        return $this->formatTime( $nanoseconds );
63 63
     }
64 64
 
65 65
     public function label(): string
66 66
     {
67
-        return __('SQL', 'blackbar');
67
+        return __( 'SQL', 'blackbar' );
68 68
     }
69 69
 
70
-    protected function sortByTime(array $a, array $b): int
70
+    protected function sortByTime( array $a, array $b ): int
71 71
     {
72
-        if ($a['time'] !== $b['time']) {
73
-            return ($a['time'] > $b['time']) ? -1 : 1;
72
+        if( $a[ 'time' ] !== $b[ 'time' ] ) {
73
+            return ( $a[ 'time' ] > $b[ 'time' ] ) ? -1 : 1;
74 74
         }
75 75
         return 0;
76 76
     }
Please login to merge, or discard this patch.
plugin/Modules/Console.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -29,37 +29,37 @@  discard block
 block discarded – undo
29 29
 
30 30
     public function classes(): string
31 31
     {
32
-        $errno = array_unique(wp_list_pluck($this->entries, 'errno'));
33
-        if (in_array(E_ERROR, $errno)) {
34
-            return sprintf('%s glbb-error', $this->id());
32
+        $errno = array_unique( wp_list_pluck( $this->entries, 'errno' ) );
33
+        if( in_array( E_ERROR, $errno ) ) {
34
+            return sprintf( '%s glbb-error', $this->id() );
35 35
         }
36
-        if (in_array(E_WARNING, $errno)) {
37
-            return sprintf('%s glbb-warning', $this->id());
36
+        if( in_array( E_WARNING, $errno ) ) {
37
+            return sprintf( '%s glbb-warning', $this->id() );
38 38
         }
39 39
         return $this->id();
40 40
     }
41 41
 
42 42
     public function entries(): array
43 43
     {
44
-        $entries = [];
45
-        foreach ($this->entries as $entry) {
46
-            $entry['name'] = ucfirst($entry['errname']);
47
-            if ($entry['count'] > 1) {
48
-                $entry['name'] = sprintf('%s (%s)', $entry['name'], $entry['count']);
44
+        $entries = [ ];
45
+        foreach( $this->entries as $entry ) {
46
+            $entry[ 'name' ] = ucfirst( $entry[ 'errname' ] );
47
+            if( $entry[ 'count' ] > 1 ) {
48
+                $entry[ 'name' ] = sprintf( '%s (%s)', $entry[ 'name' ], $entry[ 'count' ] );
49 49
             }
50
-            $entries[] = $entry;
50
+            $entries[ ] = $entry;
51 51
         }
52 52
         return $entries;
53 53
     }
54 54
 
55 55
     public function info(): string
56 56
     {
57
-        $counts = array_count_values(wp_list_pluck($this->entries, 'errno'));
58
-        $entryCount = count($this->entries);
59
-        if (!empty($counts[E_ERROR])) {
60
-            return sprintf('%d, %d!', $entryCount, $counts[E_ERROR]);
57
+        $counts = array_count_values( wp_list_pluck( $this->entries, 'errno' ) );
58
+        $entryCount = count( $this->entries );
59
+        if( !empty( $counts[ E_ERROR ] ) ) {
60
+            return sprintf( '%d, %d!', $entryCount, $counts[ E_ERROR ] );
61 61
         }
62
-        if ($entryCount > 0) {
62
+        if( $entryCount > 0 ) {
63 63
             return (string) $entryCount;
64 64
         }
65 65
         return '';
@@ -67,51 +67,51 @@  discard block
 block discarded – undo
67 67
 
68 68
     public function label(): string
69 69
     {
70
-        return __('Console', 'blackbar');
70
+        return __( 'Console', 'blackbar' );
71 71
     }
72 72
 
73
-    public function store(string $message, string $errno = '', string $location = ''): void
73
+    public function store( string $message, string $errno = '', string $location = '' ): void
74 74
     {
75
-        if (is_numeric($errno)) { // entry likely stored by set_error_handler()
75
+        if( is_numeric( $errno ) ) { // entry likely stored by set_error_handler()
76 76
             $errname = 'Unknown';
77
-            if (array_key_exists((int) $errno, static::ERROR_CODES)) {
78
-                $errname = static::ERROR_CODES[$errno];
77
+            if( array_key_exists( (int) $errno, static::ERROR_CODES ) ) {
78
+                $errname = static::ERROR_CODES[ $errno ];
79 79
             }
80 80
         } else { // entry likely stored by filter hook
81 81
             $errname = 'Debug';
82
-            if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) {
82
+            if( array_key_exists( $errno, static::MAPPED_ERROR_CODES ) ) {
83 83
                 $errname = $errno;
84
-                $errno = static::MAPPED_ERROR_CODES[$errno];
84
+                $errno = static::MAPPED_ERROR_CODES[ $errno ];
85 85
             }
86 86
         }
87
-        $errname = strtolower($errname);
88
-        $hash = md5($errno.$errname.$message.$location);
89
-        if (array_key_exists($hash, $this->entries)) {
90
-            ++$this->entries[$hash]['count'];
87
+        $errname = strtolower( $errname );
88
+        $hash = md5( $errno . $errname . $message . $location );
89
+        if( array_key_exists( $hash, $this->entries ) ) {
90
+            ++$this->entries[ $hash ][ 'count' ];
91 91
         } else {
92
-            $this->entries[$hash] = [
92
+            $this->entries[ $hash ] = [
93 93
                 'count' => 0,
94 94
                 'errname' => $errname,
95 95
                 'errno' => (int) $errno,
96
-                'message' => $this->normalizeMessage($message, $location),
96
+                'message' => $this->normalizeMessage( $message, $location ),
97 97
             ];
98 98
         }
99 99
     }
100 100
 
101
-    protected function normalizeMessage($message, string $location): string
101
+    protected function normalizeMessage( $message, string $location ): string
102 102
     {
103
-        if ($message instanceof \DateTime) {
104
-            $message = $message->format('Y-m-d H:i:s');
105
-        } elseif (is_object($message) || is_array($message)) {
106
-            $message = (new Dump())->dump($message);
103
+        if( $message instanceof \DateTime ) {
104
+            $message = $message->format( 'Y-m-d H:i:s' );
105
+        } elseif( is_object( $message ) || is_array( $message ) ) {
106
+            $message = ( new Dump() )->dump( $message );
107 107
         } else {
108
-            $message = esc_html(trim((string) $message));
108
+            $message = esc_html( trim( (string) $message ) );
109 109
         }
110
-        $location = trim($location);
111
-        if (!empty($location)) {
112
-            $location = str_replace([WP_CONTENT_DIR, ABSPATH], '', $location);
113
-            $location = sprintf('[%s]', $location);
110
+        $location = trim( $location );
111
+        if( !empty( $location ) ) {
112
+            $location = str_replace( [ WP_CONTENT_DIR, ABSPATH ], '', $location );
113
+            $location = sprintf( '[%s]', $location );
114 114
         }
115
-        return trim(sprintf('%s %s', $location, $message));
115
+        return trim( sprintf( '%s %s', $location, $message ) );
116 116
     }
117 117
 }
Please login to merge, or discard this patch.