Collection   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 74
ccs 24
cts 24
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 3 1
A next() 0 3 1
A current() 0 5 1
A key() 0 5 1
A rewind() 0 5 2
A valid() 0 6 2
A count() 0 5 1
1
<?php
2
3
namespace Zortje\MySQLKeeper\Common;
4
5
/**
6
 * Class Collection
7
 *
8
 * @package Zortje\MySQLKeeper\Common
9
 */
10
class Collection implements \Iterator, \Countable {
11
12
	protected $collection = [];
13
14
	/**
15
	 * Add item to collection
16
	 *
17
	 * @param mixed $item
18
	 */
19 4
	public function add($item) {
20 4
		$this->collection[] = $item;
21 4
	}
22
23
	/**
24
	 * Return the current item
25
	 *
26
	 * @return false|mixed Item
27
	 */
28 1
	public function current() {
29 1
		$item = current($this->collection);
30
31 1
		return $item;
32
	}
33
34
	/**
35
	 * Return the key of the current item
36
	 *
37
	 * @return mixed scalar on success, or null on failure.
38
	 */
39 1
	public function key() {
40 1
		$key = key($this->collection);
41
42 1
		return $key;
43
	}
44
45
	/**
46
	 * Move forward to next item
47
	 */
48 3
	public function next() {
49 3
		next($this->collection);
50 3
	}
51
52
	/**
53
	 * Rewind the collection to the first item
54
	 */
55 2
	public function rewind() {
56 2
		if (is_array($this->collection) === true) {
57 2
			reset($this->collection);
58 2
		}
59 2
	}
60
61
	/**
62
	 * Checks if current position is valid
63
	 *
64
	 * @return bool Returns true on success or false on failure.
65
	 */
66 1
	public function valid() {
67 1
		$key   = key($this->collection);
68 1
		$valid = ($key !== null && $key !== false);
69
70 1
		return $valid;
71
	}
72
73
	/**
74
	 * Count elements of items in collection
75
	 *
76
	 * @return int Count
77
	 */
78 1
	public function count() {
79 1
		$count = count($this->collection);
80
81 1
		return $count;
82
	}
83
}
84