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

MultiCollection::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 MultiCollection
17
 *
18
 * A collection that allows traversable item as well as scalar items.
19
 *
20
 * @package Noz\Collection
21
 */
22
class MultiCollection extends AbstractCollection
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    protected function prepareData($data)
28
    {
29
        return $data;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function contains($value, $index = null)
36
    {
37
        if (parent::contains($value, $index)) {
38
            return true;
39
        }
40
        foreach ($this->data as $key => $arr) {
41
            if (is_traversable($arr)) {
42
                $coll = static::factory($arr);
43
                if ($coll->contains($value, $index)) {
44
                    return true;
45
                }
46
            }
47
        }
48
        
49
        return false;
50
    }
51
52
    protected function isConsistentDataStructure($data)
53
    {
54
        return static::isMultiDimensional($data);
55
    }
56
}
57