Passed
Push — master ( 337d8e...76e5f0 )
by Gabriel
02:33
created

AbstractCollection::getIterator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Nip\Collections;
4
5
use ArrayAccess;
6
use ArrayIterator;
7
use Countable;
8
use IteratorAggregate;
9
use JsonSerializable;
10
use Nip\Collections\Legacy\Traits\DeprecatedTraits;
11
12
/**
13
 * Class Registry
14
 * @package Nip
15
 */
16
class AbstractCollection implements ArrayAccess, Countable, IteratorAggregate, JsonSerializable
17
{
18
    use Traits\AccessMethodsTrait;
19
    use Traits\ArrayAccessTrait;
20
    use Traits\FilterTrait;
21
    use Traits\OperationsOnItemsTrait;
22
    use Traits\OperationsTrait;
23
    use Traits\SortingTrait;
24
    use Traits\TransformMethodsTrait;
25
    use DeprecatedTraits;
26
27
    /**
28
     * @var array
29
     */
30
    protected $items = [];
31
32
    protected $index = 0;
33
34
    /**
35
     * Collection constructor.
36
     * @param array $items
37
     */
38 37
    public function __construct($items = [])
39
    {
40 37
        if (is_array($items)) {
0 ignored issues
show
introduced by
The condition is_array($items) is always true.
Loading history...
41 37
            $this->items = $items;
42
        } elseif ($items instanceof AbstractCollection) {
43
            $this->items = $items->toArray();
44
        }
45 37
    }
46
47
    /**
48
     * @param $needle
49
     * @return bool
50
     */
51
    public function contains($needle)
52
    {
53
        foreach ($this as $key => $value) {
54
            if ($value === $needle) {
55
                return true;
56
            }
57
        }
58
        return false;
59
    }
60
61
    /**
62
     * @return ArrayIterator
63
     */
64 1
    public function getIterator()
65
    {
66 1
        return new ArrayIterator($this->items);
67
    }
68
}
69