Completed
Push — master ( 461219...630231 )
by Harry
04:03
created

TraversableTrait::getArray()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.2
cc 4
eloc 4
nc 3
nop 1
crap 4
1
<?php
2
3
namespace Graze\DataFile\Format\Formatter;
4
5
use InvalidArgumentException;
6
use Traversable;
7
8
trait TraversableTrait
9
{
10
    /**
11
     * @param array|Traversable $row
12
     *
13
     * @return array
14
     */
15 21
    protected function getArray($row)
16
    {
17 21
        if (!$row instanceof Traversable && !is_array($row)) {
18 2
            throw new InvalidArgumentException("The input is not an array or traversable");
19
        }
20 19
        return ($row instanceof Traversable) ? iterator_to_array($row, true) : $row;
21
    }
22
}
23