Passed
Push — master ( 630338...867876 )
by Paul
03:16
created
plugin/Controller.php 1 patch
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.
plugin/Profiler.php 1 patch
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.
plugin/SlowActions.php 1 patch
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.
plugin/Console.php 1 patch
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.
plugin/Application.php 1 patch
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.
blackbar.php 1 patch
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.