Browse code

Moved Collection to util namespace

Niklas Modess authored on 24/05/2014 14:13:50
Showing 3 changed files
1 1
deleted file mode 100644
... ...
@@ -1,77 +0,0 @@
1
-<?php
2
-namespace Gitter\Model\Commit;
3
-
4
-class Collection implements \ArrayAccess, \IteratorAggregate, \Countable {
5
-    /**
6
-     * @var array
7
-     */
8
-    protected $commits;
9
-
10
-    /**
11
-     * @return array
12
-     */
13
-    public function getCommits()
14
-    {
15
-        return $this->commits;
16
-    }
17
-
18
-    /**
19
-     * @param array $commits
20
-     */
21
-    public function setCommits($commits)
22
-    {
23
-        $this->commits = $commits;
24
-    }
25
-
26
-    /**
27
-     * {@inheritdoc}
28
-     */
29
-    public function offsetExists($offset)
30
-    {
31
-        return isset($this->commits[$offset]);
32
-    }
33
-
34
-    /**
35
-     * {@inheritdoc}
36
-     */
37
-    public function offsetGet($offset)
38
-    {
39
-        return isset($this->commits[$offset]);
40
-    }
41
-
42
-    /**
43
-     * {@inheritdoc}
44
-     */
45
-    public function offsetSet($offset, $value)
46
-    {
47
-        if (is_null($offset)) {
48
-            $this->commits[] = $value;
49
-        } else {
50
-            $this->commits[$offset] = $value;
51
-        }
52
-    }
53
-
54
-    /**
55
-     * {@inheritdoc}
56
-     */
57
-    public function offsetUnset($offset)
58
-    {
59
-        unset($this->commits[$offset]);
60
-    }
61
-
62
-    /**
63
-     * {@inheritdoc}
64
-     */
65
-    public function getIterator()
66
-    {
67
-        return new \ArrayIterator($this->commits);
68
-    }
69
-
70
-    /**
71
-     * {@inheritdoc}
72
-     */
73
-    public function count()
74
-    {
75
-        return count($this->commits);
76
-    }
77
-}
78 1
\ No newline at end of file
... ...
@@ -1,7 +1,7 @@
1 1
 <?php
2 2
 namespace Gitter\Statistics;
3 3
 
4
-use Gitter\Model\Commit\Collection;
4
+use Gitter\Util\Collection;
5 5
 use Gitter\Model\Commit\Commit;
6 6
 
7 7
 /**
... ...
@@ -14,15 +14,9 @@ class Contributors extends Collection implements StatisticsInterface
14 14
      */
15 15
     public function addCommit(Commit $commit)
16 16
     {
17
-        $email = $commit->getAuthor()->getEmail();
18
-        $name  = $commit->getAuthor()->getName();
17
+        $email      = $commit->getAuthor()->getEmail();
18
+        $commitDate = $commit->getCommiterDate()->format('Y-m-d');
19 19
 
20
-        $commitDate  = $commit->getCommiterDate()->format('Y-m-d');
21
-
22
-        if (!isset($this->commits[$email]['name'])) {
23
-            $this->commits[$email]['name'] = $name;
24
-        }
25
-
26
-        $this->commits[$email]['commits'][$commitDate][] = $commit;
20
+        $this->items[$email][$commitDate][] = $commit;
27 21
     }
28 22
 }
29 23
\ No newline at end of file
30 24
new file mode 100644
... ...
@@ -0,0 +1,77 @@
0
+<?php
1
+namespace Gitter\Util;
2
+
3
+class Collection implements \ArrayAccess, \IteratorAggregate, \Countable {
4
+    /**
5
+     * @var array
6
+     */
7
+    protected $items = array();
8
+
9
+    /**
10
+     * @return array
11
+     */
12
+    public function getItems()
13
+    {
14
+        return $this->items;
15
+    }
16
+
17
+    /**
18
+     * @param array $items
19
+     */
20
+    public function setItems($items)
21
+    {
22
+        $this->items = $items;
23
+    }
24
+
25
+    /**
26
+     * {@inheritdoc}
27
+     */
28
+    public function offsetExists($offset)
29
+    {
30
+        return isset($this->items[$offset]);
31
+    }
32
+
33
+    /**
34
+     * {@inheritdoc}
35
+     */
36
+    public function offsetGet($offset)
37
+    {
38
+        return isset($this->items[$offset]);
39
+    }
40
+
41
+    /**
42
+     * {@inheritdoc}
43
+     */
44
+    public function offsetSet($offset, $value)
45
+    {
46
+        if (is_null($offset)) {
47
+            $this->items[] = $value;
48
+        } else {
49
+            $this->items[$offset] = $value;
50
+        }
51
+    }
52
+
53
+    /**
54
+     * {@inheritdoc}
55
+     */
56
+    public function offsetUnset($offset)
57
+    {
58
+        unset($this->items[$offset]);
59
+    }
60
+
61
+    /**
62
+     * {@inheritdoc}
63
+     */
64
+    public function getIterator()
65
+    {
66
+        return new \ArrayIterator($this->items);
67
+    }
68
+
69
+    /**
70
+     * {@inheritdoc}
71
+     */
72
+    public function count()
73
+    {
74
+        return count($this->items);
75
+    }
76
+}
0 77
\ No newline at end of file