Completed
Push — master ( 499778...79f24a )
by Emily
9s
created

AbstractCollection   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 73.32%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 55
ccs 11
cts 15
cp 0.7332
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A count() 0 4 1
A empty() 0 4 1
A contains() 0 12 3
A map() 0 7 2
A toArray() 0 4 1
1
<?php
2
/**
3
 * This file is part of the Composite Utils package.
4
 *
5
 * (c) Emily Shepherd <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the
8
 * LICENSE.md file that was distributed with this source code.
9
 *
10
 * @package spaark/composite-utils
11
 * @author Emily Shepherd <[email protected]>
12
 * @license MIT
13
 */
14
15
namespace Spaark\CompositeUtils\Model\Collection;
16
17
/**
18
 * Represents an abstract collection of items
19
 *
20
 * @generic ValueType
21
 */
22
abstract class AbstractCollection implements CollectionInterface
23
{
24
    /**
25
     * Returns how many elements are in the Collection
26
     *
27
     * @return int The number of elements in the Collection
28
     */
29 11
    public function count()
30
    {
31 11
        return $this->size();
32
    }
33
34
    /**
35
     * {@inheritDoc}
36
     */
37 15
    public function empty() : bool
38
    {
39 15
        return $this->size() === 0;
40
    }
41
42
    /**
43
     * {@inheritDoc}
44
     */
45 5
    public function contains($searchFor) : bool
46
    {
47 5
        foreach ($this as $item)
48
        {
49 5
            if ($item === $searchFor)
50
            {
51 5
                return true;
52
            }
53
        }
54
55 4
        return false;
56
    }
57
58
    /**
59
     * {@inheritDoc}
60
     */
61
    public function map(callable $cb)
62
    {
63
        foreach ($this as $key => $value)
64
        {
65
            $cb($key, $value);
66
        }
67
    }
68
69
    /**
70
     * {@inheritDoc}
71
     */
72 1
    public function toArray() : array
73
    {
74 1
        return iterator_to_array($this);
75
    }
76
}
77