File tree 2 files changed +8
-2
lines changed
2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -62,13 +62,13 @@ public static function fromValue($value, $noneValue = null)
62
62
* @template S
63
63
*
64
64
* @param array<string|int,S>|ArrayAccess<string|int,S>|null $array A potential array or \ArrayAccess value.
65
- * @param string $key The key to check.
65
+ * @param string|int|null $key The key to check.
66
66
*
67
67
* @return Option<S>
68
68
*/
69
69
public static function fromArraysValue ($ array , $ key )
70
70
{
71
- if (!(is_array ($ array ) || $ array instanceof ArrayAccess) || !isset ($ array [$ key ])) {
71
+ if ($ key === null || !(is_array ($ array ) || $ array instanceof ArrayAccess) || !isset ($ array [$ key ])) {
72
72
return None::create ();
73
73
}
74
74
Original file line number Diff line number Diff line change @@ -31,11 +31,17 @@ public function testFromArraysValue(): void
31
31
self ::assertEquals (None::create (), Option::fromArraysValue (null , 'bar ' ));
32
32
self ::assertEquals (None::create (), Option::fromArraysValue (['foo ' => 'bar ' ], 'baz ' ));
33
33
self ::assertEquals (None::create (), Option::fromArraysValue (['foo ' => null ], 'foo ' ));
34
+ self ::assertEquals (None::create (), Option::fromArraysValue (['foo ' => 'bar ' ], null ));
34
35
self ::assertEquals (new Some ('foo ' ), Option::fromArraysValue (['foo ' => 'foo ' ], 'foo ' ));
36
+ self ::assertEquals (new Some ('foo ' ), Option::fromArraysValue ([13 => 'foo ' ], 13 ));
35
37
36
38
$ object = new SomeArrayObject ();
37
39
$ object ['foo ' ] = 'foo ' ;
38
40
self ::assertEquals (new Some ('foo ' ), Option::fromArraysValue ($ object , 'foo ' ));
41
+
42
+ $ object = new SomeArrayObject ();
43
+ $ object [13 ] = 'foo ' ;
44
+ self ::assertEquals (new Some ('foo ' ), Option::fromArraysValue ($ object , 13 ));
39
45
}
40
46
41
47
public function testFromReturn (): void
You can’t perform that action at this time.
0 commit comments