Completed
Push — master ( 74a788...5880f8 )
by Karsten
03:03
created

AbstractCollection::count()   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
 * Created by gerk on 13.11.16 10:59
4
 */
5
6
namespace PeekAndPoke\Component\Collections;
7
8
use PeekAndPoke\Component\Psi\BinaryFunction;
9
use PeekAndPoke\Component\Psi\Psi;
10
use PeekAndPoke\Component\Psi\UnaryFunction;
11
12
/**
13
 * @author Karsten J. Gerber <[email protected]>
14
 */
15
abstract class AbstractCollection implements Collection
16
{
17
    /** @var array */
18
    protected $data;
19
20
    /**
21
     * @param array $data
22
     */
23 111
    public function __construct(array $data = [])
24
    {
25 111
        $this->data = $data;
26 111
    }
27
28
    /**
29
     * @return $this
30
     */
31 1
    public function clear()
32
    {
33 1
        $this->data = [];
34
35 1
        return $this;
36
    }
37
38
    /**
39
     * @return Psi
40
     */
41 1
    public function psi()
42
    {
43 1
        return Psi::it($this);
44
    }
45
46
    /**
47
     * @return array
48
     */
49 72
    public function getData()
50
    {
51 72
        return $this->data;
52
    }
53
54
    /**
55
     * @return int
56
     */
57 15
    public function count()
58
    {
59 15
        return \count($this->data);
60
    }
61
62
    /**
63
     * @return bool
64
     */
65 3
    public function isEmpty()
66
    {
67 3
        return $this->count() === 0;
68
    }
69
70
    /**
71
     * @deprecated Use psi() instead as it will be removed in v1.1.0
72
     *
73
     * @see        psi()
74
     *
75
     * @param callable|UnaryFunction|BinaryFunction $predicate
76
     *
77
     * @return static
78
     */
79 1
    public function filter($predicate)
80
    {
81 1
        return new static(
82 1
            Psi::it($this->getIterator())
83 1
                ->filter($predicate)
84 1
                ->toArray()
85
        );
86
    }
87
}
88