Browse code

Sort commits in statistics

Niklas Modess authored on 24/05/2014 14:51:12
Showing 4 changed files
... ...
@@ -95,6 +95,10 @@ class Repository
95 95
      */
96 96
     public function getStatistics ()
97 97
     {
98
+        foreach ($this->statistics as $statistic) {
99
+            $statistic->sortCommits();
100
+        }
101
+
98 102
         return $this->statistics;
99 103
     }
100 104
 
... ...
@@ -21,7 +21,18 @@ class Contributors extends Collection implements StatisticsInterface
21 21
             $this->items[$email] = new Collection;
22 22
         }
23 23
 
24
-        $commits = $this->items[$email];
25
-        $commits->items[$commitDate][] = $commit;
24
+        $this->items[$email]->items[$commitDate][] = $commit;
25
+        ksort($this->items[$email]->items);
26
+    }
27
+
28
+    public function sortCommits()
29
+    {
30
+        uasort($this->items, function ($sortA, $sortB)  {
31
+            if (count($sortA) === count($sortB)) {
32
+                return 0;
33
+            }
34
+
35
+            return count($sortA) > count($sortB) ? -1 : 1;
36
+        });
26 37
     }
27 38
 }
28 39
\ No newline at end of file
... ...
@@ -18,4 +18,9 @@ class Day extends Collection implements StatisticsInterface
18 18
 
19 19
         $this->items[$day][] = $commit;
20 20
     }
21
+
22
+    public function sortCommits()
23
+    {
24
+        ksort($this->items);
25
+    }
21 26
 }
22 27
\ No newline at end of file
... ...
@@ -6,4 +6,6 @@ use Gitter\Model\Commit\Commit;
6 6
 interface StatisticsInterface
7 7
 {
8 8
     public function addCommit (Commit $commit);
9
+
10
+    public function sortCommits ();
9 11
 }