From 5d991a1446adbfff7c794956b63c76d62963aae3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederic=20G=2E=20=C3=98stby?= Date: Thu, 23 Nov 2023 22:42:35 +0100 Subject: [PATCH] Updated cs-fixer rules --- .php-cs-fixer.php | 2 ++ src/Toolbar.php | 16 ++++++---------- src/ToolbarMiddleware.php | 7 +++---- src/ToolbarPackage.php | 24 ++++++++---------------- src/panels/ConfigPanel.php | 21 +++++++-------------- src/panels/DatabasePanel.php | 18 ++++++------------ src/panels/IncludedFilesPanel.php | 6 ++---- src/panels/MonologPanel.php | 12 ++++-------- src/panels/OPcachePanel.php | 6 ++---- src/panels/RequestPanel.php | 9 +++------ src/panels/ResponsePanel.php | 6 ++---- src/panels/SessionPanel.php | 6 ++---- src/panels/traits/DumperTrait.php | 6 ++---- 13 files changed, 49 insertions(+), 90 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 9eb35dc..e418b25 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -15,6 +15,7 @@ 'concat_space' => ['spacing' => 'one'], 'constant_case' => true, 'dir_constant' => true, + 'curly_braces_position' => true, 'elseif' => true, 'encoding' => true, 'full_opening_tag' => true, @@ -83,6 +84,7 @@ 'single_line_after_imports' => true, 'single_line_comment_style' => ['comment_types' => ['hash']], 'single_quote' => true, + 'single_space_around_construct' => true, 'space_after_semicolon' => true, 'standardize_not_equals' => true, 'switch_case_semicolon_to_colon' => true, diff --git a/src/Toolbar.php b/src/Toolbar.php index 5dede3a..f7cf321 100644 --- a/src/Toolbar.php +++ b/src/Toolbar.php @@ -41,8 +41,8 @@ public function __construct( protected ViewFactory $view, protected Humanizer $humanizer, protected Application $application - ) - {} + ) { + } /** * Add a panel to the toolbar. @@ -71,8 +71,7 @@ protected function calculateExecutionTime(): array $otherTime = 0; - foreach($this->timers as $timer) - { + foreach ($this->timers as $timer) { $otherTime += $timer instanceof Closure ? $timer() : $timer; } @@ -80,10 +79,8 @@ protected function calculateExecutionTime(): array $executionTime['details']['PHP'] = ['time' => $detailedTime, 'pct' => ($detailedTime / $totalTime * 100)]; - foreach($this->timers as $timer => $time) - { - if($time instanceof Closure) - { + foreach ($this->timers as $timer => $time) { + if ($time instanceof Closure) { $time = $time(); } @@ -100,8 +97,7 @@ public function render(): string { $executionTime = $this->calculateExecutionTime(); - $view = $this->view->create('mako-toolbar::toolbar', - [ + $view = $this->view->create('mako-toolbar::toolbar', [ 'humanizer' => $this->humanizer, 'version' => Mako::VERSION, 'memory' => memory_get_peak_usage(), diff --git a/src/ToolbarMiddleware.php b/src/ToolbarMiddleware.php index abbbe80..935f139 100644 --- a/src/ToolbarMiddleware.php +++ b/src/ToolbarMiddleware.php @@ -27,8 +27,8 @@ class ToolbarMiddleware implements MiddlewareInterface */ public function __construct( protected Toolbar $toolbar - ) - {} + ) { + } /** * {@inheritDoc} @@ -39,8 +39,7 @@ public function execute(Request $request, Response $response, Closure $next): Re $body = $response->getBody(); - if($response->getType() === 'text/html' && (is_string($body) || (is_object($body) && method_exists($body, '__toString')))) - { + if ($response->getType() === 'text/html' && (is_string($body) || (is_object($body) && method_exists($body, '__toString')))) { $response->setBody(str_replace('', $this->toolbar->render() . '', $body)); } diff --git a/src/ToolbarPackage.php b/src/ToolbarPackage.php index af873e9..9d84fe2 100644 --- a/src/ToolbarPackage.php +++ b/src/ToolbarPackage.php @@ -50,22 +50,19 @@ protected function bootstrap(): void // Add logger if monolog is in the container - if($this->container->has(LoggerInterface::class)) - { + if ($this->container->has(LoggerInterface::class)) { $monologHandler = new MonologHandler(MonoLogger::DEBUG, true); $logger = $this->container->get(LoggerInterface::class)->getLogger(); - if($logger instanceof MonoLogger) - { + if ($logger instanceof MonoLogger) { $logger->pushHandler($monologHandler); } } // Register the toolbar in the container - $this->container->registerSingleton([Toolbar::class, 'toolbar'], static function ($container) use ($monologHandler) - { + $this->container->registerSingleton([Toolbar::class, 'toolbar'], static function ($container) use ($monologHandler) { $view = $container->get(ViewFactory::class); $toolbar = new Toolbar($view, $container->get(Humanizer::class), $container->get(Application::class)); @@ -76,13 +73,11 @@ protected function bootstrap(): void $toolbar->addPanel(new ConfigPanel($view, $container->get(Config::class), $container->get(Application::class)->getEnvironment())); - if($container->has(Session::class)) - { + if ($container->has(Session::class)) { $toolbar->addPanel(new SessionPanel($view, $container->get(Session::class))); } - if($container->has(DatabaseConnectionManager::class)) - { + if ($container->has(DatabaseConnectionManager::class)) { $panel = new DatabasePanel($view, $container->get(DatabaseConnectionManager::class)); $toolbar->addPanel($panel); @@ -90,13 +85,11 @@ protected function bootstrap(): void $toolbar->addTimer('SQL', fn () => $panel->getTotalQueryTime()); } - if($monologHandler !== null) - { + if ($monologHandler !== null) { $toolbar->addPanel(new MonologPanel($view, $monologHandler)); } - if(function_exists('opcache_get_status')) - { + if (function_exists('opcache_get_status')) { $toolbar->addPanel(new OPcachePanel($view, $container->get(URLBuilder::class))); } @@ -105,8 +98,7 @@ protected function bootstrap(): void // Register routes - if(function_exists('opcache_get_status')) - { + if (function_exists('opcache_get_status')) { $this->container->get(Routes::class)->post('/mako.toolbar/opcache/reset', [OPcache::class, 'reset'], 'mako.toolbar.opcache.reset'); } } diff --git a/src/panels/ConfigPanel.php b/src/panels/ConfigPanel.php index 62327c7..2a1ad92 100644 --- a/src/panels/ConfigPanel.php +++ b/src/panels/ConfigPanel.php @@ -31,8 +31,7 @@ public function __construct( ViewFactory $view, protected Config $config, protected ?string $environment = null - ) - { + ) { parent::__construct($view); } @@ -49,8 +48,7 @@ public function getTabLabel(): string */ protected function expandKey(array $config, string $key): array { - if(strpos($key, '*') === false) - { + if (strpos($key, '*') === false) { return [$key]; } @@ -64,14 +62,10 @@ protected function maskValues(array $config): array { $mask = $this->config->get('mako-toolbar::config.config.mask'); - if(!empty($mask) && is_array($mask)) - { - foreach($mask as $key) - { - foreach($this->expandKey($config, $key) as $key) - { - if(($value = Arr::get($config, $key)) !== null) - { + if (!empty($mask) && is_array($mask)) { + foreach ($mask as $key) { + foreach ($this->expandKey($config, $key) as $key) { + if (($value = Arr::get($config, $key)) !== null) { Arr::set($config, $key, is_string($value) ? Str::mask($value) : '******'); } } @@ -86,8 +80,7 @@ protected function maskValues(array $config): array */ public function render(): string { - $view = $this->view->create('mako-toolbar::panels.config', - [ + $view = $this->view->create('mako-toolbar::panels.config', [ 'config' => $this->maskValues($this->config->getLoadedConfiguration()), 'environment' => $this->environment, 'dump' => $this->getDumper(), diff --git a/src/panels/DatabasePanel.php b/src/panels/DatabasePanel.php index 6555a5c..bcc0f5b 100644 --- a/src/panels/DatabasePanel.php +++ b/src/panels/DatabasePanel.php @@ -29,8 +29,7 @@ class DatabasePanel extends Panel implements PanelInterface public function __construct( ViewFactory $view, protected ConnectionManager $database - ) - { + ) { parent::__construct($view); } @@ -55,8 +54,7 @@ public function getTotalQueryTime(): float */ public function getTabLabel(): string { - if(($totalQueries = $this->getTotalQueryCount()) === 0) - { + if (($totalQueries = $this->getTotalQueryCount()) === 0) { return sprintf('%u database queries', $totalQueries); } @@ -70,8 +68,7 @@ protected function getFormattedLog(array $logs): array { // Configure the SQL highlighter - $highlighter = new HtmlHighlighter - ([ + $highlighter = new HtmlHighlighter([ HtmlHighlighter::HIGHLIGHT_PRE => 'style="color: inherit; background-color: transparent;"', ]); @@ -79,10 +76,8 @@ protected function getFormattedLog(array $logs): array $formatter = new SqlFormatter($highlighter); - foreach($logs as &$log) - { - foreach($log as $key => $query) - { + foreach ($logs as &$log) { + foreach ($log as $key => $query) { $log[$key]['query'] = $formatter->format($query['query']); } } @@ -95,8 +90,7 @@ protected function getFormattedLog(array $logs): array */ public function render(): string { - $view = $this->view->create('mako-toolbar::panels.database', - [ + $view = $this->view->create('mako-toolbar::panels.database', [ 'logs' => $this->getFormattedLog($this->database->getLogs()), ]); diff --git a/src/panels/IncludedFilesPanel.php b/src/panels/IncludedFilesPanel.php index ef2e8d1..f4b896e 100644 --- a/src/panels/IncludedFilesPanel.php +++ b/src/panels/IncludedFilesPanel.php @@ -30,8 +30,7 @@ class IncludedFilesPanel extends Panel implements PanelInterface */ protected function getIncludedFiles(): array { - if(empty($this->files)) - { + if (empty($this->files)) { $this->files = get_included_files(); } @@ -51,8 +50,7 @@ public function getTabLabel(): string */ public function render(): string { - $view = $this->view->create('mako-toolbar::panels.included_files', - [ + $view = $this->view->create('mako-toolbar::panels.included_files', [ 'files' => $this->getIncludedFiles(), 'dump' => $this->getDumper(), ]); diff --git a/src/panels/MonologPanel.php b/src/panels/MonologPanel.php index cd38436..93f59c8 100644 --- a/src/panels/MonologPanel.php +++ b/src/panels/MonologPanel.php @@ -27,8 +27,7 @@ class MonologPanel extends Panel implements PanelInterface public function __construct( ViewFactory $view, protected MonologHandler $monologHandler - ) - { + ) { parent::__construct($view); } @@ -45,10 +44,8 @@ public function getTabLabel(): string */ protected function getLevelHelper(): Closure { - return static function (int $level): string - { - return match($level) - { + return static function (int $level): string { + return match ($level) { 100 => 'debug', 200 => 'info', 250 => 'notice', @@ -67,8 +64,7 @@ protected function getLevelHelper(): Closure */ public function render(): string { - $view = $this->view->create('mako-toolbar::panels.monolog', - [ + $view = $this->view->create('mako-toolbar::panels.monolog', [ 'entries' => $this->monologHandler->getEntries(), 'level_helper' => $this->getLevelHelper(), 'dump' => $this->getDumper(), diff --git a/src/panels/OPcachePanel.php b/src/panels/OPcachePanel.php index 1b9e7ac..7769553 100644 --- a/src/panels/OPcachePanel.php +++ b/src/panels/OPcachePanel.php @@ -26,8 +26,7 @@ class OPcachePanel extends Panel implements PanelInterface public function __construct( ViewFactory $view, protected URLBuilder $urlBuilder - ) - { + ) { parent::__construct($view); } @@ -44,8 +43,7 @@ public function getTabLabel(): string */ public function render(): string { - return $this->view->render('mako-toolbar::panels.opcache', - [ + return $this->view->render('mako-toolbar::panels.opcache', [ 'dump' => $this->getDumper(), 'status' => opcache_get_status(), 'url' => $this->urlBuilder, diff --git a/src/panels/RequestPanel.php b/src/panels/RequestPanel.php index 8d9fb6a..96c4c5d 100644 --- a/src/panels/RequestPanel.php +++ b/src/panels/RequestPanel.php @@ -24,8 +24,7 @@ class RequestPanel extends Panel implements PanelInterface public function __construct( ViewFactory $view, protected Request $request - ) - { + ) { parent::__construct($view); } @@ -42,12 +41,10 @@ public function getTabLabel(): string */ public function render(): string { - $view = $this->view->create('mako-toolbar::panels.request', - [ + $view = $this->view->create('mako-toolbar::panels.request', [ 'request' => $this->request, 'dump' => $this->getDumper(), - 'superglobals' => - [ + 'superglobals' => [ 'GET parameters' => &$_GET, 'POST parameters' => &$_POST, 'Cookies' => &$_COOKIE, diff --git a/src/panels/ResponsePanel.php b/src/panels/ResponsePanel.php index bf64b75..c857cf6 100644 --- a/src/panels/ResponsePanel.php +++ b/src/panels/ResponsePanel.php @@ -24,8 +24,7 @@ class ResponsePanel extends Panel implements PanelInterface public function __construct( ViewFactory $view, protected Response $response - ) - { + ) { parent::__construct($view); } @@ -46,8 +45,7 @@ public function render(): string [ 'response' => $this->response, 'dump' => $this->getDumper(), - 'data' => - [ + 'data' => [ 'Headers' => $this->response->getHeaders(), 'Cookies' => $this->response->getCookies(), ], diff --git a/src/panels/SessionPanel.php b/src/panels/SessionPanel.php index 1b4eb2e..f177442 100644 --- a/src/panels/SessionPanel.php +++ b/src/panels/SessionPanel.php @@ -24,8 +24,7 @@ class SessionPanel extends Panel implements PanelInterface public function __construct( ViewFactory $view, protected Session $session - ) - { + ) { parent::__construct($view); } @@ -42,8 +41,7 @@ public function getTabLabel(): string */ public function render(): string { - $view = $this->view->create('mako-toolbar::panels.session', - [ + $view = $this->view->create('mako-toolbar::panels.session', [ 'id' => $this->session->getId(), 'data' => $this->session->getData(), 'dump' => $this->getDumper(), diff --git a/src/panels/traits/DumperTrait.php b/src/panels/traits/DumperTrait.php index b05e178..09f3e9d 100644 --- a/src/panels/traits/DumperTrait.php +++ b/src/panels/traits/DumperTrait.php @@ -21,8 +21,7 @@ trait DumperTrait */ protected function styleDumper(HtmlDumper $dumper): void { - $styles = - [ + $styles = [ 'default' => 'background-color:transparent; color:#91CDA4; line-height:1.2em; font:14px Menlo, Monaco, Consolas, monospace; word-wrap: break-word; white-space: pre-wrap; position:relative; z-index:99999; word-break: normal', 'num' => 'font-weight:normal; color:#666', 'const' => 'font-weight:bold', @@ -50,8 +49,7 @@ protected function getDumper(): Closure $this->styleDumper($dumper); - return function ($variable) use ($dumper): void - { + return function ($variable) use ($dumper): void { $dumper->dump((new VarCloner)->cloneVar($variable)); }; }