Completed
Push — master ( f191a4...75c234 )
by Andrew
02:27
created

ClassyUser::name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 5
rs 9.4285
1
<?php 
2
3
class ClassyUser extends ClassyBasis {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
5
	/**
6
	 * Current user id
7
	 * @var int
8
	 */
9
	public $ID;
10
11
	/**
12
	 * User posts url
13
	 * @var string
14
	 */
15
	public $link;
16
17
	/**
18
	 * User login (example: anrw)
19
	 * @var string
20
	 */
21
	public $user_login;
22
23
	/**
24
	 * User full name
25
	 * @var string
26
	 */
27
	public $name;
28
29
	/**
30
	 * It's basically sanitized version of user login, used for permalinks
31
	 * @var string
32
	 */
33
	public $user_nicename;
34
35
	/**
36
	 * User email
37
	 * @var string
38
	 */
39
	public $user_email;
40
41
	/**
42
	 * Human-Friendly name, like: Andrew Tolochka
43
	 * @var string
44
	 */
45
	public $display_name;
46
47
	/**
48
	 * User password hash
49
	 * @var string
50
	 */
51
	private $user_pass;
0 ignored issues
show
Unused Code introduced by
The property $user_pass is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
52
53
	/**
54
	 * Stores current post object
55
	 * @var object
56
	 */
57
	private $object;
0 ignored issues
show
Unused Code introduced by
The property $object is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
58
59
	
60
	/**
61
	 * Main constructor function. Requires user id
62
	 * @param int $uid
63
	 */
64
	public function __construct($uid = null) {
65
		$this->ID = $this->verify_id($uid);
66
		
67
		$this->init();
68
	}
69
70
	private function verify_id($uid) {
71
		return $uid;
72
	}
73
74
	/**
75
	 * Initialises Instance based on provided post id
76
	 */
77
	private function init() {
78
		$object = (array) $this->get_object();
79
80
		$this->import($object);
81
82
		if (isset($this->first_name) && isset($this->last_name)) {
83
			$this->name = $this->first_name . ' ' . $this->last_name;
0 ignored issues
show
Bug introduced by
The property first_name does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Bug introduced by
The property last_name does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
84
		} else {
85
			$this->name = 'Anonymous';
86
		}
87
88
	}
89
90
	/**
91
	 * Returns user object
92
	 * 
93
	 * @return object
94
	 */
95
	private function get_object() {
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
96
		return get_userdata($this->ID);
97
	}
98
99
	/**
100
	 * Returns user first name
101
	 * 
102
	 * @return string
103
	 */
104
	public function first_name() {
105
106
		return $this->first_name;
107
	
108
	}
109
110
	/**
111
	 * Returns user display name
112
	 * 
113
	 * @return string
114
	 */
115
	public function display_name() {
116
117
		return $this->display_name;
118
119
	}
120
	
121
	/**
122
	 * Returns user full name
123
	 * 
124
	 * @return string
125
	 */
126
	public function name() {
127
128
		return $this->name;
129
130
	}
131
	
132
	/**
133
	 * Returns user user_login
134
	 * 
135
	 * @return string
136
	 */
137
	public function user_login() {
138
139
		return $this->user_login;
140
141
	}
142
	
143
	/**
144
	 * Returns user email
145
	 * 
146
	 * @return string
147
	 */
148
	public function email() {
149
150
		return $this->user_email;
151
152
	}
153
154
	/**
155
	 * Returns author posts url
156
	 * 
157
	 * @return string
158
	 */
159
	public function link() {
160
		if ( !$this->link ) {
161
			$this->link = get_author_posts_url($this->ID);
162
		}
163
164
		return $this->link;
165
	}
166
167
}