Fix #20645: Add missing generics in yii\helpers and yii\test namespaces. Fix PHPDoc annotations in ArrayAccessTrait

This commit is contained in:
Maksim Spirkov
2025-10-28 14:58:58 +03:00
committed by GitHub
parent 503828ef3a
commit ed9af8a551
5 changed files with 29 additions and 4 deletions

View File

@@ -71,6 +71,7 @@ Yii Framework 2 Change Log
- Bug #20636: Fix `@param` annotations for `$message` in logging methods (mspirkov) - 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 #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 #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) - Bug #20640: Fix `@param` annotation for `$block` in `yii\console\Markdown::renderParagraph()` (mspirkov)

View File

@@ -17,6 +17,9 @@ namespace yii\base;
* *
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0 * @since 2.0
*
* @phpstan-property array<array-key, mixed> $data
* @psalm-property array<array-key, mixed> $data
*/ */
trait ArrayAccessTrait trait ArrayAccessTrait
{ {
@@ -45,7 +48,7 @@ trait ArrayAccessTrait
/** /**
* This method is required by the interface [[\ArrayAccess]]. * 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 * @return bool
*/ */
#[\ReturnTypeWillChange] #[\ReturnTypeWillChange]
@@ -56,7 +59,7 @@ trait ArrayAccessTrait
/** /**
* This method is required by the interface [[\ArrayAccess]]. * 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 * @return mixed the element at the offset, null if no element is found at the offset
*/ */
#[\ReturnTypeWillChange] #[\ReturnTypeWillChange]
@@ -67,7 +70,7 @@ trait ArrayAccessTrait
/** /**
* This method is required by the interface [[\ArrayAccess]]. * 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 * @param mixed $item the element value
*/ */
#[\ReturnTypeWillChange] #[\ReturnTypeWillChange]
@@ -78,7 +81,7 @@ trait ArrayAccessTrait
/** /**
* This method is required by the interface [[\ArrayAccess]]. * 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] #[\ReturnTypeWillChange]
public function offsetUnset($offset) public function offsetUnset($offset)

View File

@@ -628,6 +628,9 @@ class BaseArrayHelper
* @param array|ArrayAccess $array the array with keys to check * @param array|ArrayAccess $array the array with keys to check
* @param bool $caseSensitive whether the key comparison should be case-sensitive * @param bool $caseSensitive whether the key comparison should be case-sensitive
* @return bool whether the array contains the specified key * @return bool whether the array contains the specified key
*
* @phpstan-param array<array-key, mixed>|ArrayAccess<array-key, mixed> $array
* @psalm-param array<array-key, mixed>|ArrayAccess<array-key, mixed> $array
*/ */
public static function keyExists($key, $array, $caseSensitive = true) public static function keyExists($key, $array, $caseSensitive = true)
{ {

View File

@@ -17,6 +17,9 @@ use yii\base\InvalidConfigException;
* *
* @author Mark Jebri <mark.github@yandex.ru> * @author Mark Jebri <mark.github@yandex.ru>
* @since 2.0 * @since 2.0
*
* @implements \IteratorAggregate<string, array<string, mixed>>
* @implements \ArrayAccess<string, array<string, mixed>|null>
*/ */
class ArrayFixture extends Fixture implements \IteratorAggregate, \ArrayAccess, \Countable 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). * @var array the data rows. Each array element represents one row of data (column name => column value).
*
* @phpstan-var array<string, array<string, mixed>>
* @psalm-var array<string, array<string, mixed>>
*/ */
public $data = []; public $data = [];
@@ -48,6 +54,9 @@ class ArrayFixture extends Fixture implements \IteratorAggregate, \ArrayAccess,
* *
* @return array the data to be put into the database * @return array the data to be put into the database
* @throws InvalidConfigException if the specified data file does not exist. * @throws InvalidConfigException if the specified data file does not exist.
*
* @phpstan-return array<string, array<string, mixed>>
* @psalm-return array<string, array<string, mixed>>
*/ */
protected function getData() protected function getData()
{ {

View File

@@ -17,6 +17,9 @@ use yii\base\InvalidConfigException;
* *
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0 * @since 2.0
*
* @implements \IteratorAggregate<string, array<string, mixed>>
* @implements \ArrayAccess<string, array<string, mixed>|null>
*/ */
abstract class BaseActiveFixture extends DbFixture implements \IteratorAggregate, \ArrayAccess, \Countable abstract class BaseActiveFixture extends DbFixture implements \IteratorAggregate, \ArrayAccess, \Countable
{ {
@@ -29,6 +32,9 @@ abstract class BaseActiveFixture extends DbFixture implements \IteratorAggregate
public $modelClass; public $modelClass;
/** /**
* @var array the data rows. Each array element represents one row of data (column name => column value). * @var array the data rows. Each array element represents one row of data (column name => column value).
*
* @phpstan-var array<string, array<string, mixed>>
* @psalm-var array<string, array<string, mixed>>
*/ */
public $data = []; public $data = [];
@@ -85,6 +91,9 @@ abstract class BaseActiveFixture extends DbFixture implements \IteratorAggregate
* @return array the data to be put into the database * @return array the data to be put into the database
* @throws InvalidConfigException if the specified data file does not exist. * @throws InvalidConfigException if the specified data file does not exist.
* @see loadData() * @see loadData()
*
* @phpstan-return array<string, array<string, mixed>>
* @psalm-return array<string, array<string, mixed>>
*/ */
protected function getData() protected function getData()
{ {