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

AbstractCollection   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 73
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A clear() 0 6 1
A psi() 0 4 1
A getData() 0 4 1
A count() 0 4 1
A filter() 0 8 1
A isEmpty() 0 4 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