From b3d57a1c325f39f703b249bed7998ce8c64236b4 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 21 Aug 2019 18:20:57 +0200 Subject: [PATCH] [HttpFoundation] fix return type declarations --- BinaryFileResponse.php | 4 ++-- FileBag.php | 8 +++----- HeaderBag.php | 2 +- Request.php | 6 +++++- Response.php | 2 +- Session/Attribute/NamespacedAttributeBag.php | 2 +- Session/Storage/Handler/MemcachedSessionHandler.php | 9 +++------ Session/Storage/Handler/NullSessionHandler.php | 2 +- Session/Storage/Handler/PdoSessionHandler.php | 2 +- Session/Storage/Handler/StrictSessionHandler.php | 2 +- Session/Storage/Proxy/AbstractProxy.php | 2 +- Session/Storage/Proxy/SessionHandlerProxy.php | 2 +- StreamedResponse.php | 2 -- Tests/BinaryFileResponseTest.php | 2 +- Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php | 3 ++- 15 files changed, 24 insertions(+), 26 deletions(-) diff --git a/BinaryFileResponse.php b/BinaryFileResponse.php index 6c9a995e9..f43114111 100644 --- a/BinaryFileResponse.php +++ b/BinaryFileResponse.php @@ -327,12 +327,12 @@ public function setContent($content) if (null !== $content) { throw new \LogicException('The content cannot be set on a BinaryFileResponse instance.'); } + + return $this; } /** * {@inheritdoc} - * - * @return false */ public function getContent() { diff --git a/FileBag.php b/FileBag.php index ca849b3d7..024fadf20 100644 --- a/FileBag.php +++ b/FileBag.php @@ -75,8 +75,8 @@ protected function convertFileInformation($file) return $file; } - $file = $this->fixPhpFilesArray($file); if (\is_array($file)) { + $file = $this->fixPhpFilesArray($file); $keys = array_keys($file); sort($keys); @@ -109,14 +109,12 @@ protected function convertFileInformation($file) * It's safe to pass an already converted array, in which case this method * just returns the original array unmodified. * + * @param array $data + * * @return array */ protected function fixPhpFilesArray($data) { - if (!\is_array($data)) { - return $data; - } - $keys = array_keys($data); sort($keys); diff --git a/HeaderBag.php b/HeaderBag.php index 9798173e6..08299977c 100644 --- a/HeaderBag.php +++ b/HeaderBag.php @@ -121,7 +121,7 @@ public function get($key, $default = null, $first = true) } if ($first) { - return \count($headers[$key]) ? $headers[$key][0] : $default; + return \count($headers[$key]) ? (string) $headers[$key][0] : $default; } return $headers[$key]; diff --git a/Request.php b/Request.php index 3b9bf2f49..3fc7b71e6 100644 --- a/Request.php +++ b/Request.php @@ -528,6 +528,10 @@ public function __toString() try { $content = $this->getContent(); } catch (\LogicException $e) { + if (\PHP_VERSION_ID >= 70400) { + throw $e; + } + return trigger_error($e, E_USER_ERROR); } @@ -912,7 +916,7 @@ public function getClientIps() * ("Client-Ip" for instance), configure it via the $trustedHeaderSet * argument of the Request::setTrustedProxies() method instead. * - * @return string The client IP address + * @return string|null The client IP address * * @see getClientIps() * @see https://wikipedia.org/wiki/X-Forwarded-For diff --git a/Response.php b/Response.php index eae9b7841..8a17acdd5 100644 --- a/Response.php +++ b/Response.php @@ -407,7 +407,7 @@ public function setContent($content) /** * Gets the current response content. * - * @return string Content + * @return string|false */ public function getContent() { diff --git a/Session/Attribute/NamespacedAttributeBag.php b/Session/Attribute/NamespacedAttributeBag.php index bbf2e39c8..07885e7fb 100644 --- a/Session/Attribute/NamespacedAttributeBag.php +++ b/Session/Attribute/NamespacedAttributeBag.php @@ -97,7 +97,7 @@ public function remove($name) * @param string $name Key name * @param bool $writeContext Write context, default false * - * @return array + * @return array|null */ protected function &resolveAttributePath($name, $writeContext = false) { diff --git a/Session/Storage/Handler/MemcachedSessionHandler.php b/Session/Storage/Handler/MemcachedSessionHandler.php index 8965c089c..a399be5fd 100644 --- a/Session/Storage/Handler/MemcachedSessionHandler.php +++ b/Session/Storage/Handler/MemcachedSessionHandler.php @@ -40,9 +40,6 @@ class MemcachedSessionHandler extends AbstractSessionHandler * * prefix: The prefix to use for the memcached keys in order to avoid collision * * expiretime: The time to live in seconds. * - * @param \Memcached $memcached A \Memcached instance - * @param array $options An associative array of Memcached options - * * @throws \InvalidArgumentException When unsupported options are passed */ public function __construct(\Memcached $memcached, array $options = []) @@ -58,7 +55,7 @@ public function __construct(\Memcached $memcached, array $options = []) } /** - * {@inheritdoc} + * @return bool */ public function close() { @@ -74,7 +71,7 @@ protected function doRead($sessionId) } /** - * {@inheritdoc} + * @return bool */ public function updateTimestamp($sessionId, $data) { @@ -102,7 +99,7 @@ protected function doDestroy($sessionId) } /** - * {@inheritdoc} + * @return bool */ public function gc($maxlifetime) { diff --git a/Session/Storage/Handler/NullSessionHandler.php b/Session/Storage/Handler/NullSessionHandler.php index 8d193155b..3ba9378ca 100644 --- a/Session/Storage/Handler/NullSessionHandler.php +++ b/Session/Storage/Handler/NullSessionHandler.php @@ -67,7 +67,7 @@ protected function doDestroy($sessionId) } /** - * {@inheritdoc} + * @return bool */ public function gc($maxlifetime) { diff --git a/Session/Storage/Handler/PdoSessionHandler.php b/Session/Storage/Handler/PdoSessionHandler.php index 9a50377bc..f9e5d1e8f 100644 --- a/Session/Storage/Handler/PdoSessionHandler.php +++ b/Session/Storage/Handler/PdoSessionHandler.php @@ -286,7 +286,7 @@ public function read($sessionId) } /** - * {@inheritdoc} + * @return bool */ public function gc($maxlifetime) { diff --git a/Session/Storage/Handler/StrictSessionHandler.php b/Session/Storage/Handler/StrictSessionHandler.php index 83a1f2c06..fab8e9a16 100644 --- a/Session/Storage/Handler/StrictSessionHandler.php +++ b/Session/Storage/Handler/StrictSessionHandler.php @@ -94,7 +94,7 @@ public function close() } /** - * {@inheritdoc} + * @return bool */ public function gc($maxlifetime) { diff --git a/Session/Storage/Proxy/AbstractProxy.php b/Session/Storage/Proxy/AbstractProxy.php index 09c92483c..0303729e7 100644 --- a/Session/Storage/Proxy/AbstractProxy.php +++ b/Session/Storage/Proxy/AbstractProxy.php @@ -31,7 +31,7 @@ abstract class AbstractProxy /** * Gets the session.save_handler name. * - * @return string + * @return string|null */ public function getSaveHandlerName() { diff --git a/Session/Storage/Proxy/SessionHandlerProxy.php b/Session/Storage/Proxy/SessionHandlerProxy.php index b11cc397a..e40712d93 100644 --- a/Session/Storage/Proxy/SessionHandlerProxy.php +++ b/Session/Storage/Proxy/SessionHandlerProxy.php @@ -76,7 +76,7 @@ public function destroy($sessionId) } /** - * {@inheritdoc} + * @return bool */ public function gc($maxlifetime) { diff --git a/StreamedResponse.php b/StreamedResponse.php index 8bc5fc91a..b9148ea87 100644 --- a/StreamedResponse.php +++ b/StreamedResponse.php @@ -136,8 +136,6 @@ public function setContent($content) /** * {@inheritdoc} - * - * @return false */ public function getContent() { diff --git a/Tests/BinaryFileResponseTest.php b/Tests/BinaryFileResponseTest.php index 3df96f393..fcad11def 100644 --- a/Tests/BinaryFileResponseTest.php +++ b/Tests/BinaryFileResponseTest.php @@ -107,7 +107,7 @@ public function testRequests($requestRange, $offset, $length, $responseRange) $this->assertEquals(206, $response->getStatusCode()); $this->assertEquals($responseRange, $response->headers->get('Content-Range')); - $this->assertSame($length, $response->headers->get('Content-Length')); + $this->assertSame((string) $length, $response->headers->get('Content-Length')); } /** diff --git a/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php b/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php index ec9029c7d..1457ebd70 100644 --- a/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php +++ b/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php @@ -144,7 +144,8 @@ public function testUpdateTimestamp() { $mock = $this->getMockBuilder(['SessionHandlerInterface', 'SessionUpdateTimestampHandlerInterface'])->getMock(); $mock->expects($this->once()) - ->method('updateTimestamp'); + ->method('updateTimestamp') + ->willReturn(false); $proxy = new SessionHandlerProxy($mock); $proxy->updateTimestamp('id', 'data');