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

MultiCollection   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isConsistentDataStructure() 0 4 1
B contains() 0 16 5
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
namespace CSVelte\Collection;
15
16
use function CSVelte\is_traversable;
17
18
class MultiCollection extends AbstractCollection
19
{
20
    protected function isConsistentDataStructure($data)
21
    {
22
        return static::isMultiDimensional($data);
23
    }
24
25
    /**
26
     * @inheritdoc
27
     */
28
    public function contains($value, $index = null)
29
    {
30
        if (parent::contains($value, $index)) {
31
            return true;
32
        } else {
33
            foreach ($this->data as $key => $arr) {
34
                if (is_traversable($arr)) {
35
                    $coll = static::factory($arr);
36
                    if ($coll->contains($value, $index)) {
37
                        return true;
38
                    }
39
                }
40
            }
41
        }
42
        return false;
43
    }
44
}