Completed
Push — master ( cceadc...3df73a )
by Mikołaj
04:41
created

User::isActive()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Rudolf\Modules\Users\One;
4
5
use Rudolf\Component\Html\Text;
6
7
class User
8
{
9
    /**
10
     * @var array User data
11
     */
12
    protected $user;
13
14
    /**
15
     * Constructor.
16
     *
17
     * @param array $user
18
     */
19
    public function __construct(array $user = [])
20
    {
21
        $this->setData($user);
22
    }
23
24
    /**
25
     * Set user data.
26
     *
27
     * @param array $user
28
     */
29
    public function setData($user)
30
    {
31
        $this->user = array_merge(
32
            [
33
                'id' => 0,
34
                'nick' => '',
35
                'first_name' => '',
36
                'surname' => '',
37
                'email' => '',
38
                'active' => false,
39
                'dt' => '',
40
            ],
41
            (array) $user
42
        );
43
    }
44
45
    /**
46
     * Returns user ID.
47
     *
48
     * @return int
49
     */
50
    public function id()
51
    {
52
        return (int) $this->user['id'];
53
    }
54
55
    /**
56
     * Returns user nick.
57
     *
58
     * @param string $type null|raw
59
     *
60
     * @return string
61
     */
62 View Code Duplication
    public function nick($type = '')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
    {
64
        $nick = $this->user['nick'];
65
        if ('raw' === $type) {
66
            return $nick;
67
        }
68
69
        return Text::escape($nick);
70
    }
71
72
    /**
73
     * Returns user first name.
74
     *
75
     * @param string $type null|raw
76
     *
77
     * @return string
78
     */
79
    public function firstName($type = '')
80
    {
81
        $firstName = $this->user['first_name'];
82
        if ('raw' === $type) {
83
            return $firstName;
84
        }
85
86
        return Text::escape($firstName);
87
    }
88
89
    /**
90
     * Returns user surname.
91
     *
92
     * @param string $type null|raw
93
     *
94
     * @return string
95
     */
96 View Code Duplication
    public function surname($type = '')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
97
    {
98
        $surname = $this->user['surname'];
99
        if ('raw' === $type) {
100
            return $surname;
101
        }
102
103
        return Text::escape($surname);
104
    }
105
106
    /**
107
     * Returns user email.
108
     *
109
     * @param string $type null|raw
110
     *
111
     * @return string
112
     */
113 View Code Duplication
    public function email($type = '')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
114
    {
115
        $email = $this->user['email'];
116
        if ('raw' === $type) {
117
            return $email;
118
        }
119
120
        return Text::escape($email);
121
    }
122
123
    public function getRegisterDate()
124
    {
125
        return $this->user['dt'];
126
    }
127
128
    public function isActive()
129
    {
130
        return (bool) $this->user['active'];
131
    }
132
}
133