diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index d273bd3d8c..2f8ecd26f0 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -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 diff --git a/framework/web/HeaderCollection.php b/framework/web/HeaderCollection.php index 57ddd6dfe2..7c5e8efae8 100644 --- a/framework/web/HeaderCollection.php +++ b/framework/web/HeaderCollection.php @@ -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 */ private $_headers = []; /** * @var array the original names of the headers (indexed by the normalized header names) + * + * @phpstan-var array */ 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) {