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 44
55 /**
66 * Check wether or not a variable is iterable (i.e array or \Traversable)
7- * @param array|\Traversable $iterable
7+ *
8+ * @param array|\Traversable $iterable
89 * @return bool
910 */
1011 function is_iterable ($ iterable )
@@ -17,7 +18,8 @@ function is_iterable($iterable)
1718
1819 /**
1920 * 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
2123 * @return array
2224 */
2325 function iterable_to_array ($ iterable )
@@ -27,16 +29,21 @@ function iterable_to_array($iterable)
2729}
2830
2931if (!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+ */
3039 function iterable_to_traversable ($ iterable )
3140 {
3241 if ($ iterable instanceof Traversable) {
3342 return $ iterable ;
34- }
35- elseif (is_array ($ iterable )) {
43+ } elseif (is_array ($ iterable )) {
3644 return new ArrayIterator ($ iterable );
37- }
38- else {
45+ } else {
3946 throw new \InvalidArgumentException (sprintf ('Expected array or \\Traversable, got %s ' , is_object ($ iterable ) ? get_class ($ iterable ) : gettype ($ iterable )));
4047 }
4148 }
42- }
49+ }
You can’t perform that action at this time.
0 commit comments