Completed
Push — master ( a8898a...5c0dbc )
by Nazar
04:15
created

Properties   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 103
ccs 0
cts 30
cp 0
rs 10
c 0
b 0
f 0
wmc 12
lcom 1
cbo 1

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A get() 0 3 1
A set() 0 3 1
A __get() 0 3 1
A avatar() 0 3 1
A username() 0 3 3
A __set() 0 3 1
A get_data() 0 3 1
A set_data() 0 3 1
A del_data() 0 3 1
1
<?php
2
/**
3
 * @package   CleverStyle Framework
4
 * @author    Nazar Mokrynskyi <[email protected]>
5
 * @copyright Copyright (c) 2011-2016, Nazar Mokrynskyi
6
 * @license   MIT License, see license.txt
7
 */
8
namespace cs\User;
9
use
10
	cs\User;
11
12
/**
13
 * Class for getting of user information
14
 *
15
 * @property int    $id
16
 * @property string $login
17
 * @property string $login_hash    sha224 hash
18
 * @property string $username
19
 * @property string $password_hash sha512 hash
20
 * @property string $email
21
 * @property string $email_hash    sha224 hash
22
 * @property string $language
23
 * @property string $timezone
24
 * @property int    $reg_date      unix timestamp
25
 * @property string $reg_ip        hex value, obtained by function ip2hex()
26
 * @property string $reg_key       random md5 hash, generated during registration
27
 * @property int    $status        '-1' - not activated (for example after registration), 0 - inactive, 1 - active
28
 * @property int    $block_until   unix timestamp
29
 * @property string $avatar
30
 */
31
class Properties {
32
	/**
33
	 * @var int
34
	 */
35
	protected $id;
36
	/**
37
	 * Creating of object and saving user id inside
38
	 *
39
	 * @param int $user
40
	 */
41
	function __construct ($user) {
42
		$this->id = $user;
43
	}
44
	/**
45
	 * Get data item of user
46
	 *
47
	 * @param string|string[] $item
48
	 *
49
	 * @return false|string|mixed[]
50
	 */
51
	function get ($item) {
52
		return User::instance()->get($item, $this->id);
53
	}
54
	/**
55
	 * Set data item of specified user
56
	 *
57
	 * @param array|string $item
58
	 * @param mixed|null   $value
59
	 *
60
	 * @return bool
61
	 */
62
	function set ($item, $value = null) {
63
		return User::instance()->set($item, $value, $this->id);
64
	}
65
	/**
66
	 * Get data item of user
67
	 *
68
	 * @param string|string[] $item
69
	 *
70
	 * @return array|false|string
71
	 */
72
	function __get ($item) {
73
		return User::instance()->get($item, $this->id);
74
	}
75
	/**
76
	 * Get user avatar, if no one present - uses Gravatar
77
	 *
78
	 * @param int|null $size Avatar size, if not specified or resizing is not possible - original image is used
79
	 *
80
	 * @return string
81
	 */
82
	function avatar ($size = null) {
83
		return User::instance()->avatar($size, $this->id);
84
	}
85
	/**
86
	 * Get user name or login or email, depending on existing information
87
	 *
88
	 * @return string
89
	 */
90
	function username () {
91
		return $this->get('username') ?: ($this->get('login') ?: $this->get('email'));
92
	}
93
	/**
94
	 * Set data item of user
95
	 *
96
	 * @param array|string $item
97
	 * @param mixed|null   $value
98
	 */
99
	function __set ($item, $value = null) {
100
		User::instance()->set($item, $value, $this->id);
101
	}
102
	/**
103
	 * Getting additional data item(s) of specified user
104
	 *
105
	 * @param string|string[] $item
106
	 *
107
	 * @return false|string|mixed[]
108
	 */
109
	function get_data ($item) {
110
		return User::instance()->get_data($item, $this->id);
111
	}
112
	/**
113
	 * Setting additional data item(s) of specified user
114
	 *
115
	 * @param array|string $item
116
	 * @param mixed|null   $value
117
	 *
118
	 * @return bool
119
	 */
120
	function set_data ($item, $value = null) {
121
		return User::instance()->set_data($item, $value, $this->id);
122
	}
123
	/**
124
	 * Deletion of additional data item(s) of specified user
125
	 *
126
	 * @param string|string[] $item
127
	 *
128
	 * @return bool
129
	 */
130
	function del_data ($item) {
131
		return User::instance()->del_data($item, $this->id);
132
	}
133
}
134