@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | |
17 | 17 | public function __construct() |
18 | 18 | { |
19 | - $this->file = realpath( dirname( __DIR__ ).'/'.static::ID.'.php' ); |
|
19 | + $this->file = realpath(dirname(__DIR__).'/'.static::ID.'.php'); |
|
20 | 20 | $this->profiler = new Profiler; |
21 | 21 | } |
22 | 22 | |
@@ -27,9 +27,9 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function enqueueAssets() |
29 | 29 | { |
30 | - wp_enqueue_script( static::ID, $this->url( 'assets/main.js' )); |
|
31 | - wp_enqueue_style( static::ID, $this->url( 'assets/main.css' ), array( 'dashicons' )); |
|
32 | - wp_enqueue_style( static::ID.'-syntax', $this->url( 'assets/syntax.css' )); |
|
30 | + wp_enqueue_script(static::ID, $this->url('assets/main.js')); |
|
31 | + wp_enqueue_style(static::ID, $this->url('assets/main.css'), array('dashicons')); |
|
32 | + wp_enqueue_style(static::ID.'-syntax', $this->url('assets/syntax.css')); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * @param int $errline |
40 | 40 | * @return void |
41 | 41 | */ |
42 | - public function errorHandler( $errno, $errstr, $errfile, $errline ) |
|
42 | + public function errorHandler($errno, $errstr, $errfile, $errline) |
|
43 | 43 | { |
44 | 44 | $errorCodes = array( |
45 | 45 | 2 => 'Warning', |
@@ -47,11 +47,11 @@ discard block |
||
47 | 47 | 2048 => 'Strict', |
48 | 48 | 8192 => 'Deprecated', |
49 | 49 | ); |
50 | - $errname = array_key_exists( $errno, $errorCodes ) |
|
50 | + $errname = array_key_exists($errno, $errorCodes) |
|
51 | 51 | ? $errorCodes[$errno] |
52 | 52 | : 'Unknown'; |
53 | - $hash = md5( $errno.$errstr.$errfile.$errline ); |
|
54 | - if( array_key_exists( $hash, $this->errors )) { |
|
53 | + $hash = md5($errno.$errstr.$errfile.$errline); |
|
54 | + if (array_key_exists($hash, $this->errors)) { |
|
55 | 55 | $this->errors[$hash]['count']++; |
56 | 56 | } |
57 | 57 | else { |
@@ -70,15 +70,15 @@ discard block |
||
70 | 70 | * @param string $classes |
71 | 71 | * @return string |
72 | 72 | */ |
73 | - public function filterBodyClasses( $classes ) |
|
73 | + public function filterBodyClasses($classes) |
|
74 | 74 | { |
75 | - return trim( $classes.' '.static::ID ); |
|
75 | + return trim($classes.' '.static::ID); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * @return array |
80 | 80 | */ |
81 | - public function filterNoconflictScripts( $scripts ) |
|
81 | + public function filterNoconflictScripts($scripts) |
|
82 | 82 | { |
83 | 83 | $scripts[] = static::ID; |
84 | 84 | return $scripts; |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | /** |
88 | 88 | * @return array |
89 | 89 | */ |
90 | - public function filterNoconflictStyles( $styles ) |
|
90 | + public function filterNoconflictStyles($styles) |
|
91 | 91 | { |
92 | 92 | $styles[] = static::ID; |
93 | 93 | $styles[] = static::ID.'-syntax'; |
@@ -99,18 +99,18 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function init() |
101 | 101 | { |
102 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueueAssets' )); |
|
103 | - add_action( 'admin_footer', array( $this, 'renderBar' )); |
|
104 | - add_action( 'plugins_loaded', array( $this, 'registerLanguages' )); |
|
105 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueueAssets' )); |
|
106 | - add_action( 'wp_footer', array( $this, 'renderBar' )); |
|
107 | - add_filter( 'admin_body_class', array( $this, 'filterBodyClasses' )); |
|
108 | - add_filter( 'all', array( $this, 'initProfiler' )); |
|
109 | - add_filter( 'gform_noconflict_scripts', array( $this, 'filterNoconflictScripts' ) ); |
|
110 | - add_filter( 'gform_noconflict_styles', array( $this, 'filterNoconflictStyles' ) ); |
|
111 | - apply_filters( 'debug', 'Profiler Initiated' ); |
|
112 | - apply_filters( 'debug', 'Profiler Noise' ); |
|
113 | - set_error_handler( array( $this, 'errorHandler' ), E_ALL|E_STRICT ); |
|
102 | + add_action('admin_enqueue_scripts', array($this, 'enqueueAssets')); |
|
103 | + add_action('admin_footer', array($this, 'renderBar')); |
|
104 | + add_action('plugins_loaded', array($this, 'registerLanguages')); |
|
105 | + add_action('wp_enqueue_scripts', array($this, 'enqueueAssets')); |
|
106 | + add_action('wp_footer', array($this, 'renderBar')); |
|
107 | + add_filter('admin_body_class', array($this, 'filterBodyClasses')); |
|
108 | + add_filter('all', array($this, 'initProfiler')); |
|
109 | + add_filter('gform_noconflict_scripts', array($this, 'filterNoconflictScripts')); |
|
110 | + add_filter('gform_noconflict_styles', array($this, 'filterNoconflictStyles')); |
|
111 | + apply_filters('debug', 'Profiler Initiated'); |
|
112 | + apply_filters('debug', 'Profiler Noise'); |
|
113 | + set_error_handler(array($this, 'errorHandler'), E_ALL|E_STRICT); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function initProfiler() |
121 | 121 | { |
122 | - if( func_get_arg(0) != static::DEBUG )return; |
|
123 | - $this->profiler->trace( func_get_arg(1) ); |
|
122 | + if (func_get_arg(0) != static::DEBUG)return; |
|
123 | + $this->profiler->trace(func_get_arg(1)); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | */ |
129 | 129 | public function registerLanguages() |
130 | 130 | { |
131 | - load_plugin_textdomain( static::ID, false, plugin_basename( $this->path() ).static::LANG ); |
|
131 | + load_plugin_textdomain(static::ID, false, plugin_basename($this->path()).static::LANG); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -137,11 +137,11 @@ discard block |
||
137 | 137 | * @param string $view |
138 | 138 | * @return void |
139 | 139 | */ |
140 | - public function render( $view, array $data = array() ) |
|
140 | + public function render($view, array $data = array()) |
|
141 | 141 | { |
142 | - $file = $this->path( sprintf( 'views/%s.php', str_replace( '.php', '', $view ))); |
|
143 | - if( !file_exists( $file ))return; |
|
144 | - extract( $data ); |
|
142 | + $file = $this->path(sprintf('views/%s.php', str_replace('.php', '', $view))); |
|
143 | + if (!file_exists($file))return; |
|
144 | + extract($data); |
|
145 | 145 | include $file; |
146 | 146 | } |
147 | 147 | |
@@ -152,8 +152,8 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function renderBar() |
154 | 154 | { |
155 | - apply_filters( 'debug', 'Profiler Stopped' ); |
|
156 | - $this->render( 'debug-bar', array( |
|
155 | + apply_filters('debug', 'Profiler Stopped'); |
|
156 | + $this->render('debug-bar', array( |
|
157 | 157 | 'blackbar' => $this, |
158 | 158 | 'errors' => $this->getErrors(), |
159 | 159 | 'errorsLabel' => $this->getErrorsLabel(), |
@@ -167,9 +167,9 @@ discard block |
||
167 | 167 | /** |
168 | 168 | * @return string |
169 | 169 | */ |
170 | - protected function convertToMiliseconds( $time, $decimals = 2 ) |
|
170 | + protected function convertToMiliseconds($time, $decimals = 2) |
|
171 | 171 | { |
172 | - return number_format( $time * 1000, $decimals ); |
|
172 | + return number_format($time * 1000, $decimals); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -178,16 +178,16 @@ discard block |
||
178 | 178 | protected function getErrors() |
179 | 179 | { |
180 | 180 | $errors = array(); |
181 | - foreach( $this->errors as $error ) { |
|
182 | - if( $error['errno'] == E_WARNING ) { |
|
181 | + foreach ($this->errors as $error) { |
|
182 | + if ($error['errno'] == E_WARNING) { |
|
183 | 183 | $error['name'] = '<span class="glbb-error">'.$error['name'].'</span>'; |
184 | 184 | } |
185 | - if( $error['count'] > 1 ) { |
|
185 | + if ($error['count'] > 1) { |
|
186 | 186 | $error['name'] .= ' ('.$error['count'].')'; |
187 | 187 | } |
188 | 188 | $errors[] = array( |
189 | 189 | 'name' => $error['name'], |
190 | - 'message' => sprintf( __( '%s on line %s in file %s', 'blackbar' ), |
|
190 | + 'message' => sprintf(__('%s on line %s in file %s', 'blackbar'), |
|
191 | 191 | $error['message'], |
192 | 192 | $error['line'], |
193 | 193 | $error['file'] |
@@ -203,14 +203,14 @@ discard block |
||
203 | 203 | protected function getErrorsLabel() |
204 | 204 | { |
205 | 205 | $warningCount = 0; |
206 | - foreach( $this->errors as $error ) { |
|
207 | - if( $error['errno'] == E_WARNING ) { |
|
206 | + foreach ($this->errors as $error) { |
|
207 | + if ($error['errno'] == E_WARNING) { |
|
208 | 208 | $warningCount++; |
209 | 209 | } |
210 | 210 | } |
211 | - $errorCount = count( $this->errors ); |
|
212 | - $warnings = $warningCount > 0 ? sprintf( ', %d!', $warningCount ) : ''; |
|
213 | - return sprintf( __( 'Errors (%d%s)', 'blackbar' ), $errorCount, $warnings ); |
|
211 | + $errorCount = count($this->errors); |
|
212 | + $warnings = $warningCount > 0 ? sprintf(', %d!', $warningCount) : ''; |
|
213 | + return sprintf(__('Errors (%d%s)', 'blackbar'), $errorCount, $warnings); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
@@ -218,8 +218,8 @@ discard block |
||
218 | 218 | */ |
219 | 219 | protected function getProfilerLabel() |
220 | 220 | { |
221 | - $profilerTime = $this->convertToMiliseconds( $this->profiler->getTotalTime(), 0 ); |
|
222 | - return sprintf( __( 'Profiler (%s ms)', 'blackbar' ), $profilerTime ); |
|
221 | + $profilerTime = $this->convertToMiliseconds($this->profiler->getTotalTime(), 0); |
|
222 | + return sprintf(__('Profiler (%s ms)', 'blackbar'), $profilerTime); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
@@ -240,14 +240,14 @@ discard block |
||
240 | 240 | 'SET', |
241 | 241 | 'WHERE', |
242 | 242 | ); |
243 | - $replace = array_map( function( $value ) { |
|
243 | + $replace = array_map(function($value) { |
|
244 | 244 | return PHP_EOL.$value; |
245 | - }, $search ); |
|
246 | - foreach( $wpdb->queries as $query ) { |
|
247 | - $miliseconds = number_format( round( $query[1] * 1000, 4 ), 4 ); |
|
248 | - $sql = preg_replace( '/\s\s+/', ' ', trim( $query[0] )); |
|
249 | - $sql = str_replace( PHP_EOL, ' ', $sql ); |
|
250 | - $sql = str_replace( $search, $replace, $sql ); |
|
245 | + }, $search); |
|
246 | + foreach ($wpdb->queries as $query) { |
|
247 | + $miliseconds = number_format(round($query[1] * 1000, 4), 4); |
|
248 | + $sql = preg_replace('/\s\s+/', ' ', trim($query[0])); |
|
249 | + $sql = str_replace(PHP_EOL, ' ', $sql); |
|
250 | + $sql = str_replace($search, $replace, $sql); |
|
251 | 251 | $queries[] = array( |
252 | 252 | 'ms' => $miliseconds, |
253 | 253 | 'sql' => $sql, |
@@ -263,29 +263,29 @@ discard block |
||
263 | 263 | { |
264 | 264 | global $wpdb; |
265 | 265 | $queryTime = 0; |
266 | - foreach( $wpdb->queries as $query ) { |
|
266 | + foreach ($wpdb->queries as $query) { |
|
267 | 267 | $queryTime += $query[1]; |
268 | 268 | } |
269 | - $queriesCount = '<span class="glbb-queries-count">'.count( $wpdb->queries ).'</span>'; |
|
270 | - $queriesTime = '<span class="glbb-queries-time">'.$this->convertToMiliseconds( $queryTime ).'</span>'; |
|
271 | - return sprintf( __( 'SQL (%s queries in %s ms)', 'blackbar' ), $queriesCount, $queriesTime ); |
|
269 | + $queriesCount = '<span class="glbb-queries-count">'.count($wpdb->queries).'</span>'; |
|
270 | + $queriesTime = '<span class="glbb-queries-time">'.$this->convertToMiliseconds($queryTime).'</span>'; |
|
271 | + return sprintf(__('SQL (%s queries in %s ms)', 'blackbar'), $queriesCount, $queriesTime); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
275 | 275 | * @param string $file |
276 | 276 | * @return string |
277 | 277 | */ |
278 | - protected function path( $file = '' ) |
|
278 | + protected function path($file = '') |
|
279 | 279 | { |
280 | - return plugin_dir_path( $this->file ).ltrim( trim( $file ), '/' ); |
|
280 | + return plugin_dir_path($this->file).ltrim(trim($file), '/'); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | /** |
284 | 284 | * @param string $path |
285 | 285 | * @return string |
286 | 286 | */ |
287 | - protected function url( $path = '' ) |
|
287 | + protected function url($path = '') |
|
288 | 288 | { |
289 | - return esc_url( plugin_dir_url( $this->file ) . ltrim( trim( $path ), '/' )); |
|
289 | + return esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
290 | 290 | } |
291 | 291 | } |