Completed
Push — master ( 5fca22...233410 )
by Emily
01:43
created

AbstractCollection::empty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 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 Collection
23
{
24
    /**
25
     * Returns how many elements are in the Collection
26
     *
27
     * @return int The number of elements in the Collection
28
     */
29 9
    public function count()
30
    {
31 9
        return $this->size();
32
    }
33
34
    /**
35
     * {@inheritDoc}
36
     */
37 7
    public function empty() : bool
38
    {
39 7
        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
    public function toArray() : array
73
    {
74
        return iterator_to_array($this);
75
    }
76
}
77