From 95f9645b246360f94dfb6df99f9c8a4a666df1f6 Mon Sep 17 00:00:00 2001 From: Benjamin Pick Date: Fri, 4 Jul 2025 21:54:13 +0200 Subject: [PATCH 1/3] Fix php.net links --- Session/Storage/NativeSessionStorage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Session/Storage/NativeSessionStorage.php b/Session/Storage/NativeSessionStorage.php index f63de5740..7b0c5beca 100644 --- a/Session/Storage/NativeSessionStorage.php +++ b/Session/Storage/NativeSessionStorage.php @@ -139,7 +139,7 @@ public function start(): bool * ---------- Part 1 * * The part `[a-zA-Z0-9,-]` is related to the PHP ini directive `session.sid_bits_per_character` defined as 6. - * See https://www.php.net/manual/en/session.configuration.php#ini.session.sid-bits-per-character. + * See https://php.net/session.configuration#ini.session.sid-bits-per-character * Allowed values are integers such as: * - 4 for range `a-f0-9` * - 5 for range `a-v0-9` @@ -148,7 +148,7 @@ public function start(): bool * ---------- Part 2 * * The part `{22,250}` is related to the PHP ini directive `session.sid_length`. - * See https://www.php.net/manual/en/session.configuration.php#ini.session.sid-length. + * See https://php.net/session.configuration#ini.session.sid-length * Allowed values are integers between 22 and 256, but we use 250 for the max. * * Where does the 250 come from? From bc55079ffe0e769739ebaf6576fc696b551a0cf5 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 9 Jul 2025 11:39:35 +0200 Subject: [PATCH 2/3] [HttpFoundation] Fix deprecation in tests on PHP 8.5 --- Tests/StreamedResponseTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/StreamedResponseTest.php b/Tests/StreamedResponseTest.php index fdaee3a35..584353b7f 100644 --- a/Tests/StreamedResponseTest.php +++ b/Tests/StreamedResponseTest.php @@ -32,7 +32,7 @@ public function testConstructorWithChunks() $buffer = ''; ob_start(function (string $chunk) use (&$buffer) { - $buffer .= $chunk; + return $buffer .= $chunk; }); $callback(); From 0341e41d8d8830c31a1dff5cbc5bdb3ec872a073 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 10 Jul 2025 09:12:18 +0200 Subject: [PATCH 3/3] CS fixes --- BinaryFileResponse.php | 4 ++-- Cookie.php | 4 ++-- File/Exception/AccessDeniedException.php | 2 +- File/Exception/FileNotFoundException.php | 2 +- File/Exception/UnexpectedTypeException.php | 2 +- File/File.php | 8 ++++---- File/UploadedFile.php | 4 ++-- HeaderBag.php | 4 ++-- HeaderUtils.php | 2 +- InputBag.php | 10 +++++----- IpUtils.php | 4 ++-- JsonResponse.php | 4 ++-- ParameterBag.php | 10 +++++----- RedirectResponse.php | 4 ++-- Request.php | 16 ++++++++-------- Response.php | 8 ++++---- ResponseHeaderBag.php | 4 ++-- Session/SessionUtils.php | 4 ++-- .../Storage/Handler/AbstractSessionHandler.php | 4 ++-- Session/Storage/Handler/IdentityMarshaller.php | 2 +- .../Storage/Handler/MemcachedSessionHandler.php | 2 +- .../Storage/Handler/NativeFileSessionHandler.php | 4 ++-- Session/Storage/Handler/PdoSessionHandler.php | 12 ++++++------ Session/Storage/Handler/RedisSessionHandler.php | 2 +- .../Storage/Handler/SessionHandlerFactory.php | 4 ++-- Session/Storage/Handler/StrictSessionHandler.php | 2 +- Session/Storage/MockArraySessionStorage.php | 2 +- Session/Storage/MockFileSessionStorage.php | 2 +- Session/Storage/NativeSessionStorage.php | 6 +++--- Test/Constraint/RequestAttributeValueSame.php | 2 +- Test/Constraint/ResponseCookieValueSame.php | 8 ++++---- Test/Constraint/ResponseHasCookie.php | 6 +++--- Test/Constraint/ResponseHasHeader.php | 2 +- Test/Constraint/ResponseHeaderLocationSame.php | 4 ++-- Test/Constraint/ResponseHeaderSame.php | 2 +- Tests/InputBagTest.php | 4 ++-- Tests/JsonResponseTest.php | 2 +- Tests/ParameterBagTest.php | 10 +++++----- Tests/RequestTest.php | 2 +- Tests/ResponseFunctionalTest.php | 4 ++-- Tests/ResponseTest.php | 6 +++--- Tests/Session/Flash/AutoExpireFlashBagTest.php | 12 ++++++------ Tests/Session/Flash/FlashBagTest.php | 4 ++-- .../Handler/AbstractSessionHandlerTest.php | 4 ++-- .../Storage/Handler/IdentityMarshallerTest.php | 2 +- .../Handler/MongoDbSessionHandlerTest.php | 2 +- .../Session/Storage/Proxy/AbstractProxyTest.php | 2 +- Tests/StreamedJsonResponseTest.php | 6 +++--- 48 files changed, 111 insertions(+), 111 deletions(-) diff --git a/BinaryFileResponse.php b/BinaryFileResponse.php index c22f283cb..2c14d3668 100644 --- a/BinaryFileResponse.php +++ b/BinaryFileResponse.php @@ -259,13 +259,13 @@ public function prepare(Request $request): static $end = min($end, $fileSize - 1); if ($start < 0 || $start > $end) { $this->setStatusCode(416); - $this->headers->set('Content-Range', sprintf('bytes */%s', $fileSize)); + $this->headers->set('Content-Range', \sprintf('bytes */%s', $fileSize)); } elseif ($end - $start < $fileSize - 1) { $this->maxlen = $end < $fileSize ? $end - $start + 1 : -1; $this->offset = $start; $this->setStatusCode(206); - $this->headers->set('Content-Range', sprintf('bytes %s-%s/%s', $start, $end, $fileSize)); + $this->headers->set('Content-Range', \sprintf('bytes %s-%s/%s', $start, $end, $fileSize)); $this->headers->set('Content-Length', $end - $start + 1); } } diff --git a/Cookie.php b/Cookie.php index 4a3b73608..05c6c62d5 100644 --- a/Cookie.php +++ b/Cookie.php @@ -101,7 +101,7 @@ public function __construct(string $name, ?string $value = null, int|string|\Dat { // from PHP source code if ($raw && false !== strpbrk($name, self::RESERVED_CHARS_LIST)) { - throw new \InvalidArgumentException(sprintf('The cookie name "%s" contains invalid characters.', $name)); + throw new \InvalidArgumentException(\sprintf('The cookie name "%s" contains invalid characters.', $name)); } if (empty($name)) { @@ -211,7 +211,7 @@ public function withHttpOnly(bool $httpOnly = true): static public function withRaw(bool $raw = true): static { if ($raw && false !== strpbrk($this->name, self::RESERVED_CHARS_LIST)) { - throw new \InvalidArgumentException(sprintf('The cookie name "%s" contains invalid characters.', $this->name)); + throw new \InvalidArgumentException(\sprintf('The cookie name "%s" contains invalid characters.', $this->name)); } $cookie = clone $this; diff --git a/File/Exception/AccessDeniedException.php b/File/Exception/AccessDeniedException.php index 136d2a9f5..79ab0fce3 100644 --- a/File/Exception/AccessDeniedException.php +++ b/File/Exception/AccessDeniedException.php @@ -20,6 +20,6 @@ class AccessDeniedException extends FileException { public function __construct(string $path) { - parent::__construct(sprintf('The file %s could not be accessed', $path)); + parent::__construct(\sprintf('The file %s could not be accessed', $path)); } } diff --git a/File/Exception/FileNotFoundException.php b/File/Exception/FileNotFoundException.php index 31bdf68fe..3a5eb039b 100644 --- a/File/Exception/FileNotFoundException.php +++ b/File/Exception/FileNotFoundException.php @@ -20,6 +20,6 @@ class FileNotFoundException extends FileException { public function __construct(string $path) { - parent::__construct(sprintf('The file "%s" does not exist', $path)); + parent::__construct(\sprintf('The file "%s" does not exist', $path)); } } diff --git a/File/Exception/UnexpectedTypeException.php b/File/Exception/UnexpectedTypeException.php index 905bd5962..09b1c7e18 100644 --- a/File/Exception/UnexpectedTypeException.php +++ b/File/Exception/UnexpectedTypeException.php @@ -15,6 +15,6 @@ class UnexpectedTypeException extends FileException { public function __construct(mixed $value, string $expectedType) { - parent::__construct(sprintf('Expected argument of type %s, %s given', $expectedType, get_debug_type($value))); + parent::__construct(\sprintf('Expected argument of type %s, %s given', $expectedType, get_debug_type($value))); } } diff --git a/File/File.php b/File/File.php index 34ca5a537..c369ecbfb 100644 --- a/File/File.php +++ b/File/File.php @@ -93,7 +93,7 @@ public function move(string $directory, ?string $name = null): self restore_error_handler(); } if (!$renamed) { - throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s).', $this->getPathname(), $target, strip_tags($error))); + throw new FileException(\sprintf('Could not move the file "%s" to "%s" (%s).', $this->getPathname(), $target, strip_tags($error))); } @chmod($target, 0666 & ~umask()); @@ -106,7 +106,7 @@ public function getContent(): string $content = file_get_contents($this->getPathname()); if (false === $content) { - throw new FileException(sprintf('Could not get the content of the file "%s".', $this->getPathname())); + throw new FileException(\sprintf('Could not get the content of the file "%s".', $this->getPathname())); } return $content; @@ -116,10 +116,10 @@ protected function getTargetFile(string $directory, ?string $name = null): self { if (!is_dir($directory)) { if (false === @mkdir($directory, 0777, true) && !is_dir($directory)) { - throw new FileException(sprintf('Unable to create the "%s" directory.', $directory)); + throw new FileException(\sprintf('Unable to create the "%s" directory.', $directory)); } } elseif (!is_writable($directory)) { - throw new FileException(sprintf('Unable to write in the "%s" directory.', $directory)); + throw new FileException(\sprintf('Unable to write in the "%s" directory.', $directory)); } $target = rtrim($directory, '/\\').\DIRECTORY_SEPARATOR.(null === $name ? $this->getBasename() : $this->getName($name)); diff --git a/File/UploadedFile.php b/File/UploadedFile.php index f475d028d..85aab2872 100644 --- a/File/UploadedFile.php +++ b/File/UploadedFile.php @@ -174,7 +174,7 @@ public function move(string $directory, ?string $name = null): File restore_error_handler(); } if (!$moved) { - throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s).', $this->getPathname(), $target, strip_tags($error))); + throw new FileException(\sprintf('Could not move the file "%s" to "%s" (%s).', $this->getPathname(), $target, strip_tags($error))); } @chmod($target, 0666 & ~umask()); @@ -264,6 +264,6 @@ public function getErrorMessage(): string $maxFilesize = \UPLOAD_ERR_INI_SIZE === $errorCode ? self::getMaxFilesize() / 1024 : 0; $message = $errors[$errorCode] ?? 'The file "%s" was not uploaded due to an unknown error.'; - return sprintf($message, $this->getClientOriginalName(), $maxFilesize); + return \sprintf($message, $this->getClientOriginalName(), $maxFilesize); } } diff --git a/HeaderBag.php b/HeaderBag.php index 4dd777f16..e8072addd 100644 --- a/HeaderBag.php +++ b/HeaderBag.php @@ -51,7 +51,7 @@ public function __toString(): string foreach ($headers as $name => $values) { $name = ucwords($name, '-'); foreach ($values as $value) { - $content .= sprintf("%-{$max}s %s\r\n", $name.':', $value); + $content .= \sprintf("%-{$max}s %s\r\n", $name.':', $value); } } @@ -204,7 +204,7 @@ public function getDate(string $key, ?\DateTimeInterface $default = null): ?\Dat } if (false === $date = \DateTimeImmutable::createFromFormat(\DATE_RFC2822, $value)) { - throw new \RuntimeException(sprintf('The "%s" HTTP header is not parseable (%s).', $key, $value)); + throw new \RuntimeException(\sprintf('The "%s" HTTP header is not parseable (%s).', $key, $value)); } return $date; diff --git a/HeaderUtils.php b/HeaderUtils.php index 110896e17..ad47f2204 100644 --- a/HeaderUtils.php +++ b/HeaderUtils.php @@ -165,7 +165,7 @@ public static function unquote(string $s): string public static function makeDisposition(string $disposition, string $filename, string $filenameFallback = ''): string { if (!\in_array($disposition, [self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE])) { - throw new \InvalidArgumentException(sprintf('The disposition must be either "%s" or "%s".', self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE)); + throw new \InvalidArgumentException(\sprintf('The disposition must be either "%s" or "%s".', self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE)); } if ('' === $filenameFallback) { diff --git a/InputBag.php b/InputBag.php index 5acf35fec..08b927571 100644 --- a/InputBag.php +++ b/InputBag.php @@ -29,13 +29,13 @@ final class InputBag extends ParameterBag public function get(string $key, mixed $default = null): string|int|float|bool|null { if (null !== $default && !\is_scalar($default) && !$default instanceof \Stringable) { - throw new \InvalidArgumentException(sprintf('Expected a scalar value as a 2nd argument to "%s()", "%s" given.', __METHOD__, get_debug_type($default))); + throw new \InvalidArgumentException(\sprintf('Expected a scalar value as a 2nd argument to "%s()", "%s" given.', __METHOD__, get_debug_type($default))); } $value = parent::get($key, $this); if (null !== $value && $this !== $value && !\is_scalar($value) && !$value instanceof \Stringable) { - throw new BadRequestException(sprintf('Input value "%s" contains a non-scalar value.', $key)); + throw new BadRequestException(\sprintf('Input value "%s" contains a non-scalar value.', $key)); } return $this === $value ? $default : $value; @@ -68,7 +68,7 @@ public function add(array $inputs = []): void public function set(string $key, mixed $value): void { if (null !== $value && !\is_scalar($value) && !\is_array($value) && !$value instanceof \Stringable) { - throw new \InvalidArgumentException(sprintf('Expected a scalar, or an array as a 2nd argument to "%s()", "%s" given.', __METHOD__, get_debug_type($value))); + throw new \InvalidArgumentException(\sprintf('Expected a scalar, or an array as a 2nd argument to "%s()", "%s" given.', __METHOD__, get_debug_type($value))); } $this->parameters[$key] = $value; @@ -112,11 +112,11 @@ public function filter(string $key, mixed $default = null, int $filter = \FILTER } if (\is_array($value) && !(($options['flags'] ?? 0) & (\FILTER_REQUIRE_ARRAY | \FILTER_FORCE_ARRAY))) { - throw new BadRequestException(sprintf('Input value "%s" contains an array, but "FILTER_REQUIRE_ARRAY" or "FILTER_FORCE_ARRAY" flags were not set.', $key)); + throw new BadRequestException(\sprintf('Input value "%s" contains an array, but "FILTER_REQUIRE_ARRAY" or "FILTER_FORCE_ARRAY" flags were not set.', $key)); } if ((\FILTER_CALLBACK & $filter) && !(($options['options'] ?? null) instanceof \Closure)) { - 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))); + 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))); } $options['flags'] ??= 0; diff --git a/IpUtils.php b/IpUtils.php index 18b1c5faf..8b52d2a9d 100644 --- a/IpUtils.php +++ b/IpUtils.php @@ -102,7 +102,7 @@ public static function checkIp4(string $requestIp, string $ip): bool return self::setCacheResult($cacheKey, false); } - return self::setCacheResult($cacheKey, 0 === substr_compare(sprintf('%032b', ip2long($requestIp)), sprintf('%032b', ip2long($address)), 0, $netmask)); + return self::setCacheResult($cacheKey, 0 === substr_compare(\sprintf('%032b', ip2long($requestIp)), \sprintf('%032b', ip2long($address)), 0, $netmask)); } /** @@ -182,7 +182,7 @@ public static function checkIp6(string $requestIp, string $ip): bool */ public static function anonymize(string $ip): string { - /** + /* * If the IP contains a % symbol, then it is a local-link address with scoping according to RFC 4007 * In that case, we only care about the part before the % symbol, as the following functions, can only work with * the IP address itself. As the scope can leak information (containing interface name), we do not want to diff --git a/JsonResponse.php b/JsonResponse.php index 93c5751f2..616bccfee 100644 --- a/JsonResponse.php +++ b/JsonResponse.php @@ -41,7 +41,7 @@ public function __construct(mixed $data = null, int $status = 200, array $header parent::__construct('', $status, $headers); if ($json && !\is_string($data) && !is_numeric($data) && !\is_callable([$data, '__toString'])) { - 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))); + 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))); } $data ??= new \ArrayObject(); @@ -176,7 +176,7 @@ protected function update(): static // Not using application/javascript for compatibility reasons with older browsers. $this->headers->set('Content-Type', 'text/javascript'); - return $this->setContent(sprintf('/**/%s(%s);', $this->callback, $this->data)); + return $this->setContent(\sprintf('/**/%s(%s);', $this->callback, $this->data)); } // Only set the header when there is none or when it equals 'text/javascript' (from a previous update with callback) diff --git a/ParameterBag.php b/ParameterBag.php index 48fa4b233..2bd8cb15f 100644 --- a/ParameterBag.php +++ b/ParameterBag.php @@ -45,7 +45,7 @@ public function all(?string $key = null): array } if (!\is_array($value = $this->parameters[$key] ?? [])) { - throw new BadRequestException(sprintf('Unexpected value for parameter "%s": expecting "array", got "%s".', $key, get_debug_type($value))); + throw new BadRequestException(\sprintf('Unexpected value for parameter "%s": expecting "array", got "%s".', $key, get_debug_type($value))); } return $value; @@ -141,7 +141,7 @@ public function getString(string $key, string $default = ''): string { $value = $this->get($key, $default); if (!\is_scalar($value) && !$value instanceof \Stringable) { - throw new UnexpectedValueException(sprintf('Parameter value "%s" cannot be converted to "string".', $key)); + throw new UnexpectedValueException(\sprintf('Parameter value "%s" cannot be converted to "string".', $key)); } return (string) $value; @@ -185,7 +185,7 @@ public function getEnum(string $key, string $class, ?\BackedEnum $default = null try { return $class::from($value); } catch (\ValueError|\TypeError $e) { - throw new UnexpectedValueException(sprintf('Parameter "%s" cannot be converted to enum: %s.', $key, $e->getMessage()), $e->getCode(), $e); + throw new UnexpectedValueException(\sprintf('Parameter "%s" cannot be converted to enum: %s.', $key, $e->getMessage()), $e->getCode(), $e); } } @@ -212,11 +212,11 @@ public function filter(string $key, mixed $default = null, int $filter = \FILTER } if (\is_object($value) && !$value instanceof \Stringable) { - throw new UnexpectedValueException(sprintf('Parameter value "%s" cannot be filtered.', $key)); + throw new UnexpectedValueException(\sprintf('Parameter value "%s" cannot be filtered.', $key)); } if ((\FILTER_CALLBACK & $filter) && !(($options['options'] ?? null) instanceof \Closure)) { - 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))); + 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))); } $options['flags'] ??= 0; diff --git a/RedirectResponse.php b/RedirectResponse.php index 408629e36..220dcf616 100644 --- a/RedirectResponse.php +++ b/RedirectResponse.php @@ -39,7 +39,7 @@ public function __construct(string $url, int $status = 302, array $headers = []) $this->setTargetUrl($url); if (!$this->isRedirect()) { - throw new \InvalidArgumentException(sprintf('The HTTP status code is not a redirect ("%s" given).', $status)); + throw new \InvalidArgumentException(\sprintf('The HTTP status code is not a redirect ("%s" given).', $status)); } 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 $this->targetUrl = $url; $this->setContent( - sprintf(' + \sprintf(' diff --git a/Request.php b/Request.php index 42a3a8a2c..ec2d08d1a 100644 --- a/Request.php +++ b/Request.php @@ -537,7 +537,7 @@ public function __toString(): string } return - sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n". + \sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n". $this->headers. $cookieHeader."\r\n". $content; @@ -638,7 +638,7 @@ public static function getTrustedHeaderSet(): int */ public static function setTrustedHosts(array $hostPatterns) { - self::$trustedHostPatterns = array_map(fn ($hostPattern) => sprintf('{%s}i', $hostPattern), $hostPatterns); + self::$trustedHostPatterns = array_map(fn ($hostPattern) => \sprintf('{%s}i', $hostPattern), $hostPatterns); // we need to reset trusted hosts on trusted host patterns change self::$trustedHosts = []; } @@ -1160,7 +1160,7 @@ public function getHost(): string } $this->isHostValid = false; - throw new SuspiciousOperationException(sprintf('Invalid Host "%s".', $host)); + throw new SuspiciousOperationException(\sprintf('Invalid Host "%s".', $host)); } if (\count(self::$trustedHostPatterns) > 0) { @@ -1183,7 +1183,7 @@ public function getHost(): string } $this->isHostValid = false; - throw new SuspiciousOperationException(sprintf('Untrusted Host "%s".', $host)); + throw new SuspiciousOperationException(\sprintf('Untrusted Host "%s".', $host)); } return $host; @@ -1545,7 +1545,7 @@ public function getPayload(): InputBag } if (!\is_array($content)) { - throw new JsonException(sprintf('JSON content was expected to decode to an array, "%s" returned.', get_debug_type($content))); + throw new JsonException(\sprintf('JSON content was expected to decode to an array, "%s" returned.', get_debug_type($content))); } return new InputBag($content); @@ -1571,7 +1571,7 @@ public function toArray(): array } if (!\is_array($content)) { - throw new JsonException(sprintf('JSON content was expected to decode to an array, "%s" returned.', get_debug_type($content))); + throw new JsonException(\sprintf('JSON content was expected to decode to an array, "%s" returned.', get_debug_type($content))); } return $content; @@ -1978,7 +1978,7 @@ private function getUrlencodedPrefix(string $string, string $prefix): ?string $len = \strlen($prefix); - if (preg_match(sprintf('#^(%%[[:xdigit:]]{2}|.){%d}#', $len), $string, $match)) { + if (preg_match(\sprintf('#^(%%[[:xdigit:]]{2}|.){%d}#', $len), $string, $match)) { return $match[0]; } @@ -2070,7 +2070,7 @@ private function getTrustedValues(int $type, ?string $ip = null): array } $this->isForwardedValid = false; - throw new ConflictingHeadersException(sprintf('The request has both a trusted "%s" header and a trusted "%s" header, conflicting with each other. You should either configure your proxy to remove one of them, or configure your project to distrust the offending one.', self::TRUSTED_HEADERS[self::HEADER_FORWARDED], self::TRUSTED_HEADERS[$type])); + throw new ConflictingHeadersException(\sprintf('The request has both a trusted "%s" header and a trusted "%s" header, conflicting with each other. You should either configure your proxy to remove one of them, or configure your project to distrust the offending one.', self::TRUSTED_HEADERS[self::HEADER_FORWARDED], self::TRUSTED_HEADERS[$type])); } private function normalizeAndFilterClientIps(array $clientIps, string $ip): array diff --git a/Response.php b/Response.php index a43e7a9ac..e476e29d1 100644 --- a/Response.php +++ b/Response.php @@ -241,7 +241,7 @@ public function __construct(?string $content = '', int $status = 200, array $hea public function __toString(): string { return - sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText)."\r\n". + \sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText)."\r\n". $this->headers."\r\n". $this->getContent(); } @@ -393,7 +393,7 @@ public function sendHeaders(/* int $statusCode = null */): static $statusCode ??= $this->statusCode; // status - header(sprintf('HTTP/%s %s %s', $this->version, $statusCode, $this->statusText), true, $statusCode); + header(\sprintf('HTTP/%s %s %s', $this->version, $statusCode, $this->statusText), true, $statusCode); return $this; } @@ -499,7 +499,7 @@ public function setStatusCode(int $code, ?string $text = null): static { $this->statusCode = $code; if ($this->isInvalid()) { - throw new \InvalidArgumentException(sprintf('The HTTP status code "%s" is not valid.', $code)); + throw new \InvalidArgumentException(\sprintf('The HTTP status code "%s" is not valid.', $code)); } if (null === $text) { @@ -1011,7 +1011,7 @@ public function setEtag(?string $etag = null, bool $weak = false): static public function setCache(array $options): static { if ($diff = array_diff(array_keys($options), array_keys(self::HTTP_RESPONSE_CACHE_CONTROL_DIRECTIVES))) { - throw new \InvalidArgumentException(sprintf('Response does not support the following options: "%s".', implode('", "', $diff))); + throw new \InvalidArgumentException(\sprintf('Response does not support the following options: "%s".', implode('", "', $diff))); } if (isset($options['etag'])) { diff --git a/ResponseHeaderBag.php b/ResponseHeaderBag.php index 376357d01..8db8dce4e 100644 --- a/ResponseHeaderBag.php +++ b/ResponseHeaderBag.php @@ -212,7 +212,7 @@ public function removeCookie(string $name, ?string $path = '/', ?string $domain public function getCookies(string $format = self::COOKIES_FLAT): array { if (!\in_array($format, [self::COOKIES_FLAT, self::COOKIES_ARRAY])) { - throw new \InvalidArgumentException(sprintf('Format "%s" invalid (%s).', $format, implode(', ', [self::COOKIES_FLAT, self::COOKIES_ARRAY]))); + throw new \InvalidArgumentException(\sprintf('Format "%s" invalid (%s).', $format, implode(', ', [self::COOKIES_FLAT, self::COOKIES_ARRAY]))); } if (self::COOKIES_ARRAY === $format) { @@ -240,7 +240,7 @@ public function getCookies(string $format = self::COOKIES_FLAT): array */ public function clearCookie(string $name, ?string $path = '/', ?string $domain = null, bool $secure = false, bool $httpOnly = true, ?string $sameSite = null /* , bool $partitioned = false */) { - $partitioned = 6 < \func_num_args() ? \func_get_arg(6) : false; + $partitioned = 6 < \func_num_args() ? func_get_arg(6) : false; $this->setCookie(new Cookie($name, null, 1, $path, $domain, $secure, $httpOnly, false, $sameSite, $partitioned)); } diff --git a/Session/SessionUtils.php b/Session/SessionUtils.php index 504c5848e..57aa565ff 100644 --- a/Session/SessionUtils.php +++ b/Session/SessionUtils.php @@ -28,8 +28,8 @@ final class SessionUtils public static function popSessionCookie(string $sessionName, #[\SensitiveParameter] string $sessionId): ?string { $sessionCookie = null; - $sessionCookiePrefix = sprintf(' %s=', urlencode($sessionName)); - $sessionCookieWithId = sprintf('%s%s;', $sessionCookiePrefix, urlencode($sessionId)); + $sessionCookiePrefix = \sprintf(' %s=', urlencode($sessionName)); + $sessionCookieWithId = \sprintf('%s%s;', $sessionCookiePrefix, urlencode($sessionId)); $otherCookies = []; foreach (headers_list() as $h) { if (0 !== stripos($h, 'Set-Cookie:')) { diff --git a/Session/Storage/Handler/AbstractSessionHandler.php b/Session/Storage/Handler/AbstractSessionHandler.php index 288c24232..fd8562377 100644 --- a/Session/Storage/Handler/AbstractSessionHandler.php +++ b/Session/Storage/Handler/AbstractSessionHandler.php @@ -32,7 +32,7 @@ public function open(string $savePath, string $sessionName): bool { $this->sessionName = $sessionName; if (!headers_sent() && !\ini_get('session.cache_limiter') && '0' !== \ini_get('session.cache_limiter')) { - header(sprintf('Cache-Control: max-age=%d, private, must-revalidate', 60 * (int) \ini_get('session.cache_expire'))); + header(\sprintf('Cache-Control: max-age=%d, private, must-revalidate', 60 * (int) \ini_get('session.cache_expire'))); } return true; @@ -88,7 +88,7 @@ public function destroy(#[\SensitiveParameter] string $sessionId): bool { if (!headers_sent() && filter_var(\ini_get('session.use_cookies'), \FILTER_VALIDATE_BOOL)) { if (!isset($this->sessionName)) { - throw new \LogicException(sprintf('Session name cannot be empty, did you forget to call "parent::open()" in "%s"?.', static::class)); + throw new \LogicException(\sprintf('Session name cannot be empty, did you forget to call "parent::open()" in "%s"?.', static::class)); } $cookie = SessionUtils::popSessionCookie($this->sessionName, $sessionId); diff --git a/Session/Storage/Handler/IdentityMarshaller.php b/Session/Storage/Handler/IdentityMarshaller.php index 411a8d1f0..70ac76248 100644 --- a/Session/Storage/Handler/IdentityMarshaller.php +++ b/Session/Storage/Handler/IdentityMarshaller.php @@ -22,7 +22,7 @@ public function marshall(array $values, ?array &$failed): array { foreach ($values as $key => $value) { if (!\is_string($value)) { - throw new \LogicException(sprintf('%s accepts only string as data.', __METHOD__)); + throw new \LogicException(\sprintf('%s accepts only string as data.', __METHOD__)); } } diff --git a/Session/Storage/Handler/MemcachedSessionHandler.php b/Session/Storage/Handler/MemcachedSessionHandler.php index 91a023ddb..9647f42bb 100644 --- a/Session/Storage/Handler/MemcachedSessionHandler.php +++ b/Session/Storage/Handler/MemcachedSessionHandler.php @@ -47,7 +47,7 @@ public function __construct(\Memcached $memcached, array $options = []) $this->memcached = $memcached; if ($diff = array_diff(array_keys($options), ['prefix', 'expiretime', 'ttl'])) { - throw new \InvalidArgumentException(sprintf('The following options are not supported "%s".', implode(', ', $diff))); + throw new \InvalidArgumentException(\sprintf('The following options are not supported "%s".', implode(', ', $diff))); } $this->ttl = $options['expiretime'] ?? $options['ttl'] ?? null; diff --git a/Session/Storage/Handler/NativeFileSessionHandler.php b/Session/Storage/Handler/NativeFileSessionHandler.php index f8c6151a4..284cd869d 100644 --- a/Session/Storage/Handler/NativeFileSessionHandler.php +++ b/Session/Storage/Handler/NativeFileSessionHandler.php @@ -34,7 +34,7 @@ public function __construct(?string $savePath = null) if ($count = substr_count($savePath, ';')) { if ($count > 2) { - throw new \InvalidArgumentException(sprintf('Invalid argument $savePath \'%s\'.', $savePath)); + throw new \InvalidArgumentException(\sprintf('Invalid argument $savePath \'%s\'.', $savePath)); } // characters after last ';' are the path @@ -42,7 +42,7 @@ public function __construct(?string $savePath = null) } if ($baseDir && !is_dir($baseDir) && !@mkdir($baseDir, 0777, true) && !is_dir($baseDir)) { - throw new \RuntimeException(sprintf('Session Storage was not able to create directory "%s".', $baseDir)); + throw new \RuntimeException(\sprintf('Session Storage was not able to create directory "%s".', $baseDir)); } if ($savePath !== \ini_get('session.save_path')) { diff --git a/Session/Storage/Handler/PdoSessionHandler.php b/Session/Storage/Handler/PdoSessionHandler.php index 9cee76ddf..af5ce10b6 100644 --- a/Session/Storage/Handler/PdoSessionHandler.php +++ b/Session/Storage/Handler/PdoSessionHandler.php @@ -155,7 +155,7 @@ public function __construct(#[\SensitiveParameter] \PDO|string|null $pdoOrDsn = { if ($pdoOrDsn instanceof \PDO) { if (\PDO::ERRMODE_EXCEPTION !== $pdoOrDsn->getAttribute(\PDO::ATTR_ERRMODE)) { - throw new \InvalidArgumentException(sprintf('"%s" requires PDO error mode attribute be set to throw Exceptions (i.e. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)).', __CLASS__)); + throw new \InvalidArgumentException(\sprintf('"%s" requires PDO error mode attribute be set to throw Exceptions (i.e. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)).', __CLASS__)); } $this->pdo = $pdoOrDsn; @@ -222,7 +222,7 @@ public function configureSchema(Schema $schema, ?\Closure $isSameDatabase = null $table->addColumn($this->timeCol, Types::INTEGER)->setUnsigned(true)->setNotnull(true); break; default: - throw new \DomainException(sprintf('Creating the session table is currently not implemented for PDO driver "%s".', $this->driver)); + throw new \DomainException(\sprintf('Creating the session table is currently not implemented for PDO driver "%s".', $this->driver)); } $table->setPrimaryKey([$this->idCol]); $table->addIndex([$this->lifetimeCol], $this->lifetimeCol.'_idx'); @@ -257,7 +257,7 @@ public function createTable() 'pgsql' => "CREATE TABLE $this->table ($this->idCol VARCHAR(128) NOT NULL PRIMARY KEY, $this->dataCol BYTEA NOT NULL, $this->lifetimeCol INTEGER NOT NULL, $this->timeCol INTEGER NOT NULL)", 'oci' => "CREATE TABLE $this->table ($this->idCol VARCHAR2(128) NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER NOT NULL, $this->timeCol INTEGER NOT NULL)", 'sqlsrv' => "CREATE TABLE $this->table ($this->idCol VARCHAR(128) NOT NULL PRIMARY KEY, $this->dataCol VARBINARY(MAX) NOT NULL, $this->lifetimeCol INTEGER NOT NULL, $this->timeCol INTEGER NOT NULL)", - default => throw new \DomainException(sprintf('Creating the session table is currently not implemented for PDO driver "%s".', $this->driver)), + default => throw new \DomainException(\sprintf('Creating the session table is currently not implemented for PDO driver "%s".', $this->driver)), }; try { @@ -538,7 +538,7 @@ private function buildDsnFromUrl(#[\SensitiveParameter] string $dsnOrUrl): strin return $dsn; default: - throw new \InvalidArgumentException(sprintf('The scheme "%s" is not supported by the PdoSessionHandler URL configuration. Pass a PDO DSN directly.', $params['scheme'])); + throw new \InvalidArgumentException(\sprintf('The scheme "%s" is not supported by the PdoSessionHandler URL configuration. Pass a PDO DSN directly.', $params['scheme'])); } } @@ -734,7 +734,7 @@ private function doAdvisoryLock(#[\SensitiveParameter] string $sessionId): \PDOS case 'sqlite': throw new \DomainException('SQLite does not support advisory locks.'); default: - throw new \DomainException(sprintf('Advisory locks are currently not implemented for PDO driver "%s".', $this->driver)); + throw new \DomainException(\sprintf('Advisory locks are currently not implemented for PDO driver "%s".', $this->driver)); } } @@ -776,7 +776,7 @@ private function getSelectSql(): string // we already locked when starting transaction break; default: - throw new \DomainException(sprintf('Transactional locks are currently not implemented for PDO driver "%s".', $this->driver)); + throw new \DomainException(\sprintf('Transactional locks are currently not implemented for PDO driver "%s".', $this->driver)); } } diff --git a/Session/Storage/Handler/RedisSessionHandler.php b/Session/Storage/Handler/RedisSessionHandler.php index b696eee4b..78cd4e7c2 100644 --- a/Session/Storage/Handler/RedisSessionHandler.php +++ b/Session/Storage/Handler/RedisSessionHandler.php @@ -44,7 +44,7 @@ public function __construct( array $options = [], ) { if ($diff = array_diff(array_keys($options), ['prefix', 'ttl'])) { - throw new \InvalidArgumentException(sprintf('The following options are not supported "%s".', implode(', ', $diff))); + throw new \InvalidArgumentException(\sprintf('The following options are not supported "%s".', implode(', ', $diff))); } $this->prefix = $options['prefix'] ?? 'sf_s'; diff --git a/Session/Storage/Handler/SessionHandlerFactory.php b/Session/Storage/Handler/SessionHandlerFactory.php index ff5b70d81..43a9eb84e 100644 --- a/Session/Storage/Handler/SessionHandlerFactory.php +++ b/Session/Storage/Handler/SessionHandlerFactory.php @@ -49,7 +49,7 @@ public static function createHandler(object|string $connection, array $options = return new PdoSessionHandler($connection); case !\is_string($connection): - throw new \InvalidArgumentException(sprintf('Unsupported Connection: "%s".', get_debug_type($connection))); + throw new \InvalidArgumentException(\sprintf('Unsupported Connection: "%s".', get_debug_type($connection))); case str_starts_with($connection, 'file://'): $savePath = substr($connection, 7); @@ -94,6 +94,6 @@ public static function createHandler(object|string $connection, array $options = return new PdoSessionHandler($connection, $options); } - throw new \InvalidArgumentException(sprintf('Unsupported Connection: "%s".', $connection)); + throw new \InvalidArgumentException(\sprintf('Unsupported Connection: "%s".', $connection)); } } diff --git a/Session/Storage/Handler/StrictSessionHandler.php b/Session/Storage/Handler/StrictSessionHandler.php index 1f8668744..38afc1257 100644 --- a/Session/Storage/Handler/StrictSessionHandler.php +++ b/Session/Storage/Handler/StrictSessionHandler.php @@ -24,7 +24,7 @@ class StrictSessionHandler extends AbstractSessionHandler public function __construct(\SessionHandlerInterface $handler) { if ($handler instanceof \SessionUpdateTimestampHandlerInterface) { - throw new \LogicException(sprintf('"%s" is already an instance of "SessionUpdateTimestampHandlerInterface", you cannot wrap it with "%s".', get_debug_type($handler), self::class)); + throw new \LogicException(\sprintf('"%s" is already an instance of "SessionUpdateTimestampHandlerInterface", you cannot wrap it with "%s".', get_debug_type($handler), self::class)); } $this->handler = $handler; diff --git a/Session/Storage/MockArraySessionStorage.php b/Session/Storage/MockArraySessionStorage.php index f02793d3e..65ab34f91 100644 --- a/Session/Storage/MockArraySessionStorage.php +++ b/Session/Storage/MockArraySessionStorage.php @@ -174,7 +174,7 @@ public function registerBag(SessionBagInterface $bag) public function getBag(string $name): SessionBagInterface { if (!isset($this->bags[$name])) { - throw new \InvalidArgumentException(sprintf('The SessionBagInterface "%s" is not registered.', $name)); + throw new \InvalidArgumentException(\sprintf('The SessionBagInterface "%s" is not registered.', $name)); } if (!$this->started) { diff --git a/Session/Storage/MockFileSessionStorage.php b/Session/Storage/MockFileSessionStorage.php index ef6d9d8f8..84c2c4363 100644 --- a/Session/Storage/MockFileSessionStorage.php +++ b/Session/Storage/MockFileSessionStorage.php @@ -35,7 +35,7 @@ public function __construct(?string $savePath = null, string $name = 'MOCKSESSID $savePath ??= sys_get_temp_dir(); if (!is_dir($savePath) && !@mkdir($savePath, 0777, true) && !is_dir($savePath)) { - throw new \RuntimeException(sprintf('Session Storage was not able to create directory "%s".', $savePath)); + throw new \RuntimeException(\sprintf('Session Storage was not able to create directory "%s".', $savePath)); } $this->savePath = $savePath; diff --git a/Session/Storage/NativeSessionStorage.php b/Session/Storage/NativeSessionStorage.php index 7b0c5beca..c8801cc25 100644 --- a/Session/Storage/NativeSessionStorage.php +++ b/Session/Storage/NativeSessionStorage.php @@ -129,7 +129,7 @@ public function start(): bool } if (filter_var(\ini_get('session.use_cookies'), \FILTER_VALIDATE_BOOL) && headers_sent($file, $line)) { - throw new \RuntimeException(sprintf('Failed to start the session because headers have already been sent by "%s" at line %d.', $file, $line)); + throw new \RuntimeException(\sprintf('Failed to start the session because headers have already been sent by "%s" at line %d.', $file, $line)); } $sessionId = $_COOKIE[session_name()] ?? null; @@ -249,7 +249,7 @@ public function save() $previousHandler = set_error_handler(function ($type, $msg, $file, $line) use (&$previousHandler) { if (\E_WARNING === $type && str_starts_with($msg, 'session_write_close():')) { $handler = $this->saveHandler instanceof SessionHandlerProxy ? $this->saveHandler->getHandler() : $this->saveHandler; - $msg = sprintf('session_write_close(): Failed to write session data with "%s" handler', $handler::class); + $msg = \sprintf('session_write_close(): Failed to write session data with "%s" handler', $handler::class); } return $previousHandler ? $previousHandler($type, $msg, $file, $line) : false; @@ -302,7 +302,7 @@ public function registerBag(SessionBagInterface $bag) public function getBag(string $name): SessionBagInterface { if (!isset($this->bags[$name])) { - throw new \InvalidArgumentException(sprintf('The SessionBagInterface "%s" is not registered.', $name)); + throw new \InvalidArgumentException(\sprintf('The SessionBagInterface "%s" is not registered.', $name)); } if (!$this->started && $this->saveHandler->isActive()) { diff --git a/Test/Constraint/RequestAttributeValueSame.php b/Test/Constraint/RequestAttributeValueSame.php index 6e1142681..8fc9aa2a0 100644 --- a/Test/Constraint/RequestAttributeValueSame.php +++ b/Test/Constraint/RequestAttributeValueSame.php @@ -27,7 +27,7 @@ public function __construct(string $name, string $value) public function toString(): string { - return sprintf('has attribute "%s" with value "%s"', $this->name, $this->value); + return \sprintf('has attribute "%s" with value "%s"', $this->name, $this->value); } /** diff --git a/Test/Constraint/ResponseCookieValueSame.php b/Test/Constraint/ResponseCookieValueSame.php index 768007b95..285f45bf7 100644 --- a/Test/Constraint/ResponseCookieValueSame.php +++ b/Test/Constraint/ResponseCookieValueSame.php @@ -32,14 +32,14 @@ public function __construct(string $name, string $value, string $path = '/', ?st public function toString(): string { - $str = sprintf('has cookie "%s"', $this->name); + $str = \sprintf('has cookie "%s"', $this->name); if ('/' !== $this->path) { - $str .= sprintf(' with path "%s"', $this->path); + $str .= \sprintf(' with path "%s"', $this->path); } if ($this->domain) { - $str .= sprintf(' for domain "%s"', $this->domain); + $str .= \sprintf(' for domain "%s"', $this->domain); } - $str .= sprintf(' with value "%s"', $this->value); + $str .= \sprintf(' with value "%s"', $this->value); return $str; } diff --git a/Test/Constraint/ResponseHasCookie.php b/Test/Constraint/ResponseHasCookie.php index 8eccea9d1..a11809d04 100644 --- a/Test/Constraint/ResponseHasCookie.php +++ b/Test/Constraint/ResponseHasCookie.php @@ -30,12 +30,12 @@ public function __construct(string $name, string $path = '/', ?string $domain = public function toString(): string { - $str = sprintf('has cookie "%s"', $this->name); + $str = \sprintf('has cookie "%s"', $this->name); if ('/' !== $this->path) { - $str .= sprintf(' with path "%s"', $this->path); + $str .= \sprintf(' with path "%s"', $this->path); } if ($this->domain) { - $str .= sprintf(' for domain "%s"', $this->domain); + $str .= \sprintf(' for domain "%s"', $this->domain); } return $str; diff --git a/Test/Constraint/ResponseHasHeader.php b/Test/Constraint/ResponseHasHeader.php index 08522c89c..e5cb48adf 100644 --- a/Test/Constraint/ResponseHasHeader.php +++ b/Test/Constraint/ResponseHasHeader.php @@ -25,7 +25,7 @@ public function __construct(string $headerName) public function toString(): string { - return sprintf('has header "%s"', $this->headerName); + return \sprintf('has header "%s"', $this->headerName); } /** diff --git a/Test/Constraint/ResponseHeaderLocationSame.php b/Test/Constraint/ResponseHeaderLocationSame.php index 9286ec715..833ffd9f2 100644 --- a/Test/Constraint/ResponseHeaderLocationSame.php +++ b/Test/Constraint/ResponseHeaderLocationSame.php @@ -23,7 +23,7 @@ public function __construct(private Request $request, private string $expectedVa public function toString(): string { - return sprintf('has header "Location" matching "%s"', $this->expectedValue); + return \sprintf('has header "Location" matching "%s"', $this->expectedValue); } protected function matches($other): bool @@ -53,7 +53,7 @@ private function toFullUrl(string $url): string } if (str_starts_with($url, '//')) { - return sprintf('%s:%s', $this->request->getScheme(), $url); + return \sprintf('%s:%s', $this->request->getScheme(), $url); } if (str_starts_with($url, '/')) { diff --git a/Test/Constraint/ResponseHeaderSame.php b/Test/Constraint/ResponseHeaderSame.php index 8141df972..02b5921d2 100644 --- a/Test/Constraint/ResponseHeaderSame.php +++ b/Test/Constraint/ResponseHeaderSame.php @@ -27,7 +27,7 @@ public function __construct(string $headerName, string $expectedValue) public function toString(): string { - return sprintf('has header "%s" with value "%s"', $this->headerName, $this->expectedValue); + return \sprintf('has header "%s" with value "%s"', $this->headerName, $this->expectedValue); } /** diff --git a/Tests/InputBagTest.php b/Tests/InputBagTest.php index d1e9015f1..cb0d449c5 100644 --- a/Tests/InputBagTest.php +++ b/Tests/InputBagTest.php @@ -23,7 +23,7 @@ class InputBagTest extends TestCase public function testGet() { - $bag = new InputBag(['foo' => 'bar', 'null' => null, 'int' => 1, 'float' => 1.0, 'bool' => false, 'stringable' => new class() implements \Stringable { + $bag = new InputBag(['foo' => 'bar', 'null' => null, 'int' => 1, 'float' => 1.0, 'bool' => false, 'stringable' => new class implements \Stringable { public function __toString(): string { return 'strval'; @@ -65,7 +65,7 @@ public function testGetBooleanError() public function testGetString() { - $bag = new InputBag(['integer' => 123, 'bool_true' => true, 'bool_false' => false, 'string' => 'abc', 'stringable' => new class() implements \Stringable { + $bag = new InputBag(['integer' => 123, 'bool_true' => true, 'bool_false' => false, 'string' => 'abc', 'stringable' => new class implements \Stringable { public function __toString(): string { return 'strval'; diff --git a/Tests/JsonResponseTest.php b/Tests/JsonResponseTest.php index 2058280c5..67a038279 100644 --- a/Tests/JsonResponseTest.php +++ b/Tests/JsonResponseTest.php @@ -171,7 +171,7 @@ public function testConstructorWithNullAsDataThrowsAnUnexpectedValueException() public function testConstructorWithObjectWithToStringMethod() { - $class = new class() { + $class = new class { public function __toString(): string { return '{}'; diff --git a/Tests/ParameterBagTest.php b/Tests/ParameterBagTest.php index ad0cf99bf..0d9ae476e 100644 --- a/Tests/ParameterBagTest.php +++ b/Tests/ParameterBagTest.php @@ -192,7 +192,7 @@ public function testGetInt() */ public function testGetIntExceptionWithArray() { - $this->expectDeprecation(sprintf('Since symfony/http-foundation 6.3: Ignoring invalid values when using "%s::getInt(\'digits\')" is deprecated and will throw an "%s" in 7.0; use method "filter()" with flag "FILTER_NULL_ON_FAILURE" to keep ignoring them.', ParameterBag::class, UnexpectedValueException::class)); + $this->expectDeprecation(\sprintf('Since symfony/http-foundation 6.3: Ignoring invalid values when using "%s::getInt(\'digits\')" is deprecated and will throw an "%s" in 7.0; use method "filter()" with flag "FILTER_NULL_ON_FAILURE" to keep ignoring them.', ParameterBag::class, UnexpectedValueException::class)); $bag = new ParameterBag(['digits' => ['123']]); $result = $bag->getInt('digits', 0); @@ -204,7 +204,7 @@ public function testGetIntExceptionWithArray() */ public function testGetIntExceptionWithInvalid() { - $this->expectDeprecation(sprintf('Since symfony/http-foundation 6.3: Ignoring invalid values when using "%s::getInt(\'word\')" is deprecated and will throw an "%s" in 7.0; use method "filter()" with flag "FILTER_NULL_ON_FAILURE" to keep ignoring them.', ParameterBag::class, UnexpectedValueException::class)); + $this->expectDeprecation(\sprintf('Since symfony/http-foundation 6.3: Ignoring invalid values when using "%s::getInt(\'word\')" is deprecated and will throw an "%s" in 7.0; use method "filter()" with flag "FILTER_NULL_ON_FAILURE" to keep ignoring them.', ParameterBag::class, UnexpectedValueException::class)); $bag = new ParameterBag(['word' => 'foo_BAR_012']); $result = $bag->getInt('word', 0); @@ -213,7 +213,7 @@ public function testGetIntExceptionWithInvalid() public function testGetString() { - $bag = new ParameterBag(['integer' => 123, 'bool_true' => true, 'bool_false' => false, 'string' => 'abc', 'stringable' => new class() implements \Stringable { + $bag = new ParameterBag(['integer' => 123, 'bool_true' => true, 'bool_false' => false, 'string' => 'abc', 'stringable' => new class implements \Stringable { public function __toString(): string { return 'strval'; @@ -258,7 +258,7 @@ public function testFilter() 'dec' => '256', 'hex' => '0x100', 'array' => ['bang'], - ]); + ]); $this->assertEmpty($bag->filter('nokey'), '->filter() should return empty by default if no key is found'); @@ -339,7 +339,7 @@ public function testGetBoolean() */ public function testGetBooleanExceptionWithInvalid() { - $this->expectDeprecation(sprintf('Since symfony/http-foundation 6.3: Ignoring invalid values when using "%s::getBoolean(\'invalid\')" is deprecated and will throw an "%s" in 7.0; use method "filter()" with flag "FILTER_NULL_ON_FAILURE" to keep ignoring them.', ParameterBag::class, UnexpectedValueException::class)); + $this->expectDeprecation(\sprintf('Since symfony/http-foundation 6.3: Ignoring invalid values when using "%s::getBoolean(\'invalid\')" is deprecated and will throw an "%s" in 7.0; use method "filter()" with flag "FILTER_NULL_ON_FAILURE" to keep ignoring them.', ParameterBag::class, UnexpectedValueException::class)); $bag = new ParameterBag(['invalid' => 'foo']); $result = $bag->getBoolean('invalid', 0); diff --git a/Tests/RequestTest.php b/Tests/RequestTest.php index a2eace70e..3ab13d1f2 100644 --- a/Tests/RequestTest.php +++ b/Tests/RequestTest.php @@ -2664,7 +2664,7 @@ public static function preferSafeContentData() public function testReservedFlags() { foreach ((new \ReflectionClass(Request::class))->getConstants() as $constant => $value) { - $this->assertNotSame(0b10000000, $value, sprintf('The constant "%s" should not use the reserved value "0b10000000".', $constant)); + $this->assertNotSame(0b10000000, $value, \sprintf('The constant "%s" should not use the reserved value "0b10000000".', $constant)); } } } diff --git a/Tests/ResponseFunctionalTest.php b/Tests/ResponseFunctionalTest.php index 1b3566a2c..e5c6c2428 100644 --- a/Tests/ResponseFunctionalTest.php +++ b/Tests/ResponseFunctionalTest.php @@ -45,9 +45,9 @@ public static function tearDownAfterClass(): void */ public function testCookie($fixture) { - $result = file_get_contents(sprintf('http://localhost:8054/%s.php', $fixture)); + $result = file_get_contents(\sprintf('http://localhost:8054/%s.php', $fixture)); $result = preg_replace_callback('/expires=[^;]++/', fn ($m) => str_replace('-', ' ', $m[0]), $result); - $this->assertStringMatchesFormatFile(__DIR__.sprintf('/Fixtures/response-functional/%s.expected', $fixture), $result); + $this->assertStringMatchesFormatFile(__DIR__.\sprintf('/Fixtures/response-functional/%s.expected', $fixture), $result); } public static function provideCookie() diff --git a/Tests/ResponseTest.php b/Tests/ResponseTest.php index 007842476..491a50fd5 100644 --- a/Tests/ResponseTest.php +++ b/Tests/ResponseTest.php @@ -181,7 +181,7 @@ public function testIsNotModifiedEtag() $etagTwo = 'randomly_generated_etag_2'; $request = new Request(); - $request->headers->set('If-None-Match', sprintf('%s, %s, %s', $etagOne, $etagTwo, 'etagThree')); + $request->headers->set('If-None-Match', \sprintf('%s, %s, %s', $etagOne, $etagTwo, 'etagThree')); $response = new Response(); @@ -235,7 +235,7 @@ public function testIsNotModifiedLastModifiedAndEtag() $etag = 'randomly_generated_etag'; $request = new Request(); - $request->headers->set('If-None-Match', sprintf('%s, %s', $etag, 'etagThree')); + $request->headers->set('If-None-Match', \sprintf('%s, %s', $etag, 'etagThree')); $request->headers->set('If-Modified-Since', $modified); $response = new Response(); @@ -259,7 +259,7 @@ public function testIsNotModifiedIfModifiedSinceAndEtagWithoutLastModified() $etag = 'randomly_generated_etag'; $request = new Request(); - $request->headers->set('If-None-Match', sprintf('%s, %s', $etag, 'etagThree')); + $request->headers->set('If-None-Match', \sprintf('%s, %s', $etag, 'etagThree')); $request->headers->set('If-Modified-Since', $modified); $response = new Response(); diff --git a/Tests/Session/Flash/AutoExpireFlashBagTest.php b/Tests/Session/Flash/AutoExpireFlashBagTest.php index 6a6510a57..0b418c006 100644 --- a/Tests/Session/Flash/AutoExpireFlashBagTest.php +++ b/Tests/Session/Flash/AutoExpireFlashBagTest.php @@ -46,9 +46,9 @@ public function testInitialize() $bag->initialize($array); $this->assertEquals(['A previous flash message'], $bag->peek('notice')); $array = ['new' => [ - 'notice' => ['Something else'], - 'error' => ['a'], - ]]; + 'notice' => ['Something else'], + 'error' => ['a'], + ]]; $bag->initialize($array); $this->assertEquals(['Something else'], $bag->peek('notice')); $this->assertEquals(['a'], $bag->peek('error')); @@ -106,13 +106,13 @@ public function testPeekAll() $this->assertEquals([ 'notice' => 'Foo', 'error' => 'Bar', - ], $this->bag->peekAll() + ], $this->bag->peekAll() ); $this->assertEquals([ 'notice' => 'Foo', 'error' => 'Bar', - ], $this->bag->peekAll() + ], $this->bag->peekAll() ); } @@ -137,7 +137,7 @@ public function testAll() $this->bag->set('error', 'Bar'); $this->assertEquals([ 'notice' => ['A previous flash message'], - ], $this->bag->all() + ], $this->bag->all() ); $this->assertEquals([], $this->bag->all()); diff --git a/Tests/Session/Flash/FlashBagTest.php b/Tests/Session/Flash/FlashBagTest.php index 59e3f1f0e..8163ba769 100644 --- a/Tests/Session/Flash/FlashBagTest.php +++ b/Tests/Session/Flash/FlashBagTest.php @@ -141,14 +141,14 @@ public function testPeekAll() $this->assertEquals([ 'notice' => ['Foo'], 'error' => ['Bar'], - ], $this->bag->peekAll() + ], $this->bag->peekAll() ); $this->assertTrue($this->bag->has('notice')); $this->assertTrue($this->bag->has('error')); $this->assertEquals([ 'notice' => ['Foo'], 'error' => ['Bar'], - ], $this->bag->peekAll() + ], $this->bag->peekAll() ); } } diff --git a/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php b/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php index 27fb57da4..361d3b15d 100644 --- a/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php @@ -45,10 +45,10 @@ public function testSession($fixture) { $context = ['http' => ['header' => "Cookie: sid=123abc\r\n"]]; $context = stream_context_create($context); - $result = file_get_contents(sprintf('http://localhost:8053/%s.php', $fixture), false, $context); + $result = file_get_contents(\sprintf('http://localhost:8053/%s.php', $fixture), false, $context); $result = preg_replace_callback('/expires=[^;]++/', fn ($m) => str_replace('-', ' ', $m[0]), $result); - $this->assertStringEqualsFile(__DIR__.sprintf('/Fixtures/%s.expected', $fixture), $result); + $this->assertStringEqualsFile(__DIR__.\sprintf('/Fixtures/%s.expected', $fixture), $result); } public static function provideSession() diff --git a/Tests/Session/Storage/Handler/IdentityMarshallerTest.php b/Tests/Session/Storage/Handler/IdentityMarshallerTest.php index 8019bd2e9..6f15f96cb 100644 --- a/Tests/Session/Storage/Handler/IdentityMarshallerTest.php +++ b/Tests/Session/Storage/Handler/IdentityMarshallerTest.php @@ -17,7 +17,7 @@ /** * @author Ahmed TAILOULOUTE */ -class IdentityMarshallerTest extends Testcase +class IdentityMarshallerTest extends TestCase { public function testMarshall() { diff --git a/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php b/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php index 04dfdbef8..d607e19d2 100644 --- a/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php @@ -51,7 +51,7 @@ protected function setUp(): void try { $this->manager->executeCommand(self::DABASE_NAME, new Command(['ping' => 1])); } catch (ConnectionException $e) { - $this->markTestSkipped(sprintf('MongoDB Server "%s" not running: %s', getenv('MONGODB_HOST'), $e->getMessage())); + $this->markTestSkipped(\sprintf('MongoDB Server "%s" not running: %s', getenv('MONGODB_HOST'), $e->getMessage())); } $this->options = [ diff --git a/Tests/Session/Storage/Proxy/AbstractProxyTest.php b/Tests/Session/Storage/Proxy/AbstractProxyTest.php index 8d04830a7..9551d52b4 100644 --- a/Tests/Session/Storage/Proxy/AbstractProxyTest.php +++ b/Tests/Session/Storage/Proxy/AbstractProxyTest.php @@ -26,7 +26,7 @@ class AbstractProxyTest extends TestCase protected function setUp(): void { - $this->proxy = new class() extends AbstractProxy {}; + $this->proxy = new class extends AbstractProxy {}; } public function testGetSaveHandlerName() diff --git a/Tests/StreamedJsonResponseTest.php b/Tests/StreamedJsonResponseTest.php index db76cd3ae..3d94aa078 100644 --- a/Tests/StreamedJsonResponseTest.php +++ b/Tests/StreamedJsonResponseTest.php @@ -132,14 +132,14 @@ public function testResponseOtherTraversable() { $arrayObject = new \ArrayObject(['__symfony_json__' => '__symfony_json__']); - $iteratorAggregate = new class() implements \IteratorAggregate { + $iteratorAggregate = new class implements \IteratorAggregate { public function getIterator(): \Traversable { return new \ArrayIterator(['__symfony_json__']); } }; - $jsonSerializable = new class() implements \IteratorAggregate, \JsonSerializable { + $jsonSerializable = new class implements \IteratorAggregate, \JsonSerializable { public function getIterator(): \Traversable { return new \ArrayIterator(['This should be ignored']); @@ -187,7 +187,7 @@ public function testResponseStatusCode() public function testPlaceholderAsObjectStructure() { - $object = new class() { + $object = new class { public $__symfony_json__ = 'foo'; public $bar = '__symfony_json__'; };