Skip to content

Commit

Permalink
perf(bootstrapper): Optimize sprintf usage
Browse files Browse the repository at this point in the history
- Replace all instances of sprintf with \sprintf for consistency.
- Ensures better performance and adherence to PHP best practices.
- This change affects Bootstrapper, OutputManager, and ConsoleOutput classes.
  • Loading branch information
guanguans committed Aug 16, 2024
1 parent 993c8cd commit 1e88f7e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Bootstrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function getScores(): Collection
$query = $this->matchQuery(self::$queries, $score);

return [
'Summary' => sprintf(
'Summary' => \sprintf(
'[%s|%d分|%s|%s]',
$star = to_star($score['Score']),
$score['Score'],
Expand Down Expand Up @@ -152,7 +152,7 @@ protected function getBacktraces(int $limit = 0, int $forgetLines = 0): array
static fn ($trace): bool => isset($trace['file'], $trace['line'])
&& ! Str::contains($trace['file'], 'vendor')
)
->map(static fn ($trace, $index): string => sprintf(
->map(static fn ($trace, $index): string => \sprintf(
'#%s %s:%s',
$index,
str_replace(base_path(), '', $trace['file']),
Expand Down
2 changes: 1 addition & 1 deletion src/OutputManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function output(Collection $scores, $dispatcher): void
public function offsetSet($offset, $value): void
{
if (! $value instanceof Output) {
throw new InvalidArgumentException(sprintf('The value must be instance of %s', Output::class));
throw new InvalidArgumentException(\sprintf('The value must be instance of %s', Output::class));
}

$this->attributes[$offset] = $value;
Expand Down
2 changes: 1 addition & 1 deletion src/Outputs/ConsoleOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function output(Collection $scores, $dispatcher): void
*/
protected function toJavascript(Collection $scores): string
{
return sprintf(
return \sprintf(
'<script type="text/javascript">console.%s(`%s`);</script>',
$this->method,
str_replace('`', '\`', $this->hydrateScores($scores)),
Expand Down

0 comments on commit 1e88f7e

Please sign in to comment.