Completed
Pull Request — master (#170)
by Luke
02:40
created

Collection::isConsistentDataStructure()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 4
nop 1
dl 0
loc 13
rs 9.2
c 0
b 0
f 0
1
<?php
2
/**
3
 * CSVelte: Slender, elegant CSV for PHP
4
 *
5
 * Inspired by Python's CSV module and Frictionless Data and the W3C's CSV
6
 * standardization efforts, CSVelte was written in an effort to take all the
7
 * suck out of working with CSV.
8
 *
9
 * @version   v${CSVELTE_DEV_VERSION}
10
 * @copyright Copyright (c) 2016 Luke Visinoni <[email protected]>
11
 * @author    Luke Visinoni <[email protected]>
12
 * @license   https://github.com/deni-zen/csvelte/blob/master/LICENSE The MIT License (MIT)
13
 */
14
15
namespace CSVelte\Collection;
16
17
use function CSVelte\is_traversable;
18
19
class Collection extends AbstractCollection
20
{
21
    /**
22
     * Is correct input data type?
23
     *
24
     * @param mixed $data The data to assert correct type of
25
     * @return bool
26
     */
27
    protected function isConsistentDataStructure($data)
28
    {
29
        // this collection may only contain scalar or null values
30
        if (!is_traversable($data)) {
31
            return false;
32
        }
33
        foreach ($data as $key => $val) {
34
            if (is_traversable($val)) {
35
                return false;
36
            }
37
        }
38
        return true;
39
    }
40
}