Browse code

Commit collection and contributor statistics

Niklas Modess authored on 24/05/2014 13:57:01
Showing 4 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,62 @@
0
+<?php
1
+namespace Gitter\Model\Commit;
2
+
3
+
4
+class Collection implements \ArrayAccess {
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
+}
0 62
\ No newline at end of file
... ...
@@ -343,6 +343,10 @@ class Repository
343 343
             $commit = new Commit;
344 344
             $commit->importData($log);
345 345
             $commits[] = $commit;
346
+
347
+            foreach ($this->getStatistics() as $statistic) {
348
+                $statistic->addCommit($commit);
349
+            }
346 350
         }
347 351
 
348 352
         return $commits;
349 353
new file mode 100644
... ...
@@ -0,0 +1,28 @@
0
+<?php
1
+namespace Gitter\Statistics;
2
+
3
+use Gitter\Model\Commit\Collection;
4
+use Gitter\Model\Commit\Commit;
5
+
6
+/**
7
+ * Aggregate statistics based on contributor
8
+ */
9
+class Contributors extends Collection implements StatisticsInterface
10
+{
11
+    /**
12
+     * @param Commit $commit
13
+     */
14
+    public function addCommit(Commit $commit)
15
+    {
16
+        $email = $commit->getAuthor()->getEmail();
17
+        $name  = $commit->getAuthor()->getName();
18
+
19
+        $commitDate  = $commit->getCommiterDate()->format('Y-m-d');
20
+
21
+        if (!isset($this->commits[$email]['name'])) {
22
+            $this->commits[$email]['name'] = $name;
23
+        }
24
+
25
+        $this->commits[$email]['commits'][$commitDate][] = $commit;
26
+    }
27
+}
0 28
\ No newline at end of file
... ...
@@ -1,6 +1,9 @@
1 1
 <?php
2
-namespace Gitter\Statitics;
2
+namespace Gitter\Statistics;
3
+
4
+use Gitter\Model\Commit\Commit;
3 5
 
4 6
 interface StatisticsInterface
5 7
 {
8
+    public function addCommit (Commit $commit);
6 9
 }