Completed
Push — master ( e7db84...257943 )
by Jeroen De
09:16 queued 07:17
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 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 11
ccs 5
cts 5
cp 1
crap 3
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 16
	if ( $iterable instanceof Iterator ) {
20 5
		return $iterable;
21
	}
22
23 11
	if ( is_array( $iterable ) ) {
24 7
		return new ArrayIterator( $iterable );
25
	}
26
27
	return new \WMDE\TraversableIterator\TraversableIterator( $iterable );
28
}