Completed
Push — master ( bc6754...ed64c2 )
by
unknown
07:19
created

User   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 169
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 169
rs 10
wmc 14
lcom 1
cbo 1

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A verify_id() 0 4 1
A init() 0 7 1
A get_object() 0 3 1
A first_name() 0 3 1
A display_name() 0 3 1
A name() 0 3 1
A user_login() 0 3 1
A email() 0 3 1
A link() 0 7 2
A setup_user_name() 0 6 3
1
<?php
2
3
namespace Classy\Models;
4
5
use Classy\Basis;
6
7
8
/**
9
 * Wrapper for \WP_User.
10
 */
11
class User extends Basis {
12
13
	/**
14
	 * Current user id.
15
	 *
16
	 * @var int
17
	 */
18
	public $ID;
19
20
	/**
21
	 * User posts url.
22
	 *
23
	 * @var string
24
	 */
25
	public $link;
26
27
	/**
28
	 * User login (example: anrw).
29
	 *
30
	 * @var string
31
	 */
32
	public $user_login;
33
34
	/**
35
	 * User full name.
36
	 *
37
	 * @var string
38
	 */
39
	public $name;
40
41
	/**
42
	 * It's basically sanitized version of user login, used for permalinks.
43
	 *
44
	 * @var string
45
	 */
46
	public $user_nicename;
47
48
	/**
49
	 * User email.
50
	 *
51
	 * @var string
52
	 */
53
	public $user_email;
54
55
	/**
56
	 * Human-Friendly name, like: Andrew Tolochka.
57
	 *
58
	 * @var string
59
	 */
60
	public $display_name;
61
62
	/**
63
	 * Stores current user object.
64
	 *
65
	 * @var object
66
	 */
67
	private $object;
68
69
	/**
70
	 * Main constructor function. Requires user id.
71
	 *
72
	 * @param int $uid User id.
73
	 */
74
	public function __construct( $uid = null ) {
75
		$this->ID = $this->verify_id( $uid );
76
77
		$this->init();
78
	}
79
80
	/**
81
	 * Verify user id.
82
	 *
83
	 * @param int $uid User id.
84
	 *
85
	 * @return int
86
	 */
87
	private function verify_id( $uid ) {
88
		// @todo: Realize this method.
89
		return $uid;
90
	}
91
92
	/**
93
	 * Initialises User Instance.
94
	 */
95
	private function init() {
96
		$this->object = $this->get_object();
97
98
		$this->import( $this->object );
99
100
		$this->setup_user_name();
101
	}
102
103
	/**
104
	 * Returns user object.
105
	 *
106
	 * @return object
107
	 */
108
	private function get_object() {
109
		return get_user_by( 'id', $this->ID );
110
	}
111
112
	/**
113
	 * Returns user first name.
114
	 *
115
	 * @return string
116
	 */
117
	public function first_name() {
118
		return $this->object->first_name;
119
	}
120
121
	/**
122
	 * Returns user display name.
123
	 *
124
	 * @return string
125
	 */
126
	public function display_name() {
127
		return $this->display_name;
128
	}
129
130
	/**
131
	 * Returns user full name.
132
	 *
133
	 * @return string
134
	 */
135
	public function name() {
136
		return $this->name;
137
	}
138
139
	/**
140
	 * Returns user user_login.
141
	 *
142
	 * @return string
143
	 */
144
	public function user_login() {
145
		return $this->user_login;
146
	}
147
148
	/**
149
	 * Returns user email.
150
	 *
151
	 * @return string
152
	 */
153
	public function email() {
154
		return $this->user_email;
155
	}
156
157
	/**
158
	 * Returns author posts url.
159
	 *
160
	 * @return string
161
	 */
162
	public function link() {
163
		if ( ! $this->link ) {
164
			$this->link = get_author_posts_url( $this->ID );
165
		}
166
167
		return $this->link;
168
	}
169
170
	/**
171
	 * Setup user name and display name.
172
	 */
173
	private function setup_user_name() {
174
		$this->name = 'Anonymous';
175
		if ( isset( $this->object->first_name ) && isset( $this->object->last_name ) ) {
176
			$this->name = $this->object->first_name . ' ' . $this->object->last_name;
177
		}
178
	}
179
}
180