Fix #20579: Add PHPStan/Psalm annotations for HeaderCollection::get

This commit is contained in:
Maksim Spirkov
2025-10-07 09:08:48 +04:00
committed by GitHub
parent 4b23c4b5bd
commit 049d52d699
2 changed files with 11 additions and 0 deletions

View File

@ -45,6 +45,7 @@ Yii Framework 2 Change Log
- Bug #20571: Fix `@var` annotation for `yii\web\Response::$stream` (max-s-lab)
- Bug #20569: Fix `@param` annotation for `$default` in `HeaderCollection::get` (max-s-lab)
- Bug #20576: Fix `@var` annotation for `StringValidator::$length` (max-s-lab)
- Enh #20579: Add PHPStan/Psalm annotations for `HeaderCollection::get` (max-s-lab)
2.0.53 June 27, 2025

View File

@ -22,10 +22,14 @@ class HeaderCollection extends BaseObject implements \IteratorAggregate, \ArrayA
{
/**
* @var array the headers in this collection (indexed by the normalized header names)
*
* @phpstan-var array<string, string[]>
*/
private $_headers = [];
/**
* @var array the original names of the headers (indexed by the normalized header names)
*
* @phpstan-var array<string, string>
*/
private $_originalHeaderNames = [];
@ -72,6 +76,12 @@ class HeaderCollection extends BaseObject implements \IteratorAggregate, \ArrayA
* If false, all headers of the specified name will be returned.
* @return string|array|null the named header(s). If `$first` is true, a string will be returned;
* If `$first` is false, an array will be returned.
*
* @phpstan-param ($first is true ? string|null : string[]|null) $default
* @psalm-param ($first is true ? string|null : string[]|null) $default
*
* @phpstan-return ($first is true ? string|null : string[]|null)
* @psalm-return ($first is true ? string|null : string[]|null)
*/
public function get($name, $default = null, $first = true)
{