MultiCollection   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 35
c 0
b 0
f 0
rs 10
wmc 7
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isConsistentDataStructure() 0 4 1
B contains() 0 16 5
A prepareData() 0 4 1
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
    public function contains($value, $index = null)
28
    {
29
        if (parent::contains($value, $index)) {
30
            return true;
31
        }
32
        foreach ($this->data as $key => $arr) {
33
            if (is_traversable($arr)) {
34
                $coll = static::factory($arr);
35
                if ($coll->contains($value, $index)) {
36
                    return true;
37
                }
38
            }
39
        }
40
        
41
        return false;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    protected function prepareData($data)
48
    {
49
        return $data;
50
    }
51
52
    protected function isConsistentDataStructure($data)
53
    {
54
        return static::isMultiDimensional($data);
55
    }
56
}
57