7
7
use Illuminate \Contracts \Support \Jsonable ;
8
8
use JsonSerializable ;
9
9
10
+ /**
11
+ * @template TKey of array-key
12
+ * @template TValue
13
+ *
14
+ * @implements \Illuminate\Contracts\Support\Arrayable<TKey, TValue>
15
+ * @implements \ArrayAccess<TKey, TValue>
16
+ */
10
17
class Fluent implements Arrayable, ArrayAccess, Jsonable, JsonSerializable
11
18
{
12
19
/**
13
20
* All of the attributes set on the fluent instance.
14
21
*
15
- * @var array
22
+ * @var array<TKey, TValue>
16
23
*/
17
24
protected $ attributes = [];
18
25
19
26
/**
20
27
* Create a new fluent instance.
21
28
*
22
- * @param array|object $attributes
29
+ * @param iterable<TKey, TValue> $attributes
23
30
* @return void
24
31
*/
25
32
public function __construct ($ attributes = [])
@@ -32,9 +39,11 @@ public function __construct($attributes = [])
32
39
/**
33
40
* Get an attribute from the fluent instance.
34
41
*
35
- * @param string $key
36
- * @param mixed $default
37
- * @return mixed
42
+ * @template TGetDefault
43
+ *
44
+ * @param TKey $key
45
+ * @param TGetDefault|(\Closure(): TGetDefault) $default
46
+ * @return TValue|TGetDefault
38
47
*/
39
48
public function get ($ key , $ default = null )
40
49
{
@@ -48,7 +57,7 @@ public function get($key, $default = null)
48
57
/**
49
58
* Get the attributes from the fluent instance.
50
59
*
51
- * @return array
60
+ * @return array<TKey, TValue>
52
61
*/
53
62
public function getAttributes ()
54
63
{
@@ -58,7 +67,7 @@ public function getAttributes()
58
67
/**
59
68
* Convert the fluent instance to an array.
60
69
*
61
- * @return array
70
+ * @return array<TKey, TValue>
62
71
*/
63
72
public function toArray ()
64
73
{
@@ -68,7 +77,7 @@ public function toArray()
68
77
/**
69
78
* Convert the object into something JSON serializable.
70
79
*
71
- * @return array
80
+ * @return array<TKey, TValue>
72
81
*/
73
82
#[\ReturnTypeWillChange]
74
83
public function jsonSerialize ()
@@ -90,7 +99,7 @@ public function toJson($options = 0)
90
99
/**
91
100
* Determine if the given offset exists.
92
101
*
93
- * @param string $offset
102
+ * @param TKey $offset
94
103
* @return bool
95
104
*/
96
105
#[\ReturnTypeWillChange]
@@ -102,8 +111,8 @@ public function offsetExists($offset)
102
111
/**
103
112
* Get the value for a given offset.
104
113
*
105
- * @param string $offset
106
- * @return mixed
114
+ * @param TKey $offset
115
+ * @return TValue|null
107
116
*/
108
117
#[\ReturnTypeWillChange]
109
118
public function offsetGet ($ offset )
@@ -114,8 +123,8 @@ public function offsetGet($offset)
114
123
/**
115
124
* Set the value at the given offset.
116
125
*
117
- * @param string $offset
118
- * @param mixed $value
126
+ * @param TKey $offset
127
+ * @param TValue $value
119
128
* @return void
120
129
*/
121
130
#[\ReturnTypeWillChange]
@@ -127,7 +136,7 @@ public function offsetSet($offset, $value)
127
136
/**
128
137
* Unset the value at the given offset.
129
138
*
130
- * @param string $offset
139
+ * @param TKey $offset
131
140
* @return void
132
141
*/
133
142
#[\ReturnTypeWillChange]
@@ -139,8 +148,8 @@ public function offsetUnset($offset)
139
148
/**
140
149
* Handle dynamic calls to the fluent instance to set attributes.
141
150
*
142
- * @param string $method
143
- * @param array $parameters
151
+ * @param TKey $method
152
+ * @param array{0: ?TValue} $parameters
144
153
* @return $this
145
154
*/
146
155
public function __call ($ method , $ parameters )
@@ -153,8 +162,8 @@ public function __call($method, $parameters)
153
162
/**
154
163
* Dynamically retrieve the value of an attribute.
155
164
*
156
- * @param string $key
157
- * @return mixed
165
+ * @param TKey $key
166
+ * @return TValue|null
158
167
*/
159
168
public function __get ($ key )
160
169
{
@@ -164,8 +173,8 @@ public function __get($key)
164
173
/**
165
174
* Dynamically set the value of an attribute.
166
175
*
167
- * @param string $key
168
- * @param mixed $value
176
+ * @param TKey $key
177
+ * @param TValue $value
169
178
* @return void
170
179
*/
171
180
public function __set ($ key , $ value )
@@ -176,7 +185,7 @@ public function __set($key, $value)
176
185
/**
177
186
* Dynamically check if an attribute is set.
178
187
*
179
- * @param string $key
188
+ * @param TKey $key
180
189
* @return bool
181
190
*/
182
191
public function __isset ($ key )
@@ -187,7 +196,7 @@ public function __isset($key)
187
196
/**
188
197
* Dynamically unset an attribute.
189
198
*
190
- * @param string $key
199
+ * @param TKey $key
191
200
* @return void
192
201
*/
193
202
public function __unset ($ key )
0 commit comments