Passed
Push — master ( 532413...392df2 )
by Kylian
01:24
created

User::toJson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace KriKrixs\object\user;
4
5
class User
6
{
7
    private object $user;
8
9
    /**
10
     * Create a new User object
11
     * @param object $user
12
     */
13
    public function __construct(object $user)
14
    {
15
        $this->user = $user;
16
    }
17
18
    /**
19
     * Return raw data
20
     * @return object
21
     */
22
    public function toJson(): object
23
    {
24
        return $this->user;
25
    }
26
27
    /**
28
     * Return array data
29
     * @return array
30
     */
31
    public function toArray(): array
32
    {
33
        return json_decode($this->user, true);
0 ignored issues
show
Bug introduced by
$this->user of type object is incompatible with the type string expected by parameter $json of json_decode(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
        return json_decode(/** @scrutinizer ignore-type */ $this->user, true);
Loading history...
34
    }
35
36
    /**
37
     * Get user ID
38
     * @return int
39
     */
40
    public function getId(): int
41
    {
42
        return $this->user->id;
43
    }
44
45
    /**
46
     * Get user name
47
     * @return string
48
     */
49
    public function getName(): string
50
    {
51
        return $this->user->name;
52
    }
53
54
    /**
55
     * Is user unique set
56
     * @return bool
57
     */
58
    public function isUniqueSet(): bool
59
    {
60
        return $this->user->uniqueSet;
61
    }
62
63
    /**
64
     * Get user hash
65
     * @return string
66
     */
67
    public function getHash(): string
68
    {
69
        return $this->user->hash;
70
    }
71
72
    /**
73
     * Get user avatar link
74
     * @return string
75
     */
76
    public function getAvatarURL(): string
77
    {
78
        return $this->user->avatar;
79
    }
80
81
    /**
82
     * Get user stats (UserStats object)
83
     * @return UserStats
84
     */
85
    public function getStats(): UserStats
86
    {
87
        return new UserStats($this->user->stats);
88
    }
89
90
    /**
91
     * Get user type
92
     * @return string
93
     */
94
    public function getType(): string
95
    {
96
        return $this->user->type;
97
    }
98
}