| @@ -55,7 +55,8 @@ | ||
| 55 | 55 |          do_action('blackbar/profiler/start'); // start profiler | 
| 56 | 56 |          do_action('blackbar/profiler/noise'); // measure profiler noise | 
| 57 | 57 |          add_action('plugins_loaded', [$controller, 'registerLanguages']); | 
| 58 | -        add_action('init', function () use ($controller) { | |
| 58 | +        add_action('init', function () use ($controller) | |
| 59 | +        { | |
| 59 | 60 |              if (!apply_filters('blackbar/enabled', current_user_can('administrator'))) { | 
| 60 | 61 | return; | 
| 61 | 62 | } | 
| @@ -11,94 +11,94 @@ | ||
| 11 | 11 | |
| 12 | 12 | final class Application | 
| 13 | 13 |  { | 
| 14 | - public const CONSOLE_HOOK = 'console'; | |
| 15 | - public const ID = 'blackbar'; | |
| 16 | - public const PROFILER_START_HOOK = 'timer:start'; | |
| 17 | - public const PROFILER_STOP_HOOK = 'timer:stop'; | |
| 14 | + public const CONSOLE_HOOK = 'console'; | |
| 15 | + public const ID = 'blackbar'; | |
| 16 | + public const PROFILER_START_HOOK = 'timer:start'; | |
| 17 | + public const PROFILER_STOP_HOOK = 'timer:stop'; | |
| 18 | 18 | |
| 19 | - public $console; | |
| 20 | - public $file; | |
| 21 | - public $globals; | |
| 22 | - public $hooks; | |
| 23 | - public $profiler; | |
| 24 | - public $queries; | |
| 25 | - public $templates; | |
| 19 | + public $console; | |
| 20 | + public $file; | |
| 21 | + public $globals; | |
| 22 | + public $hooks; | |
| 23 | + public $profiler; | |
| 24 | + public $queries; | |
| 25 | + public $templates; | |
| 26 | 26 | |
| 27 | - private static $instance; | |
| 27 | + private static $instance; | |
| 28 | 28 | |
| 29 | - public function __construct() | |
| 30 | -    { | |
| 31 | - $file = wp_normalize_path((new \ReflectionClass($this))->getFileName()); | |
| 32 | - $this->console = new Console($this); | |
| 33 | -        $this->file = str_replace('plugin/Application', static::ID, $file); | |
| 34 | - $this->globals = new Globals($this); | |
| 35 | - $this->hooks = new Hooks($this); | |
| 36 | - $this->profiler = new Profiler($this); | |
| 37 | - $this->queries = new Queries($this); | |
| 38 | - $this->templates = new Templates($this); | |
| 39 | - } | |
| 29 | + public function __construct() | |
| 30 | +	{ | |
| 31 | + $file = wp_normalize_path((new \ReflectionClass($this))->getFileName()); | |
| 32 | + $this->console = new Console($this); | |
| 33 | +		$this->file = str_replace('plugin/Application', static::ID, $file); | |
| 34 | + $this->globals = new Globals($this); | |
| 35 | + $this->hooks = new Hooks($this); | |
| 36 | + $this->profiler = new Profiler($this); | |
| 37 | + $this->queries = new Queries($this); | |
| 38 | + $this->templates = new Templates($this); | |
| 39 | + } | |
| 40 | 40 | |
| 41 | - public function errorHandler(int $errno, string $message, string $file, int $line): bool | |
| 42 | -    { | |
| 43 | - $path = explode(ABSPATH, $file); | |
| 44 | -        $location = sprintf('%s:%s', array_pop($path), $line); | |
| 45 | - $this->console->store($message, (string) $errno, $location); | |
| 46 | - return true; | |
| 47 | - } | |
| 41 | + public function errorHandler(int $errno, string $message, string $file, int $line): bool | |
| 42 | +	{ | |
| 43 | + $path = explode(ABSPATH, $file); | |
| 44 | +		$location = sprintf('%s:%s', array_pop($path), $line); | |
| 45 | + $this->console->store($message, (string) $errno, $location); | |
| 46 | + return true; | |
| 47 | + } | |
| 48 | 48 | |
| 49 | - public function init(): void | |
| 50 | -    { | |
| 51 | - $controller = new Controller($this); | |
| 52 | -        add_action('all', [$controller, 'initConsole']); | |
| 53 | -        add_action('all', [$controller, 'initHooks']); | |
| 54 | -        add_action('all', [$controller, 'initProfiler']); | |
| 55 | -        do_action('blackbar/profiler/start'); // start profiler | |
| 56 | -        do_action('blackbar/profiler/noise'); // measure profiler noise | |
| 57 | -        add_action('plugins_loaded', [$controller, 'registerLanguages']); | |
| 58 | -        add_action('init', function () use ($controller) { | |
| 59 | -            if (!apply_filters('blackbar/enabled', current_user_can('administrator'))) { | |
| 60 | - return; | |
| 61 | - } | |
| 62 | -            add_action('admin_enqueue_scripts', [$controller, 'enqueueAssets']); | |
| 63 | -            add_action('wp_enqueue_scripts', [$controller, 'enqueueAssets']); | |
| 64 | -            add_action('admin_footer', [$controller, 'renderBar'], 99999); | |
| 65 | -            add_action('wp_footer', [$controller, 'renderBar'], 99999); | |
| 66 | -            add_filter('admin_body_class', [$controller, 'filterBodyClasses']); | |
| 67 | - }); | |
| 68 | - set_error_handler([$this, 'errorHandler'], E_ALL | E_STRICT); | |
| 69 | - } | |
| 49 | + public function init(): void | |
| 50 | +	{ | |
| 51 | + $controller = new Controller($this); | |
| 52 | +		add_action('all', [$controller, 'initConsole']); | |
| 53 | +		add_action('all', [$controller, 'initHooks']); | |
| 54 | +		add_action('all', [$controller, 'initProfiler']); | |
| 55 | +		do_action('blackbar/profiler/start'); // start profiler | |
| 56 | +		do_action('blackbar/profiler/noise'); // measure profiler noise | |
| 57 | +		add_action('plugins_loaded', [$controller, 'registerLanguages']); | |
| 58 | +		add_action('init', function () use ($controller) { | |
| 59 | +			if (!apply_filters('blackbar/enabled', current_user_can('administrator'))) { | |
| 60 | + return; | |
| 61 | + } | |
| 62 | +			add_action('admin_enqueue_scripts', [$controller, 'enqueueAssets']); | |
| 63 | +			add_action('wp_enqueue_scripts', [$controller, 'enqueueAssets']); | |
| 64 | +			add_action('admin_footer', [$controller, 'renderBar'], 99999); | |
| 65 | +			add_action('wp_footer', [$controller, 'renderBar'], 99999); | |
| 66 | +			add_filter('admin_body_class', [$controller, 'filterBodyClasses']); | |
| 67 | + }); | |
| 68 | + set_error_handler([$this, 'errorHandler'], E_ALL | E_STRICT); | |
| 69 | + } | |
| 70 | 70 | |
| 71 | - /** | |
| 72 | - * @return static | |
| 73 | - */ | |
| 74 | - public static function load() | |
| 75 | -    { | |
| 76 | -        if (empty(self::$instance)) { | |
| 77 | - self::$instance = new static(); | |
| 78 | - } | |
| 79 | - return self::$instance; | |
| 80 | - } | |
| 71 | + /** | |
| 72 | + * @return static | |
| 73 | + */ | |
| 74 | + public static function load() | |
| 75 | +	{ | |
| 76 | +		if (empty(self::$instance)) { | |
| 77 | + self::$instance = new static(); | |
| 78 | + } | |
| 79 | + return self::$instance; | |
| 80 | + } | |
| 81 | 81 | |
| 82 | - public function path(string $file = '', bool $realpath = true): string | |
| 83 | -    { | |
| 84 | - $path = $realpath | |
| 85 | - ? plugin_dir_path($this->file) | |
| 86 | - : trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); | |
| 87 | - return trailingslashit($path).ltrim(trim($file), '/'); | |
| 88 | - } | |
| 82 | + public function path(string $file = '', bool $realpath = true): string | |
| 83 | +	{ | |
| 84 | + $path = $realpath | |
| 85 | + ? plugin_dir_path($this->file) | |
| 86 | + : trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); | |
| 87 | + return trailingslashit($path).ltrim(trim($file), '/'); | |
| 88 | + } | |
| 89 | 89 | |
| 90 | - public function render(string $view, array $data = []): void | |
| 91 | -    { | |
| 92 | -        $file = $this->path(sprintf('views/%s.php', str_replace('.php', '', $view))); | |
| 93 | -        if (!file_exists($file)) { | |
| 94 | - return; | |
| 95 | - } | |
| 96 | - extract($data); | |
| 97 | - include $file; | |
| 98 | - } | |
| 90 | + public function render(string $view, array $data = []): void | |
| 91 | +	{ | |
| 92 | +		$file = $this->path(sprintf('views/%s.php', str_replace('.php', '', $view))); | |
| 93 | +		if (!file_exists($file)) { | |
| 94 | + return; | |
| 95 | + } | |
| 96 | + extract($data); | |
| 97 | + include $file; | |
| 98 | + } | |
| 99 | 99 | |
| 100 | - public function url(string $path = ''): string | |
| 101 | -    { | |
| 102 | - return esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); | |
| 103 | - } | |
| 100 | + public function url(string $path = ''): string | |
| 101 | +	{ | |
| 102 | + return esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); | |
| 103 | + } | |
| 104 | 104 | } | 
| @@ -28,44 +28,44 @@ discard block | ||
| 28 | 28 | |
| 29 | 29 | public function __construct() | 
| 30 | 30 |      { | 
| 31 | - $file = wp_normalize_path((new \ReflectionClass($this))->getFileName()); | |
| 32 | - $this->console = new Console($this); | |
| 33 | -        $this->file = str_replace('plugin/Application', static::ID, $file); | |
| 34 | - $this->globals = new Globals($this); | |
| 35 | - $this->hooks = new Hooks($this); | |
| 36 | - $this->profiler = new Profiler($this); | |
| 37 | - $this->queries = new Queries($this); | |
| 38 | - $this->templates = new Templates($this); | |
| 31 | + $file = wp_normalize_path( ( new \ReflectionClass( $this ) )->getFileName() ); | |
| 32 | + $this->console = new Console( $this ); | |
| 33 | + $this->file = str_replace( 'plugin/Application', static::ID, $file ); | |
| 34 | + $this->globals = new Globals( $this ); | |
| 35 | + $this->hooks = new Hooks( $this ); | |
| 36 | + $this->profiler = new Profiler( $this ); | |
| 37 | + $this->queries = new Queries( $this ); | |
| 38 | + $this->templates = new Templates( $this ); | |
| 39 | 39 | } | 
| 40 | 40 | |
| 41 | - public function errorHandler(int $errno, string $message, string $file, int $line): bool | |
| 41 | + public function errorHandler( int $errno, string $message, string $file, int $line ): bool | |
| 42 | 42 |      { | 
| 43 | - $path = explode(ABSPATH, $file); | |
| 44 | -        $location = sprintf('%s:%s', array_pop($path), $line); | |
| 45 | - $this->console->store($message, (string) $errno, $location); | |
| 43 | + $path = explode( ABSPATH, $file ); | |
| 44 | + $location = sprintf( '%s:%s', array_pop( $path ), $line ); | |
| 45 | + $this->console->store( $message, (string) $errno, $location ); | |
| 46 | 46 | return true; | 
| 47 | 47 | } | 
| 48 | 48 | |
| 49 | 49 | public function init(): void | 
| 50 | 50 |      { | 
| 51 | - $controller = new Controller($this); | |
| 52 | -        add_action('all', [$controller, 'initConsole']); | |
| 53 | -        add_action('all', [$controller, 'initHooks']); | |
| 54 | -        add_action('all', [$controller, 'initProfiler']); | |
| 55 | -        do_action('blackbar/profiler/start'); // start profiler | |
| 56 | -        do_action('blackbar/profiler/noise'); // measure profiler noise | |
| 57 | -        add_action('plugins_loaded', [$controller, 'registerLanguages']); | |
| 58 | -        add_action('init', function () use ($controller) { | |
| 59 | -            if (!apply_filters('blackbar/enabled', current_user_can('administrator'))) { | |
| 51 | + $controller = new Controller( $this ); | |
| 52 | + add_action( 'all', [ $controller, 'initConsole' ] ); | |
| 53 | + add_action( 'all', [ $controller, 'initHooks' ] ); | |
| 54 | + add_action( 'all', [ $controller, 'initProfiler' ] ); | |
| 55 | + do_action( 'blackbar/profiler/start' ); // start profiler | |
| 56 | + do_action( 'blackbar/profiler/noise' ); // measure profiler noise | |
| 57 | + add_action( 'plugins_loaded', [ $controller, 'registerLanguages' ] ); | |
| 58 | +        add_action( 'init', function() use ( $controller ) { | |
| 59 | +            if( !apply_filters( 'blackbar/enabled', current_user_can( 'administrator' ) ) ) { | |
| 60 | 60 | return; | 
| 61 | 61 | } | 
| 62 | -            add_action('admin_enqueue_scripts', [$controller, 'enqueueAssets']); | |
| 63 | -            add_action('wp_enqueue_scripts', [$controller, 'enqueueAssets']); | |
| 64 | -            add_action('admin_footer', [$controller, 'renderBar'], 99999); | |
| 65 | -            add_action('wp_footer', [$controller, 'renderBar'], 99999); | |
| 66 | -            add_filter('admin_body_class', [$controller, 'filterBodyClasses']); | |
| 62 | + add_action( 'admin_enqueue_scripts', [ $controller, 'enqueueAssets' ] ); | |
| 63 | + add_action( 'wp_enqueue_scripts', [ $controller, 'enqueueAssets' ] ); | |
| 64 | + add_action( 'admin_footer', [ $controller, 'renderBar' ], 99999 ); | |
| 65 | + add_action( 'wp_footer', [ $controller, 'renderBar' ], 99999 ); | |
| 66 | + add_filter( 'admin_body_class', [ $controller, 'filterBodyClasses' ] ); | |
| 67 | 67 | }); | 
| 68 | - set_error_handler([$this, 'errorHandler'], E_ALL | E_STRICT); | |
| 68 | + set_error_handler( [ $this, 'errorHandler' ], E_ALL | E_STRICT ); | |
| 69 | 69 | } | 
| 70 | 70 | |
| 71 | 71 | /** | 
| @@ -73,32 +73,32 @@ discard block | ||
| 73 | 73 | */ | 
| 74 | 74 | public static function load() | 
| 75 | 75 |      { | 
| 76 | -        if (empty(self::$instance)) { | |
| 76 | +        if( empty( self::$instance ) ) { | |
| 77 | 77 | self::$instance = new static(); | 
| 78 | 78 | } | 
| 79 | 79 | return self::$instance; | 
| 80 | 80 | } | 
| 81 | 81 | |
| 82 | - public function path(string $file = '', bool $realpath = true): string | |
| 82 | + public function path( string $file = '', bool $realpath = true ): string | |
| 83 | 83 |      { | 
| 84 | 84 | $path = $realpath | 
| 85 | - ? plugin_dir_path($this->file) | |
| 86 | - : trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); | |
| 87 | - return trailingslashit($path).ltrim(trim($file), '/'); | |
| 85 | + ? plugin_dir_path( $this->file ) | |
| 86 | + : trailingslashit( WP_PLUGIN_DIR ) . basename( dirname( $this->file ) ); | |
| 87 | + return trailingslashit( $path ) . ltrim( trim( $file ), '/' ); | |
| 88 | 88 | } | 
| 89 | 89 | |
| 90 | - public function render(string $view, array $data = []): void | |
| 90 | + public function render( string $view, array $data = [ ] ): void | |
| 91 | 91 |      { | 
| 92 | -        $file = $this->path(sprintf('views/%s.php', str_replace('.php', '', $view))); | |
| 93 | -        if (!file_exists($file)) { | |
| 92 | + $file = $this->path( sprintf( 'views/%s.php', str_replace( '.php', '', $view ) ) ); | |
| 93 | +        if( !file_exists( $file ) ) { | |
| 94 | 94 | return; | 
| 95 | 95 | } | 
| 96 | - extract($data); | |
| 96 | + extract( $data ); | |
| 97 | 97 | include $file; | 
| 98 | 98 | } | 
| 99 | 99 | |
| 100 | - public function url(string $path = ''): string | |
| 100 | + public function url( string $path = '' ): string | |
| 101 | 101 |      { | 
| 102 | - return esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); | |
| 102 | + return esc_url( plugin_dir_url( $this->file ) . ltrim( trim( $path ), '/' ) ); | |
| 103 | 103 | } | 
| 104 | 104 | } | 
| @@ -25,7 +25,8 @@ discard block | ||
| 25 | 25 | 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT', | 
| 26 | 26 | 'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE', | 
| 27 | 27 | ]; | 
| 28 | -        $replace = array_map(function ($value) { | |
| 28 | + $replace = array_map(function ($value) | |
| 29 | +        { | |
| 29 | 30 | return PHP_EOL.$value; | 
| 30 | 31 | }, $search); | 
| 31 | 32 |          foreach ($wpdb->queries as $query) { | 
| @@ -35,7 +36,8 @@ discard block | ||
| 35 | 36 |              $sql = str_replace(['( ',' )',' ,'], ['(',')',','], $sql); | 
| 36 | 37 | $sql = str_replace($search, $replace, $sql); | 
| 37 | 38 | $parts = explode(PHP_EOL, $sql); | 
| 38 | -            $sql = array_reduce($parts, function ($carry, $part) { | |
| 39 | + $sql = array_reduce($parts, function ($carry, $part) | |
| 40 | +            { | |
| 39 | 41 |                  if (str_starts_with($part, 'SELECT') && strlen($part) > 100) { | 
| 40 | 42 |                      $part = preg_replace('/\s*(,)\s*/', ','.PHP_EOL.'  ', $part); | 
| 41 | 43 | } | 
| @@ -6,74 +6,74 @@ | ||
| 6 | 6 | |
| 7 | 7 | class Queries extends Module | 
| 8 | 8 |  { | 
| 9 | - public function entries(): array | |
| 10 | -    { | |
| 11 | - global $wpdb; | |
| 12 | - $entries = []; | |
| 13 | - $index = 0; | |
| 14 | - $search = [ | |
| 15 | - 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT', | |
| 16 | - 'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE', | |
| 17 | - ]; | |
| 18 | -        $replace = array_map(function ($value) { | |
| 19 | - return PHP_EOL.$value; | |
| 20 | - }, $search); | |
| 21 | -        foreach ($wpdb->queries as $query) { | |
| 22 | -            $sql = preg_replace('/\s\s+/', ' ', trim($query[0])); | |
| 23 | - $sql = str_replace(PHP_EOL, ' ', $sql); | |
| 24 | -            $sql = str_replace(['( ',' )',' ,'], ['(',')',','], $sql); | |
| 25 | - $sql = str_replace($search, $replace, $sql); | |
| 26 | - $parts = explode(PHP_EOL, $sql); | |
| 27 | -            $sql = array_reduce($parts, function ($carry, $part) { | |
| 28 | -                if (str_starts_with($part, 'SELECT') && strlen($part) > 100) { | |
| 29 | -                    $part = preg_replace('/\s*(,)\s*/', ','.PHP_EOL.'  ', $part); | |
| 30 | - } | |
| 31 | -                if (str_starts_with($part, 'WHERE')) { | |
| 32 | -                    $part = str_replace('AND', PHP_EOL.'  AND', $part); | |
| 33 | - } | |
| 34 | - return $carry.$part.PHP_EOL; | |
| 35 | - }); | |
| 36 | -            $trace = explode(', ', $query[2]); | |
| 37 | - $nanoseconds = (int) round($query[1] * 1e9); | |
| 38 | - $entries[] = [ | |
| 39 | - 'index' => $index++, | |
| 40 | - 'sql' => $sql, | |
| 41 | - 'time' => $nanoseconds, | |
| 42 | - 'time_formatted' => $this->formatTime($nanoseconds), | |
| 43 | - 'trace' => array_reverse($trace, true), | |
| 44 | - ]; | |
| 45 | - } | |
| 46 | - uasort($entries, [$this, 'sortByTime']); | |
| 47 | - return $entries; | |
| 48 | - } | |
| 9 | + public function entries(): array | |
| 10 | +	{ | |
| 11 | + global $wpdb; | |
| 12 | + $entries = []; | |
| 13 | + $index = 0; | |
| 14 | + $search = [ | |
| 15 | + 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT', | |
| 16 | + 'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE', | |
| 17 | + ]; | |
| 18 | +		$replace = array_map(function ($value) { | |
| 19 | + return PHP_EOL.$value; | |
| 20 | + }, $search); | |
| 21 | +		foreach ($wpdb->queries as $query) { | |
| 22 | +			$sql = preg_replace('/\s\s+/', ' ', trim($query[0])); | |
| 23 | + $sql = str_replace(PHP_EOL, ' ', $sql); | |
| 24 | +			$sql = str_replace(['( ',' )',' ,'], ['(',')',','], $sql); | |
| 25 | + $sql = str_replace($search, $replace, $sql); | |
| 26 | + $parts = explode(PHP_EOL, $sql); | |
| 27 | +			$sql = array_reduce($parts, function ($carry, $part) { | |
| 28 | +				if (str_starts_with($part, 'SELECT') && strlen($part) > 100) { | |
| 29 | +					$part = preg_replace('/\s*(,)\s*/', ','.PHP_EOL.'  ', $part); | |
| 30 | + } | |
| 31 | +				if (str_starts_with($part, 'WHERE')) { | |
| 32 | +					$part = str_replace('AND', PHP_EOL.'  AND', $part); | |
| 33 | + } | |
| 34 | + return $carry.$part.PHP_EOL; | |
| 35 | + }); | |
| 36 | +			$trace = explode(', ', $query[2]); | |
| 37 | + $nanoseconds = (int) round($query[1] * 1e9); | |
| 38 | + $entries[] = [ | |
| 39 | + 'index' => $index++, | |
| 40 | + 'sql' => $sql, | |
| 41 | + 'time' => $nanoseconds, | |
| 42 | + 'time_formatted' => $this->formatTime($nanoseconds), | |
| 43 | + 'trace' => array_reverse($trace, true), | |
| 44 | + ]; | |
| 45 | + } | |
| 46 | + uasort($entries, [$this, 'sortByTime']); | |
| 47 | + return $entries; | |
| 48 | + } | |
| 49 | 49 | |
| 50 | - public function hasEntries(): bool | |
| 51 | -    { | |
| 52 | - global $wpdb; | |
| 53 | - return !empty($wpdb->queries); | |
| 54 | - } | |
| 50 | + public function hasEntries(): bool | |
| 51 | +	{ | |
| 52 | + global $wpdb; | |
| 53 | + return !empty($wpdb->queries); | |
| 54 | + } | |
| 55 | 55 | |
| 56 | - public function info(): string | |
| 57 | -    { | |
| 58 | -        if (!defined('SAVEQUERIES') || !SAVEQUERIES) { | |
| 59 | - return ''; | |
| 60 | - } | |
| 61 | - global $wpdb; | |
| 62 | - $seconds = (float) array_sum(wp_list_pluck($wpdb->queries, 1)); | |
| 63 | - $nanoseconds = (int) round($seconds * 1e9); | |
| 64 | - return $this->formatTime($nanoseconds); | |
| 65 | - } | |
| 56 | + public function info(): string | |
| 57 | +	{ | |
| 58 | +		if (!defined('SAVEQUERIES') || !SAVEQUERIES) { | |
| 59 | + return ''; | |
| 60 | + } | |
| 61 | + global $wpdb; | |
| 62 | + $seconds = (float) array_sum(wp_list_pluck($wpdb->queries, 1)); | |
| 63 | + $nanoseconds = (int) round($seconds * 1e9); | |
| 64 | + return $this->formatTime($nanoseconds); | |
| 65 | + } | |
| 66 | 66 | |
| 67 | - public function label(): string | |
| 68 | -    { | |
| 69 | -        return __('SQL', 'blackbar'); | |
| 70 | - } | |
| 67 | + public function label(): string | |
| 68 | +	{ | |
| 69 | +		return __('SQL', 'blackbar'); | |
| 70 | + } | |
| 71 | 71 | |
| 72 | - protected function sortByTime(array $a, array $b): int | |
| 73 | -    { | |
| 74 | -        if ($a['time'] !== $b['time']) { | |
| 75 | - return ($a['time'] > $b['time']) ? -1 : 1; | |
| 76 | - } | |
| 77 | - return 0; | |
| 78 | - } | |
| 72 | + protected function sortByTime(array $a, array $b): int | |
| 73 | +	{ | |
| 74 | +		if ($a['time'] !== $b['time']) { | |
| 75 | + return ($a['time'] > $b['time']) ? -1 : 1; | |
| 76 | + } | |
| 77 | + return 0; | |
| 78 | + } | |
| 79 | 79 | } | 
| @@ -9,70 +9,70 @@ | ||
| 9 | 9 | public function entries(): array | 
| 10 | 10 |      { | 
| 11 | 11 | global $wpdb; | 
| 12 | - $entries = []; | |
| 12 | + $entries = [ ]; | |
| 13 | 13 | $index = 0; | 
| 14 | 14 | $search = [ | 
| 15 | 15 | 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT', | 
| 16 | 16 | 'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE', | 
| 17 | 17 | ]; | 
| 18 | -        $replace = array_map(function ($value) { | |
| 19 | - return PHP_EOL.$value; | |
| 20 | - }, $search); | |
| 21 | -        foreach ($wpdb->queries as $query) { | |
| 22 | -            $sql = preg_replace('/\s\s+/', ' ', trim($query[0])); | |
| 23 | - $sql = str_replace(PHP_EOL, ' ', $sql); | |
| 24 | -            $sql = str_replace(['( ',' )',' ,'], ['(',')',','], $sql); | |
| 25 | - $sql = str_replace($search, $replace, $sql); | |
| 26 | - $parts = explode(PHP_EOL, $sql); | |
| 27 | -            $sql = array_reduce($parts, function ($carry, $part) { | |
| 28 | -                if (str_starts_with($part, 'SELECT') && strlen($part) > 100) { | |
| 29 | -                    $part = preg_replace('/\s*(,)\s*/', ','.PHP_EOL.'  ', $part); | |
| 18 | +        $replace = array_map( function( $value ) { | |
| 19 | + return PHP_EOL . $value; | |
| 20 | + }, $search ); | |
| 21 | +        foreach( $wpdb->queries as $query ) { | |
| 22 | + $sql = preg_replace( '/\s\s+/', ' ', trim( $query[ 0 ] ) ); | |
| 23 | + $sql = str_replace( PHP_EOL, ' ', $sql ); | |
| 24 | +            $sql = str_replace( [ '( ', ' )', ' ,' ], [ '(', ')', ',' ], $sql ); | |
| 25 | + $sql = str_replace( $search, $replace, $sql ); | |
| 26 | + $parts = explode( PHP_EOL, $sql ); | |
| 27 | +            $sql = array_reduce( $parts, function( $carry, $part ) { | |
| 28 | +                if( str_starts_with( $part, 'SELECT' ) && strlen( $part ) > 100 ) { | |
| 29 | + $part = preg_replace( '/\s*(,)\s*/', ',' . PHP_EOL . ' ', $part ); | |
| 30 | 30 | } | 
| 31 | -                if (str_starts_with($part, 'WHERE')) { | |
| 32 | -                    $part = str_replace('AND', PHP_EOL.'  AND', $part); | |
| 31 | +                if( str_starts_with( $part, 'WHERE' ) ) { | |
| 32 | + $part = str_replace( 'AND', PHP_EOL . ' AND', $part ); | |
| 33 | 33 | } | 
| 34 | - return $carry.$part.PHP_EOL; | |
| 34 | + return $carry . $part . PHP_EOL; | |
| 35 | 35 | }); | 
| 36 | -            $trace = explode(', ', $query[2]); | |
| 37 | - $nanoseconds = (int) round($query[1] * 1e9); | |
| 38 | - $entries[] = [ | |
| 36 | + $trace = explode( ', ', $query[ 2 ] ); | |
| 37 | + $nanoseconds = (int) round( $query[ 1 ] * 1e9 ); | |
| 38 | + $entries[ ] = [ | |
| 39 | 39 | 'index' => $index++, | 
| 40 | 40 | 'sql' => $sql, | 
| 41 | 41 | 'time' => $nanoseconds, | 
| 42 | - 'time_formatted' => $this->formatTime($nanoseconds), | |
| 43 | - 'trace' => array_reverse($trace, true), | |
| 42 | + 'time_formatted' => $this->formatTime( $nanoseconds ), | |
| 43 | + 'trace' => array_reverse( $trace, true ), | |
| 44 | 44 | ]; | 
| 45 | 45 | } | 
| 46 | - uasort($entries, [$this, 'sortByTime']); | |
| 46 | + uasort( $entries, [ $this, 'sortByTime' ] ); | |
| 47 | 47 | return $entries; | 
| 48 | 48 | } | 
| 49 | 49 | |
| 50 | 50 | public function hasEntries(): bool | 
| 51 | 51 |      { | 
| 52 | 52 | global $wpdb; | 
| 53 | - return !empty($wpdb->queries); | |
| 53 | + return !empty( $wpdb->queries ); | |
| 54 | 54 | } | 
| 55 | 55 | |
| 56 | 56 | public function info(): string | 
| 57 | 57 |      { | 
| 58 | -        if (!defined('SAVEQUERIES') || !SAVEQUERIES) { | |
| 58 | +        if( !defined( 'SAVEQUERIES' ) || !SAVEQUERIES ) { | |
| 59 | 59 | return ''; | 
| 60 | 60 | } | 
| 61 | 61 | global $wpdb; | 
| 62 | - $seconds = (float) array_sum(wp_list_pluck($wpdb->queries, 1)); | |
| 63 | - $nanoseconds = (int) round($seconds * 1e9); | |
| 64 | - return $this->formatTime($nanoseconds); | |
| 62 | + $seconds = (float) array_sum( wp_list_pluck( $wpdb->queries, 1 ) ); | |
| 63 | + $nanoseconds = (int) round( $seconds * 1e9 ); | |
| 64 | + return $this->formatTime( $nanoseconds ); | |
| 65 | 65 | } | 
| 66 | 66 | |
| 67 | 67 | public function label(): string | 
| 68 | 68 |      { | 
| 69 | -        return __('SQL', 'blackbar'); | |
| 69 | + return __( 'SQL', 'blackbar' ); | |
| 70 | 70 | } | 
| 71 | 71 | |
| 72 | - protected function sortByTime(array $a, array $b): int | |
| 72 | + protected function sortByTime( array $a, array $b ): int | |
| 73 | 73 |      { | 
| 74 | -        if ($a['time'] !== $b['time']) { | |
| 75 | - return ($a['time'] > $b['time']) ? -1 : 1; | |
| 74 | +        if( $a[ 'time' ] !== $b[ 'time' ] ) { | |
| 75 | + return ( $a[ 'time' ] > $b[ 'time' ] ) ? -1 : 1; | |
| 76 | 76 | } | 
| 77 | 77 | return 0; | 
| 78 | 78 | } | 
| @@ -8,9 +8,12 @@ | ||
| 8 | 8 | </tr> | 
| 9 | 9 | </tbody> | 
| 10 | 10 | </table> | 
| 11 | -<?php else : ?> | |
| 11 | +<?php else { | |
| 12 | + : ?> | |
| 12 | 13 | <form> | 
| 13 | -        <input type="text" id="glbb_queries_sql" placeholder="<?= esc_attr__('Find SQL containing', 'blackbar'); ?>"> | |
| 14 | +        <input type="text" id="glbb_queries_sql" placeholder="<?= esc_attr__('Find SQL containing', 'blackbar'); | |
| 15 | +} | |
| 16 | +?>"> | |
| 14 | 17 |          <input type="text" id="glbb_queries_min_time" placeholder="<?= esc_attr__('Minimum execution time', 'blackbar'); ?>"> | 
| 15 | 18 | <select id="glbb_queries_sort_by"> | 
| 16 | 19 |              <option value><?= esc_html__('Sort by execution time', 'blackbar'); ?></option> | 
| @@ -1,32 +1,32 @@ | ||
| 1 | -<?php defined('WPINC') || die; ?> | |
| 1 | +<?php defined( 'WPINC' ) || die; ?> | |
| 2 | 2 | |
| 3 | -<?php if (!defined('SAVEQUERIES') || !SAVEQUERIES) : ?> | |
| 3 | +<?php if( !defined( 'SAVEQUERIES' ) || !SAVEQUERIES ) : ?> | |
| 4 | 4 | <table> | 
| 5 | 5 | <tbody> | 
| 6 | 6 | <tr> | 
| 7 | -                <td><a href="https://wordpress.org/documentation/article/debugging-in-wordpress/#savequeries" target="_blank">SAVEQUERIES</a> <?= esc_html_x('must be enabled to view SQL queries', 'SAVEQUERIES', 'blackbar'); ?>.</td> | |
| 7 | + <td><a href="https://wordpress.org/documentation/article/debugging-in-wordpress/#savequeries" target="_blank">SAVEQUERIES</a> <?= esc_html_x( 'must be enabled to view SQL queries', 'SAVEQUERIES', 'blackbar' ); ?>.</td> | |
| 8 | 8 | </tr> | 
| 9 | 9 | </tbody> | 
| 10 | 10 | </table> | 
| 11 | 11 | <?php else : ?> | 
| 12 | 12 | <form> | 
| 13 | -        <input type="text" id="glbb_queries_sql" placeholder="<?= esc_attr__('Find SQL containing', 'blackbar'); ?>"> | |
| 14 | -        <input type="text" id="glbb_queries_min_time" placeholder="<?= esc_attr__('Minimum execution time', 'blackbar'); ?>"> | |
| 13 | + <input type="text" id="glbb_queries_sql" placeholder="<?= esc_attr__( 'Find SQL containing', 'blackbar' ); ?>"> | |
| 14 | + <input type="text" id="glbb_queries_min_time" placeholder="<?= esc_attr__( 'Minimum execution time', 'blackbar' ); ?>"> | |
| 15 | 15 | <select id="glbb_queries_sort_by"> | 
| 16 | -            <option value><?= esc_html__('Sort by execution time', 'blackbar'); ?></option> | |
| 17 | -            <option value="order"><?= esc_html__('Sort by execution order', 'blackbar'); ?></option> | |
| 16 | + <option value><?= esc_html__( 'Sort by execution time', 'blackbar' ); ?></option> | |
| 17 | + <option value="order"><?= esc_html__( 'Sort by execution order', 'blackbar' ); ?></option> | |
| 18 | 18 | </select> | 
| 19 | 19 | </form> | 
| 20 | 20 | <table class="glbb-grid"> | 
| 21 | 21 | <tbody> | 
| 22 | - <?php foreach ($module->entries() as $entry) : ?> | |
| 23 | - <tr class="glbb-row-collapsed" data-index="<?= esc_attr($entry['index']); ?>" data-time="<?= esc_attr($entry['time']); ?>"> | |
| 24 | - <td data-time="<?= esc_attr($entry['time_formatted']); ?>"><div class="glbb-row-toggle dashicons-before dashicons-arrow-right"><?= esc_html($entry['time_formatted']); ?></div></td> | |
| 25 | - <td data-sql><pre><code class="language-sql"><?= esc_html($entry['sql']); ?></code></pre></td> | |
| 22 | + <?php foreach( $module->entries() as $entry ) : ?> | |
| 23 | + <tr class="glbb-row-collapsed" data-index="<?= esc_attr( $entry[ 'index' ] ); ?>" data-time="<?= esc_attr( $entry[ 'time' ] ); ?>"> | |
| 24 | + <td data-time="<?= esc_attr( $entry[ 'time_formatted' ] ); ?>"><div class="glbb-row-toggle dashicons-before dashicons-arrow-right"><?= esc_html( $entry[ 'time_formatted' ] ); ?></div></td> | |
| 25 | + <td data-sql><pre><code class="language-sql"><?= esc_html( $entry[ 'sql' ] ); ?></code></pre></td> | |
| 26 | 26 | <td class="glbb-row-details"> | 
| 27 | 27 | <ol> | 
| 28 | - <?php foreach ($entry['trace'] as $index => $line) : ?> | |
| 29 | - <li value="<?= esc_attr($index + 1); ?>"><?= esc_html($line); ?></li> | |
| 28 | + <?php foreach( $entry[ 'trace' ] as $index => $line ) : ?> | |
| 29 | + <li value="<?= esc_attr( $index + 1 ); ?>"><?= esc_html( $line ); ?></li> | |
| 30 | 30 | <?php endforeach; ?> | 
| 31 | 31 | </ol> | 
| 32 | 32 | </td> | 
| @@ -7,142 +7,142 @@ | ||
| 7 | 7 | */ | 
| 8 | 8 | class Dump | 
| 9 | 9 |  { | 
| 10 | - public $depth; | |
| 11 | - public $ignore; | |
| 10 | + public $depth; | |
| 11 | + public $ignore; | |
| 12 | 12 | |
| 13 | - protected $level = 0; | |
| 14 | - protected $result = []; | |
| 15 | - protected $stack = []; | |
| 13 | + protected $level = 0; | |
| 14 | + protected $result = []; | |
| 15 | + protected $stack = []; | |
| 16 | 16 | |
| 17 | - /** | |
| 18 | - * @param mixed $value | |
| 19 | - */ | |
| 20 | - public function dump($value, int $depth = 3, array $ignore = []): string | |
| 21 | -    { | |
| 22 | - $this->depth = $depth; | |
| 23 | - $this->ignore = $ignore; | |
| 24 | - $this->reset(); | |
| 25 | - $this->inspect($value); | |
| 26 | -        $result = implode('', $this->result); | |
| 27 | - $result = rtrim($result, "\n"); | |
| 28 | - $this->reset(); | |
| 29 | - return $result; | |
| 30 | - } | |
| 17 | + /** | |
| 18 | + * @param mixed $value | |
| 19 | + */ | |
| 20 | + public function dump($value, int $depth = 3, array $ignore = []): string | |
| 21 | +	{ | |
| 22 | + $this->depth = $depth; | |
| 23 | + $this->ignore = $ignore; | |
| 24 | + $this->reset(); | |
| 25 | + $this->inspect($value); | |
| 26 | +		$result = implode('', $this->result); | |
| 27 | + $result = rtrim($result, "\n"); | |
| 28 | + $this->reset(); | |
| 29 | + return $result; | |
| 30 | + } | |
| 31 | 31 | |
| 32 | - protected function formatKey(string $key): string | |
| 33 | -    { | |
| 34 | - $result = []; | |
| 35 | -        $result[] = str_repeat(' ', $this->level * 4).'['; | |
| 36 | -        if (is_string($key) && "\0" === $key[0]) { | |
| 37 | -            $keyParts = explode("\0", $key); | |
| 38 | -            $result[] = $keyParts[2].(('*' === $keyParts[1]) ? ':protected' : ':private'); | |
| 39 | -        } else { | |
| 40 | - $result[] = $key; | |
| 41 | - } | |
| 42 | - $result[] = '] => '; | |
| 43 | -        return implode('', $result); | |
| 44 | - } | |
| 32 | + protected function formatKey(string $key): string | |
| 33 | +	{ | |
| 34 | + $result = []; | |
| 35 | +		$result[] = str_repeat(' ', $this->level * 4).'['; | |
| 36 | +		if (is_string($key) && "\0" === $key[0]) { | |
| 37 | +			$keyParts = explode("\0", $key); | |
| 38 | +			$result[] = $keyParts[2].(('*' === $keyParts[1]) ? ':protected' : ':private'); | |
| 39 | +		} else { | |
| 40 | + $result[] = $key; | |
| 41 | + } | |
| 42 | + $result[] = '] => '; | |
| 43 | +		return implode('', $result); | |
| 44 | + } | |
| 45 | 45 | |
| 46 | - /** | |
| 47 | - * @param mixed $subject | |
| 48 | - */ | |
| 49 | - protected function inspect($subject): void | |
| 50 | -    { | |
| 51 | - ++$this->level; | |
| 52 | -        if ($subject instanceof \Closure) { | |
| 53 | - $this->inspectClosure($subject); | |
| 54 | -        } elseif (is_object($subject)) { | |
| 55 | - $this->inspectObject($subject); | |
| 56 | -        } elseif (is_array($subject)) { | |
| 57 | - $this->inspectArray($subject); | |
| 58 | -        } else { | |
| 59 | - $this->inspectPrimitive($subject); | |
| 60 | - } | |
| 61 | - --$this->level; | |
| 62 | - } | |
| 46 | + /** | |
| 47 | + * @param mixed $subject | |
| 48 | + */ | |
| 49 | + protected function inspect($subject): void | |
| 50 | +	{ | |
| 51 | + ++$this->level; | |
| 52 | +		if ($subject instanceof \Closure) { | |
| 53 | + $this->inspectClosure($subject); | |
| 54 | +		} elseif (is_object($subject)) { | |
| 55 | + $this->inspectObject($subject); | |
| 56 | +		} elseif (is_array($subject)) { | |
| 57 | + $this->inspectArray($subject); | |
| 58 | +		} else { | |
| 59 | + $this->inspectPrimitive($subject); | |
| 60 | + } | |
| 61 | + --$this->level; | |
| 62 | + } | |
| 63 | 63 | |
| 64 | - protected function inspectArray(array $subject): void | |
| 65 | -    { | |
| 66 | -        if ($this->level > $this->depth) { | |
| 67 | - $this->result[] = "Nested Array\n"; | |
| 68 | - return; | |
| 69 | - } | |
| 70 | -        if (empty($subject)) { | |
| 71 | - $this->result[] = "Array ()\n"; | |
| 72 | - return; | |
| 73 | - } | |
| 74 | - $this->result[] = "Array (\n"; | |
| 75 | -        foreach ($subject as $key => $val) { | |
| 76 | -            if (false === $this->isIgnoredKey($key)) { | |
| 77 | -                $this->result[] = str_repeat(' ', $this->level * 4).'['.$key.'] => '; | |
| 78 | - $this->inspect($val); | |
| 79 | - } | |
| 80 | - } | |
| 81 | -        $this->result[] = str_repeat(' ', ($this->level - 1) * 4).")\n"; | |
| 82 | - } | |
| 64 | + protected function inspectArray(array $subject): void | |
| 65 | +	{ | |
| 66 | +		if ($this->level > $this->depth) { | |
| 67 | + $this->result[] = "Nested Array\n"; | |
| 68 | + return; | |
| 69 | + } | |
| 70 | +		if (empty($subject)) { | |
| 71 | + $this->result[] = "Array ()\n"; | |
| 72 | + return; | |
| 73 | + } | |
| 74 | + $this->result[] = "Array (\n"; | |
| 75 | +		foreach ($subject as $key => $val) { | |
| 76 | +			if (false === $this->isIgnoredKey($key)) { | |
| 77 | +				$this->result[] = str_repeat(' ', $this->level * 4).'['.$key.'] => '; | |
| 78 | + $this->inspect($val); | |
| 79 | + } | |
| 80 | + } | |
| 81 | +		$this->result[] = str_repeat(' ', ($this->level - 1) * 4).")\n"; | |
| 82 | + } | |
| 83 | 83 | |
| 84 | - protected function inspectClosure(\Closure $subject): void | |
| 85 | -    { | |
| 86 | - $reflection = new \ReflectionFunction($subject); | |
| 87 | -        $params = array_map(function ($param) { | |
| 88 | - return ($param->isPassedByReference() ? '&$' : '$').$param->name; | |
| 89 | - }, $reflection->getParameters()); | |
| 90 | -        $this->result[] = 'Closure ('.implode(', ', $params).') { ... }'."\n"; | |
| 91 | - } | |
| 84 | + protected function inspectClosure(\Closure $subject): void | |
| 85 | +	{ | |
| 86 | + $reflection = new \ReflectionFunction($subject); | |
| 87 | +		$params = array_map(function ($param) { | |
| 88 | + return ($param->isPassedByReference() ? '&$' : '$').$param->name; | |
| 89 | + }, $reflection->getParameters()); | |
| 90 | +		$this->result[] = 'Closure ('.implode(', ', $params).') { ... }'."\n"; | |
| 91 | + } | |
| 92 | 92 | |
| 93 | - /** | |
| 94 | - * @param object $subject | |
| 95 | - */ | |
| 96 | - protected function inspectObject($subject): void | |
| 97 | -    { | |
| 98 | - $classname = get_class($subject); | |
| 99 | -        if ($this->level > $this->depth) { | |
| 100 | - $this->result[] = 'Nested '.$classname." Object\n"; | |
| 101 | - return; | |
| 102 | - } | |
| 103 | -        if ($subject instanceof \ArrayObject) { | |
| 104 | - $this->result[] = $classname." ArrayObject (\n"; | |
| 105 | -        } else { | |
| 106 | - $this->result[] = $classname." Object (\n"; | |
| 107 | - $subject = (array) $subject; | |
| 108 | - } | |
| 109 | -        foreach ($subject as $key => $val) { | |
| 110 | -            if (false === $this->isIgnoredKey($key)) { | |
| 111 | - $this->result[] = $this->formatKey($key); | |
| 112 | - $this->inspect($val); | |
| 113 | - } | |
| 114 | - } | |
| 115 | -        $this->result[] = str_repeat(' ', ($this->level - 1) * 4).")\n"; | |
| 116 | - } | |
| 93 | + /** | |
| 94 | + * @param object $subject | |
| 95 | + */ | |
| 96 | + protected function inspectObject($subject): void | |
| 97 | +	{ | |
| 98 | + $classname = get_class($subject); | |
| 99 | +		if ($this->level > $this->depth) { | |
| 100 | + $this->result[] = 'Nested '.$classname." Object\n"; | |
| 101 | + return; | |
| 102 | + } | |
| 103 | +		if ($subject instanceof \ArrayObject) { | |
| 104 | + $this->result[] = $classname." ArrayObject (\n"; | |
| 105 | +		} else { | |
| 106 | + $this->result[] = $classname." Object (\n"; | |
| 107 | + $subject = (array) $subject; | |
| 108 | + } | |
| 109 | +		foreach ($subject as $key => $val) { | |
| 110 | +			if (false === $this->isIgnoredKey($key)) { | |
| 111 | + $this->result[] = $this->formatKey($key); | |
| 112 | + $this->inspect($val); | |
| 113 | + } | |
| 114 | + } | |
| 115 | +		$this->result[] = str_repeat(' ', ($this->level - 1) * 4).")\n"; | |
| 116 | + } | |
| 117 | 117 | |
| 118 | - /** | |
| 119 | - * @param mixed $subject | |
| 120 | - */ | |
| 121 | - protected function inspectPrimitive($subject): void | |
| 122 | -    { | |
| 123 | -        if (true === $subject) { | |
| 124 | - $subject = '(bool) true'; | |
| 125 | -        } elseif (false === $subject) { | |
| 126 | - $subject = '(bool) false'; | |
| 127 | -        } elseif (null === $subject) { | |
| 128 | - $subject = '(null)'; | |
| 129 | - } | |
| 130 | - $this->result[] = $subject."\n"; | |
| 131 | - } | |
| 118 | + /** | |
| 119 | + * @param mixed $subject | |
| 120 | + */ | |
| 121 | + protected function inspectPrimitive($subject): void | |
| 122 | +	{ | |
| 123 | +		if (true === $subject) { | |
| 124 | + $subject = '(bool) true'; | |
| 125 | +		} elseif (false === $subject) { | |
| 126 | + $subject = '(bool) false'; | |
| 127 | +		} elseif (null === $subject) { | |
| 128 | + $subject = '(null)'; | |
| 129 | + } | |
| 130 | + $this->result[] = $subject."\n"; | |
| 131 | + } | |
| 132 | 132 | |
| 133 | - /** | |
| 134 | - * @param string $key | |
| 135 | - */ | |
| 136 | - protected function isIgnoredKey($key): bool | |
| 137 | -    { | |
| 138 | - return in_array($key, $this->ignore); | |
| 139 | - } | |
| 133 | + /** | |
| 134 | + * @param string $key | |
| 135 | + */ | |
| 136 | + protected function isIgnoredKey($key): bool | |
| 137 | +	{ | |
| 138 | + return in_array($key, $this->ignore); | |
| 139 | + } | |
| 140 | 140 | |
| 141 | - protected function reset(): void | |
| 142 | -    { | |
| 143 | - $this->level = 0; | |
| 144 | - $this->result = []; | |
| 145 | - $this->stack = []; | |
| 146 | - } | |
| 141 | + protected function reset(): void | |
| 142 | +	{ | |
| 143 | + $this->level = 0; | |
| 144 | + $this->result = []; | |
| 145 | + $this->stack = []; | |
| 146 | + } | |
| 147 | 147 | } | 
| 148 | 148 | |
| @@ -11,138 +11,138 @@ | ||
| 11 | 11 | public $ignore; | 
| 12 | 12 | |
| 13 | 13 | protected $level = 0; | 
| 14 | - protected $result = []; | |
| 15 | - protected $stack = []; | |
| 14 | + protected $result = [ ]; | |
| 15 | + protected $stack = [ ]; | |
| 16 | 16 | |
| 17 | 17 | /** | 
| 18 | 18 | * @param mixed $value | 
| 19 | 19 | */ | 
| 20 | - public function dump($value, int $depth = 3, array $ignore = []): string | |
| 20 | + public function dump( $value, int $depth = 3, array $ignore = [ ] ): string | |
| 21 | 21 |      { | 
| 22 | 22 | $this->depth = $depth; | 
| 23 | 23 | $this->ignore = $ignore; | 
| 24 | 24 | $this->reset(); | 
| 25 | - $this->inspect($value); | |
| 26 | -        $result = implode('', $this->result); | |
| 27 | - $result = rtrim($result, "\n"); | |
| 25 | + $this->inspect( $value ); | |
| 26 | + $result = implode( '', $this->result ); | |
| 27 | + $result = rtrim( $result, "\n" ); | |
| 28 | 28 | $this->reset(); | 
| 29 | 29 | return $result; | 
| 30 | 30 | } | 
| 31 | 31 | |
| 32 | - protected function formatKey(string $key): string | |
| 32 | + protected function formatKey( string $key ): string | |
| 33 | 33 |      { | 
| 34 | - $result = []; | |
| 35 | -        $result[] = str_repeat(' ', $this->level * 4).'['; | |
| 36 | -        if (is_string($key) && "\0" === $key[0]) { | |
| 37 | -            $keyParts = explode("\0", $key); | |
| 38 | -            $result[] = $keyParts[2].(('*' === $keyParts[1]) ? ':protected' : ':private'); | |
| 34 | + $result = [ ]; | |
| 35 | + $result[ ] = str_repeat( ' ', $this->level * 4 ) . '['; | |
| 36 | +        if( is_string( $key ) && "\0" === $key[ 0 ] ) { | |
| 37 | + $keyParts = explode( "\0", $key ); | |
| 38 | + $result[ ] = $keyParts[ 2 ] . ( ( '*' === $keyParts[ 1 ] ) ? ':protected' : ':private' ); | |
| 39 | 39 |          } else { | 
| 40 | - $result[] = $key; | |
| 40 | + $result[ ] = $key; | |
| 41 | 41 | } | 
| 42 | - $result[] = '] => '; | |
| 43 | -        return implode('', $result); | |
| 42 | + $result[ ] = '] => '; | |
| 43 | + return implode( '', $result ); | |
| 44 | 44 | } | 
| 45 | 45 | |
| 46 | 46 | /** | 
| 47 | 47 | * @param mixed $subject | 
| 48 | 48 | */ | 
| 49 | - protected function inspect($subject): void | |
| 49 | + protected function inspect( $subject ): void | |
| 50 | 50 |      { | 
| 51 | 51 | ++$this->level; | 
| 52 | -        if ($subject instanceof \Closure) { | |
| 53 | - $this->inspectClosure($subject); | |
| 54 | -        } elseif (is_object($subject)) { | |
| 55 | - $this->inspectObject($subject); | |
| 56 | -        } elseif (is_array($subject)) { | |
| 57 | - $this->inspectArray($subject); | |
| 52 | +        if( $subject instanceof \Closure ) { | |
| 53 | + $this->inspectClosure( $subject ); | |
| 54 | +        } elseif( is_object( $subject ) ) { | |
| 55 | + $this->inspectObject( $subject ); | |
| 56 | +        } elseif( is_array( $subject ) ) { | |
| 57 | + $this->inspectArray( $subject ); | |
| 58 | 58 |          } else { | 
| 59 | - $this->inspectPrimitive($subject); | |
| 59 | + $this->inspectPrimitive( $subject ); | |
| 60 | 60 | } | 
| 61 | 61 | --$this->level; | 
| 62 | 62 | } | 
| 63 | 63 | |
| 64 | - protected function inspectArray(array $subject): void | |
| 64 | + protected function inspectArray( array $subject ): void | |
| 65 | 65 |      { | 
| 66 | -        if ($this->level > $this->depth) { | |
| 67 | - $this->result[] = "Nested Array\n"; | |
| 66 | +        if( $this->level > $this->depth ) { | |
| 67 | + $this->result[ ] = "Nested Array\n"; | |
| 68 | 68 | return; | 
| 69 | 69 | } | 
| 70 | -        if (empty($subject)) { | |
| 71 | - $this->result[] = "Array ()\n"; | |
| 70 | +        if( empty( $subject ) ) { | |
| 71 | + $this->result[ ] = "Array ()\n"; | |
| 72 | 72 | return; | 
| 73 | 73 | } | 
| 74 | - $this->result[] = "Array (\n"; | |
| 75 | -        foreach ($subject as $key => $val) { | |
| 76 | -            if (false === $this->isIgnoredKey($key)) { | |
| 77 | -                $this->result[] = str_repeat(' ', $this->level * 4).'['.$key.'] => '; | |
| 78 | - $this->inspect($val); | |
| 74 | + $this->result[ ] = "Array (\n"; | |
| 75 | +        foreach( $subject as $key => $val ) { | |
| 76 | +            if( false === $this->isIgnoredKey( $key ) ) { | |
| 77 | + $this->result[ ] = str_repeat( ' ', $this->level * 4 ) . '[' . $key . '] => '; | |
| 78 | + $this->inspect( $val ); | |
| 79 | 79 | } | 
| 80 | 80 | } | 
| 81 | -        $this->result[] = str_repeat(' ', ($this->level - 1) * 4).")\n"; | |
| 81 | + $this->result[ ] = str_repeat( ' ', ( $this->level - 1 ) * 4 ) . ")\n"; | |
| 82 | 82 | } | 
| 83 | 83 | |
| 84 | - protected function inspectClosure(\Closure $subject): void | |
| 84 | + protected function inspectClosure( \Closure $subject ): void | |
| 85 | 85 |      { | 
| 86 | - $reflection = new \ReflectionFunction($subject); | |
| 87 | -        $params = array_map(function ($param) { | |
| 88 | - return ($param->isPassedByReference() ? '&$' : '$').$param->name; | |
| 89 | - }, $reflection->getParameters()); | |
| 90 | -        $this->result[] = 'Closure ('.implode(', ', $params).') { ... }'."\n"; | |
| 86 | + $reflection = new \ReflectionFunction( $subject ); | |
| 87 | +        $params = array_map( function( $param ) { | |
| 88 | + return ( $param->isPassedByReference() ? '&$' : '$' ) . $param->name; | |
| 89 | + }, $reflection->getParameters() ); | |
| 90 | +        $this->result[ ] = 'Closure (' . implode( ', ', $params ) . ') { ... }' . "\n"; | |
| 91 | 91 | } | 
| 92 | 92 | |
| 93 | 93 | /** | 
| 94 | 94 | * @param object $subject | 
| 95 | 95 | */ | 
| 96 | - protected function inspectObject($subject): void | |
| 96 | + protected function inspectObject( $subject ): void | |
| 97 | 97 |      { | 
| 98 | - $classname = get_class($subject); | |
| 99 | -        if ($this->level > $this->depth) { | |
| 100 | - $this->result[] = 'Nested '.$classname." Object\n"; | |
| 98 | + $classname = get_class( $subject ); | |
| 99 | +        if( $this->level > $this->depth ) { | |
| 100 | + $this->result[ ] = 'Nested ' . $classname . " Object\n"; | |
| 101 | 101 | return; | 
| 102 | 102 | } | 
| 103 | -        if ($subject instanceof \ArrayObject) { | |
| 104 | - $this->result[] = $classname." ArrayObject (\n"; | |
| 103 | +        if( $subject instanceof \ArrayObject ) { | |
| 104 | + $this->result[ ] = $classname . " ArrayObject (\n"; | |
| 105 | 105 |          } else { | 
| 106 | - $this->result[] = $classname." Object (\n"; | |
| 106 | + $this->result[ ] = $classname . " Object (\n"; | |
| 107 | 107 | $subject = (array) $subject; | 
| 108 | 108 | } | 
| 109 | -        foreach ($subject as $key => $val) { | |
| 110 | -            if (false === $this->isIgnoredKey($key)) { | |
| 111 | - $this->result[] = $this->formatKey($key); | |
| 112 | - $this->inspect($val); | |
| 109 | +        foreach( $subject as $key => $val ) { | |
| 110 | +            if( false === $this->isIgnoredKey( $key ) ) { | |
| 111 | + $this->result[ ] = $this->formatKey( $key ); | |
| 112 | + $this->inspect( $val ); | |
| 113 | 113 | } | 
| 114 | 114 | } | 
| 115 | -        $this->result[] = str_repeat(' ', ($this->level - 1) * 4).")\n"; | |
| 115 | + $this->result[ ] = str_repeat( ' ', ( $this->level - 1 ) * 4 ) . ")\n"; | |
| 116 | 116 | } | 
| 117 | 117 | |
| 118 | 118 | /** | 
| 119 | 119 | * @param mixed $subject | 
| 120 | 120 | */ | 
| 121 | - protected function inspectPrimitive($subject): void | |
| 121 | + protected function inspectPrimitive( $subject ): void | |
| 122 | 122 |      { | 
| 123 | -        if (true === $subject) { | |
| 123 | +        if( true === $subject ) { | |
| 124 | 124 | $subject = '(bool) true'; | 
| 125 | -        } elseif (false === $subject) { | |
| 125 | +        } elseif( false === $subject ) { | |
| 126 | 126 | $subject = '(bool) false'; | 
| 127 | -        } elseif (null === $subject) { | |
| 127 | +        } elseif( null === $subject ) { | |
| 128 | 128 | $subject = '(null)'; | 
| 129 | 129 | } | 
| 130 | - $this->result[] = $subject."\n"; | |
| 130 | + $this->result[ ] = $subject . "\n"; | |
| 131 | 131 | } | 
| 132 | 132 | |
| 133 | 133 | /** | 
| 134 | 134 | * @param string $key | 
| 135 | 135 | */ | 
| 136 | - protected function isIgnoredKey($key): bool | |
| 136 | + protected function isIgnoredKey( $key ): bool | |
| 137 | 137 |      { | 
| 138 | - return in_array($key, $this->ignore); | |
| 138 | + return in_array( $key, $this->ignore ); | |
| 139 | 139 | } | 
| 140 | 140 | |
| 141 | 141 | protected function reset(): void | 
| 142 | 142 |      { | 
| 143 | 143 | $this->level = 0; | 
| 144 | - $this->result = []; | |
| 145 | - $this->stack = []; | |
| 144 | + $this->result = [ ]; | |
| 145 | + $this->stack = [ ]; | |
| 146 | 146 | } | 
| 147 | 147 | } | 
| 148 | 148 | |
| @@ -36,7 +36,8 @@ discard block | ||
| 36 | 36 |          if (is_string($key) && "\0" === $key[0]) { | 
| 37 | 37 |              $keyParts = explode("\0", $key); | 
| 38 | 38 |              $result[] = $keyParts[2].(('*' === $keyParts[1]) ? ':protected' : ':private'); | 
| 39 | -        } else { | |
| 39 | + } | |
| 40 | +        else { | |
| 40 | 41 | $result[] = $key; | 
| 41 | 42 | } | 
| 42 | 43 | $result[] = '] => '; | 
| @@ -51,11 +52,14 @@ discard block | ||
| 51 | 52 | ++$this->level; | 
| 52 | 53 |          if ($subject instanceof \Closure) { | 
| 53 | 54 | $this->inspectClosure($subject); | 
| 54 | -        } elseif (is_object($subject)) { | |
| 55 | + } | |
| 56 | +        elseif (is_object($subject)) { | |
| 55 | 57 | $this->inspectObject($subject); | 
| 56 | -        } elseif (is_array($subject)) { | |
| 58 | + } | |
| 59 | +        elseif (is_array($subject)) { | |
| 57 | 60 | $this->inspectArray($subject); | 
| 58 | -        } else { | |
| 61 | + } | |
| 62 | +        else { | |
| 59 | 63 | $this->inspectPrimitive($subject); | 
| 60 | 64 | } | 
| 61 | 65 | --$this->level; | 
| @@ -84,7 +88,8 @@ discard block | ||
| 84 | 88 | protected function inspectClosure(\Closure $subject): void | 
| 85 | 89 |      { | 
| 86 | 90 | $reflection = new \ReflectionFunction($subject); | 
| 87 | -        $params = array_map(function ($param) { | |
| 91 | + $params = array_map(function ($param) | |
| 92 | +        { | |
| 88 | 93 | return ($param->isPassedByReference() ? '&$' : '$').$param->name; | 
| 89 | 94 | }, $reflection->getParameters()); | 
| 90 | 95 |          $this->result[] = 'Closure ('.implode(', ', $params).') { ... }'."\n"; | 
| @@ -102,7 +107,8 @@ discard block | ||
| 102 | 107 | } | 
| 103 | 108 |          if ($subject instanceof \ArrayObject) { | 
| 104 | 109 | $this->result[] = $classname." ArrayObject (\n"; | 
| 105 | -        } else { | |
| 110 | + } | |
| 111 | +        else { | |
| 106 | 112 | $this->result[] = $classname." Object (\n"; | 
| 107 | 113 | $subject = (array) $subject; | 
| 108 | 114 | } | 
| @@ -122,9 +128,11 @@ discard block | ||
| 122 | 128 |      { | 
| 123 | 129 |          if (true === $subject) { | 
| 124 | 130 | $subject = '(bool) true'; | 
| 125 | -        } elseif (false === $subject) { | |
| 131 | + } | |
| 132 | +        elseif (false === $subject) { | |
| 126 | 133 | $subject = '(bool) false'; | 
| 127 | -        } elseif (null === $subject) { | |
| 134 | + } | |
| 135 | +        elseif (null === $subject) { | |
| 128 | 136 | $subject = '(null)'; | 
| 129 | 137 | } | 
| 130 | 138 | $this->result[] = $subject."\n"; | 
| @@ -4,118 +4,118 @@ | ||
| 4 | 4 | |
| 5 | 5 | class Controller | 
| 6 | 6 |  { | 
| 7 | - /** | |
| 8 | - * @var Application | |
| 9 | - */ | |
| 10 | - protected $app; | |
| 7 | + /** | |
| 8 | + * @var Application | |
| 9 | + */ | |
| 10 | + protected $app; | |
| 11 | 11 | |
| 12 | - public function __construct(Application $app) | |
| 13 | -    { | |
| 14 | - $this->app = $app; | |
| 15 | - } | |
| 12 | + public function __construct(Application $app) | |
| 13 | +	{ | |
| 14 | + $this->app = $app; | |
| 15 | + } | |
| 16 | 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 | - } | |
| 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 | 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 | - } | |
| 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 | 36 | |
| 37 | - /** | |
| 38 | - * @action 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 | - $args = array_combine(['hook', 'message', 'errno', 'location'], $args); | |
| 47 | -        $args = array_map('sanitize_textarea_field', $args); | |
| 48 | - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 4); | |
| 49 | - $entry = array_pop($backtrace); // get the fourth backtrace entry | |
| 50 | -        if (empty(trim($args['location'])) && array_key_exists('file', $entry)) { | |
| 51 | - $path = explode(ABSPATH, $entry['file']); | |
| 52 | -            $args['location'] = sprintf('%s:%s', array_pop($path), $entry['line']); | |
| 53 | - } | |
| 54 | - $this->app->console->store($args['message'], $args['errno'], $args['location']); | |
| 55 | - } | |
| 37 | + /** | |
| 38 | + * @action 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 | + $args = array_combine(['hook', 'message', 'errno', 'location'], $args); | |
| 47 | +		$args = array_map('sanitize_textarea_field', $args); | |
| 48 | + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 4); | |
| 49 | + $entry = array_pop($backtrace); // get the fourth backtrace entry | |
| 50 | +		if (empty(trim($args['location'])) && array_key_exists('file', $entry)) { | |
| 51 | + $path = explode(ABSPATH, $entry['file']); | |
| 52 | +			$args['location'] = sprintf('%s:%s', array_pop($path), $entry['line']); | |
| 53 | + } | |
| 54 | + $this->app->console->store($args['message'], $args['errno'], $args['location']); | |
| 55 | + } | |
| 56 | 56 | |
| 57 | - /** | |
| 58 | - * @action all | |
| 59 | - */ | |
| 60 | - public function initHooks(): void | |
| 61 | -    { | |
| 62 | - $this->app->hooks->startTimer(); | |
| 63 | - } | |
| 57 | + /** | |
| 58 | + * @action all | |
| 59 | + */ | |
| 60 | + public function initHooks(): void | |
| 61 | +	{ | |
| 62 | + $this->app->hooks->startTimer(); | |
| 63 | + } | |
| 64 | 64 | |
| 65 | - /** | |
| 66 | - * @action all | |
| 67 | - */ | |
| 68 | - public function initProfiler(): void | |
| 69 | -    { | |
| 70 | - $hook = func_get_arg(0); | |
| 71 | -        if ('blackbar/profiler/start' === $hook) { // time when the profiler started | |
| 72 | - $this->app->profiler->setStart((int) hrtime(true)); | |
| 73 | - return; | |
| 74 | - } | |
| 75 | -        if ('blackbar/profiler/noise' === $hook) { // measure the profiler noise | |
| 76 | - $this->app->profiler->setNoise((int) hrtime(true)); | |
| 77 | - return; | |
| 78 | - } | |
| 79 | -        if ('blackbar/profiler/stop' === $hook) { // time when the profiler stopped | |
| 80 | - $this->app->profiler->setStop((int) hrtime(true)); | |
| 81 | - return; | |
| 82 | - } | |
| 83 | -        if ('timer:start' === $hook) { | |
| 84 | - $name = func_num_args() > 1 ? func_get_arg(1) : 'Timer'; | |
| 85 | - $this->app->profiler->start($name); | |
| 86 | - return; | |
| 87 | - } | |
| 88 | -        if ('timer:stop' === $hook) { | |
| 89 | - $this->app->profiler->stop(); | |
| 90 | - } | |
| 91 | - } | |
| 65 | + /** | |
| 66 | + * @action all | |
| 67 | + */ | |
| 68 | + public function initProfiler(): void | |
| 69 | +	{ | |
| 70 | + $hook = func_get_arg(0); | |
| 71 | +		if ('blackbar/profiler/start' === $hook) { // time when the profiler started | |
| 72 | + $this->app->profiler->setStart((int) hrtime(true)); | |
| 73 | + return; | |
| 74 | + } | |
| 75 | +		if ('blackbar/profiler/noise' === $hook) { // measure the profiler noise | |
| 76 | + $this->app->profiler->setNoise((int) hrtime(true)); | |
| 77 | + return; | |
| 78 | + } | |
| 79 | +		if ('blackbar/profiler/stop' === $hook) { // time when the profiler stopped | |
| 80 | + $this->app->profiler->setStop((int) hrtime(true)); | |
| 81 | + return; | |
| 82 | + } | |
| 83 | +		if ('timer:start' === $hook) { | |
| 84 | + $name = func_num_args() > 1 ? func_get_arg(1) : 'Timer'; | |
| 85 | + $this->app->profiler->start($name); | |
| 86 | + return; | |
| 87 | + } | |
| 88 | +		if ('timer:stop' === $hook) { | |
| 89 | + $this->app->profiler->stop(); | |
| 90 | + } | |
| 91 | + } | |
| 92 | 92 | |
| 93 | - /** | |
| 94 | - * @action plugins_loaded | |
| 95 | - */ | |
| 96 | - public function registerLanguages(): void | |
| 97 | -    { | |
| 98 | - load_plugin_textdomain(Application::ID, false, | |
| 99 | - plugin_basename($this->app->path()).'/languages/' | |
| 100 | - ); | |
| 101 | - } | |
| 93 | + /** | |
| 94 | + * @action plugins_loaded | |
| 95 | + */ | |
| 96 | + public function registerLanguages(): void | |
| 97 | +	{ | |
| 98 | + load_plugin_textdomain(Application::ID, false, | |
| 99 | + plugin_basename($this->app->path()).'/languages/' | |
| 100 | + ); | |
| 101 | + } | |
| 102 | 102 | |
| 103 | - /** | |
| 104 | - * @action admin_footer | |
| 105 | - * @action wp_footer | |
| 106 | - */ | |
| 107 | - public function renderBar(): void | |
| 108 | -    { | |
| 109 | -        do_action('blackbar/profiler/stop'); // stop profiler | |
| 110 | -        $this->app->render('debug-bar', [ | |
| 111 | - 'modules' => [ // order is intentional | |
| 112 | - $this->app->console, | |
| 113 | - $this->app->profiler, | |
| 114 | - $this->app->queries, | |
| 115 | - $this->app->hooks, | |
| 116 | - $this->app->templates, | |
| 117 | - $this->app->globals, | |
| 118 | - ], | |
| 119 | - ]); | |
| 120 | - } | |
| 103 | + /** | |
| 104 | + * @action admin_footer | |
| 105 | + * @action wp_footer | |
| 106 | + */ | |
| 107 | + public function renderBar(): void | |
| 108 | +	{ | |
| 109 | +		do_action('blackbar/profiler/stop'); // stop profiler | |
| 110 | +		$this->app->render('debug-bar', [ | |
| 111 | + 'modules' => [ // order is intentional | |
| 112 | + $this->app->console, | |
| 113 | + $this->app->profiler, | |
| 114 | + $this->app->queries, | |
| 115 | + $this->app->hooks, | |
| 116 | + $this->app->templates, | |
| 117 | + $this->app->globals, | |
| 118 | + ], | |
| 119 | + ]); | |
| 120 | + } | |
| 121 | 121 | } | 
| @@ -9,7 +9,7 @@ discard block | ||
| 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 = $app; | 
| 15 | 15 | } | 
| @@ -20,18 +20,18 @@ discard block | ||
| 20 | 20 | */ | 
| 21 | 21 | public function enqueueAssets(): void | 
| 22 | 22 |      { | 
| 23 | -        wp_enqueue_script(Application::ID, $this->app->url('assets/main.js')); | |
| 24 | -        wp_enqueue_style(Application::ID, $this->app->url('assets/main.css'), ['dashicons']); | |
| 25 | -        wp_enqueue_style(Application::ID.'-syntax', $this->app->url('assets/syntax.css')); | |
| 23 | + wp_enqueue_script( Application::ID, $this->app->url( 'assets/main.js' ) ); | |
| 24 | + wp_enqueue_style( Application::ID, $this->app->url( 'assets/main.css' ), [ 'dashicons' ] ); | |
| 25 | + wp_enqueue_style( Application::ID . '-syntax', $this->app->url( 'assets/syntax.css' ) ); | |
| 26 | 26 | } | 
| 27 | 27 | |
| 28 | 28 | /** | 
| 29 | 29 | * @param string $classes | 
| 30 | 30 | * @action admin_body_class | 
| 31 | 31 | */ | 
| 32 | - public function filterBodyClasses($classes): string | |
| 32 | + public function filterBodyClasses( $classes ): string | |
| 33 | 33 |      { | 
| 34 | - return trim((string) $classes.' '.Application::ID); | |
| 34 | + return trim( (string) $classes . ' ' . Application::ID ); | |
| 35 | 35 | } | 
| 36 | 36 | |
| 37 | 37 | /** | 
| @@ -39,19 +39,19 @@ discard block | ||
| 39 | 39 | */ | 
| 40 | 40 | public function initConsole(): void | 
| 41 | 41 |      { | 
| 42 | -        if (Application::CONSOLE_HOOK !== func_get_arg(0)) { | |
| 42 | +        if( Application::CONSOLE_HOOK !== func_get_arg( 0 ) ) { | |
| 43 | 43 | return; | 
| 44 | 44 | } | 
| 45 | - $args = array_pad(func_get_args(), 4, ''); | |
| 46 | - $args = array_combine(['hook', 'message', 'errno', 'location'], $args); | |
| 47 | -        $args = array_map('sanitize_textarea_field', $args); | |
| 48 | - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 4); | |
| 49 | - $entry = array_pop($backtrace); // get the fourth backtrace entry | |
| 50 | -        if (empty(trim($args['location'])) && array_key_exists('file', $entry)) { | |
| 51 | - $path = explode(ABSPATH, $entry['file']); | |
| 52 | -            $args['location'] = sprintf('%s:%s', array_pop($path), $entry['line']); | |
| 45 | + $args = array_pad( func_get_args(), 4, '' ); | |
| 46 | + $args = array_combine( [ 'hook', 'message', 'errno', 'location' ], $args ); | |
| 47 | + $args = array_map( 'sanitize_textarea_field', $args ); | |
| 48 | + $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 4 ); | |
| 49 | + $entry = array_pop( $backtrace ); // get the fourth backtrace entry | |
| 50 | +        if( empty( trim( $args[ 'location' ] ) ) && array_key_exists( 'file', $entry ) ) { | |
| 51 | + $path = explode( ABSPATH, $entry[ 'file' ] ); | |
| 52 | + $args[ 'location' ] = sprintf( '%s:%s', array_pop( $path ), $entry[ 'line' ] ); | |
| 53 | 53 | } | 
| 54 | - $this->app->console->store($args['message'], $args['errno'], $args['location']); | |
| 54 | + $this->app->console->store( $args[ 'message' ], $args[ 'errno' ], $args[ 'location' ] ); | |
| 55 | 55 | } | 
| 56 | 56 | |
| 57 | 57 | /** | 
| @@ -67,25 +67,25 @@ discard block | ||
| 67 | 67 | */ | 
| 68 | 68 | public function initProfiler(): void | 
| 69 | 69 |      { | 
| 70 | - $hook = func_get_arg(0); | |
| 71 | -        if ('blackbar/profiler/start' === $hook) { // time when the profiler started | |
| 72 | - $this->app->profiler->setStart((int) hrtime(true)); | |
| 70 | + $hook = func_get_arg( 0 ); | |
| 71 | +        if( 'blackbar/profiler/start' === $hook ) { // time when the profiler started | |
| 72 | + $this->app->profiler->setStart( (int) hrtime( true ) ); | |
| 73 | 73 | return; | 
| 74 | 74 | } | 
| 75 | -        if ('blackbar/profiler/noise' === $hook) { // measure the profiler noise | |
| 76 | - $this->app->profiler->setNoise((int) hrtime(true)); | |
| 75 | +        if( 'blackbar/profiler/noise' === $hook ) { // measure the profiler noise | |
| 76 | + $this->app->profiler->setNoise( (int) hrtime( true ) ); | |
| 77 | 77 | return; | 
| 78 | 78 | } | 
| 79 | -        if ('blackbar/profiler/stop' === $hook) { // time when the profiler stopped | |
| 80 | - $this->app->profiler->setStop((int) hrtime(true)); | |
| 79 | +        if( 'blackbar/profiler/stop' === $hook ) { // time when the profiler stopped | |
| 80 | + $this->app->profiler->setStop( (int) hrtime( true ) ); | |
| 81 | 81 | return; | 
| 82 | 82 | } | 
| 83 | -        if ('timer:start' === $hook) { | |
| 84 | - $name = func_num_args() > 1 ? func_get_arg(1) : 'Timer'; | |
| 85 | - $this->app->profiler->start($name); | |
| 83 | +        if( 'timer:start' === $hook ) { | |
| 84 | + $name = func_num_args() > 1 ? func_get_arg( 1 ) : 'Timer'; | |
| 85 | + $this->app->profiler->start( $name ); | |
| 86 | 86 | return; | 
| 87 | 87 | } | 
| 88 | -        if ('timer:stop' === $hook) { | |
| 88 | +        if( 'timer:stop' === $hook ) { | |
| 89 | 89 | $this->app->profiler->stop(); | 
| 90 | 90 | } | 
| 91 | 91 | } | 
| @@ -95,8 +95,8 @@ discard block | ||
| 95 | 95 | */ | 
| 96 | 96 | public function registerLanguages(): void | 
| 97 | 97 |      { | 
| 98 | - load_plugin_textdomain(Application::ID, false, | |
| 99 | - plugin_basename($this->app->path()).'/languages/' | |
| 98 | + load_plugin_textdomain( Application::ID, false, | |
| 99 | + plugin_basename( $this->app->path() ) . '/languages/' | |
| 100 | 100 | ); | 
| 101 | 101 | } | 
| 102 | 102 | |
| @@ -106,8 +106,8 @@ discard block | ||
| 106 | 106 | */ | 
| 107 | 107 | public function renderBar(): void | 
| 108 | 108 |      { | 
| 109 | -        do_action('blackbar/profiler/stop'); // stop profiler | |
| 110 | -        $this->app->render('debug-bar', [ | |
| 109 | + do_action( 'blackbar/profiler/stop' ); // stop profiler | |
| 110 | + $this->app->render( 'debug-bar', [ | |
| 111 | 111 | 'modules' => [ // order is intentional | 
| 112 | 112 | $this->app->console, | 
| 113 | 113 | $this->app->profiler, | 
| @@ -116,6 +116,6 @@ discard block | ||
| 116 | 116 | $this->app->templates, | 
| 117 | 117 | $this->app->globals, | 
| 118 | 118 | ], | 
| 119 | - ]); | |
| 119 | + ] ); | |
| 120 | 120 | } | 
| 121 | 121 | } | 
| @@ -74,7 +74,8 @@ discard block | ||
| 74 | 74 |              if (array_key_exists((int) $errno, static::ERROR_CODES)) { | 
| 75 | 75 | $errname = static::ERROR_CODES[$errno]; | 
| 76 | 76 | } | 
| 77 | -        } else { // entry likely stored by filter hook | |
| 77 | + } | |
| 78 | +        else { // entry likely stored by filter hook | |
| 78 | 79 | $errname = 'Debug'; | 
| 79 | 80 |              if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { | 
| 80 | 81 | $errname = $errno; | 
| @@ -85,7 +86,8 @@ discard block | ||
| 85 | 86 | $hash = md5($errno.$errname.$message.$location); | 
| 86 | 87 |          if (array_key_exists($hash, $this->entries)) { | 
| 87 | 88 | ++$this->entries[$hash]['count']; | 
| 88 | -        } else { | |
| 89 | + } | |
| 90 | +        else { | |
| 89 | 91 | $this->entries[$hash] = [ | 
| 90 | 92 | 'count' => 0, | 
| 91 | 93 | 'errname' => $errname, | 
| @@ -99,9 +101,11 @@ discard block | ||
| 99 | 101 |      { | 
| 100 | 102 |          if ($message instanceof \DateTime) { | 
| 101 | 103 |              $message = $message->format('Y-m-d H:i:s'); | 
| 102 | -        } elseif (is_object($message) || is_array($message)) { | |
| 104 | + } | |
| 105 | +        elseif (is_object($message) || is_array($message)) { | |
| 103 | 106 | $message = (new Dump())->dump($message); | 
| 104 | -        } else { | |
| 107 | + } | |
| 108 | +        else { | |
| 105 | 109 | $message = esc_html(trim((string) $message)); | 
| 106 | 110 | } | 
| 107 | 111 | $location = trim($location); | 
| @@ -7,112 +7,112 @@ | ||
| 7 | 7 | |
| 8 | 8 | class Console extends Module | 
| 9 | 9 |  { | 
| 10 | - public const ERROR_CODES = [ | |
| 11 | - E_ERROR => 'error', // 1 | |
| 12 | - E_WARNING => 'warning', // 2 | |
| 13 | - E_NOTICE => 'notice', // 8 | |
| 14 | - E_STRICT => 'strict', // 2048 | |
| 15 | - E_DEPRECATED => 'deprecated', // 8192 | |
| 16 | - ]; | |
| 10 | + public const ERROR_CODES = [ | |
| 11 | + E_ERROR => 'error', // 1 | |
| 12 | + E_WARNING => 'warning', // 2 | |
| 13 | + E_NOTICE => 'notice', // 8 | |
| 14 | + E_STRICT => 'strict', // 2048 | |
| 15 | + E_DEPRECATED => 'deprecated', // 8192 | |
| 16 | + ]; | |
| 17 | 17 | |
| 18 | - public const MAPPED_ERROR_CODES = [ | |
| 19 | - 'debug' => 0, | |
| 20 | - 'info' => E_NOTICE, | |
| 21 | - 'deprecated' => E_DEPRECATED, // 8192 | |
| 22 | - 'error' => E_ERROR, // 1 | |
| 23 | - 'notice' => E_NOTICE, // 8 | |
| 24 | - 'strict' => E_STRICT, // 2048 | |
| 25 | - 'warning' => E_WARNING, // 2 | |
| 26 | - 'critical' => E_ERROR, // 1 | |
| 27 | - 'alert' => E_ERROR, // 1 | |
| 28 | - 'emergency' => E_ERROR, // 1 | |
| 29 | - ]; | |
| 18 | + public const MAPPED_ERROR_CODES = [ | |
| 19 | + 'debug' => 0, | |
| 20 | + 'info' => E_NOTICE, | |
| 21 | + 'deprecated' => E_DEPRECATED, // 8192 | |
| 22 | + 'error' => E_ERROR, // 1 | |
| 23 | + 'notice' => E_NOTICE, // 8 | |
| 24 | + 'strict' => E_STRICT, // 2048 | |
| 25 | + 'warning' => E_WARNING, // 2 | |
| 26 | + 'critical' => E_ERROR, // 1 | |
| 27 | + 'alert' => E_ERROR, // 1 | |
| 28 | + 'emergency' => E_ERROR, // 1 | |
| 29 | + ]; | |
| 30 | 30 | |
| 31 | - public function classes(): string | |
| 32 | -    { | |
| 33 | - $errno = array_unique(wp_list_pluck($this->entries, 'errno')); | |
| 34 | -        if (in_array(E_ERROR, $errno)) { | |
| 35 | -            return sprintf('%s glbb-error', $this->id()); | |
| 36 | - } | |
| 37 | -        if (in_array(E_WARNING, $errno)) { | |
| 38 | -            return sprintf('%s glbb-warning', $this->id()); | |
| 39 | - } | |
| 40 | - return $this->id(); | |
| 41 | - } | |
| 31 | + public function classes(): string | |
| 32 | +	{ | |
| 33 | + $errno = array_unique(wp_list_pluck($this->entries, 'errno')); | |
| 34 | +		if (in_array(E_ERROR, $errno)) { | |
| 35 | +			return sprintf('%s glbb-error', $this->id()); | |
| 36 | + } | |
| 37 | +		if (in_array(E_WARNING, $errno)) { | |
| 38 | +			return sprintf('%s glbb-warning', $this->id()); | |
| 39 | + } | |
| 40 | + return $this->id(); | |
| 41 | + } | |
| 42 | 42 | |
| 43 | - public function entries(): array | |
| 44 | -    { | |
| 45 | - $entries = []; | |
| 46 | -        foreach ($this->entries as $entry) { | |
| 47 | - $entry['name'] = ucfirst($entry['errname']); | |
| 48 | -            if ($entry['count'] > 1) { | |
| 49 | -                $entry['name'] = sprintf('%s (%s)', $entry['name'], $entry['count']); | |
| 50 | - } | |
| 51 | - $entries[] = $entry; | |
| 52 | - } | |
| 53 | - return $entries; | |
| 54 | - } | |
| 43 | + public function entries(): array | |
| 44 | +	{ | |
| 45 | + $entries = []; | |
| 46 | +		foreach ($this->entries as $entry) { | |
| 47 | + $entry['name'] = ucfirst($entry['errname']); | |
| 48 | +			if ($entry['count'] > 1) { | |
| 49 | +				$entry['name'] = sprintf('%s (%s)', $entry['name'], $entry['count']); | |
| 50 | + } | |
| 51 | + $entries[] = $entry; | |
| 52 | + } | |
| 53 | + return $entries; | |
| 54 | + } | |
| 55 | 55 | |
| 56 | - public function info(): string | |
| 57 | -    { | |
| 58 | - $counts = array_count_values(wp_list_pluck($this->entries, 'errno')); | |
| 59 | - $entryCount = count($this->entries); | |
| 60 | -        if (!empty($counts[E_ERROR])) { | |
| 61 | -            return sprintf('%d, %d!', $entryCount, $counts[E_ERROR]); | |
| 62 | - } | |
| 63 | -        if ($entryCount > 0) { | |
| 64 | - return (string) $entryCount; | |
| 65 | - } | |
| 66 | - return ''; | |
| 67 | - } | |
| 56 | + public function info(): string | |
| 57 | +	{ | |
| 58 | + $counts = array_count_values(wp_list_pluck($this->entries, 'errno')); | |
| 59 | + $entryCount = count($this->entries); | |
| 60 | +		if (!empty($counts[E_ERROR])) { | |
| 61 | +			return sprintf('%d, %d!', $entryCount, $counts[E_ERROR]); | |
| 62 | + } | |
| 63 | +		if ($entryCount > 0) { | |
| 64 | + return (string) $entryCount; | |
| 65 | + } | |
| 66 | + return ''; | |
| 67 | + } | |
| 68 | 68 | |
| 69 | - public function label(): string | |
| 70 | -    { | |
| 71 | -        return __('Console', 'blackbar'); | |
| 72 | - } | |
| 69 | + public function label(): string | |
| 70 | +	{ | |
| 71 | +		return __('Console', 'blackbar'); | |
| 72 | + } | |
| 73 | 73 | |
| 74 | - public function store(string $message, string $errno = '', string $location = ''): void | |
| 75 | -    { | |
| 76 | -        if (is_numeric($errno)) { // entry likely stored by set_error_handler() | |
| 77 | - $errname = 'Unknown'; | |
| 78 | -            if (array_key_exists((int) $errno, static::ERROR_CODES)) { | |
| 79 | - $errname = static::ERROR_CODES[$errno]; | |
| 80 | - } | |
| 81 | -        } else { // entry likely stored by filter hook | |
| 82 | - $errname = 'Debug'; | |
| 83 | -            if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { | |
| 84 | - $errname = $errno; | |
| 85 | - $errno = static::MAPPED_ERROR_CODES[$errno]; | |
| 86 | - } | |
| 87 | - } | |
| 88 | - $errname = strtolower($errname); | |
| 89 | - $hash = md5($errno.$errname.$message.$location); | |
| 90 | -        if (array_key_exists($hash, $this->entries)) { | |
| 91 | - ++$this->entries[$hash]['count']; | |
| 92 | -        } else { | |
| 93 | - $this->entries[$hash] = [ | |
| 94 | - 'count' => 0, | |
| 95 | - 'errname' => $errname, | |
| 96 | - 'errno' => (int) $errno, | |
| 97 | - 'message' => $this->normalizeMessage($message, $location), | |
| 98 | - ]; | |
| 99 | - }; | |
| 100 | - } | |
| 74 | + public function store(string $message, string $errno = '', string $location = ''): void | |
| 75 | +	{ | |
| 76 | +		if (is_numeric($errno)) { // entry likely stored by set_error_handler() | |
| 77 | + $errname = 'Unknown'; | |
| 78 | +			if (array_key_exists((int) $errno, static::ERROR_CODES)) { | |
| 79 | + $errname = static::ERROR_CODES[$errno]; | |
| 80 | + } | |
| 81 | +		} else { // entry likely stored by filter hook | |
| 82 | + $errname = 'Debug'; | |
| 83 | +			if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { | |
| 84 | + $errname = $errno; | |
| 85 | + $errno = static::MAPPED_ERROR_CODES[$errno]; | |
| 86 | + } | |
| 87 | + } | |
| 88 | + $errname = strtolower($errname); | |
| 89 | + $hash = md5($errno.$errname.$message.$location); | |
| 90 | +		if (array_key_exists($hash, $this->entries)) { | |
| 91 | + ++$this->entries[$hash]['count']; | |
| 92 | +		} else { | |
| 93 | + $this->entries[$hash] = [ | |
| 94 | + 'count' => 0, | |
| 95 | + 'errname' => $errname, | |
| 96 | + 'errno' => (int) $errno, | |
| 97 | + 'message' => $this->normalizeMessage($message, $location), | |
| 98 | + ]; | |
| 99 | + }; | |
| 100 | + } | |
| 101 | 101 | |
| 102 | - protected function normalizeMessage($message, string $location): string | |
| 103 | -    { | |
| 104 | -        if ($message instanceof \DateTime) { | |
| 105 | -            $message = $message->format('Y-m-d H:i:s'); | |
| 106 | -        } elseif (is_object($message) || is_array($message)) { | |
| 107 | - $message = (new Dump())->dump($message); | |
| 108 | -        } else { | |
| 109 | - $message = esc_html(trim((string) $message)); | |
| 110 | - } | |
| 111 | - $location = trim($location); | |
| 112 | -        if (!empty($location)) { | |
| 113 | - $location = str_replace([WP_CONTENT_DIR, ABSPATH], '', $location); | |
| 114 | -            $location = sprintf('[%s]', $location); | |
| 115 | - } | |
| 116 | -        return trim(sprintf('%s %s', $location, $message)); | |
| 117 | - } | |
| 102 | + protected function normalizeMessage($message, string $location): string | |
| 103 | +	{ | |
| 104 | +		if ($message instanceof \DateTime) { | |
| 105 | +			$message = $message->format('Y-m-d H:i:s'); | |
| 106 | +		} elseif (is_object($message) || is_array($message)) { | |
| 107 | + $message = (new Dump())->dump($message); | |
| 108 | +		} else { | |
| 109 | + $message = esc_html(trim((string) $message)); | |
| 110 | + } | |
| 111 | + $location = trim($location); | |
| 112 | +		if (!empty($location)) { | |
| 113 | + $location = str_replace([WP_CONTENT_DIR, ABSPATH], '', $location); | |
| 114 | +			$location = sprintf('[%s]', $location); | |
| 115 | + } | |
| 116 | +		return trim(sprintf('%s %s', $location, $message)); | |
| 117 | + } | |
| 118 | 118 | } | 
| @@ -30,37 +30,37 @@ discard block | ||
| 30 | 30 | |
| 31 | 31 | public function classes(): string | 
| 32 | 32 |      { | 
| 33 | - $errno = array_unique(wp_list_pluck($this->entries, 'errno')); | |
| 34 | -        if (in_array(E_ERROR, $errno)) { | |
| 35 | -            return sprintf('%s glbb-error', $this->id()); | |
| 33 | + $errno = array_unique( wp_list_pluck( $this->entries, 'errno' ) ); | |
| 34 | +        if( in_array( E_ERROR, $errno ) ) { | |
| 35 | + return sprintf( '%s glbb-error', $this->id() ); | |
| 36 | 36 | } | 
| 37 | -        if (in_array(E_WARNING, $errno)) { | |
| 38 | -            return sprintf('%s glbb-warning', $this->id()); | |
| 37 | +        if( in_array( E_WARNING, $errno ) ) { | |
| 38 | + return sprintf( '%s glbb-warning', $this->id() ); | |
| 39 | 39 | } | 
| 40 | 40 | return $this->id(); | 
| 41 | 41 | } | 
| 42 | 42 | |
| 43 | 43 | public function entries(): array | 
| 44 | 44 |      { | 
| 45 | - $entries = []; | |
| 46 | -        foreach ($this->entries as $entry) { | |
| 47 | - $entry['name'] = ucfirst($entry['errname']); | |
| 48 | -            if ($entry['count'] > 1) { | |
| 49 | -                $entry['name'] = sprintf('%s (%s)', $entry['name'], $entry['count']); | |
| 45 | + $entries = [ ]; | |
| 46 | +        foreach( $this->entries as $entry ) { | |
| 47 | + $entry[ 'name' ] = ucfirst( $entry[ 'errname' ] ); | |
| 48 | +            if( $entry[ 'count' ] > 1 ) { | |
| 49 | + $entry[ 'name' ] = sprintf( '%s (%s)', $entry[ 'name' ], $entry[ 'count' ] ); | |
| 50 | 50 | } | 
| 51 | - $entries[] = $entry; | |
| 51 | + $entries[ ] = $entry; | |
| 52 | 52 | } | 
| 53 | 53 | return $entries; | 
| 54 | 54 | } | 
| 55 | 55 | |
| 56 | 56 | public function info(): string | 
| 57 | 57 |      { | 
| 58 | - $counts = array_count_values(wp_list_pluck($this->entries, 'errno')); | |
| 59 | - $entryCount = count($this->entries); | |
| 60 | -        if (!empty($counts[E_ERROR])) { | |
| 61 | -            return sprintf('%d, %d!', $entryCount, $counts[E_ERROR]); | |
| 58 | + $counts = array_count_values( wp_list_pluck( $this->entries, 'errno' ) ); | |
| 59 | + $entryCount = count( $this->entries ); | |
| 60 | +        if( !empty( $counts[ E_ERROR ] ) ) { | |
| 61 | + return sprintf( '%d, %d!', $entryCount, $counts[ E_ERROR ] ); | |
| 62 | 62 | } | 
| 63 | -        if ($entryCount > 0) { | |
| 63 | +        if( $entryCount > 0 ) { | |
| 64 | 64 | return (string) $entryCount; | 
| 65 | 65 | } | 
| 66 | 66 | return ''; | 
| @@ -68,51 +68,51 @@ discard block | ||
| 68 | 68 | |
| 69 | 69 | public function label(): string | 
| 70 | 70 |      { | 
| 71 | -        return __('Console', 'blackbar'); | |
| 71 | + return __( 'Console', 'blackbar' ); | |
| 72 | 72 | } | 
| 73 | 73 | |
| 74 | - public function store(string $message, string $errno = '', string $location = ''): void | |
| 74 | + public function store( string $message, string $errno = '', string $location = '' ): void | |
| 75 | 75 |      { | 
| 76 | -        if (is_numeric($errno)) { // entry likely stored by set_error_handler() | |
| 76 | +        if( is_numeric( $errno ) ) { // entry likely stored by set_error_handler() | |
| 77 | 77 | $errname = 'Unknown'; | 
| 78 | -            if (array_key_exists((int) $errno, static::ERROR_CODES)) { | |
| 79 | - $errname = static::ERROR_CODES[$errno]; | |
| 78 | +            if( array_key_exists( (int) $errno, static::ERROR_CODES ) ) { | |
| 79 | + $errname = static::ERROR_CODES[ $errno ]; | |
| 80 | 80 | } | 
| 81 | 81 |          } else { // entry likely stored by filter hook | 
| 82 | 82 | $errname = 'Debug'; | 
| 83 | -            if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { | |
| 83 | +            if( array_key_exists( $errno, static::MAPPED_ERROR_CODES ) ) { | |
| 84 | 84 | $errname = $errno; | 
| 85 | - $errno = static::MAPPED_ERROR_CODES[$errno]; | |
| 85 | + $errno = static::MAPPED_ERROR_CODES[ $errno ]; | |
| 86 | 86 | } | 
| 87 | 87 | } | 
| 88 | - $errname = strtolower($errname); | |
| 89 | - $hash = md5($errno.$errname.$message.$location); | |
| 90 | -        if (array_key_exists($hash, $this->entries)) { | |
| 91 | - ++$this->entries[$hash]['count']; | |
| 88 | + $errname = strtolower( $errname ); | |
| 89 | + $hash = md5( $errno . $errname . $message . $location ); | |
| 90 | +        if( array_key_exists( $hash, $this->entries ) ) { | |
| 91 | + ++$this->entries[ $hash ][ 'count' ]; | |
| 92 | 92 |          } else { | 
| 93 | - $this->entries[$hash] = [ | |
| 93 | + $this->entries[ $hash ] = [ | |
| 94 | 94 | 'count' => 0, | 
| 95 | 95 | 'errname' => $errname, | 
| 96 | 96 | 'errno' => (int) $errno, | 
| 97 | - 'message' => $this->normalizeMessage($message, $location), | |
| 97 | + 'message' => $this->normalizeMessage( $message, $location ), | |
| 98 | 98 | ]; | 
| 99 | 99 | }; | 
| 100 | 100 | } | 
| 101 | 101 | |
| 102 | - protected function normalizeMessage($message, string $location): string | |
| 102 | + protected function normalizeMessage( $message, string $location ): string | |
| 103 | 103 |      { | 
| 104 | -        if ($message instanceof \DateTime) { | |
| 105 | -            $message = $message->format('Y-m-d H:i:s'); | |
| 106 | -        } elseif (is_object($message) || is_array($message)) { | |
| 107 | - $message = (new Dump())->dump($message); | |
| 104 | +        if( $message instanceof \DateTime ) { | |
| 105 | + $message = $message->format( 'Y-m-d H:i:s' ); | |
| 106 | +        } elseif( is_object( $message ) || is_array( $message ) ) { | |
| 107 | + $message = ( new Dump() )->dump( $message ); | |
| 108 | 108 |          } else { | 
| 109 | - $message = esc_html(trim((string) $message)); | |
| 109 | + $message = esc_html( trim( (string) $message ) ); | |
| 110 | 110 | } | 
| 111 | - $location = trim($location); | |
| 112 | -        if (!empty($location)) { | |
| 113 | - $location = str_replace([WP_CONTENT_DIR, ABSPATH], '', $location); | |
| 114 | -            $location = sprintf('[%s]', $location); | |
| 111 | + $location = trim( $location ); | |
| 112 | +        if( !empty( $location ) ) { | |
| 113 | + $location = str_replace( [ WP_CONTENT_DIR, ABSPATH ], '', $location ); | |
| 114 | + $location = sprintf( '[%s]', $location ); | |
| 115 | 115 | } | 
| 116 | -        return trim(sprintf('%s %s', $location, $message)); | |
| 116 | + return trim( sprintf( '%s %s', $location, $message ) ); | |
| 117 | 117 | } | 
| 118 | 118 | } | 
| @@ -6,45 +6,45 @@ | ||
| 6 | 6 | |
| 7 | 7 | class Globals extends Module | 
| 8 | 8 |  { | 
| 9 | - public function entries(): array | |
| 10 | -    { | |
| 11 | -        if (!empty($this->entries)) { | |
| 12 | - return $this->entries; | |
| 13 | - } | |
| 14 | - $globals = [ | |
| 15 | - 'INPUT_COOKIE' => $_COOKIE, | |
| 16 | - 'INPUT_ENV' => $_ENV, | |
| 17 | - 'INPUT_GET' => $_GET, | |
| 18 | - 'INPUT_POST' => $_POST, | |
| 19 | - 'INPUT_SERVER' => $_SERVER, | |
| 20 | - ]; | |
| 21 | -        if (is_admin() && $screen = get_current_screen()) { | |
| 22 | - $reflection = new \ReflectionClass($screen); | |
| 23 | - $properties = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC); | |
| 24 | - $values = []; | |
| 25 | -            foreach ($properties as $property) { | |
| 26 | - $values[$property->getName()] = $property->getValue($screen); | |
| 27 | - } | |
| 28 | - $globals['WP_Screen'] = $values; | |
| 29 | - } | |
| 30 | -        $globals = apply_filters('blackbar/globals', $globals); | |
| 31 | - $globals = array_filter($globals); | |
| 32 | -        foreach ($globals as $key => $values) { | |
| 33 | - $this->entries[] = [ | |
| 34 | - 'name' => $key, | |
| 35 | - 'value' => var_export($values, true), | |
| 36 | - ]; | |
| 37 | - } | |
| 38 | - return $this->entries; | |
| 39 | - } | |
| 9 | + public function entries(): array | |
| 10 | +	{ | |
| 11 | +		if (!empty($this->entries)) { | |
| 12 | + return $this->entries; | |
| 13 | + } | |
| 14 | + $globals = [ | |
| 15 | + 'INPUT_COOKIE' => $_COOKIE, | |
| 16 | + 'INPUT_ENV' => $_ENV, | |
| 17 | + 'INPUT_GET' => $_GET, | |
| 18 | + 'INPUT_POST' => $_POST, | |
| 19 | + 'INPUT_SERVER' => $_SERVER, | |
| 20 | + ]; | |
| 21 | +		if (is_admin() && $screen = get_current_screen()) { | |
| 22 | + $reflection = new \ReflectionClass($screen); | |
| 23 | + $properties = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC); | |
| 24 | + $values = []; | |
| 25 | +			foreach ($properties as $property) { | |
| 26 | + $values[$property->getName()] = $property->getValue($screen); | |
| 27 | + } | |
| 28 | + $globals['WP_Screen'] = $values; | |
| 29 | + } | |
| 30 | +		$globals = apply_filters('blackbar/globals', $globals); | |
| 31 | + $globals = array_filter($globals); | |
| 32 | +		foreach ($globals as $key => $values) { | |
| 33 | + $this->entries[] = [ | |
| 34 | + 'name' => $key, | |
| 35 | + 'value' => var_export($values, true), | |
| 36 | + ]; | |
| 37 | + } | |
| 38 | + return $this->entries; | |
| 39 | + } | |
| 40 | 40 | |
| 41 | - public function hasEntries(): bool | |
| 42 | -    { | |
| 43 | - return !empty($this->entries()); | |
| 44 | - } | |
| 41 | + public function hasEntries(): bool | |
| 42 | +	{ | |
| 43 | + return !empty($this->entries()); | |
| 44 | + } | |
| 45 | 45 | |
| 46 | - public function label(): string | |
| 47 | -    { | |
| 48 | -        return __('Globals', 'blackbar'); | |
| 49 | - } | |
| 46 | + public function label(): string | |
| 47 | +	{ | |
| 48 | +		return __('Globals', 'blackbar'); | |
| 49 | + } | |
| 50 | 50 | } | 
| @@ -8,7 +8,7 @@ discard block | ||
| 8 | 8 |  { | 
| 9 | 9 | public function entries(): array | 
| 10 | 10 |      { | 
| 11 | -        if (!empty($this->entries)) { | |
| 11 | +        if( !empty( $this->entries ) ) { | |
| 12 | 12 | return $this->entries; | 
| 13 | 13 | } | 
| 14 | 14 | $globals = [ | 
| @@ -18,21 +18,21 @@ discard block | ||
| 18 | 18 | 'INPUT_POST' => $_POST, | 
| 19 | 19 | 'INPUT_SERVER' => $_SERVER, | 
| 20 | 20 | ]; | 
| 21 | -        if (is_admin() && $screen = get_current_screen()) { | |
| 22 | - $reflection = new \ReflectionClass($screen); | |
| 23 | - $properties = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC); | |
| 24 | - $values = []; | |
| 25 | -            foreach ($properties as $property) { | |
| 26 | - $values[$property->getName()] = $property->getValue($screen); | |
| 21 | +        if( is_admin() && $screen = get_current_screen() ) { | |
| 22 | + $reflection = new \ReflectionClass( $screen ); | |
| 23 | + $properties = $reflection->getProperties( \ReflectionProperty::IS_PUBLIC ); | |
| 24 | + $values = [ ]; | |
| 25 | +            foreach( $properties as $property ) { | |
| 26 | + $values[ $property->getName() ] = $property->getValue( $screen ); | |
| 27 | 27 | } | 
| 28 | - $globals['WP_Screen'] = $values; | |
| 28 | + $globals[ 'WP_Screen' ] = $values; | |
| 29 | 29 | } | 
| 30 | -        $globals = apply_filters('blackbar/globals', $globals); | |
| 31 | - $globals = array_filter($globals); | |
| 32 | -        foreach ($globals as $key => $values) { | |
| 33 | - $this->entries[] = [ | |
| 30 | + $globals = apply_filters( 'blackbar/globals', $globals ); | |
| 31 | + $globals = array_filter( $globals ); | |
| 32 | +        foreach( $globals as $key => $values ) { | |
| 33 | + $this->entries[ ] = [ | |
| 34 | 34 | 'name' => $key, | 
| 35 | - 'value' => var_export($values, true), | |
| 35 | + 'value' => var_export( $values, true ), | |
| 36 | 36 | ]; | 
| 37 | 37 | } | 
| 38 | 38 | return $this->entries; | 
| @@ -40,11 +40,11 @@ discard block | ||
| 40 | 40 | |
| 41 | 41 | public function hasEntries(): bool | 
| 42 | 42 |      { | 
| 43 | - return !empty($this->entries()); | |
| 43 | + return !empty( $this->entries() ); | |
| 44 | 44 | } | 
| 45 | 45 | |
| 46 | 46 | public function label(): string | 
| 47 | 47 |      { | 
| 48 | -        return __('Globals', 'blackbar'); | |
| 48 | + return __( 'Globals', 'blackbar' ); | |
| 49 | 49 | } | 
| 50 | 50 | } | 
| @@ -6,39 +6,39 @@ | ||
| 6 | 6 | |
| 7 | 7 | class Templates extends Module | 
| 8 | 8 |  { | 
| 9 | - public function entries(): array | |
| 10 | -    { | |
| 11 | -        if (!empty($this->entries)) { | |
| 12 | - return $this->entries; | |
| 13 | - } | |
| 14 | -        if (class_exists('\GeminiLabs\Castor\Facades\Development') | |
| 15 | -            && class_exists('\GeminiLabs\Castor\Helpers\Development') | |
| 16 | -            && method_exists('\GeminiLabs\Castor\Helpers\Development', 'templatePaths')) { // @phpstan-ignore-line | |
| 17 | - $this->entries = \GeminiLabs\Castor\Facades\Development::templatePaths(); | |
| 18 | -        } else { | |
| 19 | -            $files = array_values(array_filter(get_included_files(), function ($file) { | |
| 20 | - $bool = false !== strpos($file, '/themes/') && false === strpos($file, '/functions.php'); | |
| 21 | -                return (bool) apply_filters('blackbar/templates/file', $bool, $file); | |
| 22 | - })); | |
| 23 | -            $this->entries = array_map(function ($file) { | |
| 24 | - return str_replace(trailingslashit(WP_CONTENT_DIR), '', $file); | |
| 25 | - }, $files); | |
| 26 | - } | |
| 27 | - return $this->entries; | |
| 28 | - } | |
| 9 | + public function entries(): array | |
| 10 | +	{ | |
| 11 | +		if (!empty($this->entries)) { | |
| 12 | + return $this->entries; | |
| 13 | + } | |
| 14 | +		if (class_exists('\GeminiLabs\Castor\Facades\Development') | |
| 15 | +			&& class_exists('\GeminiLabs\Castor\Helpers\Development') | |
| 16 | +			&& method_exists('\GeminiLabs\Castor\Helpers\Development', 'templatePaths')) { // @phpstan-ignore-line | |
| 17 | + $this->entries = \GeminiLabs\Castor\Facades\Development::templatePaths(); | |
| 18 | +		} else { | |
| 19 | +			$files = array_values(array_filter(get_included_files(), function ($file) { | |
| 20 | + $bool = false !== strpos($file, '/themes/') && false === strpos($file, '/functions.php'); | |
| 21 | +				return (bool) apply_filters('blackbar/templates/file', $bool, $file); | |
| 22 | + })); | |
| 23 | +			$this->entries = array_map(function ($file) { | |
| 24 | + return str_replace(trailingslashit(WP_CONTENT_DIR), '', $file); | |
| 25 | + }, $files); | |
| 26 | + } | |
| 27 | + return $this->entries; | |
| 28 | + } | |
| 29 | 29 | |
| 30 | - public function hasEntries(): bool | |
| 31 | -    { | |
| 32 | - return !empty($this->entries()); | |
| 33 | - } | |
| 30 | + public function hasEntries(): bool | |
| 31 | +	{ | |
| 32 | + return !empty($this->entries()); | |
| 33 | + } | |
| 34 | 34 | |
| 35 | - public function isVisible(): bool | |
| 36 | -    { | |
| 37 | - return !is_admin() && $this->hasEntries(); | |
| 38 | - } | |
| 35 | + public function isVisible(): bool | |
| 36 | +	{ | |
| 37 | + return !is_admin() && $this->hasEntries(); | |
| 38 | + } | |
| 39 | 39 | |
| 40 | - public function label(): string | |
| 41 | -    { | |
| 42 | -        return __('Templates', 'blackbar'); | |
| 43 | - } | |
| 40 | + public function label(): string | |
| 41 | +	{ | |
| 42 | +		return __('Templates', 'blackbar'); | |
| 43 | + } | |
| 44 | 44 | } | 
| @@ -8,28 +8,28 @@ discard block | ||
| 8 | 8 |  { | 
| 9 | 9 | public function entries(): array | 
| 10 | 10 |      { | 
| 11 | -        if (!empty($this->entries)) { | |
| 11 | +        if( !empty( $this->entries ) ) { | |
| 12 | 12 | return $this->entries; | 
| 13 | 13 | } | 
| 14 | -        if (class_exists('\GeminiLabs\Castor\Facades\Development') | |
| 15 | -            && class_exists('\GeminiLabs\Castor\Helpers\Development') | |
| 16 | -            && method_exists('\GeminiLabs\Castor\Helpers\Development', 'templatePaths')) { // @phpstan-ignore-line | |
| 14 | + if( class_exists( '\GeminiLabs\Castor\Facades\Development' ) | |
| 15 | + && class_exists( '\GeminiLabs\Castor\Helpers\Development' ) | |
| 16 | +            && method_exists( '\GeminiLabs\Castor\Helpers\Development', 'templatePaths' ) ) { // @phpstan-ignore-line | |
| 17 | 17 | $this->entries = \GeminiLabs\Castor\Facades\Development::templatePaths(); | 
| 18 | 18 |          } else { | 
| 19 | -            $files = array_values(array_filter(get_included_files(), function ($file) { | |
| 20 | - $bool = false !== strpos($file, '/themes/') && false === strpos($file, '/functions.php'); | |
| 21 | -                return (bool) apply_filters('blackbar/templates/file', $bool, $file); | |
| 22 | - })); | |
| 23 | -            $this->entries = array_map(function ($file) { | |
| 24 | - return str_replace(trailingslashit(WP_CONTENT_DIR), '', $file); | |
| 25 | - }, $files); | |
| 19 | +            $files = array_values( array_filter( get_included_files(), function( $file ) { | |
| 20 | + $bool = false !== strpos( $file, '/themes/' ) && false === strpos( $file, '/functions.php' ); | |
| 21 | + return (bool) apply_filters( 'blackbar/templates/file', $bool, $file ); | |
| 22 | + }) ); | |
| 23 | +            $this->entries = array_map( function( $file ) { | |
| 24 | + return str_replace( trailingslashit( WP_CONTENT_DIR ), '', $file ); | |
| 25 | + }, $files ); | |
| 26 | 26 | } | 
| 27 | 27 | return $this->entries; | 
| 28 | 28 | } | 
| 29 | 29 | |
| 30 | 30 | public function hasEntries(): bool | 
| 31 | 31 |      { | 
| 32 | - return !empty($this->entries()); | |
| 32 | + return !empty( $this->entries() ); | |
| 33 | 33 | } | 
| 34 | 34 | |
| 35 | 35 | public function isVisible(): bool | 
| @@ -39,6 +39,6 @@ discard block | ||
| 39 | 39 | |
| 40 | 40 | public function label(): string | 
| 41 | 41 |      { | 
| 42 | -        return __('Templates', 'blackbar'); | |
| 42 | + return __( 'Templates', 'blackbar' ); | |
| 43 | 43 | } | 
| 44 | 44 | } | 
| @@ -8,9 +8,12 @@ | ||
| 8 | 8 | </tr> | 
| 9 | 9 | </tbody> | 
| 10 | 10 | </table> | 
| 11 | -<?php else : ?> | |
| 11 | +<?php else { | |
| 12 | + : ?> | |
| 12 | 13 | <form> | 
| 13 | -        <input type="text" id="glbb_hooks_callback" placeholder="<?= esc_attr__('Find callbacks containing', 'blackbar'); ?>"> | |
| 14 | +        <input type="text" id="glbb_hooks_callback" placeholder="<?= esc_attr__('Find callbacks containing', 'blackbar'); | |
| 15 | +} | |
| 16 | +?>"> | |
| 14 | 17 |          <input type="text" id="glbb_hooks_min_time" placeholder="<?= esc_attr__('Minimum total time', 'blackbar'); ?>"> | 
| 15 | 18 | <select id="glbb_hooks_sort_by"> | 
| 16 | 19 |              <option value><?= esc_html__('Sort by total time', 'blackbar'); ?></option> | 
| @@ -1,45 +1,45 @@ | ||
| 1 | -<?php defined('WPINC') || die; ?> | |
| 1 | +<?php defined( 'WPINC' ) || die; ?> | |
| 2 | 2 | |
| 3 | -<?php if (!$module->hasEntries()) : ?> | |
| 3 | +<?php if( !$module->hasEntries() ) : ?> | |
| 4 | 4 | <table> | 
| 5 | 5 | <tbody> | 
| 6 | 6 | <tr> | 
| 7 | -                <td><?= esc_html__('Please deactivate the Debug Bar Slow Actions plugin.', 'blackbar'); ?></td> | |
| 7 | + <td><?= esc_html__( 'Please deactivate the Debug Bar Slow Actions plugin.', 'blackbar' ); ?></td> | |
| 8 | 8 | </tr> | 
| 9 | 9 | </tbody> | 
| 10 | 10 | </table> | 
| 11 | 11 | <?php else : ?> | 
| 12 | 12 | <form> | 
| 13 | -        <input type="text" id="glbb_hooks_callback" placeholder="<?= esc_attr__('Find callbacks containing', 'blackbar'); ?>"> | |
| 14 | -        <input type="text" id="glbb_hooks_min_time" placeholder="<?= esc_attr__('Minimum total time', 'blackbar'); ?>"> | |
| 13 | + <input type="text" id="glbb_hooks_callback" placeholder="<?= esc_attr__( 'Find callbacks containing', 'blackbar' ); ?>"> | |
| 14 | + <input type="text" id="glbb_hooks_min_time" placeholder="<?= esc_attr__( 'Minimum total time', 'blackbar' ); ?>"> | |
| 15 | 15 | <select id="glbb_hooks_sort_by"> | 
| 16 | -            <option value><?= esc_html__('Sort by total time', 'blackbar'); ?></option> | |
| 17 | -            <option value="order"><?= esc_html__('Sort by execution order', 'blackbar'); ?></option> | |
| 16 | + <option value><?= esc_html__( 'Sort by total time', 'blackbar' ); ?></option> | |
| 17 | + <option value="order"><?= esc_html__( 'Sort by execution order', 'blackbar' ); ?></option> | |
| 18 | 18 | </select> | 
| 19 | 19 | </form> | 
| 20 | 20 | <table class="glbb-grid"> | 
| 21 | 21 | <thead> | 
| 22 | 22 | <tr> | 
| 23 | -                <th><?= esc_html__('Action or Filter (Slowest 50)', 'blackbar'); ?></th> | |
| 24 | -                <th><?= esc_html__('Callbacks', 'blackbar'); ?></th> | |
| 25 | -                <th><?= esc_html__('Calls', 'blackbar'); ?></th> | |
| 26 | -                <th><?= esc_html__('Per Call', 'blackbar'); ?></th> | |
| 27 | -                <th><?= esc_html__('Total', 'blackbar'); ?></th> | |
| 23 | + <th><?= esc_html__( 'Action or Filter (Slowest 50)', 'blackbar' ); ?></th> | |
| 24 | + <th><?= esc_html__( 'Callbacks', 'blackbar' ); ?></th> | |
| 25 | + <th><?= esc_html__( 'Calls', 'blackbar' ); ?></th> | |
| 26 | + <th><?= esc_html__( 'Per Call', 'blackbar' ); ?></th> | |
| 27 | + <th><?= esc_html__( 'Total', 'blackbar' ); ?></th> | |
| 28 | 28 | </tr> | 
| 29 | 29 | </thead> | 
| 30 | 30 | <tbody> | 
| 31 | - <?php foreach ($module->entries() as $hook => $data) : ?> | |
| 32 | - <tr class="glbb-row-collapsed" data-index="<?= esc_attr($data['index']); ?>" data-time="<?= esc_attr($data['total']); ?>"> | |
| 33 | - <td><div class="glbb-row-toggle dashicons-before dashicons-arrow-right"><?= esc_html($hook); ?></div></td> | |
| 34 | - <td data-callbacks="<?= esc_attr($data['callbacks_count']); ?>"><?= esc_html($data['callbacks_count']); ?></td> | |
| 35 | - <td data-calls="<?= esc_attr($data['count']); ?>"><?= esc_html($data['count']); ?></td> | |
| 36 | - <td data-percall="<?= esc_attr($data['per_call']); ?>"><?= esc_html($data['per_call']); ?></td> | |
| 37 | - <td data-total="<?= esc_attr($data['total']); ?>"><?= esc_html($data['total_formatted']); ?></td> | |
| 31 | + <?php foreach( $module->entries() as $hook => $data ) : ?> | |
| 32 | + <tr class="glbb-row-collapsed" data-index="<?= esc_attr( $data[ 'index' ] ); ?>" data-time="<?= esc_attr( $data[ 'total' ] ); ?>"> | |
| 33 | + <td><div class="glbb-row-toggle dashicons-before dashicons-arrow-right"><?= esc_html( $hook ); ?></div></td> | |
| 34 | + <td data-callbacks="<?= esc_attr( $data[ 'callbacks_count' ] ); ?>"><?= esc_html( $data[ 'callbacks_count' ] ); ?></td> | |
| 35 | + <td data-calls="<?= esc_attr( $data[ 'count' ] ); ?>"><?= esc_html( $data[ 'count' ] ); ?></td> | |
| 36 | + <td data-percall="<?= esc_attr( $data[ 'per_call' ] ); ?>"><?= esc_html( $data[ 'per_call' ] ); ?></td> | |
| 37 | + <td data-total="<?= esc_attr( $data[ 'total' ] ); ?>"><?= esc_html( $data[ 'total_formatted' ] ); ?></td> | |
| 38 | 38 | <td class="glbb-row-details"> | 
| 39 | 39 | <ol> | 
| 40 | - <?php foreach ($data['callbacks'] as $priority => $callbacks) : ?> | |
| 41 | - <?php foreach ($callbacks as $callback) : ?> | |
| 42 | - <li value="<?= esc_attr($priority); ?>"><?= esc_html($callback); ?></li> | |
| 40 | + <?php foreach( $data[ 'callbacks' ] as $priority => $callbacks ) : ?> | |
| 41 | + <?php foreach( $callbacks as $callback ) : ?> | |
| 42 | + <li value="<?= esc_attr( $priority ); ?>"><?= esc_html( $callback ); ?></li> | |
| 43 | 43 | <?php endforeach; ?> | 
| 44 | 44 | <?php endforeach; ?> | 
| 45 | 45 | </ol> |