Passed
Pull Request — master (#19)
by
unknown
03:59
created

ToArrayTrait::toArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
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