Skip to content

Commit c307b0c

Browse files
committed
Prefix all sprintf() calls
1 parent 6f5c02d commit c307b0c

Some content is hidden

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

51 files changed

+149
-149
lines changed

Attribute/WithLogLevel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class WithLogLevel
2727
public function __construct(public readonly string $level)
2828
{
2929
if (!\defined('Psr\Log\LogLevel::'.strtoupper($this->level))) {
30-
throw new \InvalidArgumentException(sprintf('Invalid log level "%s".', $this->level));
30+
throw new \InvalidArgumentException(\sprintf('Invalid log level "%s".', $this->level));
3131
}
3232
}
3333
}

Bundle/Bundle.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ public function getContainerExtension(): ?ExtensionInterface
6767

6868
if (null !== $extension) {
6969
if (!$extension instanceof ExtensionInterface) {
70-
throw new \LogicException(sprintf('Extension "%s" must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface.', get_debug_type($extension)));
70+
throw new \LogicException(\sprintf('Extension "%s" must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface.', get_debug_type($extension)));
7171
}
7272

7373
// check naming convention
7474
$basename = preg_replace('/Bundle$/', '', $this->getName());
7575
$expectedAlias = Container::underscore($basename);
7676

7777
if ($expectedAlias != $extension->getAlias()) {
78-
throw new \LogicException(sprintf('Users will expect the alias of the default extension of a bundle to be the underscored version of the bundle name ("%s"). You can override "Bundle::getContainerExtension()" if you want to use "%s" or another alias.', $expectedAlias, $extension->getAlias()));
78+
throw new \LogicException(\sprintf('Users will expect the alias of the default extension of a bundle to be the underscored version of the bundle name ("%s"). You can override "Bundle::getContainerExtension()" if you want to use "%s" or another alias.', $expectedAlias, $extension->getAlias()));
7979
}
8080

8181
$this->extension = $extension;

CacheClearer/Psr6CacheClearer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function hasPool(string $name): bool
3939
public function getPool(string $name): CacheItemPoolInterface
4040
{
4141
if (!$this->hasPool($name)) {
42-
throw new \InvalidArgumentException(sprintf('Cache pool not found: "%s".', $name));
42+
throw new \InvalidArgumentException(\sprintf('Cache pool not found: "%s".', $name));
4343
}
4444

4545
return $this->pools[$name];
@@ -51,7 +51,7 @@ public function getPool(string $name): CacheItemPoolInterface
5151
public function clearPool(string $name): bool
5252
{
5353
if (!isset($this->pools[$name])) {
54-
throw new \InvalidArgumentException(sprintf('Cache pool not found: "%s".', $name));
54+
throw new \InvalidArgumentException(\sprintf('Cache pool not found: "%s".', $name));
5555
}
5656

5757
return $this->pools[$name]->clear();

CacheWarmer/CacheWarmer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ protected function writeCacheFile(string $file, $content): void
2727
return;
2828
}
2929

30-
throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file));
30+
throw new \RuntimeException(\sprintf('Failed to write cache file "%s".', $file));
3131
}
3232
}

CacheWarmer/CacheWarmerAggregate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ public function warmUp(string $cacheDir, ?string $buildDir = null, ?SymfonyStyle
9595
$start = microtime(true);
9696
foreach ((array) $warmer->warmUp($cacheDir, $buildDir) as $item) {
9797
if (is_dir($item) || (str_starts_with($item, \dirname($cacheDir)) && !is_file($item)) || ($buildDir && str_starts_with($item, \dirname($buildDir)) && !is_file($item))) {
98-
throw new \LogicException(sprintf('"%s::warmUp()" should return a list of files or classes but "%s" is none of them.', $warmer::class, $item));
98+
throw new \LogicException(\sprintf('"%s::warmUp()" should return a list of files or classes but "%s" is none of them.', $warmer::class, $item));
9999
}
100100
$preload[] = $item;
101101
}
102102

103103
if ($io?->isDebug()) {
104-
$io->info(sprintf('"%s" completed in %0.2fms.', $warmer::class, 1000 * (microtime(true) - $start)));
104+
$io->info(\sprintf('"%s" completed in %0.2fms.', $warmer::class, 1000 * (microtime(true) - $start)));
105105
}
106106
}
107107
} finally {

Controller/ArgumentResolver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function getArguments(Request $request, callable $controller, ?\Reflectio
6060
if ($attribute->disabled) {
6161
$disabledResolvers[$attribute->resolver] = true;
6262
} elseif ($resolverName) {
63-
throw new \LogicException(sprintf('You can only pin one resolver per argument, but argument "$%s" of "%s()" has more.', $metadata->getName(), $metadata->getControllerName()));
63+
throw new \LogicException(\sprintf('You can only pin one resolver per argument, but argument "$%s" of "%s()" has more.', $metadata->getName(), $metadata->getControllerName()));
6464
} else {
6565
$resolverName = $attribute->resolver;
6666
}
@@ -96,7 +96,7 @@ public function getArguments(Request $request, callable $controller, ?\Reflectio
9696
}
9797

9898
if (1 < $count && !$metadata->isVariadic()) {
99-
throw new \InvalidArgumentException(sprintf('"%s::resolve()" must yield at most one value for non-variadic arguments.', get_debug_type($resolver)));
99+
throw new \InvalidArgumentException(\sprintf('"%s::resolve()" must yield at most one value for non-variadic arguments.', get_debug_type($resolver)));
100100
}
101101

102102
if ($count) {
@@ -118,7 +118,7 @@ public function getArguments(Request $request, callable $controller, ?\Reflectio
118118
}
119119
}
120120

121-
throw new \RuntimeException(sprintf('Controller "%s" requires the "$%s" argument that could not be resolved. '.($reasonCounter > 1 ? 'Possible reasons: ' : '').'%s', $metadata->getControllerName(), $metadata->getName(), implode(' ', $reasons)));
121+
throw new \RuntimeException(\sprintf('Controller "%s" requires the "$%s" argument that could not be resolved. '.($reasonCounter > 1 ? 'Possible reasons: ' : '').'%s', $metadata->getControllerName(), $metadata->getName(), implode(' ', $reasons)));
122122
}
123123

124124
return $arguments;

Controller/ArgumentResolver/BackedEnumValueResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable
5353
}
5454

5555
if (!\is_int($value) && !\is_string($value)) {
56-
throw new \LogicException(sprintf('Could not resolve the "%s $%s" controller argument: expecting an int or string, got "%s".', $argument->getType(), $argument->getName(), get_debug_type($value)));
56+
throw new \LogicException(\sprintf('Could not resolve the "%s $%s" controller argument: expecting an int or string, got "%s".', $argument->getType(), $argument->getName(), get_debug_type($value)));
5757
}
5858

5959
/** @var class-string<\BackedEnum> $enumType */
@@ -62,7 +62,7 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable
6262
try {
6363
return [$enumType::from($value)];
6464
} catch (\ValueError|\TypeError $e) {
65-
throw new NotFoundHttpException(sprintf('Could not resolve the "%s $%s" controller argument: ', $argument->getType(), $argument->getName()).$e->getMessage(), $e);
65+
throw new NotFoundHttpException(\sprintf('Could not resolve the "%s $%s" controller argument: ', $argument->getType(), $argument->getName()).$e->getMessage(), $e);
6666
}
6767
}
6868
}

Controller/ArgumentResolver/DateTimeValueResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function resolve(Request $request, ArgumentMetadata $argument): array
7979
}
8080

8181
if (!$date) {
82-
throw new NotFoundHttpException(sprintf('Invalid date given for parameter "%s".', $argument->getName()));
82+
throw new NotFoundHttpException(\sprintf('Invalid date given for parameter "%s".', $argument->getName()));
8383
}
8484

8585
return [$date];

Controller/ArgumentResolver/NotTaggedControllerValueResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public function resolve(Request $request, ArgumentMetadata $argument): array
5353
return [];
5454
}
5555

56-
$what = sprintf('argument $%s of "%s()"', $argument->getName(), $controller);
57-
$message = sprintf('Could not resolve %s, maybe you forgot to register the controller as a service or missed tagging it with the "controller.service_arguments"?', $what);
56+
$what = \sprintf('argument $%s of "%s()"', $argument->getName(), $controller);
57+
$message = \sprintf('Could not resolve %s, maybe you forgot to register the controller as a service or missed tagging it with the "controller.service_arguments"?', $what);
5858

5959
throw new RuntimeException($message);
6060
}

Controller/ArgumentResolver/QueryParameterValueResolver.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function resolve(Request $request, ArgumentMetadata $argument): array
4141
return [];
4242
}
4343

44-
throw HttpException::fromStatusCode($validationFailedCode, sprintf('Missing query parameter "%s".', $name));
44+
throw HttpException::fromStatusCode($validationFailedCode, \sprintf('Missing query parameter "%s".', $name));
4545
}
4646

4747
$value = $request->query->all()[$name];
@@ -55,7 +55,7 @@ public function resolve(Request $request, ArgumentMetadata $argument): array
5555
$filtered = array_values(array_filter((array) $value, \is_array(...)));
5656

5757
if ($filtered !== $value && !($attribute->flags & \FILTER_NULL_ON_FAILURE)) {
58-
throw HttpException::fromStatusCode($validationFailedCode, sprintf('Invalid query parameter "%s".', $name));
58+
throw HttpException::fromStatusCode($validationFailedCode, \sprintf('Invalid query parameter "%s".', $name));
5959
}
6060

6161
return $filtered;
@@ -83,7 +83,7 @@ public function resolve(Request $request, ArgumentMetadata $argument): array
8383
default => match ($enumType = is_subclass_of($type, \BackedEnum::class) ? (new \ReflectionEnum($type))->getBackingType()->getName() : null) {
8484
'int' => \FILTER_VALIDATE_INT,
8585
'string' => \FILTER_DEFAULT,
86-
default => throw new \LogicException(sprintf('#[MapQueryParameter] cannot be used on controller argument "%s$%s" of type "%s"; one of array, string, int, float, bool or \BackedEnum should be used.', $argument->isVariadic() ? '...' : '', $argument->getName(), $type ?? 'mixed')),
86+
default => throw new \LogicException(\sprintf('#[MapQueryParameter] cannot be used on controller argument "%s$%s" of type "%s"; one of array, string, int, float, bool or \BackedEnum should be used.', $argument->isVariadic() ? '...' : '', $argument->getName(), $type ?? 'mixed')),
8787
},
8888
};
8989

@@ -106,7 +106,7 @@ public function resolve(Request $request, ArgumentMetadata $argument): array
106106
}
107107

108108
if (null === $value && !($attribute->flags & \FILTER_NULL_ON_FAILURE)) {
109-
throw HttpException::fromStatusCode($validationFailedCode, sprintf('Invalid query parameter "%s".', $name));
109+
throw HttpException::fromStatusCode($validationFailedCode, \sprintf('Invalid query parameter "%s".', $name));
110110
}
111111

112112
if (!\is_array($value)) {
@@ -120,7 +120,7 @@ public function resolve(Request $request, ArgumentMetadata $argument): array
120120
}
121121

122122
if ($filtered !== $value && !($attribute->flags & \FILTER_NULL_ON_FAILURE)) {
123-
throw HttpException::fromStatusCode($validationFailedCode, sprintf('Invalid query parameter "%s".', $name));
123+
throw HttpException::fromStatusCode($validationFailedCode, \sprintf('Invalid query parameter "%s".', $name));
124124
}
125125

126126
return $argument->isVariadic() ? $filtered : [$filtered];

Controller/ArgumentResolver/RequestPayloadValueResolver.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable
8080
}
8181

8282
if (!$attribute instanceof MapUploadedFile && $argument->isVariadic()) {
83-
throw new \LogicException(sprintf('Mapping variadic argument "$%s" is not supported.', $argument->getName()));
83+
throw new \LogicException(\sprintf('Mapping variadic argument "$%s" is not supported.', $argument->getName()));
8484
}
8585

8686
if ($attribute instanceof MapRequestPayload) {
8787
if ('array' === $argument->getType()) {
8888
if (!$attribute->type) {
89-
throw new NearMissValueResolverException(sprintf('Please set the $type argument of the #[%s] attribute to the type of the objects in the expected array.', MapRequestPayload::class));
89+
throw new NearMissValueResolverException(\sprintf('Please set the $type argument of the #[%s] attribute to the type of the objects in the expected array.', MapRequestPayload::class));
9090
}
9191
} elseif ($attribute->type) {
92-
throw new NearMissValueResolverException(sprintf('Please set its type to "array" when using argument $type of #[%s].', MapRequestPayload::class));
92+
throw new NearMissValueResolverException(\sprintf('Please set its type to "array" when using argument $type of #[%s].', MapRequestPayload::class));
9393
}
9494
}
9595

@@ -118,7 +118,7 @@ public function onKernelControllerArguments(ControllerArgumentsEvent $event): vo
118118
$request = $event->getRequest();
119119

120120
if (!$argument->metadata->getType()) {
121-
throw new \LogicException(sprintf('Could not resolve the "$%s" controller argument: argument should be typed.', $argument->metadata->getName()));
121+
throw new \LogicException(\sprintf('Could not resolve the "$%s" controller argument: argument should be typed.', $argument->metadata->getName()));
122122
}
123123

124124
if ($this->validator) {
@@ -199,7 +199,7 @@ private function mapRequestPayload(Request $request, ArgumentMetadata $argument,
199199
}
200200

201201
if ($attribute->acceptFormat && !\in_array($format, (array) $attribute->acceptFormat, true)) {
202-
throw new UnsupportedMediaTypeHttpException(sprintf('Unsupported format, expects "%s", but "%s" given.', implode('", "', (array) $attribute->acceptFormat), $format));
202+
throw new UnsupportedMediaTypeHttpException(\sprintf('Unsupported format, expects "%s", but "%s" given.', implode('", "', (array) $attribute->acceptFormat), $format));
203203
}
204204

205205
if ('array' === $argument->getType() && null !== $attribute->type) {
@@ -223,11 +223,11 @@ private function mapRequestPayload(Request $request, ArgumentMetadata $argument,
223223
try {
224224
return $this->serializer->deserialize($data, $type, $format, self::CONTEXT_DESERIALIZE + $attribute->serializationContext);
225225
} catch (UnsupportedFormatException $e) {
226-
throw new UnsupportedMediaTypeHttpException(sprintf('Unsupported format: "%s".', $format), $e);
226+
throw new UnsupportedMediaTypeHttpException(\sprintf('Unsupported format: "%s".', $format), $e);
227227
} catch (NotEncodableValueException $e) {
228-
throw new BadRequestHttpException(sprintf('Request payload contains invalid "%s" data.', $format), $e);
228+
throw new BadRequestHttpException(\sprintf('Request payload contains invalid "%s" data.', $format), $e);
229229
} catch (UnexpectedPropertyException $e) {
230-
throw new BadRequestHttpException(sprintf('Request payload contains invalid "%s" property.', $e->property), $e);
230+
throw new BadRequestHttpException(\sprintf('Request payload contains invalid "%s" property.', $e->property), $e);
231231
}
232232
}
233233

Controller/ArgumentResolver/RequestValueResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function resolve(Request $request, ArgumentMetadata $argument): array
3030
}
3131

3232
if (str_ends_with($argument->getType() ?? '', '\\Request')) {
33-
throw new NearMissValueResolverException(sprintf('Looks like you required a Request object with the wrong class name "%s". Did you mean to use "%s" instead?', $argument->getType(), Request::class));
33+
throw new NearMissValueResolverException(\sprintf('Looks like you required a Request object with the wrong class name "%s". Did you mean to use "%s" instead?', $argument->getType(), Request::class));
3434
}
3535

3636
return [];

Controller/ArgumentResolver/ServiceValueResolver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ public function resolve(Request $request, ArgumentMetadata $argument): array
5656
return [$this->container->get($controller)->get($argument->getName())];
5757
} catch (RuntimeException $e) {
5858
$what = 'argument $'.$argument->getName();
59-
$message = str_replace(sprintf('service "%s"', $argument->getName()), $what, $e->getMessage());
60-
$what .= sprintf(' of "%s()"', $controller);
59+
$message = str_replace(\sprintf('service "%s"', $argument->getName()), $what, $e->getMessage());
60+
$what .= \sprintf(' of "%s()"', $controller);
6161
$message = preg_replace('/service "\.service_locator\.[^"]++"/', $what, $message);
6262

6363
if ($e->getMessage() === $message) {
64-
$message = sprintf('Cannot resolve %s: %s', $what, $message);
64+
$message = \sprintf('Cannot resolve %s: %s', $what, $message);
6565
}
6666

6767
throw new NearMissValueResolverException($message, $e->getCode(), $e);

Controller/ArgumentResolver/UidValueResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function resolve(Request $request, ArgumentMetadata $argument): array
3232
try {
3333
return [$uidClass::fromString($value)];
3434
} catch (\InvalidArgumentException $e) {
35-
throw new NotFoundHttpException(sprintf('The uid for the "%s" parameter is invalid.', $argument->getName()), $e);
35+
throw new NotFoundHttpException(\sprintf('The uid for the "%s" parameter is invalid.', $argument->getName()), $e);
3636
}
3737
}
3838
}

Controller/ArgumentResolver/VariadicValueResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function resolve(Request $request, ArgumentMetadata $argument): array
3131
$values = $request->attributes->get($argument->getName());
3232

3333
if (!\is_array($values)) {
34-
throw new \InvalidArgumentException(sprintf('The action argument "...$%1$s" is required to be an array, the request attribute "%1$s" contains a type of "%2$s" instead.', $argument->getName(), get_debug_type($values)));
34+
throw new \InvalidArgumentException(\sprintf('The action argument "...$%1$s" is required to be an array, the request attribute "%1$s" contains a type of "%2$s" instead.', $argument->getName(), get_debug_type($values)));
3535
}
3636

3737
return $values;

Controller/ContainerControllerResolver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ protected function instantiateController(string $class): object
4646
$this->throwExceptionIfControllerWasRemoved($class, $e);
4747

4848
if ($e instanceof \ArgumentCountError) {
49-
throw new \InvalidArgumentException(sprintf('Controller "%s" has required constructor arguments and does not exist in the container. Did you forget to define the controller as a service?', $class), 0, $e);
49+
throw new \InvalidArgumentException(\sprintf('Controller "%s" has required constructor arguments and does not exist in the container. Did you forget to define the controller as a service?', $class), 0, $e);
5050
}
5151

52-
throw new \InvalidArgumentException(sprintf('Controller "%s" does neither exist as service nor as class.', $class), 0, $e);
52+
throw new \InvalidArgumentException(\sprintf('Controller "%s" does neither exist as service nor as class.', $class), 0, $e);
5353
}
5454

5555
private function throwExceptionIfControllerWasRemoved(string $controller, \Throwable $previous): void
5656
{
5757
if ($this->container instanceof Container && isset($this->container->getRemovedIds()[$controller])) {
58-
throw new \InvalidArgumentException(sprintf('Controller "%s" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?', $controller), 0, $previous);
58+
throw new \InvalidArgumentException(\sprintf('Controller "%s" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?', $controller), 0, $previous);
5959
}
6060
}
6161
}

0 commit comments

Comments
 (0)