Completed
Push — master ( ab4944...534e9c )
by Andrew
02:30
created

ClassyUser   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 152
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 0
loc 152
rs 10
wmc 11
lcom 2
cbo 1

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A verify_id() 0 3 1
A init() 0 5 1
A get_object() 0 3 1
A first_name() 0 5 1
A display_name() 0 5 1
A full_name() 0 5 1
A user_login() 0 5 1
A email() 0 5 1
A link() 0 7 2
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
	 * It's basically sanitized version of user login, used for permalinks
25
	 * @var string
26
	 */
27
	public $user_nicename;
28
29
	/**
30
	 * User email
31
	 * @var string
32
	 */
33
	public $user_email;
34
35
	/**
36
	 * Human-Friendly name, like: Andrew Tolochka
37
	 * @var string
38
	 */
39
	public $display_name;
40
41
	/**
42
	 * User password hash
43
	 * @var string
44
	 */
45
	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...
46
47
	/**
48
	 * Stores current post object
49
	 * @var object
50
	 */
51
	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...
52
53
	
54
	/**
55
	 * Main constructor function. Requires user id
56
	 * @param int $uid
57
	 */
58
	public function __construct($uid = null) {
59
		$this->ID = $this->verify_id($uid);
60
		
61
		$this->init();
62
	}
63
64
	private function verify_id($uid) {
65
		return $uid;
66
	}
67
68
	/**
69
	 * Initialises Instance based on provided post id
70
	 */
71
	private function init() {
72
		$object = (array) $this->get_object();
73
74
		$this->import($object);
75
	}
76
77
	/**
78
	 * Returns user object
79
	 * 
80
	 * @return object
81
	 */
82
	private function get_object() {
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
83
		return get_userdata($this->ID);
84
	}
85
86
	/**
87
	 * Returns user first name
88
	 * 
89
	 * @return string
90
	 */
91
	public function first_name() {
92
93
		return $this->first_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...
94
	
95
	}
96
97
	/**
98
	 * Returns user display name
99
	 * 
100
	 * @return string
101
	 */
102
	public function display_name() {
103
104
		return $this->display_name;
105
106
	}
107
	
108
	/**
109
	 * Returns user full name
110
	 * 
111
	 * @return string
112
	 */
113
	public function full_name() {
114
115
		return $this->first_name . ' ' . $this->last_name;
0 ignored issues
show
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...
116
117
	}
118
	
119
	/**
120
	 * Returns user user_login
121
	 * 
122
	 * @return string
123
	 */
124
	public function user_login() {
125
126
		return $this->user_login;
127
128
	}
129
	
130
	/**
131
	 * Returns user email
132
	 * 
133
	 * @return string
134
	 */
135
	public function email() {
136
137
		return $this->user_email;
138
139
	}
140
141
	/**
142
	 * Returns author posts url
143
	 * 
144
	 * @return string
145
	 */
146
	public function link() {
147
		if ( !$this->link ) {
148
			$this->link = get_author_posts_url($this->ID);
149
		}
150
151
		return $this->link;
152
	}
153
154
}