Skip to content

Commit f203cbd

Browse files
committed
Prefix all sprintf() calls
1 parent 47aa818 commit f203cbd

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

Debug/OptionsResolverIntrospector.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(OptionsResolver $optionsResolver)
2929
$this->get = \Closure::bind(function ($property, $option, $message) {
3030
/** @var OptionsResolver $this */
3131
if (!$this->isDefined($option)) {
32-
throw new UndefinedOptionsException(sprintf('The option "%s" does not exist.', $option));
32+
throw new UndefinedOptionsException(\sprintf('The option "%s" does not exist.', $option));
3333
}
3434

3535
if (!\array_key_exists($option, $this->{$property})) {
@@ -45,7 +45,7 @@ public function __construct(OptionsResolver $optionsResolver)
4545
*/
4646
public function getDefault(string $option): mixed
4747
{
48-
return ($this->get)('defaults', $option, sprintf('No default value was set for the "%s" option.', $option));
48+
return ($this->get)('defaults', $option, \sprintf('No default value was set for the "%s" option.', $option));
4949
}
5050

5151
/**
@@ -55,7 +55,7 @@ public function getDefault(string $option): mixed
5555
*/
5656
public function getLazyClosures(string $option): array
5757
{
58-
return ($this->get)('lazy', $option, sprintf('No lazy closures were set for the "%s" option.', $option));
58+
return ($this->get)('lazy', $option, \sprintf('No lazy closures were set for the "%s" option.', $option));
5959
}
6060

6161
/**
@@ -65,7 +65,7 @@ public function getLazyClosures(string $option): array
6565
*/
6666
public function getAllowedTypes(string $option): array
6767
{
68-
return ($this->get)('allowedTypes', $option, sprintf('No allowed types were set for the "%s" option.', $option));
68+
return ($this->get)('allowedTypes', $option, \sprintf('No allowed types were set for the "%s" option.', $option));
6969
}
7070

7171
/**
@@ -75,7 +75,7 @@ public function getAllowedTypes(string $option): array
7575
*/
7676
public function getAllowedValues(string $option): array
7777
{
78-
return ($this->get)('allowedValues', $option, sprintf('No allowed values were set for the "%s" option.', $option));
78+
return ($this->get)('allowedValues', $option, \sprintf('No allowed values were set for the "%s" option.', $option));
7979
}
8080

8181
/**
@@ -91,14 +91,14 @@ public function getNormalizer(string $option): \Closure
9191
*/
9292
public function getNormalizers(string $option): array
9393
{
94-
return ($this->get)('normalizers', $option, sprintf('No normalizer was set for the "%s" option.', $option));
94+
return ($this->get)('normalizers', $option, \sprintf('No normalizer was set for the "%s" option.', $option));
9595
}
9696

9797
/**
9898
* @throws NoConfigurationException on no configured deprecation
9999
*/
100100
public function getDeprecation(string $option): array
101101
{
102-
return ($this->get)('deprecated', $option, sprintf('No deprecation was set for the "%s" option.', $option));
102+
return ($this->get)('deprecated', $option, \sprintf('No deprecation was set for the "%s" option.', $option));
103103
}
104104
}

OptionsResolver.php

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,11 @@ public function setDeprecated(string $option, string $package, string $version,
438438
}
439439

440440
if (!isset($this->defined[$option])) {
441-
throw new UndefinedOptionsException(sprintf('The option "%s" does not exist, defined options are: "%s".', $this->formatOptions([$option]), implode('", "', array_keys($this->defined))));
441+
throw new UndefinedOptionsException(\sprintf('The option "%s" does not exist, defined options are: "%s".', $this->formatOptions([$option]), implode('", "', array_keys($this->defined))));
442442
}
443443

444444
if (!\is_string($message) && !$message instanceof \Closure) {
445-
throw new InvalidArgumentException(sprintf('Invalid type for deprecation message argument, expected string or \Closure, but got "%s".', get_debug_type($message)));
445+
throw new InvalidArgumentException(\sprintf('Invalid type for deprecation message argument, expected string or \Closure, but got "%s".', get_debug_type($message)));
446446
}
447447

448448
// ignore if empty string
@@ -497,7 +497,7 @@ public function setNormalizer(string $option, \Closure $normalizer): static
497497
}
498498

499499
if (!isset($this->defined[$option])) {
500-
throw new UndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptions([$option]), implode('", "', array_keys($this->defined))));
500+
throw new UndefinedOptionsException(\sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptions([$option]), implode('", "', array_keys($this->defined))));
501501
}
502502

503503
$this->normalizers[$option] = [$normalizer];
@@ -538,7 +538,7 @@ public function addNormalizer(string $option, \Closure $normalizer, bool $forceP
538538
}
539539

540540
if (!isset($this->defined[$option])) {
541-
throw new UndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptions([$option]), implode('", "', array_keys($this->defined))));
541+
throw new UndefinedOptionsException(\sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptions([$option]), implode('", "', array_keys($this->defined))));
542542
}
543543

544544
if ($forcePrepend) {
@@ -581,7 +581,7 @@ public function setAllowedValues(string $option, mixed $allowedValues): static
581581
}
582582

583583
if (!isset($this->defined[$option])) {
584-
throw new UndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptions([$option]), implode('", "', array_keys($this->defined))));
584+
throw new UndefinedOptionsException(\sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptions([$option]), implode('", "', array_keys($this->defined))));
585585
}
586586

587587
$this->allowedValues[$option] = \is_array($allowedValues) ? $allowedValues : [$allowedValues];
@@ -621,7 +621,7 @@ public function addAllowedValues(string $option, mixed $allowedValues): static
621621
}
622622

623623
if (!isset($this->defined[$option])) {
624-
throw new UndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptions([$option]), implode('", "', array_keys($this->defined))));
624+
throw new UndefinedOptionsException(\sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptions([$option]), implode('", "', array_keys($this->defined))));
625625
}
626626

627627
if (!\is_array($allowedValues)) {
@@ -661,7 +661,7 @@ public function setAllowedTypes(string $option, string|array $allowedTypes): sta
661661
}
662662

663663
if (!isset($this->defined[$option])) {
664-
throw new UndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptions([$option]), implode('", "', array_keys($this->defined))));
664+
throw new UndefinedOptionsException(\sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptions([$option]), implode('", "', array_keys($this->defined))));
665665
}
666666

667667
$this->allowedTypes[$option] = (array) $allowedTypes;
@@ -695,7 +695,7 @@ public function addAllowedTypes(string $option, string|array $allowedTypes): sta
695695
}
696696

697697
if (!isset($this->defined[$option])) {
698-
throw new UndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptions([$option]), implode('", "', array_keys($this->defined))));
698+
throw new UndefinedOptionsException(\sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptions([$option]), implode('", "', array_keys($this->defined))));
699699
}
700700

701701
if (!isset($this->allowedTypes[$option])) {
@@ -716,7 +716,7 @@ public function addAllowedTypes(string $option, string|array $allowedTypes): sta
716716
public function define(string $option): OptionConfigurator
717717
{
718718
if (isset($this->defined[$option])) {
719-
throw new OptionDefinitionException(sprintf('The option "%s" is already defined.', $option));
719+
throw new OptionDefinitionException(\sprintf('The option "%s" is already defined.', $option));
720720
}
721721

722722
return new OptionConfigurator($option, $this);
@@ -737,7 +737,7 @@ public function setInfo(string $option, string $info): static
737737
}
738738

739739
if (!isset($this->defined[$option])) {
740-
throw new UndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptions([$option]), implode('", "', array_keys($this->defined))));
740+
throw new UndefinedOptionsException(\sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptions([$option]), implode('", "', array_keys($this->defined))));
741741
}
742742

743743
$this->info[$option] = $info;
@@ -751,7 +751,7 @@ public function setInfo(string $option, string $info): static
751751
public function getInfo(string $option): ?string
752752
{
753753
if (!isset($this->defined[$option])) {
754-
throw new UndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptions([$option]), implode('", "', array_keys($this->defined))));
754+
throw new UndefinedOptionsException(\sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptions([$option]), implode('", "', array_keys($this->defined))));
755755
}
756756

757757
return $this->info[$option] ?? null;
@@ -873,7 +873,7 @@ public function resolve(array $options = []): array
873873
ksort($clone->defined);
874874
ksort($diff);
875875

876-
throw new UndefinedOptionsException(sprintf((\count($diff) > 1 ? 'The options "%s" do not exist.' : 'The option "%s" does not exist.').' Defined options are: "%s".', $this->formatOptions(array_keys($diff)), implode('", "', array_keys($clone->defined))));
876+
throw new UndefinedOptionsException(\sprintf((\count($diff) > 1 ? 'The options "%s" do not exist.' : 'The option "%s" does not exist.').' Defined options are: "%s".', $this->formatOptions(array_keys($diff)), implode('", "', array_keys($clone->defined))));
877877
}
878878

879879
// Override options set by the user
@@ -893,7 +893,7 @@ public function resolve(array $options = []): array
893893
if (\count($diff) > 0) {
894894
ksort($diff);
895895

896-
throw new MissingOptionsException(sprintf(\count($diff) > 1 ? 'The required options "%s" are missing.' : 'The required option "%s" is missing.', $this->formatOptions(array_keys($diff))));
896+
throw new MissingOptionsException(\sprintf(\count($diff) > 1 ? 'The required options "%s" are missing.' : 'The required option "%s" is missing.', $this->formatOptions(array_keys($diff))));
897897
}
898898

899899
// Lock the container
@@ -939,10 +939,10 @@ public function offsetGet(mixed $option, bool $triggerDeprecation = true): mixed
939939
// Check whether the option is set at all
940940
if (!isset($this->defaults[$option]) && !\array_key_exists($option, $this->defaults)) {
941941
if (!isset($this->defined[$option])) {
942-
throw new NoSuchOptionException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptions([$option]), implode('", "', array_keys($this->defined))));
942+
throw new NoSuchOptionException(\sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptions([$option]), implode('", "', array_keys($this->defined))));
943943
}
944944

945-
throw new NoSuchOptionException(sprintf('The optional option "%s" has no value set. You should make sure it is set with "isset" before reading it.', $this->formatOptions([$option])));
945+
throw new NoSuchOptionException(\sprintf('The optional option "%s" has no value set. You should make sure it is set with "isset" before reading it.', $this->formatOptions([$option])));
946946
}
947947

948948
$value = $this->defaults[$option];
@@ -951,11 +951,11 @@ public function offsetGet(mixed $option, bool $triggerDeprecation = true): mixed
951951
if (isset($this->nested[$option])) {
952952
// If the closure is already being called, we have a cyclic dependency
953953
if (isset($this->calling[$option])) {
954-
throw new OptionDefinitionException(sprintf('The options "%s" have a cyclic dependency.', $this->formatOptions(array_keys($this->calling))));
954+
throw new OptionDefinitionException(\sprintf('The options "%s" have a cyclic dependency.', $this->formatOptions(array_keys($this->calling))));
955955
}
956956

957957
if (!\is_array($value)) {
958-
throw new InvalidOptionsException(sprintf('The nested option "%s" with value %s is expected to be of type array, but is of type "%s".', $this->formatOptions([$option]), $this->formatValue($value), get_debug_type($value)));
958+
throw new InvalidOptionsException(\sprintf('The nested option "%s" with value %s is expected to be of type array, but is of type "%s".', $this->formatOptions([$option]), $this->formatValue($value), get_debug_type($value)));
959959
}
960960

961961
// The following section must be protected from cyclic calls.
@@ -973,7 +973,7 @@ public function offsetGet(mixed $option, bool $triggerDeprecation = true): mixed
973973
$values = [];
974974
foreach ($value as $index => $prototypeValue) {
975975
if (!\is_array($prototypeValue)) {
976-
throw new InvalidOptionsException(sprintf('The value of the option "%s" is expected to be of type array of array, but is of type array of "%s".', $this->formatOptions([$option]), get_debug_type($prototypeValue)));
976+
throw new InvalidOptionsException(\sprintf('The value of the option "%s" is expected to be of type array of array, but is of type array of "%s".', $this->formatOptions([$option]), get_debug_type($prototypeValue)));
977977
}
978978

979979
$resolver->prototypeIndex = $index;
@@ -994,7 +994,7 @@ public function offsetGet(mixed $option, bool $triggerDeprecation = true): mixed
994994
// If the closure is already being called, we have a cyclic
995995
// dependency
996996
if (isset($this->calling[$option])) {
997-
throw new OptionDefinitionException(sprintf('The options "%s" have a cyclic dependency.', $this->formatOptions(array_keys($this->calling))));
997+
throw new OptionDefinitionException(\sprintf('The options "%s" have a cyclic dependency.', $this->formatOptions(array_keys($this->calling))));
998998
}
999999

10001000
// The following section must be protected from cyclic
@@ -1030,10 +1030,10 @@ public function offsetGet(mixed $option, bool $triggerDeprecation = true): mixed
10301030
$allowedContainsArrayType = \count(array_filter($this->allowedTypes[$option], static fn ($item) => str_ends_with($item, '[]'))) > 0;
10311031

10321032
if (\is_array($value) && $allowedContainsArrayType) {
1033-
throw new InvalidOptionsException(sprintf('The option "%s" with value %s is expected to be of type "%s", but one of the elements is of type "%s".', $this->formatOptions([$option]), $fmtActualValue, $fmtAllowedTypes, $fmtProvidedTypes));
1033+
throw new InvalidOptionsException(\sprintf('The option "%s" with value %s is expected to be of type "%s", but one of the elements is of type "%s".', $this->formatOptions([$option]), $fmtActualValue, $fmtAllowedTypes, $fmtProvidedTypes));
10341034
}
10351035

1036-
throw new InvalidOptionsException(sprintf('The option "%s" with value %s is expected to be of type "%s", but is of type "%s".', $this->formatOptions([$option]), $fmtActualValue, $fmtAllowedTypes, $fmtProvidedTypes));
1036+
throw new InvalidOptionsException(\sprintf('The option "%s" with value %s is expected to be of type "%s", but is of type "%s".', $this->formatOptions([$option]), $fmtActualValue, $fmtAllowedTypes, $fmtProvidedTypes));
10371037
}
10381038
}
10391039

@@ -1062,21 +1062,21 @@ public function offsetGet(mixed $option, bool $triggerDeprecation = true): mixed
10621062
}
10631063

10641064
if (!$success) {
1065-
$message = sprintf(
1065+
$message = \sprintf(
10661066
'The option "%s" with value %s is invalid.',
10671067
$this->formatOptions([$option]),
10681068
$this->formatValue($value)
10691069
);
10701070

10711071
if (\count($printableAllowedValues) > 0) {
1072-
$message .= sprintf(
1072+
$message .= \sprintf(
10731073
' Accepted values are: %s.',
10741074
$this->formatValues($printableAllowedValues)
10751075
);
10761076
}
10771077

10781078
if (isset($this->info[$option])) {
1079-
$message .= sprintf(' Info: %s.', $this->info[$option]);
1079+
$message .= \sprintf(' Info: %s.', $this->info[$option]);
10801080
}
10811081

10821082
throw new InvalidOptionsException($message);
@@ -1092,13 +1092,13 @@ public function offsetGet(mixed $option, bool $triggerDeprecation = true): mixed
10921092
if ($message instanceof \Closure) {
10931093
// If the closure is already being called, we have a cyclic dependency
10941094
if (isset($this->calling[$option])) {
1095-
throw new OptionDefinitionException(sprintf('The options "%s" have a cyclic dependency.', $this->formatOptions(array_keys($this->calling))));
1095+
throw new OptionDefinitionException(\sprintf('The options "%s" have a cyclic dependency.', $this->formatOptions(array_keys($this->calling))));
10961096
}
10971097

10981098
$this->calling[$option] = true;
10991099
try {
11001100
if (!\is_string($message = $message($this, $value))) {
1101-
throw new InvalidOptionsException(sprintf('Invalid type for deprecation message, expected string but got "%s", return an empty string to ignore.', get_debug_type($message)));
1101+
throw new InvalidOptionsException(\sprintf('Invalid type for deprecation message, expected string but got "%s", return an empty string to ignore.', get_debug_type($message)));
11021102
}
11031103
} finally {
11041104
unset($this->calling[$option]);
@@ -1115,7 +1115,7 @@ public function offsetGet(mixed $option, bool $triggerDeprecation = true): mixed
11151115
// If the closure is already being called, we have a cyclic
11161116
// dependency
11171117
if (isset($this->calling[$option])) {
1118-
throw new OptionDefinitionException(sprintf('The options "%s" have a cyclic dependency.', $this->formatOptions(array_keys($this->calling))));
1118+
throw new OptionDefinitionException(\sprintf('The options "%s" have a cyclic dependency.', $this->formatOptions(array_keys($this->calling))));
11191119
}
11201120

11211121
// The following section must be protected from cyclic
@@ -1293,14 +1293,14 @@ private function formatOptions(array $options): string
12931293
if ($this->parentsOptions) {
12941294
$prefix = array_shift($this->parentsOptions);
12951295
if ($this->parentsOptions) {
1296-
$prefix .= sprintf('[%s]', implode('][', $this->parentsOptions));
1296+
$prefix .= \sprintf('[%s]', implode('][', $this->parentsOptions));
12971297
}
12981298

12991299
if ($this->prototype && null !== $this->prototypeIndex) {
1300-
$prefix .= sprintf('[%s]', $this->prototypeIndex);
1300+
$prefix .= \sprintf('[%s]', $this->prototypeIndex);
13011301
}
13021302

1303-
$options = array_map(static fn (string $option): string => sprintf('%s[%s]', $prefix, $option), $options);
1303+
$options = array_map(static fn (string $option): string => \sprintf('%s[%s]', $prefix, $option), $options);
13041304
}
13051305

13061306
return implode('", "', $options);

0 commit comments

Comments
 (0)