20
20
final class Optional
21
21
{
22
22
/**
23
- * @var self
23
+ * @var self|null
24
24
*/
25
- private static $ empty ;
25
+ private static ? Optional $ empty ;
26
26
27
27
/**
28
28
* Returns an Optional with the specified present non-null value.
29
29
*
30
30
* @template S
31
+ *
31
32
* @param S $value
32
33
*
33
34
* @return static
34
35
*/
35
- public static function of ($ value ): self
36
+ public static function of (mixed $ value ): self
36
37
{
37
38
return new self (Obj::requireNotNull ($ value ));
38
39
}
@@ -54,38 +55,38 @@ public static function empty(): self
54
55
*
55
56
* @template S
56
57
*
57
- * @param S $value The actual return value.
58
- * @param S $nullValue The value which should be considered "None"; null by default.
58
+ * @param S $value The actual return value.
59
+ * @param S|null $nullValue The value which should be considered "None"; null by default.
59
60
*
60
61
* @return static
61
62
*/
62
- public static function nullable ($ value , $ nullValue = null ): self
63
+ public static function nullable (mixed $ value , mixed $ nullValue = null ): self
63
64
{
64
65
return $ value === $ nullValue ? self ::empty () : self ::of ($ value );
65
66
}
66
67
67
68
/**
68
69
* @template S
69
70
*
70
- * @param S $value
71
- * @param S $nullValue
71
+ * @param S $value
72
+ * @param S|null $nullValue
72
73
*
73
74
* @return static
74
75
*/
75
- public static function ofNullable ($ value , $ nullValue = null ): self
76
+ public static function ofNullable (mixed $ value , mixed $ nullValue = null ): self
76
77
{
77
78
return self ::nullable ($ value , $ nullValue );
78
79
}
79
80
80
81
/**
81
82
* @template S
82
83
*
83
- * @param array| ArrayAccess $array
84
- * @param string| int $key
84
+ * @param ArrayAccess|array $array
85
+ * @param int|string $key
85
86
*
86
87
* @return static
87
88
*/
88
- public static function ofArrayKey ($ array , $ key ): self
89
+ public static function ofArrayKey (ArrayAccess | array $ array , int | string $ key ): self
89
90
{
90
91
if (!(is_array ($ array ) || $ array instanceof ArrayAccess) || !isset ($ array [$ key ])) {
91
92
return self ::empty ();
@@ -102,14 +103,14 @@ public static function ofReturn(callable $fn): self
102
103
/**
103
104
* @var T
104
105
*/
105
- private $ value ;
106
+ private mixed $ value ;
106
107
107
108
/**
108
109
* Class constructor.
109
110
*
110
111
* @param T $value
111
112
*/
112
- private function __construct ($ value )
113
+ private function __construct (mixed $ value )
113
114
{
114
115
$ this ->value = $ value ;
115
116
}
0 commit comments