Completed
Push — master ( 714e52...03936a )
by Miro
02:26
created

GithubCommitCommitter::deserialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 10
Ratio 100 %
Metric Value
dl 10
loc 10
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
1
<?php
2
3
namespace DevBoardLib\GithubCore\Commit;
4
5
use DevBoardLib\GithubCore\User\GithubUserId;
6
7
/**
8
 * @todo: Reason this class exists
9
 */
10 View Code Duplication
class GithubCommitCommitter
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
{
12
    /** @var string */
13
    private $name;
14
    /** @var string */
15
    private $email;
16
    /** @var GithubUserId */
17
    private $githubUserId;
18
    /** @var string */
19
    private $username;
20
    /** @var string */
21
    private $avatarUrl;
22
23
    /**
24
     * Author constructor.
25
     *
26
     * @param $name
27
     * @param $email
28
     * @param $githubUserId
29
     * @param $username
30
     * @param $avatarUrl
31
     */
32
    public function __construct(
33
        string $name,
34
        string $email,
35
        GithubUserId $githubUserId = null,
36
        string $username = null,
37
        string $avatarUrl = null
38
    ) {
39
        $this->name         = $name;
40
        $this->email        = $email;
41
        $this->githubUserId = $githubUserId;
42
        $this->username     = $username;
43
        $this->avatarUrl    = $avatarUrl;
44
    }
45
46
    /** @return string */
47
    public function getName() : string
48
    {
49
        return $this->name;
50
    }
51
52
    /** @return string */
53
    public function getEmail() : string
54
    {
55
        return $this->email;
56
    }
57
58
    /** @return GithubUserId */
59
    public function getGithubUserId() : GithubUserId
60
    {
61
        return $this->githubUserId;
62
    }
63
64
    /** @return string */
65
    public function getUsername() : string
66
    {
67
        return $this->username;
68
    }
69
70
    /** @return string */
71
    public function getAvatarUrl() : string
72
    {
73
        return $this->avatarUrl;
74
    }
75
76
    /** @return array */
77
    public function serialize()
78
    {
79
        return [
80
            'name'         => $this->name,
81
            'email'        => $this->email,
82
            'githubUserId' => (string) $this->githubUserId,
83
            'username'     => $this->username,
84
            'avatarUrl'    => $this->avatarUrl,
85
        ];
86
    }
87
88
    /**
89
     * @param array $data
90
     *
91
     * @throws \Exception
92
     *
93
     * @return static
94
     */
95
    public static function deserialize(array $data)
96
    {
97
        return new static(
98
            $data['name'],
99
            $data['email'],
100
            self::unSerializeId($data['githubUserId']),
101
            $data['username'],
102
            $data['avatarUrl']
103
        );
104
    }
105
106
    /**
107
     * @param $id
108
     *
109
     * @return GithubUserId|null
110
     */
111
    private static function unSerializeId($id)
112
    {
113
        if (null === $id) {
114
            return null;
115
        }
116
117
        return new GithubUserId($id);
118
    }
119
}
120