Skip to content

Commit a06315e

Browse files
committed
Prefix all sprintf() calls
1 parent be90483 commit a06315e

30 files changed

+59
-59
lines changed

Address.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ final class Address
4242
public function __construct(string $address, string $name = '')
4343
{
4444
if (!class_exists(EmailValidator::class)) {
45-
throw new LogicException(sprintf('The "%s" class cannot be used as it needs "%s". Try running "composer require egulias/email-validator".', __CLASS__, EmailValidator::class));
45+
throw new LogicException(\sprintf('The "%s" class cannot be used as it needs "%s". Try running "composer require egulias/email-validator".', __CLASS__, EmailValidator::class));
4646
}
4747

4848
self::$validator ??= new EmailValidator();
@@ -51,7 +51,7 @@ public function __construct(string $address, string $name = '')
5151
$this->name = trim(str_replace(["\n", "\r"], '', $name));
5252

5353
if (!self::$validator->isValid($this->address, class_exists(MessageIDValidation::class) ? new MessageIDValidation() : new RFCValidation())) {
54-
throw new RfcComplianceException(sprintf('Email "%s" does not comply with addr-spec of RFC 2822.', $address));
54+
throw new RfcComplianceException(\sprintf('Email "%s" does not comply with addr-spec of RFC 2822.', $address));
5555
}
5656
}
5757

@@ -83,7 +83,7 @@ public function getEncodedName(): string
8383
return '';
8484
}
8585

86-
return sprintf('"%s"', preg_replace('/"/u', '\"', $this->getName()));
86+
return \sprintf('"%s"', preg_replace('/"/u', '\"', $this->getName()));
8787
}
8888

8989
public static function create(self|string $address): self
@@ -97,7 +97,7 @@ public static function create(self|string $address): self
9797
}
9898

9999
if (!preg_match(self::FROM_STRING_PATTERN, $address, $matches)) {
100-
throw new InvalidArgumentException(sprintf('Could not parse "%s" to a "%s" instance.', $address, self::class));
100+
throw new InvalidArgumentException(\sprintf('Could not parse "%s" to a "%s" instance.', $address, self::class));
101101
}
102102

103103
return new self($matches['addrSpec'], trim($matches['displayName'], ' \'"'));

Crypto/DkimSigner.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function sign(Message $message, array $options = []): Message
6262
{
6363
$options += $this->defaultOptions;
6464
if (!\in_array($options['algorithm'], [self::ALGO_SHA256, self::ALGO_ED25519], true)) {
65-
throw new InvalidArgumentException(sprintf('Invalid DKIM signing algorithm "%s".', $options['algorithm']));
65+
throw new InvalidArgumentException(\sprintf('Invalid DKIM signing algorithm "%s".', $options['algorithm']));
6666
}
6767
$headersToIgnore['return-path'] = true;
6868
$headersToIgnore['x-transport'] = true;
@@ -119,7 +119,7 @@ public function sign(Message $message, array $options = []): Message
119119
throw new RuntimeException('Unable to sign DKIM hash: '.openssl_error_string());
120120
}
121121
} else {
122-
throw new \RuntimeException(sprintf('The "%s" DKIM signing algorithm is not supported yet.', self::ALGO_ED25519));
122+
throw new \RuntimeException(\sprintf('The "%s" DKIM signing algorithm is not supported yet.', self::ALGO_ED25519));
123123
}
124124
$header->setValue($value.' b='.trim(chunk_split(base64_encode($signature), 73, ' ')));
125125
$headers->add($header);

Crypto/SMime.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ abstract class SMime
2424
protected function normalizeFilePath(string $path): string
2525
{
2626
if (!file_exists($path)) {
27-
throw new RuntimeException(sprintf('File does not exist: "%s".', $path));
27+
throw new RuntimeException(\sprintf('File does not exist: "%s".', $path));
2828
}
2929

3030
return 'file://'.str_replace('\\', '/', realpath($path));

Crypto/SMimeEncrypter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function encrypt(Message $message): Message
4949
$this->iteratorToFile($message->toIterable(), $bufferFile);
5050

5151
if (!@openssl_pkcs7_encrypt(stream_get_meta_data($bufferFile)['uri'], stream_get_meta_data($outputFile)['uri'], $this->certs, [], 0, $this->cipher)) {
52-
throw new RuntimeException(sprintf('Failed to encrypt S/Mime message. Error: "%s".', openssl_error_string()));
52+
throw new RuntimeException(\sprintf('Failed to encrypt S/Mime message. Error: "%s".', openssl_error_string()));
5353
}
5454

5555
$mimePart = $this->convertMessageToSMimePart($outputFile, 'application', 'pkcs7-mime');

Crypto/SMimeSigner.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function sign(Message $message): Message
5757
$this->iteratorToFile($message->getBody()->toIterable(), $bufferFile);
5858

5959
if (!@openssl_pkcs7_sign(stream_get_meta_data($bufferFile)['uri'], stream_get_meta_data($outputFile)['uri'], $this->signCertificate, $this->signPrivateKey, [], $this->signOptions, $this->extraCerts)) {
60-
throw new RuntimeException(sprintf('Failed to sign S/Mime message. Error: "%s".', openssl_error_string()));
60+
throw new RuntimeException(\sprintf('Failed to sign S/Mime message. Error: "%s".', openssl_error_string()));
6161
}
6262

6363
return new Message($message->getHeaders(), $this->convertMessageToSMimePart($outputFile, 'multipart', 'signed'));

Email.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public function priority(int $priority): static
246246
$priority = 1;
247247
}
248248

249-
return $this->setHeaderBody('Text', 'X-Priority', sprintf('%d (%s)', $priority, self::PRIORITY_MAP[$priority]));
249+
return $this->setHeaderBody('Text', 'X-Priority', \sprintf('%d (%s)', $priority, self::PRIORITY_MAP[$priority]));
250250
}
251251

252252
/**
@@ -270,7 +270,7 @@ public function getPriority(): int
270270
public function text($body, string $charset = 'utf-8'): static
271271
{
272272
if (null !== $body && !\is_string($body) && !\is_resource($body)) {
273-
throw new \TypeError(sprintf('The body must be a string, a resource or null (got "%s").', get_debug_type($body)));
273+
throw new \TypeError(\sprintf('The body must be a string, a resource or null (got "%s").', get_debug_type($body)));
274274
}
275275

276276
$this->cachedBody = null;
@@ -301,7 +301,7 @@ public function getTextCharset(): ?string
301301
public function html($body, string $charset = 'utf-8'): static
302302
{
303303
if (null !== $body && !\is_string($body) && !\is_resource($body)) {
304-
throw new \TypeError(sprintf('The body must be a string, a resource or null (got "%s").', get_debug_type($body)));
304+
throw new \TypeError(\sprintf('The body must be a string, a resource or null (got "%s").', get_debug_type($body)));
305305
}
306306

307307
$this->cachedBody = null;

Encoder/Base64ContentEncoder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class Base64ContentEncoder extends Base64Encoder implements ContentEncoder
2121
public function encodeByteStream($stream, int $maxLineLength = 0): iterable
2222
{
2323
if (!\is_resource($stream)) {
24-
throw new \TypeError(sprintf('Method "%s" takes a stream as a first argument.', __METHOD__));
24+
throw new \TypeError(\sprintf('Method "%s" takes a stream as a first argument.', __METHOD__));
2525
}
2626

2727
$filter = stream_filter_append($stream, 'convert.base64-encode', \STREAM_FILTER_READ, [

Encoder/IdnAddressEncoder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function encodeString(string $address): string
3535
$domain = substr($address, $i + 1);
3636

3737
if (preg_match('/[^\x00-\x7F]/', $domain)) {
38-
$address = sprintf('%s@%s', $local, idn_to_ascii($domain, \IDNA_DEFAULT | \IDNA_USE_STD3_RULES | \IDNA_CHECK_BIDI | \IDNA_CHECK_CONTEXTJ | \IDNA_NONTRANSITIONAL_TO_ASCII, \INTL_IDNA_VARIANT_UTS46));
38+
$address = \sprintf('%s@%s', $local, idn_to_ascii($domain, \IDNA_DEFAULT | \IDNA_USE_STD3_RULES | \IDNA_CHECK_BIDI | \IDNA_CHECK_CONTEXTJ | \IDNA_NONTRANSITIONAL_TO_ASCII, \INTL_IDNA_VARIANT_UTS46));
3939
}
4040
}
4141

Encoder/QpContentEncoder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class QpContentEncoder implements ContentEncoderInterface
1919
public function encodeByteStream($stream, int $maxLineLength = 0): iterable
2020
{
2121
if (!\is_resource($stream)) {
22-
throw new \TypeError(sprintf('Method "%s" takes a stream as a first argument.', __METHOD__));
22+
throw new \TypeError(\sprintf('Method "%s" takes a stream as a first argument.', __METHOD__));
2323
}
2424

2525
// we don't use PHP stream filters here as the content should be small enough

FileBinaryMimeTypeGuesser.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ public function isGuesserSupported(): bool
5656
public function guessMimeType(string $path): ?string
5757
{
5858
if (!is_file($path) || !is_readable($path)) {
59-
throw new InvalidArgumentException(sprintf('The "%s" file does not exist or is not readable.', $path));
59+
throw new InvalidArgumentException(\sprintf('The "%s" file does not exist or is not readable.', $path));
6060
}
6161

6262
if (!$this->isGuesserSupported()) {
63-
throw new LogicException(sprintf('The "%s" guesser is not supported.', __CLASS__));
63+
throw new LogicException(\sprintf('The "%s" guesser is not supported.', __CLASS__));
6464
}
6565

6666
ob_start();
6767

6868
// need to use --mime instead of -i. see #6641
69-
passthru(sprintf($this->cmd, escapeshellarg((str_starts_with($path, '-') ? './' : '').$path)), $return);
69+
passthru(\sprintf($this->cmd, escapeshellarg((str_starts_with($path, '-') ? './' : '').$path)), $return);
7070
if ($return > 0) {
7171
ob_end_clean();
7272

FileinfoMimeTypeGuesser.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ public function isGuesserSupported(): bool
3939
public function guessMimeType(string $path): ?string
4040
{
4141
if (!is_file($path) || !is_readable($path)) {
42-
throw new InvalidArgumentException(sprintf('The "%s" file does not exist or is not readable.', $path));
42+
throw new InvalidArgumentException(\sprintf('The "%s" file does not exist or is not readable.', $path));
4343
}
4444

4545
if (!$this->isGuesserSupported()) {
46-
throw new LogicException(sprintf('The "%s" guesser is not supported.', __CLASS__));
46+
throw new LogicException(\sprintf('The "%s" guesser is not supported.', __CLASS__));
4747
}
4848

4949
if (false === $finfo = new \finfo(\FILEINFO_MIME_TYPE, $this->magicFile)) {

Header/Headers.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function add(HeaderInterface $header): static
170170
$name = strtolower($header->getName());
171171

172172
if (\in_array($name, self::UNIQUE_HEADERS, true) && isset($this->headers[$name]) && \count($this->headers[$name]) > 0) {
173-
throw new LogicException(sprintf('Impossible to set header "%s" as it\'s already defined and must be unique.', $header->getName()));
173+
throw new LogicException(\sprintf('Impossible to set header "%s" as it\'s already defined and must be unique.', $header->getName()));
174174
}
175175

176176
$this->headers[$name][] = $header;
@@ -241,7 +241,7 @@ public static function checkHeaderClass(HeaderInterface $header): void
241241
}
242242
}
243243

244-
throw new LogicException(sprintf('The "%s" header must be an instance of "%s" (got "%s").', $header->getName(), implode('" or "', $headerClasses), get_debug_type($header)));
244+
throw new LogicException(\sprintf('The "%s" header must be an instance of "%s" (got "%s").', $header->getName(), implode('" or "', $headerClasses), get_debug_type($header)));
245245
}
246246

247247
public function toString(): string
@@ -291,7 +291,7 @@ public function getHeaderParameter(string $name, string $parameter): ?string
291291

292292
$header = $this->get($name);
293293
if (!$header instanceof ParameterizedHeader) {
294-
throw new LogicException(sprintf('Unable to get parameter "%s" on header "%s" as the header is not of class "%s".', $parameter, $name, ParameterizedHeader::class));
294+
throw new LogicException(\sprintf('Unable to get parameter "%s" on header "%s" as the header is not of class "%s".', $parameter, $name, ParameterizedHeader::class));
295295
}
296296

297297
return $header->getParameter($parameter);
@@ -303,12 +303,12 @@ public function getHeaderParameter(string $name, string $parameter): ?string
303303
public function setHeaderParameter(string $name, string $parameter, ?string $value): void
304304
{
305305
if (!$this->has($name)) {
306-
throw new LogicException(sprintf('Unable to set parameter "%s" on header "%s" as the header is not defined.', $parameter, $name));
306+
throw new LogicException(\sprintf('Unable to set parameter "%s" on header "%s" as the header is not defined.', $parameter, $name));
307307
}
308308

309309
$header = $this->get($name);
310310
if (!$header instanceof ParameterizedHeader) {
311-
throw new LogicException(sprintf('Unable to set parameter "%s" on header "%s" as the header is not of class "%s".', $parameter, $name, ParameterizedHeader::class));
311+
throw new LogicException(\sprintf('Unable to set parameter "%s" on header "%s" as the header is not of class "%s".', $parameter, $name, ParameterizedHeader::class));
312312
}
313313

314314
$header->setParameter($parameter, $value);

MessageConverter.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ public static function toEmail(Message $message): Email
5555
} elseif ($parts[0] instanceof TextPart) {
5656
$email = self::createEmailFromTextPart($message, $parts[0]);
5757
} else {
58-
throw new RuntimeException(sprintf('Unable to create an Email from an instance of "%s" as the body is too complex.', get_debug_type($message)));
58+
throw new RuntimeException(\sprintf('Unable to create an Email from an instance of "%s" as the body is too complex.', get_debug_type($message)));
5959
}
6060

6161
return self::addParts($email, \array_slice($parts, 1));
6262
}
6363

64-
throw new RuntimeException(sprintf('Unable to create an Email from an instance of "%s" as the body is too complex.', get_debug_type($message)));
64+
throw new RuntimeException(\sprintf('Unable to create an Email from an instance of "%s" as the body is too complex.', get_debug_type($message)));
6565
}
6666

6767
private static function createEmailFromTextPart(Message $message, TextPart $part): Email
@@ -73,7 +73,7 @@ private static function createEmailFromTextPart(Message $message, TextPart $part
7373
return (new Email(clone $message->getHeaders()))->html($part->getBody(), $part->getPreparedHeaders()->getHeaderParameter('Content-Type', 'charset') ?: 'utf-8');
7474
}
7575

76-
throw new RuntimeException(sprintf('Unable to create an Email from an instance of "%s" as the body is too complex.', get_debug_type($message)));
76+
throw new RuntimeException(\sprintf('Unable to create an Email from an instance of "%s" as the body is too complex.', get_debug_type($message)));
7777
}
7878

7979
private static function createEmailFromAlternativePart(Message $message, AlternativePart $part): Email
@@ -90,7 +90,7 @@ private static function createEmailFromAlternativePart(Message $message, Alterna
9090
;
9191
}
9292

93-
throw new RuntimeException(sprintf('Unable to create an Email from an instance of "%s" as the body is too complex.', get_debug_type($message)));
93+
throw new RuntimeException(\sprintf('Unable to create an Email from an instance of "%s" as the body is too complex.', get_debug_type($message)));
9494
}
9595

9696
private static function createEmailFromRelatedPart(Message $message, RelatedPart $part): Email
@@ -101,7 +101,7 @@ private static function createEmailFromRelatedPart(Message $message, RelatedPart
101101
} elseif ($parts[0] instanceof TextPart) {
102102
$email = self::createEmailFromTextPart($message, $parts[0]);
103103
} else {
104-
throw new RuntimeException(sprintf('Unable to create an Email from an instance of "%s" as the body is too complex.', get_debug_type($message)));
104+
throw new RuntimeException(\sprintf('Unable to create an Email from an instance of "%s" as the body is too complex.', get_debug_type($message)));
105105
}
106106

107107
return self::addParts($email, \array_slice($parts, 1));
@@ -111,7 +111,7 @@ private static function addParts(Email $email, array $parts): Email
111111
{
112112
foreach ($parts as $part) {
113113
if (!$part instanceof DataPart) {
114-
throw new RuntimeException(sprintf('Unable to create an Email from an instance of "%s" as the body is too complex.', get_debug_type($email)));
114+
throw new RuntimeException(\sprintf('Unable to create an Email from an instance of "%s" as the body is too complex.', get_debug_type($email)));
115115
}
116116

117117
$email->addPart($part);

Part/DataPart.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function asInline(): static
6666
public function setContentId(string $cid): static
6767
{
6868
if (!str_contains($cid, '@')) {
69-
throw new InvalidArgumentException(sprintf('The "%s" CID is invalid as it doesn\'t contain an "@".', $cid));
69+
throw new InvalidArgumentException(\sprintf('The "%s" CID is invalid as it doesn\'t contain an "@".', $cid));
7070
}
7171

7272
$this->cid = $cid;

Part/Multipart/FormDataPart.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ private function prepareFields(array $fields): array
5252
$prepare = function ($item, $key, $root = null) use (&$values, &$prepare) {
5353
if (null === $root && \is_int($key) && \is_array($item)) {
5454
if (1 !== \count($item)) {
55-
throw new InvalidArgumentException(sprintf('Form field values with integer keys can only have one array element, the key being the field name and the value being the field value, %d provided.', \count($item)));
55+
throw new InvalidArgumentException(\sprintf('Form field values with integer keys can only have one array element, the key being the field name and the value being the field value, %d provided.', \count($item)));
5656
}
5757

5858
$key = key($item);
5959
$item = $item[$key];
6060
}
6161

62-
$fieldName = null !== $root ? sprintf('%s[%s]', $root, $key) : $key;
62+
$fieldName = null !== $root ? \sprintf('%s[%s]', $root, $key) : $key;
6363

6464
if (\is_array($item)) {
6565
array_walk($item, $prepare, $fieldName);
@@ -68,7 +68,7 @@ private function prepareFields(array $fields): array
6868
}
6969

7070
if (!\is_string($item) && !$item instanceof TextPart) {
71-
throw new InvalidArgumentException(sprintf('The value of the form field "%s" can only be a string, an array, or an instance of TextPart, "%s" given.', $fieldName, get_debug_type($item)));
71+
throw new InvalidArgumentException(\sprintf('The value of the form field "%s" can only be a string, an array, or an instance of TextPart, "%s" given.', $fieldName, get_debug_type($item)));
7272
}
7373

7474
$values[] = $this->preparePart($fieldName, $item);

0 commit comments

Comments
 (0)