Skip to content

Commit ba2e329

Browse files
authored
Use optimized sprintf (#46)
1 parent dc5e38d commit ba2e329

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

src/AssetMapper/TypeScriptCompiler.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function supports(MappedAsset $asset): bool
3434
foreach ($this->typeScriptFilesPaths as $path) {
3535
$realTypeScriptPath = realpath($path);
3636
if (false === $realTypeScriptPath) {
37-
throw new \Exception(sprintf('The TypeScript directory "%s" does not exist', $path));
37+
throw new \Exception(\sprintf('The TypeScript directory "%s" does not exist', $path));
3838
}
3939
// If the asset matches one of the TypeScript files source paths
4040
if ($realSourcePath === $realTypeScriptPath) {
@@ -46,19 +46,19 @@ public function supports(MappedAsset $asset): bool
4646
}
4747
}
4848

49-
throw new \Exception(sprintf('The TypeScript file "%s" is not in the TypeScript files paths. Check the asset path or your "sensiolabs_typescript.source_dir" in your config', $realSourcePath));
49+
throw new \Exception(\sprintf('The TypeScript file "%s" is not in the TypeScript files paths. Check the asset path or your "sensiolabs_typescript.source_dir" in your config', $realSourcePath));
5050
}
5151

5252
public function compile(string $content, MappedAsset $asset, AssetMapperInterface $assetMapper): string
5353
{
5454
$realSourcePath = realpath($asset->sourcePath);
5555
if (false === $realSourcePath) {
56-
throw new \Exception(sprintf('The TypeScript file "%s" does not exist', $asset->sourcePath));
56+
throw new \Exception(\sprintf('The TypeScript file "%s" does not exist', $asset->sourcePath));
5757
}
5858
foreach ($this->typeScriptFilesPaths as $typeScriptFilesPath) {
5959
$realTypeScriptPath = realpath($typeScriptFilesPath);
6060
if (false === $realTypeScriptPath) {
61-
throw new \Exception(sprintf('The TypeScript directory "%s" does not exist', $typeScriptFilesPath));
61+
throw new \Exception(\sprintf('The TypeScript directory "%s" does not exist', $typeScriptFilesPath));
6262
}
6363
if (str_starts_with($realSourcePath, $realTypeScriptPath)) {
6464
$fileName = basename($realSourcePath, '.ts');
@@ -69,7 +69,7 @@ public function compile(string $content, MappedAsset $asset, AssetMapperInterfac
6969
}
7070

7171
if (!isset($jsFile)) {
72-
throw new \Exception(sprintf('The TypeScript file "%s" is not in the TypeScript files paths. Check the asset path or your "sensiolabs_typescript.source_dir" in your config', $asset->sourcePath));
72+
throw new \Exception(\sprintf('The TypeScript file "%s" is not in the TypeScript files paths. Check the asset path or your "sensiolabs_typescript.source_dir" in your config', $asset->sourcePath));
7373
}
7474
$asset->addFileDependency($jsFile);
7575

src/Tools/TypeScriptBinary.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public function __construct(
1010
private readonly string $pathToExecutable,
1111
) {
1212
if (!file_exists($this->pathToExecutable)) {
13-
throw new \Exception(sprintf('The Typescript binary could not be found at the provided path : "%s"', $this->pathToExecutable));
13+
throw new \Exception(\sprintf('The Typescript binary could not be found at the provided path : "%s"', $this->pathToExecutable));
1414
}
1515
}
1616

src/Tools/TypeScriptBinaryFactory.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static function getBinaryNameFromServerSpecs(
6464
return 'swc-darwin-x64';
6565
}
6666

67-
throw new \Exception(sprintf('No matching machine found for Darwin platform (Machine: %s).', $machine));
67+
throw new \Exception(\sprintf('No matching machine found for Darwin platform (Machine: %s).', $machine));
6868
}
6969

7070
if (str_contains($os, 'linux')) {
@@ -76,7 +76,7 @@ public static function getBinaryNameFromServerSpecs(
7676
return 'swc-linux-x64-'.$kernelVersion;
7777
}
7878

79-
throw new \Exception(sprintf('No matching machine found for Linux platform (Machine: %s).', $machine));
79+
throw new \Exception(\sprintf('No matching machine found for Linux platform (Machine: %s).', $machine));
8080
}
8181

8282
if (str_contains($os, 'win')) {
@@ -90,10 +90,10 @@ public static function getBinaryNameFromServerSpecs(
9090
return 'swc-win32-ia32-msvc.exe';
9191
}
9292

93-
throw new \Exception(sprintf('No matching machine found for Windows platform (Machine: %s).', $machine));
93+
throw new \Exception(\sprintf('No matching machine found for Windows platform (Machine: %s).', $machine));
9494
}
9595

96-
throw new \Exception(sprintf('Unknown platform or architecture (OS: %s, Machine: %s).', $os, $machine));
96+
throw new \Exception(\sprintf('Unknown platform or architecture (OS: %s, Machine: %s).', $os, $machine));
9797
}
9898

9999
private function downloadAndExtract(string $binaryName): void
@@ -105,10 +105,10 @@ private function downloadAndExtract(string $binaryName): void
105105
if (file_exists($targetPath)) {
106106
return;
107107
}
108-
$url = sprintf(self::SWC_RELEASE_URL_PATTERN, self::VERSION, $binaryName);
108+
$url = \sprintf(self::SWC_RELEASE_URL_PATTERN, self::VERSION, $binaryName);
109109

110110
if ($this->output->isVerbose()) {
111-
$this->output->note(sprintf('Downloading SWC binary from "%s" to "%s"...', $url, $targetPath));
111+
$this->output->note(\sprintf('Downloading SWC binary from "%s" to "%s"...', $url, $targetPath));
112112
} else {
113113
$this->output->note('Downloading SWC binary ...');
114114
}
@@ -128,7 +128,7 @@ private function downloadAndExtract(string $binaryName): void
128128
]);
129129
$fileHandler = fopen($targetPath, 'w');
130130
if (false === $fileHandler) {
131-
throw new \Exception(sprintf('Could not open file "%s" for writing.', $targetPath));
131+
throw new \Exception(\sprintf('Could not open file "%s" for writing.', $targetPath));
132132
}
133133
foreach ($this->httpClient->stream($response) as $chunk) {
134134
fwrite($fileHandler, $chunk->getContent());

src/Tools/WatcherBinaryFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public function getBinaryFromServerSpecs(string $os): WatcherBinary
99
$binaryName = self::getBinaryNameFromServerSpecs($os);
1010
$binaryPath = __DIR__.'/watcher/'.$binaryName;
1111
if (!file_exists($binaryPath)) {
12-
throw new \Exception(sprintf('The watcher binary could not be found at the provided path : "%s"', $binaryPath));
12+
throw new \Exception(\sprintf('The watcher binary could not be found at the provided path : "%s"', $binaryPath));
1313
}
1414

1515
return new WatcherBinary($binaryPath);
@@ -28,6 +28,6 @@ public static function getBinaryNameFromServerSpecs(string $os): string
2828
return 'watcher-windows.exe';
2929
}
3030

31-
throw new \Exception(sprintf('Unknown platform or architecture (OS: %s).', $os));
31+
throw new \Exception(\sprintf('Unknown platform or architecture (OS: %s).', $os));
3232
}
3333
}

src/TypeScriptBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ private function createBuildProcess(string $path, bool $watch = false): Process
4242
$fs = new Filesystem();
4343
$relativePath = rtrim($fs->makePathRelative($path, $this->projectRootDir), '/');
4444
if (str_starts_with($relativePath, '..')) {
45-
throw new \Exception(sprintf('The TypeScript file "%s" is not in the project directory "%s".', $path, $this->projectRootDir));
45+
throw new \Exception(\sprintf('The TypeScript file "%s" is not in the project directory "%s".', $path, $this->projectRootDir));
4646
}
4747
if ($this->configFile && file_exists($this->configFile)) {
4848
$args = array_merge($args, ['--config-file', trim($fs->makePathRelative($this->configFile, $this->projectRootDir), '/')]);
4949
}
5050
$buildProcess = $this->getBuildBinary()->createProcess(array_merge(['compile', $relativePath], $args));
5151
$buildProcess->setWorkingDirectory($this->projectRootDir);
5252

53-
$this->output->note(sprintf('Executing SWC compile on %s.', $relativePath));
53+
$this->output->note(\sprintf('Executing SWC compile on %s.', $relativePath));
5454
if ($this->output->isVerbose()) {
5555
$this->output->writeln([
5656
' Command:',

0 commit comments

Comments
 (0)