Completed
Push — master ( 12dc59...e7db84 )
by Jeroen De
09:10
created

functions.php ➔ iterable_to_iterator()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 11
ccs 0
cts 0
cp 0
crap 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare( strict_types = 1 );
4
5
/**
6
 * @license GNU GPL v2+
7
 * @author Jeroen De Dauw < [email protected] >
8
 */
9
10
function iterable_to_array( iterable $iterable ): array {
11 13
	if ( is_array( $iterable ) ) {
12 7
		return $iterable;
13
	}
14
15 6
	return iterator_to_array( $iterable );
16
}
17
18
function iterable_to_iterator( iterable $iterable ): Iterator {
19
	if ( $iterable instanceof Iterator ) {
20
		return $iterable;
21
	}
22
23
	if ( is_array( $iterable ) ) {
24
		return new ArrayIterator( $iterable );
25
	}
26
27
	return new \WMDE\TraversableIterator\TraversableIterator( $iterable );
28
}