File tree Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change 4
4
5
5
/**
6
6
* Check wether or not a variable is iterable (i.e array or \Traversable)
7
- * @param array|\Traversable $iterable
7
+ *
8
+ * @param array|\Traversable $iterable
8
9
* @return bool
9
10
*/
10
11
function is_iterable ($ iterable )
@@ -17,7 +18,8 @@ function is_iterable($iterable)
17
18
18
19
/**
19
20
* Copy the iterable into an array. If the iterable is already an array, return it.
20
- * @param array|\Traversable $iterable
21
+ *
22
+ * @param array|\Traversable $iterable
21
23
* @return array
22
24
*/
23
25
function iterable_to_array ($ iterable )
@@ -27,16 +29,21 @@ function iterable_to_array($iterable)
27
29
}
28
30
29
31
if (!function_exists ('iterable_to_traversable ' )) {
32
+
33
+ /**
34
+ * If the iterable is not intance of \Traversable, it is an array => convert it to an ArrayIterator.
35
+ *
36
+ * @param $iterable
37
+ * @return \Traversable
38
+ */
30
39
function iterable_to_traversable ($ iterable )
31
40
{
32
41
if ($ iterable instanceof Traversable) {
33
42
return $ iterable ;
34
- }
35
- elseif (is_array ($ iterable )) {
43
+ } elseif (is_array ($ iterable )) {
36
44
return new ArrayIterator ($ iterable );
37
- }
38
- else {
45
+ } else {
39
46
throw new \InvalidArgumentException (sprintf ('Expected array or \\Traversable, got %s ' , is_object ($ iterable ) ? get_class ($ iterable ) : gettype ($ iterable )));
40
47
}
41
48
}
42
- }
49
+ }
You can’t perform that action at this time.
0 commit comments