Skip to content

Commit

Permalink
Updated cs-fixer rules
Browse files Browse the repository at this point in the history
  • Loading branch information
freost committed Nov 23, 2023
1 parent dd9b343 commit 5d991a1
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 90 deletions.
2 changes: 2 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 6 additions & 10 deletions src/Toolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function __construct(
protected ViewFactory $view,
protected Humanizer $humanizer,
protected Application $application
)
{}
) {
}

/**
* Add a panel to the toolbar.
Expand Down Expand Up @@ -71,19 +71,16 @@ protected function calculateExecutionTime(): array

$otherTime = 0;

foreach($this->timers as $timer)
{
foreach ($this->timers as $timer) {
$otherTime += $timer instanceof Closure ? $timer() : $timer;
}

$detailedTime = $totalTime - $otherTime;

$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();
}

Expand All @@ -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(),
Expand Down
7 changes: 3 additions & 4 deletions src/ToolbarMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class ToolbarMiddleware implements MiddlewareInterface
*/
public function __construct(
protected Toolbar $toolbar
)
{}
) {
}

/**
* {@inheritDoc}
Expand All @@ -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('</body>', $this->toolbar->render() . '</body>', $body));
}

Expand Down
24 changes: 8 additions & 16 deletions src/ToolbarPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -76,27 +73,23 @@ 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);

$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)));
}

Expand All @@ -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');
}
}
Expand Down
21 changes: 7 additions & 14 deletions src/panels/ConfigPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public function __construct(
ViewFactory $view,
protected Config $config,
protected ?string $environment = null
)
{
) {
parent::__construct($view);
}

Expand All @@ -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];
}

Expand All @@ -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) : '******');
}
}
Expand All @@ -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(),
Expand Down
18 changes: 6 additions & 12 deletions src/panels/DatabasePanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ class DatabasePanel extends Panel implements PanelInterface
public function __construct(
ViewFactory $view,
protected ConnectionManager $database
)
{
) {
parent::__construct($view);
}

Expand All @@ -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);
}

Expand All @@ -70,19 +68,16 @@ 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;"',
]);

// Add syntax highlighting to SQL queries

$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']);
}
}
Expand All @@ -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()),
]);

Expand Down
6 changes: 2 additions & 4 deletions src/panels/IncludedFilesPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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(),
]);
Expand Down
12 changes: 4 additions & 8 deletions src/panels/MonologPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class MonologPanel extends Panel implements PanelInterface
public function __construct(
ViewFactory $view,
protected MonologHandler $monologHandler
)
{
) {
parent::__construct($view);
}

Expand All @@ -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',
Expand All @@ -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(),
Expand Down
6 changes: 2 additions & 4 deletions src/panels/OPcachePanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class OPcachePanel extends Panel implements PanelInterface
public function __construct(
ViewFactory $view,
protected URLBuilder $urlBuilder
)
{
) {
parent::__construct($view);
}

Expand All @@ -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,
Expand Down
9 changes: 3 additions & 6 deletions src/panels/RequestPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class RequestPanel extends Panel implements PanelInterface
public function __construct(
ViewFactory $view,
protected Request $request
)
{
) {
parent::__construct($view);
}

Expand All @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions src/panels/ResponsePanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class ResponsePanel extends Panel implements PanelInterface
public function __construct(
ViewFactory $view,
protected Response $response
)
{
) {
parent::__construct($view);
}

Expand All @@ -46,8 +45,7 @@ public function render(): string
[
'response' => $this->response,
'dump' => $this->getDumper(),
'data' =>
[
'data' => [
'Headers' => $this->response->getHeaders(),
'Cookies' => $this->response->getCookies(),
],
Expand Down
6 changes: 2 additions & 4 deletions src/panels/SessionPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class SessionPanel extends Panel implements PanelInterface
public function __construct(
ViewFactory $view,
protected Session $session
)
{
) {
parent::__construct($view);
}

Expand All @@ -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(),
Expand Down
Loading

0 comments on commit 5d991a1

Please sign in to comment.