Skip to content

Commit ed9af8a

Browse files
authored
Fix yiisoft#20645: Add missing generics in yii\helpers and yii\test namespaces. Fix PHPDoc annotations in ArrayAccessTrait
1 parent 503828e commit ed9af8a

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

framework/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Yii Framework 2 Change Log
7171
- Bug #20636: Fix `@param` annotations for `$message` in logging methods (mspirkov)
7272
- Bug #20637: Fix PHPDoc annotations in `ActiveRelationTrait`. Add PHPStan/Psalm annotations for `$modelClass` in `ActiveQuery`, `ActiveQueryTrait` and `ActiveRelationTrait` (mspirkov)
7373
- Bug #20639: Add missing generics in `yii\web` namespace (mspirkov)
74+
- Bug #20645: Add missing generics in `yii\helpers` and `yii\test` namespaces. Fix PHPDoc annotations in `ArrayAccessTrait` (mspirkov)
7475
- Bug #20640: Fix `@param` annotation for `$block` in `yii\console\Markdown::renderParagraph()` (mspirkov)
7576

7677

framework/base/ArrayAccessTrait.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
*
1818
* @author Qiang Xue <qiang.xue@gmail.com>
1919
* @since 2.0
20+
*
21+
* @phpstan-property array<array-key, mixed> $data
22+
* @psalm-property array<array-key, mixed> $data
2023
*/
2124
trait ArrayAccessTrait
2225
{
@@ -45,7 +48,7 @@ public function count()
4548

4649
/**
4750
* This method is required by the interface [[\ArrayAccess]].
48-
* @param mixed $offset the offset to check on
51+
* @param int|string $offset the offset to check on
4952
* @return bool
5053
*/
5154
#[\ReturnTypeWillChange]
@@ -56,7 +59,7 @@ public function offsetExists($offset)
5659

5760
/**
5861
* This method is required by the interface [[\ArrayAccess]].
59-
* @param int $offset the offset to retrieve element.
62+
* @param int|string $offset the offset to retrieve element.
6063
* @return mixed the element at the offset, null if no element is found at the offset
6164
*/
6265
#[\ReturnTypeWillChange]
@@ -67,7 +70,7 @@ public function offsetGet($offset)
6770

6871
/**
6972
* This method is required by the interface [[\ArrayAccess]].
70-
* @param int $offset the offset to set element
73+
* @param int|string $offset the offset to set element
7174
* @param mixed $item the element value
7275
*/
7376
#[\ReturnTypeWillChange]
@@ -78,7 +81,7 @@ public function offsetSet($offset, $item)
7881

7982
/**
8083
* This method is required by the interface [[\ArrayAccess]].
81-
* @param mixed $offset the offset to unset element
84+
* @param int|string $offset the offset to unset element
8285
*/
8386
#[\ReturnTypeWillChange]
8487
public function offsetUnset($offset)

framework/helpers/BaseArrayHelper.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,9 @@ public static function map($array, $from, $to, $group = null)
628628
* @param array|ArrayAccess $array the array with keys to check
629629
* @param bool $caseSensitive whether the key comparison should be case-sensitive
630630
* @return bool whether the array contains the specified key
631+
*
632+
* @phpstan-param array<array-key, mixed>|ArrayAccess<array-key, mixed> $array
633+
* @psalm-param array<array-key, mixed>|ArrayAccess<array-key, mixed> $array
631634
*/
632635
public static function keyExists($key, $array, $caseSensitive = true)
633636
{

framework/test/ArrayFixture.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
*
1818
* @author Mark Jebri <mark.github@yandex.ru>
1919
* @since 2.0
20+
*
21+
* @implements \IteratorAggregate<string, array<string, mixed>>
22+
* @implements \ArrayAccess<string, array<string, mixed>|null>
2023
*/
2124
class ArrayFixture extends Fixture implements \IteratorAggregate, \ArrayAccess, \Countable
2225
{
@@ -25,6 +28,9 @@ class ArrayFixture extends Fixture implements \IteratorAggregate, \ArrayAccess,
2528

2629
/**
2730
* @var array the data rows. Each array element represents one row of data (column name => column value).
31+
*
32+
* @phpstan-var array<string, array<string, mixed>>
33+
* @psalm-var array<string, array<string, mixed>>
2834
*/
2935
public $data = [];
3036

@@ -48,6 +54,9 @@ public function load()
4854
*
4955
* @return array the data to be put into the database
5056
* @throws InvalidConfigException if the specified data file does not exist.
57+
*
58+
* @phpstan-return array<string, array<string, mixed>>
59+
* @psalm-return array<string, array<string, mixed>>
5160
*/
5261
protected function getData()
5362
{

framework/test/BaseActiveFixture.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
*
1818
* @author Qiang Xue <qiang.xue@gmail.com>
1919
* @since 2.0
20+
*
21+
* @implements \IteratorAggregate<string, array<string, mixed>>
22+
* @implements \ArrayAccess<string, array<string, mixed>|null>
2023
*/
2124
abstract class BaseActiveFixture extends DbFixture implements \IteratorAggregate, \ArrayAccess, \Countable
2225
{
@@ -29,6 +32,9 @@ abstract class BaseActiveFixture extends DbFixture implements \IteratorAggregate
2932
public $modelClass;
3033
/**
3134
* @var array the data rows. Each array element represents one row of data (column name => column value).
35+
*
36+
* @phpstan-var array<string, array<string, mixed>>
37+
* @psalm-var array<string, array<string, mixed>>
3238
*/
3339
public $data = [];
3440

@@ -85,6 +91,9 @@ public function load()
8591
* @return array the data to be put into the database
8692
* @throws InvalidConfigException if the specified data file does not exist.
8793
* @see loadData()
94+
*
95+
* @phpstan-return array<string, array<string, mixed>>
96+
* @psalm-return array<string, array<string, mixed>>
8897
*/
8998
protected function getData()
9099
{

0 commit comments

Comments
 (0)