@@ -8,141 +8,141 @@ |
||
8 | 8 | */ |
9 | 9 | class GL_Plugin_Check_v6 |
10 | 10 | { |
11 | - const MIN_PHP_VERSION = '7.2'; |
|
12 | - const MIN_WORDPRESS_VERSION = '5.8'; |
|
11 | + const MIN_PHP_VERSION = '7.2'; |
|
12 | + const MIN_WORDPRESS_VERSION = '5.8'; |
|
13 | 13 | |
14 | - /** |
|
15 | - * @var array |
|
16 | - */ |
|
17 | - public $versions; |
|
14 | + /** |
|
15 | + * @var array |
|
16 | + */ |
|
17 | + public $versions; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $file; |
|
19 | + /** |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $file; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @param string $file |
|
26 | - */ |
|
27 | - public function __construct($file) |
|
28 | - { |
|
29 | - $this->file = realpath($file); |
|
30 | - $versionRequirements = get_file_data($this->file, [ |
|
31 | - 'php' => 'Requires PHP', |
|
32 | - 'wordpress' => 'Requires at least', |
|
33 | - ]); |
|
34 | - $this->versions = wp_parse_args(array_filter($versionRequirements), [ |
|
35 | - 'php' => static::MIN_PHP_VERSION, |
|
36 | - 'wordpress' => static::MIN_WORDPRESS_VERSION, |
|
37 | - ]); |
|
38 | - } |
|
24 | + /** |
|
25 | + * @param string $file |
|
26 | + */ |
|
27 | + public function __construct($file) |
|
28 | + { |
|
29 | + $this->file = realpath($file); |
|
30 | + $versionRequirements = get_file_data($this->file, [ |
|
31 | + 'php' => 'Requires PHP', |
|
32 | + 'wordpress' => 'Requires at least', |
|
33 | + ]); |
|
34 | + $this->versions = wp_parse_args(array_filter($versionRequirements), [ |
|
35 | + 'php' => static::MIN_PHP_VERSION, |
|
36 | + 'wordpress' => static::MIN_WORDPRESS_VERSION, |
|
37 | + ]); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return bool |
|
42 | - */ |
|
43 | - public function canProceed() |
|
44 | - { |
|
45 | - if ($this->isValid()) { |
|
46 | - return true; |
|
47 | - } |
|
48 | - add_action('activated_plugin', [$this, 'deactivate']); |
|
49 | - add_action('admin_notices', [$this, 'deactivate']); |
|
50 | - return false; |
|
51 | - } |
|
40 | + /** |
|
41 | + * @return bool |
|
42 | + */ |
|
43 | + public function canProceed() |
|
44 | + { |
|
45 | + if ($this->isValid()) { |
|
46 | + return true; |
|
47 | + } |
|
48 | + add_action('activated_plugin', [$this, 'deactivate']); |
|
49 | + add_action('admin_notices', [$this, 'deactivate']); |
|
50 | + return false; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @return bool |
|
55 | - */ |
|
56 | - public function isPhpValid() |
|
57 | - { |
|
58 | - return version_compare(PHP_VERSION, $this->versions['php'], '>='); |
|
59 | - } |
|
53 | + /** |
|
54 | + * @return bool |
|
55 | + */ |
|
56 | + public function isPhpValid() |
|
57 | + { |
|
58 | + return version_compare(PHP_VERSION, $this->versions['php'], '>='); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @return bool |
|
63 | - */ |
|
64 | - public function isValid() |
|
65 | - { |
|
66 | - return $this->isPhpValid() && $this->isWpValid(); |
|
67 | - } |
|
61 | + /** |
|
62 | + * @return bool |
|
63 | + */ |
|
64 | + public function isValid() |
|
65 | + { |
|
66 | + return $this->isPhpValid() && $this->isWpValid(); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @return bool |
|
71 | - */ |
|
72 | - public function isWpValid() |
|
73 | - { |
|
74 | - global $wp_version; |
|
75 | - return version_compare($wp_version, $this->versions['wordpress'], '>='); |
|
76 | - } |
|
69 | + /** |
|
70 | + * @return bool |
|
71 | + */ |
|
72 | + public function isWpValid() |
|
73 | + { |
|
74 | + global $wp_version; |
|
75 | + return version_compare($wp_version, $this->versions['wordpress'], '>='); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param string $plugin |
|
80 | - * @return void |
|
81 | - */ |
|
82 | - public function deactivate($plugin) |
|
83 | - { |
|
84 | - if ($this->isValid()) { |
|
85 | - return; |
|
86 | - } |
|
87 | - $pluginSlug = plugin_basename($this->file); |
|
88 | - if ($plugin == $pluginSlug) { |
|
89 | - $this->redirect(); // exit |
|
90 | - } |
|
91 | - $pluginData = get_file_data($this->file, ['name' => 'Plugin Name'], 'plugin'); |
|
92 | - deactivate_plugins($pluginSlug); |
|
93 | - $this->printNotice($pluginData['name']); |
|
94 | - } |
|
78 | + /** |
|
79 | + * @param string $plugin |
|
80 | + * @return void |
|
81 | + */ |
|
82 | + public function deactivate($plugin) |
|
83 | + { |
|
84 | + if ($this->isValid()) { |
|
85 | + return; |
|
86 | + } |
|
87 | + $pluginSlug = plugin_basename($this->file); |
|
88 | + if ($plugin == $pluginSlug) { |
|
89 | + $this->redirect(); // exit |
|
90 | + } |
|
91 | + $pluginData = get_file_data($this->file, ['name' => 'Plugin Name'], 'plugin'); |
|
92 | + deactivate_plugins($pluginSlug); |
|
93 | + $this->printNotice($pluginData['name']); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * @return array |
|
98 | - */ |
|
99 | - protected function getMessages() |
|
100 | - { |
|
101 | - return [ |
|
102 | - 'notice' => _x('The %s plugin was deactivated.', 'admin-text', 'blackbar'), |
|
103 | - 'php_version' => _x('PHP version', 'admin-text', 'blackbar'), |
|
104 | - 'rollback' => _x('You can use the %s plugin to restore %s to the previous version.', 'admin-text', 'blackbar'), |
|
105 | - 'update_php' => _x('Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'admin-text', 'blackbar'), |
|
106 | - 'update_wp' => _x('Update WordPress', 'admin-text', 'blackbar'), |
|
107 | - 'wp_version' => _x('WordPress version', 'admin-text', 'blackbar'), |
|
108 | - 'wrong_version' => _x('This plugin requires %s or greater in order to work properly.', 'admin-text', 'blackbar'), |
|
109 | - ]; |
|
110 | - } |
|
96 | + /** |
|
97 | + * @return array |
|
98 | + */ |
|
99 | + protected function getMessages() |
|
100 | + { |
|
101 | + return [ |
|
102 | + 'notice' => _x('The %s plugin was deactivated.', 'admin-text', 'blackbar'), |
|
103 | + 'php_version' => _x('PHP version', 'admin-text', 'blackbar'), |
|
104 | + 'rollback' => _x('You can use the %s plugin to restore %s to the previous version.', 'admin-text', 'blackbar'), |
|
105 | + 'update_php' => _x('Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'admin-text', 'blackbar'), |
|
106 | + 'update_wp' => _x('Update WordPress', 'admin-text', 'blackbar'), |
|
107 | + 'wp_version' => _x('WordPress version', 'admin-text', 'blackbar'), |
|
108 | + 'wrong_version' => _x('This plugin requires %s or greater in order to work properly.', 'admin-text', 'blackbar'), |
|
109 | + ]; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * @param string $pluginName |
|
114 | - * @return void |
|
115 | - */ |
|
116 | - protected function printNotice($pluginName) |
|
117 | - { |
|
118 | - $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>'; |
|
119 | - $messages = $this->getMessages(); |
|
120 | - $rollbackMessage = sprintf('<strong>'.$messages['rollback'].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/" target="_blank">WP Rollback</a>', $pluginName); |
|
121 | - if (!$this->isPhpValid()) { |
|
122 | - printf($noticeTemplate, |
|
123 | - sprintf($messages['notice'], $pluginName), |
|
124 | - sprintf($messages['wrong_version'], $messages['php_version'].' '.$this->versions['php']), |
|
125 | - sprintf($messages['update_php'], PHP_VERSION).'</p><p>'.$rollbackMessage |
|
126 | - ); |
|
127 | - } elseif (!$this->isWpValid()) { |
|
128 | - printf($noticeTemplate, |
|
129 | - sprintf($messages['notice'], $pluginName), |
|
130 | - sprintf($messages['wrong_version'], $messages['wp_version'].' '.$this->versions['wordpress']), |
|
131 | - $rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages['update_wp']) |
|
132 | - ); |
|
133 | - } |
|
134 | - } |
|
112 | + /** |
|
113 | + * @param string $pluginName |
|
114 | + * @return void |
|
115 | + */ |
|
116 | + protected function printNotice($pluginName) |
|
117 | + { |
|
118 | + $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>'; |
|
119 | + $messages = $this->getMessages(); |
|
120 | + $rollbackMessage = sprintf('<strong>'.$messages['rollback'].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/" target="_blank">WP Rollback</a>', $pluginName); |
|
121 | + if (!$this->isPhpValid()) { |
|
122 | + printf($noticeTemplate, |
|
123 | + sprintf($messages['notice'], $pluginName), |
|
124 | + sprintf($messages['wrong_version'], $messages['php_version'].' '.$this->versions['php']), |
|
125 | + sprintf($messages['update_php'], PHP_VERSION).'</p><p>'.$rollbackMessage |
|
126 | + ); |
|
127 | + } elseif (!$this->isWpValid()) { |
|
128 | + printf($noticeTemplate, |
|
129 | + sprintf($messages['notice'], $pluginName), |
|
130 | + sprintf($messages['wrong_version'], $messages['wp_version'].' '.$this->versions['wordpress']), |
|
131 | + $rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages['update_wp']) |
|
132 | + ); |
|
133 | + } |
|
134 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * @return void |
|
138 | - */ |
|
139 | - protected function redirect() |
|
140 | - { |
|
141 | - wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
142 | - filter_input(INPUT_GET, 'plugin_status'), |
|
143 | - filter_input(INPUT_GET, 'paged'), |
|
144 | - filter_input(INPUT_GET, 's') |
|
145 | - ))); |
|
146 | - exit; |
|
147 | - } |
|
136 | + /** |
|
137 | + * @return void |
|
138 | + */ |
|
139 | + protected function redirect() |
|
140 | + { |
|
141 | + wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
142 | + filter_input(INPUT_GET, 'plugin_status'), |
|
143 | + filter_input(INPUT_GET, 'paged'), |
|
144 | + filter_input(INPUT_GET, 's') |
|
145 | + ))); |
|
146 | + exit; |
|
147 | + } |
|
148 | 148 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -defined('ABSPATH') || exit; |
|
3 | +defined( 'ABSPATH' ) || exit; |
|
4 | 4 | |
5 | 5 | /** |
6 | 6 | * Check for minimum system requirements on plugin activation. |
@@ -24,17 +24,17 @@ discard block |
||
24 | 24 | /** |
25 | 25 | * @param string $file |
26 | 26 | */ |
27 | - public function __construct($file) |
|
27 | + public function __construct( $file ) |
|
28 | 28 | { |
29 | - $this->file = realpath($file); |
|
30 | - $versionRequirements = get_file_data($this->file, [ |
|
29 | + $this->file = realpath( $file ); |
|
30 | + $versionRequirements = get_file_data( $this->file, [ |
|
31 | 31 | 'php' => 'Requires PHP', |
32 | 32 | 'wordpress' => 'Requires at least', |
33 | - ]); |
|
34 | - $this->versions = wp_parse_args(array_filter($versionRequirements), [ |
|
33 | + ] ); |
|
34 | + $this->versions = wp_parse_args( array_filter( $versionRequirements ), [ |
|
35 | 35 | 'php' => static::MIN_PHP_VERSION, |
36 | 36 | 'wordpress' => static::MIN_WORDPRESS_VERSION, |
37 | - ]); |
|
37 | + ] ); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -42,11 +42,11 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function canProceed() |
44 | 44 | { |
45 | - if ($this->isValid()) { |
|
45 | + if( $this->isValid() ) { |
|
46 | 46 | return true; |
47 | 47 | } |
48 | - add_action('activated_plugin', [$this, 'deactivate']); |
|
49 | - add_action('admin_notices', [$this, 'deactivate']); |
|
48 | + add_action( 'activated_plugin', [ $this, 'deactivate' ] ); |
|
49 | + add_action( 'admin_notices', [ $this, 'deactivate' ] ); |
|
50 | 50 | return false; |
51 | 51 | } |
52 | 52 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | */ |
56 | 56 | public function isPhpValid() |
57 | 57 | { |
58 | - return version_compare(PHP_VERSION, $this->versions['php'], '>='); |
|
58 | + return version_compare( PHP_VERSION, $this->versions[ 'php' ], '>=' ); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -72,25 +72,25 @@ discard block |
||
72 | 72 | public function isWpValid() |
73 | 73 | { |
74 | 74 | global $wp_version; |
75 | - return version_compare($wp_version, $this->versions['wordpress'], '>='); |
|
75 | + return version_compare( $wp_version, $this->versions[ 'wordpress' ], '>=' ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * @param string $plugin |
80 | 80 | * @return void |
81 | 81 | */ |
82 | - public function deactivate($plugin) |
|
82 | + public function deactivate( $plugin ) |
|
83 | 83 | { |
84 | - if ($this->isValid()) { |
|
84 | + if( $this->isValid() ) { |
|
85 | 85 | return; |
86 | 86 | } |
87 | - $pluginSlug = plugin_basename($this->file); |
|
88 | - if ($plugin == $pluginSlug) { |
|
87 | + $pluginSlug = plugin_basename( $this->file ); |
|
88 | + if( $plugin == $pluginSlug ) { |
|
89 | 89 | $this->redirect(); // exit |
90 | 90 | } |
91 | - $pluginData = get_file_data($this->file, ['name' => 'Plugin Name'], 'plugin'); |
|
92 | - deactivate_plugins($pluginSlug); |
|
93 | - $this->printNotice($pluginData['name']); |
|
91 | + $pluginData = get_file_data( $this->file, [ 'name' => 'Plugin Name' ], 'plugin' ); |
|
92 | + deactivate_plugins( $pluginSlug ); |
|
93 | + $this->printNotice( $pluginData[ 'name' ] ); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -99,13 +99,13 @@ discard block |
||
99 | 99 | protected function getMessages() |
100 | 100 | { |
101 | 101 | return [ |
102 | - 'notice' => _x('The %s plugin was deactivated.', 'admin-text', 'blackbar'), |
|
103 | - 'php_version' => _x('PHP version', 'admin-text', 'blackbar'), |
|
104 | - 'rollback' => _x('You can use the %s plugin to restore %s to the previous version.', 'admin-text', 'blackbar'), |
|
105 | - 'update_php' => _x('Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'admin-text', 'blackbar'), |
|
106 | - 'update_wp' => _x('Update WordPress', 'admin-text', 'blackbar'), |
|
107 | - 'wp_version' => _x('WordPress version', 'admin-text', 'blackbar'), |
|
108 | - 'wrong_version' => _x('This plugin requires %s or greater in order to work properly.', 'admin-text', 'blackbar'), |
|
102 | + 'notice' => _x( 'The %s plugin was deactivated.', 'admin-text', 'blackbar' ), |
|
103 | + 'php_version' => _x( 'PHP version', 'admin-text', 'blackbar' ), |
|
104 | + 'rollback' => _x( 'You can use the %s plugin to restore %s to the previous version.', 'admin-text', 'blackbar' ), |
|
105 | + 'update_php' => _x( 'Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'admin-text', 'blackbar' ), |
|
106 | + 'update_wp' => _x( 'Update WordPress', 'admin-text', 'blackbar' ), |
|
107 | + 'wp_version' => _x( 'WordPress version', 'admin-text', 'blackbar' ), |
|
108 | + 'wrong_version' => _x( 'This plugin requires %s or greater in order to work properly.', 'admin-text', 'blackbar' ), |
|
109 | 109 | ]; |
110 | 110 | } |
111 | 111 | |
@@ -113,22 +113,22 @@ discard block |
||
113 | 113 | * @param string $pluginName |
114 | 114 | * @return void |
115 | 115 | */ |
116 | - protected function printNotice($pluginName) |
|
116 | + protected function printNotice( $pluginName ) |
|
117 | 117 | { |
118 | 118 | $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>'; |
119 | 119 | $messages = $this->getMessages(); |
120 | - $rollbackMessage = sprintf('<strong>'.$messages['rollback'].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/" target="_blank">WP Rollback</a>', $pluginName); |
|
121 | - if (!$this->isPhpValid()) { |
|
122 | - printf($noticeTemplate, |
|
123 | - sprintf($messages['notice'], $pluginName), |
|
124 | - sprintf($messages['wrong_version'], $messages['php_version'].' '.$this->versions['php']), |
|
125 | - sprintf($messages['update_php'], PHP_VERSION).'</p><p>'.$rollbackMessage |
|
120 | + $rollbackMessage = sprintf( '<strong>' . $messages[ 'rollback' ] . '</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/" target="_blank">WP Rollback</a>', $pluginName ); |
|
121 | + if( !$this->isPhpValid() ) { |
|
122 | + printf( $noticeTemplate, |
|
123 | + sprintf( $messages[ 'notice' ], $pluginName ), |
|
124 | + sprintf( $messages[ 'wrong_version' ], $messages[ 'php_version' ] . ' ' . $this->versions[ 'php' ] ), |
|
125 | + sprintf( $messages[ 'update_php' ], PHP_VERSION ) . '</p><p>' . $rollbackMessage |
|
126 | 126 | ); |
127 | - } elseif (!$this->isWpValid()) { |
|
128 | - printf($noticeTemplate, |
|
129 | - sprintf($messages['notice'], $pluginName), |
|
130 | - sprintf($messages['wrong_version'], $messages['wp_version'].' '.$this->versions['wordpress']), |
|
131 | - $rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages['update_wp']) |
|
127 | + } elseif( !$this->isWpValid() ) { |
|
128 | + printf( $noticeTemplate, |
|
129 | + sprintf( $messages[ 'notice' ], $pluginName ), |
|
130 | + sprintf( $messages[ 'wrong_version' ], $messages[ 'wp_version' ] . ' ' . $this->versions[ 'wordpress' ] ), |
|
131 | + $rollbackMessage . '</p><p>' . sprintf( '<a href="%s">%s</a>', admin_url( 'update-core.php' ), $messages[ 'update_wp' ] ) |
|
132 | 132 | ); |
133 | 133 | } |
134 | 134 | } |
@@ -138,11 +138,11 @@ discard block |
||
138 | 138 | */ |
139 | 139 | protected function redirect() |
140 | 140 | { |
141 | - wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
142 | - filter_input(INPUT_GET, 'plugin_status'), |
|
143 | - filter_input(INPUT_GET, 'paged'), |
|
144 | - filter_input(INPUT_GET, 's') |
|
145 | - ))); |
|
141 | + wp_safe_redirect( self_admin_url( sprintf( 'plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
142 | + filter_input( INPUT_GET, 'plugin_status' ), |
|
143 | + filter_input( INPUT_GET, 'paged' ), |
|
144 | + filter_input( INPUT_GET, 's' ) |
|
145 | + ) ) ); |
|
146 | 146 | exit; |
147 | 147 | } |
148 | 148 | } |
@@ -124,7 +124,8 @@ |
||
124 | 124 | sprintf($messages['wrong_version'], $messages['php_version'].' '.$this->versions['php']), |
125 | 125 | sprintf($messages['update_php'], PHP_VERSION).'</p><p>'.$rollbackMessage |
126 | 126 | ); |
127 | - } elseif (!$this->isWpValid()) { |
|
127 | + } |
|
128 | + elseif (!$this->isWpValid()) { |
|
128 | 129 | printf($noticeTemplate, |
129 | 130 | sprintf($messages['notice'], $pluginName), |
130 | 131 | sprintf($messages['wrong_version'], $messages['wp_version'].' '.$this->versions['wordpress']), |
@@ -4,100 +4,100 @@ |
||
4 | 4 | |
5 | 5 | final class Application |
6 | 6 | { |
7 | - const CONSOLE_HOOK = 'console'; |
|
8 | - const ID = 'blackbar'; |
|
9 | - const PROFILER_HOOK = 'profile'; |
|
7 | + const CONSOLE_HOOK = 'console'; |
|
8 | + const ID = 'blackbar'; |
|
9 | + const PROFILER_HOOK = 'profile'; |
|
10 | 10 | |
11 | - public $actions; |
|
12 | - public $console; |
|
13 | - public $errors = []; |
|
14 | - public $file; |
|
15 | - public $profiler; |
|
11 | + public $actions; |
|
12 | + public $console; |
|
13 | + public $errors = []; |
|
14 | + public $file; |
|
15 | + public $profiler; |
|
16 | 16 | |
17 | - protected static $instance; |
|
17 | + protected static $instance; |
|
18 | 18 | |
19 | - public function __construct() |
|
20 | - { |
|
21 | - $file = wp_normalize_path((new \ReflectionClass($this))->getFileName()); |
|
22 | - $this->actions = new SlowActions(); |
|
23 | - $this->console = new Console(); |
|
24 | - $this->file = str_replace('plugin/Application', static::ID, $file); |
|
25 | - $this->profiler = new Profiler(); |
|
26 | - } |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + $file = wp_normalize_path((new \ReflectionClass($this))->getFileName()); |
|
22 | + $this->actions = new SlowActions(); |
|
23 | + $this->console = new Console(); |
|
24 | + $this->file = str_replace('plugin/Application', static::ID, $file); |
|
25 | + $this->profiler = new Profiler(); |
|
26 | + } |
|
27 | 27 | |
28 | - public function errorHandler(int $errno, string $message, string $file, int $line): void |
|
29 | - { |
|
30 | - $errname = array_key_exists($errno, Console::ERROR_CODES) |
|
31 | - ? Console::ERROR_CODES[$errno] |
|
32 | - : 'Unknown'; |
|
33 | - $hash = md5($errno.$message.$file.$line); |
|
34 | - if (array_key_exists($hash, $this->errors)) { |
|
35 | - ++$this->errors[$hash]['count']; |
|
36 | - } else { |
|
37 | - $this->errors[$hash] = [ |
|
38 | - 'count' => 0, |
|
39 | - 'errno' => $errno, |
|
40 | - 'file' => $file, |
|
41 | - 'line' => $line, |
|
42 | - 'message' => $message, |
|
43 | - 'name' => $errname, |
|
44 | - ]; |
|
45 | - } |
|
46 | - } |
|
28 | + public function errorHandler(int $errno, string $message, string $file, int $line): void |
|
29 | + { |
|
30 | + $errname = array_key_exists($errno, Console::ERROR_CODES) |
|
31 | + ? Console::ERROR_CODES[$errno] |
|
32 | + : 'Unknown'; |
|
33 | + $hash = md5($errno.$message.$file.$line); |
|
34 | + if (array_key_exists($hash, $this->errors)) { |
|
35 | + ++$this->errors[$hash]['count']; |
|
36 | + } else { |
|
37 | + $this->errors[$hash] = [ |
|
38 | + 'count' => 0, |
|
39 | + 'errno' => $errno, |
|
40 | + 'file' => $file, |
|
41 | + 'line' => $line, |
|
42 | + 'message' => $message, |
|
43 | + 'name' => $errname, |
|
44 | + ]; |
|
45 | + } |
|
46 | + } |
|
47 | 47 | |
48 | - public function init(): void |
|
49 | - { |
|
50 | - $controller = new Controller(); |
|
51 | - add_filter('all', [$controller, 'initConsole']); |
|
52 | - add_filter('all', [$controller, 'initProfiler']); |
|
53 | - add_filter('all', [$controller, 'measureSlowActions']); |
|
54 | - add_action('plugins_loaded', [$controller, 'registerLanguages']); |
|
55 | - add_action('init', function () use ($controller) { |
|
56 | - if (!apply_filters('blackbar/enabled', current_user_can('administrator'))) { |
|
57 | - return; |
|
58 | - } |
|
59 | - add_action('admin_enqueue_scripts', [$controller, 'enqueueAssets']); |
|
60 | - add_action('wp_enqueue_scripts', [$controller, 'enqueueAssets']); |
|
61 | - add_action('admin_footer', [$controller, 'renderBar']); |
|
62 | - add_action('wp_footer', [$controller, 'renderBar']); |
|
63 | - add_filter('admin_body_class', [$controller, 'filterBodyClasses']); |
|
64 | - }); |
|
65 | - apply_filters('debug', 'Profiler Started'); |
|
66 | - apply_filters('debug', 'blackbar/profiler/noise'); |
|
67 | - set_error_handler([$this, 'errorHandler'], E_ALL | E_STRICT); |
|
68 | - } |
|
48 | + public function init(): void |
|
49 | + { |
|
50 | + $controller = new Controller(); |
|
51 | + add_filter('all', [$controller, 'initConsole']); |
|
52 | + add_filter('all', [$controller, 'initProfiler']); |
|
53 | + add_filter('all', [$controller, 'measureSlowActions']); |
|
54 | + add_action('plugins_loaded', [$controller, 'registerLanguages']); |
|
55 | + add_action('init', function () use ($controller) { |
|
56 | + if (!apply_filters('blackbar/enabled', current_user_can('administrator'))) { |
|
57 | + return; |
|
58 | + } |
|
59 | + add_action('admin_enqueue_scripts', [$controller, 'enqueueAssets']); |
|
60 | + add_action('wp_enqueue_scripts', [$controller, 'enqueueAssets']); |
|
61 | + add_action('admin_footer', [$controller, 'renderBar']); |
|
62 | + add_action('wp_footer', [$controller, 'renderBar']); |
|
63 | + add_filter('admin_body_class', [$controller, 'filterBodyClasses']); |
|
64 | + }); |
|
65 | + apply_filters('debug', 'Profiler Started'); |
|
66 | + apply_filters('debug', 'blackbar/profiler/noise'); |
|
67 | + set_error_handler([$this, 'errorHandler'], E_ALL | E_STRICT); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * @return static |
|
72 | - */ |
|
73 | - public static function load() |
|
74 | - { |
|
75 | - if (empty(static::$instance)) { |
|
76 | - static::$instance = new static(); |
|
77 | - } |
|
78 | - return static::$instance; |
|
79 | - } |
|
70 | + /** |
|
71 | + * @return static |
|
72 | + */ |
|
73 | + public static function load() |
|
74 | + { |
|
75 | + if (empty(static::$instance)) { |
|
76 | + static::$instance = new static(); |
|
77 | + } |
|
78 | + return static::$instance; |
|
79 | + } |
|
80 | 80 | |
81 | - public function path(string $file = '', bool $realpath = true): string |
|
82 | - { |
|
83 | - $path = $realpath |
|
84 | - ? plugin_dir_path($this->file) |
|
85 | - : trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
86 | - return trailingslashit($path).ltrim(trim($file), '/'); |
|
87 | - } |
|
81 | + public function path(string $file = '', bool $realpath = true): string |
|
82 | + { |
|
83 | + $path = $realpath |
|
84 | + ? plugin_dir_path($this->file) |
|
85 | + : trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
86 | + return trailingslashit($path).ltrim(trim($file), '/'); |
|
87 | + } |
|
88 | 88 | |
89 | - public function render(string $view, array $data = []): void |
|
90 | - { |
|
91 | - $file = $this->path(sprintf('views/%s.php', str_replace('.php', '', $view))); |
|
92 | - if (!file_exists($file)) { |
|
93 | - return; |
|
94 | - } |
|
95 | - extract($data); |
|
96 | - include $file; |
|
97 | - } |
|
89 | + public function render(string $view, array $data = []): void |
|
90 | + { |
|
91 | + $file = $this->path(sprintf('views/%s.php', str_replace('.php', '', $view))); |
|
92 | + if (!file_exists($file)) { |
|
93 | + return; |
|
94 | + } |
|
95 | + extract($data); |
|
96 | + include $file; |
|
97 | + } |
|
98 | 98 | |
99 | - public function url(string $path = ''): string |
|
100 | - { |
|
101 | - return esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
102 | - } |
|
99 | + public function url(string $path = ''): string |
|
100 | + { |
|
101 | + return esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
102 | + } |
|
103 | 103 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | |
11 | 11 | public $actions; |
12 | 12 | public $console; |
13 | - public $errors = []; |
|
13 | + public $errors = [ ]; |
|
14 | 14 | public $file; |
15 | 15 | public $profiler; |
16 | 16 | |
@@ -18,23 +18,23 @@ discard block |
||
18 | 18 | |
19 | 19 | public function __construct() |
20 | 20 | { |
21 | - $file = wp_normalize_path((new \ReflectionClass($this))->getFileName()); |
|
21 | + $file = wp_normalize_path( ( new \ReflectionClass( $this ) )->getFileName() ); |
|
22 | 22 | $this->actions = new SlowActions(); |
23 | 23 | $this->console = new Console(); |
24 | - $this->file = str_replace('plugin/Application', static::ID, $file); |
|
24 | + $this->file = str_replace( 'plugin/Application', static::ID, $file ); |
|
25 | 25 | $this->profiler = new Profiler(); |
26 | 26 | } |
27 | 27 | |
28 | - public function errorHandler(int $errno, string $message, string $file, int $line): void |
|
28 | + public function errorHandler( int $errno, string $message, string $file, int $line ): void |
|
29 | 29 | { |
30 | - $errname = array_key_exists($errno, Console::ERROR_CODES) |
|
31 | - ? Console::ERROR_CODES[$errno] |
|
30 | + $errname = array_key_exists( $errno, Console::ERROR_CODES ) |
|
31 | + ? Console::ERROR_CODES[ $errno ] |
|
32 | 32 | : 'Unknown'; |
33 | - $hash = md5($errno.$message.$file.$line); |
|
34 | - if (array_key_exists($hash, $this->errors)) { |
|
35 | - ++$this->errors[$hash]['count']; |
|
33 | + $hash = md5( $errno . $message . $file . $line ); |
|
34 | + if( array_key_exists( $hash, $this->errors ) ) { |
|
35 | + ++$this->errors[ $hash ][ 'count' ]; |
|
36 | 36 | } else { |
37 | - $this->errors[$hash] = [ |
|
37 | + $this->errors[ $hash ] = [ |
|
38 | 38 | 'count' => 0, |
39 | 39 | 'errno' => $errno, |
40 | 40 | 'file' => $file, |
@@ -48,23 +48,23 @@ discard block |
||
48 | 48 | public function init(): void |
49 | 49 | { |
50 | 50 | $controller = new Controller(); |
51 | - add_filter('all', [$controller, 'initConsole']); |
|
52 | - add_filter('all', [$controller, 'initProfiler']); |
|
53 | - add_filter('all', [$controller, 'measureSlowActions']); |
|
54 | - add_action('plugins_loaded', [$controller, 'registerLanguages']); |
|
55 | - add_action('init', function () use ($controller) { |
|
56 | - if (!apply_filters('blackbar/enabled', current_user_can('administrator'))) { |
|
51 | + add_filter( 'all', [ $controller, 'initConsole' ] ); |
|
52 | + add_filter( 'all', [ $controller, 'initProfiler' ] ); |
|
53 | + add_filter( 'all', [ $controller, 'measureSlowActions' ] ); |
|
54 | + add_action( 'plugins_loaded', [ $controller, 'registerLanguages' ] ); |
|
55 | + add_action( 'init', function() use ( $controller ) { |
|
56 | + if( !apply_filters( 'blackbar/enabled', current_user_can( 'administrator' ) ) ) { |
|
57 | 57 | return; |
58 | 58 | } |
59 | - add_action('admin_enqueue_scripts', [$controller, 'enqueueAssets']); |
|
60 | - add_action('wp_enqueue_scripts', [$controller, 'enqueueAssets']); |
|
61 | - add_action('admin_footer', [$controller, 'renderBar']); |
|
62 | - add_action('wp_footer', [$controller, 'renderBar']); |
|
63 | - add_filter('admin_body_class', [$controller, 'filterBodyClasses']); |
|
59 | + add_action( 'admin_enqueue_scripts', [ $controller, 'enqueueAssets' ] ); |
|
60 | + add_action( 'wp_enqueue_scripts', [ $controller, 'enqueueAssets' ] ); |
|
61 | + add_action( 'admin_footer', [ $controller, 'renderBar' ] ); |
|
62 | + add_action( 'wp_footer', [ $controller, 'renderBar' ] ); |
|
63 | + add_filter( 'admin_body_class', [ $controller, 'filterBodyClasses' ] ); |
|
64 | 64 | }); |
65 | - apply_filters('debug', 'Profiler Started'); |
|
66 | - apply_filters('debug', 'blackbar/profiler/noise'); |
|
67 | - set_error_handler([$this, 'errorHandler'], E_ALL | E_STRICT); |
|
65 | + apply_filters( 'debug', 'Profiler Started' ); |
|
66 | + apply_filters( 'debug', 'blackbar/profiler/noise' ); |
|
67 | + set_error_handler( [ $this, 'errorHandler' ], E_ALL | E_STRICT ); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -72,32 +72,32 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public static function load() |
74 | 74 | { |
75 | - if (empty(static::$instance)) { |
|
75 | + if( empty( static::$instance ) ) { |
|
76 | 76 | static::$instance = new static(); |
77 | 77 | } |
78 | 78 | return static::$instance; |
79 | 79 | } |
80 | 80 | |
81 | - public function path(string $file = '', bool $realpath = true): string |
|
81 | + public function path( string $file = '', bool $realpath = true ): string |
|
82 | 82 | { |
83 | 83 | $path = $realpath |
84 | - ? plugin_dir_path($this->file) |
|
85 | - : trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
86 | - return trailingslashit($path).ltrim(trim($file), '/'); |
|
84 | + ? plugin_dir_path( $this->file ) |
|
85 | + : trailingslashit( WP_PLUGIN_DIR ) . basename( dirname( $this->file ) ); |
|
86 | + return trailingslashit( $path ) . ltrim( trim( $file ), '/' ); |
|
87 | 87 | } |
88 | 88 | |
89 | - public function render(string $view, array $data = []): void |
|
89 | + public function render( string $view, array $data = [ ] ): void |
|
90 | 90 | { |
91 | - $file = $this->path(sprintf('views/%s.php', str_replace('.php', '', $view))); |
|
92 | - if (!file_exists($file)) { |
|
91 | + $file = $this->path( sprintf( 'views/%s.php', str_replace( '.php', '', $view ) ) ); |
|
92 | + if( !file_exists( $file ) ) { |
|
93 | 93 | return; |
94 | 94 | } |
95 | - extract($data); |
|
95 | + extract( $data ); |
|
96 | 96 | include $file; |
97 | 97 | } |
98 | 98 | |
99 | - public function url(string $path = ''): string |
|
99 | + public function url( string $path = '' ): string |
|
100 | 100 | { |
101 | - return esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
101 | + return esc_url( plugin_dir_url( $this->file ) . ltrim( trim( $path ), '/' ) ); |
|
102 | 102 | } |
103 | 103 | } |
@@ -33,7 +33,8 @@ discard block |
||
33 | 33 | $hash = md5($errno.$message.$file.$line); |
34 | 34 | if (array_key_exists($hash, $this->errors)) { |
35 | 35 | ++$this->errors[$hash]['count']; |
36 | - } else { |
|
36 | + } |
|
37 | + else { |
|
37 | 38 | $this->errors[$hash] = [ |
38 | 39 | 'count' => 0, |
39 | 40 | 'errno' => $errno, |
@@ -52,7 +53,8 @@ discard block |
||
52 | 53 | add_filter('all', [$controller, 'initProfiler']); |
53 | 54 | add_filter('all', [$controller, 'measureSlowActions']); |
54 | 55 | add_action('plugins_loaded', [$controller, 'registerLanguages']); |
55 | - add_action('init', function () use ($controller) { |
|
56 | + add_action('init', function () use ($controller) |
|
57 | + { |
|
56 | 58 | if (!apply_filters('blackbar/enabled', current_user_can('administrator'))) { |
57 | 59 | return; |
58 | 60 | } |
@@ -20,13 +20,13 @@ |
||
20 | 20 | defined('ABSPATH') || exit; |
21 | 21 | |
22 | 22 | if (!class_exists('GL_Plugin_Check_v6')) { |
23 | - require_once __DIR__.'/activate.php'; |
|
23 | + require_once __DIR__.'/activate.php'; |
|
24 | 24 | } |
25 | 25 | if ((new GL_Plugin_Check_v6(__FILE__))->canProceed()) { |
26 | - require_once __DIR__.'/autoload.php'; |
|
27 | - require_once __DIR__.'/compatibility.php'; |
|
28 | - if (!defined('SAVEQUERIES')) { |
|
29 | - define('SAVEQUERIES', 1); |
|
30 | - } |
|
31 | - GeminiLabs\BlackBar\Application::load()->init(); |
|
26 | + require_once __DIR__.'/autoload.php'; |
|
27 | + require_once __DIR__.'/compatibility.php'; |
|
28 | + if (!defined('SAVEQUERIES')) { |
|
29 | + define('SAVEQUERIES', 1); |
|
30 | + } |
|
31 | + GeminiLabs\BlackBar\Application::load()->init(); |
|
32 | 32 | } |
@@ -17,16 +17,16 @@ |
||
17 | 17 | * Text Domain: blackbar |
18 | 18 | * Domain Path: languages |
19 | 19 | */ |
20 | -defined('ABSPATH') || exit; |
|
20 | +defined( 'ABSPATH' ) || exit; |
|
21 | 21 | |
22 | -if (!class_exists('GL_Plugin_Check_v6')) { |
|
23 | - require_once __DIR__.'/activate.php'; |
|
22 | +if( !class_exists( 'GL_Plugin_Check_v6' ) ) { |
|
23 | + require_once __DIR__ . '/activate.php'; |
|
24 | 24 | } |
25 | -if ((new GL_Plugin_Check_v6(__FILE__))->canProceed()) { |
|
26 | - require_once __DIR__.'/autoload.php'; |
|
27 | - require_once __DIR__.'/compatibility.php'; |
|
28 | - if (!defined('SAVEQUERIES')) { |
|
29 | - define('SAVEQUERIES', 1); |
|
25 | +if( ( new GL_Plugin_Check_v6( __FILE__ ) )->canProceed() ) { |
|
26 | + require_once __DIR__ . '/autoload.php'; |
|
27 | + require_once __DIR__ . '/compatibility.php'; |
|
28 | + if( !defined( 'SAVEQUERIES' ) ) { |
|
29 | + define( 'SAVEQUERIES', 1 ); |
|
30 | 30 | } |
31 | 31 | GeminiLabs\BlackBar\Application::load()->init(); |
32 | 32 | } |
@@ -4,86 +4,86 @@ |
||
4 | 4 | |
5 | 5 | class Profiler |
6 | 6 | { |
7 | - /** |
|
8 | - * This is the time that WordPress takes to execute the profiler hook. |
|
9 | - * @var float |
|
10 | - */ |
|
11 | - protected $noise; |
|
12 | - /** |
|
13 | - * @var float |
|
14 | - */ |
|
15 | - protected $start; |
|
16 | - /** |
|
17 | - * @var float |
|
18 | - */ |
|
19 | - protected $stop; |
|
20 | - /** |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $timers; |
|
7 | + /** |
|
8 | + * This is the time that WordPress takes to execute the profiler hook. |
|
9 | + * @var float |
|
10 | + */ |
|
11 | + protected $noise; |
|
12 | + /** |
|
13 | + * @var float |
|
14 | + */ |
|
15 | + protected $start; |
|
16 | + /** |
|
17 | + * @var float |
|
18 | + */ |
|
19 | + protected $stop; |
|
20 | + /** |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $timers; |
|
24 | 24 | |
25 | - public function __construct() |
|
26 | - { |
|
27 | - $this->noise = (float) 0; |
|
28 | - $this->start = (float) 0; |
|
29 | - $this->stop = (float) 0; |
|
30 | - $this->timers = []; |
|
31 | - } |
|
25 | + public function __construct() |
|
26 | + { |
|
27 | + $this->noise = (float) 0; |
|
28 | + $this->start = (float) 0; |
|
29 | + $this->stop = (float) 0; |
|
30 | + $this->timers = []; |
|
31 | + } |
|
32 | 32 | |
33 | - public function getMeasure(): array |
|
34 | - { |
|
35 | - return $this->timers; |
|
36 | - } |
|
33 | + public function getMeasure(): array |
|
34 | + { |
|
35 | + return $this->timers; |
|
36 | + } |
|
37 | 37 | |
38 | - public function getMemoryString(array $timer): string |
|
39 | - { |
|
40 | - return sprintf('%s kB', round($this->normalize($timer)['memory'] / 1000)); |
|
41 | - } |
|
38 | + public function getMemoryString(array $timer): string |
|
39 | + { |
|
40 | + return sprintf('%s kB', round($this->normalize($timer)['memory'] / 1000)); |
|
41 | + } |
|
42 | 42 | |
43 | - public function getNameString(array $timer): string |
|
44 | - { |
|
45 | - return $this->normalize($timer)['name']; |
|
46 | - } |
|
43 | + public function getNameString(array $timer): string |
|
44 | + { |
|
45 | + return $this->normalize($timer)['name']; |
|
46 | + } |
|
47 | 47 | |
48 | - public function getTimeString(array $timer): string |
|
49 | - { |
|
50 | - $timer = $this->normalize($timer); |
|
51 | - $index = array_search($timer['name'], array_column($this->timers, 'name')); |
|
52 | - $start = $this->start + ($index * $this->noise); |
|
53 | - $time = number_format(round(($timer['time'] - $start) * 1000, 4), 4); |
|
54 | - return sprintf('%s ms', $time); |
|
55 | - } |
|
48 | + public function getTimeString(array $timer): string |
|
49 | + { |
|
50 | + $timer = $this->normalize($timer); |
|
51 | + $index = array_search($timer['name'], array_column($this->timers, 'name')); |
|
52 | + $start = $this->start + ($index * $this->noise); |
|
53 | + $time = number_format(round(($timer['time'] - $start) * 1000, 4), 4); |
|
54 | + return sprintf('%s ms', $time); |
|
55 | + } |
|
56 | 56 | |
57 | - public function getTotalTime(): float |
|
58 | - { |
|
59 | - $totalNoise = (count($this->timers) - 1) * $this->noise; |
|
60 | - return $this->stop - $this->start - $totalNoise; |
|
61 | - } |
|
57 | + public function getTotalTime(): float |
|
58 | + { |
|
59 | + $totalNoise = (count($this->timers) - 1) * $this->noise; |
|
60 | + return $this->stop - $this->start - $totalNoise; |
|
61 | + } |
|
62 | 62 | |
63 | - public function trace(string $name): void |
|
64 | - { |
|
65 | - $microtime = microtime(true); // float |
|
66 | - if (!$this->start) { |
|
67 | - $this->start = $microtime; |
|
68 | - } |
|
69 | - if ('blackbar/profiler/noise' === $name) { |
|
70 | - $this->noise = $microtime - $this->start; |
|
71 | - return; |
|
72 | - } |
|
73 | - $this->timers[] = [ |
|
74 | - 'memory' => memory_get_peak_usage(), |
|
75 | - 'name' => $name, |
|
76 | - 'time' => $microtime, |
|
77 | - ]; |
|
78 | - $this->stop = $microtime; |
|
79 | - } |
|
63 | + public function trace(string $name): void |
|
64 | + { |
|
65 | + $microtime = microtime(true); // float |
|
66 | + if (!$this->start) { |
|
67 | + $this->start = $microtime; |
|
68 | + } |
|
69 | + if ('blackbar/profiler/noise' === $name) { |
|
70 | + $this->noise = $microtime - $this->start; |
|
71 | + return; |
|
72 | + } |
|
73 | + $this->timers[] = [ |
|
74 | + 'memory' => memory_get_peak_usage(), |
|
75 | + 'name' => $name, |
|
76 | + 'time' => $microtime, |
|
77 | + ]; |
|
78 | + $this->stop = $microtime; |
|
79 | + } |
|
80 | 80 | |
81 | - protected function normalize(array $timer): array |
|
82 | - { |
|
83 | - return wp_parse_args($timer, [ |
|
84 | - 'memory' => 0, |
|
85 | - 'name' => '', |
|
86 | - 'time' => (float) 0, |
|
87 | - ]); |
|
88 | - } |
|
81 | + protected function normalize(array $timer): array |
|
82 | + { |
|
83 | + return wp_parse_args($timer, [ |
|
84 | + 'memory' => 0, |
|
85 | + 'name' => '', |
|
86 | + 'time' => (float) 0, |
|
87 | + ]); |
|
88 | + } |
|
89 | 89 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | $this->noise = (float) 0; |
28 | 28 | $this->start = (float) 0; |
29 | 29 | $this->stop = (float) 0; |
30 | - $this->timers = []; |
|
30 | + $this->timers = [ ]; |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | public function getMeasure(): array |
@@ -35,42 +35,42 @@ discard block |
||
35 | 35 | return $this->timers; |
36 | 36 | } |
37 | 37 | |
38 | - public function getMemoryString(array $timer): string |
|
38 | + public function getMemoryString( array $timer ): string |
|
39 | 39 | { |
40 | - return sprintf('%s kB', round($this->normalize($timer)['memory'] / 1000)); |
|
40 | + return sprintf( '%s kB', round( $this->normalize( $timer )[ 'memory' ] / 1000 ) ); |
|
41 | 41 | } |
42 | 42 | |
43 | - public function getNameString(array $timer): string |
|
43 | + public function getNameString( array $timer ): string |
|
44 | 44 | { |
45 | - return $this->normalize($timer)['name']; |
|
45 | + return $this->normalize( $timer )[ 'name' ]; |
|
46 | 46 | } |
47 | 47 | |
48 | - public function getTimeString(array $timer): string |
|
48 | + public function getTimeString( array $timer ): string |
|
49 | 49 | { |
50 | - $timer = $this->normalize($timer); |
|
51 | - $index = array_search($timer['name'], array_column($this->timers, 'name')); |
|
52 | - $start = $this->start + ($index * $this->noise); |
|
53 | - $time = number_format(round(($timer['time'] - $start) * 1000, 4), 4); |
|
54 | - return sprintf('%s ms', $time); |
|
50 | + $timer = $this->normalize( $timer ); |
|
51 | + $index = array_search( $timer[ 'name' ], array_column( $this->timers, 'name' ) ); |
|
52 | + $start = $this->start + ( $index * $this->noise ); |
|
53 | + $time = number_format( round( ( $timer[ 'time' ] - $start ) * 1000, 4 ), 4 ); |
|
54 | + return sprintf( '%s ms', $time ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | public function getTotalTime(): float |
58 | 58 | { |
59 | - $totalNoise = (count($this->timers) - 1) * $this->noise; |
|
59 | + $totalNoise = ( count( $this->timers ) - 1 ) * $this->noise; |
|
60 | 60 | return $this->stop - $this->start - $totalNoise; |
61 | 61 | } |
62 | 62 | |
63 | - public function trace(string $name): void |
|
63 | + public function trace( string $name ): void |
|
64 | 64 | { |
65 | - $microtime = microtime(true); // float |
|
66 | - if (!$this->start) { |
|
65 | + $microtime = microtime( true ); // float |
|
66 | + if( !$this->start ) { |
|
67 | 67 | $this->start = $microtime; |
68 | 68 | } |
69 | - if ('blackbar/profiler/noise' === $name) { |
|
69 | + if( 'blackbar/profiler/noise' === $name ) { |
|
70 | 70 | $this->noise = $microtime - $this->start; |
71 | 71 | return; |
72 | 72 | } |
73 | - $this->timers[] = [ |
|
73 | + $this->timers[ ] = [ |
|
74 | 74 | 'memory' => memory_get_peak_usage(), |
75 | 75 | 'name' => $name, |
76 | 76 | 'time' => $microtime, |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | $this->stop = $microtime; |
79 | 79 | } |
80 | 80 | |
81 | - protected function normalize(array $timer): array |
|
81 | + protected function normalize( array $timer ): array |
|
82 | 82 | { |
83 | - return wp_parse_args($timer, [ |
|
83 | + return wp_parse_args( $timer, [ |
|
84 | 84 | 'memory' => 0, |
85 | 85 | 'name' => '', |
86 | 86 | 'time' => (float) 0, |
87 | - ]); |
|
87 | + ] ); |
|
88 | 88 | } |
89 | 89 | } |
@@ -4,250 +4,250 @@ |
||
4 | 4 | |
5 | 5 | class Controller |
6 | 6 | { |
7 | - /** |
|
8 | - * @var Application |
|
9 | - */ |
|
10 | - protected $app; |
|
11 | - |
|
12 | - public function __construct() |
|
13 | - { |
|
14 | - $this->app = Application::load(); |
|
15 | - } |
|
16 | - |
|
17 | - /** |
|
18 | - * @action admin_enqueue_scripts |
|
19 | - * @action wp_enqueue_scripts |
|
20 | - */ |
|
21 | - public function enqueueAssets(): void |
|
22 | - { |
|
23 | - wp_enqueue_script(Application::ID, $this->app->url('assets/main.js')); |
|
24 | - wp_enqueue_style(Application::ID, $this->app->url('assets/main.css'), ['dashicons']); |
|
25 | - wp_enqueue_style(Application::ID.'-syntax', $this->app->url('assets/syntax.css')); |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * @param string $classes |
|
30 | - * @action admin_body_class |
|
31 | - */ |
|
32 | - public function filterBodyClasses($classes): string |
|
33 | - { |
|
34 | - return trim((string) $classes.' '.Application::ID); |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * @filter all |
|
39 | - */ |
|
40 | - public function initConsole(): void |
|
41 | - { |
|
42 | - if (Application::CONSOLE_HOOK !== func_get_arg(0)) { |
|
43 | - return; |
|
44 | - } |
|
45 | - $args = array_pad(func_get_args(), 4, ''); |
|
46 | - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 4); |
|
47 | - $entry = array_pop($backtrace); |
|
48 | - $message = $args[1]; |
|
49 | - $errno = $args[2]; |
|
50 | - $location = $args[3]; |
|
51 | - if (empty(trim($location)) && array_key_exists('file', $entry)) { |
|
52 | - $path = explode(ABSPATH, $entry['file']); |
|
53 | - $location = sprintf('%s:%s', array_pop($path), $entry['line']); |
|
54 | - } |
|
55 | - $this->app->console->store($message, $errno, '['.$location.'] '); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @filter all |
|
60 | - */ |
|
61 | - public function initProfiler(): void |
|
62 | - { |
|
63 | - if (Application::PROFILER_HOOK === func_get_arg(0)) { |
|
64 | - $this->app->profiler->trace(func_get_arg(1)); |
|
65 | - } |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @filter all |
|
70 | - */ |
|
71 | - public function measureSlowActions(): void |
|
72 | - { |
|
73 | - $this->app->actions->startTimer(); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @action plugins_loaded |
|
78 | - */ |
|
79 | - public function registerLanguages(): void |
|
80 | - { |
|
81 | - load_plugin_textdomain(Application::ID, false, |
|
82 | - plugin_basename($this->app->path()).'/languages/' |
|
83 | - ); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @action admin_footer |
|
88 | - * @action wp_footer |
|
89 | - */ |
|
90 | - public function renderBar(): void |
|
91 | - { |
|
92 | - apply_filters('debug', 'Profiler Stopped'); |
|
93 | - $this->app->render('debug-bar', [ |
|
94 | - 'actions' => $this->app->actions, |
|
95 | - 'actionsLabel' => $this->getSlowActionsLabel(), |
|
96 | - 'blackbar' => $this->app, |
|
97 | - 'consoleEntries' => $this->getConsoleEntries(), |
|
98 | - 'consoleLabel' => $this->getConsoleLabel(), |
|
99 | - 'profiler' => $this->app->profiler, |
|
100 | - 'profilerLabel' => $this->getProfilerLabel(), |
|
101 | - 'queries' => $this->getQueries(), |
|
102 | - 'queriesLabel' => $this->getQueriesLabel(), |
|
103 | - 'templates' => $this->getTemplates(), |
|
104 | - ]); |
|
105 | - } |
|
106 | - |
|
107 | - protected function convertToMiliseconds(float $time, int $decimals = 2): string |
|
108 | - { |
|
109 | - return number_format($time * 1000, $decimals); |
|
110 | - } |
|
111 | - |
|
112 | - protected function getConsoleEntries(): array |
|
113 | - { |
|
114 | - return array_merge($this->getErrors(), $this->app->console->entries); |
|
115 | - } |
|
116 | - |
|
117 | - protected function getConsoleLabel(): string |
|
118 | - { |
|
119 | - $class = ''; |
|
120 | - $entries = $this->getConsoleEntries(); |
|
121 | - $entryCount = count($entries); |
|
122 | - $errorCount = 0; |
|
123 | - $label = __('Console', 'blackbar'); |
|
124 | - foreach ($entries as $entry) { |
|
125 | - if (in_array($entry['code'], [E_NOTICE, E_STRICT, E_DEPRECATED])) { |
|
126 | - $class = 'glbb-warning'; |
|
127 | - } |
|
128 | - if (in_array($entry['code'], [E_WARNING])) { |
|
129 | - ++$errorCount; |
|
130 | - } |
|
131 | - } |
|
132 | - if ($entryCount > 0) { |
|
133 | - $label .= sprintf(' (%d)', $entryCount); |
|
134 | - } |
|
135 | - if ($errorCount > 0) { |
|
136 | - $class = 'glbb-error'; |
|
137 | - $label .= sprintf(' (%d, %d!)', $entryCount, $errorCount); |
|
138 | - } |
|
139 | - return sprintf('<span class="%s">%s</span>', $class, $label); |
|
140 | - } |
|
141 | - |
|
142 | - protected function getErrors(): array |
|
143 | - { |
|
144 | - $errors = []; |
|
145 | - foreach ($this->app->errors as $error) { |
|
146 | - $class = 'glbb-info'; |
|
147 | - if (in_array($error['code'], [E_NOTICE, E_STRICT, E_DEPRECATED])) { |
|
148 | - $class = 'glbb-warning'; |
|
149 | - } |
|
150 | - if (E_WARNING == $error['code']) { |
|
151 | - $class = 'glbb-error'; |
|
152 | - } |
|
153 | - if ($error['count'] > 1) { |
|
154 | - $error['name'] .= ' ('.$error['count'].')'; |
|
155 | - } |
|
156 | - $errors[] = [ |
|
157 | - 'code' => $error['code'], |
|
158 | - 'name' => '<span class="'.$class.'">'.$error['name'].'</span>', |
|
159 | - 'message' => sprintf(__('%s on line %s in file %s', 'blackbar'), |
|
160 | - $error['message'], |
|
161 | - $error['line'], |
|
162 | - $error['file'] |
|
163 | - ), |
|
164 | - ]; |
|
165 | - } |
|
166 | - return $errors; |
|
167 | - } |
|
168 | - |
|
169 | - protected function getIncludedFiles(): array |
|
170 | - { |
|
171 | - $files = array_values(array_filter(get_included_files(), function ($file) { |
|
172 | - $bool = false !== strpos($file, '/themes/') && false === strpos($file, '/functions.php'); |
|
173 | - return (bool) apply_filters('blackbar/templates/file', $bool, $file); |
|
174 | - })); |
|
175 | - return array_map(function ($key, $value) { |
|
176 | - $value = str_replace(trailingslashit(WP_CONTENT_DIR), '', $value); |
|
177 | - return sprintf('[%s] => %s', $key, $value); |
|
178 | - }, array_keys($files), $files); |
|
179 | - } |
|
180 | - |
|
181 | - protected function getProfilerLabel(): string |
|
182 | - { |
|
183 | - $label = __('Profiler', 'blackbar'); |
|
184 | - $profilerTime = $this->convertToMiliseconds($this->app->profiler->getTotalTime(), 0); |
|
185 | - if ($profilerTime > 0) { |
|
186 | - $label .= sprintf(' (%s %s)', $profilerTime, __('ms', 'blackbar')); |
|
187 | - } |
|
188 | - return $label; |
|
189 | - } |
|
190 | - |
|
191 | - protected function getQueries(): array |
|
192 | - { |
|
193 | - global $wpdb; |
|
194 | - $queries = []; |
|
195 | - $search = [ |
|
196 | - 'AND', 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT', |
|
197 | - 'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE', |
|
198 | - ]; |
|
199 | - $replace = array_map(function ($value) { |
|
200 | - return PHP_EOL.$value; |
|
201 | - }, $search); |
|
202 | - foreach ($wpdb->queries as $query) { |
|
203 | - $miliseconds = number_format(round($query[1] * 1000, 4), 4); |
|
204 | - $sql = preg_replace('/\s\s+/', ' ', trim($query[0])); |
|
205 | - $sql = str_replace(PHP_EOL, ' ', $sql); |
|
206 | - $sql = str_replace($search, $replace, $sql); |
|
207 | - $queries[] = [ |
|
208 | - 'ms' => $miliseconds, |
|
209 | - 'sql' => $sql, |
|
210 | - ]; |
|
211 | - } |
|
212 | - return $queries; |
|
213 | - } |
|
214 | - |
|
215 | - protected function getQueriesLabel(): string |
|
216 | - { |
|
217 | - $label = __('SQL', 'blackbar'); |
|
218 | - if (!SAVEQUERIES) { |
|
219 | - return $label; |
|
220 | - } |
|
221 | - global $wpdb; |
|
222 | - $queryTime = 0; |
|
223 | - foreach ($wpdb->queries as $query) { |
|
224 | - $queryTime += $query[1]; |
|
225 | - } |
|
226 | - $queriesCount = sprintf('<span class="glbb-queries-count">%s</span>', count($wpdb->queries)); |
|
227 | - $queriesTime = sprintf('<span class="glbb-queries-time">%s</span>', $this->convertToMiliseconds((float) $queryTime)); |
|
228 | - return $label.sprintf(' (%s %s | %s %s)', $queriesCount, __('queries', 'blackbar'), $queriesTime, __('ms', 'blackbar')); |
|
229 | - } |
|
230 | - |
|
231 | - protected function getSlowActionsLabel(): string |
|
232 | - { |
|
233 | - $label = __('Hooks', 'blackbar'); |
|
234 | - $totalTime = $this->convertToMiliseconds($this->app->actions->getTotalTime(), 0); |
|
235 | - if ($totalTime > 0) { |
|
236 | - $label .= sprintf(' (%s %s)', $totalTime, __('ms', 'blackbar')); |
|
237 | - } |
|
238 | - return $label; |
|
239 | - } |
|
240 | - |
|
241 | - protected function getTemplates(): string |
|
242 | - { |
|
243 | - if (is_admin()) { |
|
244 | - return ''; |
|
245 | - } |
|
246 | - if (class_exists('\GeminiLabs\Castor\Facades\Development')) { |
|
247 | - ob_start(); |
|
248 | - \GeminiLabs\Castor\Facades\Development::printTemplatePaths(); |
|
249 | - return ob_get_clean(); |
|
250 | - } |
|
251 | - return sprintf('<pre>%s</pre>', implode(PHP_EOL, $this->getIncludedFiles())); |
|
252 | - } |
|
7 | + /** |
|
8 | + * @var Application |
|
9 | + */ |
|
10 | + protected $app; |
|
11 | + |
|
12 | + public function __construct() |
|
13 | + { |
|
14 | + $this->app = Application::load(); |
|
15 | + } |
|
16 | + |
|
17 | + /** |
|
18 | + * @action admin_enqueue_scripts |
|
19 | + * @action wp_enqueue_scripts |
|
20 | + */ |
|
21 | + public function enqueueAssets(): void |
|
22 | + { |
|
23 | + wp_enqueue_script(Application::ID, $this->app->url('assets/main.js')); |
|
24 | + wp_enqueue_style(Application::ID, $this->app->url('assets/main.css'), ['dashicons']); |
|
25 | + wp_enqueue_style(Application::ID.'-syntax', $this->app->url('assets/syntax.css')); |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * @param string $classes |
|
30 | + * @action admin_body_class |
|
31 | + */ |
|
32 | + public function filterBodyClasses($classes): string |
|
33 | + { |
|
34 | + return trim((string) $classes.' '.Application::ID); |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * @filter all |
|
39 | + */ |
|
40 | + public function initConsole(): void |
|
41 | + { |
|
42 | + if (Application::CONSOLE_HOOK !== func_get_arg(0)) { |
|
43 | + return; |
|
44 | + } |
|
45 | + $args = array_pad(func_get_args(), 4, ''); |
|
46 | + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 4); |
|
47 | + $entry = array_pop($backtrace); |
|
48 | + $message = $args[1]; |
|
49 | + $errno = $args[2]; |
|
50 | + $location = $args[3]; |
|
51 | + if (empty(trim($location)) && array_key_exists('file', $entry)) { |
|
52 | + $path = explode(ABSPATH, $entry['file']); |
|
53 | + $location = sprintf('%s:%s', array_pop($path), $entry['line']); |
|
54 | + } |
|
55 | + $this->app->console->store($message, $errno, '['.$location.'] '); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @filter all |
|
60 | + */ |
|
61 | + public function initProfiler(): void |
|
62 | + { |
|
63 | + if (Application::PROFILER_HOOK === func_get_arg(0)) { |
|
64 | + $this->app->profiler->trace(func_get_arg(1)); |
|
65 | + } |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @filter all |
|
70 | + */ |
|
71 | + public function measureSlowActions(): void |
|
72 | + { |
|
73 | + $this->app->actions->startTimer(); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @action plugins_loaded |
|
78 | + */ |
|
79 | + public function registerLanguages(): void |
|
80 | + { |
|
81 | + load_plugin_textdomain(Application::ID, false, |
|
82 | + plugin_basename($this->app->path()).'/languages/' |
|
83 | + ); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @action admin_footer |
|
88 | + * @action wp_footer |
|
89 | + */ |
|
90 | + public function renderBar(): void |
|
91 | + { |
|
92 | + apply_filters('debug', 'Profiler Stopped'); |
|
93 | + $this->app->render('debug-bar', [ |
|
94 | + 'actions' => $this->app->actions, |
|
95 | + 'actionsLabel' => $this->getSlowActionsLabel(), |
|
96 | + 'blackbar' => $this->app, |
|
97 | + 'consoleEntries' => $this->getConsoleEntries(), |
|
98 | + 'consoleLabel' => $this->getConsoleLabel(), |
|
99 | + 'profiler' => $this->app->profiler, |
|
100 | + 'profilerLabel' => $this->getProfilerLabel(), |
|
101 | + 'queries' => $this->getQueries(), |
|
102 | + 'queriesLabel' => $this->getQueriesLabel(), |
|
103 | + 'templates' => $this->getTemplates(), |
|
104 | + ]); |
|
105 | + } |
|
106 | + |
|
107 | + protected function convertToMiliseconds(float $time, int $decimals = 2): string |
|
108 | + { |
|
109 | + return number_format($time * 1000, $decimals); |
|
110 | + } |
|
111 | + |
|
112 | + protected function getConsoleEntries(): array |
|
113 | + { |
|
114 | + return array_merge($this->getErrors(), $this->app->console->entries); |
|
115 | + } |
|
116 | + |
|
117 | + protected function getConsoleLabel(): string |
|
118 | + { |
|
119 | + $class = ''; |
|
120 | + $entries = $this->getConsoleEntries(); |
|
121 | + $entryCount = count($entries); |
|
122 | + $errorCount = 0; |
|
123 | + $label = __('Console', 'blackbar'); |
|
124 | + foreach ($entries as $entry) { |
|
125 | + if (in_array($entry['code'], [E_NOTICE, E_STRICT, E_DEPRECATED])) { |
|
126 | + $class = 'glbb-warning'; |
|
127 | + } |
|
128 | + if (in_array($entry['code'], [E_WARNING])) { |
|
129 | + ++$errorCount; |
|
130 | + } |
|
131 | + } |
|
132 | + if ($entryCount > 0) { |
|
133 | + $label .= sprintf(' (%d)', $entryCount); |
|
134 | + } |
|
135 | + if ($errorCount > 0) { |
|
136 | + $class = 'glbb-error'; |
|
137 | + $label .= sprintf(' (%d, %d!)', $entryCount, $errorCount); |
|
138 | + } |
|
139 | + return sprintf('<span class="%s">%s</span>', $class, $label); |
|
140 | + } |
|
141 | + |
|
142 | + protected function getErrors(): array |
|
143 | + { |
|
144 | + $errors = []; |
|
145 | + foreach ($this->app->errors as $error) { |
|
146 | + $class = 'glbb-info'; |
|
147 | + if (in_array($error['code'], [E_NOTICE, E_STRICT, E_DEPRECATED])) { |
|
148 | + $class = 'glbb-warning'; |
|
149 | + } |
|
150 | + if (E_WARNING == $error['code']) { |
|
151 | + $class = 'glbb-error'; |
|
152 | + } |
|
153 | + if ($error['count'] > 1) { |
|
154 | + $error['name'] .= ' ('.$error['count'].')'; |
|
155 | + } |
|
156 | + $errors[] = [ |
|
157 | + 'code' => $error['code'], |
|
158 | + 'name' => '<span class="'.$class.'">'.$error['name'].'</span>', |
|
159 | + 'message' => sprintf(__('%s on line %s in file %s', 'blackbar'), |
|
160 | + $error['message'], |
|
161 | + $error['line'], |
|
162 | + $error['file'] |
|
163 | + ), |
|
164 | + ]; |
|
165 | + } |
|
166 | + return $errors; |
|
167 | + } |
|
168 | + |
|
169 | + protected function getIncludedFiles(): array |
|
170 | + { |
|
171 | + $files = array_values(array_filter(get_included_files(), function ($file) { |
|
172 | + $bool = false !== strpos($file, '/themes/') && false === strpos($file, '/functions.php'); |
|
173 | + return (bool) apply_filters('blackbar/templates/file', $bool, $file); |
|
174 | + })); |
|
175 | + return array_map(function ($key, $value) { |
|
176 | + $value = str_replace(trailingslashit(WP_CONTENT_DIR), '', $value); |
|
177 | + return sprintf('[%s] => %s', $key, $value); |
|
178 | + }, array_keys($files), $files); |
|
179 | + } |
|
180 | + |
|
181 | + protected function getProfilerLabel(): string |
|
182 | + { |
|
183 | + $label = __('Profiler', 'blackbar'); |
|
184 | + $profilerTime = $this->convertToMiliseconds($this->app->profiler->getTotalTime(), 0); |
|
185 | + if ($profilerTime > 0) { |
|
186 | + $label .= sprintf(' (%s %s)', $profilerTime, __('ms', 'blackbar')); |
|
187 | + } |
|
188 | + return $label; |
|
189 | + } |
|
190 | + |
|
191 | + protected function getQueries(): array |
|
192 | + { |
|
193 | + global $wpdb; |
|
194 | + $queries = []; |
|
195 | + $search = [ |
|
196 | + 'AND', 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT', |
|
197 | + 'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE', |
|
198 | + ]; |
|
199 | + $replace = array_map(function ($value) { |
|
200 | + return PHP_EOL.$value; |
|
201 | + }, $search); |
|
202 | + foreach ($wpdb->queries as $query) { |
|
203 | + $miliseconds = number_format(round($query[1] * 1000, 4), 4); |
|
204 | + $sql = preg_replace('/\s\s+/', ' ', trim($query[0])); |
|
205 | + $sql = str_replace(PHP_EOL, ' ', $sql); |
|
206 | + $sql = str_replace($search, $replace, $sql); |
|
207 | + $queries[] = [ |
|
208 | + 'ms' => $miliseconds, |
|
209 | + 'sql' => $sql, |
|
210 | + ]; |
|
211 | + } |
|
212 | + return $queries; |
|
213 | + } |
|
214 | + |
|
215 | + protected function getQueriesLabel(): string |
|
216 | + { |
|
217 | + $label = __('SQL', 'blackbar'); |
|
218 | + if (!SAVEQUERIES) { |
|
219 | + return $label; |
|
220 | + } |
|
221 | + global $wpdb; |
|
222 | + $queryTime = 0; |
|
223 | + foreach ($wpdb->queries as $query) { |
|
224 | + $queryTime += $query[1]; |
|
225 | + } |
|
226 | + $queriesCount = sprintf('<span class="glbb-queries-count">%s</span>', count($wpdb->queries)); |
|
227 | + $queriesTime = sprintf('<span class="glbb-queries-time">%s</span>', $this->convertToMiliseconds((float) $queryTime)); |
|
228 | + return $label.sprintf(' (%s %s | %s %s)', $queriesCount, __('queries', 'blackbar'), $queriesTime, __('ms', 'blackbar')); |
|
229 | + } |
|
230 | + |
|
231 | + protected function getSlowActionsLabel(): string |
|
232 | + { |
|
233 | + $label = __('Hooks', 'blackbar'); |
|
234 | + $totalTime = $this->convertToMiliseconds($this->app->actions->getTotalTime(), 0); |
|
235 | + if ($totalTime > 0) { |
|
236 | + $label .= sprintf(' (%s %s)', $totalTime, __('ms', 'blackbar')); |
|
237 | + } |
|
238 | + return $label; |
|
239 | + } |
|
240 | + |
|
241 | + protected function getTemplates(): string |
|
242 | + { |
|
243 | + if (is_admin()) { |
|
244 | + return ''; |
|
245 | + } |
|
246 | + if (class_exists('\GeminiLabs\Castor\Facades\Development')) { |
|
247 | + ob_start(); |
|
248 | + \GeminiLabs\Castor\Facades\Development::printTemplatePaths(); |
|
249 | + return ob_get_clean(); |
|
250 | + } |
|
251 | + return sprintf('<pre>%s</pre>', implode(PHP_EOL, $this->getIncludedFiles())); |
|
252 | + } |
|
253 | 253 | } |
@@ -20,18 +20,18 @@ discard block |
||
20 | 20 | */ |
21 | 21 | public function enqueueAssets(): void |
22 | 22 | { |
23 | - wp_enqueue_script(Application::ID, $this->app->url('assets/main.js')); |
|
24 | - wp_enqueue_style(Application::ID, $this->app->url('assets/main.css'), ['dashicons']); |
|
25 | - wp_enqueue_style(Application::ID.'-syntax', $this->app->url('assets/syntax.css')); |
|
23 | + wp_enqueue_script( Application::ID, $this->app->url( 'assets/main.js' ) ); |
|
24 | + wp_enqueue_style( Application::ID, $this->app->url( 'assets/main.css' ), [ 'dashicons' ] ); |
|
25 | + wp_enqueue_style( Application::ID . '-syntax', $this->app->url( 'assets/syntax.css' ) ); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
29 | 29 | * @param string $classes |
30 | 30 | * @action admin_body_class |
31 | 31 | */ |
32 | - public function filterBodyClasses($classes): string |
|
32 | + public function filterBodyClasses( $classes ): string |
|
33 | 33 | { |
34 | - return trim((string) $classes.' '.Application::ID); |
|
34 | + return trim( (string) $classes . ' ' . Application::ID ); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -39,20 +39,20 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function initConsole(): void |
41 | 41 | { |
42 | - if (Application::CONSOLE_HOOK !== func_get_arg(0)) { |
|
42 | + if( Application::CONSOLE_HOOK !== func_get_arg( 0 ) ) { |
|
43 | 43 | return; |
44 | 44 | } |
45 | - $args = array_pad(func_get_args(), 4, ''); |
|
46 | - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 4); |
|
47 | - $entry = array_pop($backtrace); |
|
48 | - $message = $args[1]; |
|
49 | - $errno = $args[2]; |
|
50 | - $location = $args[3]; |
|
51 | - if (empty(trim($location)) && array_key_exists('file', $entry)) { |
|
52 | - $path = explode(ABSPATH, $entry['file']); |
|
53 | - $location = sprintf('%s:%s', array_pop($path), $entry['line']); |
|
45 | + $args = array_pad( func_get_args(), 4, '' ); |
|
46 | + $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 4 ); |
|
47 | + $entry = array_pop( $backtrace ); |
|
48 | + $message = $args[ 1 ]; |
|
49 | + $errno = $args[ 2 ]; |
|
50 | + $location = $args[ 3 ]; |
|
51 | + if( empty( trim( $location ) ) && array_key_exists( 'file', $entry ) ) { |
|
52 | + $path = explode( ABSPATH, $entry[ 'file' ] ); |
|
53 | + $location = sprintf( '%s:%s', array_pop( $path ), $entry[ 'line' ] ); |
|
54 | 54 | } |
55 | - $this->app->console->store($message, $errno, '['.$location.'] '); |
|
55 | + $this->app->console->store( $message, $errno, '[' . $location . '] ' ); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function initProfiler(): void |
62 | 62 | { |
63 | - if (Application::PROFILER_HOOK === func_get_arg(0)) { |
|
64 | - $this->app->profiler->trace(func_get_arg(1)); |
|
63 | + if( Application::PROFILER_HOOK === func_get_arg( 0 ) ) { |
|
64 | + $this->app->profiler->trace( func_get_arg( 1 ) ); |
|
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function registerLanguages(): void |
80 | 80 | { |
81 | - load_plugin_textdomain(Application::ID, false, |
|
82 | - plugin_basename($this->app->path()).'/languages/' |
|
81 | + load_plugin_textdomain( Application::ID, false, |
|
82 | + plugin_basename( $this->app->path() ) . '/languages/' |
|
83 | 83 | ); |
84 | 84 | } |
85 | 85 | |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public function renderBar(): void |
91 | 91 | { |
92 | - apply_filters('debug', 'Profiler Stopped'); |
|
93 | - $this->app->render('debug-bar', [ |
|
92 | + apply_filters( 'debug', 'Profiler Stopped' ); |
|
93 | + $this->app->render( 'debug-bar', [ |
|
94 | 94 | 'actions' => $this->app->actions, |
95 | 95 | 'actionsLabel' => $this->getSlowActionsLabel(), |
96 | 96 | 'blackbar' => $this->app, |
@@ -101,65 +101,65 @@ discard block |
||
101 | 101 | 'queries' => $this->getQueries(), |
102 | 102 | 'queriesLabel' => $this->getQueriesLabel(), |
103 | 103 | 'templates' => $this->getTemplates(), |
104 | - ]); |
|
104 | + ] ); |
|
105 | 105 | } |
106 | 106 | |
107 | - protected function convertToMiliseconds(float $time, int $decimals = 2): string |
|
107 | + protected function convertToMiliseconds( float $time, int $decimals = 2 ): string |
|
108 | 108 | { |
109 | - return number_format($time * 1000, $decimals); |
|
109 | + return number_format( $time * 1000, $decimals ); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | protected function getConsoleEntries(): array |
113 | 113 | { |
114 | - return array_merge($this->getErrors(), $this->app->console->entries); |
|
114 | + return array_merge( $this->getErrors(), $this->app->console->entries ); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | protected function getConsoleLabel(): string |
118 | 118 | { |
119 | 119 | $class = ''; |
120 | 120 | $entries = $this->getConsoleEntries(); |
121 | - $entryCount = count($entries); |
|
121 | + $entryCount = count( $entries ); |
|
122 | 122 | $errorCount = 0; |
123 | - $label = __('Console', 'blackbar'); |
|
124 | - foreach ($entries as $entry) { |
|
125 | - if (in_array($entry['code'], [E_NOTICE, E_STRICT, E_DEPRECATED])) { |
|
123 | + $label = __( 'Console', 'blackbar' ); |
|
124 | + foreach( $entries as $entry ) { |
|
125 | + if( in_array( $entry[ 'code' ], [ E_NOTICE, E_STRICT, E_DEPRECATED ] ) ) { |
|
126 | 126 | $class = 'glbb-warning'; |
127 | 127 | } |
128 | - if (in_array($entry['code'], [E_WARNING])) { |
|
128 | + if( in_array( $entry[ 'code' ], [ E_WARNING ] ) ) { |
|
129 | 129 | ++$errorCount; |
130 | 130 | } |
131 | 131 | } |
132 | - if ($entryCount > 0) { |
|
133 | - $label .= sprintf(' (%d)', $entryCount); |
|
132 | + if( $entryCount > 0 ) { |
|
133 | + $label .= sprintf( ' (%d)', $entryCount ); |
|
134 | 134 | } |
135 | - if ($errorCount > 0) { |
|
135 | + if( $errorCount > 0 ) { |
|
136 | 136 | $class = 'glbb-error'; |
137 | - $label .= sprintf(' (%d, %d!)', $entryCount, $errorCount); |
|
137 | + $label .= sprintf( ' (%d, %d!)', $entryCount, $errorCount ); |
|
138 | 138 | } |
139 | - return sprintf('<span class="%s">%s</span>', $class, $label); |
|
139 | + return sprintf( '<span class="%s">%s</span>', $class, $label ); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | protected function getErrors(): array |
143 | 143 | { |
144 | - $errors = []; |
|
145 | - foreach ($this->app->errors as $error) { |
|
144 | + $errors = [ ]; |
|
145 | + foreach( $this->app->errors as $error ) { |
|
146 | 146 | $class = 'glbb-info'; |
147 | - if (in_array($error['code'], [E_NOTICE, E_STRICT, E_DEPRECATED])) { |
|
147 | + if( in_array( $error[ 'code' ], [ E_NOTICE, E_STRICT, E_DEPRECATED ] ) ) { |
|
148 | 148 | $class = 'glbb-warning'; |
149 | 149 | } |
150 | - if (E_WARNING == $error['code']) { |
|
150 | + if( E_WARNING == $error[ 'code' ] ) { |
|
151 | 151 | $class = 'glbb-error'; |
152 | 152 | } |
153 | - if ($error['count'] > 1) { |
|
154 | - $error['name'] .= ' ('.$error['count'].')'; |
|
153 | + if( $error[ 'count' ] > 1 ) { |
|
154 | + $error[ 'name' ] .= ' (' . $error[ 'count' ] . ')'; |
|
155 | 155 | } |
156 | - $errors[] = [ |
|
157 | - 'code' => $error['code'], |
|
158 | - 'name' => '<span class="'.$class.'">'.$error['name'].'</span>', |
|
159 | - 'message' => sprintf(__('%s on line %s in file %s', 'blackbar'), |
|
160 | - $error['message'], |
|
161 | - $error['line'], |
|
162 | - $error['file'] |
|
156 | + $errors[ ] = [ |
|
157 | + 'code' => $error[ 'code' ], |
|
158 | + 'name' => '<span class="' . $class . '">' . $error[ 'name' ] . '</span>', |
|
159 | + 'message' => sprintf( __( '%s on line %s in file %s', 'blackbar' ), |
|
160 | + $error[ 'message' ], |
|
161 | + $error[ 'line' ], |
|
162 | + $error[ 'file' ] |
|
163 | 163 | ), |
164 | 164 | ]; |
165 | 165 | } |
@@ -168,22 +168,22 @@ discard block |
||
168 | 168 | |
169 | 169 | protected function getIncludedFiles(): array |
170 | 170 | { |
171 | - $files = array_values(array_filter(get_included_files(), function ($file) { |
|
172 | - $bool = false !== strpos($file, '/themes/') && false === strpos($file, '/functions.php'); |
|
173 | - return (bool) apply_filters('blackbar/templates/file', $bool, $file); |
|
174 | - })); |
|
175 | - return array_map(function ($key, $value) { |
|
176 | - $value = str_replace(trailingslashit(WP_CONTENT_DIR), '', $value); |
|
177 | - return sprintf('[%s] => %s', $key, $value); |
|
178 | - }, array_keys($files), $files); |
|
171 | + $files = array_values( array_filter( get_included_files(), function( $file ) { |
|
172 | + $bool = false !== strpos( $file, '/themes/' ) && false === strpos( $file, '/functions.php' ); |
|
173 | + return (bool) apply_filters( 'blackbar/templates/file', $bool, $file ); |
|
174 | + }) ); |
|
175 | + return array_map( function( $key, $value ) { |
|
176 | + $value = str_replace( trailingslashit( WP_CONTENT_DIR ), '', $value ); |
|
177 | + return sprintf( '[%s] => %s', $key, $value ); |
|
178 | + }, array_keys( $files ), $files ); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | protected function getProfilerLabel(): string |
182 | 182 | { |
183 | - $label = __('Profiler', 'blackbar'); |
|
184 | - $profilerTime = $this->convertToMiliseconds($this->app->profiler->getTotalTime(), 0); |
|
185 | - if ($profilerTime > 0) { |
|
186 | - $label .= sprintf(' (%s %s)', $profilerTime, __('ms', 'blackbar')); |
|
183 | + $label = __( 'Profiler', 'blackbar' ); |
|
184 | + $profilerTime = $this->convertToMiliseconds( $this->app->profiler->getTotalTime(), 0 ); |
|
185 | + if( $profilerTime > 0 ) { |
|
186 | + $label .= sprintf( ' (%s %s)', $profilerTime, __( 'ms', 'blackbar' ) ); |
|
187 | 187 | } |
188 | 188 | return $label; |
189 | 189 | } |
@@ -191,20 +191,20 @@ discard block |
||
191 | 191 | protected function getQueries(): array |
192 | 192 | { |
193 | 193 | global $wpdb; |
194 | - $queries = []; |
|
194 | + $queries = [ ]; |
|
195 | 195 | $search = [ |
196 | 196 | 'AND', 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT', |
197 | 197 | 'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE', |
198 | 198 | ]; |
199 | - $replace = array_map(function ($value) { |
|
200 | - return PHP_EOL.$value; |
|
201 | - }, $search); |
|
202 | - foreach ($wpdb->queries as $query) { |
|
203 | - $miliseconds = number_format(round($query[1] * 1000, 4), 4); |
|
204 | - $sql = preg_replace('/\s\s+/', ' ', trim($query[0])); |
|
205 | - $sql = str_replace(PHP_EOL, ' ', $sql); |
|
206 | - $sql = str_replace($search, $replace, $sql); |
|
207 | - $queries[] = [ |
|
199 | + $replace = array_map( function( $value ) { |
|
200 | + return PHP_EOL . $value; |
|
201 | + }, $search ); |
|
202 | + foreach( $wpdb->queries as $query ) { |
|
203 | + $miliseconds = number_format( round( $query[ 1 ] * 1000, 4 ), 4 ); |
|
204 | + $sql = preg_replace( '/\s\s+/', ' ', trim( $query[ 0 ] ) ); |
|
205 | + $sql = str_replace( PHP_EOL, ' ', $sql ); |
|
206 | + $sql = str_replace( $search, $replace, $sql ); |
|
207 | + $queries[ ] = [ |
|
208 | 208 | 'ms' => $miliseconds, |
209 | 209 | 'sql' => $sql, |
210 | 210 | ]; |
@@ -214,40 +214,40 @@ discard block |
||
214 | 214 | |
215 | 215 | protected function getQueriesLabel(): string |
216 | 216 | { |
217 | - $label = __('SQL', 'blackbar'); |
|
218 | - if (!SAVEQUERIES) { |
|
217 | + $label = __( 'SQL', 'blackbar' ); |
|
218 | + if( !SAVEQUERIES ) { |
|
219 | 219 | return $label; |
220 | 220 | } |
221 | 221 | global $wpdb; |
222 | 222 | $queryTime = 0; |
223 | - foreach ($wpdb->queries as $query) { |
|
224 | - $queryTime += $query[1]; |
|
223 | + foreach( $wpdb->queries as $query ) { |
|
224 | + $queryTime += $query[ 1 ]; |
|
225 | 225 | } |
226 | - $queriesCount = sprintf('<span class="glbb-queries-count">%s</span>', count($wpdb->queries)); |
|
227 | - $queriesTime = sprintf('<span class="glbb-queries-time">%s</span>', $this->convertToMiliseconds((float) $queryTime)); |
|
228 | - return $label.sprintf(' (%s %s | %s %s)', $queriesCount, __('queries', 'blackbar'), $queriesTime, __('ms', 'blackbar')); |
|
226 | + $queriesCount = sprintf( '<span class="glbb-queries-count">%s</span>', count( $wpdb->queries ) ); |
|
227 | + $queriesTime = sprintf( '<span class="glbb-queries-time">%s</span>', $this->convertToMiliseconds( (float) $queryTime ) ); |
|
228 | + return $label . sprintf( ' (%s %s | %s %s)', $queriesCount, __( 'queries', 'blackbar' ), $queriesTime, __( 'ms', 'blackbar' ) ); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | protected function getSlowActionsLabel(): string |
232 | 232 | { |
233 | - $label = __('Hooks', 'blackbar'); |
|
234 | - $totalTime = $this->convertToMiliseconds($this->app->actions->getTotalTime(), 0); |
|
235 | - if ($totalTime > 0) { |
|
236 | - $label .= sprintf(' (%s %s)', $totalTime, __('ms', 'blackbar')); |
|
233 | + $label = __( 'Hooks', 'blackbar' ); |
|
234 | + $totalTime = $this->convertToMiliseconds( $this->app->actions->getTotalTime(), 0 ); |
|
235 | + if( $totalTime > 0 ) { |
|
236 | + $label .= sprintf( ' (%s %s)', $totalTime, __( 'ms', 'blackbar' ) ); |
|
237 | 237 | } |
238 | 238 | return $label; |
239 | 239 | } |
240 | 240 | |
241 | 241 | protected function getTemplates(): string |
242 | 242 | { |
243 | - if (is_admin()) { |
|
243 | + if( is_admin() ) { |
|
244 | 244 | return ''; |
245 | 245 | } |
246 | - if (class_exists('\GeminiLabs\Castor\Facades\Development')) { |
|
246 | + if( class_exists( '\GeminiLabs\Castor\Facades\Development' ) ) { |
|
247 | 247 | ob_start(); |
248 | 248 | \GeminiLabs\Castor\Facades\Development::printTemplatePaths(); |
249 | 249 | return ob_get_clean(); |
250 | 250 | } |
251 | - return sprintf('<pre>%s</pre>', implode(PHP_EOL, $this->getIncludedFiles())); |
|
251 | + return sprintf( '<pre>%s</pre>', implode( PHP_EOL, $this->getIncludedFiles() ) ); |
|
252 | 252 | } |
253 | 253 | } |
@@ -168,11 +168,13 @@ discard block |
||
168 | 168 | |
169 | 169 | protected function getIncludedFiles(): array |
170 | 170 | { |
171 | - $files = array_values(array_filter(get_included_files(), function ($file) { |
|
171 | + $files = array_values(array_filter(get_included_files(), function ($file) |
|
172 | + { |
|
172 | 173 | $bool = false !== strpos($file, '/themes/') && false === strpos($file, '/functions.php'); |
173 | 174 | return (bool) apply_filters('blackbar/templates/file', $bool, $file); |
174 | 175 | })); |
175 | - return array_map(function ($key, $value) { |
|
176 | + return array_map(function ($key, $value) |
|
177 | + { |
|
176 | 178 | $value = str_replace(trailingslashit(WP_CONTENT_DIR), '', $value); |
177 | 179 | return sprintf('[%s] => %s', $key, $value); |
178 | 180 | }, array_keys($files), $files); |
@@ -196,7 +198,8 @@ discard block |
||
196 | 198 | 'AND', 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT', |
197 | 199 | 'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE', |
198 | 200 | ]; |
199 | - $replace = array_map(function ($value) { |
|
201 | + $replace = array_map(function ($value) |
|
202 | + { |
|
200 | 203 | return PHP_EOL.$value; |
201 | 204 | }, $search); |
202 | 205 | foreach ($wpdb->queries as $query) { |
@@ -6,58 +6,58 @@ |
||
6 | 6 | |
7 | 7 | class Console |
8 | 8 | { |
9 | - const ERROR_CODES = [ |
|
10 | - E_ERROR => 'Error', // 1 |
|
11 | - E_WARNING => 'Warning', // 2 |
|
12 | - E_NOTICE => 'Notice', // 8 |
|
13 | - E_STRICT => 'Strict', // 2048 |
|
14 | - E_DEPRECATED => 'Deprecated', // 8192 |
|
15 | - ]; |
|
9 | + const ERROR_CODES = [ |
|
10 | + E_ERROR => 'Error', // 1 |
|
11 | + E_WARNING => 'Warning', // 2 |
|
12 | + E_NOTICE => 'Notice', // 8 |
|
13 | + E_STRICT => 'Strict', // 2048 |
|
14 | + E_DEPRECATED => 'Deprecated', // 8192 |
|
15 | + ]; |
|
16 | 16 | |
17 | - const MAPPED_ERROR_CODES = [ |
|
18 | - 'debug' => 0, |
|
19 | - 'info' => 0, |
|
20 | - 'notice' => 0, |
|
21 | - 'warning' => E_NOTICE, // 8 |
|
22 | - 'error' => E_WARNING, // 2 |
|
23 | - 'critical' => E_WARNING, // 2 |
|
24 | - 'alert' => E_WARNING, // 2 |
|
25 | - 'emergency' => E_WARNING, // 2 |
|
26 | - ]; |
|
17 | + const MAPPED_ERROR_CODES = [ |
|
18 | + 'debug' => 0, |
|
19 | + 'info' => 0, |
|
20 | + 'notice' => 0, |
|
21 | + 'warning' => E_NOTICE, // 8 |
|
22 | + 'error' => E_WARNING, // 2 |
|
23 | + 'critical' => E_WARNING, // 2 |
|
24 | + 'alert' => E_WARNING, // 2 |
|
25 | + 'emergency' => E_WARNING, // 2 |
|
26 | + ]; |
|
27 | 27 | |
28 | - public $entries = []; |
|
28 | + public $entries = []; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @param int|string $errno |
|
32 | - * @return static |
|
33 | - */ |
|
34 | - public function store(string $message, $errno = 0, string $location = '') |
|
35 | - { |
|
36 | - $errname = 'Debug'; |
|
37 | - if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { |
|
38 | - $errname = ucfirst($errno); |
|
39 | - $errno = static::MAPPED_ERROR_CODES[$errno]; |
|
40 | - } elseif (array_key_exists($errno, static::ERROR_CODES)) { |
|
41 | - $errname = static::ERROR_CODES[$errno]; |
|
42 | - } |
|
43 | - $this->entries[] = [ |
|
44 | - 'errno' => $errno, |
|
45 | - 'message' => $location.$this->normalizeValue($message), |
|
46 | - 'name' => sprintf('<span class="glbb-info glbb-%s">%s</span>', strtolower($errname), $errname), |
|
47 | - ]; |
|
48 | - return $this; |
|
49 | - } |
|
30 | + /** |
|
31 | + * @param int|string $errno |
|
32 | + * @return static |
|
33 | + */ |
|
34 | + public function store(string $message, $errno = 0, string $location = '') |
|
35 | + { |
|
36 | + $errname = 'Debug'; |
|
37 | + if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { |
|
38 | + $errname = ucfirst($errno); |
|
39 | + $errno = static::MAPPED_ERROR_CODES[$errno]; |
|
40 | + } elseif (array_key_exists($errno, static::ERROR_CODES)) { |
|
41 | + $errname = static::ERROR_CODES[$errno]; |
|
42 | + } |
|
43 | + $this->entries[] = [ |
|
44 | + 'errno' => $errno, |
|
45 | + 'message' => $location.$this->normalizeValue($message), |
|
46 | + 'name' => sprintf('<span class="glbb-info glbb-%s">%s</span>', strtolower($errname), $errname), |
|
47 | + ]; |
|
48 | + return $this; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param mixed $value |
|
53 | - */ |
|
54 | - protected function normalizeValue($value): string |
|
55 | - { |
|
56 | - if ($value instanceof DateTime) { |
|
57 | - $value = $value->format('Y-m-d H:i:s'); |
|
58 | - } elseif (is_object($value) || is_array($value)) { |
|
59 | - $value = print_r(json_decode(json_encode($value)), true); |
|
60 | - } |
|
61 | - return esc_html((string) $value); |
|
62 | - } |
|
51 | + /** |
|
52 | + * @param mixed $value |
|
53 | + */ |
|
54 | + protected function normalizeValue($value): string |
|
55 | + { |
|
56 | + if ($value instanceof DateTime) { |
|
57 | + $value = $value->format('Y-m-d H:i:s'); |
|
58 | + } elseif (is_object($value) || is_array($value)) { |
|
59 | + $value = print_r(json_decode(json_encode($value)), true); |
|
60 | + } |
|
61 | + return esc_html((string) $value); |
|
62 | + } |
|
63 | 63 | } |
@@ -25,25 +25,25 @@ discard block |
||
25 | 25 | 'emergency' => E_WARNING, // 2 |
26 | 26 | ]; |
27 | 27 | |
28 | - public $entries = []; |
|
28 | + public $entries = [ ]; |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * @param int|string $errno |
32 | 32 | * @return static |
33 | 33 | */ |
34 | - public function store(string $message, $errno = 0, string $location = '') |
|
34 | + public function store( string $message, $errno = 0, string $location = '' ) |
|
35 | 35 | { |
36 | 36 | $errname = 'Debug'; |
37 | - if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { |
|
38 | - $errname = ucfirst($errno); |
|
39 | - $errno = static::MAPPED_ERROR_CODES[$errno]; |
|
40 | - } elseif (array_key_exists($errno, static::ERROR_CODES)) { |
|
41 | - $errname = static::ERROR_CODES[$errno]; |
|
37 | + if( array_key_exists( $errno, static::MAPPED_ERROR_CODES ) ) { |
|
38 | + $errname = ucfirst( $errno ); |
|
39 | + $errno = static::MAPPED_ERROR_CODES[ $errno ]; |
|
40 | + } elseif( array_key_exists( $errno, static::ERROR_CODES ) ) { |
|
41 | + $errname = static::ERROR_CODES[ $errno ]; |
|
42 | 42 | } |
43 | - $this->entries[] = [ |
|
43 | + $this->entries[ ] = [ |
|
44 | 44 | 'errno' => $errno, |
45 | - 'message' => $location.$this->normalizeValue($message), |
|
46 | - 'name' => sprintf('<span class="glbb-info glbb-%s">%s</span>', strtolower($errname), $errname), |
|
45 | + 'message' => $location . $this->normalizeValue( $message ), |
|
46 | + 'name' => sprintf( '<span class="glbb-info glbb-%s">%s</span>', strtolower( $errname ), $errname ), |
|
47 | 47 | ]; |
48 | 48 | return $this; |
49 | 49 | } |
@@ -51,13 +51,13 @@ discard block |
||
51 | 51 | /** |
52 | 52 | * @param mixed $value |
53 | 53 | */ |
54 | - protected function normalizeValue($value): string |
|
54 | + protected function normalizeValue( $value ): string |
|
55 | 55 | { |
56 | - if ($value instanceof DateTime) { |
|
57 | - $value = $value->format('Y-m-d H:i:s'); |
|
58 | - } elseif (is_object($value) || is_array($value)) { |
|
59 | - $value = print_r(json_decode(json_encode($value)), true); |
|
56 | + if( $value instanceof DateTime ) { |
|
57 | + $value = $value->format( 'Y-m-d H:i:s' ); |
|
58 | + } elseif( is_object( $value ) || is_array( $value ) ) { |
|
59 | + $value = print_r( json_decode( json_encode( $value ) ), true ); |
|
60 | 60 | } |
61 | - return esc_html((string) $value); |
|
61 | + return esc_html( (string) $value ); |
|
62 | 62 | } |
63 | 63 | } |
@@ -37,7 +37,8 @@ discard block |
||
37 | 37 | if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { |
38 | 38 | $errname = ucfirst($errno); |
39 | 39 | $errno = static::MAPPED_ERROR_CODES[$errno]; |
40 | - } elseif (array_key_exists($errno, static::ERROR_CODES)) { |
|
40 | + } |
|
41 | + elseif (array_key_exists($errno, static::ERROR_CODES)) { |
|
41 | 42 | $errname = static::ERROR_CODES[$errno]; |
42 | 43 | } |
43 | 44 | $this->entries[] = [ |
@@ -55,7 +56,8 @@ discard block |
||
55 | 56 | { |
56 | 57 | if ($value instanceof DateTime) { |
57 | 58 | $value = $value->format('Y-m-d H:i:s'); |
58 | - } elseif (is_object($value) || is_array($value)) { |
|
59 | + } |
|
60 | + elseif (is_object($value) || is_array($value)) { |
|
59 | 61 | $value = print_r(json_decode(json_encode($value)), true); |
60 | 62 | } |
61 | 63 | return esc_html((string) $value); |