@@ -4,74 +4,74 @@ |
||
4 | 4 | |
5 | 5 | class Queries extends Module |
6 | 6 | { |
7 | - public function entries(): array |
|
8 | - { |
|
9 | - global $wpdb; |
|
10 | - $entries = []; |
|
11 | - $index = 0; |
|
12 | - $search = [ |
|
13 | - 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT', |
|
14 | - 'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE', |
|
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); |
|
28 | - } |
|
29 | - if (str_starts_with($part, 'WHERE')) { |
|
30 | - $part = str_replace('AND', PHP_EOL.' AND', $part); |
|
31 | - } |
|
32 | - return $carry.$part.PHP_EOL; |
|
33 | - }); |
|
34 | - $trace = explode(', ', $query[2]); |
|
35 | - $nanoseconds = (int) round($query[1] * 1e9); |
|
36 | - $entries[] = [ |
|
37 | - 'index' => $index++, |
|
38 | - 'sql' => $sql, |
|
39 | - 'time' => $nanoseconds, |
|
40 | - 'time_formatted' => $this->formatTime($nanoseconds), |
|
41 | - 'trace' => array_reverse($trace, true), |
|
42 | - ]; |
|
43 | - } |
|
44 | - uasort($entries, [$this, 'sortByTime']); |
|
45 | - return $entries; |
|
46 | - } |
|
7 | + public function entries(): array |
|
8 | + { |
|
9 | + global $wpdb; |
|
10 | + $entries = []; |
|
11 | + $index = 0; |
|
12 | + $search = [ |
|
13 | + 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT', |
|
14 | + 'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE', |
|
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); |
|
28 | + } |
|
29 | + if (str_starts_with($part, 'WHERE')) { |
|
30 | + $part = str_replace('AND', PHP_EOL.' AND', $part); |
|
31 | + } |
|
32 | + return $carry.$part.PHP_EOL; |
|
33 | + }); |
|
34 | + $trace = explode(', ', $query[2]); |
|
35 | + $nanoseconds = (int) round($query[1] * 1e9); |
|
36 | + $entries[] = [ |
|
37 | + 'index' => $index++, |
|
38 | + 'sql' => $sql, |
|
39 | + 'time' => $nanoseconds, |
|
40 | + 'time_formatted' => $this->formatTime($nanoseconds), |
|
41 | + 'trace' => array_reverse($trace, true), |
|
42 | + ]; |
|
43 | + } |
|
44 | + uasort($entries, [$this, 'sortByTime']); |
|
45 | + return $entries; |
|
46 | + } |
|
47 | 47 | |
48 | - public function hasEntries(): bool |
|
49 | - { |
|
50 | - global $wpdb; |
|
51 | - return !empty($wpdb->queries); |
|
52 | - } |
|
48 | + public function hasEntries(): bool |
|
49 | + { |
|
50 | + global $wpdb; |
|
51 | + return !empty($wpdb->queries); |
|
52 | + } |
|
53 | 53 | |
54 | - public function info(): string |
|
55 | - { |
|
56 | - if (!defined('SAVEQUERIES') || !SAVEQUERIES) { |
|
57 | - return ''; |
|
58 | - } |
|
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); |
|
63 | - } |
|
54 | + public function info(): string |
|
55 | + { |
|
56 | + if (!defined('SAVEQUERIES') || !SAVEQUERIES) { |
|
57 | + return ''; |
|
58 | + } |
|
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); |
|
63 | + } |
|
64 | 64 | |
65 | - public function label(): string |
|
66 | - { |
|
67 | - return __('SQL', 'blackbar'); |
|
68 | - } |
|
65 | + public function label(): string |
|
66 | + { |
|
67 | + return __('SQL', 'blackbar'); |
|
68 | + } |
|
69 | 69 | |
70 | - protected function sortByTime(array $a, array $b): int |
|
71 | - { |
|
72 | - if ($a['time'] !== $b['time']) { |
|
73 | - return ($a['time'] > $b['time']) ? -1 : 1; |
|
74 | - } |
|
75 | - return 0; |
|
76 | - } |
|
70 | + protected function sortByTime(array $a, array $b): int |
|
71 | + { |
|
72 | + if ($a['time'] !== $b['time']) { |
|
73 | + return ($a['time'] > $b['time']) ? -1 : 1; |
|
74 | + } |
|
75 | + return 0; |
|
76 | + } |
|
77 | 77 | } |
@@ -7,70 +7,70 @@ |
||
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 | } |
@@ -13,7 +13,8 @@ discard block |
||
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) { |
|
16 | + $replace = array_map(function ($value) |
|
17 | + { |
|
17 | 18 | return PHP_EOL.$value; |
18 | 19 | }, $search); |
19 | 20 | foreach ($wpdb->queries as $query) { |
@@ -22,7 +23,8 @@ discard block |
||
22 | 23 | $sql = str_replace(['( ', ' )', ' ,'], ['(', ')', ','], $sql); |
23 | 24 | $sql = str_replace($search, $replace, $sql); |
24 | 25 | $parts = explode(PHP_EOL, $sql); |
25 | - $sql = array_reduce($parts, function ($carry, $part) { |
|
26 | + $sql = array_reduce($parts, function ($carry, $part) |
|
27 | + { |
|
26 | 28 | if (str_starts_with($part, 'SELECT') && strlen($part) > 100) { |
27 | 29 | $part = preg_replace('/\s*(,)\s*/', ','.PHP_EOL.' ', $part); |
28 | 30 | } |