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

AbstractCollection::key()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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