1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DevBoardLib\GithubObjectApiFacade\Repo\Commit\Converter; |
4
|
|
|
|
5
|
|
|
use DevBoardLib\GithubCore\Commit\GithubCommitAuthor; |
6
|
|
|
use DevBoardLib\GithubCore\Commit\GithubCommitCommitter; |
7
|
|
|
use DevBoardLib\GithubCore\Commit\GithubCommitSha; |
8
|
|
|
use DevBoardLib\GithubCore\Commit\GithubCommitSource; |
9
|
|
|
use DevBoardLib\GithubCore\User\GithubUserId; |
10
|
|
|
use DevBoardLib\GithubCore\User\GithubUserSource; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class GithubCommitConvertTrait. |
14
|
|
|
*/ |
15
|
|
|
trait GithubCommitConvertTrait |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @param array $data |
19
|
|
|
* |
20
|
|
|
* @return GithubCommitSource |
21
|
|
|
*/ |
22
|
|
|
protected function convertCommit(array $data) |
23
|
|
|
{ |
24
|
|
|
return new GithubCommitSource( |
25
|
|
|
new GithubCommitSha($data['sha']), |
26
|
|
|
$this->githubRepo->getId(), |
|
|
|
|
27
|
|
|
$this->getAuthor($data), |
28
|
|
|
$this->getCommitter($data), |
29
|
|
|
$data['commit']['message'], |
30
|
|
|
null |
|
|
|
|
31
|
|
|
|
32
|
|
|
); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param array $data |
37
|
|
|
* |
38
|
|
|
* @return GithubUserSource |
39
|
|
|
*/ |
40
|
|
View Code Duplication |
protected function getAuthor(array $data) |
|
|
|
|
41
|
|
|
{ |
42
|
|
|
return new GithubCommitAuthor( |
43
|
|
|
$data['commit']['author']['name'], |
44
|
|
|
$data['commit']['author']['email'], |
45
|
|
|
new GithubUserId($data['author']['id']), |
46
|
|
|
$data['author']['login'], |
47
|
|
|
$data['author']['avatar_url'] |
48
|
|
|
|
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param array $data |
54
|
|
|
* |
55
|
|
|
* @return GithubUserSource |
56
|
|
|
*/ |
57
|
|
View Code Duplication |
protected function getCommitter(array $data) |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
return new GithubCommitCommitter( |
60
|
|
|
$data['commit']['committer']['name'], |
61
|
|
|
$data['commit']['committer']['email'], |
62
|
|
|
new GithubUserId($data['committer']['id']), |
63
|
|
|
$data['committer']['login'], |
64
|
|
|
$data['committer']['avatar_url'] |
65
|
|
|
|
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
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: