Test Failed
Push — master ( 5a7453...e9bda3 )
by Daniel
04:29
created

User::fromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 7
ccs 0
cts 6
cp 0
crap 2
rs 10
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 $webUrl;
21
22
    /**
23
     * Project constructor.
24
     * @param int $id
25
     * @param string $username
26
     * @param string $name
27
     * @param string $webUrl
28
     */
29
    public function __construct(
30
        int $id,
31
        string $username,
32
        string $name,
33
        string $webUrl
34
    ) {
35
        $this->id = $id;
36
        $this->username = $username;
37
        $this->name = $name;
38
        $this->webUrl = $webUrl;
39
    }
40
41
    /**
42
     * @param array $user
43
     * @return User
44
     */
45
    public static function fromArray(array $user): self
46
    {
47
        return new self(
48
            (int)$user['id'],
49
            (string)$user['username'],
50
            (string)$user['name'],
51
            (string)$user['web_url']
52
        );
53
    }
54
55
    /**
56
     * @return int
57
     */
58
    public function getId(): int
59
    {
60
        return $this->id;
61
    }
62
63
    /**
64
     * @return string
65
     */
66
    public function getUsername(): string
67
    {
68
        return $this->username;
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 getWebUrl(): string
83
    {
84
        return $this->webUrl;
85
    }
86
}
87