Passed
Push — master ( 630338...867876 )
by Paul
03:16
created
plugin/Controller.php 3 patches
Indentation   +248 added lines, -248 removed lines patch added patch discarded remove patch
@@ -4,252 +4,252 @@
 block discarded – undo
4 4
 
5 5
 class Controller
6 6
 {
7
-    /**
8
-     * @var Application
9
-     */
10
-    protected $app;
11
-
12
-    public function __construct(Application $app)
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
-            return;
65
-        }
66
-        $this->app->profiler->trace(func_get_arg(1));
67
-    }
68
-
69
-    /**
70
-     * @filter all
71
-     */
72
-    public function measureSlowActions(): void
73
-    {
74
-        $this->app->actions->startTimer();
75
-    }
76
-
77
-    /**
78
-     * @action plugins_loaded
79
-     */
80
-    public function registerLanguages(): void
81
-    {
82
-        load_plugin_textdomain(Application::ID, false,
83
-            plugin_basename($this->app->path()).'/languages/'
84
-        );
85
-    }
86
-
87
-    /**
88
-     * @action admin_footer
89
-     * @action wp_footer
90
-     */
91
-    public function renderBar(): void
92
-    {
93
-        apply_filters('debug', 'Profiler Stopped');
94
-        $this->app->render('debug-bar', [
95
-            'actions' => $this->app->actions,
96
-            'actionsLabel' => $this->getSlowActionsLabel(),
97
-            'blackbar' => $this->app,
98
-            'consoleEntries' => $this->getConsoleEntries(),
99
-            'consoleLabel' => $this->getConsoleLabel(),
100
-            'profiler' => $this->app->profiler,
101
-            'profilerLabel' => $this->getProfilerLabel(),
102
-            'queries' => $this->getQueries(),
103
-            'queriesLabel' => $this->getQueriesLabel(),
104
-            'templates' => $this->getTemplates(),
105
-        ]);
106
-    }
107
-
108
-    protected function convertToMiliseconds(int $time, int $decimals = 2): string
109
-    {
110
-        return number_format($time * 1000, $decimals);
111
-    }
112
-
113
-    protected function getConsoleEntries(): array
114
-    {
115
-        return array_merge($this->getErrors(), $this->app->console->entries);
116
-    }
117
-
118
-    protected function getConsoleLabel(): string
119
-    {
120
-        $class = '';
121
-        $entries = $this->getConsoleEntries();
122
-        $entryCount = count($entries);
123
-        $errorCount = 0;
124
-        $label = __('Console', 'blackbar');
125
-        foreach ($entries as $entry) {
126
-            if (in_array($entry['code'], [E_NOTICE, E_STRICT, E_DEPRECATED])) {
127
-                $class = 'glbb-warning';
128
-            }
129
-            if (in_array($entry['code'], [E_WARNING])) {
130
-                ++$errorCount;
131
-            }
132
-        }
133
-        if ($entryCount > 0) {
134
-            $label .= sprintf(' (%d)', $entryCount);
135
-        }
136
-        if ($errorCount > 0) {
137
-            $class = 'glbb-error';
138
-            $label .= sprintf(' (%d, %d!)', $entryCount, $errorCount);
139
-        }
140
-        return sprintf('<span class="%s">%s</span>', $class, $label);
141
-    }
142
-
143
-    protected function getErrors(): array
144
-    {
145
-        $errors = [];
146
-        foreach ($this->app->errors as $error) {
147
-            $class = 'glbb-info';
148
-            if (in_array($error['code'], [E_NOTICE, E_STRICT, E_DEPRECATED])) {
149
-                $class = 'glbb-warning';
150
-            }
151
-            if (E_WARNING == $error['code']) {
152
-                $class = 'glbb-error';
153
-            }
154
-            if ($error['count'] > 1) {
155
-                $error['name'] .= ' ('.$error['count'].')';
156
-            }
157
-            $errors[] = [
158
-                'code' => $error['code'],
159
-                'name' => '<span class="'.$class.'">'.$error['name'].'</span>',
160
-                'message' => sprintf(__('%s on line %s in file %s', 'blackbar'),
161
-                    $error['message'],
162
-                    $error['line'],
163
-                    $error['file']
164
-                ),
165
-            ];
166
-        }
167
-        return $errors;
168
-    }
169
-
170
-    protected function getIncludedFiles(): array
171
-    {
172
-        $files = array_values(array_filter(get_included_files(), function ($file) {
173
-            $bool = false !== strpos($file, '/themes/')
174
-                && false === strpos($file, '/functions.php');
175
-            return (bool) apply_filters('blackbar/templates/file', $bool, $file);
176
-        }));
177
-        return array_map(function ($key, $value) {
178
-            $value = str_replace(trailingslashit(WP_CONTENT_DIR), '', $value);
179
-            return sprintf('[%s] => %s', $key, $value);
180
-        }, array_keys($files), $files);
181
-    }
182
-
183
-    protected function getProfilerLabel(): string
184
-    {
185
-        $label = __('Profiler', 'blackbar');
186
-        $profilerTime = $this->convertToMiliseconds($this->app->profiler->getTotalTime(), 0);
187
-        if ($profilerTime > 0) {
188
-            $label .= sprintf(' (%s %s)', $profilerTime, __('ms', 'blackbar'));
189
-        }
190
-        return $label;
191
-    }
192
-
193
-    protected function getQueries(): array
194
-    {
195
-        global $wpdb;
196
-        $queries = [];
197
-        $search = [
198
-            'AND', 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT',
199
-            'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE',
200
-        ];
201
-        $replace = array_map(function ($value) {
202
-            return PHP_EOL.$value;
203
-        }, $search);
204
-        foreach ($wpdb->queries as $query) {
205
-            $miliseconds = number_format(round($query[1] * 1000, 4), 4);
206
-            $sql = preg_replace('/\s\s+/', ' ', trim($query[0]));
207
-            $sql = str_replace(PHP_EOL, ' ', $sql);
208
-            $sql = str_replace($search, $replace, $sql);
209
-            $queries[] = [
210
-                'ms' => $miliseconds,
211
-                'sql' => $sql,
212
-            ];
213
-        }
214
-        return $queries;
215
-    }
216
-
217
-    protected function getQueriesLabel(): string
218
-    {
219
-        $label = __('SQL', 'blackbar');
220
-        if (!SAVEQUERIES) {
221
-            return $label;
222
-        }
223
-        global $wpdb;
224
-        $queryTime = 0;
225
-        foreach ($wpdb->queries as $query) {
226
-            $queryTime += $query[1];
227
-        }
228
-        $queriesCount = sprintf('<span class="glbb-queries-count">%s</span>', count($wpdb->queries));
229
-        $queriesTime = sprintf('<span class="glbb-queries-time">%s</span>', $this->convertToMiliseconds($queryTime));
230
-        return $label.sprintf(' (%s %s | %s %s)', $queriesCount, __('queries', 'blackbar'), $queriesTime, __('ms', 'blackbar'));
231
-    }
232
-
233
-    protected function getSlowActionsLabel(): string
234
-    {
235
-        $label = __('Hooks', 'blackbar');
236
-        $totalTime = $this->convertToMiliseconds($this->app->actions->getTotalTime(), 0);
237
-        if ($totalTime > 0) {
238
-            $label .= sprintf(' (%s %s)', $totalTime, __('ms', 'blackbar'));
239
-        }
240
-        return $label;
241
-    }
242
-
243
-    protected function getTemplates(): string
244
-    {
245
-        if (is_admin()) {
246
-            return '';
247
-        }
248
-        if (class_exists('\GeminiLabs\Castor\Facades\Development')) {
249
-            ob_start();
250
-            \GeminiLabs\Castor\Facades\Development::printTemplatePaths();
251
-            return ob_get_clean();
252
-        }
253
-        return sprintf('<pre>%s</pre>', implode(PHP_EOL, $this->getIncludedFiles()));
254
-    }
7
+	/**
8
+	 * @var Application
9
+	 */
10
+	protected $app;
11
+
12
+	public function __construct(Application $app)
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
+			return;
65
+		}
66
+		$this->app->profiler->trace(func_get_arg(1));
67
+	}
68
+
69
+	/**
70
+	 * @filter all
71
+	 */
72
+	public function measureSlowActions(): void
73
+	{
74
+		$this->app->actions->startTimer();
75
+	}
76
+
77
+	/**
78
+	 * @action plugins_loaded
79
+	 */
80
+	public function registerLanguages(): void
81
+	{
82
+		load_plugin_textdomain(Application::ID, false,
83
+			plugin_basename($this->app->path()).'/languages/'
84
+		);
85
+	}
86
+
87
+	/**
88
+	 * @action admin_footer
89
+	 * @action wp_footer
90
+	 */
91
+	public function renderBar(): void
92
+	{
93
+		apply_filters('debug', 'Profiler Stopped');
94
+		$this->app->render('debug-bar', [
95
+			'actions' => $this->app->actions,
96
+			'actionsLabel' => $this->getSlowActionsLabel(),
97
+			'blackbar' => $this->app,
98
+			'consoleEntries' => $this->getConsoleEntries(),
99
+			'consoleLabel' => $this->getConsoleLabel(),
100
+			'profiler' => $this->app->profiler,
101
+			'profilerLabel' => $this->getProfilerLabel(),
102
+			'queries' => $this->getQueries(),
103
+			'queriesLabel' => $this->getQueriesLabel(),
104
+			'templates' => $this->getTemplates(),
105
+		]);
106
+	}
107
+
108
+	protected function convertToMiliseconds(int $time, int $decimals = 2): string
109
+	{
110
+		return number_format($time * 1000, $decimals);
111
+	}
112
+
113
+	protected function getConsoleEntries(): array
114
+	{
115
+		return array_merge($this->getErrors(), $this->app->console->entries);
116
+	}
117
+
118
+	protected function getConsoleLabel(): string
119
+	{
120
+		$class = '';
121
+		$entries = $this->getConsoleEntries();
122
+		$entryCount = count($entries);
123
+		$errorCount = 0;
124
+		$label = __('Console', 'blackbar');
125
+		foreach ($entries as $entry) {
126
+			if (in_array($entry['code'], [E_NOTICE, E_STRICT, E_DEPRECATED])) {
127
+				$class = 'glbb-warning';
128
+			}
129
+			if (in_array($entry['code'], [E_WARNING])) {
130
+				++$errorCount;
131
+			}
132
+		}
133
+		if ($entryCount > 0) {
134
+			$label .= sprintf(' (%d)', $entryCount);
135
+		}
136
+		if ($errorCount > 0) {
137
+			$class = 'glbb-error';
138
+			$label .= sprintf(' (%d, %d!)', $entryCount, $errorCount);
139
+		}
140
+		return sprintf('<span class="%s">%s</span>', $class, $label);
141
+	}
142
+
143
+	protected function getErrors(): array
144
+	{
145
+		$errors = [];
146
+		foreach ($this->app->errors as $error) {
147
+			$class = 'glbb-info';
148
+			if (in_array($error['code'], [E_NOTICE, E_STRICT, E_DEPRECATED])) {
149
+				$class = 'glbb-warning';
150
+			}
151
+			if (E_WARNING == $error['code']) {
152
+				$class = 'glbb-error';
153
+			}
154
+			if ($error['count'] > 1) {
155
+				$error['name'] .= ' ('.$error['count'].')';
156
+			}
157
+			$errors[] = [
158
+				'code' => $error['code'],
159
+				'name' => '<span class="'.$class.'">'.$error['name'].'</span>',
160
+				'message' => sprintf(__('%s on line %s in file %s', 'blackbar'),
161
+					$error['message'],
162
+					$error['line'],
163
+					$error['file']
164
+				),
165
+			];
166
+		}
167
+		return $errors;
168
+	}
169
+
170
+	protected function getIncludedFiles(): array
171
+	{
172
+		$files = array_values(array_filter(get_included_files(), function ($file) {
173
+			$bool = false !== strpos($file, '/themes/')
174
+				&& false === strpos($file, '/functions.php');
175
+			return (bool) apply_filters('blackbar/templates/file', $bool, $file);
176
+		}));
177
+		return array_map(function ($key, $value) {
178
+			$value = str_replace(trailingslashit(WP_CONTENT_DIR), '', $value);
179
+			return sprintf('[%s] => %s', $key, $value);
180
+		}, array_keys($files), $files);
181
+	}
182
+
183
+	protected function getProfilerLabel(): string
184
+	{
185
+		$label = __('Profiler', 'blackbar');
186
+		$profilerTime = $this->convertToMiliseconds($this->app->profiler->getTotalTime(), 0);
187
+		if ($profilerTime > 0) {
188
+			$label .= sprintf(' (%s %s)', $profilerTime, __('ms', 'blackbar'));
189
+		}
190
+		return $label;
191
+	}
192
+
193
+	protected function getQueries(): array
194
+	{
195
+		global $wpdb;
196
+		$queries = [];
197
+		$search = [
198
+			'AND', 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT',
199
+			'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE',
200
+		];
201
+		$replace = array_map(function ($value) {
202
+			return PHP_EOL.$value;
203
+		}, $search);
204
+		foreach ($wpdb->queries as $query) {
205
+			$miliseconds = number_format(round($query[1] * 1000, 4), 4);
206
+			$sql = preg_replace('/\s\s+/', ' ', trim($query[0]));
207
+			$sql = str_replace(PHP_EOL, ' ', $sql);
208
+			$sql = str_replace($search, $replace, $sql);
209
+			$queries[] = [
210
+				'ms' => $miliseconds,
211
+				'sql' => $sql,
212
+			];
213
+		}
214
+		return $queries;
215
+	}
216
+
217
+	protected function getQueriesLabel(): string
218
+	{
219
+		$label = __('SQL', 'blackbar');
220
+		if (!SAVEQUERIES) {
221
+			return $label;
222
+		}
223
+		global $wpdb;
224
+		$queryTime = 0;
225
+		foreach ($wpdb->queries as $query) {
226
+			$queryTime += $query[1];
227
+		}
228
+		$queriesCount = sprintf('<span class="glbb-queries-count">%s</span>', count($wpdb->queries));
229
+		$queriesTime = sprintf('<span class="glbb-queries-time">%s</span>', $this->convertToMiliseconds($queryTime));
230
+		return $label.sprintf(' (%s %s | %s %s)', $queriesCount, __('queries', 'blackbar'), $queriesTime, __('ms', 'blackbar'));
231
+	}
232
+
233
+	protected function getSlowActionsLabel(): string
234
+	{
235
+		$label = __('Hooks', 'blackbar');
236
+		$totalTime = $this->convertToMiliseconds($this->app->actions->getTotalTime(), 0);
237
+		if ($totalTime > 0) {
238
+			$label .= sprintf(' (%s %s)', $totalTime, __('ms', 'blackbar'));
239
+		}
240
+		return $label;
241
+	}
242
+
243
+	protected function getTemplates(): string
244
+	{
245
+		if (is_admin()) {
246
+			return '';
247
+		}
248
+		if (class_exists('\GeminiLabs\Castor\Facades\Development')) {
249
+			ob_start();
250
+			\GeminiLabs\Castor\Facades\Development::printTemplatePaths();
251
+			return ob_get_clean();
252
+		}
253
+		return sprintf('<pre>%s</pre>', implode(PHP_EOL, $this->getIncludedFiles()));
254
+	}
255 255
 }
Please login to merge, or discard this patch.
Spacing   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
      */
10 10
     protected $app;
11 11
 
12
-    public function __construct(Application $app)
12
+    public function __construct( Application $app )
13 13
     {
14 14
         $this->app = Application::load();
15 15
     }
@@ -20,18 +20,18 @@  discard block
 block discarded – undo
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
 block discarded – undo
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,10 +60,10 @@  discard block
 block discarded – undo
60 60
      */
61 61
     public function initProfiler(): void
62 62
     {
63
-        if (Application::PROFILER_HOOK !== func_get_arg(0)) {
63
+        if( Application::PROFILER_HOOK !== func_get_arg( 0 ) ) {
64 64
             return;
65 65
         }
66
-        $this->app->profiler->trace(func_get_arg(1));
66
+        $this->app->profiler->trace( func_get_arg( 1 ) );
67 67
     }
68 68
 
69 69
     /**
@@ -79,8 +79,8 @@  discard block
 block discarded – undo
79 79
      */
80 80
     public function registerLanguages(): void
81 81
     {
82
-        load_plugin_textdomain(Application::ID, false,
83
-            plugin_basename($this->app->path()).'/languages/'
82
+        load_plugin_textdomain( Application::ID, false,
83
+            plugin_basename( $this->app->path() ) . '/languages/'
84 84
         );
85 85
     }
86 86
 
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
      */
91 91
     public function renderBar(): void
92 92
     {
93
-        apply_filters('debug', 'Profiler Stopped');
94
-        $this->app->render('debug-bar', [
93
+        apply_filters( 'debug', 'Profiler Stopped' );
94
+        $this->app->render( 'debug-bar', [
95 95
             'actions' => $this->app->actions,
96 96
             'actionsLabel' => $this->getSlowActionsLabel(),
97 97
             'blackbar' => $this->app,
@@ -102,65 +102,65 @@  discard block
 block discarded – undo
102 102
             'queries' => $this->getQueries(),
103 103
             'queriesLabel' => $this->getQueriesLabel(),
104 104
             'templates' => $this->getTemplates(),
105
-        ]);
105
+        ] );
106 106
     }
107 107
 
108
-    protected function convertToMiliseconds(int $time, int $decimals = 2): string
108
+    protected function convertToMiliseconds( int $time, int $decimals = 2 ): string
109 109
     {
110
-        return number_format($time * 1000, $decimals);
110
+        return number_format( $time * 1000, $decimals );
111 111
     }
112 112
 
113 113
     protected function getConsoleEntries(): array
114 114
     {
115
-        return array_merge($this->getErrors(), $this->app->console->entries);
115
+        return array_merge( $this->getErrors(), $this->app->console->entries );
116 116
     }
117 117
 
118 118
     protected function getConsoleLabel(): string
119 119
     {
120 120
         $class = '';
121 121
         $entries = $this->getConsoleEntries();
122
-        $entryCount = count($entries);
122
+        $entryCount = count( $entries );
123 123
         $errorCount = 0;
124
-        $label = __('Console', 'blackbar');
125
-        foreach ($entries as $entry) {
126
-            if (in_array($entry['code'], [E_NOTICE, E_STRICT, E_DEPRECATED])) {
124
+        $label = __( 'Console', 'blackbar' );
125
+        foreach( $entries as $entry ) {
126
+            if( in_array( $entry[ 'code' ], [ E_NOTICE, E_STRICT, E_DEPRECATED ] ) ) {
127 127
                 $class = 'glbb-warning';
128 128
             }
129
-            if (in_array($entry['code'], [E_WARNING])) {
129
+            if( in_array( $entry[ 'code' ], [ E_WARNING ] ) ) {
130 130
                 ++$errorCount;
131 131
             }
132 132
         }
133
-        if ($entryCount > 0) {
134
-            $label .= sprintf(' (%d)', $entryCount);
133
+        if( $entryCount > 0 ) {
134
+            $label .= sprintf( ' (%d)', $entryCount );
135 135
         }
136
-        if ($errorCount > 0) {
136
+        if( $errorCount > 0 ) {
137 137
             $class = 'glbb-error';
138
-            $label .= sprintf(' (%d, %d!)', $entryCount, $errorCount);
138
+            $label .= sprintf( ' (%d, %d!)', $entryCount, $errorCount );
139 139
         }
140
-        return sprintf('<span class="%s">%s</span>', $class, $label);
140
+        return sprintf( '<span class="%s">%s</span>', $class, $label );
141 141
     }
142 142
 
143 143
     protected function getErrors(): array
144 144
     {
145
-        $errors = [];
146
-        foreach ($this->app->errors as $error) {
145
+        $errors = [ ];
146
+        foreach( $this->app->errors as $error ) {
147 147
             $class = 'glbb-info';
148
-            if (in_array($error['code'], [E_NOTICE, E_STRICT, E_DEPRECATED])) {
148
+            if( in_array( $error[ 'code' ], [ E_NOTICE, E_STRICT, E_DEPRECATED ] ) ) {
149 149
                 $class = 'glbb-warning';
150 150
             }
151
-            if (E_WARNING == $error['code']) {
151
+            if( E_WARNING == $error[ 'code' ] ) {
152 152
                 $class = 'glbb-error';
153 153
             }
154
-            if ($error['count'] > 1) {
155
-                $error['name'] .= ' ('.$error['count'].')';
154
+            if( $error[ 'count' ] > 1 ) {
155
+                $error[ 'name' ] .= ' (' . $error[ 'count' ] . ')';
156 156
             }
157
-            $errors[] = [
158
-                'code' => $error['code'],
159
-                'name' => '<span class="'.$class.'">'.$error['name'].'</span>',
160
-                'message' => sprintf(__('%s on line %s in file %s', 'blackbar'),
161
-                    $error['message'],
162
-                    $error['line'],
163
-                    $error['file']
157
+            $errors[ ] = [
158
+                'code' => $error[ 'code' ],
159
+                'name' => '<span class="' . $class . '">' . $error[ 'name' ] . '</span>',
160
+                'message' => sprintf( __( '%s on line %s in file %s', 'blackbar' ),
161
+                    $error[ 'message' ],
162
+                    $error[ 'line' ],
163
+                    $error[ 'file' ]
164 164
                 ),
165 165
             ];
166 166
         }
@@ -169,23 +169,23 @@  discard block
 block discarded – undo
169 169
 
170 170
     protected function getIncludedFiles(): array
171 171
     {
172
-        $files = array_values(array_filter(get_included_files(), function ($file) {
173
-            $bool = false !== strpos($file, '/themes/')
174
-                && false === strpos($file, '/functions.php');
175
-            return (bool) apply_filters('blackbar/templates/file', $bool, $file);
176
-        }));
177
-        return array_map(function ($key, $value) {
178
-            $value = str_replace(trailingslashit(WP_CONTENT_DIR), '', $value);
179
-            return sprintf('[%s] => %s', $key, $value);
180
-        }, array_keys($files), $files);
172
+        $files = array_values( array_filter( get_included_files(), function( $file ) {
173
+            $bool = false !== strpos( $file, '/themes/' )
174
+                && false === strpos( $file, '/functions.php' );
175
+            return (bool) apply_filters( 'blackbar/templates/file', $bool, $file );
176
+        }) );
177
+        return array_map( function( $key, $value ) {
178
+            $value = str_replace( trailingslashit( WP_CONTENT_DIR ), '', $value );
179
+            return sprintf( '[%s] => %s', $key, $value );
180
+        }, array_keys( $files ), $files );
181 181
     }
182 182
 
183 183
     protected function getProfilerLabel(): string
184 184
     {
185
-        $label = __('Profiler', 'blackbar');
186
-        $profilerTime = $this->convertToMiliseconds($this->app->profiler->getTotalTime(), 0);
187
-        if ($profilerTime > 0) {
188
-            $label .= sprintf(' (%s %s)', $profilerTime, __('ms', 'blackbar'));
185
+        $label = __( 'Profiler', 'blackbar' );
186
+        $profilerTime = $this->convertToMiliseconds( $this->app->profiler->getTotalTime(), 0 );
187
+        if( $profilerTime > 0 ) {
188
+            $label .= sprintf( ' (%s %s)', $profilerTime, __( 'ms', 'blackbar' ) );
189 189
         }
190 190
         return $label;
191 191
     }
@@ -193,20 +193,20 @@  discard block
 block discarded – undo
193 193
     protected function getQueries(): array
194 194
     {
195 195
         global $wpdb;
196
-        $queries = [];
196
+        $queries = [ ];
197 197
         $search = [
198 198
             'AND', 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT',
199 199
             'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE',
200 200
         ];
201
-        $replace = array_map(function ($value) {
202
-            return PHP_EOL.$value;
203
-        }, $search);
204
-        foreach ($wpdb->queries as $query) {
205
-            $miliseconds = number_format(round($query[1] * 1000, 4), 4);
206
-            $sql = preg_replace('/\s\s+/', ' ', trim($query[0]));
207
-            $sql = str_replace(PHP_EOL, ' ', $sql);
208
-            $sql = str_replace($search, $replace, $sql);
209
-            $queries[] = [
201
+        $replace = array_map( function( $value ) {
202
+            return PHP_EOL . $value;
203
+        }, $search );
204
+        foreach( $wpdb->queries as $query ) {
205
+            $miliseconds = number_format( round( $query[ 1 ] * 1000, 4 ), 4 );
206
+            $sql = preg_replace( '/\s\s+/', ' ', trim( $query[ 0 ] ) );
207
+            $sql = str_replace( PHP_EOL, ' ', $sql );
208
+            $sql = str_replace( $search, $replace, $sql );
209
+            $queries[ ] = [
210 210
                 'ms' => $miliseconds,
211 211
                 'sql' => $sql,
212 212
             ];
@@ -216,40 +216,40 @@  discard block
 block discarded – undo
216 216
 
217 217
     protected function getQueriesLabel(): string
218 218
     {
219
-        $label = __('SQL', 'blackbar');
220
-        if (!SAVEQUERIES) {
219
+        $label = __( 'SQL', 'blackbar' );
220
+        if( !SAVEQUERIES ) {
221 221
             return $label;
222 222
         }
223 223
         global $wpdb;
224 224
         $queryTime = 0;
225
-        foreach ($wpdb->queries as $query) {
226
-            $queryTime += $query[1];
225
+        foreach( $wpdb->queries as $query ) {
226
+            $queryTime += $query[ 1 ];
227 227
         }
228
-        $queriesCount = sprintf('<span class="glbb-queries-count">%s</span>', count($wpdb->queries));
229
-        $queriesTime = sprintf('<span class="glbb-queries-time">%s</span>', $this->convertToMiliseconds($queryTime));
230
-        return $label.sprintf(' (%s %s | %s %s)', $queriesCount, __('queries', 'blackbar'), $queriesTime, __('ms', 'blackbar'));
228
+        $queriesCount = sprintf( '<span class="glbb-queries-count">%s</span>', count( $wpdb->queries ) );
229
+        $queriesTime = sprintf( '<span class="glbb-queries-time">%s</span>', $this->convertToMiliseconds( $queryTime ) );
230
+        return $label . sprintf( ' (%s %s | %s %s)', $queriesCount, __( 'queries', 'blackbar' ), $queriesTime, __( 'ms', 'blackbar' ) );
231 231
     }
232 232
 
233 233
     protected function getSlowActionsLabel(): string
234 234
     {
235
-        $label = __('Hooks', 'blackbar');
236
-        $totalTime = $this->convertToMiliseconds($this->app->actions->getTotalTime(), 0);
237
-        if ($totalTime > 0) {
238
-            $label .= sprintf(' (%s %s)', $totalTime, __('ms', 'blackbar'));
235
+        $label = __( 'Hooks', 'blackbar' );
236
+        $totalTime = $this->convertToMiliseconds( $this->app->actions->getTotalTime(), 0 );
237
+        if( $totalTime > 0 ) {
238
+            $label .= sprintf( ' (%s %s)', $totalTime, __( 'ms', 'blackbar' ) );
239 239
         }
240 240
         return $label;
241 241
     }
242 242
 
243 243
     protected function getTemplates(): string
244 244
     {
245
-        if (is_admin()) {
245
+        if( is_admin() ) {
246 246
             return '';
247 247
         }
248
-        if (class_exists('\GeminiLabs\Castor\Facades\Development')) {
248
+        if( class_exists( '\GeminiLabs\Castor\Facades\Development' ) ) {
249 249
             ob_start();
250 250
             \GeminiLabs\Castor\Facades\Development::printTemplatePaths();
251 251
             return ob_get_clean();
252 252
         }
253
-        return sprintf('<pre>%s</pre>', implode(PHP_EOL, $this->getIncludedFiles()));
253
+        return sprintf( '<pre>%s</pre>', implode( PHP_EOL, $this->getIncludedFiles() ) );
254 254
     }
255 255
 }
Please login to merge, or discard this patch.
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -169,12 +169,14 @@  discard block
 block discarded – undo
169 169
 
170 170
     protected function getIncludedFiles(): array
171 171
     {
172
-        $files = array_values(array_filter(get_included_files(), function ($file) {
172
+        $files = array_values(array_filter(get_included_files(), function ($file)
173
+        {
173 174
             $bool = false !== strpos($file, '/themes/')
174 175
                 && false === strpos($file, '/functions.php');
175 176
             return (bool) apply_filters('blackbar/templates/file', $bool, $file);
176 177
         }));
177
-        return array_map(function ($key, $value) {
178
+        return array_map(function ($key, $value)
179
+        {
178 180
             $value = str_replace(trailingslashit(WP_CONTENT_DIR), '', $value);
179 181
             return sprintf('[%s] => %s', $key, $value);
180 182
         }, array_keys($files), $files);
@@ -198,7 +200,8 @@  discard block
 block discarded – undo
198 200
             'AND', 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT',
199 201
             'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE',
200 202
         ];
201
-        $replace = array_map(function ($value) {
203
+        $replace = array_map(function ($value)
204
+        {
202 205
             return PHP_EOL.$value;
203 206
         }, $search);
204 207
         foreach ($wpdb->queries as $query) {
Please login to merge, or discard this patch.
plugin/Profiler.php 2 patches
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -4,86 +4,86 @@
 block discarded – undo
4 4
 
5 5
 class Profiler
6 6
 {
7
-    /**
8
-     * This is the time that WordPress takes to execute the profiler hook.
9
-     * @var int
10
-     */
11
-    protected $noise = 0;
7
+	/**
8
+	 * This is the time that WordPress takes to execute the profiler hook.
9
+	 * @var int
10
+	 */
11
+	protected $noise = 0;
12 12
 
13
-    /**
14
-     * @var int
15
-     */
16
-    protected $start = null;
13
+	/**
14
+	 * @var int
15
+	 */
16
+	protected $start = null;
17 17
 
18
-    /**
19
-     * @var int
20
-     */
21
-    protected $stop = null;
18
+	/**
19
+	 * @var int
20
+	 */
21
+	protected $stop = null;
22 22
 
23
-    /**
24
-     * @var array
25
-     */
26
-    protected $timers = [];
23
+	/**
24
+	 * @var array
25
+	 */
26
+	protected $timers = [];
27 27
 
28
-    public function getMeasure(): array
29
-    {
30
-        return $this->timers;
31
-    }
28
+	public function getMeasure(): array
29
+	{
30
+		return $this->timers;
31
+	}
32 32
 
33
-    public function getMemoryString(array $timer): string
34
-    {
35
-        $timer = $this->normalize($timer);
36
-        return sprintf('%s kB', round($timer['memory'] / 1000));
37
-    }
33
+	public function getMemoryString(array $timer): string
34
+	{
35
+		$timer = $this->normalize($timer);
36
+		return sprintf('%s kB', round($timer['memory'] / 1000));
37
+	}
38 38
 
39
-    public function getNameString(array $timer): string
40
-    {
41
-        $timer = $this->normalize($timer);
42
-        return $timer['name'];
43
-    }
39
+	public function getNameString(array $timer): string
40
+	{
41
+		$timer = $this->normalize($timer);
42
+		return $timer['name'];
43
+	}
44 44
 
45
-    public function getTimeString(array $timer): string
46
-    {
47
-        $timer = $this->normalize($timer);
48
-        $index = array_search($timer['name'], array_column($this->timers, 'name'));
49
-        $start = $this->start + ($index * $this->noise);
50
-        $time = number_format(round(($timer['time'] - $start) * 1000, 4), 4);
51
-        return sprintf('%s ms', $time);
52
-    }
45
+	public function getTimeString(array $timer): string
46
+	{
47
+		$timer = $this->normalize($timer);
48
+		$index = array_search($timer['name'], array_column($this->timers, 'name'));
49
+		$start = $this->start + ($index * $this->noise);
50
+		$time = number_format(round(($timer['time'] - $start) * 1000, 4), 4);
51
+		return sprintf('%s ms', $time);
52
+	}
53 53
 
54
-    /**
55
-     * Time in Microseconds
56
-     */
57
-    public function getTotalTime(): int
58
-    {
59
-        $totalNoise = (count($this->timers) - 1) * $this->noise;
60
-        return $this->stop - $this->start - $totalNoise;
61
-    }
54
+	/**
55
+	 * Time in Microseconds
56
+	 */
57
+	public function getTotalTime(): int
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);
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);
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' => 0,
87
-        ]);
88
-    }
81
+	protected function normalize(array $timer): array
82
+	{
83
+		return wp_parse_args($timer, [
84
+			'memory' => 0,
85
+			'name' => '',
86
+			'time' => 0,
87
+		]);
88
+	}
89 89
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -23,32 +23,32 @@  discard block
 block discarded – undo
23 23
     /**
24 24
      * @var array
25 25
      */
26
-    protected $timers = [];
26
+    protected $timers = [ ];
27 27
 
28 28
     public function getMeasure(): array
29 29
     {
30 30
         return $this->timers;
31 31
     }
32 32
 
33
-    public function getMemoryString(array $timer): string
33
+    public function getMemoryString( array $timer ): string
34 34
     {
35
-        $timer = $this->normalize($timer);
36
-        return sprintf('%s kB', round($timer['memory'] / 1000));
35
+        $timer = $this->normalize( $timer );
36
+        return sprintf( '%s kB', round( $timer[ 'memory' ] / 1000 ) );
37 37
     }
38 38
 
39
-    public function getNameString(array $timer): string
39
+    public function getNameString( array $timer ): string
40 40
     {
41
-        $timer = $this->normalize($timer);
42
-        return $timer['name'];
41
+        $timer = $this->normalize( $timer );
42
+        return $timer[ 'name' ];
43 43
     }
44 44
 
45
-    public function getTimeString(array $timer): string
45
+    public function getTimeString( array $timer ): string
46 46
     {
47
-        $timer = $this->normalize($timer);
48
-        $index = array_search($timer['name'], array_column($this->timers, 'name'));
49
-        $start = $this->start + ($index * $this->noise);
50
-        $time = number_format(round(($timer['time'] - $start) * 1000, 4), 4);
51
-        return sprintf('%s ms', $time);
47
+        $timer = $this->normalize( $timer );
48
+        $index = array_search( $timer[ 'name' ], array_column( $this->timers, 'name' ) );
49
+        $start = $this->start + ( $index * $this->noise );
50
+        $time = number_format( round( ( $timer[ 'time' ] - $start ) * 1000, 4 ), 4 );
51
+        return sprintf( '%s ms', $time );
52 52
     }
53 53
 
54 54
     /**
@@ -56,21 +56,21 @@  discard block
 block discarded – undo
56 56
      */
57 57
     public function getTotalTime(): int
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);
66
-        if (!$this->start) {
65
+        $microtime = microtime( true );
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
 block discarded – undo
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' => 0,
87
-        ]);
87
+        ] );
88 88
     }
89 89
 }
Please login to merge, or discard this patch.
plugin/SlowActions.php 2 patches
Indentation   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -4,140 +4,140 @@
 block discarded – undo
4 4
 
5 5
 class SlowActions
6 6
 {
7
-    /**
8
-     * @var array
9
-     */
10
-    protected $flow;
11
-
12
-    /**
13
-     * This is the time that WordPress takes to execute the all hook.
14
-     * @var int
15
-     */
16
-    protected $noise = 0;
17
-
18
-    /**
19
-     * @var int
20
-     */
21
-    protected $start = null;
22
-
23
-    /**
24
-     * @var int
25
-     */
26
-    protected $stop = null;
27
-
28
-    /**
29
-     * @var int
30
-     */
31
-    protected $totalActions = 0;
32
-
33
-    /**
34
-     * @var int
35
-     */
36
-    protected $totalTime = 0;
37
-
38
-    public function __construct()
39
-    {
40
-        $this->flow = [];
41
-        $this->start = microtime(true);
42
-    }
43
-
44
-    public function getTotalTimeForHook(array $data): array
45
-    {
46
-        $total = 0;
47
-        foreach ($data['time'] as $time) {
48
-            $total += ($time['stop'] - $time['start']) * 1000;
49
-        }
50
-        return $total;
51
-    }
52
-
53
-    public function addCallbacksForAction(string $action): array
54
-    {
55
-        global $wp_filter;
56
-        if (!array_key_exists($action, $this->flow)) {
57
-            return;
58
-        }
59
-        $this->flow[$action]['callbacks_count'] = 0;
60
-        foreach ($wp_filter[$action] as $priority => $callbacks) {
61
-            if (!array_key_exists($priority, $this->flow[$action]['callbacks'])) {
62
-                $this->flow[$action]['callbacks'][$priority] = [];
63
-            }
64
-            foreach ($callbacks as $callback) {
65
-                if (is_array($callback['function']) && 2 == count($callback['function'])) {
66
-                    list($object, $method) = $callback['function'];
67
-                    if (is_object($object)) {
68
-                        $object = get_class($object);
69
-                    }
70
-                    $this->flow[$action]['callbacks'][$priority][] = sprintf('%s::%s', $object, $method);
71
-                } elseif (is_object($callback['function'])) {
72
-                    $this->flow[$action]['callbacks'][$priority][] = get_class($callback['function']);
73
-                } else {
74
-                    $this->flow[$action]['callbacks'][$priority][] = $callback['function'];
75
-                }
76
-                ++$this->flow[$action]['callbacks_count'];
77
-            }
78
-        }
79
-    }
80
-
81
-    public function getMeasure(): array
82
-    {
83
-        foreach ($this->flow as $action => $data) {
84
-            $total = $this->getTotalTimeForHook($data);
85
-            $this->flow[$action]['total'] = $total;
86
-            $this->totalTime += $total;
87
-            $this->totalActions += $data['count'];
88
-            $this->addCallbacksForAction($action);
89
-        }
90
-        uasort($this->flow, [$this, 'sortByTime']);
91
-        return $this->flow;
92
-    }
93
-
94
-    public function getTotalActions(): int
95
-    {
96
-        return $this->totalActions;
97
-    }
98
-
99
-    /**
100
-     * Time in Microseconds
101
-     */
102
-    public function getTotalTime(): int
103
-    {
104
-        return $this->totalTime;
105
-        // $totalNoise = (count($this->timers) - 1) * $this->noise;
106
-        // return $this->stop - $this->start - $totalNoise;
107
-    }
108
-
109
-    public function startTimer(): void
110
-    {
111
-        if (!isset($this->flow[current_filter()])) {
112
-            $this->flow[current_filter()] = [
113
-                'callbacks' => [],
114
-                'count' => 0,
115
-                'stack' => [],
116
-                'time' => [],
117
-            ];
118
-            add_action(current_filter(), [$this, 'stopTimer'], 9000);
119
-        }
120
-        $count = ++$this->flow[current_filter()]['count'];
121
-        array_push($this->flow[current_filter()]['stack'], ['start' => microtime(true)]);
122
-    }
123
-
124
-    /**
125
-     * @param mixed $possibleFilter
126
-     * @return mixed
127
-     */
128
-    public function stopTimer($possibleFilter = null)
129
-    {
130
-        $time = array_pop($this->flow[current_filter()]['stack']);
131
-        $time['stop'] = microtime(true);
132
-        array_push($this->flow[current_filter()]['time'], $time);
133
-        return $possibleFilter;
134
-    }
135
-
136
-    protected function sortByTime(array $a, array $b): int
137
-    {
138
-        if ($a['total'] == $b['total']) {
139
-            return 0;
140
-        }
141
-        return ($a['total'] > $b['total']) ? -1 : 1;
142
-    }
7
+	/**
8
+	 * @var array
9
+	 */
10
+	protected $flow;
11
+
12
+	/**
13
+	 * This is the time that WordPress takes to execute the all hook.
14
+	 * @var int
15
+	 */
16
+	protected $noise = 0;
17
+
18
+	/**
19
+	 * @var int
20
+	 */
21
+	protected $start = null;
22
+
23
+	/**
24
+	 * @var int
25
+	 */
26
+	protected $stop = null;
27
+
28
+	/**
29
+	 * @var int
30
+	 */
31
+	protected $totalActions = 0;
32
+
33
+	/**
34
+	 * @var int
35
+	 */
36
+	protected $totalTime = 0;
37
+
38
+	public function __construct()
39
+	{
40
+		$this->flow = [];
41
+		$this->start = microtime(true);
42
+	}
43
+
44
+	public function getTotalTimeForHook(array $data): array
45
+	{
46
+		$total = 0;
47
+		foreach ($data['time'] as $time) {
48
+			$total += ($time['stop'] - $time['start']) * 1000;
49
+		}
50
+		return $total;
51
+	}
52
+
53
+	public function addCallbacksForAction(string $action): array
54
+	{
55
+		global $wp_filter;
56
+		if (!array_key_exists($action, $this->flow)) {
57
+			return;
58
+		}
59
+		$this->flow[$action]['callbacks_count'] = 0;
60
+		foreach ($wp_filter[$action] as $priority => $callbacks) {
61
+			if (!array_key_exists($priority, $this->flow[$action]['callbacks'])) {
62
+				$this->flow[$action]['callbacks'][$priority] = [];
63
+			}
64
+			foreach ($callbacks as $callback) {
65
+				if (is_array($callback['function']) && 2 == count($callback['function'])) {
66
+					list($object, $method) = $callback['function'];
67
+					if (is_object($object)) {
68
+						$object = get_class($object);
69
+					}
70
+					$this->flow[$action]['callbacks'][$priority][] = sprintf('%s::%s', $object, $method);
71
+				} elseif (is_object($callback['function'])) {
72
+					$this->flow[$action]['callbacks'][$priority][] = get_class($callback['function']);
73
+				} else {
74
+					$this->flow[$action]['callbacks'][$priority][] = $callback['function'];
75
+				}
76
+				++$this->flow[$action]['callbacks_count'];
77
+			}
78
+		}
79
+	}
80
+
81
+	public function getMeasure(): array
82
+	{
83
+		foreach ($this->flow as $action => $data) {
84
+			$total = $this->getTotalTimeForHook($data);
85
+			$this->flow[$action]['total'] = $total;
86
+			$this->totalTime += $total;
87
+			$this->totalActions += $data['count'];
88
+			$this->addCallbacksForAction($action);
89
+		}
90
+		uasort($this->flow, [$this, 'sortByTime']);
91
+		return $this->flow;
92
+	}
93
+
94
+	public function getTotalActions(): int
95
+	{
96
+		return $this->totalActions;
97
+	}
98
+
99
+	/**
100
+	 * Time in Microseconds
101
+	 */
102
+	public function getTotalTime(): int
103
+	{
104
+		return $this->totalTime;
105
+		// $totalNoise = (count($this->timers) - 1) * $this->noise;
106
+		// return $this->stop - $this->start - $totalNoise;
107
+	}
108
+
109
+	public function startTimer(): void
110
+	{
111
+		if (!isset($this->flow[current_filter()])) {
112
+			$this->flow[current_filter()] = [
113
+				'callbacks' => [],
114
+				'count' => 0,
115
+				'stack' => [],
116
+				'time' => [],
117
+			];
118
+			add_action(current_filter(), [$this, 'stopTimer'], 9000);
119
+		}
120
+		$count = ++$this->flow[current_filter()]['count'];
121
+		array_push($this->flow[current_filter()]['stack'], ['start' => microtime(true)]);
122
+	}
123
+
124
+	/**
125
+	 * @param mixed $possibleFilter
126
+	 * @return mixed
127
+	 */
128
+	public function stopTimer($possibleFilter = null)
129
+	{
130
+		$time = array_pop($this->flow[current_filter()]['stack']);
131
+		$time['stop'] = microtime(true);
132
+		array_push($this->flow[current_filter()]['time'], $time);
133
+		return $possibleFilter;
134
+	}
135
+
136
+	protected function sortByTime(array $a, array $b): int
137
+	{
138
+		if ($a['total'] == $b['total']) {
139
+			return 0;
140
+		}
141
+		return ($a['total'] > $b['total']) ? -1 : 1;
142
+	}
143 143
 }
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -37,57 +37,57 @@  discard block
 block discarded – undo
37 37
 
38 38
     public function __construct()
39 39
     {
40
-        $this->flow = [];
41
-        $this->start = microtime(true);
40
+        $this->flow = [ ];
41
+        $this->start = microtime( true );
42 42
     }
43 43
 
44
-    public function getTotalTimeForHook(array $data): array
44
+    public function getTotalTimeForHook( array $data ): array
45 45
     {
46 46
         $total = 0;
47
-        foreach ($data['time'] as $time) {
48
-            $total += ($time['stop'] - $time['start']) * 1000;
47
+        foreach( $data[ 'time' ] as $time ) {
48
+            $total += ( $time[ 'stop' ] - $time[ 'start' ] ) * 1000;
49 49
         }
50 50
         return $total;
51 51
     }
52 52
 
53
-    public function addCallbacksForAction(string $action): array
53
+    public function addCallbacksForAction( string $action ): array
54 54
     {
55 55
         global $wp_filter;
56
-        if (!array_key_exists($action, $this->flow)) {
56
+        if( !array_key_exists( $action, $this->flow ) ) {
57 57
             return;
58 58
         }
59
-        $this->flow[$action]['callbacks_count'] = 0;
60
-        foreach ($wp_filter[$action] as $priority => $callbacks) {
61
-            if (!array_key_exists($priority, $this->flow[$action]['callbacks'])) {
62
-                $this->flow[$action]['callbacks'][$priority] = [];
59
+        $this->flow[ $action ][ 'callbacks_count' ] = 0;
60
+        foreach( $wp_filter[ $action ] as $priority => $callbacks ) {
61
+            if( !array_key_exists( $priority, $this->flow[ $action ][ 'callbacks' ] ) ) {
62
+                $this->flow[ $action ][ 'callbacks' ][ $priority ] = [ ];
63 63
             }
64
-            foreach ($callbacks as $callback) {
65
-                if (is_array($callback['function']) && 2 == count($callback['function'])) {
66
-                    list($object, $method) = $callback['function'];
67
-                    if (is_object($object)) {
68
-                        $object = get_class($object);
64
+            foreach( $callbacks as $callback ) {
65
+                if( is_array( $callback[ 'function' ] ) && 2 == count( $callback[ 'function' ] ) ) {
66
+                    list( $object, $method ) = $callback[ 'function' ];
67
+                    if( is_object( $object ) ) {
68
+                        $object = get_class( $object );
69 69
                     }
70
-                    $this->flow[$action]['callbacks'][$priority][] = sprintf('%s::%s', $object, $method);
71
-                } elseif (is_object($callback['function'])) {
72
-                    $this->flow[$action]['callbacks'][$priority][] = get_class($callback['function']);
70
+                    $this->flow[ $action ][ 'callbacks' ][ $priority ][ ] = sprintf( '%s::%s', $object, $method );
71
+                } elseif( is_object( $callback[ 'function' ] ) ) {
72
+                    $this->flow[ $action ][ 'callbacks' ][ $priority ][ ] = get_class( $callback[ 'function' ] );
73 73
                 } else {
74
-                    $this->flow[$action]['callbacks'][$priority][] = $callback['function'];
74
+                    $this->flow[ $action ][ 'callbacks' ][ $priority ][ ] = $callback[ 'function' ];
75 75
                 }
76
-                ++$this->flow[$action]['callbacks_count'];
76
+                ++$this->flow[ $action ][ 'callbacks_count' ];
77 77
             }
78 78
         }
79 79
     }
80 80
 
81 81
     public function getMeasure(): array
82 82
     {
83
-        foreach ($this->flow as $action => $data) {
84
-            $total = $this->getTotalTimeForHook($data);
85
-            $this->flow[$action]['total'] = $total;
83
+        foreach( $this->flow as $action => $data ) {
84
+            $total = $this->getTotalTimeForHook( $data );
85
+            $this->flow[ $action ][ 'total' ] = $total;
86 86
             $this->totalTime += $total;
87
-            $this->totalActions += $data['count'];
88
-            $this->addCallbacksForAction($action);
87
+            $this->totalActions += $data[ 'count' ];
88
+            $this->addCallbacksForAction( $action );
89 89
         }
90
-        uasort($this->flow, [$this, 'sortByTime']);
90
+        uasort( $this->flow, [ $this, 'sortByTime' ] );
91 91
         return $this->flow;
92 92
     }
93 93
 
@@ -108,36 +108,36 @@  discard block
 block discarded – undo
108 108
 
109 109
     public function startTimer(): void
110 110
     {
111
-        if (!isset($this->flow[current_filter()])) {
112
-            $this->flow[current_filter()] = [
113
-                'callbacks' => [],
111
+        if( !isset( $this->flow[ current_filter() ] ) ) {
112
+            $this->flow[ current_filter() ] = [
113
+                'callbacks' => [ ],
114 114
                 'count' => 0,
115
-                'stack' => [],
116
-                'time' => [],
115
+                'stack' => [ ],
116
+                'time' => [ ],
117 117
             ];
118
-            add_action(current_filter(), [$this, 'stopTimer'], 9000);
118
+            add_action( current_filter(), [ $this, 'stopTimer' ], 9000 );
119 119
         }
120
-        $count = ++$this->flow[current_filter()]['count'];
121
-        array_push($this->flow[current_filter()]['stack'], ['start' => microtime(true)]);
120
+        $count = ++$this->flow[ current_filter() ][ 'count' ];
121
+        array_push( $this->flow[ current_filter() ][ 'stack' ], [ 'start' => microtime( true ) ] );
122 122
     }
123 123
 
124 124
     /**
125 125
      * @param mixed $possibleFilter
126 126
      * @return mixed
127 127
      */
128
-    public function stopTimer($possibleFilter = null)
128
+    public function stopTimer( $possibleFilter = null )
129 129
     {
130
-        $time = array_pop($this->flow[current_filter()]['stack']);
131
-        $time['stop'] = microtime(true);
132
-        array_push($this->flow[current_filter()]['time'], $time);
130
+        $time = array_pop( $this->flow[ current_filter() ][ 'stack' ] );
131
+        $time[ 'stop' ] = microtime( true );
132
+        array_push( $this->flow[ current_filter() ][ 'time' ], $time );
133 133
         return $possibleFilter;
134 134
     }
135 135
 
136
-    protected function sortByTime(array $a, array $b): int
136
+    protected function sortByTime( array $a, array $b ): int
137 137
     {
138
-        if ($a['total'] == $b['total']) {
138
+        if( $a[ 'total' ] == $b[ 'total' ] ) {
139 139
             return 0;
140 140
         }
141
-        return ($a['total'] > $b['total']) ? -1 : 1;
141
+        return ( $a[ 'total' ] > $b[ 'total' ] ) ? -1 : 1;
142 142
     }
143 143
 }
Please login to merge, or discard this patch.
plugin/Console.php 3 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -6,68 +6,68 @@
 block discarded – undo
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 isObjectOrArray($value): bool
55
-    {
56
-        return is_object($value) || is_array($value);
57
-    }
51
+	/**
52
+	 * @param mixed $value
53
+	 */
54
+	protected function isObjectOrArray($value): bool
55
+	{
56
+		return is_object($value) || is_array($value);
57
+	}
58 58
 
59
-    /**
60
-     * @param mixed $value
61
-     */
62
-    protected function normalizeValue($value): string
63
-    {
64
-        if ($value instanceof DateTime) {
65
-            $value = $value->format('Y-m-d H:i:s');
66
-        } elseif ($this->isObjectOrArray($value)) {
67
-            $value = print_r(json_decode(json_encode($value)), true);
68
-        } elseif (is_resource($value)) {
69
-            $value = (string) $value;
70
-        }
71
-        return esc_html($value);
72
-    }
59
+	/**
60
+	 * @param mixed $value
61
+	 */
62
+	protected function normalizeValue($value): string
63
+	{
64
+		if ($value instanceof DateTime) {
65
+			$value = $value->format('Y-m-d H:i:s');
66
+		} elseif ($this->isObjectOrArray($value)) {
67
+			$value = print_r(json_decode(json_encode($value)), true);
68
+		} elseif (is_resource($value)) {
69
+			$value = (string) $value;
70
+		}
71
+		return esc_html($value);
72
+	}
73 73
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -25,25 +25,25 @@  discard block
 block discarded – undo
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,23 +51,23 @@  discard block
 block discarded – undo
51 51
     /**
52 52
      * @param mixed $value
53 53
      */
54
-    protected function isObjectOrArray($value): bool
54
+    protected function isObjectOrArray( $value ): bool
55 55
     {
56
-        return is_object($value) || is_array($value);
56
+        return is_object( $value ) || is_array( $value );
57 57
     }
58 58
 
59 59
     /**
60 60
      * @param mixed $value
61 61
      */
62
-    protected function normalizeValue($value): string
62
+    protected function normalizeValue( $value ): string
63 63
     {
64
-        if ($value instanceof DateTime) {
65
-            $value = $value->format('Y-m-d H:i:s');
66
-        } elseif ($this->isObjectOrArray($value)) {
67
-            $value = print_r(json_decode(json_encode($value)), true);
68
-        } elseif (is_resource($value)) {
64
+        if( $value instanceof DateTime ) {
65
+            $value = $value->format( 'Y-m-d H:i:s' );
66
+        } elseif( $this->isObjectOrArray( $value ) ) {
67
+            $value = print_r( json_decode( json_encode( $value ) ), true );
68
+        } elseif( is_resource( $value ) ) {
69 69
             $value = (string) $value;
70 70
         }
71
-        return esc_html($value);
71
+        return esc_html( $value );
72 72
     }
73 73
 }
Please login to merge, or discard this patch.
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -37,7 +37,8 @@  discard block
 block discarded – undo
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[] = [
@@ -63,9 +64,11 @@  discard block
 block discarded – undo
63 64
     {
64 65
         if ($value instanceof DateTime) {
65 66
             $value = $value->format('Y-m-d H:i:s');
66
-        } elseif ($this->isObjectOrArray($value)) {
67
+        }
68
+        elseif ($this->isObjectOrArray($value)) {
67 69
             $value = print_r(json_decode(json_encode($value)), true);
68
-        } elseif (is_resource($value)) {
70
+        }
71
+        elseif (is_resource($value)) {
69 72
             $value = (string) $value;
70 73
         }
71 74
         return esc_html($value);
Please login to merge, or discard this patch.
plugin/Application.php 3 patches
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -4,100 +4,100 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,7 +33,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
             }
Please login to merge, or discard this patch.
blackbar.php 2 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -20,13 +20,13 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -17,16 +17,16 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.