Passed
Push — master ( 867876...1bb139 )
by Paul
02:57
created
plugin/Controller.php 1 patch
Spacing   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -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.
plugin/SlowActions.php 1 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): int
44
+    public function getTotalTimeForHook( array $data ): int
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): void
53
+    public function addCallbacksForAction( string $action ): void
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.