ec4a04a7aed1bc3f83409277b862fc74a4a6c552
[phorkie.git] / src / phorkie / Repository / Commit.php
1 <?php
2 namespace phorkie;
3
4
5 class Repository_Commit
6 {
7     public $hash;
8     public $committerName;
9     public $committerEmail;
10     public $committerTime;
11
12     public $linesAdded;
13     public $linesDeleted;
14     public $filesChanged;
15
16
17     public function getIconUrl()
18     {
19         //workaround for https://pear.php.net/bugs/bug.php?id=19384
20         require_once 'PEAR/Services/Libravatar.php';
21
22         $s = new \Services_Libravatar();
23         return $s->url('cweiske@cweiske.de'/*$this->committerEmail*/, array('s' => 32));
24     }
25
26     /**
27      * @return array Array with 7 fields, each has either "r", "g" or "n"
28      *               ("red", "green" or "none")
29      */
30     public function getDots()
31     {
32         $r = $this->getDotNum($this->linesDeleted);
33         $g = $this->getDotNum($this->linesAdded);
34         $sum = $r + $g;
35         if ($sum > 7) {
36             $quot = ceil($sum / 7);
37             $r = int($r / $quot);
38             $g = int($g / $quot);
39         }
40         $string = str_repeat('g', $g) . str_repeat('r', $r) . str_repeat('n', 7 - $g - $r);
41
42         return str_split($string);
43     }
44
45     public function getDotNum($lines)
46     {
47         if ($lines == 0) {
48             return 0;
49         } else if ($lines == 1) {
50             return 1;
51         } else if ($lines == 2) {
52             return 2;
53         } else if ($lines == 3) {
54             return 3;
55         } else if ($lines == 4) {
56             return 4;
57         } else if ($lines < 10) {
58             return 5;
59         } else if ($lines < 50) {
60             return 6;
61         }
62         return 7;
63     }
64 }
65
66 ?>