Completed
Push — master ( 706672...0f2117 )
by Daniel
02:07
created

User::getUsername()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace DanielPieper\MergeReminder\ValueObject;
4
5
class User
6
{
7
    public const STATE_ACTIVE = 'active';
8
    public const STATE_BLOCKED = 'blocked';
9
10
    /** @var int */
11
    private $id;
12
13
    /** @var string */
14
    private $username;
15
16
    /** @var string */
17
    private $name;
18
19
    /** @var string */
20
    private $state;
21
22
    /** @var string */
23
    private $avatarUrl;
24
25
    /** @var string */
26
    private $webUrl;
27
28
    /**
29
     * Project constructor.
30
     * @param int $id
31
     * @param string $username
32
     * @param string $name
33
     * @param string $state
34
     * @param string $avatarUrl
35
     * @param string $webUrl
36
     */
37 18
    public function __construct(
38
        int $id,
39
        string $username,
40
        string $name,
41
        string $state,
42
        string $avatarUrl,
43
        string $webUrl
44
    ) {
45 18
        $this->id = $id;
46 18
        $this->username = $username;
47 18
        $this->name = $name;
48 18
        $this->state = $state;
49 18
        $this->avatarUrl = $avatarUrl;
50 18
        $this->webUrl = $webUrl;
51 18
    }
52
53
    /**
54
     * @param array $user
55
     * @return User
56
     */
57 18
    public static function fromArray(array $user): self
58
    {
59 18
        return new self(
60 18
            (int)$user['id'],
61 18
            (string)$user['username'],
62 18
            (string)$user['name'],
63 18
            (string)$user['state'],
64 18
            (string)$user['avatar_url'],
65 18
            (string)$user['web_url']
66
        );
67
    }
68
69
    /**
70
     * @return int
71
     */
72 4
    public function getId(): int
73
    {
74 4
        return $this->id;
75
    }
76
77
    /**
78
     * @return string
79
     */
80 3
    public function getUsername(): string
81
    {
82 3
        return $this->username;
83
    }
84
85
    /**
86
     * @return string
87
     */
88
    public function getName(): string
89
    {
90
        return $this->name;
91
    }
92
93
    /**
94
     * @return string
95
     */
96
    public function getState(): string
97
    {
98
        return $this->state;
99
    }
100
101
    /**
102
     * @return bool
103
     */
104
    public function isActive(): bool
105
    {
106
        return $this->state === self::STATE_ACTIVE;
107
    }
108
109
    /**
110
     * @return bool
111
     */
112
    public function isBlocked(): bool
113
    {
114
        return $this->state === self::STATE_BLOCKED;
115
    }
116
117
    /**
118
     * @return string
119
     */
120
    public function getAvatarUrl(): string
121
    {
122
        return $this->avatarUrl;
123
    }
124
125
    /**
126
     * @return string
127
     */
128 2
    public function getWebUrl(): string
129
    {
130 2
        return $this->webUrl;
131
    }
132
}
133