1<?php
2
3/*
4 * This file is part of the Gitter library.
5 *
6 * (c) Klaus Silveira <klaussilveira@php.net>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Gitter\Model\Commit;
13
14use Gitter\Model\GitObject;
15use Gitter\Util\DateTime;
16
17class Commit extends GitObject
18{
19    protected $shortHash;
20    protected $treeHash;
21    protected $parentsHash;
22    protected $author;
23    protected $date;
24    protected $commiter;
25    protected $commiterDate;
26    protected $message;
27    protected $body;
28    protected $diffs;
29
30    public function importData(array $data)
31    {
32        $this->setHash($data['hash']);
33        $this->setShortHash($data['short_hash']);
34        $this->setTreeHash($data['tree']);
35        $this->setParentsHash(isset($data['parents']) ? array_filter(explode(' ', $data['parents'])) : array());
36
37        $this->setAuthor(
38            new Author($data['author'], $data['author_email'])
39        );
40
41        $this->setDate(
42            new DateTime('@' . $data['date'])
43        );
44
45        $this->setCommiter(
46            new Author($data['commiter'], $data['commiter_email'])
47        );
48
49        $this->setCommiterDate(
50            new DateTime('@' . $data['commiter_date'])
51        );
52
53        $this->setMessage($data['message']);
54
55        if (isset($data['body'])) {
56            $this->setBody($data['body']);
57        }
58    }
59
60    public function getShortHash()
61    {
62        return $this->shortHash;
63    }
64
65    public function setShortHash($shortHash)
66    {
67        $this->shortHash = $shortHash;
68
69        return $this;
70    }
71
72    public function getTreeHash()
73    {
74        return $this->treeHash;
75    }
76
77    public function setTreeHash($treeHash)
78    {
79        $this->treeHash = $treeHash;
80
81        return $this;
82    }
83
84    public function getParentsHash()
85    {
86        return $this->parentsHash;
87    }
88
89    public function setParentsHash($parentsHash)
90    {
91        $this->parentsHash = $parentsHash;
92
93        return $this;
94    }
95
96    public function getAuthor()
97    {
98        return $this->author;
99    }
100
101    public function setAuthor($author)
102    {
103        $this->author = $author;
104
105        return $this;
106    }
107
108    public function getDate()
109    {
110        return $this->date;
111    }
112
113    public function setDate($date)
114    {
115        $this->date = $date;
116
117        return $this;
118    }
119
120    public function getCommiter()
121    {
122        return $this->commiter;
123    }
124
125    public function setCommiter($commiter)
126    {
127        $this->commiter = $commiter;
128
129        return $this;
130    }
131
132    public function getCommiterDate()
133    {
134        return $this->commiterDate;
135    }
136
137    public function setCommiterDate($commiterDate)
138    {
139        $this->commiterDate = $commiterDate;
140
141        return $this;
142    }
143
144    public function getMessage()
145    {
146        return $this->message;
147    }
148
149    public function setMessage($message)
150    {
151        $this->message = $message;
152
153        return $this;
154    }
155
156    public function getBody()
157    {
158        return $this->body;
159    }
160
161    public function setBody($body)
162    {
163        $this->body = $body;
164
165        return $this;
166    }
167
168    public function getDiffs()
169    {
170        return $this->diffs;
171    }
172
173    public function setDiffs($diffs)
174    {
175        $this->diffs = $diffs;
176
177        return $this;
178    }
179
180    public function getChangedFiles()
181    {
182        return sizeof($this->diffs);
183    }
184
185    public function isCommit()
186    {
187        return true;
188    }
189}
190