User   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 62.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 61
ccs 5
cts 8
cp 0.625
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setPassword() 0 4 1
A verifyPassword() 0 5 1
A gravatar() 0 4 1
1
<?php
2
3
namespace Anax\User;
4
5
use \Anax\Database\ActiveRecordModel;
6
7
/**
8
 * A database driven model.
9
 */
10
class User extends ActiveRecordModel
11
{
12
13
    /**
14
     * @var string $tableName name of the database table.
15
     */
16
    protected $tableName = "User";
17
18
    /**
19
     * Columns in the table.
20
     *
21
     * @var integer $id primary key auto incremented.
22
     */
23
    public $id;
24
    public $acronym;
25
    public $password;
26
    public $email;
27
    public $gravatar;
28
    public $created;
29
    public $updated;
30
    public $deleted;
31
    public $active;
32
    //public $role;
33
34
    /**
35
     * Set the password.
36
     *
37
     * @param string $password the password to use.
38
     *
39
     * @return void
40
     */
41 1
    public function setPassword($password)
42
    {
43 1
        $this->password = password_hash($password, PASSWORD_DEFAULT);
44 1
    }
45
46
    /**
47
     * Verify the acronym and the password, if successful the object contains
48
     * all details from the database row.
49
     *
50
     * @param string $acronym  acronym to check.
51
     * @param string $password the password to use.
52
     *
53
     * @return boolean true if acronym and password matches, else false.
54
     */
55
    public function verifyPassword($acronym, $password)
56
    {
57
        $this->find("acronym", $acronym);
58
        return password_verify($password, $this->password);
59
    }
60
61
    /**
62
    * @param string email
63
    *
64
    * @return string gravatar
65
    **/
66 2
    public function gravatar($email)
67
    {
68 2
        return "https://www.gravatar.com/avatar/" . md5(strtolower(trim($email))) . "&s=" . 40;
69
    }
70
}
71