Completed
Push — master ( e447f7...c16ba2 )
by Miro
02:27
created

GithubRepoOwner::serialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 9
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace DevBoardLib\GithubCore\Repo;
4
5
use DevBoardLib\GithubCore\User\GithubUser;
6
use DevBoardLib\GithubCore\User\GithubUserId;
7
use DevBoardLib\GithubCore\User\Type\GithubType;
8
use DevBoardLib\GithubCore\User\Type\GithubTypeFactory;
9
10
/**
11
 * Value object representing github repo owner.
12
 */
13
class GithubRepoOwner implements GithubUser
14
{
15
    /** @var GithubUserId */
16
    private $githubUserId;
17
    /** @var string */
18
    private $username;
19
    /** @var string */
20
    private $avatarUrl;
21
    /** @var GithubType */
22
    private $type;
23
24
    /**
25
     * GithubUserSource constructor.
26
     *
27
     * @param GithubUserId $githubUserId
28
     * @param string       $username
29
     * @param string       $avatarUrl
30
     * @param GithubType   $type
31
     */
32
    public function __construct(
33
        GithubUserId $githubUserId,
34
        string $username,
35
        string $avatarUrl,
36
        GithubType $type
37
    ) {
38
        $this->githubUserId = $githubUserId;
39
        $this->username     = $username;
40
        $this->avatarUrl    = $avatarUrl;
41
        $this->type         = $type;
42
    }
43
44
    /**
45
     * @return GithubUserId
46
     */
47
    public function getGithubUserId() : GithubUserId
48
    {
49
        return $this->githubUserId;
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getUsername() : string
56
    {
57
        return $this->username;
58
    }
59
60
    /**
61
     */
62
    public function getEmail()
63
    {
64
        return null;
65
    }
66
67
    /**
68
     */
69
    public function getName()
70
    {
71
        return null;
72
    }
73
74
    /**
75
     * @return GithubType
76
     */
77
    public function getType() : GithubType
78
    {
79
        return $this->type;
80
    }
81
82
    /**
83
     * @return string
84
     */
85
    public function getAvatarUrl() : string
86
    {
87
        return $this->avatarUrl;
88
    }
89
90
    /**
91
     * @return array
92
     */
93
    public function serialize() : array
94
    {
95
        return [
96
            'githubUserId' => (string) $this->githubUserId,
97
            'username'     => $this->username,
98
            'avatarUrl'    => $this->avatarUrl,
99
            'type'         => (string) $this->type,
100
        ];
101
    }
102
103
    /**
104
     * @param array $data
105
     *
106
     * @return GithubRepoOwner
107
     */
108
    public static function deserialize(array  $data) : GithubRepoOwner
109
    {
110
        return new static(
111
            new GithubUserId($data['githubUserId']),
112
            $data['username'],
113
            $data['avatarUrl'],
114
            GithubTypeFactory::create($data['type'])
115
        );
116
    }
117
}
118