diff --git a/BinaryFileResponse.php b/BinaryFileResponse.php index ca18c92f1..41c3166d8 100644 --- a/BinaryFileResponse.php +++ b/BinaryFileResponse.php @@ -45,7 +45,7 @@ class BinaryFileResponse extends Response * @param bool $autoEtag Whether the ETag header should be automatically set * @param bool $autoLastModified Whether the Last-Modified header should be automatically set */ - public function __construct(\SplFileInfo|string $file, int $status = 200, array $headers = [], bool $public = true, string $contentDisposition = null, bool $autoEtag = false, bool $autoLastModified = true) + public function __construct(\SplFileInfo|string $file, int $status = 200, array $headers = [], bool $public = true, ?string $contentDisposition = null, bool $autoEtag = false, bool $autoLastModified = true) { parent::__construct(null, $status, $headers); @@ -63,7 +63,7 @@ public function __construct(\SplFileInfo|string $file, int $status = 200, array * * @throws FileException */ - public function setFile(\SplFileInfo|string $file, string $contentDisposition = null, bool $autoEtag = false, bool $autoLastModified = true): static + public function setFile(\SplFileInfo|string $file, ?string $contentDisposition = null, bool $autoEtag = false, bool $autoLastModified = true): static { if (!$file instanceof File) { if ($file instanceof \SplFileInfo) { diff --git a/Cookie.php b/Cookie.php index 706f5ca25..4a3b73608 100644 --- a/Cookie.php +++ b/Cookie.php @@ -77,7 +77,7 @@ public static function fromString(string $cookie, bool $decode = false): static * @param self::SAMESITE_*|''|null $sameSite * @param bool $partitioned */ - public static function create(string $name, string $value = null, int|string|\DateTimeInterface $expire = 0, ?string $path = '/', string $domain = null, bool $secure = null, bool $httpOnly = true, bool $raw = false, ?string $sameSite = self::SAMESITE_LAX /* , bool $partitioned = false */): self + public static function create(string $name, ?string $value = null, int|string|\DateTimeInterface $expire = 0, ?string $path = '/', ?string $domain = null, ?bool $secure = null, bool $httpOnly = true, bool $raw = false, ?string $sameSite = self::SAMESITE_LAX /* , bool $partitioned = false */): self { $partitioned = 9 < \func_num_args() ? func_get_arg(9) : false; @@ -97,7 +97,7 @@ public static function create(string $name, string $value = null, int|string|\Da * * @throws \InvalidArgumentException */ - public function __construct(string $name, string $value = null, int|string|\DateTimeInterface $expire = 0, ?string $path = '/', string $domain = null, bool $secure = null, bool $httpOnly = true, bool $raw = false, ?string $sameSite = self::SAMESITE_LAX, bool $partitioned = false) + public function __construct(string $name, ?string $value = null, int|string|\DateTimeInterface $expire = 0, ?string $path = '/', ?string $domain = null, ?bool $secure = null, bool $httpOnly = true, bool $raw = false, ?string $sameSite = self::SAMESITE_LAX, bool $partitioned = false) { // from PHP source code if ($raw && false !== strpbrk($name, self::RESERVED_CHARS_LIST)) { diff --git a/Exception/SessionNotFoundException.php b/Exception/SessionNotFoundException.php index 94b0cb69a..80a21bf15 100644 --- a/Exception/SessionNotFoundException.php +++ b/Exception/SessionNotFoundException.php @@ -20,7 +20,7 @@ */ class SessionNotFoundException extends \LogicException implements RequestExceptionInterface { - public function __construct(string $message = 'There is currently no session available.', int $code = 0, \Throwable $previous = null) + public function __construct(string $message = 'There is currently no session available.', int $code = 0, ?\Throwable $previous = null) { parent::__construct($message, $code, $previous); } diff --git a/File/File.php b/File/File.php index e8ce4bcf8..34ca5a537 100644 --- a/File/File.php +++ b/File/File.php @@ -82,7 +82,7 @@ public function getMimeType(): ?string * * @throws FileException if the target file could not be created */ - public function move(string $directory, string $name = null): self + public function move(string $directory, ?string $name = null): self { $target = $this->getTargetFile($directory, $name); @@ -112,7 +112,7 @@ public function getContent(): string return $content; } - protected function getTargetFile(string $directory, string $name = null): self + protected function getTargetFile(string $directory, ?string $name = null): self { if (!is_dir($directory)) { if (false === @mkdir($directory, 0777, true) && !is_dir($directory)) { diff --git a/File/UploadedFile.php b/File/UploadedFile.php index e27cf3812..f475d028d 100644 --- a/File/UploadedFile.php +++ b/File/UploadedFile.php @@ -60,7 +60,7 @@ class UploadedFile extends File * @throws FileException If file_uploads is disabled * @throws FileNotFoundException If the file does not exist */ - public function __construct(string $path, string $originalName, string $mimeType = null, int $error = null, bool $test = false) + public function __construct(string $path, string $originalName, ?string $mimeType = null, ?int $error = null, bool $test = false) { $this->originalName = $this->getName($originalName); $this->mimeType = $mimeType ?: 'application/octet-stream'; @@ -158,7 +158,7 @@ public function isValid(): bool * * @throws FileException if, for any reason, the file could not have been moved */ - public function move(string $directory, string $name = null): File + public function move(string $directory, ?string $name = null): File { if ($this->isValid()) { if ($this->test) { diff --git a/HeaderBag.php b/HeaderBag.php index 9a3d5549f..4dd777f16 100644 --- a/HeaderBag.php +++ b/HeaderBag.php @@ -65,7 +65,7 @@ public function __toString(): string * * @return ($key is null ? array> : list) */ - public function all(string $key = null): array + public function all(?string $key = null): array { if (null !== $key) { return $this->headers[strtr($key, self::UPPER, self::LOWER)] ?? []; @@ -110,7 +110,7 @@ public function add(array $headers) /** * Returns the first header by name or the default one. */ - public function get(string $key, string $default = null): ?string + public function get(string $key, ?string $default = null): ?string { $headers = $this->all($key); @@ -197,7 +197,7 @@ public function remove(string $key) * * @throws \RuntimeException When the HTTP header is not parseable */ - public function getDate(string $key, \DateTimeInterface $default = null): ?\DateTimeInterface + public function getDate(string $key, ?\DateTimeInterface $default = null): ?\DateTimeInterface { if (null === $value = $this->get($key)) { return null !== $default ? \DateTimeImmutable::createFromInterface($default) : null; diff --git a/InputBag.php b/InputBag.php index 7676d9fe7..5acf35fec 100644 --- a/InputBag.php +++ b/InputBag.php @@ -84,7 +84,7 @@ public function set(string $key, mixed $value): void * * @return ?T */ - public function getEnum(string $key, string $class, \BackedEnum $default = null): ?\BackedEnum + public function getEnum(string $key, string $class, ?\BackedEnum $default = null): ?\BackedEnum { try { return parent::getEnum($key, $class, $default); diff --git a/JsonResponse.php b/JsonResponse.php index 8dd250a36..93c5751f2 100644 --- a/JsonResponse.php +++ b/JsonResponse.php @@ -75,7 +75,7 @@ public static function fromJsonString(string $data, int $status = 200, array $he * * @throws \InvalidArgumentException When the callback name is not valid */ - public function setCallback(string $callback = null): static + public function setCallback(?string $callback = null): static { if (1 > \func_num_args()) { trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__); diff --git a/ParameterBag.php b/ParameterBag.php index 0456e474c..48fa4b233 100644 --- a/ParameterBag.php +++ b/ParameterBag.php @@ -38,7 +38,7 @@ public function __construct(array $parameters = []) * * @param string|null $key The name of the parameter to return or null to get them all */ - public function all(string $key = null): array + public function all(?string $key = null): array { if (null === $key) { return $this->parameters; @@ -174,7 +174,7 @@ public function getBoolean(string $key, bool $default = false): bool * * @return ?T */ - public function getEnum(string $key, string $class, \BackedEnum $default = null): ?\BackedEnum + public function getEnum(string $key, string $class, ?\BackedEnum $default = null): ?\BackedEnum { $value = $this->get($key); diff --git a/Request.php b/Request.php index 10f3a758f..b482a76dd 100644 --- a/Request.php +++ b/Request.php @@ -448,7 +448,7 @@ public static function setFactory(?callable $callable) * @param array|null $files The FILES parameters * @param array|null $server The SERVER parameters */ - public function duplicate(array $query = null, array $request = null, array $attributes = null, array $cookies = null, array $files = null, array $server = null): static + public function duplicate(?array $query = null, ?array $request = null, ?array $attributes = null, ?array $cookies = null, ?array $files = null, ?array $server = null): static { $dup = clone $this; if (null !== $query) { @@ -1606,7 +1606,7 @@ public function getPreferredFormat(?string $default = 'html'): ?string * * @param string[] $locales An array of ordered available locales */ - public function getPreferredLanguage(array $locales = null): ?string + public function getPreferredLanguage(?array $locales = null): ?string { $preferredLanguages = $this->getLanguages(); @@ -2004,7 +2004,7 @@ public function isFromTrustedProxy(): bool * getPort(), isSecure(), getHost(), getClientIps(), getBaseUrl() etc. Thus, we try to cache the results for * best performance. */ - private function getTrustedValues(int $type, string $ip = null): array + private function getTrustedValues(int $type, ?string $ip = null): array { $cacheKey = $type."\0".((self::$trustedHeaderSet & $type) ? $this->headers->get(self::TRUSTED_HEADERS[$type]) : ''); $cacheKey .= "\0".$ip."\0".$this->headers->get(self::TRUSTED_HEADERS[self::HEADER_FORWARDED]); diff --git a/RequestMatcher.php b/RequestMatcher.php index ac155fa30..b3ca3715d 100644 --- a/RequestMatcher.php +++ b/RequestMatcher.php @@ -51,7 +51,7 @@ class RequestMatcher implements RequestMatcherInterface * @param string|string[]|null $ips * @param string|string[]|null $schemes */ - public function __construct(string $path = null, string $host = null, string|array $methods = null, string|array $ips = null, array $attributes = [], string|array $schemes = null, int $port = null) + public function __construct(?string $path = null, ?string $host = null, string|array|null $methods = null, string|array|null $ips = null, array $attributes = [], string|array|null $schemes = null, ?int $port = null) { $this->matchPath($path); $this->matchHost($host); diff --git a/Response.php b/Response.php index ef6ece002..d67c8f726 100644 --- a/Response.php +++ b/Response.php @@ -497,7 +497,7 @@ public function getProtocolVersion(): string * * @final */ - public function setStatusCode(int $code, string $text = null): static + public function setStatusCode(int $code, ?string $text = null): static { $this->statusCode = $code; if ($this->isInvalid()) { @@ -762,7 +762,7 @@ public function getExpires(): ?\DateTimeImmutable * * @final */ - public function setExpires(\DateTimeInterface $date = null): static + public function setExpires(?\DateTimeInterface $date = null): static { if (1 > \func_num_args()) { trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__); @@ -943,7 +943,7 @@ public function getLastModified(): ?\DateTimeImmutable * * @final */ - public function setLastModified(\DateTimeInterface $date = null): static + public function setLastModified(?\DateTimeInterface $date = null): static { if (1 > \func_num_args()) { trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__); @@ -981,7 +981,7 @@ public function getEtag(): ?string * * @final */ - public function setEtag(string $etag = null, bool $weak = false): static + public function setEtag(?string $etag = null, bool $weak = false): static { if (1 > \func_num_args()) { trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__); @@ -1284,7 +1284,7 @@ public function isNotFound(): bool * * @final */ - public function isRedirect(string $location = null): bool + public function isRedirect(?string $location = null): bool { return \in_array($this->statusCode, [201, 301, 302, 303, 307, 308]) && (null === $location ?: $location == $this->headers->get('Location')); } diff --git a/ResponseHeaderBag.php b/ResponseHeaderBag.php index 10450ca5e..80d267553 100644 --- a/ResponseHeaderBag.php +++ b/ResponseHeaderBag.php @@ -86,7 +86,7 @@ public function replace(array $headers = []) } } - public function all(string $key = null): array + public function all(?string $key = null): array { $headers = parent::all(); @@ -183,7 +183,7 @@ public function setCookie(Cookie $cookie) * * @return void */ - public function removeCookie(string $name, ?string $path = '/', string $domain = null) + public function removeCookie(string $name, ?string $path = '/', ?string $domain = null) { $path ??= '/'; @@ -236,7 +236,7 @@ public function getCookies(string $format = self::COOKIES_FLAT): array * * @return void */ - public function clearCookie(string $name, ?string $path = '/', string $domain = null, bool $secure = false, bool $httpOnly = true, string $sameSite = null) + public function clearCookie(string $name, ?string $path = '/', ?string $domain = null, bool $secure = false, bool $httpOnly = true, ?string $sameSite = null) { $this->setCookie(new Cookie($name, null, 1, $path, $domain, $secure, $httpOnly, false, $sameSite)); } diff --git a/ServerBag.php b/ServerBag.php index 3e912cb80..09fc38664 100644 --- a/ServerBag.php +++ b/ServerBag.php @@ -29,7 +29,7 @@ public function getHeaders(): array foreach ($this->parameters as $key => $value) { if (str_starts_with($key, 'HTTP_')) { $headers[substr($key, 5)] = $value; - } elseif (\in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH', 'CONTENT_MD5'], true)) { + } elseif (\in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH', 'CONTENT_MD5'], true) && '' !== $value) { $headers[$key] = $value; } } diff --git a/Session/Session.php b/Session/Session.php index b45be2f8c..5b6db1754 100644 --- a/Session/Session.php +++ b/Session/Session.php @@ -40,7 +40,7 @@ class Session implements FlashBagAwareSessionInterface, \IteratorAggregate, \Cou private int $usageIndex = 0; private ?\Closure $usageReporter; - public function __construct(SessionStorageInterface $storage = null, AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null, callable $usageReporter = null) + public function __construct(?SessionStorageInterface $storage = null, ?AttributeBagInterface $attributes = null, ?FlashBagInterface $flashes = null, ?callable $usageReporter = null) { $this->storage = $storage ?? new NativeSessionStorage(); $this->usageReporter = null === $usageReporter ? null : $usageReporter(...); @@ -151,14 +151,14 @@ public function isEmpty(): bool return true; } - public function invalidate(int $lifetime = null): bool + public function invalidate(?int $lifetime = null): bool { $this->storage->clear(); return $this->migrate(true, $lifetime); } - public function migrate(bool $destroy = false, int $lifetime = null): bool + public function migrate(bool $destroy = false, ?int $lifetime = null): bool { return $this->storage->regenerate($destroy, $lifetime); } diff --git a/Session/SessionFactory.php b/Session/SessionFactory.php index cdb6af51e..c06ed4b7d 100644 --- a/Session/SessionFactory.php +++ b/Session/SessionFactory.php @@ -26,7 +26,7 @@ class SessionFactory implements SessionFactoryInterface private SessionStorageFactoryInterface $storageFactory; private ?\Closure $usageReporter; - public function __construct(RequestStack $requestStack, SessionStorageFactoryInterface $storageFactory, callable $usageReporter = null) + public function __construct(RequestStack $requestStack, SessionStorageFactoryInterface $storageFactory, ?callable $usageReporter = null) { $this->requestStack = $requestStack; $this->storageFactory = $storageFactory; diff --git a/Session/SessionInterface.php b/Session/SessionInterface.php index 534883d2d..07785a6f4 100644 --- a/Session/SessionInterface.php +++ b/Session/SessionInterface.php @@ -62,7 +62,7 @@ public function setName(string $name); * to expire with browser session. Time is in seconds, and is * not a Unix timestamp. */ - public function invalidate(int $lifetime = null): bool; + public function invalidate(?int $lifetime = null): bool; /** * Migrates the current session to a new session id while maintaining all @@ -74,7 +74,7 @@ public function invalidate(int $lifetime = null): bool; * to expire with browser session. Time is in seconds, and is * not a Unix timestamp. */ - public function migrate(bool $destroy = false, int $lifetime = null): bool; + public function migrate(bool $destroy = false, ?int $lifetime = null): bool; /** * Force the session to be saved and closed. diff --git a/Session/Storage/Handler/NativeFileSessionHandler.php b/Session/Storage/Handler/NativeFileSessionHandler.php index f6e73f9e6..f8c6151a4 100644 --- a/Session/Storage/Handler/NativeFileSessionHandler.php +++ b/Session/Storage/Handler/NativeFileSessionHandler.php @@ -28,7 +28,7 @@ class NativeFileSessionHandler extends \SessionHandler * @throws \InvalidArgumentException On invalid $savePath * @throws \RuntimeException When failing to create the save directory */ - public function __construct(string $savePath = null) + public function __construct(?string $savePath = null) { $baseDir = $savePath ??= \ini_get('session.save_path'); diff --git a/Session/Storage/Handler/PdoSessionHandler.php b/Session/Storage/Handler/PdoSessionHandler.php index 1e8f9c6c4..9cee76ddf 100644 --- a/Session/Storage/Handler/PdoSessionHandler.php +++ b/Session/Storage/Handler/PdoSessionHandler.php @@ -151,7 +151,7 @@ class PdoSessionHandler extends AbstractSessionHandler * * @throws \InvalidArgumentException When PDO error mode is not PDO::ERRMODE_EXCEPTION */ - public function __construct(#[\SensitiveParameter] \PDO|string $pdoOrDsn = null, #[\SensitiveParameter] array $options = []) + public function __construct(#[\SensitiveParameter] \PDO|string|null $pdoOrDsn = null, #[\SensitiveParameter] array $options = []) { if ($pdoOrDsn instanceof \PDO) { if (\PDO::ERRMODE_EXCEPTION !== $pdoOrDsn->getAttribute(\PDO::ATTR_ERRMODE)) { @@ -181,7 +181,7 @@ public function __construct(#[\SensitiveParameter] \PDO|string $pdoOrDsn = null, /** * Adds the Table to the Schema if it doesn't exist. */ - public function configureSchema(Schema $schema, \Closure $isSameDatabase = null): void + public function configureSchema(Schema $schema, ?\Closure $isSameDatabase = null): void { if ($schema->hasTable($this->table) || ($isSameDatabase && !$isSameDatabase($this->getConnection()->exec(...)))) { return; diff --git a/Session/Storage/MetadataBag.php b/Session/Storage/MetadataBag.php index ebe4b748a..5bb4cfbc7 100644 --- a/Session/Storage/MetadataBag.php +++ b/Session/Storage/MetadataBag.php @@ -88,7 +88,7 @@ public function getLifetime(): int * * @return void */ - public function stampNew(int $lifetime = null) + public function stampNew(?int $lifetime = null) { $this->stampCreated($lifetime); } @@ -139,7 +139,7 @@ public function setName(string $name) $this->name = $name; } - private function stampCreated(int $lifetime = null): void + private function stampCreated(?int $lifetime = null): void { $timeStamp = time(); $this->meta[self::CREATED] = $this->meta[self::UPDATED] = $this->lastUsed = $timeStamp; diff --git a/Session/Storage/MockArraySessionStorage.php b/Session/Storage/MockArraySessionStorage.php index d30b56d69..5d1802561 100644 --- a/Session/Storage/MockArraySessionStorage.php +++ b/Session/Storage/MockArraySessionStorage.php @@ -62,7 +62,7 @@ class MockArraySessionStorage implements SessionStorageInterface */ protected $bags = []; - public function __construct(string $name = 'MOCKSESSID', MetadataBag $metaBag = null) + public function __construct(string $name = 'MOCKSESSID', ?MetadataBag $metaBag = null) { $this->name = $name; $this->setMetadataBag($metaBag); @@ -91,7 +91,7 @@ public function start(): bool return true; } - public function regenerate(bool $destroy = false, int $lifetime = null): bool + public function regenerate(bool $destroy = false, ?int $lifetime = null): bool { if (!$this->started) { $this->start(); @@ -192,7 +192,7 @@ public function isStarted(): bool /** * @return void */ - public function setMetadataBag(MetadataBag $bag = null) + public function setMetadataBag(?MetadataBag $bag = null) { if (1 > \func_num_args()) { trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__); diff --git a/Session/Storage/MockFileSessionStorage.php b/Session/Storage/MockFileSessionStorage.php index 95f69f2e1..ef6d9d8f8 100644 --- a/Session/Storage/MockFileSessionStorage.php +++ b/Session/Storage/MockFileSessionStorage.php @@ -30,7 +30,7 @@ class MockFileSessionStorage extends MockArraySessionStorage /** * @param string|null $savePath Path of directory to save session files */ - public function __construct(string $savePath = null, string $name = 'MOCKSESSID', MetadataBag $metaBag = null) + public function __construct(?string $savePath = null, string $name = 'MOCKSESSID', ?MetadataBag $metaBag = null) { $savePath ??= sys_get_temp_dir(); @@ -60,7 +60,7 @@ public function start(): bool return true; } - public function regenerate(bool $destroy = false, int $lifetime = null): bool + public function regenerate(bool $destroy = false, ?int $lifetime = null): bool { if (!$this->started) { $this->start(); diff --git a/Session/Storage/MockFileSessionStorageFactory.php b/Session/Storage/MockFileSessionStorageFactory.php index 8ecf943dc..6727cf14f 100644 --- a/Session/Storage/MockFileSessionStorageFactory.php +++ b/Session/Storage/MockFileSessionStorageFactory.php @@ -28,7 +28,7 @@ class MockFileSessionStorageFactory implements SessionStorageFactoryInterface /** * @see MockFileSessionStorage constructor. */ - public function __construct(string $savePath = null, string $name = 'MOCKSESSID', MetadataBag $metaBag = null) + public function __construct(?string $savePath = null, string $name = 'MOCKSESSID', ?MetadataBag $metaBag = null) { $this->savePath = $savePath; $this->name = $name; diff --git a/Session/Storage/NativeSessionStorage.php b/Session/Storage/NativeSessionStorage.php index 7c6b6f929..f63de5740 100644 --- a/Session/Storage/NativeSessionStorage.php +++ b/Session/Storage/NativeSessionStorage.php @@ -89,7 +89,7 @@ class NativeSessionStorage implements SessionStorageInterface * trans_sid_hosts, $_SERVER['HTTP_HOST'] * trans_sid_tags, "a=href,area=href,frame=src,form=" */ - public function __construct(array $options = [], AbstractProxy|\SessionHandlerInterface $handler = null, MetadataBag $metaBag = null) + public function __construct(array $options = [], AbstractProxy|\SessionHandlerInterface|null $handler = null, ?MetadataBag $metaBag = null) { if (!\extension_loaded('session')) { throw new \LogicException('PHP extension "session" is required.'); @@ -204,7 +204,7 @@ public function setName(string $name) $this->saveHandler->setName($name); } - public function regenerate(bool $destroy = false, int $lifetime = null): bool + public function regenerate(bool $destroy = false, ?int $lifetime = null): bool { // Cannot regenerate the session ID for non-active sessions. if (\PHP_SESSION_ACTIVE !== session_status()) { @@ -317,7 +317,7 @@ public function getBag(string $name): SessionBagInterface /** * @return void */ - public function setMetadataBag(MetadataBag $metaBag = null) + public function setMetadataBag(?MetadataBag $metaBag = null) { if (1 > \func_num_args()) { trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__); @@ -396,7 +396,7 @@ public function setOptions(array $options) * * @throws \InvalidArgumentException */ - public function setSaveHandler(AbstractProxy|\SessionHandlerInterface $saveHandler = null) + public function setSaveHandler(AbstractProxy|\SessionHandlerInterface|null $saveHandler = null) { if (1 > \func_num_args()) { trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__); @@ -429,7 +429,7 @@ public function setSaveHandler(AbstractProxy|\SessionHandlerInterface $saveHandl * * @return void */ - protected function loadSession(array &$session = null) + protected function loadSession(?array &$session = null) { if (null === $session) { $session = &$_SESSION; diff --git a/Session/Storage/NativeSessionStorageFactory.php b/Session/Storage/NativeSessionStorageFactory.php index 08901284c..6463a4c1b 100644 --- a/Session/Storage/NativeSessionStorageFactory.php +++ b/Session/Storage/NativeSessionStorageFactory.php @@ -30,7 +30,7 @@ class NativeSessionStorageFactory implements SessionStorageFactoryInterface /** * @see NativeSessionStorage constructor. */ - public function __construct(array $options = [], AbstractProxy|\SessionHandlerInterface $handler = null, MetadataBag $metaBag = null, bool $secure = false) + public function __construct(array $options = [], AbstractProxy|\SessionHandlerInterface|null $handler = null, ?MetadataBag $metaBag = null, bool $secure = false) { $this->options = $options; $this->handler = $handler; diff --git a/Session/Storage/PhpBridgeSessionStorage.php b/Session/Storage/PhpBridgeSessionStorage.php index 28cb3c3d0..4fb26d2a9 100644 --- a/Session/Storage/PhpBridgeSessionStorage.php +++ b/Session/Storage/PhpBridgeSessionStorage.php @@ -20,7 +20,7 @@ */ class PhpBridgeSessionStorage extends NativeSessionStorage { - public function __construct(AbstractProxy|\SessionHandlerInterface $handler = null, MetadataBag $metaBag = null) + public function __construct(AbstractProxy|\SessionHandlerInterface|null $handler = null, ?MetadataBag $metaBag = null) { if (!\extension_loaded('session')) { throw new \LogicException('PHP extension "session" is required.'); diff --git a/Session/Storage/PhpBridgeSessionStorageFactory.php b/Session/Storage/PhpBridgeSessionStorageFactory.php index 5cc738024..aa4f800d3 100644 --- a/Session/Storage/PhpBridgeSessionStorageFactory.php +++ b/Session/Storage/PhpBridgeSessionStorageFactory.php @@ -26,7 +26,7 @@ class PhpBridgeSessionStorageFactory implements SessionStorageFactoryInterface private ?MetadataBag $metaBag; private bool $secure; - public function __construct(AbstractProxy|\SessionHandlerInterface $handler = null, MetadataBag $metaBag = null, bool $secure = false) + public function __construct(AbstractProxy|\SessionHandlerInterface|null $handler = null, ?MetadataBag $metaBag = null, bool $secure = false) { $this->handler = $handler; $this->metaBag = $metaBag; diff --git a/Session/Storage/SessionStorageInterface.php b/Session/Storage/SessionStorageInterface.php index ed2189e4e..7865135b0 100644 --- a/Session/Storage/SessionStorageInterface.php +++ b/Session/Storage/SessionStorageInterface.php @@ -84,7 +84,7 @@ public function setName(string $name); * * @throws \RuntimeException If an error occurs while regenerating this storage */ - public function regenerate(bool $destroy = false, int $lifetime = null): bool; + public function regenerate(bool $destroy = false, ?int $lifetime = null): bool; /** * Force the session to be saved and closed. diff --git a/StreamedResponse.php b/StreamedResponse.php index 87be96a11..0ab88e098 100644 --- a/StreamedResponse.php +++ b/StreamedResponse.php @@ -33,7 +33,7 @@ class StreamedResponse extends Response /** * @param int $status The HTTP status code (200 "OK" by default) */ - public function __construct(callable $callback = null, int $status = 200, array $headers = []) + public function __construct(?callable $callback = null, int $status = 200, array $headers = []) { parent::__construct(null, $status, $headers); diff --git a/Test/Constraint/ResponseCookieValueSame.php b/Test/Constraint/ResponseCookieValueSame.php index 417efc77a..768007b95 100644 --- a/Test/Constraint/ResponseCookieValueSame.php +++ b/Test/Constraint/ResponseCookieValueSame.php @@ -22,7 +22,7 @@ final class ResponseCookieValueSame extends Constraint private string $path; private ?string $domain; - public function __construct(string $name, string $value, string $path = '/', string $domain = null) + public function __construct(string $name, string $value, string $path = '/', ?string $domain = null) { $this->name = $name; $this->value = $value; diff --git a/Test/Constraint/ResponseHasCookie.php b/Test/Constraint/ResponseHasCookie.php index 73393d386..8eccea9d1 100644 --- a/Test/Constraint/ResponseHasCookie.php +++ b/Test/Constraint/ResponseHasCookie.php @@ -21,7 +21,7 @@ final class ResponseHasCookie extends Constraint private string $path; private ?string $domain; - public function __construct(string $name, string $path = '/', string $domain = null) + public function __construct(string $name, string $path = '/', ?string $domain = null) { $this->name = $name; $this->path = $path; diff --git a/Tests/HeaderUtilsTest.php b/Tests/HeaderUtilsTest.php index befa4aea0..3279b9a53 100644 --- a/Tests/HeaderUtilsTest.php +++ b/Tests/HeaderUtilsTest.php @@ -149,7 +149,7 @@ public static function provideMakeDispositionFail() /** * @dataProvider provideParseQuery */ - public function testParseQuery(string $query, string $expected = null) + public function testParseQuery(string $query, ?string $expected = null) { $this->assertSame($expected ?? $query, http_build_query(HeaderUtils::parseQuery($query), '', '&')); } diff --git a/Tests/ServerBagTest.php b/Tests/ServerBagTest.php index e26714bc4..3d675c512 100644 --- a/Tests/ServerBagTest.php +++ b/Tests/ServerBagTest.php @@ -177,4 +177,20 @@ public function testItDoesNotOverwriteTheAuthorizationHeaderIfItIsAlreadySet() 'PHP_AUTH_PW' => '', ], $bag->getHeaders()); } + + /** + * An HTTP request without content-type and content-length will result in + * the variables $_SERVER['CONTENT_TYPE'] and $_SERVER['CONTENT_LENGTH'] + * containing an empty string in PHP. + */ + public function testRequestWithoutContentTypeAndContentLength() + { + $bag = new ServerBag([ + 'CONTENT_TYPE' => '', + 'CONTENT_LENGTH' => '', + 'HTTP_USER_AGENT' => 'foo', + ]); + + $this->assertSame(['USER_AGENT' => 'foo'], $bag->getHeaders()); + } } diff --git a/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php b/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php index cd34c72e3..ede4703aa 100644 --- a/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php @@ -408,7 +408,7 @@ class MockPdo extends \PDO private ?string $driverName; private bool|int $errorMode; - public function __construct(string $driverName = null, int $errorMode = null) + public function __construct(?string $driverName = null, ?int $errorMode = null) { $this->driverName = $driverName; $this->errorMode = null !== $errorMode ?: \PDO::ERRMODE_EXCEPTION;