@@ -4,91 +4,91 @@ |
||
4 | 4 | |
5 | 5 | class Profiler extends Module |
6 | 6 | { |
7 | - /** |
|
8 | - * @var int |
|
9 | - */ |
|
10 | - protected $memory_start = 0; |
|
11 | - /** |
|
12 | - * @var int |
|
13 | - */ |
|
14 | - protected $memory_stop = 0; |
|
15 | - /** |
|
16 | - * The profiler noise to remove from the timer (in nanoseconds). |
|
17 | - * @var int |
|
18 | - */ |
|
19 | - protected $noise = 0; |
|
20 | - /** |
|
21 | - * The hrtime the profiler started measuring (in nanoseconds). |
|
22 | - * @var int |
|
23 | - */ |
|
24 | - protected $start = 0; |
|
25 | - /** |
|
26 | - * The hrtime the profiler stopped measuring (in nanoseconds). |
|
27 | - * @var int |
|
28 | - */ |
|
29 | - protected $stop = 0; |
|
30 | - /** |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - protected $timer = []; |
|
7 | + /** |
|
8 | + * @var int |
|
9 | + */ |
|
10 | + protected $memory_start = 0; |
|
11 | + /** |
|
12 | + * @var int |
|
13 | + */ |
|
14 | + protected $memory_stop = 0; |
|
15 | + /** |
|
16 | + * The profiler noise to remove from the timer (in nanoseconds). |
|
17 | + * @var int |
|
18 | + */ |
|
19 | + protected $noise = 0; |
|
20 | + /** |
|
21 | + * The hrtime the profiler started measuring (in nanoseconds). |
|
22 | + * @var int |
|
23 | + */ |
|
24 | + protected $start = 0; |
|
25 | + /** |
|
26 | + * The hrtime the profiler stopped measuring (in nanoseconds). |
|
27 | + * @var int |
|
28 | + */ |
|
29 | + protected $stop = 0; |
|
30 | + /** |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + protected $timer = []; |
|
34 | 34 | |
35 | - public function entries(): array |
|
36 | - { |
|
37 | - $entries = []; |
|
38 | - foreach ($this->entries as $entry) { |
|
39 | - $entry['time'] = $this->formatTime($entry['time']); |
|
40 | - $entries[] = $entry; |
|
41 | - } |
|
42 | - return $entries; |
|
43 | - } |
|
35 | + public function entries(): array |
|
36 | + { |
|
37 | + $entries = []; |
|
38 | + foreach ($this->entries as $entry) { |
|
39 | + $entry['time'] = $this->formatTime($entry['time']); |
|
40 | + $entries[] = $entry; |
|
41 | + } |
|
42 | + return $entries; |
|
43 | + } |
|
44 | 44 | |
45 | - public function isVisible(): bool |
|
46 | - { |
|
47 | - return $this->hasEntries(); |
|
48 | - } |
|
45 | + public function isVisible(): bool |
|
46 | + { |
|
47 | + return $this->hasEntries(); |
|
48 | + } |
|
49 | 49 | |
50 | - public function label(): string |
|
51 | - { |
|
52 | - return __('Profiler', 'blackbar'); |
|
53 | - } |
|
50 | + public function label(): string |
|
51 | + { |
|
52 | + return __('Profiler', 'blackbar'); |
|
53 | + } |
|
54 | 54 | |
55 | - public function setNoise(int $nanoseconds): void |
|
56 | - { |
|
57 | - $this->noise = $nanoseconds - $this->start; |
|
58 | - } |
|
55 | + public function setNoise(int $nanoseconds): void |
|
56 | + { |
|
57 | + $this->noise = $nanoseconds - $this->start; |
|
58 | + } |
|
59 | 59 | |
60 | - public function setStart(int $nanoseconds): void |
|
61 | - { |
|
62 | - $this->start = $nanoseconds; |
|
63 | - $this->memory_start = memory_get_peak_usage(); |
|
64 | - } |
|
60 | + public function setStart(int $nanoseconds): void |
|
61 | + { |
|
62 | + $this->start = $nanoseconds; |
|
63 | + $this->memory_start = memory_get_peak_usage(); |
|
64 | + } |
|
65 | 65 | |
66 | - public function setStop(int $nanoseconds): void |
|
67 | - { |
|
68 | - $this->stop = $nanoseconds; |
|
69 | - $this->memory_stop = memory_get_peak_usage(); |
|
70 | - } |
|
66 | + public function setStop(int $nanoseconds): void |
|
67 | + { |
|
68 | + $this->stop = $nanoseconds; |
|
69 | + $this->memory_stop = memory_get_peak_usage(); |
|
70 | + } |
|
71 | 71 | |
72 | - public function start(string $name): void |
|
73 | - { |
|
74 | - $this->timer = [ |
|
75 | - 'memory' => memory_get_peak_usage(), |
|
76 | - 'name' => $name, |
|
77 | - 'start' => (int) hrtime(true), |
|
78 | - 'stop' => 0, |
|
79 | - 'time' => 0, |
|
80 | - ]; |
|
81 | - } |
|
72 | + public function start(string $name): void |
|
73 | + { |
|
74 | + $this->timer = [ |
|
75 | + 'memory' => memory_get_peak_usage(), |
|
76 | + 'name' => $name, |
|
77 | + 'start' => (int) hrtime(true), |
|
78 | + 'stop' => 0, |
|
79 | + 'time' => 0, |
|
80 | + ]; |
|
81 | + } |
|
82 | 82 | |
83 | - public function stop(): void |
|
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 |
|
92 | - } |
|
93 | - } |
|
83 | + public function stop(): void |
|
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 |
|
92 | + } |
|
93 | + } |
|
94 | 94 | } |
@@ -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,13 +82,13 @@ 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 | } |
@@ -4,142 +4,142 @@ |
||
4 | 4 | |
5 | 5 | class Hooks extends Module |
6 | 6 | { |
7 | - /** |
|
8 | - * @var array |
|
9 | - */ |
|
10 | - protected $hooks = []; |
|
11 | - /** |
|
12 | - * @var int |
|
13 | - */ |
|
14 | - protected $totalHooks = 0; |
|
15 | - /** |
|
16 | - * Total elapsed time in nanoseconds |
|
17 | - * @var int |
|
18 | - */ |
|
19 | - protected $totalTime = 0; |
|
7 | + /** |
|
8 | + * @var array |
|
9 | + */ |
|
10 | + protected $hooks = []; |
|
11 | + /** |
|
12 | + * @var int |
|
13 | + */ |
|
14 | + protected $totalHooks = 0; |
|
15 | + /** |
|
16 | + * Total elapsed time in nanoseconds |
|
17 | + * @var int |
|
18 | + */ |
|
19 | + protected $totalTime = 0; |
|
20 | 20 | |
21 | - public function entries(): array |
|
22 | - { |
|
23 | - if (!$this->hasEntries()) { |
|
24 | - return []; |
|
25 | - } |
|
26 | - if (!empty($this->hooks)) { |
|
27 | - return $this->hooks; |
|
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); |
|
35 | - }); |
|
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; |
|
45 | - } |
|
46 | - return $this->hooks; |
|
47 | - } |
|
21 | + public function entries(): array |
|
22 | + { |
|
23 | + if (!$this->hasEntries()) { |
|
24 | + return []; |
|
25 | + } |
|
26 | + if (!empty($this->hooks)) { |
|
27 | + return $this->hooks; |
|
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); |
|
35 | + }); |
|
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; |
|
45 | + } |
|
46 | + return $this->hooks; |
|
47 | + } |
|
48 | 48 | |
49 | - public function info(): string |
|
50 | - { |
|
51 | - $this->entries(); // calculate the totalTime |
|
52 | - return $this->formatTime($this->totalTime); |
|
53 | - } |
|
49 | + public function info(): string |
|
50 | + { |
|
51 | + $this->entries(); // calculate the totalTime |
|
52 | + return $this->formatTime($this->totalTime); |
|
53 | + } |
|
54 | 54 | |
55 | - public function label(): string |
|
56 | - { |
|
57 | - return __('Hooks', 'blackbar'); |
|
58 | - } |
|
55 | + public function label(): string |
|
56 | + { |
|
57 | + return __('Hooks', 'blackbar'); |
|
58 | + } |
|
59 | 59 | |
60 | - public function startTimer(): void |
|
61 | - { |
|
62 | - if (class_exists('Debug_Bar_Slow_Actions')) { |
|
63 | - return; |
|
64 | - } |
|
65 | - $hook = current_filter(); |
|
66 | - if (!isset($this->entries[$hook])) { |
|
67 | - $callbacks = $this->callbacksForHook($hook); |
|
68 | - if (empty($callbacks)) { |
|
69 | - return; // We skipped Blackbar callbacks |
|
70 | - } |
|
71 | - $this->entries[$hook] = [ |
|
72 | - 'callbacks' => $callbacks, |
|
73 | - 'callbacks_count' => count(array_merge(...$callbacks)), |
|
74 | - 'count' => 0, |
|
75 | - 'stack' => [], |
|
76 | - 'time' => [], |
|
77 | - ]; |
|
78 | - add_action($hook, [$this, 'stopTimer'], 9999); // @phpstan-ignore-line |
|
79 | - } |
|
80 | - ++$this->entries[$hook]['count']; |
|
81 | - array_push($this->entries[$hook]['stack'], ['start' => (int) hrtime(true)]); |
|
82 | - } |
|
60 | + public function startTimer(): void |
|
61 | + { |
|
62 | + if (class_exists('Debug_Bar_Slow_Actions')) { |
|
63 | + return; |
|
64 | + } |
|
65 | + $hook = current_filter(); |
|
66 | + if (!isset($this->entries[$hook])) { |
|
67 | + $callbacks = $this->callbacksForHook($hook); |
|
68 | + if (empty($callbacks)) { |
|
69 | + return; // We skipped Blackbar callbacks |
|
70 | + } |
|
71 | + $this->entries[$hook] = [ |
|
72 | + 'callbacks' => $callbacks, |
|
73 | + 'callbacks_count' => count(array_merge(...$callbacks)), |
|
74 | + 'count' => 0, |
|
75 | + 'stack' => [], |
|
76 | + 'time' => [], |
|
77 | + ]; |
|
78 | + add_action($hook, [$this, 'stopTimer'], 9999); // @phpstan-ignore-line |
|
79 | + } |
|
80 | + ++$this->entries[$hook]['count']; |
|
81 | + array_push($this->entries[$hook]['stack'], ['start' => (int) hrtime(true)]); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * @param mixed $filteredValue |
|
86 | - * @return mixed |
|
87 | - */ |
|
88 | - public function stopTimer($filteredValue = null) |
|
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); |
|
93 | - return $filteredValue; // In case this was a filter. |
|
94 | - } |
|
84 | + /** |
|
85 | + * @param mixed $filteredValue |
|
86 | + * @return mixed |
|
87 | + */ |
|
88 | + public function stopTimer($filteredValue = null) |
|
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); |
|
93 | + return $filteredValue; // In case this was a filter. |
|
94 | + } |
|
95 | 95 | |
96 | - protected function callbacksForHook(string $hook): array |
|
97 | - { |
|
98 | - global $wp_filter; |
|
99 | - $results = []; |
|
100 | - if (!isset($wp_filter[$hook])) { |
|
101 | - return $results; |
|
102 | - } |
|
103 | - foreach ($wp_filter[$hook] as $priority => $callbacks) { |
|
104 | - $results[$priority] = $results[$priority] ?? []; |
|
105 | - foreach ($callbacks as $callback) { |
|
106 | - if (is_array($callback['function']) && 2 === count($callback['function'])) { |
|
107 | - list($object, $method) = $callback['function']; |
|
108 | - if (is_object($object)) { |
|
109 | - $object = get_class($object); |
|
110 | - $reflection = new \ReflectionClass($object); |
|
111 | - if (str_starts_with($reflection->getNamespaceName(), 'GeminiLabs\BlackBar')) { |
|
112 | - continue; // skip Blackbar callbacks |
|
113 | - } |
|
114 | - } |
|
115 | - $results[$priority][] = sprintf('%s::%s', $object, $method); |
|
116 | - } elseif (is_object($callback['function'])) { |
|
117 | - $results[$priority][] = get_class($callback['function']); |
|
118 | - } else { |
|
119 | - $results[$priority][] = $callback['function']; |
|
120 | - } |
|
121 | - } |
|
122 | - } |
|
123 | - return $results; |
|
124 | - } |
|
96 | + protected function callbacksForHook(string $hook): array |
|
97 | + { |
|
98 | + global $wp_filter; |
|
99 | + $results = []; |
|
100 | + if (!isset($wp_filter[$hook])) { |
|
101 | + return $results; |
|
102 | + } |
|
103 | + foreach ($wp_filter[$hook] as $priority => $callbacks) { |
|
104 | + $results[$priority] = $results[$priority] ?? []; |
|
105 | + foreach ($callbacks as $callback) { |
|
106 | + if (is_array($callback['function']) && 2 === count($callback['function'])) { |
|
107 | + list($object, $method) = $callback['function']; |
|
108 | + if (is_object($object)) { |
|
109 | + $object = get_class($object); |
|
110 | + $reflection = new \ReflectionClass($object); |
|
111 | + if (str_starts_with($reflection->getNamespaceName(), 'GeminiLabs\BlackBar')) { |
|
112 | + continue; // skip Blackbar callbacks |
|
113 | + } |
|
114 | + } |
|
115 | + $results[$priority][] = sprintf('%s::%s', $object, $method); |
|
116 | + } elseif (is_object($callback['function'])) { |
|
117 | + $results[$priority][] = get_class($callback['function']); |
|
118 | + } else { |
|
119 | + $results[$priority][] = $callback['function']; |
|
120 | + } |
|
121 | + } |
|
122 | + } |
|
123 | + return $results; |
|
124 | + } |
|
125 | 125 | |
126 | - protected function sortByTime(array $a, array $b): int |
|
127 | - { |
|
128 | - if ($a['total'] !== $b['total']) { |
|
129 | - return ($a['total'] > $b['total']) ? -1 : 1; |
|
130 | - } |
|
131 | - return 0; |
|
132 | - } |
|
126 | + protected function sortByTime(array $a, array $b): int |
|
127 | + { |
|
128 | + if ($a['total'] !== $b['total']) { |
|
129 | + return ($a['total'] > $b['total']) ? -1 : 1; |
|
130 | + } |
|
131 | + return 0; |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * Total elapsed time in nanoseconds |
|
136 | - */ |
|
137 | - protected function totalTimeForHook(array $data): int |
|
138 | - { |
|
139 | - $total = 0; |
|
140 | - foreach ($data['time'] as $time) { |
|
141 | - $total += ($time['stop'] - $time['start']); |
|
142 | - } |
|
143 | - return $total; |
|
144 | - } |
|
134 | + /** |
|
135 | + * Total elapsed time in nanoseconds |
|
136 | + */ |
|
137 | + protected function totalTimeForHook(array $data): int |
|
138 | + { |
|
139 | + $total = 0; |
|
140 | + foreach ($data['time'] as $time) { |
|
141 | + $total += ($time['stop'] - $time['start']); |
|
142 | + } |
|
143 | + return $total; |
|
144 | + } |
|
145 | 145 | } |
@@ -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 | */ |
@@ -20,28 +20,28 @@ discard block |
||
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,84 +49,84 @@ discard block |
||
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 | - protected function callbacksForHook(string $hook): array |
|
96 | + protected function callbacksForHook( string $hook ): array |
|
97 | 97 | { |
98 | 98 | global $wp_filter; |
99 | - $results = []; |
|
100 | - if (!isset($wp_filter[$hook])) { |
|
99 | + $results = [ ]; |
|
100 | + if( !isset( $wp_filter[ $hook ] ) ) { |
|
101 | 101 | return $results; |
102 | 102 | } |
103 | - foreach ($wp_filter[$hook] as $priority => $callbacks) { |
|
104 | - $results[$priority] = $results[$priority] ?? []; |
|
105 | - foreach ($callbacks as $callback) { |
|
106 | - if (is_array($callback['function']) && 2 === count($callback['function'])) { |
|
107 | - list($object, $method) = $callback['function']; |
|
108 | - if (is_object($object)) { |
|
109 | - $object = get_class($object); |
|
110 | - $reflection = new \ReflectionClass($object); |
|
111 | - if (str_starts_with($reflection->getNamespaceName(), 'GeminiLabs\BlackBar')) { |
|
103 | + foreach( $wp_filter[ $hook ] as $priority => $callbacks ) { |
|
104 | + $results[ $priority ] = $results[ $priority ] ?? [ ]; |
|
105 | + foreach( $callbacks as $callback ) { |
|
106 | + if( is_array( $callback[ 'function' ] ) && 2 === count( $callback[ 'function' ] ) ) { |
|
107 | + list( $object, $method ) = $callback[ 'function' ]; |
|
108 | + if( is_object( $object ) ) { |
|
109 | + $object = get_class( $object ); |
|
110 | + $reflection = new \ReflectionClass( $object ); |
|
111 | + if( str_starts_with( $reflection->getNamespaceName(), 'GeminiLabs\BlackBar' ) ) { |
|
112 | 112 | continue; // skip Blackbar callbacks |
113 | 113 | } |
114 | 114 | } |
115 | - $results[$priority][] = sprintf('%s::%s', $object, $method); |
|
116 | - } elseif (is_object($callback['function'])) { |
|
117 | - $results[$priority][] = get_class($callback['function']); |
|
115 | + $results[ $priority ][ ] = sprintf( '%s::%s', $object, $method ); |
|
116 | + } elseif( is_object( $callback[ 'function' ] ) ) { |
|
117 | + $results[ $priority ][ ] = get_class( $callback[ 'function' ] ); |
|
118 | 118 | } else { |
119 | - $results[$priority][] = $callback['function']; |
|
119 | + $results[ $priority ][ ] = $callback[ 'function' ]; |
|
120 | 120 | } |
121 | 121 | } |
122 | 122 | } |
123 | 123 | return $results; |
124 | 124 | } |
125 | 125 | |
126 | - protected function sortByTime(array $a, array $b): int |
|
126 | + protected function sortByTime( array $a, array $b ): int |
|
127 | 127 | { |
128 | - if ($a['total'] !== $b['total']) { |
|
129 | - return ($a['total'] > $b['total']) ? -1 : 1; |
|
128 | + if( $a[ 'total' ] !== $b[ 'total' ] ) { |
|
129 | + return ( $a[ 'total' ] > $b[ 'total' ] ) ? -1 : 1; |
|
130 | 130 | } |
131 | 131 | return 0; |
132 | 132 | } |
@@ -134,11 +134,11 @@ discard block |
||
134 | 134 | /** |
135 | 135 | * Total elapsed time in nanoseconds |
136 | 136 | */ |
137 | - protected function totalTimeForHook(array $data): int |
|
137 | + protected function totalTimeForHook( array $data ): int |
|
138 | 138 | { |
139 | 139 | $total = 0; |
140 | - foreach ($data['time'] as $time) { |
|
141 | - $total += ($time['stop'] - $time['start']); |
|
140 | + foreach( $data[ 'time' ] as $time ) { |
|
141 | + $total += ( $time[ 'stop' ] - $time[ 'start' ] ); |
|
142 | 142 | } |
143 | 143 | return $total; |
144 | 144 | } |
@@ -26,7 +26,8 @@ discard block |
||
26 | 26 | if (!empty($this->hooks)) { |
27 | 27 | return $this->hooks; |
28 | 28 | } |
29 | - array_walk($this->entries, function (&$data) { |
|
29 | + array_walk($this->entries, function (&$data) |
|
30 | + { |
|
30 | 31 | $total = $this->totalTimeForHook($data); |
31 | 32 | $perCall = (int) round($total / $data['count']); |
32 | 33 | $data['per_call'] = $this->formatTime($perCall); |
@@ -113,9 +114,11 @@ discard block |
||
113 | 114 | } |
114 | 115 | } |
115 | 116 | $results[$priority][] = sprintf('%s::%s', $object, $method); |
116 | - } elseif (is_object($callback['function'])) { |
|
117 | + } |
|
118 | + elseif (is_object($callback['function'])) { |
|
117 | 119 | $results[$priority][] = get_class($callback['function']); |
118 | - } else { |
|
120 | + } |
|
121 | + else { |
|
119 | 122 | $results[$priority][] = $callback['function']; |
120 | 123 | } |
121 | 124 | } |
@@ -7,112 +7,112 @@ |
||
7 | 7 | |
8 | 8 | class Console extends Module |
9 | 9 | { |
10 | - public const ERROR_CODES = [ |
|
11 | - E_ERROR => 'error', // 1 |
|
12 | - E_WARNING => 'warning', // 2 |
|
13 | - E_NOTICE => 'notice', // 8 |
|
14 | - E_STRICT => 'strict', // 2048 |
|
15 | - E_DEPRECATED => 'deprecated', // 8192 |
|
16 | - ]; |
|
10 | + public const ERROR_CODES = [ |
|
11 | + E_ERROR => 'error', // 1 |
|
12 | + E_WARNING => 'warning', // 2 |
|
13 | + E_NOTICE => 'notice', // 8 |
|
14 | + E_STRICT => 'strict', // 2048 |
|
15 | + E_DEPRECATED => 'deprecated', // 8192 |
|
16 | + ]; |
|
17 | 17 | |
18 | - public const MAPPED_ERROR_CODES = [ |
|
19 | - 'debug' => 0, |
|
20 | - 'info' => E_NOTICE, |
|
21 | - 'deprecated' => E_DEPRECATED, // 8192 |
|
22 | - 'error' => E_ERROR, // 1 |
|
23 | - 'notice' => E_NOTICE, // 8 |
|
24 | - 'strict' => E_STRICT, // 2048 |
|
25 | - 'warning' => E_WARNING, // 2 |
|
26 | - 'critical' => E_ERROR, // 1 |
|
27 | - 'alert' => E_ERROR, // 1 |
|
28 | - 'emergency' => E_ERROR, // 1 |
|
29 | - ]; |
|
18 | + public const MAPPED_ERROR_CODES = [ |
|
19 | + 'debug' => 0, |
|
20 | + 'info' => E_NOTICE, |
|
21 | + 'deprecated' => E_DEPRECATED, // 8192 |
|
22 | + 'error' => E_ERROR, // 1 |
|
23 | + 'notice' => E_NOTICE, // 8 |
|
24 | + 'strict' => E_STRICT, // 2048 |
|
25 | + 'warning' => E_WARNING, // 2 |
|
26 | + 'critical' => E_ERROR, // 1 |
|
27 | + 'alert' => E_ERROR, // 1 |
|
28 | + 'emergency' => E_ERROR, // 1 |
|
29 | + ]; |
|
30 | 30 | |
31 | - public function classes(): string |
|
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()); |
|
36 | - } |
|
37 | - if (in_array(E_WARNING, $errno)) { |
|
38 | - return sprintf('%s glbb-warning', $this->id()); |
|
39 | - } |
|
40 | - return $this->id(); |
|
41 | - } |
|
31 | + public function classes(): string |
|
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()); |
|
36 | + } |
|
37 | + if (in_array(E_WARNING, $errno)) { |
|
38 | + return sprintf('%s glbb-warning', $this->id()); |
|
39 | + } |
|
40 | + return $this->id(); |
|
41 | + } |
|
42 | 42 | |
43 | - public function entries(): array |
|
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']); |
|
50 | - } |
|
51 | - $entries[] = $entry; |
|
52 | - } |
|
53 | - return $entries; |
|
54 | - } |
|
43 | + public function entries(): array |
|
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']); |
|
50 | + } |
|
51 | + $entries[] = $entry; |
|
52 | + } |
|
53 | + return $entries; |
|
54 | + } |
|
55 | 55 | |
56 | - public function info(): string |
|
57 | - { |
|
58 | - $counts = array_count_values(wp_list_pluck($this->entries, 'errno')); |
|
59 | - $entryCount = count($this->entries); |
|
60 | - if (!empty($counts[E_ERROR])) { |
|
61 | - return sprintf('%d, %d!', $entryCount, $counts[E_ERROR]); |
|
62 | - } |
|
63 | - if ($entryCount > 0) { |
|
64 | - return (string) $entryCount; |
|
65 | - } |
|
66 | - return ''; |
|
67 | - } |
|
56 | + public function info(): string |
|
57 | + { |
|
58 | + $counts = array_count_values(wp_list_pluck($this->entries, 'errno')); |
|
59 | + $entryCount = count($this->entries); |
|
60 | + if (!empty($counts[E_ERROR])) { |
|
61 | + return sprintf('%d, %d!', $entryCount, $counts[E_ERROR]); |
|
62 | + } |
|
63 | + if ($entryCount > 0) { |
|
64 | + return (string) $entryCount; |
|
65 | + } |
|
66 | + return ''; |
|
67 | + } |
|
68 | 68 | |
69 | - public function label(): string |
|
70 | - { |
|
71 | - return __('Console', 'blackbar'); |
|
72 | - } |
|
69 | + public function label(): string |
|
70 | + { |
|
71 | + return __('Console', 'blackbar'); |
|
72 | + } |
|
73 | 73 | |
74 | - public function store(string $message, string $errno = '', string $location = ''): void |
|
75 | - { |
|
76 | - if (is_numeric($errno)) { // entry likely stored by set_error_handler() |
|
77 | - $errname = 'Unknown'; |
|
78 | - if (array_key_exists((int) $errno, static::ERROR_CODES)) { |
|
79 | - $errname = static::ERROR_CODES[$errno]; |
|
80 | - } |
|
81 | - } else { // entry likely stored by filter hook |
|
82 | - $errname = 'Debug'; |
|
83 | - if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { |
|
84 | - $errname = $errno; |
|
85 | - $errno = static::MAPPED_ERROR_CODES[$errno]; |
|
86 | - } |
|
87 | - } |
|
88 | - $errname = strtolower($errname); |
|
89 | - $hash = md5($errno.$errname.$message.$location); |
|
90 | - if (array_key_exists($hash, $this->entries)) { |
|
91 | - ++$this->entries[$hash]['count']; |
|
92 | - } else { |
|
93 | - $this->entries[$hash] = [ |
|
94 | - 'count' => 0, |
|
95 | - 'errname' => $errname, |
|
96 | - 'errno' => (int) $errno, |
|
97 | - 'message' => $this->normalizeMessage($message, $location), |
|
98 | - ]; |
|
99 | - }; |
|
100 | - } |
|
74 | + public function store(string $message, string $errno = '', string $location = ''): void |
|
75 | + { |
|
76 | + if (is_numeric($errno)) { // entry likely stored by set_error_handler() |
|
77 | + $errname = 'Unknown'; |
|
78 | + if (array_key_exists((int) $errno, static::ERROR_CODES)) { |
|
79 | + $errname = static::ERROR_CODES[$errno]; |
|
80 | + } |
|
81 | + } else { // entry likely stored by filter hook |
|
82 | + $errname = 'Debug'; |
|
83 | + if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { |
|
84 | + $errname = $errno; |
|
85 | + $errno = static::MAPPED_ERROR_CODES[$errno]; |
|
86 | + } |
|
87 | + } |
|
88 | + $errname = strtolower($errname); |
|
89 | + $hash = md5($errno.$errname.$message.$location); |
|
90 | + if (array_key_exists($hash, $this->entries)) { |
|
91 | + ++$this->entries[$hash]['count']; |
|
92 | + } else { |
|
93 | + $this->entries[$hash] = [ |
|
94 | + 'count' => 0, |
|
95 | + 'errname' => $errname, |
|
96 | + 'errno' => (int) $errno, |
|
97 | + 'message' => $this->normalizeMessage($message, $location), |
|
98 | + ]; |
|
99 | + }; |
|
100 | + } |
|
101 | 101 | |
102 | - protected function normalizeMessage($message, string $location): string |
|
103 | - { |
|
104 | - if ($message instanceof \DateTime) { |
|
105 | - $message = $message->format('Y-m-d H:i:s'); |
|
106 | - } elseif (is_object($message) || is_array($message)) { |
|
107 | - $message = (new Dump())->dump($message); |
|
108 | - } else { |
|
109 | - $message = esc_html(trim((string) $message)); |
|
110 | - } |
|
111 | - $location = trim($location); |
|
112 | - if (!empty($location)) { |
|
113 | - $location = str_replace([WP_CONTENT_DIR, ABSPATH], '', $location); |
|
114 | - $location = sprintf('[%s]', $location); |
|
115 | - } |
|
116 | - return trim(sprintf('%s %s', $location, $message)); |
|
117 | - } |
|
102 | + protected function normalizeMessage($message, string $location): string |
|
103 | + { |
|
104 | + if ($message instanceof \DateTime) { |
|
105 | + $message = $message->format('Y-m-d H:i:s'); |
|
106 | + } elseif (is_object($message) || is_array($message)) { |
|
107 | + $message = (new Dump())->dump($message); |
|
108 | + } else { |
|
109 | + $message = esc_html(trim((string) $message)); |
|
110 | + } |
|
111 | + $location = trim($location); |
|
112 | + if (!empty($location)) { |
|
113 | + $location = str_replace([WP_CONTENT_DIR, ABSPATH], '', $location); |
|
114 | + $location = sprintf('[%s]', $location); |
|
115 | + } |
|
116 | + return trim(sprintf('%s %s', $location, $message)); |
|
117 | + } |
|
118 | 118 | } |
@@ -30,37 +30,37 @@ discard block |
||
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 info(): string |
57 | 57 | { |
58 | - $counts = array_count_values(wp_list_pluck($this->entries, 'errno')); |
|
59 | - $entryCount = count($this->entries); |
|
60 | - if (!empty($counts[E_ERROR])) { |
|
61 | - return sprintf('%d, %d!', $entryCount, $counts[E_ERROR]); |
|
58 | + $counts = array_count_values( wp_list_pluck( $this->entries, 'errno' ) ); |
|
59 | + $entryCount = count( $this->entries ); |
|
60 | + if( !empty( $counts[ E_ERROR ] ) ) { |
|
61 | + return sprintf( '%d, %d!', $entryCount, $counts[ E_ERROR ] ); |
|
62 | 62 | } |
63 | - if ($entryCount > 0) { |
|
63 | + if( $entryCount > 0 ) { |
|
64 | 64 | return (string) $entryCount; |
65 | 65 | } |
66 | 66 | return ''; |
@@ -68,51 +68,51 @@ discard block |
||
68 | 68 | |
69 | 69 | public function label(): string |
70 | 70 | { |
71 | - return __('Console', 'blackbar'); |
|
71 | + return __( 'Console', 'blackbar' ); |
|
72 | 72 | } |
73 | 73 | |
74 | - public function store(string $message, string $errno = '', string $location = ''): void |
|
74 | + public function store( string $message, string $errno = '', string $location = '' ): void |
|
75 | 75 | { |
76 | - if (is_numeric($errno)) { // entry likely stored by set_error_handler() |
|
76 | + if( is_numeric( $errno ) ) { // entry likely stored by set_error_handler() |
|
77 | 77 | $errname = 'Unknown'; |
78 | - if (array_key_exists((int) $errno, static::ERROR_CODES)) { |
|
79 | - $errname = static::ERROR_CODES[$errno]; |
|
78 | + if( array_key_exists( (int) $errno, static::ERROR_CODES ) ) { |
|
79 | + $errname = static::ERROR_CODES[ $errno ]; |
|
80 | 80 | } |
81 | 81 | } else { // entry likely stored by filter hook |
82 | 82 | $errname = 'Debug'; |
83 | - if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { |
|
83 | + if( array_key_exists( $errno, static::MAPPED_ERROR_CODES ) ) { |
|
84 | 84 | $errname = $errno; |
85 | - $errno = static::MAPPED_ERROR_CODES[$errno]; |
|
85 | + $errno = static::MAPPED_ERROR_CODES[ $errno ]; |
|
86 | 86 | } |
87 | 87 | } |
88 | - $errname = strtolower($errname); |
|
89 | - $hash = md5($errno.$errname.$message.$location); |
|
90 | - if (array_key_exists($hash, $this->entries)) { |
|
91 | - ++$this->entries[$hash]['count']; |
|
88 | + $errname = strtolower( $errname ); |
|
89 | + $hash = md5( $errno . $errname . $message . $location ); |
|
90 | + if( array_key_exists( $hash, $this->entries ) ) { |
|
91 | + ++$this->entries[ $hash ][ 'count' ]; |
|
92 | 92 | } else { |
93 | - $this->entries[$hash] = [ |
|
93 | + $this->entries[ $hash ] = [ |
|
94 | 94 | 'count' => 0, |
95 | 95 | 'errname' => $errname, |
96 | 96 | 'errno' => (int) $errno, |
97 | - 'message' => $this->normalizeMessage($message, $location), |
|
97 | + 'message' => $this->normalizeMessage( $message, $location ), |
|
98 | 98 | ]; |
99 | 99 | }; |
100 | 100 | } |
101 | 101 | |
102 | - protected function normalizeMessage($message, string $location): string |
|
102 | + protected function normalizeMessage( $message, string $location ): string |
|
103 | 103 | { |
104 | - if ($message instanceof \DateTime) { |
|
105 | - $message = $message->format('Y-m-d H:i:s'); |
|
106 | - } elseif (is_object($message) || is_array($message)) { |
|
107 | - $message = (new Dump())->dump($message); |
|
104 | + if( $message instanceof \DateTime ) { |
|
105 | + $message = $message->format( 'Y-m-d H:i:s' ); |
|
106 | + } elseif( is_object( $message ) || is_array( $message ) ) { |
|
107 | + $message = ( new Dump() )->dump( $message ); |
|
108 | 108 | } else { |
109 | - $message = esc_html(trim((string) $message)); |
|
109 | + $message = esc_html( trim( (string) $message ) ); |
|
110 | 110 | } |
111 | - $location = trim($location); |
|
112 | - if (!empty($location)) { |
|
113 | - $location = str_replace([WP_CONTENT_DIR, ABSPATH], '', $location); |
|
114 | - $location = sprintf('[%s]', $location); |
|
111 | + $location = trim( $location ); |
|
112 | + if( !empty( $location ) ) { |
|
113 | + $location = str_replace( [ WP_CONTENT_DIR, ABSPATH ], '', $location ); |
|
114 | + $location = sprintf( '[%s]', $location ); |
|
115 | 115 | } |
116 | - return trim(sprintf('%s %s', $location, $message)); |
|
116 | + return trim( sprintf( '%s %s', $location, $message ) ); |
|
117 | 117 | } |
118 | 118 | } |
@@ -6,74 +6,74 @@ |
||
6 | 6 | |
7 | 7 | class Queries extends Module |
8 | 8 | { |
9 | - public function entries(): array |
|
10 | - { |
|
11 | - global $wpdb; |
|
12 | - $entries = []; |
|
13 | - $index = 0; |
|
14 | - $search = [ |
|
15 | - 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT', |
|
16 | - 'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE', |
|
17 | - ]; |
|
18 | - $replace = array_map(function ($value) { |
|
19 | - return PHP_EOL.$value; |
|
20 | - }, $search); |
|
21 | - foreach ($wpdb->queries as $query) { |
|
22 | - $sql = preg_replace('/\s\s+/', ' ', trim($query[0])); |
|
23 | - $sql = str_replace(PHP_EOL, ' ', $sql); |
|
24 | - $sql = str_replace(['( ',' )',' ,'], ['(',')',','], $sql); |
|
25 | - $sql = str_replace($search, $replace, $sql); |
|
26 | - $parts = explode(PHP_EOL, $sql); |
|
27 | - $sql = array_reduce($parts, function ($carry, $part) { |
|
28 | - if (str_starts_with($part, 'SELECT') && strlen($part) > 100) { |
|
29 | - $part = preg_replace('/\s*(,)\s*/', ','.PHP_EOL.' ', $part); |
|
30 | - } |
|
31 | - if (str_starts_with($part, 'WHERE')) { |
|
32 | - $part = str_replace('AND', PHP_EOL.' AND', $part); |
|
33 | - } |
|
34 | - return $carry.$part.PHP_EOL; |
|
35 | - }); |
|
36 | - $trace = explode(', ', $query[2]); |
|
37 | - $nanoseconds = (int) round($query[1] * 1e9); |
|
38 | - $entries[] = [ |
|
39 | - 'index' => $index++, |
|
40 | - 'sql' => $sql, |
|
41 | - 'time' => $nanoseconds, |
|
42 | - 'time_formatted' => $this->formatTime($nanoseconds), |
|
43 | - 'trace' => array_reverse($trace, true), |
|
44 | - ]; |
|
45 | - } |
|
46 | - uasort($entries, [$this, 'sortByTime']); |
|
47 | - return $entries; |
|
48 | - } |
|
9 | + public function entries(): array |
|
10 | + { |
|
11 | + global $wpdb; |
|
12 | + $entries = []; |
|
13 | + $index = 0; |
|
14 | + $search = [ |
|
15 | + 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT', |
|
16 | + 'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE', |
|
17 | + ]; |
|
18 | + $replace = array_map(function ($value) { |
|
19 | + return PHP_EOL.$value; |
|
20 | + }, $search); |
|
21 | + foreach ($wpdb->queries as $query) { |
|
22 | + $sql = preg_replace('/\s\s+/', ' ', trim($query[0])); |
|
23 | + $sql = str_replace(PHP_EOL, ' ', $sql); |
|
24 | + $sql = str_replace(['( ',' )',' ,'], ['(',')',','], $sql); |
|
25 | + $sql = str_replace($search, $replace, $sql); |
|
26 | + $parts = explode(PHP_EOL, $sql); |
|
27 | + $sql = array_reduce($parts, function ($carry, $part) { |
|
28 | + if (str_starts_with($part, 'SELECT') && strlen($part) > 100) { |
|
29 | + $part = preg_replace('/\s*(,)\s*/', ','.PHP_EOL.' ', $part); |
|
30 | + } |
|
31 | + if (str_starts_with($part, 'WHERE')) { |
|
32 | + $part = str_replace('AND', PHP_EOL.' AND', $part); |
|
33 | + } |
|
34 | + return $carry.$part.PHP_EOL; |
|
35 | + }); |
|
36 | + $trace = explode(', ', $query[2]); |
|
37 | + $nanoseconds = (int) round($query[1] * 1e9); |
|
38 | + $entries[] = [ |
|
39 | + 'index' => $index++, |
|
40 | + 'sql' => $sql, |
|
41 | + 'time' => $nanoseconds, |
|
42 | + 'time_formatted' => $this->formatTime($nanoseconds), |
|
43 | + 'trace' => array_reverse($trace, true), |
|
44 | + ]; |
|
45 | + } |
|
46 | + uasort($entries, [$this, 'sortByTime']); |
|
47 | + return $entries; |
|
48 | + } |
|
49 | 49 | |
50 | - public function hasEntries(): bool |
|
51 | - { |
|
52 | - global $wpdb; |
|
53 | - return !empty($wpdb->queries); |
|
54 | - } |
|
50 | + public function hasEntries(): bool |
|
51 | + { |
|
52 | + global $wpdb; |
|
53 | + return !empty($wpdb->queries); |
|
54 | + } |
|
55 | 55 | |
56 | - public function info(): string |
|
57 | - { |
|
58 | - if (!defined('SAVEQUERIES') || !SAVEQUERIES) { |
|
59 | - return ''; |
|
60 | - } |
|
61 | - global $wpdb; |
|
62 | - $seconds = (float) array_sum(wp_list_pluck($wpdb->queries, 1)); |
|
63 | - $nanoseconds = (int) round($seconds * 1e9); |
|
64 | - return $this->formatTime($nanoseconds); |
|
65 | - } |
|
56 | + public function info(): string |
|
57 | + { |
|
58 | + if (!defined('SAVEQUERIES') || !SAVEQUERIES) { |
|
59 | + return ''; |
|
60 | + } |
|
61 | + global $wpdb; |
|
62 | + $seconds = (float) array_sum(wp_list_pluck($wpdb->queries, 1)); |
|
63 | + $nanoseconds = (int) round($seconds * 1e9); |
|
64 | + return $this->formatTime($nanoseconds); |
|
65 | + } |
|
66 | 66 | |
67 | - public function label(): string |
|
68 | - { |
|
69 | - return __('SQL', 'blackbar'); |
|
70 | - } |
|
67 | + public function label(): string |
|
68 | + { |
|
69 | + return __('SQL', 'blackbar'); |
|
70 | + } |
|
71 | 71 | |
72 | - protected function sortByTime(array $a, array $b): int |
|
73 | - { |
|
74 | - if ($a['time'] !== $b['time']) { |
|
75 | - return ($a['time'] > $b['time']) ? -1 : 1; |
|
76 | - } |
|
77 | - return 0; |
|
78 | - } |
|
72 | + protected function sortByTime(array $a, array $b): int |
|
73 | + { |
|
74 | + if ($a['time'] !== $b['time']) { |
|
75 | + return ($a['time'] > $b['time']) ? -1 : 1; |
|
76 | + } |
|
77 | + return 0; |
|
78 | + } |
|
79 | 79 | } |
@@ -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 | - $sql = preg_replace('/\s\s+/', ' ', trim($query[0])); |
|
23 | - $sql = str_replace(PHP_EOL, ' ', $sql); |
|
24 | - $sql = str_replace(['( ',' )',' ,'], ['(',')',','], $sql); |
|
25 | - $sql = str_replace($search, $replace, $sql); |
|
26 | - $parts = explode(PHP_EOL, $sql); |
|
27 | - $sql = array_reduce($parts, function ($carry, $part) { |
|
28 | - if (str_starts_with($part, 'SELECT') && strlen($part) > 100) { |
|
29 | - $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 | + $sql = preg_replace( '/\s\s+/', ' ', trim( $query[ 0 ] ) ); |
|
23 | + $sql = str_replace( PHP_EOL, ' ', $sql ); |
|
24 | + $sql = str_replace( [ '( ', ' )', ' ,' ], [ '(', ')', ',' ], $sql ); |
|
25 | + $sql = str_replace( $search, $replace, $sql ); |
|
26 | + $parts = explode( PHP_EOL, $sql ); |
|
27 | + $sql = array_reduce( $parts, function( $carry, $part ) { |
|
28 | + if( str_starts_with( $part, 'SELECT' ) && strlen( $part ) > 100 ) { |
|
29 | + $part = preg_replace( '/\s*(,)\s*/', ',' . PHP_EOL . ' ', $part ); |
|
30 | 30 | } |
31 | - if (str_starts_with($part, 'WHERE')) { |
|
32 | - $part = str_replace('AND', PHP_EOL.' AND', $part); |
|
31 | + if( str_starts_with( $part, 'WHERE' ) ) { |
|
32 | + $part = str_replace( 'AND', PHP_EOL . ' AND', $part ); |
|
33 | 33 | } |
34 | - return $carry.$part.PHP_EOL; |
|
34 | + return $carry . $part . PHP_EOL; |
|
35 | 35 | }); |
36 | - $trace = explode(', ', $query[2]); |
|
37 | - $nanoseconds = (int) round($query[1] * 1e9); |
|
38 | - $entries[] = [ |
|
36 | + $trace = explode( ', ', $query[ 2 ] ); |
|
37 | + $nanoseconds = (int) round( $query[ 1 ] * 1e9 ); |
|
38 | + $entries[ ] = [ |
|
39 | 39 | 'index' => $index++, |
40 | 40 | 'sql' => $sql, |
41 | 41 | 'time' => $nanoseconds, |
42 | - 'time_formatted' => $this->formatTime($nanoseconds), |
|
43 | - 'trace' => array_reverse($trace, true), |
|
42 | + 'time_formatted' => $this->formatTime( $nanoseconds ), |
|
43 | + 'trace' => array_reverse( $trace, true ), |
|
44 | 44 | ]; |
45 | 45 | } |
46 | - uasort($entries, [$this, 'sortByTime']); |
|
46 | + uasort( $entries, [ $this, 'sortByTime' ] ); |
|
47 | 47 | return $entries; |
48 | 48 | } |
49 | 49 | |
50 | 50 | public function hasEntries(): bool |
51 | 51 | { |
52 | 52 | global $wpdb; |
53 | - return !empty($wpdb->queries); |
|
53 | + return !empty( $wpdb->queries ); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | public function info(): string |
57 | 57 | { |
58 | - if (!defined('SAVEQUERIES') || !SAVEQUERIES) { |
|
58 | + if( !defined( 'SAVEQUERIES' ) || !SAVEQUERIES ) { |
|
59 | 59 | return ''; |
60 | 60 | } |
61 | 61 | global $wpdb; |
62 | - $seconds = (float) array_sum(wp_list_pluck($wpdb->queries, 1)); |
|
63 | - $nanoseconds = (int) round($seconds * 1e9); |
|
64 | - return $this->formatTime($nanoseconds); |
|
62 | + $seconds = (float) array_sum( wp_list_pluck( $wpdb->queries, 1 ) ); |
|
63 | + $nanoseconds = (int) round( $seconds * 1e9 ); |
|
64 | + return $this->formatTime( $nanoseconds ); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | public function label(): string |
68 | 68 | { |
69 | - return __('SQL', 'blackbar'); |
|
69 | + return __( 'SQL', 'blackbar' ); |
|
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 | } |
@@ -6,80 +6,80 @@ |
||
6 | 6 | |
7 | 7 | abstract class Module |
8 | 8 | { |
9 | - /** |
|
10 | - * @var Application |
|
11 | - */ |
|
12 | - protected $app; |
|
13 | - /** |
|
14 | - * @var array |
|
15 | - */ |
|
16 | - protected $entries; |
|
9 | + /** |
|
10 | + * @var Application |
|
11 | + */ |
|
12 | + protected $app; |
|
13 | + /** |
|
14 | + * @var array |
|
15 | + */ |
|
16 | + protected $entries; |
|
17 | 17 | |
18 | - public function __construct(Application $app) |
|
19 | - { |
|
20 | - $this->app = $app; |
|
21 | - $this->entries = []; |
|
22 | - } |
|
18 | + public function __construct(Application $app) |
|
19 | + { |
|
20 | + $this->app = $app; |
|
21 | + $this->entries = []; |
|
22 | + } |
|
23 | 23 | |
24 | - public function classes(): string |
|
25 | - { |
|
26 | - return $this->id(); |
|
27 | - } |
|
24 | + public function classes(): string |
|
25 | + { |
|
26 | + return $this->id(); |
|
27 | + } |
|
28 | 28 | |
29 | - abstract public function entries(): array; |
|
29 | + abstract public function entries(): array; |
|
30 | 30 | |
31 | - public function hasEntries(): bool |
|
32 | - { |
|
33 | - return !empty($this->entries); |
|
34 | - } |
|
31 | + public function hasEntries(): bool |
|
32 | + { |
|
33 | + return !empty($this->entries); |
|
34 | + } |
|
35 | 35 | |
36 | - public function id(): string |
|
37 | - { |
|
38 | - return sprintf('glbb-%s', $this->slug()); |
|
39 | - } |
|
36 | + public function id(): string |
|
37 | + { |
|
38 | + return sprintf('glbb-%s', $this->slug()); |
|
39 | + } |
|
40 | 40 | |
41 | - public function info(): string |
|
42 | - { |
|
43 | - return ''; |
|
44 | - } |
|
41 | + public function info(): string |
|
42 | + { |
|
43 | + return ''; |
|
44 | + } |
|
45 | 45 | |
46 | - public function isVisible(): bool |
|
47 | - { |
|
48 | - return true; |
|
49 | - } |
|
46 | + public function isVisible(): bool |
|
47 | + { |
|
48 | + return true; |
|
49 | + } |
|
50 | 50 | |
51 | - abstract public function label(): string; |
|
51 | + abstract public function label(): string; |
|
52 | 52 | |
53 | - public function render(): void |
|
54 | - { |
|
55 | - $this->app->render('panels/'.$this->slug(), ['module' => $this]); |
|
56 | - } |
|
53 | + public function render(): void |
|
54 | + { |
|
55 | + $this->app->render('panels/'.$this->slug(), ['module' => $this]); |
|
56 | + } |
|
57 | 57 | |
58 | - public function slug(): string |
|
59 | - { |
|
60 | - return strtolower((new \ReflectionClass($this))->getShortName()); |
|
61 | - } |
|
58 | + public function slug(): string |
|
59 | + { |
|
60 | + return strtolower((new \ReflectionClass($this))->getShortName()); |
|
61 | + } |
|
62 | 62 | |
63 | - protected function formatTime(int $nanoseconds): string |
|
64 | - { |
|
65 | - if ($nanoseconds >= 1e9) { |
|
66 | - return sprintf('%s s', $this->toDecimal(round($nanoseconds / 1e9, 2))); |
|
67 | - } |
|
68 | - if ($nanoseconds >= 1e6) { |
|
69 | - return sprintf('%s ms', $this->toDecimal(round($nanoseconds / 1e6, 2))); |
|
70 | - } |
|
71 | - if ($nanoseconds >= 1e3) { |
|
72 | - return sprintf('%s µs', round($nanoseconds / 1e3)); |
|
73 | - } |
|
74 | - return sprintf('%s ns', $nanoseconds); |
|
75 | - } |
|
63 | + protected function formatTime(int $nanoseconds): string |
|
64 | + { |
|
65 | + if ($nanoseconds >= 1e9) { |
|
66 | + return sprintf('%s s', $this->toDecimal(round($nanoseconds / 1e9, 2))); |
|
67 | + } |
|
68 | + if ($nanoseconds >= 1e6) { |
|
69 | + return sprintf('%s ms', $this->toDecimal(round($nanoseconds / 1e6, 2))); |
|
70 | + } |
|
71 | + if ($nanoseconds >= 1e3) { |
|
72 | + return sprintf('%s µs', round($nanoseconds / 1e3)); |
|
73 | + } |
|
74 | + return sprintf('%s ns', $nanoseconds); |
|
75 | + } |
|
76 | 76 | |
77 | - protected function toDecimal(float $number): string |
|
78 | - { |
|
79 | - $number = (string) $number; |
|
80 | - if (false !== strpos($number, '.')) { |
|
81 | - $number = rtrim(rtrim($number, '0'), '.'); |
|
82 | - } |
|
83 | - return $number; |
|
84 | - } |
|
77 | + protected function toDecimal(float $number): string |
|
78 | + { |
|
79 | + $number = (string) $number; |
|
80 | + if (false !== strpos($number, '.')) { |
|
81 | + $number = rtrim(rtrim($number, '0'), '.'); |
|
82 | + } |
|
83 | + return $number; |
|
84 | + } |
|
85 | 85 | } |
@@ -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 info(): string |
@@ -52,33 +52,33 @@ discard block |
||
52 | 52 | |
53 | 53 | public function render(): void |
54 | 54 | { |
55 | - $this->app->render('panels/'.$this->slug(), ['module' => $this]); |
|
55 | + $this->app->render( 'panels/' . $this->slug(), [ 'module' => $this ] ); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | public function slug(): string |
59 | 59 | { |
60 | - return strtolower((new \ReflectionClass($this))->getShortName()); |
|
60 | + return strtolower( ( new \ReflectionClass( $this ) )->getShortName() ); |
|
61 | 61 | } |
62 | 62 | |
63 | - protected function formatTime(int $nanoseconds): string |
|
63 | + protected function formatTime( int $nanoseconds ): string |
|
64 | 64 | { |
65 | - if ($nanoseconds >= 1e9) { |
|
66 | - return sprintf('%s s', $this->toDecimal(round($nanoseconds / 1e9, 2))); |
|
65 | + if( $nanoseconds >= 1e9 ) { |
|
66 | + return sprintf( '%s s', $this->toDecimal( round( $nanoseconds / 1e9, 2 ) ) ); |
|
67 | 67 | } |
68 | - if ($nanoseconds >= 1e6) { |
|
69 | - return sprintf('%s ms', $this->toDecimal(round($nanoseconds / 1e6, 2))); |
|
68 | + if( $nanoseconds >= 1e6 ) { |
|
69 | + return sprintf( '%s ms', $this->toDecimal( round( $nanoseconds / 1e6, 2 ) ) ); |
|
70 | 70 | } |
71 | - if ($nanoseconds >= 1e3) { |
|
72 | - return sprintf('%s µs', round($nanoseconds / 1e3)); |
|
71 | + if( $nanoseconds >= 1e3 ) { |
|
72 | + return sprintf( '%s µs', round( $nanoseconds / 1e3 ) ); |
|
73 | 73 | } |
74 | - return sprintf('%s ns', $nanoseconds); |
|
74 | + return sprintf( '%s ns', $nanoseconds ); |
|
75 | 75 | } |
76 | 76 | |
77 | - protected function toDecimal(float $number): string |
|
77 | + protected function toDecimal( float $number ): string |
|
78 | 78 | { |
79 | 79 | $number = (string) $number; |
80 | - if (false !== strpos($number, '.')) { |
|
81 | - $number = rtrim(rtrim($number, '0'), '.'); |
|
80 | + if( false !== strpos( $number, '.' ) ) { |
|
81 | + $number = rtrim( rtrim( $number, '0' ), '.' ); |
|
82 | 82 | } |
83 | 83 | return $number; |
84 | 84 | } |
@@ -1,32 +1,32 @@ |
||
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" target="_blank">SAVEQUERIES</a> <?= esc_html_x('must be enabled to view SQL queries', 'SAVEQUERIES', 'blackbar'); ?>.</td> |
|
7 | + <td><a href="https://wordpress.org/documentation/article/debugging-in-wordpress/#savequeries" target="_blank">SAVEQUERIES</a> <?= esc_html_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> |
13 | - <input type="text" id="glbb_queries_sql" placeholder="<?= esc_attr__('Find SQL containing', 'blackbar'); ?>"> |
|
14 | - <input type="text" id="glbb_queries_min_time" placeholder="<?= esc_attr__('Minimum execution time', 'blackbar'); ?>"> |
|
13 | + <input type="text" id="glbb_queries_sql" placeholder="<?= esc_attr__( 'Find SQL containing', 'blackbar' ); ?>"> |
|
14 | + <input type="text" id="glbb_queries_min_time" placeholder="<?= esc_attr__( 'Minimum execution time', 'blackbar' ); ?>"> |
|
15 | 15 | <select id="glbb_queries_sort_by"> |
16 | - <option value><?= esc_html__('Sort by execution time', 'blackbar'); ?></option> |
|
17 | - <option value="order"><?= esc_html__('Sort by execution order', 'blackbar'); ?></option> |
|
16 | + <option value><?= esc_html__( 'Sort by execution 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 | <tbody> |
22 | - <?php foreach ($module->entries() as $entry) : ?> |
|
23 | - <tr class="glbb-row-collapsed" data-index="<?= esc_attr($entry['index']); ?>" data-time="<?= esc_attr($entry['time']); ?>"> |
|
24 | - <td data-time="<?= esc_attr($entry['time_formatted']); ?>"><div class="glbb-row-toggle dashicons-before dashicons-arrow-right"><?= esc_html($entry['time_formatted']); ?></div></td> |
|
25 | - <td data-sql><pre><code class="language-sql"><?= esc_html($entry['sql']); ?></code></pre></td> |
|
22 | + <?php foreach( $module->entries() as $entry ) : ?> |
|
23 | + <tr class="glbb-row-collapsed" data-index="<?= esc_attr( $entry[ 'index' ] ); ?>" data-time="<?= esc_attr( $entry[ 'time' ] ); ?>"> |
|
24 | + <td data-time="<?= esc_attr( $entry[ 'time_formatted' ] ); ?>"><div class="glbb-row-toggle dashicons-before dashicons-arrow-right"><?= esc_html( $entry[ 'time_formatted' ] ); ?></div></td> |
|
25 | + <td data-sql><pre><code class="language-sql"><?= esc_html( $entry[ 'sql' ] ); ?></code></pre></td> |
|
26 | 26 | <td class="glbb-row-details"> |
27 | 27 | <ol> |
28 | - <?php foreach ($entry['trace'] as $index => $line) : ?> |
|
29 | - <li value="<?= esc_attr($index + 1); ?>"><?= esc_html($line); ?></li> |
|
28 | + <?php foreach( $entry[ 'trace' ] as $index => $line ) : ?> |
|
29 | + <li value="<?= esc_attr( $index + 1 ); ?>"><?= esc_html( $line ); ?></li> |
|
30 | 30 | <?php endforeach; ?> |
31 | 31 | </ol> |
32 | 32 | </td> |
@@ -1,45 +1,45 @@ |
||
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> |
@@ -1,14 +1,14 @@ discard block |
||
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 |
||
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> |
@@ -2,13 +2,19 @@ discard block |
||
2 | 2 | |
3 | 3 | <div id="glbb"> |
4 | 4 | <?php foreach ($modules as $module) : /* Ensure that the console entries are loaded last */ ?> |
5 | - <?php if (!$module->isVisible() || 'glbb-console' === $module->id()) continue; ?> |
|
5 | + <?php if (!$module->isVisible() || 'glbb-console' === $module->id()) { |
|
6 | + continue; |
|
7 | +} |
|
8 | +?> |
|
6 | 9 | <div id="<?= $module->id(); ?>" class="glbb-panel glbb-hidden"> |
7 | 10 | <?php $module->render(); ?> |
8 | 11 | </div> |
9 | 12 | <?php endforeach; ?> |
10 | 13 | <?php foreach ($modules as $module) : /* Ensure that the console entries are loaded last */ ?> |
11 | - <?php if (!$module->isVisible() || 'glbb-console' !== $module->id()) continue; ?> |
|
14 | + <?php if (!$module->isVisible() || 'glbb-console' !== $module->id()) { |
|
15 | + continue; |
|
16 | +} |
|
17 | +?> |
|
12 | 18 | <div id="<?= $module->id(); ?>" class="glbb-panel glbb-hidden"> |
13 | 19 | <?php $module->render(); ?> |
14 | 20 | </div> |
@@ -20,7 +26,10 @@ discard block |
||
20 | 26 | </span> |
21 | 27 | </a> |
22 | 28 | <?php foreach ($modules as $module) : ?> |
23 | - <?php if (!$module->isVisible()) continue; ?> |
|
29 | + <?php if (!$module->isVisible()) { |
|
30 | + continue; |
|
31 | +} |
|
32 | +?> |
|
24 | 33 | <a href="#" data-panel="<?= esc_attr($module->id()); ?>" data-info="<?= esc_attr($module->info()); ?>" class="dashicons-before <?= $module->classes(); ?>"> |
25 | 34 | <span><?= $module->label(); ?></span> |
26 | 35 | </a> |