|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DevBoardLib\GithubObjectApiFacade\Repo\Repo\Converter; |
|
4
|
|
|
|
|
5
|
|
|
use DevBoardLib\GithubCore\Repo\GithubRepoCreatedAt; |
|
6
|
|
|
use DevBoardLib\GithubCore\Repo\GithubRepoFullName; |
|
7
|
|
|
use DevBoardLib\GithubCore\Repo\GithubRepoGitUrl; |
|
8
|
|
|
use DevBoardLib\GithubCore\Repo\GithubRepoId; |
|
9
|
|
|
use DevBoardLib\GithubCore\Repo\GithubRepoName; |
|
10
|
|
|
use DevBoardLib\GithubCore\Repo\GithubRepoPermissions; |
|
11
|
|
|
use DevBoardLib\GithubCore\Repo\GithubRepoPushedAt; |
|
12
|
|
|
use DevBoardLib\GithubCore\Repo\GithubRepoSource; |
|
13
|
|
|
use DevBoardLib\GithubCore\Repo\GithubRepoSshUrl; |
|
14
|
|
|
use DevBoardLib\GithubCore\Repo\GithubRepoUpdatedAt; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class GithubRepoConvertTrait. |
|
18
|
|
|
*/ |
|
19
|
|
|
trait GithubRepoConvertTrait |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @param array $data |
|
23
|
|
|
* |
|
24
|
|
|
* @return GithubRepoSource |
|
25
|
|
|
*/ |
|
26
|
|
|
protected function convertRepo(array $data) |
|
27
|
|
|
{ |
|
28
|
|
|
$permissions = null; |
|
29
|
|
|
|
|
30
|
|
|
if (array_key_exists('permissions', $data)) { |
|
31
|
|
|
$permissions = new GithubRepoPermissions( |
|
32
|
|
|
(bool) $data['permissions']['admin'], |
|
33
|
|
|
(bool) $data['permissions']['push'], |
|
34
|
|
|
(bool) $data['permissions']['pull'] |
|
35
|
|
|
); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
return new GithubRepoSource( |
|
39
|
|
|
new GithubRepoId($data['id']), |
|
40
|
|
|
$this->getGithubRepoOwner($data['owner']), |
|
|
|
|
|
|
41
|
|
|
new GithubRepoName($data['name']), |
|
42
|
|
|
new GithubRepoFullName($data['full_name']), |
|
43
|
|
|
$data['html_url'], |
|
44
|
|
|
$data['description'], |
|
45
|
|
|
$data['fork'], |
|
46
|
|
|
$data['default_branch'], |
|
47
|
|
|
$data['private'], |
|
48
|
|
|
new GithubRepoGitUrl($data['git_url']), |
|
49
|
|
|
new GithubRepoSshUrl($data['ssh_url']), |
|
50
|
|
|
$permissions, |
|
51
|
|
|
new GithubRepoCreatedAt($data['created_at']), |
|
52
|
|
|
new GithubRepoUpdatedAt($data['updated_at']), |
|
53
|
|
|
new GithubRepoPushedAt($data['pushed_at']) |
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.