Skip to content

Commit

Permalink
pref: replace helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
jiannei committed Jun 16, 2021
1 parent d8f79d5 commit 566514c
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 25 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
}
],
"require": {
"ext-json": "*"
"ext-json": "*",
"jiannei/helpers": "^0.1.1"
},
"require-dev": {
"orchestra/testbench": "^6.4",
Expand Down
2 changes: 1 addition & 1 deletion src/Listeners/RequestHandledListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function handle(RequestHandledEvent $event)
'response' => $event->response instanceof SymfonyResponse ? json_decode($event->response->getContent(), true) : (string) $event->response,
'start' => $start,
'end' => $end,
'duration' => formatDuration($end - $start),
'duration' => format_duration($end - $start),
];

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function logQuery()
$bindings = $query->connection->prepareBindings($query->bindings);
$pdo = $query->connection->getPdo();
$realSql = $sqlWithPlaceholders;
$duration = formatDuration($query->time / 1000);
$duration = format_duration($query->time / 1000);

if (count($bindings) > 0) {
$realSql = vsprintf($sqlWithPlaceholders, array_map([$pdo, 'quote'], $bindings));
Expand Down
22 changes: 0 additions & 22 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,3 @@ function logger_async(string $message, array $context = [])
return dispatch(new \Jiannei\Logger\Laravel\Jobs\LogJob($message, $context, request()->server()));
}
}

if (! function_exists('formatDuration')) {
/**
* Format duration.
*
* @param float $seconds
*
* @return string
*/
function formatDuration(float $seconds)
{
if ($seconds < 0.001) {
return round($seconds * 1000000).'μs';
}

if ($seconds < 1) {
return round($seconds * 1000, 2).'ms';
}

return round($seconds, 2).'s';
}
}

0 comments on commit 566514c

Please sign in to comment.