diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 1a4fee3469..671d6786d3 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -71,6 +71,7 @@ Yii Framework 2 Change Log - Bug #20636: Fix `@param` annotations for `$message` in logging methods (mspirkov) - Bug #20637: Fix PHPDoc annotations in `ActiveRelationTrait`. Add PHPStan/Psalm annotations for `$modelClass` in `ActiveQuery`, `ActiveQueryTrait` and `ActiveRelationTrait` (mspirkov) - Bug #20639: Add missing generics in `yii\web` namespace (mspirkov) +- Bug #20645: Add missing generics in `yii\helpers` and `yii\test` namespaces. Fix PHPDoc annotations in `ArrayAccessTrait` (mspirkov) - Bug #20640: Fix `@param` annotation for `$block` in `yii\console\Markdown::renderParagraph()` (mspirkov) diff --git a/framework/base/ArrayAccessTrait.php b/framework/base/ArrayAccessTrait.php index 177894e554..6d16bf613a 100644 --- a/framework/base/ArrayAccessTrait.php +++ b/framework/base/ArrayAccessTrait.php @@ -17,6 +17,9 @@ namespace yii\base; * * @author Qiang Xue * @since 2.0 + * + * @phpstan-property array $data + * @psalm-property array $data */ trait ArrayAccessTrait { @@ -45,7 +48,7 @@ trait ArrayAccessTrait /** * This method is required by the interface [[\ArrayAccess]]. - * @param mixed $offset the offset to check on + * @param int|string $offset the offset to check on * @return bool */ #[\ReturnTypeWillChange] @@ -56,7 +59,7 @@ trait ArrayAccessTrait /** * This method is required by the interface [[\ArrayAccess]]. - * @param int $offset the offset to retrieve element. + * @param int|string $offset the offset to retrieve element. * @return mixed the element at the offset, null if no element is found at the offset */ #[\ReturnTypeWillChange] @@ -67,7 +70,7 @@ trait ArrayAccessTrait /** * This method is required by the interface [[\ArrayAccess]]. - * @param int $offset the offset to set element + * @param int|string $offset the offset to set element * @param mixed $item the element value */ #[\ReturnTypeWillChange] @@ -78,7 +81,7 @@ trait ArrayAccessTrait /** * This method is required by the interface [[\ArrayAccess]]. - * @param mixed $offset the offset to unset element + * @param int|string $offset the offset to unset element */ #[\ReturnTypeWillChange] public function offsetUnset($offset) diff --git a/framework/helpers/BaseArrayHelper.php b/framework/helpers/BaseArrayHelper.php index 4f56d38f0c..546f60024c 100644 --- a/framework/helpers/BaseArrayHelper.php +++ b/framework/helpers/BaseArrayHelper.php @@ -628,6 +628,9 @@ class BaseArrayHelper * @param array|ArrayAccess $array the array with keys to check * @param bool $caseSensitive whether the key comparison should be case-sensitive * @return bool whether the array contains the specified key + * + * @phpstan-param array|ArrayAccess $array + * @psalm-param array|ArrayAccess $array */ public static function keyExists($key, $array, $caseSensitive = true) { diff --git a/framework/test/ArrayFixture.php b/framework/test/ArrayFixture.php index c146ab34e3..55b48f505d 100644 --- a/framework/test/ArrayFixture.php +++ b/framework/test/ArrayFixture.php @@ -17,6 +17,9 @@ use yii\base\InvalidConfigException; * * @author Mark Jebri * @since 2.0 + * + * @implements \IteratorAggregate> + * @implements \ArrayAccess|null> */ class ArrayFixture extends Fixture implements \IteratorAggregate, \ArrayAccess, \Countable { @@ -25,6 +28,9 @@ class ArrayFixture extends Fixture implements \IteratorAggregate, \ArrayAccess, /** * @var array the data rows. Each array element represents one row of data (column name => column value). + * + * @phpstan-var array> + * @psalm-var array> */ public $data = []; @@ -48,6 +54,9 @@ class ArrayFixture extends Fixture implements \IteratorAggregate, \ArrayAccess, * * @return array the data to be put into the database * @throws InvalidConfigException if the specified data file does not exist. + * + * @phpstan-return array> + * @psalm-return array> */ protected function getData() { diff --git a/framework/test/BaseActiveFixture.php b/framework/test/BaseActiveFixture.php index 0fb45dd483..a5b8d54aec 100644 --- a/framework/test/BaseActiveFixture.php +++ b/framework/test/BaseActiveFixture.php @@ -17,6 +17,9 @@ use yii\base\InvalidConfigException; * * @author Qiang Xue * @since 2.0 + * + * @implements \IteratorAggregate> + * @implements \ArrayAccess|null> */ abstract class BaseActiveFixture extends DbFixture implements \IteratorAggregate, \ArrayAccess, \Countable { @@ -29,6 +32,9 @@ abstract class BaseActiveFixture extends DbFixture implements \IteratorAggregate public $modelClass; /** * @var array the data rows. Each array element represents one row of data (column name => column value). + * + * @phpstan-var array> + * @psalm-var array> */ public $data = []; @@ -85,6 +91,9 @@ abstract class BaseActiveFixture extends DbFixture implements \IteratorAggregate * @return array the data to be put into the database * @throws InvalidConfigException if the specified data file does not exist. * @see loadData() + * + * @phpstan-return array> + * @psalm-return array> */ protected function getData() {