Completed
Pull Request — master (#175)
by Luke
06:22 queued 01:51
created

MultiCollection::contains()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 9
nc 5
nop 2
dl 0
loc 16
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * CSVelte: Slender, elegant CSV for PHP
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   {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
namespace CSVelte\Collection;
15
16
use function CSVelte\is_traversable;
17
18
class MultiCollection extends AbstractCollection
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function contains($value, $index = null)
24
    {
25
        if (parent::contains($value, $index)) {
26
            return true;
27
        }
28
        foreach ($this->data as $key => $arr) {
29
            if (is_traversable($arr)) {
30
                $coll = static::factory($arr);
31
                if ($coll->contains($value, $index)) {
32
                    return true;
33
                }
34
            }
35
        }
36
        
37
        return false;
38
    }
39
40
    protected function isConsistentDataStructure($data)
41
    {
42
        return static::isMultiDimensional($data);
43
    }
44
}
45