From 1e88f7e3c4999ec353302ccbd4b50664d7728aae Mon Sep 17 00:00:00 2001 From: guanguans Date: Fri, 16 Aug 2024 16:32:15 +0800 Subject: [PATCH] perf(bootstrapper): Optimize sprintf usage - 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. --- src/Bootstrapper.php | 4 ++-- src/OutputManager.php | 2 +- src/Outputs/ConsoleOutput.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Bootstrapper.php b/src/Bootstrapper.php index f9dd9a0..870f074 100644 --- a/src/Bootstrapper.php +++ b/src/Bootstrapper.php @@ -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'], @@ -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']), diff --git a/src/OutputManager.php b/src/OutputManager.php index e62cd8c..70567a0 100644 --- a/src/OutputManager.php +++ b/src/OutputManager.php @@ -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; diff --git a/src/Outputs/ConsoleOutput.php b/src/Outputs/ConsoleOutput.php index 64f03b1..359de23 100644 --- a/src/Outputs/ConsoleOutput.php +++ b/src/Outputs/ConsoleOutput.php @@ -47,7 +47,7 @@ public function output(Collection $scores, $dispatcher): void */ protected function toJavascript(Collection $scores): string { - return sprintf( + return \sprintf( '', $this->method, str_replace('`', '\`', $this->hydrateScores($scores)),