Passed
Push — master ( 0bfe2c...477c3d )
by Paul
03:02
created
plugin/Modules/Actions.php 1 patch
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -27,70 +27,70 @@  discard block
 block discarded – undo
27 27
      */
28 28
     protected $totalTime;
29 29
 
30
-    public function __construct(Application $app)
30
+    public function __construct( Application $app )
31 31
     {
32 32
         $this->app = $app;
33
-        $this->entries = [];
34
-        $this->hooks = [];
33
+        $this->entries = [ ];
34
+        $this->hooks = [ ];
35 35
         $this->totalActions = 0;
36 36
         $this->totalTime = (float) 0;
37 37
     }
38 38
 
39
-    public function callbacksForHook(string $action): void
39
+    public function callbacksForHook( string $action ): void
40 40
     {
41 41
         global $wp_filter;
42
-        if (!array_key_exists($action, $this->hooks)) {
42
+        if( !array_key_exists( $action, $this->hooks ) ) {
43 43
             return;
44 44
         }
45
-        $this->hooks[$action]['callbacks_count'] = 0;
46
-        foreach ($wp_filter[$action] as $priority => $callbacks) {
47
-            if (!array_key_exists($priority, $this->hooks[$action]['callbacks'])) {
48
-                $this->hooks[$action]['callbacks'][$priority] = [];
45
+        $this->hooks[ $action ][ 'callbacks_count' ] = 0;
46
+        foreach( $wp_filter[ $action ] as $priority => $callbacks ) {
47
+            if( !array_key_exists( $priority, $this->hooks[ $action ][ 'callbacks' ] ) ) {
48
+                $this->hooks[ $action ][ 'callbacks' ][ $priority ] = [ ];
49 49
             }
50
-            foreach ($callbacks as $callback) {
51
-                if (is_array($callback['function']) && 2 === count($callback['function'])) {
52
-                    list($object, $method) = $callback['function'];
53
-                    if (is_object($object)) {
54
-                        $object = get_class($object);
50
+            foreach( $callbacks as $callback ) {
51
+                if( is_array( $callback[ 'function' ] ) && 2 === count( $callback[ 'function' ] ) ) {
52
+                    list( $object, $method ) = $callback[ 'function' ];
53
+                    if( is_object( $object ) ) {
54
+                        $object = get_class( $object );
55 55
                         // $reflection = new \ReflectionClass($object);
56 56
                         // if (str_starts_with($reflection->getNamespaceName(), 'GeminiLabs\BlackBar')) {
57 57
                         //     continue; // skip blackbar callbacks
58 58
                         // }
59 59
                     }
60
-                    $this->hooks[$action]['callbacks'][$priority][] = sprintf('%s::%s', $object, $method);
61
-                } elseif (is_object($callback['function'])) {
62
-                    $this->hooks[$action]['callbacks'][$priority][] = get_class($callback['function']);
60
+                    $this->hooks[ $action ][ 'callbacks' ][ $priority ][ ] = sprintf( '%s::%s', $object, $method );
61
+                } elseif( is_object( $callback[ 'function' ] ) ) {
62
+                    $this->hooks[ $action ][ 'callbacks' ][ $priority ][ ] = get_class( $callback[ 'function' ] );
63 63
                 } else {
64
-                    $this->hooks[$action]['callbacks'][$priority][] = $callback['function'];
64
+                    $this->hooks[ $action ][ 'callbacks' ][ $priority ][ ] = $callback[ 'function' ];
65 65
                 }
66
-                ++$this->hooks[$action]['callbacks_count'];
66
+                ++$this->hooks[ $action ][ 'callbacks_count' ];
67 67
             }
68 68
         }
69 69
     }
70 70
 
71 71
     public function entries(): array
72 72
     {
73
-        if (class_exists('Debug_Bar_Slow_Actions')) {
74
-            return [];
73
+        if( class_exists( 'Debug_Bar_Slow_Actions' ) ) {
74
+            return [ ];
75 75
         }
76
-        if (!empty($this->entries) || empty($this->hooks)) {
76
+        if( !empty( $this->entries ) || empty( $this->hooks ) ) {
77 77
             return $this->entries;
78 78
         }
79
-        foreach ($this->hooks as $action => $data) {
80
-            $total = $this->totalTimeForHook($data);
81
-            $this->hooks[$action]['total'] = $total;
79
+        foreach( $this->hooks as $action => $data ) {
80
+            $total = $this->totalTimeForHook( $data );
81
+            $this->hooks[ $action ][ 'total' ] = $total;
82 82
             $this->totalTime += $total;
83
-            $this->totalActions += $data['count'];
84
-            $this->callbacksForHook($action);
83
+            $this->totalActions += $data[ 'count' ];
84
+            $this->callbacksForHook( $action );
85 85
         }
86
-        uasort($this->hooks, [$this, 'sortByTime']);
87
-        $this->entries = array_slice($this->hooks, 0, 50); // return the 50 slowest actions
86
+        uasort( $this->hooks, [ $this, 'sortByTime' ] );
87
+        $this->entries = array_slice( $this->hooks, 0, 50 ); // return the 50 slowest actions
88 88
         return $this->entries;
89 89
     }
90 90
 
91 91
     public function hasEntries(): bool
92 92
     {
93
-        return !empty($this->entries());
93
+        return !empty( $this->entries() );
94 94
     }
95 95
 
96 96
     public function id(): string
@@ -105,62 +105,62 @@  discard block
 block discarded – undo
105 105
 
106 106
     public function label(): string
107 107
     {
108
-        $label = __('Hooks', 'blackbar');
109
-        if (class_exists('Debug_Bar_Slow_Actions')) {
108
+        $label = __( 'Hooks', 'blackbar' );
109
+        if( class_exists( 'Debug_Bar_Slow_Actions' ) ) {
110 110
             return $label;
111 111
         }
112 112
         $this->entries(); // calculates the totalTime
113
-        if ($this->totalTime > 0) {
114
-            $label = sprintf('%s (<span class="glbb-actions-time">%.2f</span> %s)', $label, $this->totalTime, __('ms', 'blackbar'));
113
+        if( $this->totalTime > 0 ) {
114
+            $label = sprintf( '%s (<span class="glbb-actions-time">%.2f</span> %s)', $label, $this->totalTime, __( 'ms', 'blackbar' ) );
115 115
         }
116 116
         return $label;
117 117
     }
118 118
 
119 119
     public function render(): void
120 120
     {
121
-        $this->app->render('panels/actions', ['actions' => $this]);
121
+        $this->app->render( 'panels/actions', [ 'actions' => $this ] );
122 122
     }
123 123
 
124 124
     public function startTimer(): void
125 125
     {
126
-        if (!isset($this->hooks[current_filter()])) {
127
-            $this->hooks[current_filter()] = [
128
-                'callbacks' => [],
126
+        if( !isset( $this->hooks[ current_filter() ] ) ) {
127
+            $this->hooks[ current_filter() ] = [
128
+                'callbacks' => [ ],
129 129
                 'count' => 0,
130
-                'stack' => [],
131
-                'time' => [],
130
+                'stack' => [ ],
131
+                'time' => [ ],
132 132
             ];
133
-            add_action(current_filter(), [$this, 'stopTimer'], 9999); // @phpstan-ignore-line
133
+            add_action( current_filter(), [ $this, 'stopTimer' ], 9999 ); // @phpstan-ignore-line
134 134
         }
135
-        ++$this->hooks[current_filter()]['count'];
136
-        array_push($this->hooks[current_filter()]['stack'], ['start' => microtime(true)]);
135
+        ++$this->hooks[ current_filter() ][ 'count' ];
136
+        array_push( $this->hooks[ current_filter() ][ 'stack' ], [ 'start' => microtime( true ) ] );
137 137
     }
138 138
 
139 139
     /**
140 140
      * @param mixed $filteredValue
141 141
      * @return mixed
142 142
      */
143
-    public function stopTimer($filteredValue = null)
143
+    public function stopTimer( $filteredValue = null )
144 144
     {
145
-        $time = array_pop($this->hooks[current_filter()]['stack']);
146
-        $time['stop'] = microtime(true);
147
-        array_push($this->hooks[current_filter()]['time'], $time);
145
+        $time = array_pop( $this->hooks[ current_filter() ][ 'stack' ] );
146
+        $time[ 'stop' ] = microtime( true );
147
+        array_push( $this->hooks[ current_filter() ][ 'time' ], $time );
148 148
         return $filteredValue; // In case this was a filter.
149 149
     }
150 150
 
151
-    public function totalTimeForHook(array $data): float
151
+    public function totalTimeForHook( array $data ): float
152 152
     {
153 153
         $total = 0;
154
-        foreach ($data['time'] as $time) {
155
-            $total += ($time['stop'] - $time['start']) * 1000;
154
+        foreach( $data[ 'time' ] as $time ) {
155
+            $total += ( $time[ 'stop' ] - $time[ 'start' ] ) * 1000;
156 156
         }
157 157
         return (float) $total;
158 158
     }
159 159
 
160
-    protected function sortByTime(array $a, array $b): int
160
+    protected function sortByTime( array $a, array $b ): int
161 161
     {
162
-        if ($a['total'] !== $b['total']) {
163
-            return ($a['total'] > $b['total']) ? -1 : 1;
162
+        if( $a[ 'total' ] !== $b[ 'total' ] ) {
163
+            return ( $a[ 'total' ] > $b[ 'total' ] ) ? -1 : 1;
164 164
         }
165 165
         return 0;
166 166
     }
Please login to merge, or discard this patch.
views/panels/queries.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,28 +1,28 @@
 block discarded – undo
1
-<?php defined('WPINC') || die; ?>
1
+<?php defined( 'WPINC' ) || die; ?>
2 2
 
3
-<?php if (!defined('SAVEQUERIES') || !SAVEQUERIES) : ?>
3
+<?php if( !defined( 'SAVEQUERIES' ) || !SAVEQUERIES ) : ?>
4 4
     <table>
5 5
         <tbody>
6 6
             <tr>
7
-                <td><a href="https://wordpress.org/documentation/article/debugging-in-wordpress/#savequeries">SAVEQUERIES</a> <?= _x('must be enabled to view SQL queries', 'SAVEQUERIES', 'blackbar'); ?>.</td>
7
+                <td><a href="https://wordpress.org/documentation/article/debugging-in-wordpress/#savequeries">SAVEQUERIES</a> <?= _x( 'must be enabled to view SQL queries', 'SAVEQUERIES', 'blackbar' ); ?>.</td>
8 8
             </tr>
9 9
         </tbody>
10 10
     </table>
11 11
 <?php else : ?>
12 12
     <form method="get" class="glbb-queries-filter">
13
-        <input class="glbb-input" type="text" name="glbb_query_filter" id="glbb_query_filter" placeholder="<?= __('Find Queries Containing', 'blackbar'); ?>">
14
-        <input class="glbb-input glbb-input-small" type="text" name="glbb_query_min_time" id="glbb_query_min_time" placeholder="<?= __('Minimum Execution Time', 'blackbar'); ?>">
13
+        <input class="glbb-input" type="text" name="glbb_query_filter" id="glbb_query_filter" placeholder="<?= __( 'Find Queries Containing', 'blackbar' ); ?>">
14
+        <input class="glbb-input glbb-input-small" type="text" name="glbb_query_min_time" id="glbb_query_min_time" placeholder="<?= __( 'Minimum Execution Time', 'blackbar' ); ?>">
15 15
         <select class="glbb-input" name="glbb_query_sort" id="glbb_query_sort">
16
-            <option value><?= __('Sort by execution order', 'blackbar'); ?></option>
17
-            <option value="time"><?= __('Sort by execution time', 'blackbar'); ?></option>
16
+            <option value><?= __( 'Sort by execution order', 'blackbar' ); ?></option>
17
+            <option value="time"><?= __( 'Sort by execution time', 'blackbar' ); ?></option>
18 18
         </select>
19 19
     </form>
20 20
     <table class="glbb-queries-table">
21 21
         <tbody>
22
-            <?php foreach ($queries->entries() as $index => $entry) : ?>
23
-                <tr data-index="<?= esc_attr($index); ?>" data-time="<?= esc_attr($entry['time']); ?>">
24
-                    <td class="glbb-small"><?= esc_html($entry['time']); ?></td>
25
-                    <td><pre><code class="language-sql"><?= esc_html($entry['sql']); ?></code></pre></td>
22
+            <?php foreach( $queries->entries() as $index => $entry ) : ?>
23
+                <tr data-index="<?= esc_attr( $index ); ?>" data-time="<?= esc_attr( $entry[ 'time' ] ); ?>">
24
+                    <td class="glbb-small"><?= esc_html( $entry[ 'time' ] ); ?></td>
25
+                    <td><pre><code class="language-sql"><?= esc_html( $entry[ 'sql' ] ); ?></code></pre></td>
26 26
                 </tr>
27 27
             <?php endforeach; ?>
28 28
         </tbody>
Please login to merge, or discard this patch.