Kohana_Model_Auth_User   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 27.27%

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 7
dl 0
loc 98
ccs 12
cts 44
cp 0.2727
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 50 1
A unique_key() 0 4 3
A complete_login() 0 14 2
A load_service_values() 0 4 1
A build_user_token() 0 6 1
A has_facebook() 0 4 1
1
<?php defined('SYSPATH') OR die('No direct access allowed.');
2
/**
3
 * Default auth user.
4
 *
5
 * @package	   Kohana/Auth
6
 * @author     Ivan Kerin
7
 * @copyright  (c) 2011-2012 Despark Ltd.
8
 * @author	   creatoro
9
 * @copyright  (c) 2011 creatoro
10
 * @license	   http://creativecommons.org/licenses/by-sa/3.0/legalcode
11
 */
12
class Kohana_Model_Auth_User extends Jam_Model {
13
14
	public $validate_password = FALSE;
15
16
	public static function initialize(Jam_Meta $meta)
17
	{
18
		$meta
19
			->name_key('email')
20
21
			->associations(array(
22
				'user_tokens' => Jam::association('hasmany'),
23
				'roles' => Jam::association('manytomany'),
24
			))
25
26
			->fields(array(
27
				'id' => Jam::field('primary'),
28
				'email' => Jam::field('string', array(
29
					'label' => 'email address',
30
				)),
31
				'password' => Jam::field('password', array(
32
					'hash_with' => array(Auth::instance(), 'hash'),
33
				)),
34
				'logins' => Jam::field('integer', array(
35
					'default' => 0,
36
					'convert_empty' => TRUE,
37
					'empty_value' => 0,
38
				)),
39
				'last_login' => Jam::field('timestamp'),
40
				'facebook_uid' => Jam::field('string'),
41
				'twitter_uid' => Jam::field('string'),
42
				'last_login_ip' => Jam::field('string', array('label' => 'Last logged from')),
43
			))
44
45
			->validator('email', array(
46
				'format' => array('email' => TRUE),
47
				'unique' => TRUE
48
			))
49
			->validator('password', array(
50
				'length' => array('minimum' => 5, 'maximum' => 30),
51
				'if' => 'validate_password',
52
			))
53
			->validator('last_login_ip', array(
54
				'format' => array('filter' => FILTER_VALIDATE_IP),
55
			))
56
			->validator('password', array(
57
				'if' => 'validate_password',
58
				'present' => TRUE,
59
				'confirmed' => TRUE,
60
			))
61
			->validator('password_confirmation', array(
62
				'present' => TRUE,
63
				'if' => 'validate_password',
64
			));
65
	}
66
67
	public static function unique_key($value)
68
	{
69
		return (is_numeric($value) OR $value === NULL) ? 'id' : 'email';
70
	}
71
72
	/**
73
	 * Complete the login for a user by incrementing the logins and saving login timestamp
74
	 *
75
	 * @return void
76
	 */
77 9
	public function complete_login()
78
	{
79 9
		if ($this->loaded())
80
		{
81
			// Update the number of logins
82 9
			$this->logins = $this->logins + 1;
0 ignored issues
show
Documentation introduced by
The property logins does not exist on object<Kohana_Model_Auth_User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property logins does not exist on object<Kohana_Model_Auth_User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
83
84
			// Set the last login date
85 9
			$this->last_login = time();
0 ignored issues
show
Documentation introduced by
The property last_login does not exist on object<Kohana_Model_Auth_User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
86
87
			// Save the user
88 9
			$this->save();
89
		}
90 9
	}
91
92 1
	public function load_service_values(Auth_Service $service, array $user_data, $create = FALSE)
0 ignored issues
show
Unused Code introduced by
The parameter $service is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $user_data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $create is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
93
	{
94
95 1
	}
96
97 2
	public function build_user_token(array $values = array())
98
	{
99 2
		return $this->user_tokens->build(Arr::merge(array(
0 ignored issues
show
Documentation introduced by
The property user_tokens does not exist on object<Kohana_Model_Auth_User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
100 2
			'expires' => time() + Kohana::$config->load('auth.lifetime'),
101 2
		), $values))->generate_unique_token();
102
	}
103
104
	public function has_facebook()
105
	{
106
		return (bool) $this->facebook_uid;
0 ignored issues
show
Documentation introduced by
The property facebook_uid does not exist on object<Kohana_Model_Auth_User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
107
	}
108
109
} // End Kohana_Model_Auth_User
110