Completed
Push — master ( 3e5383...5237e6 )
by Miro
02:50
created

GithubUserConvertTrait::getUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
1
<?php
2
3
namespace DevBoardLib\GithubObjectApiFacade\User\Converter;
4
5
use DevBoardLib\GithubCore\Repo\GithubRepoOwner;
6
use DevBoardLib\GithubCore\User\GithubUserId;
7
use DevBoardLib\GithubCore\User\GithubUserSource;
8
use DevBoardLib\GithubCore\User\Type\GithubTypeFactory;
9
10
/**
11
 * Class GithubUserConvertTrait.
12
 */
13
trait GithubUserConvertTrait
14
{
15
    /**
16
     * @param array $data
17
     *
18
     * @return GithubUserSource
19
     */
20
    protected function getGithubRepoOwner(array $data)
21
    {
22
        return new GithubRepoOwner(
23
            new GithubUserId($data['id']),
24
            $data['login'],
25
            $data['avatar_url'],
26
            GithubTypeFactory::create($data['type'])
27
28
        );
29
    }
30
31
    /**
32
     * @param array $data
33
     *
34
     * @return GithubUserSource
35
     */
36
    protected function getUser(array $data)
37
    {
38
        return new GithubUserSource(
39
            new GithubUserId($data['id']),
40
            $data['login'],
41
            null,
42
            null,
43
            $data['avatar_url']
44
45
        );
46
    }
47
48
    /**
49
     * @param array|null $data
50
     *
51
     * @return GithubUserSource|null
52
     */
53
    protected function getUserIfExists(array $data = null)
54
    {
55
        if (empty($data)) {
56
            return null;
57
        }
58
59
        return $this->getUser($data);
60
    }
61
}
62