Completed
Push — master ( 09a151...fdd724 )
by Zoltán
02:38
created

AbstractCollection   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 0 Features 0
Metric Value
wmc 13
c 6
b 0
f 0
lcom 1
cbo 1
dl 0
loc 101
ccs 16
cts 16
cp 1
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A current() 0 3 1
A next() 0 3 1
A key() 0 3 1
A valid() 0 3 1
A rewind() 0 3 1
A count() 0 3 1
A collectionToArray() 0 7 2
A toArray() 0 3 1
A clear() 0 3 1
A isEmpty() 0 3 1
A size() 0 3 2
1
<?php namespace BuildR\Collection\Collection;
2
3
use BuildR\Collection\Exception\CollectionException;
4
5
/**
6
 * Abstract collection implementation
7
 *
8
 * BuildR PHP Framework
9
 *
10
 * @author Zoltán Borsos <[email protected]>
11
 * @package Collection
12
 * @subpackage Collection
13
 *
14
 * @copyright    Copyright 2015, Zoltán Borsos.
15
 * @license      https://github.com/Zolli/BuildR/blob/master/LICENSE.md
16
 * @link         https://github.com/Zolli/BuildR
17
 */
18
abstract class AbstractCollection implements CollectionInterface {
19
20
    /**
21
     * @type array
22
     */
23
    protected $data = [];
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 39
    public function toArray() {
29 39
        return (array) $this->data;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 2
    public function clear() {
36 2
        $this->data = [];
37 2
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 1
    public function isEmpty() {
43 1
        return empty($this->data);
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 59
    public function size() {
50 59
        return (is_array($this->data)) ? count($this->data) : 0;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     *
56
     * @codeCoverageIgnore
57
     */
58
    public function current() {
59
        return current($this->data);
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     *
65
     * @codeCoverageIgnore
66
     */
67
    public function next() {
68
        return next($this->data);
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     *
74
     * @codeCoverageIgnore
75
     */
76
    public function key() {
77
        return key($this->data);
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     *
83
     * @codeCoverageIgnore
84
     */
85
    public function valid() {
86
        return key($this->data) !== NULL;
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     *
92
     * @codeCoverageIgnore
93
     */
94
    public function rewind() {
95
        return reset($this->data);
96
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101 40
    public function count() {
102 40
        return $this->size();
103
    }
104
105
    /**
106
     * @param array|\BuildR\Collection\Collection\CollectionInterface $elements
107
     *
108
     * @return array
109
     */
110 36
    protected function collectionToArray($elements) {
111 36
        if($elements instanceof CollectionInterface) {
112 1
            $elements = $elements->toArray();
113 1
        }
114
115 36
        return $elements;
116
    }
117
118
}
119