AbstractCollection   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 52
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A count() 0 4 1
A getIterator() 0 4 1
A contains() 0 9 3
1
<?php
2
3
namespace Ducatel\PHPCollection\Base;
4
5
abstract class AbstractCollection implements \IteratorAggregate, \Countable
6
{
7
    /**
8
     * @var The array where data are stored internally
9
     */
10
    protected $data = [];
11
12
    /**
13
     * Check if an object is present in the collection.
14
     * The check will be done by `===`
15
     * @param $objectToFind The object you want to check if it's already present.
16
     * @return bool True if present else false
17
     */
18 3
    public function contains($objectToFind) : bool
19
    {
20 3
        foreach ($this as $elem) {
21 3
            if ($elem === $objectToFind) {
22 3
                return true;
23
            }
24
        }
25 3
        return false;
26
    }
27
28
    /**
29
     * Count elements of an object
30
     *
31
     * @link  http://php.net/manual/en/countable.count.php
32
     * @return int The custom count as an integer.
33
     *        </p>
34
     *        <p>
35
     *        The return value is cast to an integer.
36
     * @since 5.1.0
37
     */
38 4
    public function count()
39
    {
40 4
        return count($this->data);
41
    }
42
43
44
    /**
45
     * Retrieve an external iterator
46
     *
47
     * @link  http://php.net/manual/en/iteratoraggregate.getiterator.php
48
     * @return \Traversable An instance of an object implementing <b>Iterator</b> or
49
     *        <b>Traversable</b>
50
     * @since 5.0.0
51
     */
52 13
    public function getIterator()
53
    {
54 13
        return new \ArrayIterator($this->data);
55
    }
56
}
57