2626
2727class AccessHelper
2828{
29- /**
30- * @param array|ArrayAccess $collection
31- */
32- public static function collectionKeys ($ collection ): array
29+ public static function collectionKeys (mixed $ collection ): array
3330 {
3431 if (is_object ($ collection )) {
3532 return array_keys (get_object_vars ($ collection ));
@@ -38,18 +35,12 @@ public static function collectionKeys($collection): array
3835 return array_keys ($ collection );
3936 }
4037
41- /**
42- * @param array|ArrayAccess $collection
43- */
44- public static function isCollectionType ($ collection ): bool
38+ public static function isCollectionType (mixed $ collection ): bool
4539 {
4640 return is_array ($ collection ) || is_object ($ collection );
4741 }
4842
49- /**
50- * @param array|ArrayAccess $collection
51- */
52- public static function keyExists ($ collection , $ key , bool $ magicIsAllowed = false ): bool
43+ public static function keyExists (mixed $ collection , $ key , bool $ magicIsAllowed = false ): bool
5344 {
5445 if ($ magicIsAllowed && is_object ($ collection ) && method_exists ($ collection , '__get ' )) {
5546 return true ;
@@ -76,14 +67,9 @@ public static function keyExists($collection, $key, bool $magicIsAllowed = false
7667
7768 /**
7869 * @todo Optimize conditions
79- *
80- * @param array|ArrayAccess $collection
81- * @noinspection NotOptimalIfConditionsInspection
8270 */
83- public static function getValue ($ collection , $ key , bool $ magicIsAllowed = false )
71+ public static function getValue (mixed $ collection , $ key , bool $ magicIsAllowed = false )
8472 {
85- $ return = null ;
86-
8773 if (
8874 $ magicIsAllowed &&
8975 is_object ($ collection ) &&
@@ -112,12 +98,8 @@ public static function getValue($collection, $key, bool $magicIsAllowed = false)
11298 /**
11399 * Find item in php collection by index
114100 * Written this way to handle instances ArrayAccess or Traversable objects
115- *
116- * @param array|ArrayAccess $collection
117- *
118- * @return mixed|null
119101 */
120- private static function getValueByIndex ($ collection , $ key )
102+ private static function getValueByIndex (mixed $ collection , $ key ): mixed
121103 {
122104 $ i = 0 ;
123105
@@ -145,26 +127,21 @@ private static function getValueByIndex($collection, $key)
145127 return null ;
146128 }
147129
148- /**
149- * @param array|ArrayAccess $collection
150- */
151- public static function setValue (&$ collection , $ key , $ value )
130+ public static function setValue (mixed &$ collection , $ key , $ value )
152131 {
153132 if (is_object ($ collection ) && !$ collection instanceof ArrayAccess) {
154133 return $ collection ->$ key = $ value ;
155134 }
156135
157136 if ($ collection instanceof ArrayAccess) {
137+ /** @noinspection PhpVoidFunctionResultUsedInspection */
158138 return $ collection ->offsetSet ($ key , $ value );
159139 }
160140
161141 return $ collection [$ key ] = $ value ;
162142 }
163143
164- /**
165- * @param array|ArrayAccess $collection
166- */
167- public static function unsetValue (&$ collection , $ key ): void
144+ public static function unsetValue (mixed &$ collection , $ key ): void
168145 {
169146 if (is_object ($ collection ) && !$ collection instanceof ArrayAccess) {
170147 unset($ collection ->$ key );
@@ -180,11 +157,9 @@ public static function unsetValue(&$collection, $key): void
180157 }
181158
182159 /**
183- * @param array|ArrayAccess $collection
184- *
185160 * @throws JSONPathException
186161 */
187- public static function arrayValues ($ collection ): array
162+ public static function arrayValues (array | ArrayAccess $ collection ): array
188163 {
189164 if (is_array ($ collection )) {
190165 return array_values ($ collection );
0 commit comments