1
|
|
|
<?php |
2
|
|
|
namespace DevBoardLib\GithubObjectApiFacade\Repo\Commit\Converter; |
3
|
|
|
|
4
|
|
|
use DateTime; |
5
|
|
|
use DevBoardLib\GithubCore\Commit\GithubCommitId; |
6
|
|
|
use DevBoardLib\GithubCore\Commit\GithubCommitSha; |
7
|
|
|
use DevBoardLib\GithubCore\Commit\GithubCommitSource; |
8
|
|
|
use DevBoardLib\GithubCore\User\GithubUserId; |
9
|
|
|
use DevBoardLib\GithubCore\User\GithubUserSource; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class GithubCommitConvertTrait. |
13
|
|
|
*/ |
14
|
|
|
trait GithubCommitConvertTrait |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @param $data |
18
|
|
|
* |
19
|
|
|
* @return GithubCommitSource |
20
|
|
|
*/ |
21
|
|
|
protected function convertCommit($data) |
22
|
|
|
{ |
23
|
|
|
return new GithubCommitSource( |
24
|
|
|
new GithubCommitId($this->githubRepo->getId(), new GithubCommitSha($data['sha'])), |
|
|
|
|
25
|
|
|
$this->githubRepo, |
26
|
|
|
new GithubCommitSha($data['sha']), |
27
|
|
|
$data['commit']['author']['name'], |
28
|
|
|
$data['commit']['author']['email'], |
29
|
|
|
$this->getAuthor($data), |
30
|
|
|
new DateTime($data['commit']['author']['date']), |
31
|
|
|
$this->getCommitter($data), |
32
|
|
|
new DateTime($data['commit']['committer']['date']), |
33
|
|
|
$data['commit']['message'], |
34
|
|
|
null |
35
|
|
|
|
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param $data |
41
|
|
|
* |
42
|
|
|
* @return GithubUserSource |
43
|
|
|
*/ |
44
|
|
View Code Duplication |
protected function getAuthor($data) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
return new GithubUserSource( |
47
|
|
|
new GithubUserId($data['author']['id']), |
48
|
|
|
$data['author']['login'], |
49
|
|
|
$data['commit']['author']['email'], |
50
|
|
|
$data['commit']['author']['name'], |
51
|
|
|
$data['author']['avatar_url'] |
52
|
|
|
|
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param $data |
58
|
|
|
* |
59
|
|
|
* @return GithubUserSource |
60
|
|
|
*/ |
61
|
|
View Code Duplication |
protected function getCommitter($data) |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
return new GithubUserSource( |
64
|
|
|
new GithubUserId($data['committer']['id']), |
65
|
|
|
$data['committer']['login'], |
66
|
|
|
$data['commit']['committer']['email'], |
67
|
|
|
$data['commit']['committer']['name'], |
68
|
|
|
$data['committer']['avatar_url'] |
69
|
|
|
|
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: