| @@ -6,142 +6,142 @@ | ||
| 6 | 6 | |
| 7 | 7 | class Console implements Module | 
| 8 | 8 |  { | 
| 9 | - public const ERROR_CODES = [ | |
| 10 | - E_ERROR => 'error', // 1 | |
| 11 | - E_WARNING => 'warning', // 2 | |
| 12 | - E_NOTICE => 'notice', // 8 | |
| 13 | - E_STRICT => 'strict', // 2048 | |
| 14 | - E_DEPRECATED => 'deprecated', // 8192 | |
| 15 | - ]; | |
| 9 | + public const ERROR_CODES = [ | |
| 10 | + E_ERROR => 'error', // 1 | |
| 11 | + E_WARNING => 'warning', // 2 | |
| 12 | + E_NOTICE => 'notice', // 8 | |
| 13 | + E_STRICT => 'strict', // 2048 | |
| 14 | + E_DEPRECATED => 'deprecated', // 8192 | |
| 15 | + ]; | |
| 16 | 16 | |
| 17 | - public const MAPPED_ERROR_CODES = [ | |
| 18 | - 'debug' => 0, | |
| 19 | - 'info' => E_NOTICE, | |
| 20 | - 'deprecated' => E_DEPRECATED, // 8192 | |
| 21 | - 'error' => E_ERROR, // 1 | |
| 22 | - 'notice' => E_NOTICE, // 8 | |
| 23 | - 'strict' => E_STRICT, // 2048 | |
| 24 | - 'warning' => E_WARNING, // 2 | |
| 25 | - 'critical' => E_ERROR, // 1 | |
| 26 | - 'alert' => E_ERROR, // 1 | |
| 27 | - 'emergency' => E_ERROR, // 1 | |
| 28 | - ]; | |
| 17 | + public const MAPPED_ERROR_CODES = [ | |
| 18 | + 'debug' => 0, | |
| 19 | + 'info' => E_NOTICE, | |
| 20 | + 'deprecated' => E_DEPRECATED, // 8192 | |
| 21 | + 'error' => E_ERROR, // 1 | |
| 22 | + 'notice' => E_NOTICE, // 8 | |
| 23 | + 'strict' => E_STRICT, // 2048 | |
| 24 | + 'warning' => E_WARNING, // 2 | |
| 25 | + 'critical' => E_ERROR, // 1 | |
| 26 | + 'alert' => E_ERROR, // 1 | |
| 27 | + 'emergency' => E_ERROR, // 1 | |
| 28 | + ]; | |
| 29 | 29 | |
| 30 | - /** | |
| 31 | - * @var Application | |
| 32 | - */ | |
| 33 | - protected $app; | |
| 34 | - /** | |
| 35 | - * @var array | |
| 36 | - */ | |
| 37 | - protected $entries; | |
| 30 | + /** | |
| 31 | + * @var Application | |
| 32 | + */ | |
| 33 | + protected $app; | |
| 34 | + /** | |
| 35 | + * @var array | |
| 36 | + */ | |
| 37 | + protected $entries; | |
| 38 | 38 | |
| 39 | - public function __construct(Application $app) | |
| 40 | -    { | |
| 41 | - $this->app = $app; | |
| 42 | - $this->entries = []; | |
| 43 | - } | |
| 39 | + public function __construct(Application $app) | |
| 40 | +	{ | |
| 41 | + $this->app = $app; | |
| 42 | + $this->entries = []; | |
| 43 | + } | |
| 44 | 44 | |
| 45 | - public function entries(): array | |
| 46 | -    { | |
| 47 | - $entries = []; | |
| 48 | -        foreach ($this->entries as $entry) { | |
| 49 | - $entry['name'] = ucfirst($entry['errname']); | |
| 50 | -            if ($entry['count'] > 1) { | |
| 51 | -                $entry['message'] = sprintf('(%s) %s', $entry['count'], $entry['message']); | |
| 52 | - } | |
| 53 | - $entries[] = $entry; | |
| 54 | - } | |
| 55 | - return $entries; | |
| 56 | - } | |
| 45 | + public function entries(): array | |
| 46 | +	{ | |
| 47 | + $entries = []; | |
| 48 | +		foreach ($this->entries as $entry) { | |
| 49 | + $entry['name'] = ucfirst($entry['errname']); | |
| 50 | +			if ($entry['count'] > 1) { | |
| 51 | +				$entry['message'] = sprintf('(%s) %s', $entry['count'], $entry['message']); | |
| 52 | + } | |
| 53 | + $entries[] = $entry; | |
| 54 | + } | |
| 55 | + return $entries; | |
| 56 | + } | |
| 57 | 57 | |
| 58 | - public function hasEntries(): bool | |
| 59 | -    { | |
| 60 | - return !empty($this->entries); | |
| 61 | - } | |
| 58 | + public function hasEntries(): bool | |
| 59 | +	{ | |
| 60 | + return !empty($this->entries); | |
| 61 | + } | |
| 62 | 62 | |
| 63 | - public function id(): string | |
| 64 | -    { | |
| 65 | - return 'glbb-console'; | |
| 66 | - } | |
| 63 | + public function id(): string | |
| 64 | +	{ | |
| 65 | + return 'glbb-console'; | |
| 66 | + } | |
| 67 | 67 | |
| 68 | - public function isVisible(): bool | |
| 69 | -    { | |
| 70 | - return true; | |
| 71 | - } | |
| 68 | + public function isVisible(): bool | |
| 69 | +	{ | |
| 70 | + return true; | |
| 71 | + } | |
| 72 | 72 | |
| 73 | - public function label(): string | |
| 74 | -    { | |
| 75 | - $class = ''; | |
| 76 | - $entryCount = count($this->entries); | |
| 77 | - $errorCount = 0; | |
| 78 | -        $label = __('Console', 'blackbar'); | |
| 79 | -        foreach ($this->entries as $entry) { | |
| 80 | -            if (in_array($entry['errno'], [E_WARNING])) { | |
| 81 | - $class = 'glbb-warning'; | |
| 82 | - } | |
| 83 | -            if (in_array($entry['errno'], [E_ERROR])) { | |
| 84 | - ++$errorCount; | |
| 85 | - } | |
| 86 | - } | |
| 87 | -        if ($errorCount > 0) { | |
| 88 | - $class = 'glbb-error'; | |
| 89 | -            $label = sprintf('%s (%d, %d!)', $label, $entryCount, $errorCount); | |
| 90 | -        } elseif ($entryCount > 0) { | |
| 91 | -            $label = sprintf('%s (%d)', $label, $entryCount); | |
| 92 | - } | |
| 93 | -        return sprintf('<span class="%s">%s</span>', $class, $label); | |
| 94 | - } | |
| 73 | + public function label(): string | |
| 74 | +	{ | |
| 75 | + $class = ''; | |
| 76 | + $entryCount = count($this->entries); | |
| 77 | + $errorCount = 0; | |
| 78 | +		$label = __('Console', 'blackbar'); | |
| 79 | +		foreach ($this->entries as $entry) { | |
| 80 | +			if (in_array($entry['errno'], [E_WARNING])) { | |
| 81 | + $class = 'glbb-warning'; | |
| 82 | + } | |
| 83 | +			if (in_array($entry['errno'], [E_ERROR])) { | |
| 84 | + ++$errorCount; | |
| 85 | + } | |
| 86 | + } | |
| 87 | +		if ($errorCount > 0) { | |
| 88 | + $class = 'glbb-error'; | |
| 89 | +			$label = sprintf('%s (%d, %d!)', $label, $entryCount, $errorCount); | |
| 90 | +		} elseif ($entryCount > 0) { | |
| 91 | +			$label = sprintf('%s (%d)', $label, $entryCount); | |
| 92 | + } | |
| 93 | +		return sprintf('<span class="%s">%s</span>', $class, $label); | |
| 94 | + } | |
| 95 | 95 | |
| 96 | - public function render(): void | |
| 97 | -    { | |
| 98 | -        $this->app->render('panels/console', ['console' => $this]); | |
| 99 | - } | |
| 96 | + public function render(): void | |
| 97 | +	{ | |
| 98 | +		$this->app->render('panels/console', ['console' => $this]); | |
| 99 | + } | |
| 100 | 100 | |
| 101 | - public function store(string $message, string $errno = '', string $location = ''): void | |
| 102 | -    { | |
| 103 | -        if (is_numeric($errno)) { | |
| 104 | - // entry likely stored by set_error_handler() | |
| 105 | - $errname = 'Unknown'; | |
| 106 | -            if (array_key_exists((int) $errno, static::ERROR_CODES)) { | |
| 107 | - $errname = static::ERROR_CODES[$errno]; | |
| 108 | - } | |
| 109 | -        } else { | |
| 110 | - // entry likely stored by filter hook | |
| 111 | - $errname = 'Debug'; | |
| 112 | -            if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { | |
| 113 | - $errname = $errno; | |
| 114 | - $errno = static::MAPPED_ERROR_CODES[$errno]; | |
| 115 | - } | |
| 116 | - } | |
| 117 | - $errname = strtolower($errname); | |
| 118 | - $hash = md5($errno.$errname.$message.$location); | |
| 119 | -        if (array_key_exists($hash, $this->entries)) { | |
| 120 | - ++$this->entries[$hash]['count']; | |
| 121 | -        } else { | |
| 122 | - $this->entries[$hash] = [ | |
| 123 | - 'count' => 0, | |
| 124 | - 'errname' => $errname, | |
| 125 | - 'errno' => (int) $errno, | |
| 126 | - 'message' => $this->normalizeMessage($message, $location), | |
| 127 | - ]; | |
| 128 | - }; | |
| 129 | - } | |
| 101 | + public function store(string $message, string $errno = '', string $location = ''): void | |
| 102 | +	{ | |
| 103 | +		if (is_numeric($errno)) { | |
| 104 | + // entry likely stored by set_error_handler() | |
| 105 | + $errname = 'Unknown'; | |
| 106 | +			if (array_key_exists((int) $errno, static::ERROR_CODES)) { | |
| 107 | + $errname = static::ERROR_CODES[$errno]; | |
| 108 | + } | |
| 109 | +		} else { | |
| 110 | + // entry likely stored by filter hook | |
| 111 | + $errname = 'Debug'; | |
| 112 | +			if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { | |
| 113 | + $errname = $errno; | |
| 114 | + $errno = static::MAPPED_ERROR_CODES[$errno]; | |
| 115 | + } | |
| 116 | + } | |
| 117 | + $errname = strtolower($errname); | |
| 118 | + $hash = md5($errno.$errname.$message.$location); | |
| 119 | +		if (array_key_exists($hash, $this->entries)) { | |
| 120 | + ++$this->entries[$hash]['count']; | |
| 121 | +		} else { | |
| 122 | + $this->entries[$hash] = [ | |
| 123 | + 'count' => 0, | |
| 124 | + 'errname' => $errname, | |
| 125 | + 'errno' => (int) $errno, | |
| 126 | + 'message' => $this->normalizeMessage($message, $location), | |
| 127 | + ]; | |
| 128 | + }; | |
| 129 | + } | |
| 130 | 130 | |
| 131 | - protected function normalizeMessage($message, string $location): string | |
| 132 | -    { | |
| 133 | -        if ($message instanceof \DateTime) { | |
| 134 | -            $message = $message->format('Y-m-d H:i:s'); | |
| 135 | -        } elseif (is_object($message) || is_array($message)) { | |
| 136 | - $message = print_r(json_decode(json_encode($message)), true); | |
| 137 | -        } else { | |
| 138 | - $message = esc_html(trim((string) $message)); | |
| 139 | - } | |
| 140 | - $location = trim($location); | |
| 141 | -        if (!empty($location)) { | |
| 142 | - $location = str_replace([WP_CONTENT_DIR, ABSPATH], '', $location); | |
| 143 | -            $location = sprintf('[%s] ', $location); | |
| 144 | - } | |
| 145 | -        return sprintf('%s%s', $location, (string) $message); | |
| 146 | - } | |
| 131 | + protected function normalizeMessage($message, string $location): string | |
| 132 | +	{ | |
| 133 | +		if ($message instanceof \DateTime) { | |
| 134 | +			$message = $message->format('Y-m-d H:i:s'); | |
| 135 | +		} elseif (is_object($message) || is_array($message)) { | |
| 136 | + $message = print_r(json_decode(json_encode($message)), true); | |
| 137 | +		} else { | |
| 138 | + $message = esc_html(trim((string) $message)); | |
| 139 | + } | |
| 140 | + $location = trim($location); | |
| 141 | +		if (!empty($location)) { | |
| 142 | + $location = str_replace([WP_CONTENT_DIR, ABSPATH], '', $location); | |
| 143 | +			$location = sprintf('[%s] ', $location); | |
| 144 | + } | |
| 145 | +		return sprintf('%s%s', $location, (string) $message); | |
| 146 | + } | |
| 147 | 147 | } | 
| @@ -36,28 +36,28 @@ discard block | ||
| 36 | 36 | */ | 
| 37 | 37 | protected $entries; | 
| 38 | 38 | |
| 39 | - public function __construct(Application $app) | |
| 39 | + public function __construct( Application $app ) | |
| 40 | 40 |      { | 
| 41 | 41 | $this->app = $app; | 
| 42 | - $this->entries = []; | |
| 42 | + $this->entries = [ ]; | |
| 43 | 43 | } | 
| 44 | 44 | |
| 45 | 45 | public function entries(): array | 
| 46 | 46 |      { | 
| 47 | - $entries = []; | |
| 48 | -        foreach ($this->entries as $entry) { | |
| 49 | - $entry['name'] = ucfirst($entry['errname']); | |
| 50 | -            if ($entry['count'] > 1) { | |
| 51 | -                $entry['message'] = sprintf('(%s) %s', $entry['count'], $entry['message']); | |
| 47 | + $entries = [ ]; | |
| 48 | +        foreach( $this->entries as $entry ) { | |
| 49 | + $entry[ 'name' ] = ucfirst( $entry[ 'errname' ] ); | |
| 50 | +            if( $entry[ 'count' ] > 1 ) { | |
| 51 | + $entry[ 'message' ] = sprintf( '(%s) %s', $entry[ 'count' ], $entry[ 'message' ] ); | |
| 52 | 52 | } | 
| 53 | - $entries[] = $entry; | |
| 53 | + $entries[ ] = $entry; | |
| 54 | 54 | } | 
| 55 | 55 | return $entries; | 
| 56 | 56 | } | 
| 57 | 57 | |
| 58 | 58 | public function hasEntries(): bool | 
| 59 | 59 |      { | 
| 60 | - return !empty($this->entries); | |
| 60 | + return !empty( $this->entries ); | |
| 61 | 61 | } | 
| 62 | 62 | |
| 63 | 63 | public function id(): string | 
| @@ -73,75 +73,75 @@ discard block | ||
| 73 | 73 | public function label(): string | 
| 74 | 74 |      { | 
| 75 | 75 | $class = ''; | 
| 76 | - $entryCount = count($this->entries); | |
| 76 | + $entryCount = count( $this->entries ); | |
| 77 | 77 | $errorCount = 0; | 
| 78 | -        $label = __('Console', 'blackbar'); | |
| 79 | -        foreach ($this->entries as $entry) { | |
| 80 | -            if (in_array($entry['errno'], [E_WARNING])) { | |
| 78 | + $label = __( 'Console', 'blackbar' ); | |
| 79 | +        foreach( $this->entries as $entry ) { | |
| 80 | +            if( in_array( $entry[ 'errno' ], [ E_WARNING ] ) ) { | |
| 81 | 81 | $class = 'glbb-warning'; | 
| 82 | 82 | } | 
| 83 | -            if (in_array($entry['errno'], [E_ERROR])) { | |
| 83 | +            if( in_array( $entry[ 'errno' ], [ E_ERROR ] ) ) { | |
| 84 | 84 | ++$errorCount; | 
| 85 | 85 | } | 
| 86 | 86 | } | 
| 87 | -        if ($errorCount > 0) { | |
| 87 | +        if( $errorCount > 0 ) { | |
| 88 | 88 | $class = 'glbb-error'; | 
| 89 | -            $label = sprintf('%s (%d, %d!)', $label, $entryCount, $errorCount); | |
| 90 | -        } elseif ($entryCount > 0) { | |
| 91 | -            $label = sprintf('%s (%d)', $label, $entryCount); | |
| 89 | + $label = sprintf( '%s (%d, %d!)', $label, $entryCount, $errorCount ); | |
| 90 | +        } elseif( $entryCount > 0 ) { | |
| 91 | + $label = sprintf( '%s (%d)', $label, $entryCount ); | |
| 92 | 92 | } | 
| 93 | -        return sprintf('<span class="%s">%s</span>', $class, $label); | |
| 93 | + return sprintf( '<span class="%s">%s</span>', $class, $label ); | |
| 94 | 94 | } | 
| 95 | 95 | |
| 96 | 96 | public function render(): void | 
| 97 | 97 |      { | 
| 98 | -        $this->app->render('panels/console', ['console' => $this]); | |
| 98 | + $this->app->render( 'panels/console', [ 'console' => $this ] ); | |
| 99 | 99 | } | 
| 100 | 100 | |
| 101 | - public function store(string $message, string $errno = '', string $location = ''): void | |
| 101 | + public function store( string $message, string $errno = '', string $location = '' ): void | |
| 102 | 102 |      { | 
| 103 | -        if (is_numeric($errno)) { | |
| 103 | +        if( is_numeric( $errno ) ) { | |
| 104 | 104 | // entry likely stored by set_error_handler() | 
| 105 | 105 | $errname = 'Unknown'; | 
| 106 | -            if (array_key_exists((int) $errno, static::ERROR_CODES)) { | |
| 107 | - $errname = static::ERROR_CODES[$errno]; | |
| 106 | +            if( array_key_exists( (int) $errno, static::ERROR_CODES ) ) { | |
| 107 | + $errname = static::ERROR_CODES[ $errno ]; | |
| 108 | 108 | } | 
| 109 | 109 |          } else { | 
| 110 | 110 | // entry likely stored by filter hook | 
| 111 | 111 | $errname = 'Debug'; | 
| 112 | -            if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { | |
| 112 | +            if( array_key_exists( $errno, static::MAPPED_ERROR_CODES ) ) { | |
| 113 | 113 | $errname = $errno; | 
| 114 | - $errno = static::MAPPED_ERROR_CODES[$errno]; | |
| 114 | + $errno = static::MAPPED_ERROR_CODES[ $errno ]; | |
| 115 | 115 | } | 
| 116 | 116 | } | 
| 117 | - $errname = strtolower($errname); | |
| 118 | - $hash = md5($errno.$errname.$message.$location); | |
| 119 | -        if (array_key_exists($hash, $this->entries)) { | |
| 120 | - ++$this->entries[$hash]['count']; | |
| 117 | + $errname = strtolower( $errname ); | |
| 118 | + $hash = md5( $errno . $errname . $message . $location ); | |
| 119 | +        if( array_key_exists( $hash, $this->entries ) ) { | |
| 120 | + ++$this->entries[ $hash ][ 'count' ]; | |
| 121 | 121 |          } else { | 
| 122 | - $this->entries[$hash] = [ | |
| 122 | + $this->entries[ $hash ] = [ | |
| 123 | 123 | 'count' => 0, | 
| 124 | 124 | 'errname' => $errname, | 
| 125 | 125 | 'errno' => (int) $errno, | 
| 126 | - 'message' => $this->normalizeMessage($message, $location), | |
| 126 | + 'message' => $this->normalizeMessage( $message, $location ), | |
| 127 | 127 | ]; | 
| 128 | 128 | }; | 
| 129 | 129 | } | 
| 130 | 130 | |
| 131 | - protected function normalizeMessage($message, string $location): string | |
| 131 | + protected function normalizeMessage( $message, string $location ): string | |
| 132 | 132 |      { | 
| 133 | -        if ($message instanceof \DateTime) { | |
| 134 | -            $message = $message->format('Y-m-d H:i:s'); | |
| 135 | -        } elseif (is_object($message) || is_array($message)) { | |
| 136 | - $message = print_r(json_decode(json_encode($message)), true); | |
| 133 | +        if( $message instanceof \DateTime ) { | |
| 134 | + $message = $message->format( 'Y-m-d H:i:s' ); | |
| 135 | +        } elseif( is_object( $message ) || is_array( $message ) ) { | |
| 136 | + $message = print_r( json_decode( json_encode( $message ) ), true ); | |
| 137 | 137 |          } else { | 
| 138 | - $message = esc_html(trim((string) $message)); | |
| 138 | + $message = esc_html( trim( (string) $message ) ); | |
| 139 | 139 | } | 
| 140 | - $location = trim($location); | |
| 141 | -        if (!empty($location)) { | |
| 142 | - $location = str_replace([WP_CONTENT_DIR, ABSPATH], '', $location); | |
| 143 | -            $location = sprintf('[%s] ', $location); | |
| 140 | + $location = trim( $location ); | |
| 141 | +        if( !empty( $location ) ) { | |
| 142 | + $location = str_replace( [ WP_CONTENT_DIR, ABSPATH ], '', $location ); | |
| 143 | + $location = sprintf( '[%s] ', $location ); | |
| 144 | 144 | } | 
| 145 | -        return sprintf('%s%s', $location, (string) $message); | |
| 145 | + return sprintf( '%s%s', $location, (string) $message ); | |
| 146 | 146 | } | 
| 147 | 147 | } | 
| @@ -6,162 +6,162 @@ | ||
| 6 | 6 | |
| 7 | 7 | class Actions implements Module | 
| 8 | 8 |  { | 
| 9 | - /** | |
| 10 | - * @var Application | |
| 11 | - */ | |
| 12 | - protected $app; | |
| 13 | - /** | |
| 14 | - * @var array | |
| 15 | - */ | |
| 16 | - protected $entries; | |
| 17 | - /** | |
| 18 | - * @var array | |
| 19 | - */ | |
| 20 | - protected $hooks; | |
| 21 | - /** | |
| 22 | - * @var int | |
| 23 | - */ | |
| 24 | - protected $totalActions; | |
| 25 | - /** | |
| 26 | - * @var float | |
| 27 | - */ | |
| 28 | - protected $totalTime; | |
| 9 | + /** | |
| 10 | + * @var Application | |
| 11 | + */ | |
| 12 | + protected $app; | |
| 13 | + /** | |
| 14 | + * @var array | |
| 15 | + */ | |
| 16 | + protected $entries; | |
| 17 | + /** | |
| 18 | + * @var array | |
| 19 | + */ | |
| 20 | + protected $hooks; | |
| 21 | + /** | |
| 22 | + * @var int | |
| 23 | + */ | |
| 24 | + protected $totalActions; | |
| 25 | + /** | |
| 26 | + * @var float | |
| 27 | + */ | |
| 28 | + protected $totalTime; | |
| 29 | 29 | |
| 30 | - public function __construct(Application $app) | |
| 31 | -    { | |
| 32 | - $this->app = $app; | |
| 33 | - $this->entries = []; | |
| 34 | - $this->hooks = []; | |
| 35 | - $this->totalActions = 0; | |
| 36 | - $this->totalTime = (float) 0; | |
| 37 | - } | |
| 30 | + public function __construct(Application $app) | |
| 31 | +	{ | |
| 32 | + $this->app = $app; | |
| 33 | + $this->entries = []; | |
| 34 | + $this->hooks = []; | |
| 35 | + $this->totalActions = 0; | |
| 36 | + $this->totalTime = (float) 0; | |
| 37 | + } | |
| 38 | 38 | |
| 39 | - public function callbacksForHook(string $action): void | |
| 40 | -    { | |
| 41 | - global $wp_filter; | |
| 42 | -        if (!array_key_exists($action, $this->hooks)) { | |
| 43 | - return; | |
| 44 | - } | |
| 45 | - $this->hooks[$action]['callbacks_count'] = 0; | |
| 46 | -        foreach ($wp_filter[$action] as $priority => $callbacks) { | |
| 47 | -            if (!array_key_exists($priority, $this->hooks[$action]['callbacks'])) { | |
| 48 | - $this->hooks[$action]['callbacks'][$priority] = []; | |
| 49 | - } | |
| 50 | -            foreach ($callbacks as $callback) { | |
| 51 | -                if (is_array($callback['function']) && 2 === count($callback['function'])) { | |
| 52 | - list($object, $method) = $callback['function']; | |
| 53 | -                    if (is_object($object)) { | |
| 54 | - $object = get_class($object); | |
| 55 | - // $reflection = new \ReflectionClass($object); | |
| 56 | -                        // if (str_starts_with($reflection->getNamespaceName(), 'GeminiLabs\BlackBar')) { | |
| 57 | - // continue; // skip blackbar callbacks | |
| 58 | - // } | |
| 59 | - } | |
| 60 | -                    $this->hooks[$action]['callbacks'][$priority][] = sprintf('%s::%s', $object, $method); | |
| 61 | -                } elseif (is_object($callback['function'])) { | |
| 62 | - $this->hooks[$action]['callbacks'][$priority][] = get_class($callback['function']); | |
| 63 | -                } else { | |
| 64 | - $this->hooks[$action]['callbacks'][$priority][] = $callback['function']; | |
| 65 | - } | |
| 66 | - ++$this->hooks[$action]['callbacks_count']; | |
| 67 | - } | |
| 68 | - } | |
| 69 | - } | |
| 39 | + public function callbacksForHook(string $action): void | |
| 40 | +	{ | |
| 41 | + global $wp_filter; | |
| 42 | +		if (!array_key_exists($action, $this->hooks)) { | |
| 43 | + return; | |
| 44 | + } | |
| 45 | + $this->hooks[$action]['callbacks_count'] = 0; | |
| 46 | +		foreach ($wp_filter[$action] as $priority => $callbacks) { | |
| 47 | +			if (!array_key_exists($priority, $this->hooks[$action]['callbacks'])) { | |
| 48 | + $this->hooks[$action]['callbacks'][$priority] = []; | |
| 49 | + } | |
| 50 | +			foreach ($callbacks as $callback) { | |
| 51 | +				if (is_array($callback['function']) && 2 === count($callback['function'])) { | |
| 52 | + list($object, $method) = $callback['function']; | |
| 53 | +					if (is_object($object)) { | |
| 54 | + $object = get_class($object); | |
| 55 | + // $reflection = new \ReflectionClass($object); | |
| 56 | +						// if (str_starts_with($reflection->getNamespaceName(), 'GeminiLabs\BlackBar')) { | |
| 57 | + // continue; // skip blackbar callbacks | |
| 58 | + // } | |
| 59 | + } | |
| 60 | +					$this->hooks[$action]['callbacks'][$priority][] = sprintf('%s::%s', $object, $method); | |
| 61 | +				} elseif (is_object($callback['function'])) { | |
| 62 | + $this->hooks[$action]['callbacks'][$priority][] = get_class($callback['function']); | |
| 63 | +				} else { | |
| 64 | + $this->hooks[$action]['callbacks'][$priority][] = $callback['function']; | |
| 65 | + } | |
| 66 | + ++$this->hooks[$action]['callbacks_count']; | |
| 67 | + } | |
| 68 | + } | |
| 69 | + } | |
| 70 | 70 | |
| 71 | - public function entries(): array | |
| 72 | -    { | |
| 73 | -        if (class_exists('Debug_Bar_Slow_Actions')) { | |
| 74 | - return []; | |
| 75 | - } | |
| 76 | -        if (!empty($this->entries) || empty($this->hooks)) { | |
| 77 | - return $this->entries; | |
| 78 | - } | |
| 79 | -        foreach ($this->hooks as $action => $data) { | |
| 80 | - $total = $this->totalTimeForHook($data); | |
| 81 | - $this->hooks[$action]['total'] = $total; | |
| 82 | - $this->totalTime += $total; | |
| 83 | - $this->totalActions += $data['count']; | |
| 84 | - $this->callbacksForHook($action); | |
| 85 | - } | |
| 86 | - uasort($this->hooks, [$this, 'sortByTime']); | |
| 87 | - $this->entries = array_slice($this->hooks, 0, 50); // return the 50 slowest actions | |
| 88 | - return $this->entries; | |
| 89 | - } | |
| 71 | + public function entries(): array | |
| 72 | +	{ | |
| 73 | +		if (class_exists('Debug_Bar_Slow_Actions')) { | |
| 74 | + return []; | |
| 75 | + } | |
| 76 | +		if (!empty($this->entries) || empty($this->hooks)) { | |
| 77 | + return $this->entries; | |
| 78 | + } | |
| 79 | +		foreach ($this->hooks as $action => $data) { | |
| 80 | + $total = $this->totalTimeForHook($data); | |
| 81 | + $this->hooks[$action]['total'] = $total; | |
| 82 | + $this->totalTime += $total; | |
| 83 | + $this->totalActions += $data['count']; | |
| 84 | + $this->callbacksForHook($action); | |
| 85 | + } | |
| 86 | + uasort($this->hooks, [$this, 'sortByTime']); | |
| 87 | + $this->entries = array_slice($this->hooks, 0, 50); // return the 50 slowest actions | |
| 88 | + return $this->entries; | |
| 89 | + } | |
| 90 | 90 | |
| 91 | - public function hasEntries(): bool | |
| 92 | -    { | |
| 93 | - return !empty($this->entries()); | |
| 94 | - } | |
| 91 | + public function hasEntries(): bool | |
| 92 | +	{ | |
| 93 | + return !empty($this->entries()); | |
| 94 | + } | |
| 95 | 95 | |
| 96 | - public function id(): string | |
| 97 | -    { | |
| 98 | - return 'glbb-actions'; | |
| 99 | - } | |
| 96 | + public function id(): string | |
| 97 | +	{ | |
| 98 | + return 'glbb-actions'; | |
| 99 | + } | |
| 100 | 100 | |
| 101 | - public function isVisible(): bool | |
| 102 | -    { | |
| 103 | - return true; | |
| 104 | - } | |
| 101 | + public function isVisible(): bool | |
| 102 | +	{ | |
| 103 | + return true; | |
| 104 | + } | |
| 105 | 105 | |
| 106 | - public function label(): string | |
| 107 | -    { | |
| 108 | -        $label = __('Hooks', 'blackbar'); | |
| 109 | -        if (class_exists('Debug_Bar_Slow_Actions')) { | |
| 110 | - return $label; | |
| 111 | - } | |
| 112 | - $this->entries(); // calculates the totalTime | |
| 113 | -        if ($this->totalTime > 0) { | |
| 114 | -            $label = sprintf('%s (%.2f %s)', $label, $this->totalTime, __('ms', 'blackbar')); | |
| 115 | - } | |
| 116 | - return $label; | |
| 117 | - } | |
| 106 | + public function label(): string | |
| 107 | +	{ | |
| 108 | +		$label = __('Hooks', 'blackbar'); | |
| 109 | +		if (class_exists('Debug_Bar_Slow_Actions')) { | |
| 110 | + return $label; | |
| 111 | + } | |
| 112 | + $this->entries(); // calculates the totalTime | |
| 113 | +		if ($this->totalTime > 0) { | |
| 114 | +			$label = sprintf('%s (%.2f %s)', $label, $this->totalTime, __('ms', 'blackbar')); | |
| 115 | + } | |
| 116 | + return $label; | |
| 117 | + } | |
| 118 | 118 | |
| 119 | - public function render(): void | |
| 120 | -    { | |
| 121 | -        $this->app->render('panels/actions', ['actions' => $this]); | |
| 122 | - } | |
| 119 | + public function render(): void | |
| 120 | +	{ | |
| 121 | +		$this->app->render('panels/actions', ['actions' => $this]); | |
| 122 | + } | |
| 123 | 123 | |
| 124 | - public function startTimer(): void | |
| 125 | -    { | |
| 126 | -        if (!isset($this->hooks[current_filter()])) { | |
| 127 | - $this->hooks[current_filter()] = [ | |
| 128 | - 'callbacks' => [], | |
| 129 | - 'count' => 0, | |
| 130 | - 'stack' => [], | |
| 131 | - 'time' => [], | |
| 132 | - ]; | |
| 133 | - add_action(current_filter(), [$this, 'stopTimer'], 9999); // @phpstan-ignore-line | |
| 134 | - } | |
| 135 | - ++$this->hooks[current_filter()]['count']; | |
| 136 | - array_push($this->hooks[current_filter()]['stack'], ['start' => microtime(true)]); | |
| 137 | - } | |
| 124 | + public function startTimer(): void | |
| 125 | +	{ | |
| 126 | +		if (!isset($this->hooks[current_filter()])) { | |
| 127 | + $this->hooks[current_filter()] = [ | |
| 128 | + 'callbacks' => [], | |
| 129 | + 'count' => 0, | |
| 130 | + 'stack' => [], | |
| 131 | + 'time' => [], | |
| 132 | + ]; | |
| 133 | + add_action(current_filter(), [$this, 'stopTimer'], 9999); // @phpstan-ignore-line | |
| 134 | + } | |
| 135 | + ++$this->hooks[current_filter()]['count']; | |
| 136 | + array_push($this->hooks[current_filter()]['stack'], ['start' => microtime(true)]); | |
| 137 | + } | |
| 138 | 138 | |
| 139 | - /** | |
| 140 | - * @param mixed $filteredValue | |
| 141 | - * @return mixed | |
| 142 | - */ | |
| 143 | - public function stopTimer($filteredValue = null) | |
| 144 | -    { | |
| 145 | - $time = array_pop($this->hooks[current_filter()]['stack']); | |
| 146 | - $time['stop'] = microtime(true); | |
| 147 | - array_push($this->hooks[current_filter()]['time'], $time); | |
| 148 | - return $filteredValue; // In case this was a filter. | |
| 149 | - } | |
| 139 | + /** | |
| 140 | + * @param mixed $filteredValue | |
| 141 | + * @return mixed | |
| 142 | + */ | |
| 143 | + public function stopTimer($filteredValue = null) | |
| 144 | +	{ | |
| 145 | + $time = array_pop($this->hooks[current_filter()]['stack']); | |
| 146 | + $time['stop'] = microtime(true); | |
| 147 | + array_push($this->hooks[current_filter()]['time'], $time); | |
| 148 | + return $filteredValue; // In case this was a filter. | |
| 149 | + } | |
| 150 | 150 | |
| 151 | - public function totalTimeForHook(array $data): float | |
| 152 | -    { | |
| 153 | - $total = 0; | |
| 154 | -        foreach ($data['time'] as $time) { | |
| 155 | - $total += ($time['stop'] - $time['start']) * 1000; | |
| 156 | - } | |
| 157 | - return (float) $total; | |
| 158 | - } | |
| 151 | + public function totalTimeForHook(array $data): float | |
| 152 | +	{ | |
| 153 | + $total = 0; | |
| 154 | +		foreach ($data['time'] as $time) { | |
| 155 | + $total += ($time['stop'] - $time['start']) * 1000; | |
| 156 | + } | |
| 157 | + return (float) $total; | |
| 158 | + } | |
| 159 | 159 | |
| 160 | - protected function sortByTime(array $a, array $b): int | |
| 161 | -    { | |
| 162 | -        if ($a['total'] !== $b['total']) { | |
| 163 | - return ($a['total'] > $b['total']) ? -1 : 1; | |
| 164 | - } | |
| 165 | - return 0; | |
| 166 | - } | |
| 160 | + protected function sortByTime(array $a, array $b): int | |
| 161 | +	{ | |
| 162 | +		if ($a['total'] !== $b['total']) { | |
| 163 | + return ($a['total'] > $b['total']) ? -1 : 1; | |
| 164 | + } | |
| 165 | + return 0; | |
| 166 | + } | |
| 167 | 167 | } | 
| @@ -27,70 +27,70 @@ discard block | ||
| 27 | 27 | */ | 
| 28 | 28 | protected $totalTime; | 
| 29 | 29 | |
| 30 | - public function __construct(Application $app) | |
| 30 | + public function __construct( Application $app ) | |
| 31 | 31 |      { | 
| 32 | 32 | $this->app = $app; | 
| 33 | - $this->entries = []; | |
| 34 | - $this->hooks = []; | |
| 33 | + $this->entries = [ ]; | |
| 34 | + $this->hooks = [ ]; | |
| 35 | 35 | $this->totalActions = 0; | 
| 36 | 36 | $this->totalTime = (float) 0; | 
| 37 | 37 | } | 
| 38 | 38 | |
| 39 | - public function callbacksForHook(string $action): void | |
| 39 | + public function callbacksForHook( string $action ): void | |
| 40 | 40 |      { | 
| 41 | 41 | global $wp_filter; | 
| 42 | -        if (!array_key_exists($action, $this->hooks)) { | |
| 42 | +        if( !array_key_exists( $action, $this->hooks ) ) { | |
| 43 | 43 | return; | 
| 44 | 44 | } | 
| 45 | - $this->hooks[$action]['callbacks_count'] = 0; | |
| 46 | -        foreach ($wp_filter[$action] as $priority => $callbacks) { | |
| 47 | -            if (!array_key_exists($priority, $this->hooks[$action]['callbacks'])) { | |
| 48 | - $this->hooks[$action]['callbacks'][$priority] = []; | |
| 45 | + $this->hooks[ $action ][ 'callbacks_count' ] = 0; | |
| 46 | +        foreach( $wp_filter[ $action ] as $priority => $callbacks ) { | |
| 47 | +            if( !array_key_exists( $priority, $this->hooks[ $action ][ 'callbacks' ] ) ) { | |
| 48 | + $this->hooks[ $action ][ 'callbacks' ][ $priority ] = [ ]; | |
| 49 | 49 | } | 
| 50 | -            foreach ($callbacks as $callback) { | |
| 51 | -                if (is_array($callback['function']) && 2 === count($callback['function'])) { | |
| 52 | - list($object, $method) = $callback['function']; | |
| 53 | -                    if (is_object($object)) { | |
| 54 | - $object = get_class($object); | |
| 50 | +            foreach( $callbacks as $callback ) { | |
| 51 | +                if( is_array( $callback[ 'function' ] ) && 2 === count( $callback[ 'function' ] ) ) { | |
| 52 | + list( $object, $method ) = $callback[ 'function' ]; | |
| 53 | +                    if( is_object( $object ) ) { | |
| 54 | + $object = get_class( $object ); | |
| 55 | 55 | // $reflection = new \ReflectionClass($object); | 
| 56 | 56 |                          // if (str_starts_with($reflection->getNamespaceName(), 'GeminiLabs\BlackBar')) { | 
| 57 | 57 | // continue; // skip blackbar callbacks | 
| 58 | 58 | // } | 
| 59 | 59 | } | 
| 60 | -                    $this->hooks[$action]['callbacks'][$priority][] = sprintf('%s::%s', $object, $method); | |
| 61 | -                } elseif (is_object($callback['function'])) { | |
| 62 | - $this->hooks[$action]['callbacks'][$priority][] = get_class($callback['function']); | |
| 60 | + $this->hooks[ $action ][ 'callbacks' ][ $priority ][ ] = sprintf( '%s::%s', $object, $method ); | |
| 61 | +                } elseif( is_object( $callback[ 'function' ] ) ) { | |
| 62 | + $this->hooks[ $action ][ 'callbacks' ][ $priority ][ ] = get_class( $callback[ 'function' ] ); | |
| 63 | 63 |                  } else { | 
| 64 | - $this->hooks[$action]['callbacks'][$priority][] = $callback['function']; | |
| 64 | + $this->hooks[ $action ][ 'callbacks' ][ $priority ][ ] = $callback[ 'function' ]; | |
| 65 | 65 | } | 
| 66 | - ++$this->hooks[$action]['callbacks_count']; | |
| 66 | + ++$this->hooks[ $action ][ 'callbacks_count' ]; | |
| 67 | 67 | } | 
| 68 | 68 | } | 
| 69 | 69 | } | 
| 70 | 70 | |
| 71 | 71 | public function entries(): array | 
| 72 | 72 |      { | 
| 73 | -        if (class_exists('Debug_Bar_Slow_Actions')) { | |
| 74 | - return []; | |
| 73 | +        if( class_exists( 'Debug_Bar_Slow_Actions' ) ) { | |
| 74 | + return [ ]; | |
| 75 | 75 | } | 
| 76 | -        if (!empty($this->entries) || empty($this->hooks)) { | |
| 76 | +        if( !empty( $this->entries ) || empty( $this->hooks ) ) { | |
| 77 | 77 | return $this->entries; | 
| 78 | 78 | } | 
| 79 | -        foreach ($this->hooks as $action => $data) { | |
| 80 | - $total = $this->totalTimeForHook($data); | |
| 81 | - $this->hooks[$action]['total'] = $total; | |
| 79 | +        foreach( $this->hooks as $action => $data ) { | |
| 80 | + $total = $this->totalTimeForHook( $data ); | |
| 81 | + $this->hooks[ $action ][ 'total' ] = $total; | |
| 82 | 82 | $this->totalTime += $total; | 
| 83 | - $this->totalActions += $data['count']; | |
| 84 | - $this->callbacksForHook($action); | |
| 83 | + $this->totalActions += $data[ 'count' ]; | |
| 84 | + $this->callbacksForHook( $action ); | |
| 85 | 85 | } | 
| 86 | - uasort($this->hooks, [$this, 'sortByTime']); | |
| 87 | - $this->entries = array_slice($this->hooks, 0, 50); // return the 50 slowest actions | |
| 86 | + uasort( $this->hooks, [ $this, 'sortByTime' ] ); | |
| 87 | + $this->entries = array_slice( $this->hooks, 0, 50 ); // return the 50 slowest actions | |
| 88 | 88 | return $this->entries; | 
| 89 | 89 | } | 
| 90 | 90 | |
| 91 | 91 | public function hasEntries(): bool | 
| 92 | 92 |      { | 
| 93 | - return !empty($this->entries()); | |
| 93 | + return !empty( $this->entries() ); | |
| 94 | 94 | } | 
| 95 | 95 | |
| 96 | 96 | public function id(): string | 
| @@ -105,62 +105,62 @@ discard block | ||
| 105 | 105 | |
| 106 | 106 | public function label(): string | 
| 107 | 107 |      { | 
| 108 | -        $label = __('Hooks', 'blackbar'); | |
| 109 | -        if (class_exists('Debug_Bar_Slow_Actions')) { | |
| 108 | + $label = __( 'Hooks', 'blackbar' ); | |
| 109 | +        if( class_exists( 'Debug_Bar_Slow_Actions' ) ) { | |
| 110 | 110 | return $label; | 
| 111 | 111 | } | 
| 112 | 112 | $this->entries(); // calculates the totalTime | 
| 113 | -        if ($this->totalTime > 0) { | |
| 114 | -            $label = sprintf('%s (%.2f %s)', $label, $this->totalTime, __('ms', 'blackbar')); | |
| 113 | +        if( $this->totalTime > 0 ) { | |
| 114 | + $label = sprintf( '%s (%.2f %s)', $label, $this->totalTime, __( 'ms', 'blackbar' ) ); | |
| 115 | 115 | } | 
| 116 | 116 | return $label; | 
| 117 | 117 | } | 
| 118 | 118 | |
| 119 | 119 | public function render(): void | 
| 120 | 120 |      { | 
| 121 | -        $this->app->render('panels/actions', ['actions' => $this]); | |
| 121 | + $this->app->render( 'panels/actions', [ 'actions' => $this ] ); | |
| 122 | 122 | } | 
| 123 | 123 | |
| 124 | 124 | public function startTimer(): void | 
| 125 | 125 |      { | 
| 126 | -        if (!isset($this->hooks[current_filter()])) { | |
| 127 | - $this->hooks[current_filter()] = [ | |
| 128 | - 'callbacks' => [], | |
| 126 | +        if( !isset( $this->hooks[ current_filter() ] ) ) { | |
| 127 | + $this->hooks[ current_filter() ] = [ | |
| 128 | + 'callbacks' => [ ], | |
| 129 | 129 | 'count' => 0, | 
| 130 | - 'stack' => [], | |
| 131 | - 'time' => [], | |
| 130 | + 'stack' => [ ], | |
| 131 | + 'time' => [ ], | |
| 132 | 132 | ]; | 
| 133 | - add_action(current_filter(), [$this, 'stopTimer'], 9999); // @phpstan-ignore-line | |
| 133 | + add_action( current_filter(), [ $this, 'stopTimer' ], 9999 ); // @phpstan-ignore-line | |
| 134 | 134 | } | 
| 135 | - ++$this->hooks[current_filter()]['count']; | |
| 136 | - array_push($this->hooks[current_filter()]['stack'], ['start' => microtime(true)]); | |
| 135 | + ++$this->hooks[ current_filter() ][ 'count' ]; | |
| 136 | + array_push( $this->hooks[ current_filter() ][ 'stack' ], [ 'start' => microtime( true ) ] ); | |
| 137 | 137 | } | 
| 138 | 138 | |
| 139 | 139 | /** | 
| 140 | 140 | * @param mixed $filteredValue | 
| 141 | 141 | * @return mixed | 
| 142 | 142 | */ | 
| 143 | - public function stopTimer($filteredValue = null) | |
| 143 | + public function stopTimer( $filteredValue = null ) | |
| 144 | 144 |      { | 
| 145 | - $time = array_pop($this->hooks[current_filter()]['stack']); | |
| 146 | - $time['stop'] = microtime(true); | |
| 147 | - array_push($this->hooks[current_filter()]['time'], $time); | |
| 145 | + $time = array_pop( $this->hooks[ current_filter() ][ 'stack' ] ); | |
| 146 | + $time[ 'stop' ] = microtime( true ); | |
| 147 | + array_push( $this->hooks[ current_filter() ][ 'time' ], $time ); | |
| 148 | 148 | return $filteredValue; // In case this was a filter. | 
| 149 | 149 | } | 
| 150 | 150 | |
| 151 | - public function totalTimeForHook(array $data): float | |
| 151 | + public function totalTimeForHook( array $data ): float | |
| 152 | 152 |      { | 
| 153 | 153 | $total = 0; | 
| 154 | -        foreach ($data['time'] as $time) { | |
| 155 | - $total += ($time['stop'] - $time['start']) * 1000; | |
| 154 | +        foreach( $data[ 'time' ] as $time ) { | |
| 155 | + $total += ( $time[ 'stop' ] - $time[ 'start' ] ) * 1000; | |
| 156 | 156 | } | 
| 157 | 157 | return (float) $total; | 
| 158 | 158 | } | 
| 159 | 159 | |
| 160 | - protected function sortByTime(array $a, array $b): int | |
| 160 | + protected function sortByTime( array $a, array $b ): int | |
| 161 | 161 |      { | 
| 162 | -        if ($a['total'] !== $b['total']) { | |
| 163 | - return ($a['total'] > $b['total']) ? -1 : 1; | |
| 162 | +        if( $a[ 'total' ] !== $b[ 'total' ] ) { | |
| 163 | + return ( $a[ 'total' ] > $b[ 'total' ] ) ? -1 : 1; | |
| 164 | 164 | } | 
| 165 | 165 | return 0; | 
| 166 | 166 | } |