Skip to content

Commit d4f6891

Browse files
committed
Prefix all sprintf() calls
1 parent aaef070 commit d4f6891

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+186
-186
lines changed

Application.php

+18-18
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ public function doRun(InputInterface $input, OutputInterface $output): int
262262

263263
$style = new SymfonyStyle($input, $output);
264264
$output->writeln('');
265-
$formattedBlock = (new FormatterHelper())->formatBlock(sprintf('Command "%s" is not defined.', $name), 'error', true);
265+
$formattedBlock = (new FormatterHelper())->formatBlock(\sprintf('Command "%s" is not defined.', $name), 'error', true);
266266
$output->writeln($formattedBlock);
267-
if (!$style->confirm(sprintf('Do you want to run "%s" instead? ', $alternative), false)) {
267+
if (!$style->confirm(\sprintf('Do you want to run "%s" instead? ', $alternative), false)) {
268268
if (null !== $this->dispatcher) {
269269
$event = new ConsoleErrorEvent($input, $output, $e);
270270
$this->dispatcher->dispatch($event, ConsoleEvents::ERROR);
@@ -475,7 +475,7 @@ public function getLongVersion(): string
475475
{
476476
if ('UNKNOWN' !== $this->getName()) {
477477
if ('UNKNOWN' !== $this->getVersion()) {
478-
return sprintf('%s <info>%s</info>', $this->getName(), $this->getVersion());
478+
return \sprintf('%s <info>%s</info>', $this->getName(), $this->getVersion());
479479
}
480480

481481
return $this->getName();
@@ -530,7 +530,7 @@ public function add(Command $command): ?Command
530530
}
531531

532532
if (!$command->getName()) {
533-
throw new LogicException(sprintf('The command defined in "%s" cannot have an empty name.', get_debug_type($command)));
533+
throw new LogicException(\sprintf('The command defined in "%s" cannot have an empty name.', get_debug_type($command)));
534534
}
535535

536536
$this->commands[$command->getName()] = $command;
@@ -552,12 +552,12 @@ public function get(string $name): Command
552552
$this->init();
553553

554554
if (!$this->has($name)) {
555-
throw new CommandNotFoundException(sprintf('The command "%s" does not exist.', $name));
555+
throw new CommandNotFoundException(\sprintf('The command "%s" does not exist.', $name));
556556
}
557557

558558
// When the command has a different name than the one used at the command loader level
559559
if (!isset($this->commands[$name])) {
560-
throw new CommandNotFoundException(sprintf('The "%s" command cannot be found because it is registered under multiple names. Make sure you don\'t set a different name via constructor or "setName()".', $name));
560+
throw new CommandNotFoundException(\sprintf('The "%s" command cannot be found because it is registered under multiple names. Make sure you don\'t set a different name via constructor or "setName()".', $name));
561561
}
562562

563563
$command = $this->commands[$name];
@@ -621,7 +621,7 @@ public function findNamespace(string $namespace): string
621621
$namespaces = preg_grep('{^'.$expr.'}', $allNamespaces);
622622

623623
if (!$namespaces) {
624-
$message = sprintf('There are no commands defined in the "%s" namespace.', $namespace);
624+
$message = \sprintf('There are no commands defined in the "%s" namespace.', $namespace);
625625

626626
if ($alternatives = $this->findAlternatives($namespace, $allNamespaces)) {
627627
if (1 == \count($alternatives)) {
@@ -638,7 +638,7 @@ public function findNamespace(string $namespace): string
638638

639639
$exact = \in_array($namespace, $namespaces, true);
640640
if (\count($namespaces) > 1 && !$exact) {
641-
throw new NamespaceNotFoundException(sprintf("The namespace \"%s\" is ambiguous.\nDid you mean one of these?\n%s.", $namespace, $this->getAbbreviationSuggestions(array_values($namespaces))), array_values($namespaces));
641+
throw new NamespaceNotFoundException(\sprintf("The namespace \"%s\" is ambiguous.\nDid you mean one of these?\n%s.", $namespace, $this->getAbbreviationSuggestions(array_values($namespaces))), array_values($namespaces));
642642
}
643643

644644
return $exact ? $namespace : reset($namespaces);
@@ -685,7 +685,7 @@ public function find(string $name): Command
685685
$this->findNamespace(substr($name, 0, $pos));
686686
}
687687

688-
$message = sprintf('Command "%s" is not defined.', $name);
688+
$message = \sprintf('Command "%s" is not defined.', $name);
689689

690690
if ($alternatives = $this->findAlternatives($name, $allCommands)) {
691691
// remove hidden commands
@@ -740,14 +740,14 @@ public function find(string $name): Command
740740
if (\count($commands) > 1) {
741741
$suggestions = $this->getAbbreviationSuggestions(array_filter($abbrevs));
742742

743-
throw new CommandNotFoundException(sprintf("Command \"%s\" is ambiguous.\nDid you mean one of these?\n%s.", $name, $suggestions), array_values($commands));
743+
throw new CommandNotFoundException(\sprintf("Command \"%s\" is ambiguous.\nDid you mean one of these?\n%s.", $name, $suggestions), array_values($commands));
744744
}
745745
}
746746

747747
$command = $this->get(reset($commands));
748748

749749
if ($command->isHidden()) {
750-
throw new CommandNotFoundException(sprintf('The command "%s" does not exist.', $name));
750+
throw new CommandNotFoundException(\sprintf('The command "%s" does not exist.', $name));
751751
}
752752

753753
return $command;
@@ -822,7 +822,7 @@ public function renderThrowable(\Throwable $e, OutputInterface $output): void
822822
$this->doRenderThrowable($e, $output);
823823

824824
if (null !== $this->runningCommand) {
825-
$output->writeln(sprintf('<info>%s</info>', OutputFormatter::escape(sprintf($this->runningCommand->getSynopsis(), $this->getName()))), OutputInterface::VERBOSITY_QUIET);
825+
$output->writeln(\sprintf('<info>%s</info>', OutputFormatter::escape(\sprintf($this->runningCommand->getSynopsis(), $this->getName()))), OutputInterface::VERBOSITY_QUIET);
826826
$output->writeln('', OutputInterface::VERBOSITY_QUIET);
827827
}
828828
}
@@ -833,7 +833,7 @@ protected function doRenderThrowable(\Throwable $e, OutputInterface $output): vo
833833
$message = trim($e->getMessage());
834834
if ('' === $message || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
835835
$class = get_debug_type($e);
836-
$title = sprintf(' [%s%s] ', $class, 0 !== ($code = $e->getCode()) ? ' ('.$code.')' : '');
836+
$title = \sprintf(' [%s%s] ', $class, 0 !== ($code = $e->getCode()) ? ' ('.$code.')' : '');
837837
$len = Helper::width($title);
838838
} else {
839839
$len = 0;
@@ -857,14 +857,14 @@ protected function doRenderThrowable(\Throwable $e, OutputInterface $output): vo
857857

858858
$messages = [];
859859
if (!$e instanceof ExceptionInterface || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
860-
$messages[] = sprintf('<comment>%s</comment>', OutputFormatter::escape(sprintf('In %s line %s:', basename($e->getFile()) ?: 'n/a', $e->getLine() ?: 'n/a')));
860+
$messages[] = \sprintf('<comment>%s</comment>', OutputFormatter::escape(\sprintf('In %s line %s:', basename($e->getFile()) ?: 'n/a', $e->getLine() ?: 'n/a')));
861861
}
862-
$messages[] = $emptyLine = sprintf('<error>%s</error>', str_repeat(' ', $len));
862+
$messages[] = $emptyLine = \sprintf('<error>%s</error>', str_repeat(' ', $len));
863863
if ('' === $message || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
864-
$messages[] = sprintf('<error>%s%s</error>', $title, str_repeat(' ', max(0, $len - Helper::width($title))));
864+
$messages[] = \sprintf('<error>%s%s</error>', $title, str_repeat(' ', max(0, $len - Helper::width($title))));
865865
}
866866
foreach ($lines as $line) {
867-
$messages[] = sprintf('<error> %s %s</error>', OutputFormatter::escape($line[0]), str_repeat(' ', $len - $line[1]));
867+
$messages[] = \sprintf('<error> %s %s</error>', OutputFormatter::escape($line[0]), str_repeat(' ', $len - $line[1]));
868868
}
869869
$messages[] = $emptyLine;
870870
$messages[] = '';
@@ -891,7 +891,7 @@ protected function doRenderThrowable(\Throwable $e, OutputInterface $output): vo
891891
$file = $trace[$i]['file'] ?? 'n/a';
892892
$line = $trace[$i]['line'] ?? 'n/a';
893893

894-
$output->writeln(sprintf(' %s%s at <info>%s:%s</info>', $class, $function ? $type.$function.'()' : '', $file, $line), OutputInterface::VERBOSITY_QUIET);
894+
$output->writeln(\sprintf(' %s%s at <info>%s:%s</info>', $class, $function ? $type.$function.'()' : '', $file, $line), OutputInterface::VERBOSITY_QUIET);
895895
}
896896

897897
$output->writeln('', OutputInterface::VERBOSITY_QUIET);

CI/GithubActionReporter.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ private function log(string $type, string $message, ?string $file = null, ?int $
8989

9090
if (!$file) {
9191
// No file provided, output the message solely:
92-
$this->output->writeln(sprintf('::%s::%s', $type, $message));
92+
$this->output->writeln(\sprintf('::%s::%s', $type, $message));
9393

9494
return;
9595
}
9696

97-
$this->output->writeln(sprintf('::%s file=%s,line=%s,col=%s::%s', $type, strtr($file, self::ESCAPED_PROPERTIES), strtr($line ?? 1, self::ESCAPED_PROPERTIES), strtr($col ?? 0, self::ESCAPED_PROPERTIES), $message));
97+
$this->output->writeln(\sprintf('::%s file=%s,line=%s,col=%s::%s', $type, strtr($file, self::ESCAPED_PROPERTIES), strtr($line ?? 1, self::ESCAPED_PROPERTIES), strtr($col ?? 0, self::ESCAPED_PROPERTIES), $message));
9898
}
9999
}

Color.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function __construct(string $foreground = '', string $background = '', ar
6060

6161
foreach ($options as $option) {
6262
if (!isset(self::AVAILABLE_OPTIONS[$option])) {
63-
throw new InvalidArgumentException(sprintf('Invalid option specified: "%s". Expected one of (%s).', $option, implode(', ', array_keys(self::AVAILABLE_OPTIONS))));
63+
throw new InvalidArgumentException(\sprintf('Invalid option specified: "%s". Expected one of (%s).', $option, implode(', ', array_keys(self::AVAILABLE_OPTIONS))));
6464
}
6565

6666
$this->options[$option] = self::AVAILABLE_OPTIONS[$option];
@@ -88,7 +88,7 @@ public function set(): string
8888
return '';
8989
}
9090

91-
return sprintf("\033[%sm", implode(';', $setCodes));
91+
return \sprintf("\033[%sm", implode(';', $setCodes));
9292
}
9393

9494
public function unset(): string
@@ -107,7 +107,7 @@ public function unset(): string
107107
return '';
108108
}
109109

110-
return sprintf("\033[%sm", implode(';', $unsetCodes));
110+
return \sprintf("\033[%sm", implode(';', $unsetCodes));
111111
}
112112

113113
private function parseColor(string $color, bool $background = false): string
@@ -128,6 +128,6 @@ private function parseColor(string $color, bool $background = false): string
128128
return ($background ? '10' : '9').self::BRIGHT_COLORS[$color];
129129
}
130130

131-
throw new InvalidArgumentException(sprintf('Invalid "%s" color; expected one of (%s).', $color, implode(', ', array_merge(array_keys(self::COLORS), array_keys(self::BRIGHT_COLORS)))));
131+
throw new InvalidArgumentException(\sprintf('Invalid "%s" color; expected one of (%s).', $color, implode(', ', array_merge(array_keys(self::COLORS), array_keys(self::BRIGHT_COLORS)))));
132132
}
133133
}

Command/Command.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ public function getDefinition(): InputDefinition
395395
*/
396396
public function getNativeDefinition(): InputDefinition
397397
{
398-
return $this->definition ?? throw new LogicException(sprintf('Command class "%s" is not correctly initialized. You probably forgot to call the parent constructor.', static::class));
398+
return $this->definition ?? throw new LogicException(\sprintf('Command class "%s" is not correctly initialized. You probably forgot to call the parent constructor.', static::class));
399399
}
400400

401401
/**
@@ -603,7 +603,7 @@ public function getSynopsis(bool $short = false): string
603603
$key = $short ? 'short' : 'long';
604604

605605
if (!isset($this->synopsis[$key])) {
606-
$this->synopsis[$key] = trim(sprintf('%s %s', $this->name, $this->definition->getSynopsis($short)));
606+
$this->synopsis[$key] = trim(\sprintf('%s %s', $this->name, $this->definition->getSynopsis($short)));
607607
}
608608

609609
return $this->synopsis[$key];
@@ -617,7 +617,7 @@ public function getSynopsis(bool $short = false): string
617617
public function addUsage(string $usage): static
618618
{
619619
if (!str_starts_with($usage, $this->name)) {
620-
$usage = sprintf('%s %s', $this->name, $usage);
620+
$usage = \sprintf('%s %s', $this->name, $usage);
621621
}
622622

623623
$this->usages[] = $usage;
@@ -642,7 +642,7 @@ public function getUsages(): array
642642
public function getHelper(string $name): HelperInterface
643643
{
644644
if (null === $this->helperSet) {
645-
throw new LogicException(sprintf('Cannot retrieve helper "%s" because there is no HelperSet defined. Did you forget to add your command to the application or to set the application on the command using the setApplication() method? You can also set the HelperSet directly using the setHelperSet() method.', $name));
645+
throw new LogicException(\sprintf('Cannot retrieve helper "%s" because there is no HelperSet defined. Did you forget to add your command to the application or to set the application on the command using the setApplication() method? You can also set the HelperSet directly using the setHelperSet() method.', $name));
646646
}
647647

648648
return $this->helperSet->get($name);
@@ -658,7 +658,7 @@ public function getHelper(string $name): HelperInterface
658658
private function validateName(string $name): void
659659
{
660660
if (!preg_match('/^[^\:]++(\:[^\:]++)*$/', $name)) {
661-
throw new InvalidArgumentException(sprintf('Command name "%s" is invalid.', $name));
661+
throw new InvalidArgumentException(\sprintf('Command name "%s" is invalid.', $name));
662662
}
663663
}
664664
}

Command/CompleteCommand.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7474
// "symfony" must be kept for compat with the shell scripts generated by Symfony Console 5.4 - 6.1
7575
$version = $input->getOption('symfony') ? '1' : $input->getOption('api-version');
7676
if ($version && version_compare($version, self::COMPLETION_API_VERSION, '<')) {
77-
$message = sprintf('Completion script version is not supported ("%s" given, ">=%s" required).', $version, self::COMPLETION_API_VERSION);
77+
$message = \sprintf('Completion script version is not supported ("%s" given, ">=%s" required).', $version, self::COMPLETION_API_VERSION);
7878
$this->log($message);
7979

8080
$output->writeln($message.' Install the Symfony completion script again by using the "completion" command.');
@@ -88,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8888
}
8989

9090
if (!$completionOutput = $this->completionOutputs[$shell] ?? false) {
91-
throw new \RuntimeException(sprintf('Shell completion is not supported for your shell: "%s" (supported: "%s").', $shell, implode('", "', array_keys($this->completionOutputs))));
91+
throw new \RuntimeException(\sprintf('Shell completion is not supported for your shell: "%s" (supported: "%s").', $shell, implode('", "', array_keys($this->completionOutputs))));
9292
}
9393

9494
$completionInput = $this->createCompletionInput($input);

Command/DumpCompletionCommand.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9898
$output = $output->getErrorOutput();
9999
}
100100
if ($shell) {
101-
$output->writeln(sprintf('<error>Detected shell "%s", which is not supported by Symfony shell completion (supported shells: "%s").</>', $shell, implode('", "', $supportedShells)));
101+
$output->writeln(\sprintf('<error>Detected shell "%s", which is not supported by Symfony shell completion (supported shells: "%s").</>', $shell, implode('", "', $supportedShells)));
102102
} else {
103-
$output->writeln(sprintf('<error>Shell not detected, Symfony shell completion only supports "%s").</>', implode('", "', $supportedShells)));
103+
$output->writeln(\sprintf('<error>Shell not detected, Symfony shell completion only supports "%s").</>', implode('", "', $supportedShells)));
104104
}
105105

106106
return 2;

CommandLoader/ContainerCommandLoader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(
3434
public function get(string $name): Command
3535
{
3636
if (!$this->has($name)) {
37-
throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));
37+
throw new CommandNotFoundException(\sprintf('Command "%s" does not exist.', $name));
3838
}
3939

4040
return $this->container->get($this->commandMap[$name]);

CommandLoader/FactoryCommandLoader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function has(string $name): bool
3737
public function get(string $name): Command
3838
{
3939
if (!isset($this->factories[$name])) {
40-
throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));
40+
throw new CommandNotFoundException(\sprintf('Command "%s" does not exist.', $name));
4141
}
4242

4343
$factory = $this->factories[$name];

Cursor.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(
3636
*/
3737
public function moveUp(int $lines = 1): static
3838
{
39-
$this->output->write(sprintf("\x1b[%dA", $lines));
39+
$this->output->write(\sprintf("\x1b[%dA", $lines));
4040

4141
return $this;
4242
}
@@ -46,7 +46,7 @@ public function moveUp(int $lines = 1): static
4646
*/
4747
public function moveDown(int $lines = 1): static
4848
{
49-
$this->output->write(sprintf("\x1b[%dB", $lines));
49+
$this->output->write(\sprintf("\x1b[%dB", $lines));
5050

5151
return $this;
5252
}
@@ -56,7 +56,7 @@ public function moveDown(int $lines = 1): static
5656
*/
5757
public function moveRight(int $columns = 1): static
5858
{
59-
$this->output->write(sprintf("\x1b[%dC", $columns));
59+
$this->output->write(\sprintf("\x1b[%dC", $columns));
6060

6161
return $this;
6262
}
@@ -66,7 +66,7 @@ public function moveRight(int $columns = 1): static
6666
*/
6767
public function moveLeft(int $columns = 1): static
6868
{
69-
$this->output->write(sprintf("\x1b[%dD", $columns));
69+
$this->output->write(\sprintf("\x1b[%dD", $columns));
7070

7171
return $this;
7272
}
@@ -76,7 +76,7 @@ public function moveLeft(int $columns = 1): static
7676
*/
7777
public function moveToColumn(int $column): static
7878
{
79-
$this->output->write(sprintf("\x1b[%dG", $column));
79+
$this->output->write(\sprintf("\x1b[%dG", $column));
8080

8181
return $this;
8282
}
@@ -86,7 +86,7 @@ public function moveToColumn(int $column): static
8686
*/
8787
public function moveToPosition(int $column, int $row): static
8888
{
89-
$this->output->write(sprintf("\x1b[%d;%dH", $row + 1, $column));
89+
$this->output->write(\sprintf("\x1b[%d;%dH", $row + 1, $column));
9090

9191
return $this;
9292
}
@@ -195,7 +195,7 @@ public function getCurrentPosition(): array
195195

196196
$code = trim(fread($this->input, 1024));
197197

198-
shell_exec(sprintf('stty %s', $sttyMode));
198+
shell_exec(\sprintf('stty %s', $sttyMode));
199199

200200
sscanf($code, "\033[%d;%dR", $row, $col);
201201

0 commit comments

Comments
 (0)