Completed
Push — master ( e447f7...0a0e4a )
by Miro
02:26
created

GithubRepoOwner::deserialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

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