@@ -15,7 +15,7 @@ class OuterList implements \IteratorAggregate, \ArrayAccess
1515 *
1616 * @var array<TupleInterface|array{mixed, object}>
1717 */
18- public $ value ;
18+ public array $ value ;
1919
2020 /**
2121 * @param array<TupleInterface|array{mixed, object}> $value
@@ -35,26 +35,25 @@ public function __construct(array $value = [])
3535 */
3636 public static function fromArray (array $ array ): OuterList
3737 {
38- $ list = new self ();
39- foreach ($ array as $ value ) {
40- if (!$ value instanceof TupleInterface) {
41- if (is_array ($ value )) {
42- $ value = InnerList::fromArray ($ value );
38+ array_walk ($ array , function (&$ item ) {
39+ if (!$ item instanceof TupleInterface) {
40+ if (is_array ($ item )) {
41+ $ item = InnerList::fromArray ($ item );
4342 } else {
44- $ value = new Item ($ value );
43+ $ item = new Item ($ item );
4544 }
4645 }
47- $ list [] = $ value ;
48- }
46+ });
4947
50- return $ list ;
48+ /** @var TupleInterface[] $array */
49+ return new self ($ array );
5150 }
5251
5352 /**
5453 * @param TupleInterface|array{mixed, object} $value
5554 * @return void
5655 */
57- private static function validateItemType ($ value ): void
56+ private static function validateItemType (mixed $ value ): void
5857 {
5958 if (is_object ($ value )) {
6059 if (!($ value instanceof TupleInterface)) {
@@ -63,7 +62,7 @@ private static function validateItemType($value): void
6362 );
6463 }
6564 } elseif (is_array ($ value )) {
66- if (count ($ value ) != 2 ) { // @phpstan-ignore-line
65+ if (count ($ value ) != 2 ) {
6766 throw new \InvalidArgumentException ();
6867 }
6968 } else {
@@ -87,10 +86,10 @@ public function offsetExists($offset): bool
8786
8887 /**
8988 * @param int $offset
90- * @return TupleInterface|array{mixed, object}|null
89+ * @return mixed
90+ * @phpstan-return TupleInterface|array{mixed, object}|null
9191 */
92- #[\ReturnTypeWillChange]
93- public function offsetGet ($ offset )
92+ public function offsetGet ($ offset ): mixed
9493 {
9594 return $ this ->value [$ offset ] ?? null ;
9695 }
0 commit comments