Completed
Push — master ( 7c9b2f...038cbf )
by Luke
32s
created

Collection::prepareData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 4
c 0
b 0
f 0
cc 1
eloc 2
nop 1
rs 10
1
<?php
2
3
/*
4
 * Nozavroni/Collections
5
 * Just another collections library for PHP5.6+.
6
 *
7
 * @copyright Copyright (c) 2016 Luke Visinoni <[email protected]>
8
 * @author    Luke Visinoni <[email protected]>
9
 * @license   https://github.com/nozavroni/collections/blob/master/LICENSE The MIT License (MIT)
10
 */
11
namespace Noz\Collection;
12
13
use function Noz\is_traversable;
14
15
/**
16
 * Class Collection
17
 *
18
 * A basic collection class, allowing only scalar/non-traversable items.
19
 *
20
 * @package Noz\Collection
21
 */
22
class Collection extends AbstractCollection
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    protected function prepareData($data)
28
    {
29
        return $data;
30
    }
31
32
    /**
33
     * Is correct input data type?
34
     *
35
     * @param mixed $data The data to assert correct type of
36
     *
37
     * @return bool
38
     */
39
    protected function isConsistentDataStructure($data)
40
    {
41
        // this collection may only contain scalar or null values
42
        if (!is_traversable($data)) {
43
            return false;
44
        }
45
        foreach ($data as $key => $val) {
46
            if (is_traversable($val)) {
47
                return false;
48
            }
49
        }
50
51
        return true;
52
    }
53
}
54