add type-hints

This commit is contained in:
julien57 2019-06-28 23:22:42 +02:00 committed by Nicolas Grekas
parent 9fec71ea34
commit ead419b77b
42 changed files with 207 additions and 450 deletions

View File

@ -44,15 +44,13 @@ class AcceptHeader
/**
* 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 @@ class AcceptHeader
/**
* 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 @@ class AcceptHeader
/**
* 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 @@ class AcceptHeader
/**
* 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());

View File

@ -34,13 +34,11 @@ class AcceptHeaderItem
/**
* 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 @@ class AcceptHeaderItem
/**
* 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 @@ class AcceptHeaderItem
/**
* 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 @@ class AcceptHeaderItem
/**
* 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 @@ class AcceptHeaderItem
/**
* 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 @@ class AcceptHeaderItem
/**
* 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 @@ class AcceptHeaderItem
/**
* 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;

View File

@ -66,7 +66,7 @@ class BinaryFileResponse extends Response
*
* @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 @@ class BinaryFileResponse extends Response
/**
* 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 @@ class BinaryFileResponse extends Response
*
* @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 @@ class BinaryFileResponse extends Response
*
* @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 @@ class BinaryFileResponse extends Response
* 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;

View File

@ -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,

View File

@ -76,14 +76,11 @@ class File extends \SplFileInfo
/**
* 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 @@ class File extends \SplFileInfo
/**
* @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 @@ class File extends \SplFileInfo
/**
* 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, '/');

View File

@ -164,14 +164,11 @@ class UploadedFile extends File
/**
* 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) {

View File

@ -43,7 +43,7 @@ class FileBag extends ParameterBag
/**
* {@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.');

View File

@ -102,14 +102,11 @@ class HeaderBag implements \IteratorAggregate, \Countable
/**
* 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 @@ class HeaderBag implements \IteratorAggregate, \Countable
/**
* 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 @@ class HeaderBag implements \IteratorAggregate, \Countable
/**
* 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 @@ class HeaderBag implements \IteratorAggregate, \Countable
/**
* 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 @@ class HeaderBag implements \IteratorAggregate, \Countable
/**
* 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 @@ class HeaderBag implements \IteratorAggregate, \Countable
/**
* 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 @@ class HeaderBag implements \IteratorAggregate, \Countable
/**
* 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 @@ class HeaderBag implements \IteratorAggregate, \Countable
/**
* 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 @@ class HeaderBag implements \IteratorAggregate, \Countable
/**
* 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, ',=');

View File

@ -30,12 +30,11 @@ class IpUtils
/**
* 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 @@ class IpUtils
* 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 @@ class IpUtils
*
* @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])) {

View File

@ -64,7 +64,7 @@ class JsonResponse extends Response
*
* @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 @@ class JsonResponse extends Response
*
* @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 @@ class JsonResponse extends Response
*
* @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 @@ class JsonResponse extends Response
/**
* 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 @@ class JsonResponse extends Response
/**
* 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));
}

View File

@ -67,12 +67,11 @@ class ParameterBag implements \IteratorAggregate, \Countable
/**
* 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 @@ class ParameterBag implements \IteratorAggregate, \Countable
/**
* 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 @@ class ParameterBag implements \IteratorAggregate, \Countable
/**
* 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 @@ class ParameterBag implements \IteratorAggregate, \Countable
/**
* 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 @@ class ParameterBag implements \IteratorAggregate, \Countable
/**
* 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 @@ class ParameterBag implements \IteratorAggregate, \Countable
/**
* 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 @@ class ParameterBag implements \IteratorAggregate, \Countable
/**
* 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 @@ class ParameterBag implements \IteratorAggregate, \Countable
/**
* 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);

View File

@ -50,13 +50,11 @@ class RedirectResponse extends Response
/**
* 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 @@ class RedirectResponse extends Response
/**
* 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.');
}

View File

@ -310,7 +310,7 @@ class Request
*
* @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 @@ class Request
* 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 @@ class Request
* 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 @@ class Request
*
* 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 @@ class Request
*
* @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 @@ class Request
* - "/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 @@ class Request
/**
* 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 @@ class Request
/**
* 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 @@ class Request
/**
* 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 @@ class Request
/**
* 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 @@ class Request
/**
* 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 @@ class Request
*
* @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 @@ class Request
/**
* 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 @@ class Request
/**
* Sets the default locale.
*
* @param string $locale
*/
public function setDefaultLocale($locale)
public function setDefaultLocale(string $locale)
{
$this->defaultLocale = $locale;
@ -1406,10 +1384,8 @@ class Request
/**
* Sets the locale.
*
* @param string $locale
*/
public function setLocale($locale)
public function setLocale(string $locale)
{
$this->setPhpDefaultLocale($this->locale = $locale);
}
@ -1431,7 +1407,7 @@ class Request
*
* @return bool
*/
public function isMethod($method)
public function isMethod(string $method)
{
return $this->getMethod() === strtoupper($method);
}
@ -1503,7 +1479,7 @@ class Request
*
* @throws \LogicException
*/
public function getContent($asResource = false)
public function getContent(bool $asResource = false)
{
$currentContentIsResource = \is_resource($this->content);

View File

@ -84,10 +84,8 @@ class RequestMatcher implements RequestMatcherInterface
/**
* 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 @@ class RequestMatcher implements RequestMatcherInterface
/**
* 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 @@ class RequestMatcher implements RequestMatcherInterface
*
* @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 @@ class RequestMatcher implements RequestMatcherInterface
/**
* 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;
}

View File

@ -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 @@ class Response
* 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 @@ class Response
/**
* 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;
}

View File

@ -108,7 +108,7 @@ class ResponseHeaderBag extends HeaderBag
/**
* {@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 @@ class ResponseHeaderBag extends HeaderBag
/**
* {@inheritdoc}
*/
public function remove($key)
public function remove(string $key)
{
$uniqueKey = str_replace('_', '-', strtolower($key));
unset($this->headerNames[$uniqueKey]);
@ -164,7 +164,7 @@ class ResponseHeaderBag extends HeaderBag
/**
* {@inheritdoc}
*/
public function hasCacheControlDirective($key)
public function hasCacheControlDirective(string $key)
{
return \array_key_exists($key, $this->computedCacheControl);
}
@ -172,7 +172,7 @@ class ResponseHeaderBag extends HeaderBag
/**
* {@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 @@ class ResponseHeaderBag extends HeaderBag
/**
* 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 @@ class ResponseHeaderBag extends HeaderBag
/**
* 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 @@ class ResponseHeaderBag extends HeaderBag
/**
* 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 @@ class ResponseHeaderBag extends HeaderBag
/**
* @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);
}
/**

View File

@ -37,7 +37,7 @@ class AttributeBag implements AttributeBagInterface, \IteratorAggregate, \Counta
return $this->name;
}
public function setName($name)
public function setName(string $name)
{
$this->name = $name;
}
@ -61,7 +61,7 @@ class AttributeBag implements AttributeBagInterface, \IteratorAggregate, \Counta
/**
* {@inheritdoc}
*/
public function has($name)
public function has(string $name)
{
return \array_key_exists($name, $this->attributes);
}
@ -69,7 +69,7 @@ class AttributeBag implements AttributeBagInterface, \IteratorAggregate, \Counta
/**
* {@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 @@ class AttributeBag implements AttributeBagInterface, \IteratorAggregate, \Counta
/**
* {@inheritdoc}
*/
public function set($name, $value)
public function set(string $name, $value)
{
$this->attributes[$name] = $value;
}
@ -104,7 +104,7 @@ class AttributeBag implements AttributeBagInterface, \IteratorAggregate, \Counta
/**
* {@inheritdoc}
*/
public function remove($name)
public function remove(string $name)
{
$retval = null;
if (\array_key_exists($name, $this->attributes)) {

View File

@ -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 @@ interface AttributeBagInterface extends SessionBagInterface
/**
* 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);
}

View File

@ -34,7 +34,7 @@ class NamespacedAttributeBag extends AttributeBag
/**
* {@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 @@ class NamespacedAttributeBag extends AttributeBag
/**
* {@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 @@ class NamespacedAttributeBag extends AttributeBag
/**
* {@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 @@ class NamespacedAttributeBag extends AttributeBag
/**
* {@inheritdoc}
*/
public function remove($name)
public function remove(string $name)
{
$retval = null;
$attributes = &$this->resolveAttributePath($name);
@ -99,7 +99,7 @@ class NamespacedAttributeBag extends AttributeBag
*
* @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 @@ class NamespacedAttributeBag extends AttributeBag
*
* 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);

View File

@ -38,7 +38,7 @@ class AutoExpireFlashBag implements FlashBagInterface
return $this->name;
}
public function setName($name)
public function setName(string $name)
{
$this->name = $name;
}
@ -60,7 +60,7 @@ class AutoExpireFlashBag implements FlashBagInterface
/**
* {@inheritdoc}
*/
public function add($type, $message)
public function add(string $type, $message)
{
$this->flashes['new'][$type][] = $message;
}
@ -68,7 +68,7 @@ class AutoExpireFlashBag implements FlashBagInterface
/**
* {@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 @@ class AutoExpireFlashBag implements FlashBagInterface
/**
* {@inheritdoc}
*/
public function get($type, array $default = [])
public function get(string $type, array $default = [])
{
$return = $default;
@ -122,7 +122,7 @@ class AutoExpireFlashBag implements FlashBagInterface
/**
* {@inheritdoc}
*/
public function set($type, $messages)
public function set(string $type, $messages)
{
$this->flashes['new'][$type] = (array) $messages;
}
@ -130,7 +130,7 @@ class AutoExpireFlashBag implements FlashBagInterface
/**
* {@inheritdoc}
*/
public function has($type)
public function has(string $type)
{
return \array_key_exists($type, $this->flashes['display']) && $this->flashes['display'][$type];
}

View File

@ -38,7 +38,7 @@ class FlashBag implements FlashBagInterface
return $this->name;
}
public function setName($name)
public function setName(string $name)
{
$this->name = $name;
}
@ -54,7 +54,7 @@ class FlashBag implements FlashBagInterface
/**
* {@inheritdoc}
*/
public function add($type, $message)
public function add(string $type, $message)
{
$this->flashes[$type][] = $message;
}
@ -62,7 +62,7 @@ class FlashBag implements FlashBagInterface
/**
* {@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 @@ class FlashBag implements FlashBagInterface
/**
* {@inheritdoc}
*/
public function get($type, array $default = [])
public function get(string $type, array $default = [])
{
if (!$this->has($type)) {
return $default;
@ -105,7 +105,7 @@ class FlashBag implements FlashBagInterface
/**
* {@inheritdoc}
*/
public function set($type, $messages)
public function set(string $type, $messages)
{
$this->flashes[$type] = (array) $messages;
}
@ -121,7 +121,7 @@ class FlashBag implements FlashBagInterface
/**
* {@inheritdoc}
*/
public function has($type)
public function has(string $type)
{
return \array_key_exists($type, $this->flashes) && $this->flashes[$type];
}

View File

@ -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 @@ interface FlashBagInterface extends SessionBagInterface
*
* @return array
*/
public function peek($type, array $default = []);
public function peek(string $type, array $default = []);
/**
* Gets all flash messages.
@ -56,12 +54,11 @@ interface FlashBagInterface extends SessionBagInterface
/**
* 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 @@ interface FlashBagInterface extends SessionBagInterface
/**
* 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.

View File

@ -55,7 +55,7 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
/**
* {@inheritdoc}
*/
public function has($name)
public function has(string $name)
{
return $this->getAttributeBag()->has($name);
}
@ -63,7 +63,7 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
/**
* {@inheritdoc}
*/
public function get($name, $default = null)
public function get(string $name, $default = null)
{
return $this->getAttributeBag()->get($name, $default);
}
@ -71,7 +71,7 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
/**
* {@inheritdoc}
*/
public function set($name, $value)
public function set(string $name, $value)
{
$this->getAttributeBag()->set($name, $value);
}
@ -95,7 +95,7 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
/**
* {@inheritdoc}
*/
public function remove($name)
public function remove(string $name)
{
return $this->getAttributeBag()->remove($name);
}
@ -168,7 +168,7 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
/**
* {@inheritdoc}
*/
public function invalidate($lifetime = null)
public function invalidate(int $lifetime = null)
{
$this->storage->clear();
@ -178,7 +178,7 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
/**
* {@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 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
/**
* {@inheritdoc}
*/
public function setId($id)
public function setId(string $id)
{
if ($this->storage->getId() !== $id) {
$this->storage->setId($id);
@ -220,7 +220,7 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
/**
* {@inheritdoc}
*/
public function setName($name)
public function setName(string $name)
{
$this->storage->setName($name);
}
@ -246,7 +246,7 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
/**
* {@inheritdoc}
*/
public function getBag($name)
public function getBag(string $name)
{
$bag = $this->storage->getBag($name);

View File

@ -38,10 +38,8 @@ interface SessionInterface
/**
* Sets the session ID.
*
* @param string $id
*/
public function setId($id);
public function setId(string $id);
/**
* Returns the session name.
@ -52,10 +50,8 @@ interface SessionInterface
/**
* Sets the session name.
*
* @param string $name
*/
public function setName($name);
public function setName(string $name);
/**
* Invalidates the current session.
@ -70,7 +66,7 @@ interface SessionInterface
*
* @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 @@ interface SessionInterface
*
* @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 @@ interface SessionInterface
/**
* 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 @@ interface SessionInterface
/**
* 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 @@ interface SessionInterface
/**
* Gets a bag instance by name.
*
* @param string $name
*
* @return SessionBagInterface
*/
public function getBag($name);
public function getBag(string $name);
/**
* Gets session meta.

View File

@ -42,26 +42,19 @@ abstract class AbstractSessionHandler implements \SessionHandlerInterface, \Sess
}
/**
* @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}

View File

@ -65,7 +65,7 @@ class MemcachedSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doRead($sessionId)
protected function doRead(string $sessionId)
{
return $this->memcached->get($this->prefix.$sessionId) ?: '';
}
@ -83,7 +83,7 @@ class MemcachedSessionHandler extends AbstractSessionHandler
/**
* {@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 @@ class MemcachedSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doDestroy($sessionId)
protected function doDestroy(string $sessionId)
{
$result = $this->memcached->delete($this->prefix.$sessionId);

View File

@ -90,7 +90,7 @@ class MongoDbSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doDestroy($sessionId)
protected function doDestroy(string $sessionId)
{
$this->getCollection()->deleteOne([
$this->options['id_field'] => $sessionId,
@ -114,7 +114,7 @@ class MongoDbSessionHandler extends AbstractSessionHandler
/**
* {@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 @@ class MongoDbSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doRead($sessionId)
protected function doRead(string $sessionId)
{
$dbData = $this->getCollection()->findOne([
$this->options['id_field'] => $sessionId,

View File

@ -37,7 +37,7 @@ class NullSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doRead($sessionId)
protected function doRead(string $sessionId)
{
return '';
}
@ -53,7 +53,7 @@ class NullSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doWrite($sessionId, $data)
protected function doWrite(string $sessionId, string $data)
{
return true;
}
@ -61,7 +61,7 @@ class NullSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doDestroy($sessionId)
protected function doDestroy(string $sessionId)
{
return true;
}

View File

@ -299,7 +299,7 @@ class PdoSessionHandler extends AbstractSessionHandler
/**
* {@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 @@ class PdoSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doWrite($sessionId, $data)
protected function doWrite(string $sessionId, string $data)
{
$maxlifetime = (int) ini_get('session.gc_maxlifetime');
@ -596,11 +596,9 @@ class PdoSessionHandler extends AbstractSessionHandler
* 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);

View File

@ -62,7 +62,7 @@ class RedisSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doRead($sessionId): string
protected function doRead(string $sessionId): string
{
return $this->redis->get($this->prefix.$sessionId) ?: '';
}
@ -70,7 +70,7 @@ class RedisSessionHandler extends AbstractSessionHandler
/**
* {@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 @@ class RedisSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doDestroy($sessionId): bool
protected function doDestroy(string $sessionId): bool
{
$this->redis->del($this->prefix.$sessionId);

View File

@ -43,7 +43,7 @@ class StrictSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doRead($sessionId)
protected function doRead(string $sessionId)
{
return $this->handler->read($sessionId);
}
@ -59,7 +59,7 @@ class StrictSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doWrite($sessionId, $data)
protected function doWrite(string $sessionId, string $data)
{
return $this->handler->write($sessionId, $data);
}
@ -78,7 +78,7 @@ class StrictSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doDestroy($sessionId)
protected function doDestroy(string $sessionId)
{
$this->doDestroy = false;

View File

@ -100,7 +100,7 @@ class MetadataBag implements SessionBagInterface
* 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 @@ class MetadataBag implements SessionBagInterface
/**
* Sets name.
*
* @param string $name
*/
public function setName($name)
public function setName(string $name)
{
$this->name = $name;
}

View File

@ -94,7 +94,7 @@ class MockArraySessionStorage implements SessionStorageInterface
/**
* {@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 @@ class MockArraySessionStorage implements SessionStorageInterface
/**
* {@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 @@ class MockArraySessionStorage implements SessionStorageInterface
/**
* {@inheritdoc}
*/
public function setName($name)
public function setName(string $name)
{
$this->name = $name;
}
@ -183,7 +183,7 @@ class MockArraySessionStorage implements SessionStorageInterface
/**
* {@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));

View File

@ -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 @@ class MockFileSessionStorage extends MockArraySessionStorage
/**
* {@inheritdoc}
*/
public function regenerate($destroy = false, $lifetime = null)
public function regenerate(bool $destroy = false, int $lifetime = null)
{
if (!$this->started) {
$this->start();

View File

@ -175,7 +175,7 @@ class NativeSessionStorage implements SessionStorageInterface
/**
* {@inheritdoc}
*/
public function setId($id)
public function setId(string $id)
{
$this->saveHandler->setId($id);
}
@ -191,7 +191,7 @@ class NativeSessionStorage implements SessionStorageInterface
/**
* {@inheritdoc}
*/
public function setName($name)
public function setName(string $name)
{
$this->saveHandler->setName($name);
}
@ -199,7 +199,7 @@ class NativeSessionStorage implements SessionStorageInterface
/**
* {@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 @@ class NativeSessionStorage implements SessionStorageInterface
/**
* {@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));

View File

@ -81,11 +81,9 @@ abstract class AbstractProxy
/**
* 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 @@ abstract class AbstractProxy
/**
* 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');

View File

@ -46,24 +46,20 @@ interface SessionStorageInterface
/**
* 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 @@ interface SessionStorageInterface
*
* @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 @@ interface SessionStorageInterface
/**
* 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.

View File

@ -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 @@ class StreamedResponse extends Response
* 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 @@ class StreamedResponse extends Response
*
* @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.');

View File

@ -62,13 +62,6 @@ class RedirectResponseTest extends TestCase
$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);

View File

@ -426,7 +426,7 @@ class RequestTest extends TestCase
}
/**
* @dataProvider getFormatToMimeTypeMapProviderWithAdditionalNullFormat
* @dataProvider getFormatToMimeTypeMapProvider
*/
public function testGetFormatFromMimeType($format, $mimeTypes)
{
@ -444,14 +444,6 @@ class RequestTest extends TestCase
}
}
public function getFormatToMimeTypeMapProviderWithAdditionalNullFormat()
{
return array_merge(
[[null, [null, 'unexistent-mime-type']]],
$this->getFormatToMimeTypeMapProvider()
);
}
public function testGetFormatFromMimeTypeWithParameters()
{
$request = new Request();

View File

@ -900,16 +900,6 @@ class ResponseTest extends ResponseTestCase
$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 @@ class ResponseTest extends ResponseTestCase
];
}
public function invalidContentProvider()
{
return [
'obj' => [new \stdClass()],
'array' => [[]],
'bool' => [true, '1'],
];
}
protected function createDateTimeOneHourAgo()
{
return $this->createDateTimeNow()->sub(new \DateInterval('PT1H'));

View File

@ -199,13 +199,6 @@ class NativeSessionStorageTest extends TestCase
$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');