Completed
Push — master ( aec9f9...84751c )
by Sam
02:36 queued 01:13
created

WebUser   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 45
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 6 2
A getRole() 0 6 2
A loadUser() 0 10 3
1
<?php
2
3
/**
4
 * Represents the currently authenticated user
5
 * 
6
 * @author Sam Stenvall <[email protected]>
7
 * @copyright Copyright &copy; Sam Stenvall 2013-
8
 * @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0
9
 */
10
class WebUser extends CWebUser
11
{
12
13
	/**
14
	 * @var User the user model
15
	 */
16
	private $_model;
17
	
18
	/**
19
	 * @return string the username of the current user
20
	 */
21
	public function getName()
22
	{
23
		$user = $this->loadUser();
24
25
		return $user !== null ? $user->username : 'guest';
26
	}
27
28
	/**
29
	 * Returns the user's role
30
	 * @return string
31
	 */
32
	public function getRole()
33
	{
34
		$user = $this->loadUser();
35
36
		return $user !== null ? $user->role : User::ROLE_NONE;
37
	}
38
39
	/**
40
	 * Loads the user model
41
	 * @return User the user
42
	 */
43
	protected function loadUser()
44
	{
45
		if ($this->_model === null)
46
		{
47
			if ($this->id !== null)
48
				$this->_model = User::model()->findByPk($this->id);
49
		}
50
51
		return $this->_model;
52
	}
53
54
}
55