From 2177d280e572937bbbbd3aed78a4032229833f6d Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Wed, 8 Mar 2023 15:19:11 +0100 Subject: [PATCH] Use more precise return type for StreamInterface::getMetadata MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The array keys are always strings. And when `null` is passed as `$key` argument, it should always return an array. But that can be only concisely expressed in PHPStan – Psalm requires a template type for conditional types. So let’s use prefixed annotation. --- src/StreamInterface.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/StreamInterface.php b/src/StreamInterface.php index f68f391..2f4fd67 100644 --- a/src/StreamInterface.php +++ b/src/StreamInterface.php @@ -150,9 +150,10 @@ public function getContents(); * * @link http://php.net/manual/en/function.stream-get-meta-data.php * @param string $key Specific metadata to retrieve. - * @return array|mixed|null Returns an associative array if no key is + * @return array|mixed|null Returns an associative array if no key is * provided. Returns a specific key value if a key is provided and the * value is found, or null if the key is not found. + * @phpstan-return ($key is null ? array : mixed|null) */ public function getMetadata($key = null); }