User::withUsername()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace TechDeCo\ElasticApmAgent\Message;
5
6
use JsonSerializable;
7
use TechDeCo\ElasticApmAgent\Serialization;
8
9
final class User implements JsonSerializable
10
{
11
    /**
12
     * @var string|int|null
13
     */
14
    private $id;
15
16
    /**
17
     * @var string|null
18
     */
19
    private $email;
20
21
    /**
22
     * @var string
23
     */
24
    private $username;
25
26
    /**
27
     * @param string|int $id
28
     */
29 2
    public function withId($id): self
30
    {
31 2
        $me     = clone $this;
32 2
        $me->id = $id;
33
34 2
        return $me;
35
    }
36
37 1
    public function withEmail(string $email): self
38
    {
39 1
        $me        = clone $this;
40 1
        $me->email = $email;
41
42 1
        return $me;
43
    }
44
45 1
    public function withUsername(string $username): self
46
    {
47 1
        $me           = clone $this;
48 1
        $me->username = $username;
49
50 1
        return $me;
51
    }
52
53
    /**
54
     * @return mixed[]
55
     */
56 3
    public function jsonSerialize(): array
57
    {
58 3
        return Serialization::filterUnset([
59 3
            'id' => $this->id,
60 3
            'email' => $this->email,
61 3
            'username' => $this->username,
62
        ]);
63
    }
64
}
65