From ece8392e001980173c91423c5d73bafeec0da685 Mon Sep 17 00:00:00 2001 From: Mponos George Date: Sat, 21 Dec 2019 10:36:23 +0200 Subject: [PATCH] Be strict about array_replace that may return null (#2471) * Be strict about array_replace that may return null * revert cs changes --- phpstan-baseline.neon | 5 ----- src/Cookie/SetCookie.php | 7 ++++++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index f4f433d6..ab0463b8 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -165,11 +165,6 @@ parameters: count: 1 path: src/Cookie/SetCookie.php - - - message: "#^Property GuzzleHttp\\\\Cookie\\\\SetCookie\\:\\:\\$data \\(array\\) does not accept array\\|null\\.$#" - count: 1 - path: src/Cookie/SetCookie.php - - message: "#^Parameter \\#1 \\$timestamp of method GuzzleHttp\\\\Cookie\\\\SetCookie\\:\\:setExpires\\(\\) expects int, mixed given\\.$#" count: 1 diff --git a/src/Cookie/SetCookie.php b/src/Cookie/SetCookie.php index d6edda94..f2276dc4 100644 --- a/src/Cookie/SetCookie.php +++ b/src/Cookie/SetCookie.php @@ -69,7 +69,12 @@ class SetCookie */ public function __construct(array $data = []) { - $this->data = \array_replace(self::$defaults, $data); + $replaced = \array_replace(self::$defaults, $data); + if ($replaced === null) { + throw new \InvalidArgumentException('Unable to replace the default values for the Cookie.'); + } + + $this->data = $replaced; // Extract the Expires value and turn it into a UNIX timestamp if needed if (!$this->getExpires() && $this->getMaxAge()) { // Calculate the Expires date