Skip to content

Commit

Permalink
Prefix all sprintf() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Jun 20, 2024
1 parent 9dab38d commit e6d23df
Show file tree
Hide file tree
Showing 29 changed files with 103 additions and 103 deletions.
2 changes: 1 addition & 1 deletion AssetMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function allAssets(): iterable
foreach ($this->mapperRepository->all() as $logicalPath => $filePath) {
$asset = $this->getAsset($logicalPath);
if (null === $asset) {
throw new \LogicException(sprintf('Asset "%s" could not be found.', $logicalPath));
throw new \LogicException(\sprintf('Asset "%s" could not be found.', $logicalPath));
}
yield $asset;
}
Expand Down
2 changes: 1 addition & 1 deletion AssetMapperDevServerSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function onKernelRequest(RequestEvent $event): void
$asset = $this->findAssetFromCache($pathInfo);

if (!$asset) {
throw new NotFoundHttpException(sprintf('Asset with public path "%s" not found.', $pathInfo));
throw new NotFoundHttpException(\sprintf('Asset with public path "%s" not found.', $pathInfo));
}

$this->profiler?->disable();
Expand Down
4 changes: 2 additions & 2 deletions AssetMapperRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private function getDirectories(): array
foreach ($this->paths as $path => $namespace) {
if ($filesystem->isAbsolutePath($path)) {
if (!file_exists($path) && $this->debug) {
throw new \InvalidArgumentException(sprintf('The asset mapper directory "%s" does not exist.', $path));
throw new \InvalidArgumentException(\sprintf('The asset mapper directory "%s" does not exist.', $path));
}
$this->absolutePaths[realpath($path)] = $namespace;

Expand All @@ -163,7 +163,7 @@ private function getDirectories(): array
}

if ($this->debug) {
throw new \InvalidArgumentException(sprintf('The asset mapper directory "%s" does not exist.', $path));
throw new \InvalidArgumentException(\sprintf('The asset mapper directory "%s" does not exist.', $path));
}
}

Expand Down
16 changes: 8 additions & 8 deletions Command/AssetMapperCompileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,26 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->compiledConfigReader->removeConfig(ImportMapGenerator::IMPORT_MAP_CACHE_FILENAME);
$entrypointFiles = [];
foreach ($this->importMapGenerator->getEntrypointNames() as $entrypointName) {
$path = sprintf(ImportMapGenerator::ENTRYPOINT_CACHE_FILENAME_PATTERN, $entrypointName);
$path = \sprintf(ImportMapGenerator::ENTRYPOINT_CACHE_FILENAME_PATTERN, $entrypointName);
$this->compiledConfigReader->removeConfig($path);
$entrypointFiles[$entrypointName] = $path;
}

$manifest = $this->createManifestAndWriteFiles($io);
$manifestPath = $this->compiledConfigReader->saveConfig(AssetMapper::MANIFEST_FILE_NAME, $manifest);
$io->comment(sprintf('Manifest written to <info>%s</info>', $this->shortenPath($manifestPath)));
$io->comment(\sprintf('Manifest written to <info>%s</info>', $this->shortenPath($manifestPath)));

$importMapPath = $this->compiledConfigReader->saveConfig(ImportMapGenerator::IMPORT_MAP_CACHE_FILENAME, $this->importMapGenerator->getRawImportMapData());
$io->comment(sprintf('Import map data written to <info>%s</info>.', $this->shortenPath($importMapPath)));
$io->comment(\sprintf('Import map data written to <info>%s</info>.', $this->shortenPath($importMapPath)));

foreach ($entrypointFiles as $entrypointName => $path) {
$this->compiledConfigReader->saveConfig($path, $this->importMapGenerator->findEagerEntrypointImports($entrypointName));
}
$styledEntrypointNames = array_map(fn (string $entrypointName) => sprintf('<info>%s</>', $entrypointName), array_keys($entrypointFiles));
$io->comment(sprintf('Entrypoint metadata written for <comment>%d</> entrypoints (%s).', \count($entrypointFiles), implode(', ', $styledEntrypointNames)));
$styledEntrypointNames = array_map(fn (string $entrypointName) => \sprintf('<info>%s</>', $entrypointName), array_keys($entrypointFiles));
$io->comment(\sprintf('Entrypoint metadata written for <comment>%d</> entrypoints (%s).', \count($entrypointFiles), implode(', ', $styledEntrypointNames)));

if ($this->isDebug) {
$io->warning(sprintf(
$io->warning(\sprintf(
'Debug mode is enabled in your project: Symfony will not serve any changed assets until you delete the files in the "%s" directory again.',
$this->shortenPath(\dirname($manifestPath))
));
Expand All @@ -104,7 +104,7 @@ private function shortenPath(string $path): string

private function createManifestAndWriteFiles(SymfonyStyle $io): array
{
$io->comment(sprintf('Compiling and writing asset files to <info>%s</info>', $this->shortenPath($this->assetsFilesystem->getDestinationPath())));
$io->comment(\sprintf('Compiling and writing asset files to <info>%s</info>', $this->shortenPath($this->assetsFilesystem->getDestinationPath())));
$manifest = [];
foreach ($this->assetMapper->allAssets() as $asset) {
if (null !== $asset->content) {
Expand All @@ -117,7 +117,7 @@ private function createManifestAndWriteFiles(SymfonyStyle $io): array
$manifest[$asset->logicalPath] = $asset->publicPath;
}
ksort($manifest);
$io->comment(sprintf('Compiled <info>%d</info> assets', \count($manifest)));
$io->comment(\sprintf('Compiled <info>%d</info> assets', \count($manifest)));

return $manifest;
}
Expand Down
14 changes: 7 additions & 7 deletions Command/ImportMapAuditCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function configure(): void
$this->addOption(
name: 'format',
mode: InputOption::VALUE_REQUIRED,
description: sprintf('The output format ("%s")', implode(', ', $this->getAvailableFormatOptions())),
description: \sprintf('The output format ("%s")', implode(', ', $this->getAvailableFormatOptions())),
default: 'txt',
);
}
Expand All @@ -63,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return match ($format) {
'txt' => $this->displayTxt($audit),
'json' => $this->displayJson($audit),
default => throw new \InvalidArgumentException(sprintf('Supported formats are "%s".', implode('", "', $this->getAvailableFormatOptions()))),
default => throw new \InvalidArgumentException(\sprintf('Supported formats are "%s".', implode('", "', $this->getAvailableFormatOptions()))),
};
}

Expand All @@ -79,7 +79,7 @@ private function displayTxt(array $audit): int
}
foreach ($packageAudit->vulnerabilities as $vulnerability) {
$rows[] = [
sprintf('<fg=%s>%s</>', self::SEVERITY_COLORS[$vulnerability->severity] ?? 'default', ucfirst($vulnerability->severity)),
\sprintf('<fg=%s>%s</>', self::SEVERITY_COLORS[$vulnerability->severity] ?? 'default', ucfirst($vulnerability->severity)),
$vulnerability->summary,
$packageAudit->package,
$packageAudit->version ?? 'n/a',
Expand Down Expand Up @@ -113,15 +113,15 @@ private function displayTxt(array $audit): int
$this->io->newLine();
}

$this->io->text(sprintf('%d package%s found: %d audited / %d skipped',
$this->io->text(\sprintf('%d package%s found: %d audited / %d skipped',
$packagesCount,
1 === $packagesCount ? '' : 's',
$packagesCount - $packagesWithoutVersionCount,
$packagesWithoutVersionCount,
));

if (0 < $packagesWithoutVersionCount) {
$this->io->warning(sprintf('Unable to retrieve versions for package%s: %s',
$this->io->warning(\sprintf('Unable to retrieve versions for package%s: %s',
1 === $packagesWithoutVersionCount ? '' : 's',
implode(', ', $packagesWithoutVersion)
));
Expand All @@ -134,10 +134,10 @@ private function displayTxt(array $audit): int
if (!$count) {
continue;
}
$vulnerabilitySummary[] = sprintf('%d %s', $count, ucfirst($severity));
$vulnerabilitySummary[] = \sprintf('%d %s', $count, ucfirst($severity));
$vulnerabilityCount += $count;
}
$this->io->text(sprintf('%d vulnerabilit%s found: %s',
$this->io->text(\sprintf('%d vulnerabilit%s found: %s',
$vulnerabilityCount,
1 === $vulnerabilityCount ? 'y' : 'ies',
implode(' / ', $vulnerabilitySummary),
Expand Down
2 changes: 1 addition & 1 deletion Command/ImportMapInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return Command::SUCCESS;
}

$io->success(sprintf(
$io->success(\sprintf(
'Downloaded %d package%s into %s.',
\count($downloadedPackages),
1 === \count($downloadedPackages) ? '' : 's',
Expand Down
6 changes: 3 additions & 3 deletions Command/ImportMapOutdatedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function configure(): void
->addOption(
name: 'format',
mode: InputOption::VALUE_REQUIRED,
description: sprintf('The output format ("%s")', implode(', ', $this->getAvailableFormatOptions())),
description: \sprintf('The output format ("%s")', implode(', ', $this->getAvailableFormatOptions())),
default: 'txt',
)
->setHelp(<<<'EOT'
Expand Down Expand Up @@ -88,9 +88,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
foreach ($displayData as $datum) {
$color = self::COLOR_MAPPING[$datum['latest-status']] ?? 'default';
$table->addRow([
sprintf('<fg=%s>%s</>', $color, $datum['name']),
\sprintf('<fg=%s>%s</>', $color, $datum['name']),
$datum['current'],
sprintf('<fg=%s>%s</>', $color, $datum['latest']),
\sprintf('<fg=%s>%s</>', $color, $datum['latest']),
]);
}
$table->render();
Expand Down
4 changes: 2 additions & 2 deletions Command/ImportMapRemoveCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->importMapManager->remove($packageList);

if (1 === \count($packageList)) {
$io->success(sprintf('Removed "%s" from importmap.php.', $packageList[0]));
$io->success(\sprintf('Removed "%s" from importmap.php.', $packageList[0]));
} else {
$io->success(sprintf('Removed %d items from importmap.php.', \count($packageList)));
$io->success(\sprintf('Removed %d items from importmap.php.', \count($packageList)));
}

return Command::SUCCESS;
Expand Down
8 changes: 4 additions & 4 deletions Command/ImportMapRequireCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
foreach ($packageList as $packageName) {
$parts = ImportMapManager::parsePackageName($packageName);
if (null === $parts) {
$io->error(sprintf('Package "%s" is not a valid package name format. Use the format PACKAGE@VERSION - e.g. "lodash" or "lodash@^4"', $packageName));
$io->error(\sprintf('Package "%s" is not a valid package name format. Use the format PACKAGE@VERSION - e.g. "lodash" or "lodash@^4"', $packageName));

return Command::FAILURE;
}
Expand All @@ -116,18 +116,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int

if (1 === \count($newPackages)) {
$newPackage = $newPackages[0];
$message = sprintf('Package "%s" added to importmap.php', $newPackage->importName);
$message = \sprintf('Package "%s" added to importmap.php', $newPackage->importName);

$message .= '.';
} else {
$names = array_map(fn (ImportMapEntry $package) => $package->importName, $newPackages);
$message = sprintf('%d new items (%s) added to the importmap.php!', \count($newPackages), implode(', ', $names));
$message = \sprintf('%d new items (%s) added to the importmap.php!', \count($newPackages), implode(', ', $names));
}

$messages = [$message];

if (1 === \count($newPackages)) {
$messages[] = sprintf('Use the new package normally by importing "%s".', $newPackages[0]->importName);
$messages[] = \sprintf('Use the new package normally by importing "%s".', $newPackages[0]->importName);
}

$io->success($messages);
Expand Down
2 changes: 1 addition & 1 deletion Command/ImportMapUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->renderVersionProblems($this->importMapVersionChecker, $output);

if (0 < \count($packages)) {
$io->success(sprintf(
$io->success(\sprintf(
'Updated %s package%s in importmap.php.',
implode(', ', array_map(static fn (ImportMapEntry $entry): string => $entry->importName, $updatedPackages)),
1 < \count($updatedPackages) ? 's' : '',
Expand Down
4 changes: 2 additions & 2 deletions Command/VersionProblemCommandTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ private function renderVersionProblems(ImportMapVersionChecker $importMapVersion
$problems = $importMapVersionChecker->checkVersions();
foreach ($problems as $problem) {
if (null === $problem->installedVersion) {
$output->writeln(sprintf('[warning] <info>%s</info> requires <info>%s</info> but it is not in the importmap.php. You may need to run "php bin/console importmap:require %s".', $problem->packageName, $problem->dependencyPackageName, $problem->dependencyPackageName));
$output->writeln(\sprintf('[warning] <info>%s</info> requires <info>%s</info> but it is not in the importmap.php. You may need to run "php bin/console importmap:require %s".', $problem->packageName, $problem->dependencyPackageName, $problem->dependencyPackageName));

continue;
}

$output->writeln(sprintf('[warning] <info>%s</info> requires <info>%s</info>@<comment>%s</comment> but version <comment>%s</comment> is installed.', $problem->packageName, $problem->dependencyPackageName, $problem->requiredVersionConstraint, $problem->installedVersion));
$output->writeln(\sprintf('[warning] <info>%s</info> requires <info>%s</info>@<comment>%s</comment> but version <comment>%s</comment> is installed.', $problem->packageName, $problem->dependencyPackageName, $problem->requiredVersionConstraint, $problem->installedVersion));
}
}
}
4 changes: 2 additions & 2 deletions Compiler/CssAssetUrlCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public function compile(string $content, MappedAsset $asset, AssetMapperInterfac
try {
$resolvedSourcePath = Path::join(\dirname($asset->sourcePath), $matches[1]);
} catch (RuntimeException $e) {
$this->handleMissingImport(sprintf('Error processing import in "%s": ', $asset->sourcePath).$e->getMessage(), $e);
$this->handleMissingImport(\sprintf('Error processing import in "%s": ', $asset->sourcePath).$e->getMessage(), $e);

return $matches[0];
}
$dependentAsset = $assetMapper->getAssetFromSourcePath($resolvedSourcePath);

if (null === $dependentAsset) {
$message = sprintf('Unable to find asset "%s" referenced in "%s". The file "%s" ', $matches[1], $asset->sourcePath, $resolvedSourcePath);
$message = \sprintf('Unable to find asset "%s" referenced in "%s". The file "%s" ', $matches[1], $asset->sourcePath, $resolvedSourcePath);
if (is_file($resolvedSourcePath)) {
$message .= 'exists, but it is not in a mapped asset path. Add it to the "paths" config.';
} else {
Expand Down
12 changes: 6 additions & 6 deletions Compiler/JavaScriptImportPathCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function compile(string $content, MappedAsset $asset, AssetMapperInterfac
$relativeImportPath = $this->makeRelativeForJavaScript($relativeImportPath);

return str_replace($importedModule, $relativeImportPath, $fullImportString);
}, $content, -1, $count, \PREG_OFFSET_CAPTURE) ?? throw new RuntimeException(sprintf('Failed to compile JavaScript import paths in "%s". Error: "%s".', $asset->sourcePath, preg_last_error_msg()));
}, $content, -1, $count, \PREG_OFFSET_CAPTURE) ?? throw new RuntimeException(\sprintf('Failed to compile JavaScript import paths in "%s". Error: "%s".', $asset->sourcePath, preg_last_error_msg()));
}

public function supports(MappedAsset $asset): bool
Expand Down Expand Up @@ -194,7 +194,7 @@ private function findAssetForRelativeImport(string $importedModule, MappedAsset
} catch (RuntimeException $e) {
// avoid warning about vendor imports - these are often comments
if (!$asset->isVendor) {
$this->handleMissingImport(sprintf('Error processing import in "%s": ', $asset->sourcePath).$e->getMessage(), $e);
$this->handleMissingImport(\sprintf('Error processing import in "%s": ', $asset->sourcePath).$e->getMessage(), $e);
}

return null;
Expand All @@ -215,14 +215,14 @@ private function findAssetForRelativeImport(string $importedModule, MappedAsset
return null;
}

$message = sprintf('Unable to find asset "%s" imported from "%s".', $importedModule, $asset->sourcePath);
$message = \sprintf('Unable to find asset "%s" imported from "%s".', $importedModule, $asset->sourcePath);

if (is_file($resolvedSourcePath)) {
$message .= sprintf('The file "%s" exists, but it is not in a mapped asset path. Add it to the "paths" config.', $resolvedSourcePath);
$message .= \sprintf('The file "%s" exists, but it is not in a mapped asset path. Add it to the "paths" config.', $resolvedSourcePath);
} else {
try {
if (null !== $assetMapper->getAssetFromSourcePath(sprintf('%s.js', $resolvedSourcePath))) {
$message .= sprintf(' Try adding ".js" to the end of the import - i.e. "%s.js".', $importedModule);
if (null !== $assetMapper->getAssetFromSourcePath(\sprintf('%s.js', $resolvedSourcePath))) {
$message .= \sprintf(' Try adding ".js" to the end of the import - i.e. "%s.js".', $importedModule);
}
} catch (CircularAssetsException) {
// avoid circular error if there is self-referencing import comments
Expand Down
4 changes: 2 additions & 2 deletions Factory/MappedAssetFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(
public function createMappedAsset(string $logicalPath, string $sourcePath): ?MappedAsset
{
if (isset($this->assetsBeingCreated[$logicalPath])) {
throw new CircularAssetsException($this->assetsCache[$logicalPath], sprintf('Circular reference detected while creating asset for "%s": "%s".', $logicalPath, implode(' -> ', $this->assetsBeingCreated).' -> '.$logicalPath));
throw new CircularAssetsException($this->assetsCache[$logicalPath], \sprintf('Circular reference detected while creating asset for "%s": "%s".', $logicalPath, implode(' -> ', $this->assetsBeingCreated).' -> '.$logicalPath));
}
$this->assetsBeingCreated[$logicalPath] = $logicalPath;

Expand Down Expand Up @@ -98,7 +98,7 @@ private function getDigest(MappedAsset $asset, ?string $content): array
private function compileContent(MappedAsset $asset): ?string
{
if (!is_file($asset->sourcePath)) {
throw new RuntimeException(sprintf('Asset source path "%s" could not be found.', $asset->sourcePath));
throw new RuntimeException(\sprintf('Asset source path "%s" could not be found.', $asset->sourcePath));
}

if (!$this->compiler->supports($asset)) {
Expand Down
2 changes: 1 addition & 1 deletion ImportMap/ImportMapAuditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function audit(): array
]);

if (200 !== $response->getStatusCode()) {
throw new RuntimeException(sprintf('Error %d auditing packages. Response: '.$response->getContent(false), $response->getStatusCode()));
throw new RuntimeException(\sprintf('Error %d auditing packages. Response: '.$response->getContent(false), $response->getStatusCode()));
}

foreach ($response->toArray() as $advisory) {
Expand Down
Loading

0 comments on commit e6d23df

Please sign in to comment.