Skip to content

Commit 044d555

Browse files
committed
Prefix all sprintf() calls
1 parent 8d43e17 commit 044d555

Some content is hidden

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

41 files changed

+95
-95
lines changed

BinaryFileResponse.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,13 @@ public function prepare(Request $request): static
256256
$end = min($end, $fileSize - 1);
257257
if ($start < 0 || $start > $end) {
258258
$this->setStatusCode(416);
259-
$this->headers->set('Content-Range', sprintf('bytes */%s', $fileSize));
259+
$this->headers->set('Content-Range', \sprintf('bytes */%s', $fileSize));
260260
} elseif ($end - $start < $fileSize - 1) {
261261
$this->maxlen = $end < $fileSize ? $end - $start + 1 : -1;
262262
$this->offset = $start;
263263

264264
$this->setStatusCode(206);
265-
$this->headers->set('Content-Range', sprintf('bytes %s-%s/%s', $start, $end, $fileSize));
265+
$this->headers->set('Content-Range', \sprintf('bytes %s-%s/%s', $start, $end, $fileSize));
266266
$this->headers->set('Content-Length', $end - $start + 1);
267267
}
268268
}

Cookie.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function __construct(
101101
) {
102102
// from PHP source code
103103
if ($raw && false !== strpbrk($name, self::RESERVED_CHARS_LIST)) {
104-
throw new \InvalidArgumentException(sprintf('The cookie name "%s" contains invalid characters.', $name));
104+
throw new \InvalidArgumentException(\sprintf('The cookie name "%s" contains invalid characters.', $name));
105105
}
106106

107107
if (!$name) {
@@ -204,7 +204,7 @@ public function withHttpOnly(bool $httpOnly = true): static
204204
public function withRaw(bool $raw = true): static
205205
{
206206
if ($raw && false !== strpbrk($this->name, self::RESERVED_CHARS_LIST)) {
207-
throw new \InvalidArgumentException(sprintf('The cookie name "%s" contains invalid characters.', $this->name));
207+
throw new \InvalidArgumentException(\sprintf('The cookie name "%s" contains invalid characters.', $this->name));
208208
}
209209

210210
$cookie = clone $this;

File/Exception/AccessDeniedException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ class AccessDeniedException extends FileException
2020
{
2121
public function __construct(string $path)
2222
{
23-
parent::__construct(sprintf('The file %s could not be accessed', $path));
23+
parent::__construct(\sprintf('The file %s could not be accessed', $path));
2424
}
2525
}

File/Exception/FileNotFoundException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ class FileNotFoundException extends FileException
2020
{
2121
public function __construct(string $path)
2222
{
23-
parent::__construct(sprintf('The file "%s" does not exist', $path));
23+
parent::__construct(\sprintf('The file "%s" does not exist', $path));
2424
}
2525
}

File/Exception/UnexpectedTypeException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ class UnexpectedTypeException extends FileException
1515
{
1616
public function __construct(mixed $value, string $expectedType)
1717
{
18-
parent::__construct(sprintf('Expected argument of type %s, %s given', $expectedType, get_debug_type($value)));
18+
parent::__construct(\sprintf('Expected argument of type %s, %s given', $expectedType, get_debug_type($value)));
1919
}
2020
}

File/File.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function move(string $directory, ?string $name = null): self
9393
restore_error_handler();
9494
}
9595
if (!$renamed) {
96-
throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s).', $this->getPathname(), $target, strip_tags($error)));
96+
throw new FileException(\sprintf('Could not move the file "%s" to "%s" (%s).', $this->getPathname(), $target, strip_tags($error)));
9797
}
9898

9999
@chmod($target, 0666 & ~umask());
@@ -106,7 +106,7 @@ public function getContent(): string
106106
$content = file_get_contents($this->getPathname());
107107

108108
if (false === $content) {
109-
throw new FileException(sprintf('Could not get the content of the file "%s".', $this->getPathname()));
109+
throw new FileException(\sprintf('Could not get the content of the file "%s".', $this->getPathname()));
110110
}
111111

112112
return $content;
@@ -116,10 +116,10 @@ protected function getTargetFile(string $directory, ?string $name = null): self
116116
{
117117
if (!is_dir($directory)) {
118118
if (false === @mkdir($directory, 0777, true) && !is_dir($directory)) {
119-
throw new FileException(sprintf('Unable to create the "%s" directory.', $directory));
119+
throw new FileException(\sprintf('Unable to create the "%s" directory.', $directory));
120120
}
121121
} elseif (!is_writable($directory)) {
122-
throw new FileException(sprintf('Unable to write in the "%s" directory.', $directory));
122+
throw new FileException(\sprintf('Unable to write in the "%s" directory.', $directory));
123123
}
124124

125125
$target = rtrim($directory, '/\\').\DIRECTORY_SEPARATOR.(null === $name ? $this->getBasename() : $this->getName($name));

File/UploadedFile.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public function move(string $directory, ?string $name = null): File
194194
restore_error_handler();
195195
}
196196
if (!$moved) {
197-
throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s).', $this->getPathname(), $target, strip_tags($error)));
197+
throw new FileException(\sprintf('Could not move the file "%s" to "%s" (%s).', $this->getPathname(), $target, strip_tags($error)));
198198
}
199199

200200
@chmod($target, 0666 & ~umask());
@@ -284,6 +284,6 @@ public function getErrorMessage(): string
284284
$maxFilesize = \UPLOAD_ERR_INI_SIZE === $errorCode ? self::getMaxFilesize() / 1024 : 0;
285285
$message = $errors[$errorCode] ?? 'The file "%s" was not uploaded due to an unknown error.';
286286

287-
return sprintf($message, $this->getClientOriginalName(), $maxFilesize);
287+
return \sprintf($message, $this->getClientOriginalName(), $maxFilesize);
288288
}
289289
}

HeaderBag.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function __toString(): string
5151
foreach ($headers as $name => $values) {
5252
$name = ucwords($name, '-');
5353
foreach ($values as $value) {
54-
$content .= sprintf("%-{$max}s %s\r\n", $name.':', $value);
54+
$content .= \sprintf("%-{$max}s %s\r\n", $name.':', $value);
5555
}
5656
}
5757

@@ -194,7 +194,7 @@ public function getDate(string $key, ?\DateTimeInterface $default = null): ?\Dat
194194
}
195195

196196
if (false === $date = \DateTimeImmutable::createFromFormat(\DATE_RFC2822, $value)) {
197-
throw new \RuntimeException(sprintf('The "%s" HTTP header is not parseable (%s).', $key, $value));
197+
throw new \RuntimeException(\sprintf('The "%s" HTTP header is not parseable (%s).', $key, $value));
198198
}
199199

200200
return $date;

HeaderUtils.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public static function unquote(string $s): string
165165
public static function makeDisposition(string $disposition, string $filename, string $filenameFallback = ''): string
166166
{
167167
if (!\in_array($disposition, [self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE])) {
168-
throw new \InvalidArgumentException(sprintf('The disposition must be either "%s" or "%s".', self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE));
168+
throw new \InvalidArgumentException(\sprintf('The disposition must be either "%s" or "%s".', self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE));
169169
}
170170

171171
if ('' === $filenameFallback) {

InputBag.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ final class InputBag extends ParameterBag
2929
public function get(string $key, mixed $default = null): string|int|float|bool|null
3030
{
3131
if (null !== $default && !\is_scalar($default) && !$default instanceof \Stringable) {
32-
throw new \InvalidArgumentException(sprintf('Expected a scalar value as a 2nd argument to "%s()", "%s" given.', __METHOD__, get_debug_type($default)));
32+
throw new \InvalidArgumentException(\sprintf('Expected a scalar value as a 2nd argument to "%s()", "%s" given.', __METHOD__, get_debug_type($default)));
3333
}
3434

3535
$value = parent::get($key, $this);
3636

3737
if (null !== $value && $this !== $value && !\is_scalar($value) && !$value instanceof \Stringable) {
38-
throw new BadRequestException(sprintf('Input value "%s" contains a non-scalar value.', $key));
38+
throw new BadRequestException(\sprintf('Input value "%s" contains a non-scalar value.', $key));
3939
}
4040

4141
return $this === $value ? $default : $value;
@@ -68,7 +68,7 @@ public function add(array $inputs = []): void
6868
public function set(string $key, mixed $value): void
6969
{
7070
if (null !== $value && !\is_scalar($value) && !\is_array($value) && !$value instanceof \Stringable) {
71-
throw new \InvalidArgumentException(sprintf('Expected a scalar, or an array as a 2nd argument to "%s()", "%s" given.', __METHOD__, get_debug_type($value)));
71+
throw new \InvalidArgumentException(\sprintf('Expected a scalar, or an array as a 2nd argument to "%s()", "%s" given.', __METHOD__, get_debug_type($value)));
7272
}
7373

7474
$this->parameters[$key] = $value;
@@ -114,11 +114,11 @@ public function filter(string $key, mixed $default = null, int $filter = \FILTER
114114
}
115115

116116
if (\is_array($value) && !(($options['flags'] ?? 0) & (\FILTER_REQUIRE_ARRAY | \FILTER_FORCE_ARRAY))) {
117-
throw new BadRequestException(sprintf('Input value "%s" contains an array, but "FILTER_REQUIRE_ARRAY" or "FILTER_FORCE_ARRAY" flags were not set.', $key));
117+
throw new BadRequestException(\sprintf('Input value "%s" contains an array, but "FILTER_REQUIRE_ARRAY" or "FILTER_FORCE_ARRAY" flags were not set.', $key));
118118
}
119119

120120
if ((\FILTER_CALLBACK & $filter) && !(($options['options'] ?? null) instanceof \Closure)) {
121-
throw new \InvalidArgumentException(sprintf('A Closure must be passed to "%s()" when FILTER_CALLBACK is used, "%s" given.', __METHOD__, get_debug_type($options['options'] ?? null)));
121+
throw new \InvalidArgumentException(\sprintf('A Closure must be passed to "%s()" when FILTER_CALLBACK is used, "%s" given.', __METHOD__, get_debug_type($options['options'] ?? null)));
122122
}
123123

124124
$options['flags'] ??= 0;
@@ -131,6 +131,6 @@ public function filter(string $key, mixed $default = null, int $filter = \FILTER
131131
return $value;
132132
}
133133

134-
throw new BadRequestException(sprintf('Input value "%s" is invalid and flag "FILTER_NULL_ON_FAILURE" was not set.', $key));
134+
throw new BadRequestException(\sprintf('Input value "%s" is invalid and flag "FILTER_NULL_ON_FAILURE" was not set.', $key));
135135
}
136136
}

IpUtils.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public static function checkIp4(string $requestIp, string $ip): bool
102102
return self::setCacheResult($cacheKey, false);
103103
}
104104

105-
return self::setCacheResult($cacheKey, 0 === substr_compare(sprintf('%032b', ip2long($requestIp)), sprintf('%032b', ip2long($address)), 0, $netmask));
105+
return self::setCacheResult($cacheKey, 0 === substr_compare(\sprintf('%032b', ip2long($requestIp)), \sprintf('%032b', ip2long($address)), 0, $netmask));
106106
}
107107

108108
/**

JsonResponse.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(mixed $data = null, int $status = 200, array $header
4141
parent::__construct('', $status, $headers);
4242

4343
if ($json && !\is_string($data) && !is_numeric($data) && !\is_callable([$data, '__toString'])) {
44-
throw new \TypeError(sprintf('"%s": If $json is set to true, argument $data must be a string or object implementing __toString(), "%s" given.', __METHOD__, get_debug_type($data)));
44+
throw new \TypeError(\sprintf('"%s": If $json is set to true, argument $data must be a string or object implementing __toString(), "%s" given.', __METHOD__, get_debug_type($data)));
4545
}
4646

4747
$data ??= new \ArrayObject();
@@ -173,7 +173,7 @@ protected function update(): static
173173
// Not using application/javascript for compatibility reasons with older browsers.
174174
$this->headers->set('Content-Type', 'text/javascript');
175175

176-
return $this->setContent(sprintf('/**/%s(%s);', $this->callback, $this->data));
176+
return $this->setContent(\sprintf('/**/%s(%s);', $this->callback, $this->data));
177177
}
178178

179179
// Only set the header when there is none or when it equals 'text/javascript' (from a previous update with callback)

ParameterBag.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function all(?string $key = null): array
4040
}
4141

4242
if (!\is_array($value = $this->parameters[$key] ?? [])) {
43-
throw new BadRequestException(sprintf('Unexpected value for parameter "%s": expecting "array", got "%s".', $key, get_debug_type($value)));
43+
throw new BadRequestException(\sprintf('Unexpected value for parameter "%s": expecting "array", got "%s".', $key, get_debug_type($value)));
4444
}
4545

4646
return $value;
@@ -127,7 +127,7 @@ public function getString(string $key, string $default = ''): string
127127
{
128128
$value = $this->get($key, $default);
129129
if (!\is_scalar($value) && !$value instanceof \Stringable) {
130-
throw new UnexpectedValueException(sprintf('Parameter value "%s" cannot be converted to "string".', $key));
130+
throw new UnexpectedValueException(\sprintf('Parameter value "%s" cannot be converted to "string".', $key));
131131
}
132132

133133
return (string) $value;
@@ -172,7 +172,7 @@ public function getEnum(string $key, string $class, ?\BackedEnum $default = null
172172
try {
173173
return $class::from($value);
174174
} catch (\ValueError|\TypeError $e) {
175-
throw new UnexpectedValueException(sprintf('Parameter "%s" cannot be converted to enum: %s.', $key, $e->getMessage()), $e->getCode(), $e);
175+
throw new UnexpectedValueException(\sprintf('Parameter "%s" cannot be converted to enum: %s.', $key, $e->getMessage()), $e->getCode(), $e);
176176
}
177177
}
178178

@@ -199,11 +199,11 @@ public function filter(string $key, mixed $default = null, int $filter = \FILTER
199199
}
200200

201201
if (\is_object($value) && !$value instanceof \Stringable) {
202-
throw new UnexpectedValueException(sprintf('Parameter value "%s" cannot be filtered.', $key));
202+
throw new UnexpectedValueException(\sprintf('Parameter value "%s" cannot be filtered.', $key));
203203
}
204204

205205
if ((\FILTER_CALLBACK & $filter) && !(($options['options'] ?? null) instanceof \Closure)) {
206-
throw new \InvalidArgumentException(sprintf('A Closure must be passed to "%s()" when FILTER_CALLBACK is used, "%s" given.', __METHOD__, get_debug_type($options['options'] ?? null)));
206+
throw new \InvalidArgumentException(\sprintf('A Closure must be passed to "%s()" when FILTER_CALLBACK is used, "%s" given.', __METHOD__, get_debug_type($options['options'] ?? null)));
207207
}
208208

209209
$options['flags'] ??= 0;
@@ -216,7 +216,7 @@ public function filter(string $key, mixed $default = null, int $filter = \FILTER
216216
return $value;
217217
}
218218

219-
throw new \UnexpectedValueException(sprintf('Parameter value "%s" is invalid and flag "FILTER_NULL_ON_FAILURE" was not set.', $key));
219+
throw new \UnexpectedValueException(\sprintf('Parameter value "%s" is invalid and flag "FILTER_NULL_ON_FAILURE" was not set.', $key));
220220
}
221221

222222
/**

RedirectResponse.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(string $url, int $status = 302, array $headers = [])
3939
$this->setTargetUrl($url);
4040

4141
if (!$this->isRedirect()) {
42-
throw new \InvalidArgumentException(sprintf('The HTTP status code is not a redirect ("%s" given).', $status));
42+
throw new \InvalidArgumentException(\sprintf('The HTTP status code is not a redirect ("%s" given).', $status));
4343
}
4444

4545
if (301 == $status && !\array_key_exists('cache-control', array_change_key_case($headers, \CASE_LOWER))) {
@@ -71,7 +71,7 @@ public function setTargetUrl(string $url): static
7171
$this->targetUrl = $url;
7272

7373
$this->setContent(
74-
sprintf('<!DOCTYPE html>
74+
\sprintf('<!DOCTYPE html>
7575
<html>
7676
<head>
7777
<meta charset="UTF-8" />

0 commit comments

Comments
 (0)