diff --git a/src/Symfony/Component/HttpFoundation/AcceptHeader.php b/src/Symfony/Component/HttpFoundation/AcceptHeader.php index bbbd62a6d28ab..90f9f479d5958 100644 --- a/src/Symfony/Component/HttpFoundation/AcceptHeader.php +++ b/src/Symfony/Component/HttpFoundation/AcceptHeader.php @@ -44,15 +44,13 @@ public function __construct(array $items) /** * Builds an AcceptHeader instance from a string. * - * @param string $headerValue - * * @return self */ - public static function fromString($headerValue) + public static function fromString(?string $headerValue) { $index = 0; - $parts = HeaderUtils::split((string) $headerValue, ',;='); + $parts = HeaderUtils::split($headerValue ?? '', ',;='); return new self(array_map(function ($subParts) use (&$index) { $part = array_shift($subParts); @@ -78,11 +76,9 @@ public function __toString() /** * Tests if header has given value. * - * @param string $value - * * @return bool */ - public function has($value) + public function has(string $value) { return isset($this->items[$value]); } @@ -90,11 +86,9 @@ public function has($value) /** * Returns given value's item, if exists. * - * @param string $value - * * @return AcceptHeaderItem|null */ - public function get($value) + public function get(string $value) { return $this->items[$value] ?? $this->items[explode('/', $value)[0].'/*'] ?? $this->items['*/*'] ?? $this->items['*'] ?? null; } @@ -127,11 +121,9 @@ public function all() /** * Filters items on their value using given regex. * - * @param string $pattern - * * @return self */ - public function filter($pattern) + public function filter(string $pattern) { return new self(array_filter($this->items, function (AcceptHeaderItem $item) use ($pattern) { return preg_match($pattern, $item->getValue()); diff --git a/src/Symfony/Component/HttpFoundation/AcceptHeaderItem.php b/src/Symfony/Component/HttpFoundation/AcceptHeaderItem.php index 954aac6014544..bc4014e581693 100644 --- a/src/Symfony/Component/HttpFoundation/AcceptHeaderItem.php +++ b/src/Symfony/Component/HttpFoundation/AcceptHeaderItem.php @@ -34,13 +34,11 @@ public function __construct(string $value, array $attributes = []) /** * Builds an AcceptHeaderInstance instance from a string. * - * @param string $itemValue - * * @return self */ - public static function fromString($itemValue) + public static function fromString(?string $itemValue) { - $parts = HeaderUtils::split($itemValue, ';='); + $parts = HeaderUtils::split($itemValue ?? '', ';='); $part = array_shift($parts); $attributes = HeaderUtils::combine($parts); @@ -66,11 +64,9 @@ public function __toString() /** * Set the item value. * - * @param string $value - * * @return $this */ - public function setValue($value) + public function setValue(string $value) { $this->value = $value; @@ -90,11 +86,9 @@ public function getValue() /** * Set the item quality. * - * @param float $quality - * * @return $this */ - public function setQuality($quality) + public function setQuality(float $quality) { $this->quality = $quality; @@ -114,11 +108,9 @@ public function getQuality() /** * Set the item index. * - * @param int $index - * * @return $this */ - public function setIndex($index) + public function setIndex(int $index) { $this->index = $index; @@ -138,11 +130,9 @@ public function getIndex() /** * Tests if an attribute exists. * - * @param string $name - * * @return bool */ - public function hasAttribute($name) + public function hasAttribute(string $name) { return isset($this->attributes[$name]); } @@ -150,12 +140,11 @@ public function hasAttribute($name) /** * Returns an attribute by its name. * - * @param string $name - * @param mixed $default + * @param mixed $default * * @return mixed */ - public function getAttribute($name, $default = null) + public function getAttribute(string $name, $default = null) { return isset($this->attributes[$name]) ? $this->attributes[$name] : $default; } @@ -173,17 +162,14 @@ public function getAttributes() /** * Set an attribute. * - * @param string $name - * @param string $value - * * @return $this */ - public function setAttribute($name, $value) + public function setAttribute(string $name, string $value) { if ('q' === $name) { $this->quality = (float) $value; } else { - $this->attributes[$name] = (string) $value; + $this->attributes[$name] = $value; } return $this; diff --git a/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php b/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php index 4fd4aec1af296..3f70232e091d8 100644 --- a/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php +++ b/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php @@ -66,7 +66,7 @@ public function __construct($file, int $status = 200, array $headers = [], bool * * @return static */ - public static function create($file = null, $status = 200, $headers = [], $public = true, $contentDisposition = null, $autoEtag = false, $autoLastModified = true) + public static function create($file = null, int $status = 200, array $headers = [], bool $public = true, string $contentDisposition = null, bool $autoEtag = false, bool $autoLastModified = true) { return new static($file, $status, $headers, $public, $contentDisposition, $autoEtag, $autoLastModified); } @@ -74,16 +74,13 @@ public static function create($file = null, $status = 200, $headers = [], $publi /** * Sets the file to stream. * - * @param \SplFileInfo|string $file The file to stream - * @param string $contentDisposition - * @param bool $autoEtag - * @param bool $autoLastModified + * @param \SplFileInfo|string $file The file to stream * * @return $this * * @throws FileException */ - public function setFile($file, $contentDisposition = null, $autoEtag = false, $autoLastModified = true) + public function setFile($file, string $contentDisposition = null, bool $autoEtag = false, bool $autoLastModified = true) { if (!$file instanceof File) { if ($file instanceof \SplFileInfo) { @@ -153,7 +150,7 @@ public function setAutoEtag() * * @return $this */ - public function setContentDisposition($disposition, $filename = '', $filenameFallback = '') + public function setContentDisposition(string $disposition, string $filename = '', string $filenameFallback = '') { if ('' === $filename) { $filename = $this->file->getFilename(); @@ -317,7 +314,7 @@ public function sendContent() * * @throws \LogicException when the content is not null */ - public function setContent($content) + public function setContent(?string $content) { if (null !== $content) { throw new \LogicException('The content cannot be set on a BinaryFileResponse instance.'); @@ -346,11 +343,9 @@ public static function trustXSendfileTypeHeader() * If this is set to true, the file will be unlinked after the request is send * Note: If the X-Sendfile header is used, the deleteFileAfterSend setting will not be used. * - * @param bool $shouldDelete - * * @return $this */ - public function deleteFileAfterSend($shouldDelete = true) + public function deleteFileAfterSend(bool $shouldDelete = true) { $this->deleteFileAfterSend = $shouldDelete; diff --git a/src/Symfony/Component/HttpFoundation/Cookie.php b/src/Symfony/Component/HttpFoundation/Cookie.php index 9391076df8659..6ada5889f6f84 100644 --- a/src/Symfony/Component/HttpFoundation/Cookie.php +++ b/src/Symfony/Component/HttpFoundation/Cookie.php @@ -36,12 +36,9 @@ class Cookie /** * Creates cookie from raw header string. * - * @param string $cookie - * @param bool $decode - * * @return static */ - public static function fromString($cookie, $decode = false) + public static function fromString(string $cookie, bool $decode = false) { $data = [ 'expires' => 0, diff --git a/src/Symfony/Component/HttpFoundation/File/File.php b/src/Symfony/Component/HttpFoundation/File/File.php index 4906588a72aa1..d79c27f68ef79 100644 --- a/src/Symfony/Component/HttpFoundation/File/File.php +++ b/src/Symfony/Component/HttpFoundation/File/File.php @@ -76,14 +76,11 @@ public function getMimeType() /** * Moves the file to a new location. * - * @param string $directory The destination folder - * @param string $name The new file name - * * @return self A File object representing the new file * * @throws FileException if the target file could not be created */ - public function move($directory, $name = null) + public function move(string $directory, string $name = null) { $target = $this->getTargetFile($directory, $name); @@ -102,7 +99,7 @@ public function move($directory, $name = null) /** * @return self */ - protected function getTargetFile($directory, $name = null) + protected function getTargetFile(string $directory, string $name = null) { if (!is_dir($directory)) { if (false === @mkdir($directory, 0777, true) && !is_dir($directory)) { @@ -120,11 +117,9 @@ protected function getTargetFile($directory, $name = null) /** * Returns locale independent base name of the given path. * - * @param string $name The new file name - * * @return string */ - protected function getName($name) + protected function getName(string $name) { $originalName = str_replace('\\', '/', $name); $pos = strrpos($originalName, '/'); diff --git a/src/Symfony/Component/HttpFoundation/File/UploadedFile.php b/src/Symfony/Component/HttpFoundation/File/UploadedFile.php index 3ea8ab55e6aee..a2ed4262d4457 100644 --- a/src/Symfony/Component/HttpFoundation/File/UploadedFile.php +++ b/src/Symfony/Component/HttpFoundation/File/UploadedFile.php @@ -164,14 +164,11 @@ public function isValid() /** * Moves the file to a new location. * - * @param string $directory The destination folder - * @param string $name The new file name - * * @return File A File object representing the new file * * @throws FileException if, for any reason, the file could not have been moved */ - public function move($directory, $name = null) + public function move(string $directory, string $name = null) { if ($this->isValid()) { if ($this->test) { diff --git a/src/Symfony/Component/HttpFoundation/FileBag.php b/src/Symfony/Component/HttpFoundation/FileBag.php index eec3ff4465916..3a131e8243bc4 100644 --- a/src/Symfony/Component/HttpFoundation/FileBag.php +++ b/src/Symfony/Component/HttpFoundation/FileBag.php @@ -43,7 +43,7 @@ public function replace(array $files = []) /** * {@inheritdoc} */ - public function set($key, $value) + public function set(string $key, $value) { if (!\is_array($value) && !$value instanceof UploadedFile) { throw new \InvalidArgumentException('An uploaded file must be an array or an instance of UploadedFile.'); diff --git a/src/Symfony/Component/HttpFoundation/HeaderBag.php b/src/Symfony/Component/HttpFoundation/HeaderBag.php index dd0e0f3966cf6..6a6ebdf3c2492 100644 --- a/src/Symfony/Component/HttpFoundation/HeaderBag.php +++ b/src/Symfony/Component/HttpFoundation/HeaderBag.php @@ -102,14 +102,11 @@ public function add(array $headers) /** * Returns a header value by name. * - * @param string $key The header name - * @param string|null $default The default value - * * @return string|null The first header value or default value */ - public function get($key, $default = null) + public function get(string $key, string $default = null) { - $headers = $this->all((string) $key); + $headers = $this->all($key); return $headers[0] ?? $default; } @@ -117,11 +114,10 @@ public function get($key, $default = null) /** * Sets a header by name. * - * @param string $key The key * @param string|string[] $values The value or an array of values * @param bool $replace Whether to replace the actual value or not (true by default) */ - public function set($key, $values, $replace = true) + public function set(string $key, $values, bool $replace = true) { $key = str_replace('_', '-', strtolower($key)); @@ -149,11 +145,9 @@ public function set($key, $values, $replace = true) /** * Returns true if the HTTP header is defined. * - * @param string $key The HTTP header - * * @return bool true if the parameter exists, false otherwise */ - public function has($key) + public function has(string $key) { return \array_key_exists(str_replace('_', '-', strtolower($key)), $this->all()); } @@ -161,22 +155,17 @@ public function has($key) /** * Returns true if the given HTTP header contains the given value. * - * @param string $key The HTTP header name - * @param string $value The HTTP value - * * @return bool true if the value is contained in the header, false otherwise */ - public function contains($key, $value) + public function contains(string $key, string $value) { - return \in_array($value, $this->all((string) $key)); + return \in_array($value, $this->all($key)); } /** * Removes a header. - * - * @param string $key The HTTP header name */ - public function remove($key) + public function remove(string $key) { $key = str_replace('_', '-', strtolower($key)); @@ -190,13 +179,11 @@ public function remove($key) /** * Returns the HTTP header value converted to a date. * - * @param string $key The parameter key - * * @return \DateTimeInterface|null The parsed DateTime or the default value if the header does not exist * * @throws \RuntimeException When the HTTP header is not parseable */ - public function getDate($key, \DateTime $default = null) + public function getDate(string $key, \DateTime $default = null) { if (null === $value = $this->get($key)) { return $default; @@ -212,10 +199,9 @@ public function getDate($key, \DateTime $default = null) /** * Adds a custom Cache-Control directive. * - * @param string $key The Cache-Control directive name - * @param mixed $value The Cache-Control directive value + * @param mixed $value The Cache-Control directive value */ - public function addCacheControlDirective($key, $value = true) + public function addCacheControlDirective(string $key, $value = true) { $this->cacheControl[$key] = $value; @@ -225,11 +211,9 @@ public function addCacheControlDirective($key, $value = true) /** * Returns true if the Cache-Control directive is defined. * - * @param string $key The Cache-Control directive - * * @return bool true if the directive exists, false otherwise */ - public function hasCacheControlDirective($key) + public function hasCacheControlDirective(string $key) { return \array_key_exists($key, $this->cacheControl); } @@ -237,21 +221,17 @@ public function hasCacheControlDirective($key) /** * Returns a Cache-Control directive value by name. * - * @param string $key The directive name - * * @return mixed|null The directive value if defined, null otherwise */ - public function getCacheControlDirective($key) + public function getCacheControlDirective(string $key) { return \array_key_exists($key, $this->cacheControl) ? $this->cacheControl[$key] : null; } /** * Removes a Cache-Control directive. - * - * @param string $key The Cache-Control directive */ - public function removeCacheControlDirective($key) + public function removeCacheControlDirective(string $key) { unset($this->cacheControl[$key]); @@ -288,11 +268,9 @@ protected function getCacheControlHeader() /** * Parses a Cache-Control HTTP header. * - * @param string $header The value of the Cache-Control HTTP header - * * @return array An array representing the attribute values */ - protected function parseCacheControl($header) + protected function parseCacheControl(string $header) { $parts = HeaderUtils::split($header, ',='); diff --git a/src/Symfony/Component/HttpFoundation/IpUtils.php b/src/Symfony/Component/HttpFoundation/IpUtils.php index 67d13e57aafce..68b472d64a81d 100644 --- a/src/Symfony/Component/HttpFoundation/IpUtils.php +++ b/src/Symfony/Component/HttpFoundation/IpUtils.php @@ -30,12 +30,11 @@ private function __construct() /** * Checks if an IPv4 or IPv6 address is contained in the list of given IPs or subnets. * - * @param string $requestIp IP to check - * @param string|array $ips List of IPs or subnets (can be a string if only a single one) + * @param string|array $ips List of IPs or subnets (can be a string if only a single one) * * @return bool Whether the IP is valid */ - public static function checkIp($requestIp, $ips) + public static function checkIp(?string $requestIp, $ips) { if (!\is_array($ips)) { $ips = [$ips]; @@ -56,12 +55,11 @@ public static function checkIp($requestIp, $ips) * Compares two IPv4 addresses. * In case a subnet is given, it checks if it contains the request IP. * - * @param string $requestIp IPv4 address to check - * @param string $ip IPv4 address or subnet in CIDR notation + * @param string $ip IPv4 address or subnet in CIDR notation * * @return bool Whether the request IP matches the IP, or whether the request IP is within the CIDR subnet */ - public static function checkIp4($requestIp, $ip) + public static function checkIp4(?string $requestIp, string $ip) { $cacheKey = $requestIp.'-'.$ip; if (isset(self::$checkedIps[$cacheKey])) { @@ -102,14 +100,13 @@ public static function checkIp4($requestIp, $ip) * * @see https://github.com/dsp/v6tools * - * @param string $requestIp IPv6 address to check - * @param string $ip IPv6 address or subnet in CIDR notation + * @param string $ip IPv6 address or subnet in CIDR notation * * @return bool Whether the IP is valid * * @throws \RuntimeException When IPV6 support is not enabled */ - public static function checkIp6($requestIp, $ip) + public static function checkIp6(?string $requestIp, string $ip) { $cacheKey = $requestIp.'-'.$ip; if (isset(self::$checkedIps[$cacheKey])) { diff --git a/src/Symfony/Component/HttpFoundation/JsonResponse.php b/src/Symfony/Component/HttpFoundation/JsonResponse.php index 11a0bebf88302..f2a4e60b13b60 100644 --- a/src/Symfony/Component/HttpFoundation/JsonResponse.php +++ b/src/Symfony/Component/HttpFoundation/JsonResponse.php @@ -64,7 +64,7 @@ public function __construct($data = null, int $status = 200, array $headers = [] * * @return static */ - public static function create($data = null, $status = 200, $headers = []) + public static function create($data = null, int $status = 200, array $headers = []) { return new static($data, $status, $headers); } @@ -83,7 +83,7 @@ public static function create($data = null, $status = 200, $headers = []) * * @return static */ - public static function fromJsonString($data = null, $status = 200, $headers = []) + public static function fromJsonString($data = null, int $status = 200, array $headers = []) { return new static($data, $status, $headers, true); } @@ -97,7 +97,7 @@ public static function fromJsonString($data = null, $status = 200, $headers = [] * * @throws \InvalidArgumentException When the callback name is not valid */ - public function setCallback($callback = null) + public function setCallback(string $callback = null) { if (null !== $callback) { // partially taken from https://geekality.net/2011/08/03/valid-javascript-identifier/ @@ -126,13 +126,11 @@ public function setCallback($callback = null) /** * Sets a raw string containing a JSON document to be sent. * - * @param string $json - * * @return $this * * @throws \InvalidArgumentException */ - public function setJson($json) + public function setJson(string $json) { $this->data = $json; @@ -183,13 +181,11 @@ public function getEncodingOptions() /** * Sets options used while encoding data to JSON. * - * @param int $encodingOptions - * * @return $this */ - public function setEncodingOptions($encodingOptions) + public function setEncodingOptions(int $encodingOptions) { - $this->encodingOptions = (int) $encodingOptions; + $this->encodingOptions = $encodingOptions; return $this->setData(json_decode($this->data)); } diff --git a/src/Symfony/Component/HttpFoundation/ParameterBag.php b/src/Symfony/Component/HttpFoundation/ParameterBag.php index 20ca6758b68bc..bf021a55b1c71 100644 --- a/src/Symfony/Component/HttpFoundation/ParameterBag.php +++ b/src/Symfony/Component/HttpFoundation/ParameterBag.php @@ -67,12 +67,11 @@ public function add(array $parameters = []) /** * Returns a parameter by name. * - * @param string $key The key - * @param mixed $default The default value if the parameter key does not exist + * @param mixed $default The default value if the parameter key does not exist * * @return mixed */ - public function get($key, $default = null) + public function get(string $key, $default = null) { return \array_key_exists($key, $this->parameters) ? $this->parameters[$key] : $default; } @@ -80,10 +79,9 @@ public function get($key, $default = null) /** * Sets a parameter by name. * - * @param string $key The key - * @param mixed $value The value + * @param mixed $value The value */ - public function set($key, $value) + public function set(string $key, $value) { $this->parameters[$key] = $value; } @@ -91,21 +89,17 @@ public function set($key, $value) /** * Returns true if the parameter is defined. * - * @param string $key The key - * * @return bool true if the parameter exists, false otherwise */ - public function has($key) + public function has(string $key) { return \array_key_exists($key, $this->parameters); } /** * Removes a parameter. - * - * @param string $key The key */ - public function remove($key) + public function remove(string $key) { unset($this->parameters[$key]); } @@ -113,12 +107,9 @@ public function remove($key) /** * Returns the alphabetic characters of the parameter value. * - * @param string $key The parameter key - * @param string $default The default value if the parameter key does not exist - * * @return string The filtered value */ - public function getAlpha($key, $default = '') + public function getAlpha(string $key, string $default = '') { return preg_replace('/[^[:alpha:]]/', '', $this->get($key, $default)); } @@ -126,12 +117,9 @@ public function getAlpha($key, $default = '') /** * Returns the alphabetic characters and digits of the parameter value. * - * @param string $key The parameter key - * @param string $default The default value if the parameter key does not exist - * * @return string The filtered value */ - public function getAlnum($key, $default = '') + public function getAlnum(string $key, string $default = '') { return preg_replace('/[^[:alnum:]]/', '', $this->get($key, $default)); } @@ -139,12 +127,9 @@ public function getAlnum($key, $default = '') /** * Returns the digits of the parameter value. * - * @param string $key The parameter key - * @param string $default The default value if the parameter key does not exist - * * @return string The filtered value */ - public function getDigits($key, $default = '') + public function getDigits(string $key, string $default = '') { // we need to remove - and + because they're allowed in the filter return str_replace(['-', '+'], '', $this->filter($key, $default, FILTER_SANITIZE_NUMBER_INT)); @@ -153,25 +138,19 @@ public function getDigits($key, $default = '') /** * Returns the parameter value converted to integer. * - * @param string $key The parameter key - * @param int $default The default value if the parameter key does not exist - * * @return int The filtered value */ - public function getInt($key, $default = 0) + public function getInt(string $key, int $default = 0) { - return (int) $this->get($key, $default); + return $this->get($key, $default); } /** * Returns the parameter value converted to boolean. * - * @param string $key The parameter key - * @param bool $default The default value if the parameter key does not exist - * * @return bool The filtered value */ - public function getBoolean($key, $default = false) + public function getBoolean(string $key, bool $default = false) { return $this->filter($key, $default, FILTER_VALIDATE_BOOLEAN); } @@ -179,16 +158,15 @@ public function getBoolean($key, $default = false) /** * Filter key. * - * @param string $key Key - * @param mixed $default Default = null - * @param int $filter FILTER_* constant - * @param mixed $options Filter options + * @param mixed $default Default = null + * @param int $filter FILTER_* constant + * @param mixed $options Filter options * * @see https://php.net/filter-var * * @return mixed */ - public function filter($key, $default = null, $filter = FILTER_DEFAULT, $options = []) + public function filter(string $key, $default = null, int $filter = FILTER_DEFAULT, $options = []) { $value = $this->get($key, $default); diff --git a/src/Symfony/Component/HttpFoundation/RedirectResponse.php b/src/Symfony/Component/HttpFoundation/RedirectResponse.php index 621a3d8d359ca..c7da9f61cad7d 100644 --- a/src/Symfony/Component/HttpFoundation/RedirectResponse.php +++ b/src/Symfony/Component/HttpFoundation/RedirectResponse.php @@ -50,13 +50,11 @@ public function __construct(string $url, int $status = 302, array $headers = []) /** * Factory method for chainability. * - * @param string $url The url to redirect to - * @param int $status The response status code - * @param array $headers An array of response headers + * @param string $url The URL to redirect to * * @return static */ - public static function create($url = '', $status = 302, $headers = []) + public static function create($url = '', int $status = 302, array $headers = []) { return new static($url, $status, $headers); } @@ -74,15 +72,13 @@ public function getTargetUrl() /** * Sets the redirect target of this response. * - * @param string $url The URL to redirect to - * * @return $this * * @throws \InvalidArgumentException */ - public function setTargetUrl($url) + public function setTargetUrl(string $url) { - if ('' === ($url ?? '')) { + if ('' === $url) { throw new \InvalidArgumentException('Cannot redirect to an empty URL.'); } diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 8368ba655ed3b..309565fc109a1 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -310,7 +310,7 @@ public static function createFromGlobals() * * @return static */ - public static function create($uri, $method = 'GET', $parameters = [], $cookies = [], $files = [], $server = [], $content = null) + public static function create(string $uri, string $method = 'GET', array $parameters = [], array $cookies = [], array $files = [], array $server = [], $content = null) { $server = array_replace([ 'SERVER_NAME' => 'localhost', @@ -408,10 +408,8 @@ public static function create($uri, $method = 'GET', $parameters = [], $cookies * This is mainly useful when you need to override the Request class * to keep BC with an existing system. It should not be used for any * other purpose. - * - * @param callable|null $callable A PHP callable */ - public static function setFactory($callable) + public static function setFactory(?callable $callable) { self::$requestFactory = $callable; } @@ -626,11 +624,9 @@ public static function getTrustedHosts() * It builds a normalized query string, where keys/value pairs are alphabetized, * have consistent escaping and unneeded delimiters are removed. * - * @param string $qs Query string - * * @return string A normalized query string for the Request */ - public static function normalizeQueryString($qs) + public static function normalizeQueryString(?string $qs) { if ('' === ($qs ?? '')) { return ''; @@ -677,12 +673,11 @@ public static function getHttpMethodParameterOverride() * * Order of precedence: PATH (routing placeholders or custom attributes), GET, BODY * - * @param string $key The key - * @param mixed $default The default value if the parameter key does not exist + * @param mixed $default The default value if the parameter key does not exist * * @return mixed */ - public function get($key, $default = null) + public function get(string $key, $default = null) { if ($this !== $result = $this->attributes->get($key, $this)) { return $result; @@ -1028,7 +1023,7 @@ public function getUri() * * @return string The normalized URI for the path */ - public function getUriForPath($path) + public function getUriForPath(string $path) { return $this->getSchemeAndHttpHost().$this->getBaseUrl().$path; } @@ -1048,11 +1043,9 @@ public function getUriForPath($path) * - "/a/b/c/other" -> "other" * - "/a/x/y" -> "../../x/y" * - * @param string $path The target path - * * @return string The relative target path */ - public function getRelativeUriForPath($path) + public function getRelativeUriForPath(string $path) { // be sure that we are dealing with an absolute path if (!isset($path[0]) || '/' !== $path[0]) { @@ -1190,10 +1183,8 @@ public function getHost() /** * Sets the request method. - * - * @param string $method */ - public function setMethod($method) + public function setMethod(string $method) { $this->method = null; $this->server->set('REQUEST_METHOD', $method); @@ -1264,11 +1255,9 @@ public function getRealMethod() /** * Gets the mime type associated with the format. * - * @param string $format The format - * * @return string|null The associated mime type (null if not found) */ - public function getMimeType($format) + public function getMimeType(string $format) { if (null === static::$formats) { static::initializeFormats(); @@ -1280,11 +1269,9 @@ public function getMimeType($format) /** * Gets the mime types associated with the format. * - * @param string $format The format - * * @return array The associated mime types */ - public static function getMimeTypes($format) + public static function getMimeTypes(string $format) { if (null === static::$formats) { static::initializeFormats(); @@ -1296,11 +1283,9 @@ public static function getMimeTypes($format) /** * Gets the format associated with the mime type. * - * @param string $mimeType The associated mime type - * * @return string|null The format (null if not found) */ - public function getFormat($mimeType) + public function getFormat(?string $mimeType) { $canonicalMimeType = null; if (false !== $pos = strpos($mimeType, ';')) { @@ -1324,10 +1309,9 @@ public function getFormat($mimeType) /** * Associates a format with mime types. * - * @param string $format The format * @param string|array $mimeTypes The associated mime types (the preferred one must be the first as it will be used as the content type) */ - public function setFormat($format, $mimeTypes) + public function setFormat(?string $format, $mimeTypes) { if (null === static::$formats) { static::initializeFormats(); @@ -1347,11 +1331,9 @@ public function setFormat($format, $mimeTypes) * * @see getPreferredFormat * - * @param string|null $default The default format - * * @return string|null The request format */ - public function getRequestFormat($default = 'html') + public function getRequestFormat(?string $default = 'html') { if (null === $this->format) { $this->format = $this->attributes->get('_format'); @@ -1362,10 +1344,8 @@ public function getRequestFormat($default = 'html') /** * Sets the request format. - * - * @param string $format The request format */ - public function setRequestFormat($format) + public function setRequestFormat(?string $format) { $this->format = $format; } @@ -1382,10 +1362,8 @@ public function getContentType() /** * Sets the default locale. - * - * @param string $locale */ - public function setDefaultLocale($locale) + public function setDefaultLocale(string $locale) { $this->defaultLocale = $locale; @@ -1406,10 +1384,8 @@ public function getDefaultLocale() /** * Sets the locale. - * - * @param string $locale */ - public function setLocale($locale) + public function setLocale(string $locale) { $this->setPhpDefaultLocale($this->locale = $locale); } @@ -1431,7 +1407,7 @@ public function getLocale() * * @return bool */ - public function isMethod($method) + public function isMethod(string $method) { return $this->getMethod() === strtoupper($method); } @@ -1503,7 +1479,7 @@ public function getProtocolVersion() * * @throws \LogicException */ - public function getContent($asResource = false) + public function getContent(bool $asResource = false) { $currentContentIsResource = \is_resource($this->content); diff --git a/src/Symfony/Component/HttpFoundation/RequestMatcher.php b/src/Symfony/Component/HttpFoundation/RequestMatcher.php index 9a4a2a13761e1..c32c5cdce5e1c 100644 --- a/src/Symfony/Component/HttpFoundation/RequestMatcher.php +++ b/src/Symfony/Component/HttpFoundation/RequestMatcher.php @@ -84,10 +84,8 @@ public function matchScheme($scheme) /** * Adds a check for the URL host name. - * - * @param string|null $regexp A Regexp */ - public function matchHost($regexp) + public function matchHost(?string $regexp) { $this->host = $regexp; } @@ -104,10 +102,8 @@ public function matchPort(?int $port) /** * Adds a check for the URL path info. - * - * @param string|null $regexp A Regexp */ - public function matchPath($regexp) + public function matchPath(?string $regexp) { $this->path = $regexp; } @@ -117,7 +113,7 @@ public function matchPath($regexp) * * @param string $ip A specific IP address or a range specified using IP/netmask like 192.168.1.0/24 */ - public function matchIp($ip) + public function matchIp(string $ip) { $this->matchIps($ip); } @@ -144,11 +140,8 @@ public function matchMethod($method) /** * Adds a check for request attribute. - * - * @param string $key The request attribute name - * @param string $regexp A Regexp */ - public function matchAttribute($key, $regexp) + public function matchAttribute(string $key, string $regexp) { $this->attributes[$key] = $regexp; } diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index 929fac4727bd0..6c69b9536d50e 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -191,7 +191,7 @@ class Response /** * @throws \InvalidArgumentException When the HTTP status code is not valid */ - public function __construct($content = '', int $status = 200, array $headers = []) + public function __construct(?string $content = '', int $status = 200, array $headers = []) { $this->headers = new ResponseHeaderBag($headers); $this->setContent($content); @@ -207,13 +207,9 @@ public function __construct($content = '', int $status = 200, array $headers = [ * return Response::create($body, 200) * ->setSharedMaxAge(300); * - * @param mixed $content The response content, see setContent() - * @param int $status The response status code - * @param array $headers An array of response headers - * * @return static */ - public static function create($content = '', $status = 200, $headers = []) + public static function create(?string $content = '', int $status = 200, array $headers = []) { return new static($content, $status, $headers); } @@ -382,21 +378,13 @@ public function send() /** * Sets the response content. * - * Valid types are strings, numbers, null, and objects that implement a __toString() method. - * - * @param mixed $content Content that can be cast to string - * * @return $this * * @throws \UnexpectedValueException */ - public function setContent($content) + public function setContent(?string $content) { - if (null !== $content && !\is_string($content) && !is_numeric($content) && !\is_callable([$content, '__toString'])) { - throw new \UnexpectedValueException(sprintf('The Response content must be a string or object implementing __toString(), "%s" given.', \gettype($content))); - } - - $this->content = (string) $content; + $this->content = $content ?? ''; return $this; } diff --git a/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php b/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php index 9d7163ebcc226..2abd3b6a174fe 100644 --- a/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php +++ b/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php @@ -108,7 +108,7 @@ public function all(string $key = null) /** * {@inheritdoc} */ - public function set($key, $values, $replace = true) + public function set(string $key, $values, bool $replace = true) { $uniqueKey = str_replace('_', '-', strtolower($key)); @@ -139,7 +139,7 @@ public function set($key, $values, $replace = true) /** * {@inheritdoc} */ - public function remove($key) + public function remove(string $key) { $uniqueKey = str_replace('_', '-', strtolower($key)); unset($this->headerNames[$uniqueKey]); @@ -164,7 +164,7 @@ public function remove($key) /** * {@inheritdoc} */ - public function hasCacheControlDirective($key) + public function hasCacheControlDirective(string $key) { return \array_key_exists($key, $this->computedCacheControl); } @@ -172,7 +172,7 @@ public function hasCacheControlDirective($key) /** * {@inheritdoc} */ - public function getCacheControlDirective($key) + public function getCacheControlDirective(string $key) { return \array_key_exists($key, $this->computedCacheControl) ? $this->computedCacheControl[$key] : null; } @@ -185,12 +185,8 @@ public function setCookie(Cookie $cookie) /** * Removes a cookie from the array, but does not unset it in the browser. - * - * @param string $name - * @param string $path - * @param string $domain */ - public function removeCookie($name, $path = '/', $domain = null) + public function removeCookie(string $name, ?string $path = '/', string $domain = null) { if (null === $path) { $path = '/'; @@ -214,13 +210,11 @@ public function removeCookie($name, $path = '/', $domain = null) /** * Returns an array with all cookies. * - * @param string $format - * * @return Cookie[] * * @throws \InvalidArgumentException When the $format is invalid */ - public function getCookies($format = self::COOKIES_FLAT) + public function getCookies(string $format = self::COOKIES_FLAT) { 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]))); @@ -244,14 +238,8 @@ public function getCookies($format = self::COOKIES_FLAT) /** * Clears a cookie in the browser. - * - * @param string $name - * @param string $path - * @param string $domain - * @param bool $secure - * @param bool $httpOnly */ - public function clearCookie($name, $path = '/', $domain = null, $secure = false, $httpOnly = true) + public function clearCookie(string $name, ?string $path = '/', string $domain = null, bool $secure = false, bool $httpOnly = true) { $this->setCookie(new Cookie($name, null, 1, $path, $domain, $secure, $httpOnly, false, null)); } @@ -259,9 +247,9 @@ public function clearCookie($name, $path = '/', $domain = null, $secure = false, /** * @see HeaderUtils::makeDisposition() */ - public function makeDisposition($disposition, $filename, $filenameFallback = '') + public function makeDisposition(string $disposition, string $filename, string $filenameFallback = '') { - return HeaderUtils::makeDisposition((string) $disposition, (string) $filename, (string) $filenameFallback); + return HeaderUtils::makeDisposition($disposition, $filename, $filenameFallback); } /** diff --git a/src/Symfony/Component/HttpFoundation/Session/Attribute/AttributeBag.php b/src/Symfony/Component/HttpFoundation/Session/Attribute/AttributeBag.php index ee33698cf0842..aad6b610e7bb3 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Attribute/AttributeBag.php +++ b/src/Symfony/Component/HttpFoundation/Session/Attribute/AttributeBag.php @@ -37,7 +37,7 @@ public function getName() return $this->name; } - public function setName($name) + public function setName(string $name) { $this->name = $name; } @@ -61,7 +61,7 @@ public function getStorageKey() /** * {@inheritdoc} */ - public function has($name) + public function has(string $name) { return \array_key_exists($name, $this->attributes); } @@ -69,7 +69,7 @@ public function has($name) /** * {@inheritdoc} */ - public function get($name, $default = null) + public function get(string $name, $default = null) { return \array_key_exists($name, $this->attributes) ? $this->attributes[$name] : $default; } @@ -77,7 +77,7 @@ public function get($name, $default = null) /** * {@inheritdoc} */ - public function set($name, $value) + public function set(string $name, $value) { $this->attributes[$name] = $value; } @@ -104,7 +104,7 @@ public function replace(array $attributes) /** * {@inheritdoc} */ - public function remove($name) + public function remove(string $name) { $retval = null; if (\array_key_exists($name, $this->attributes)) { diff --git a/src/Symfony/Component/HttpFoundation/Session/Attribute/AttributeBagInterface.php b/src/Symfony/Component/HttpFoundation/Session/Attribute/AttributeBagInterface.php index 6fa2293970b90..7017b717e4064 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Attribute/AttributeBagInterface.php +++ b/src/Symfony/Component/HttpFoundation/Session/Attribute/AttributeBagInterface.php @@ -23,29 +23,25 @@ interface AttributeBagInterface extends SessionBagInterface /** * Checks if an attribute is defined. * - * @param string $name The attribute name - * * @return bool true if the attribute is defined, false otherwise */ - public function has($name); + public function has(string $name); /** * Returns an attribute. * - * @param string $name The attribute name - * @param mixed $default The default value if not found + * @param mixed $default The default value if not found * * @return mixed */ - public function get($name, $default = null); + public function get(string $name, $default = null); /** * Sets an attribute. * - * @param string $name - * @param mixed $value + * @param mixed $value */ - public function set($name, $value); + public function set(string $name, $value); /** * Returns attributes. @@ -59,9 +55,7 @@ public function replace(array $attributes); /** * Removes an attribute. * - * @param string $name - * * @return mixed The removed value or null when it does not exist */ - public function remove($name); + public function remove(string $name); } diff --git a/src/Symfony/Component/HttpFoundation/Session/Attribute/NamespacedAttributeBag.php b/src/Symfony/Component/HttpFoundation/Session/Attribute/NamespacedAttributeBag.php index 162c4b5295849..0c4690f4b74ca 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Attribute/NamespacedAttributeBag.php +++ b/src/Symfony/Component/HttpFoundation/Session/Attribute/NamespacedAttributeBag.php @@ -34,7 +34,7 @@ public function __construct(string $storageKey = '_sf2_attributes', string $name /** * {@inheritdoc} */ - public function has($name) + public function has(string $name) { // reference mismatch: if fixed, re-introduced in array_key_exists; keep as it is $attributes = $this->resolveAttributePath($name); @@ -50,7 +50,7 @@ public function has($name) /** * {@inheritdoc} */ - public function get($name, $default = null) + public function get(string $name, $default = null) { // reference mismatch: if fixed, re-introduced in array_key_exists; keep as it is $attributes = $this->resolveAttributePath($name); @@ -66,7 +66,7 @@ public function get($name, $default = null) /** * {@inheritdoc} */ - public function set($name, $value) + public function set(string $name, $value) { $attributes = &$this->resolveAttributePath($name, true); $name = $this->resolveKey($name); @@ -76,7 +76,7 @@ public function set($name, $value) /** * {@inheritdoc} */ - public function remove($name) + public function remove(string $name) { $retval = null; $attributes = &$this->resolveAttributePath($name); @@ -99,7 +99,7 @@ public function remove($name) * * @return array */ - protected function &resolveAttributePath($name, $writeContext = false) + protected function &resolveAttributePath(string $name, bool $writeContext = false) { $array = &$this->attributes; $name = (0 === strpos($name, $this->namespaceCharacter)) ? substr($name, 1) : $name; @@ -144,11 +144,9 @@ protected function &resolveAttributePath($name, $writeContext = false) * * This is the last part in a dot separated string. * - * @param string $name - * * @return string */ - protected function resolveKey($name) + protected function resolveKey(string $name) { if (false !== $pos = strrpos($name, $this->namespaceCharacter)) { $name = substr($name, $pos + 1); diff --git a/src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php b/src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php index 6502f3d50155f..2707d64ec7138 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php +++ b/src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php @@ -38,7 +38,7 @@ public function getName() return $this->name; } - public function setName($name) + public function setName(string $name) { $this->name = $name; } @@ -60,7 +60,7 @@ public function initialize(array &$flashes) /** * {@inheritdoc} */ - public function add($type, $message) + public function add(string $type, $message) { $this->flashes['new'][$type][] = $message; } @@ -68,7 +68,7 @@ public function add($type, $message) /** * {@inheritdoc} */ - public function peek($type, array $default = []) + public function peek(string $type, array $default = []) { return $this->has($type) ? $this->flashes['display'][$type] : $default; } @@ -84,7 +84,7 @@ public function peekAll() /** * {@inheritdoc} */ - public function get($type, array $default = []) + public function get(string $type, array $default = []) { $return = $default; @@ -122,7 +122,7 @@ public function setAll(array $messages) /** * {@inheritdoc} */ - public function set($type, $messages) + public function set(string $type, $messages) { $this->flashes['new'][$type] = (array) $messages; } @@ -130,7 +130,7 @@ public function set($type, $messages) /** * {@inheritdoc} */ - public function has($type) + public function has(string $type) { return \array_key_exists($type, $this->flashes['display']) && $this->flashes['display'][$type]; } diff --git a/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBag.php b/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBag.php index c6b7ce354cec4..88df7508ac689 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBag.php +++ b/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBag.php @@ -38,7 +38,7 @@ public function getName() return $this->name; } - public function setName($name) + public function setName(string $name) { $this->name = $name; } @@ -54,7 +54,7 @@ public function initialize(array &$flashes) /** * {@inheritdoc} */ - public function add($type, $message) + public function add(string $type, $message) { $this->flashes[$type][] = $message; } @@ -62,7 +62,7 @@ public function add($type, $message) /** * {@inheritdoc} */ - public function peek($type, array $default = []) + public function peek(string $type, array $default = []) { return $this->has($type) ? $this->flashes[$type] : $default; } @@ -78,7 +78,7 @@ public function peekAll() /** * {@inheritdoc} */ - public function get($type, array $default = []) + public function get(string $type, array $default = []) { if (!$this->has($type)) { return $default; @@ -105,7 +105,7 @@ public function all() /** * {@inheritdoc} */ - public function set($type, $messages) + public function set(string $type, $messages) { $this->flashes[$type] = (array) $messages; } @@ -121,7 +121,7 @@ public function setAll(array $messages) /** * {@inheritdoc} */ - public function has($type) + public function has(string $type) { return \array_key_exists($type, $this->flashes) && $this->flashes[$type]; } diff --git a/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBagInterface.php b/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBagInterface.php index 99e8074214b62..8713e71d0f62e 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBagInterface.php +++ b/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBagInterface.php @@ -23,18 +23,16 @@ interface FlashBagInterface extends SessionBagInterface /** * Adds a flash message for the given type. * - * @param string $type - * @param mixed $message + * @param mixed $message */ - public function add($type, $message); + public function add(string $type, $message); /** * Registers one or more messages for a given type. * - * @param string $type * @param string|array $messages */ - public function set($type, $messages); + public function set(string $type, $messages); /** * Gets flash messages for a given type. @@ -44,7 +42,7 @@ public function set($type, $messages); * * @return array */ - public function peek($type, array $default = []); + public function peek(string $type, array $default = []); /** * Gets all flash messages. @@ -56,12 +54,11 @@ public function peekAll(); /** * Gets and clears flash from the stack. * - * @param string $type - * @param array $default Default value if $type does not exist + * @param array $default Default value if $type does not exist * * @return array */ - public function get($type, array $default = []); + public function get(string $type, array $default = []); /** * Gets and clears flashes from the stack. @@ -78,11 +75,9 @@ public function setAll(array $messages); /** * Has flash messages for a given type? * - * @param string $type - * * @return bool */ - public function has($type); + public function has(string $type); /** * Returns a list of all defined types. diff --git a/src/Symfony/Component/HttpFoundation/Session/Session.php b/src/Symfony/Component/HttpFoundation/Session/Session.php index 365ef29cf0f8b..e55eb45eaf90f 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Session.php +++ b/src/Symfony/Component/HttpFoundation/Session/Session.php @@ -55,7 +55,7 @@ public function start() /** * {@inheritdoc} */ - public function has($name) + public function has(string $name) { return $this->getAttributeBag()->has($name); } @@ -63,7 +63,7 @@ public function has($name) /** * {@inheritdoc} */ - public function get($name, $default = null) + public function get(string $name, $default = null) { return $this->getAttributeBag()->get($name, $default); } @@ -71,7 +71,7 @@ public function get($name, $default = null) /** * {@inheritdoc} */ - public function set($name, $value) + public function set(string $name, $value) { $this->getAttributeBag()->set($name, $value); } @@ -95,7 +95,7 @@ public function replace(array $attributes) /** * {@inheritdoc} */ - public function remove($name) + public function remove(string $name) { return $this->getAttributeBag()->remove($name); } @@ -168,7 +168,7 @@ public function isEmpty() /** * {@inheritdoc} */ - public function invalidate($lifetime = null) + public function invalidate(int $lifetime = null) { $this->storage->clear(); @@ -178,7 +178,7 @@ public function invalidate($lifetime = null) /** * {@inheritdoc} */ - public function migrate($destroy = false, $lifetime = null) + public function migrate(bool $destroy = false, int $lifetime = null) { return $this->storage->regenerate($destroy, $lifetime); } @@ -202,7 +202,7 @@ public function getId() /** * {@inheritdoc} */ - public function setId($id) + public function setId(string $id) { if ($this->storage->getId() !== $id) { $this->storage->setId($id); @@ -220,7 +220,7 @@ public function getName() /** * {@inheritdoc} */ - public function setName($name) + public function setName(string $name) { $this->storage->setName($name); } @@ -246,7 +246,7 @@ public function registerBag(SessionBagInterface $bag) /** * {@inheritdoc} */ - public function getBag($name) + public function getBag(string $name) { $bag = $this->storage->getBag($name); diff --git a/src/Symfony/Component/HttpFoundation/Session/SessionInterface.php b/src/Symfony/Component/HttpFoundation/Session/SessionInterface.php index e758c6bda6018..b2f09fd0dc713 100644 --- a/src/Symfony/Component/HttpFoundation/Session/SessionInterface.php +++ b/src/Symfony/Component/HttpFoundation/Session/SessionInterface.php @@ -38,10 +38,8 @@ public function getId(); /** * Sets the session ID. - * - * @param string $id */ - public function setId($id); + public function setId(string $id); /** * Returns the session name. @@ -52,10 +50,8 @@ public function getName(); /** * Sets the session name. - * - * @param string $name */ - public function setName($name); + public function setName(string $name); /** * Invalidates the current session. @@ -70,7 +66,7 @@ public function setName($name); * * @return bool */ - public function invalidate($lifetime = null); + public function invalidate(int $lifetime = null); /** * Migrates the current session to a new session id while maintaining all @@ -84,7 +80,7 @@ public function invalidate($lifetime = null); * * @return bool */ - public function migrate($destroy = false, $lifetime = null); + public function migrate(bool $destroy = false, int $lifetime = null); /** * Force the session to be saved and closed. @@ -98,29 +94,25 @@ public function save(); /** * Checks if an attribute is defined. * - * @param string $name The attribute name - * * @return bool */ - public function has($name); + public function has(string $name); /** * Returns an attribute. * - * @param string $name The attribute name - * @param mixed $default The default value if not found + * @param mixed $default The default value if not found * * @return mixed */ - public function get($name, $default = null); + public function get(string $name, $default = null); /** * Sets an attribute. * - * @param string $name - * @param mixed $value + * @param mixed $value */ - public function set($name, $value); + public function set(string $name, $value); /** * Returns attributes. @@ -137,11 +129,9 @@ public function replace(array $attributes); /** * Removes an attribute. * - * @param string $name - * * @return mixed The removed value or null when it does not exist */ - public function remove($name); + public function remove(string $name); /** * Clears all attributes. @@ -163,11 +153,9 @@ public function registerBag(SessionBagInterface $bag); /** * Gets a bag instance by name. * - * @param string $name - * * @return SessionBagInterface */ - public function getBag($name); + public function getBag(string $name); /** * Gets session meta. diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/AbstractSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/AbstractSessionHandler.php index 78340efbd2228..9594c0ac42460 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/AbstractSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/AbstractSessionHandler.php @@ -42,26 +42,19 @@ public function open($savePath, $sessionName) } /** - * @param string $sessionId - * * @return string */ - abstract protected function doRead($sessionId); + abstract protected function doRead(string $sessionId); /** - * @param string $sessionId - * @param string $data - * * @return bool */ - abstract protected function doWrite($sessionId, $data); + abstract protected function doWrite(string $sessionId, string $data); /** - * @param string $sessionId - * * @return bool */ - abstract protected function doDestroy($sessionId); + abstract protected function doDestroy(string $sessionId); /** * {@inheritdoc} diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcachedSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcachedSessionHandler.php index 3faa336f69dd6..6f5df61f4d87d 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcachedSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcachedSessionHandler.php @@ -65,7 +65,7 @@ public function close() /** * {@inheritdoc} */ - protected function doRead($sessionId) + protected function doRead(string $sessionId) { return $this->memcached->get($this->prefix.$sessionId) ?: ''; } @@ -83,7 +83,7 @@ public function updateTimestamp($sessionId, $data) /** * {@inheritdoc} */ - protected function doWrite($sessionId, $data) + protected function doWrite(string $sessionId, string $data) { return $this->memcached->set($this->prefix.$sessionId, $data, time() + $this->ttl); } @@ -91,7 +91,7 @@ protected function doWrite($sessionId, $data) /** * {@inheritdoc} */ - protected function doDestroy($sessionId) + protected function doDestroy(string $sessionId) { $result = $this->memcached->delete($this->prefix.$sessionId); diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php index 53d9369e8d53b..7ee188acf6443 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php @@ -90,7 +90,7 @@ public function close() /** * {@inheritdoc} */ - protected function doDestroy($sessionId) + protected function doDestroy(string $sessionId) { $this->getCollection()->deleteOne([ $this->options['id_field'] => $sessionId, @@ -114,7 +114,7 @@ public function gc($maxlifetime) /** * {@inheritdoc} */ - protected function doWrite($sessionId, $data) + protected function doWrite(string $sessionId, string $data) { $expiry = new \MongoDB\BSON\UTCDateTime((time() + (int) ini_get('session.gc_maxlifetime')) * 1000); @@ -154,7 +154,7 @@ public function updateTimestamp($sessionId, $data) /** * {@inheritdoc} */ - protected function doRead($sessionId) + protected function doRead(string $sessionId) { $dbData = $this->getCollection()->findOne([ $this->options['id_field'] => $sessionId, diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NullSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NullSessionHandler.php index 8d193155b090f..603b682378777 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NullSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NullSessionHandler.php @@ -37,7 +37,7 @@ public function validateId($sessionId) /** * {@inheritdoc} */ - protected function doRead($sessionId) + protected function doRead(string $sessionId) { return ''; } @@ -53,7 +53,7 @@ public function updateTimestamp($sessionId, $data) /** * {@inheritdoc} */ - protected function doWrite($sessionId, $data) + protected function doWrite(string $sessionId, string $data) { return true; } @@ -61,7 +61,7 @@ protected function doWrite($sessionId, $data) /** * {@inheritdoc} */ - protected function doDestroy($sessionId) + protected function doDestroy(string $sessionId) { return true; } diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php index f1648adaa52e4..d8bb069edd8f1 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php @@ -299,7 +299,7 @@ public function gc($maxlifetime) /** * {@inheritdoc} */ - protected function doDestroy($sessionId) + protected function doDestroy(string $sessionId) { // delete the record associated with this id $sql = "DELETE FROM $this->table WHERE $this->idCol = :id"; @@ -320,7 +320,7 @@ protected function doDestroy($sessionId) /** * {@inheritdoc} */ - protected function doWrite($sessionId, $data) + protected function doWrite(string $sessionId, string $data) { $maxlifetime = (int) ini_get('session.gc_maxlifetime'); @@ -596,11 +596,9 @@ private function rollback(): void * We need to make sure we do not return session data that is already considered garbage according * to the session.gc_maxlifetime setting because gc() is called after read() and only sometimes. * - * @param string $sessionId Session ID - * - * @return string The session data + * @return string */ - protected function doRead($sessionId) + protected function doRead(string $sessionId) { if (self::LOCK_ADVISORY === $this->lockMode) { $this->unlockStatements[] = $this->doAdvisoryLock($sessionId); diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php index c2e7d34dcfe09..38727fb536750 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php @@ -62,7 +62,7 @@ public function __construct($redis, array $options = []) /** * {@inheritdoc} */ - protected function doRead($sessionId): string + protected function doRead(string $sessionId): string { return $this->redis->get($this->prefix.$sessionId) ?: ''; } @@ -70,7 +70,7 @@ protected function doRead($sessionId): string /** * {@inheritdoc} */ - protected function doWrite($sessionId, $data): bool + protected function doWrite(string $sessionId, string $data): bool { $result = $this->redis->setEx($this->prefix.$sessionId, (int) ini_get('session.gc_maxlifetime'), $data); @@ -80,7 +80,7 @@ protected function doWrite($sessionId, $data): bool /** * {@inheritdoc} */ - protected function doDestroy($sessionId): bool + protected function doDestroy(string $sessionId): bool { $this->redis->del($this->prefix.$sessionId); diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/StrictSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/StrictSessionHandler.php index 83a1f2c063c05..07559fa234cd0 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/StrictSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/StrictSessionHandler.php @@ -43,7 +43,7 @@ public function open($savePath, $sessionName) /** * {@inheritdoc} */ - protected function doRead($sessionId) + protected function doRead(string $sessionId) { return $this->handler->read($sessionId); } @@ -59,7 +59,7 @@ public function updateTimestamp($sessionId, $data) /** * {@inheritdoc} */ - protected function doWrite($sessionId, $data) + protected function doWrite(string $sessionId, string $data) { return $this->handler->write($sessionId, $data); } @@ -78,7 +78,7 @@ public function destroy($sessionId) /** * {@inheritdoc} */ - protected function doDestroy($sessionId) + protected function doDestroy(string $sessionId) { $this->doDestroy = false; diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/MetadataBag.php b/src/Symfony/Component/HttpFoundation/Session/Storage/MetadataBag.php index 5fe40fc106183..c79ee023c4e50 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/MetadataBag.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/MetadataBag.php @@ -100,7 +100,7 @@ public function getLifetime() * to expire with browser session. Time is in seconds, and is * not a Unix timestamp. */ - public function stampNew($lifetime = null) + public function stampNew(int $lifetime = null) { $this->stampCreated($lifetime); } @@ -151,10 +151,8 @@ public function getName() /** * Sets name. - * - * @param string $name */ - public function setName($name) + public function setName(string $name) { $this->name = $name; } diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php index 37b6f145b87cc..4662bd864c944 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php @@ -94,7 +94,7 @@ public function start() /** * {@inheritdoc} */ - public function regenerate($destroy = false, $lifetime = null) + public function regenerate(bool $destroy = false, int $lifetime = null) { if (!$this->started) { $this->start(); @@ -117,7 +117,7 @@ public function getId() /** * {@inheritdoc} */ - public function setId($id) + public function setId(string $id) { if ($this->started) { throw new \LogicException('Cannot set session ID after the session has started.'); @@ -137,7 +137,7 @@ public function getName() /** * {@inheritdoc} */ - public function setName($name) + public function setName(string $name) { $this->name = $name; } @@ -183,7 +183,7 @@ public function registerBag(SessionBagInterface $bag) /** * {@inheritdoc} */ - public function getBag($name) + public function getBag(string $name) { if (!isset($this->bags[$name])) { throw new \InvalidArgumentException(sprintf('The SessionBagInterface %s is not registered.', $name)); diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/MockFileSessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/MockFileSessionStorage.php index 02fe4dad48dd6..019a63484e2e7 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/MockFileSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/MockFileSessionStorage.php @@ -28,7 +28,6 @@ class MockFileSessionStorage extends MockArraySessionStorage /** * @param string $savePath Path of directory to save session files - * @param string $name Session name */ public function __construct(string $savePath = null, string $name = 'MOCKSESSID', MetadataBag $metaBag = null) { @@ -68,7 +67,7 @@ public function start() /** * {@inheritdoc} */ - public function regenerate($destroy = false, $lifetime = null) + public function regenerate(bool $destroy = false, int $lifetime = null) { if (!$this->started) { $this->start(); diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php index 2a57e6ce8801b..ed4c11d920a3c 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php @@ -175,7 +175,7 @@ public function getId() /** * {@inheritdoc} */ - public function setId($id) + public function setId(string $id) { $this->saveHandler->setId($id); } @@ -191,7 +191,7 @@ public function getName() /** * {@inheritdoc} */ - public function setName($name) + public function setName(string $name) { $this->saveHandler->setName($name); } @@ -199,7 +199,7 @@ public function setName($name) /** * {@inheritdoc} */ - public function regenerate($destroy = false, $lifetime = null) + public function regenerate(bool $destroy = false, int $lifetime = null) { // Cannot regenerate the session ID for non-active sessions. if (\PHP_SESSION_ACTIVE !== session_status()) { @@ -308,7 +308,7 @@ public function registerBag(SessionBagInterface $bag) /** * {@inheritdoc} */ - public function getBag($name) + public function getBag(string $name) { if (!isset($this->bags[$name])) { throw new \InvalidArgumentException(sprintf('The SessionBagInterface %s is not registered.', $name)); diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/AbstractProxy.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/AbstractProxy.php index 09c92483c7575..cc6a5527726a2 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/AbstractProxy.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/AbstractProxy.php @@ -81,11 +81,9 @@ public function getId() /** * Sets the session ID. * - * @param string $id - * * @throws \LogicException */ - public function setId($id) + public function setId(string $id) { if ($this->isActive()) { throw new \LogicException('Cannot change the ID of an active session'); @@ -107,11 +105,9 @@ public function getName() /** * Sets the session name. * - * @param string $name - * * @throws \LogicException */ - public function setName($name) + public function setName(string $name) { if ($this->isActive()) { throw new \LogicException('Cannot change the name of an active session'); diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/SessionStorageInterface.php b/src/Symfony/Component/HttpFoundation/Session/Storage/SessionStorageInterface.php index eeb396a2f131c..eb8e8ff2357e5 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/SessionStorageInterface.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/SessionStorageInterface.php @@ -46,24 +46,20 @@ public function getId(); /** * Sets the session ID. - * - * @param string $id */ - public function setId($id); + public function setId(string $id); /** * Returns the session name. * - * @return mixed The session name + * @return string The session name */ public function getName(); /** * Sets the session name. - * - * @param string $name */ - public function setName($name); + public function setName(string $name); /** * Regenerates id that represents this storage. @@ -94,7 +90,7 @@ public function setName($name); * * @throws \RuntimeException If an error occurs while regenerating this storage */ - public function regenerate($destroy = false, $lifetime = null); + public function regenerate(bool $destroy = false, int $lifetime = null); /** * Force the session to be saved and closed. @@ -117,13 +113,11 @@ public function clear(); /** * Gets a SessionBagInterface by name. * - * @param string $name - * * @return SessionBagInterface * * @throws \InvalidArgumentException If the bag does not exist */ - public function getBag($name); + public function getBag(string $name); /** * Registers a SessionBagInterface for use. diff --git a/src/Symfony/Component/HttpFoundation/StreamedResponse.php b/src/Symfony/Component/HttpFoundation/StreamedResponse.php index 06d7a47ad8bcd..c21591be66957 100644 --- a/src/Symfony/Component/HttpFoundation/StreamedResponse.php +++ b/src/Symfony/Component/HttpFoundation/StreamedResponse.php @@ -30,11 +30,6 @@ class StreamedResponse extends Response protected $streamed; private $headersSent; - /** - * @param callable|null $callback A valid PHP callback or null to set it later - * @param int $status The response status code - * @param array $headers An array of response headers - */ public function __construct(callable $callback = null, int $status = 200, array $headers = []) { parent::__construct(null, $status, $headers); @@ -50,12 +45,10 @@ public function __construct(callable $callback = null, int $status = 200, array * Factory method for chainability. * * @param callable|null $callback A valid PHP callback or null to set it later - * @param int $status The response status code - * @param array $headers An array of response headers * * @return static */ - public static function create($callback = null, $status = 200, $headers = []) + public static function create($callback = null, int $status = 200, array $headers = []) { return new static($callback, $status, $headers); } @@ -121,7 +114,7 @@ public function sendContent() * * @return $this */ - public function setContent($content) + public function setContent(?string $content) { if (null !== $content) { throw new \LogicException('The content cannot be set on a StreamedResponse instance.'); diff --git a/src/Symfony/Component/HttpFoundation/Tests/RedirectResponseTest.php b/src/Symfony/Component/HttpFoundation/Tests/RedirectResponseTest.php index 4e28b9ac97261..54c4fdaa07df6 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RedirectResponseTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RedirectResponseTest.php @@ -62,13 +62,6 @@ public function testSetTargetUrl() $this->assertEquals('baz.beep', $response->getTargetUrl()); } - public function testSetTargetUrlNull() - { - $this->expectException('InvalidArgumentException'); - $response = new RedirectResponse('foo.bar'); - $response->setTargetUrl(null); - } - public function testCreate() { $response = RedirectResponse::create('foo', 301); diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index 4a009903a947f..38454667bf88e 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -426,7 +426,7 @@ public function testGetPreferredFormat() } /** - * @dataProvider getFormatToMimeTypeMapProviderWithAdditionalNullFormat + * @dataProvider getFormatToMimeTypeMapProvider */ public function testGetFormatFromMimeType($format, $mimeTypes) { @@ -444,14 +444,6 @@ public function testGetFormatFromMimeType($format, $mimeTypes) } } - public function getFormatToMimeTypeMapProviderWithAdditionalNullFormat() - { - return array_merge( - [[null, [null, 'unexistent-mime-type']]], - $this->getFormatToMimeTypeMapProvider() - ); - } - public function testGetFormatFromMimeTypeWithParameters() { $request = new Request(); diff --git a/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php b/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php index 03b29653e8831..2feac9b892763 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php @@ -900,16 +900,6 @@ public function testSetContent($content) $this->assertEquals((string) $content, $response->getContent()); } - /** - * @dataProvider invalidContentProvider - */ - public function testSetContentInvalid($content) - { - $this->expectException('UnexpectedValueException'); - $response = new Response(); - $response->setContent($content); - } - public function testSettersAreChainable() { $response = new Response(); @@ -951,15 +941,6 @@ public function validContentProvider() ]; } - public function invalidContentProvider() - { - return [ - 'obj' => [new \stdClass()], - 'array' => [[]], - 'bool' => [true, '1'], - ]; - } - protected function createDateTimeOneHourAgo() { return $this->createDateTimeNow()->sub(new \DateInterval('PT1H')); diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php index 17f46bef5e1a1..c846248adc6d8 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php @@ -199,13 +199,6 @@ public function testSessionOptions() $this->assertSame('200', ini_get('session.cache_expire')); } - public function testSetSaveHandlerException() - { - $this->expectException('InvalidArgumentException'); - $storage = $this->getStorage(); - $storage->setSaveHandler(new \stdClass()); - } - public function testSetSaveHandler() { $this->iniSet('session.save_handler', 'files');