Passed
Push — master ( faf39f...21841e )
by Gerard van
43s
created

ToArrayTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 25
ccs 4
cts 4
cp 1
rs 10
wmc 2
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 8 2
1
<?php
2
/**
3
 * @author Boudewijn Schoon <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
7
namespace Zicht\Itertools\lib\Traits;
8
9
trait ToArrayTrait
10
{
11
    /**
12
     * Returns an unsafe array build from this iterator
13
     *
14
     * Note that the resulting array may contain overlapping keys!
15
     * If this is the case, the resulting array will contain fewer
16
     * items than the original iterator!
17
     *
18
     * A safer option is to use either
19
     * - $iterable->keys(),
20
     * - $iterable->values(), or
21
     * - $iterable->items()
22
     *
23
     * @return array
24
     */
25 39
    public function toArray()
26
    {
27 39
        if ($this instanceof \Traversable) {
28 38
            return iterator_to_array($this);
29
        } else {
30 1
            return [];
31
        }
32
    }
33
}
34