Passed
Push — master ( 4e582d...e8c0a3 )
by n
02:48
created

User::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace N1215\SimpleAdr\Domain;
4
5
class User implements \JsonSerializable
6
{
7
8
    /** @var UserId */
9
    private $userId;
10
11
    /** @var UserName */
12
    private $userName;
13
14 4
    public function __construct(UserId $userId, UserName $userName)
15
    {
16 4
        $this->userId = $userId;
17 4
        $this->userName = $userName;
18 4
    }
19
20
    /**
21
     * ユーザー名を取得
22
     */
23 2
    public function getName() : UserName
24
    {
25 2
        return $this->userName;
26
    }
27
28
    /**
29
     * ユーザーIDを取得
30
     */
31 2
    public function getId() : UserId
32
    {
33 2
        return $this->userId;
34
    }
35
36
    /**
37
     * JSON用の配列に変換
38
     */
39 1
    public function jsonSerialize() : array
40
    {
41 1
        $rawId = $this->userId->getValue();
42 1
        $rawName = $this->userName->getValue();
43
44
        return [
45 1
            'id' => $rawId,
46 1
            'name' => $rawName,
47
        ];
48
    }
49
}