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 100%

Importance

Changes 0
Metric Value
dl 0
loc 61
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setPassword() 0 4 1
A verifyPassword() 0 5 1
A getUserData() 0 5 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
     * @var string $tableName name of the database table.
14
     */
15
    protected $tableName = "User";
16
17
    /**
18
     * Columns in the table.
19
     *
20
     * @var integer $id primary key auto incremented.
21
     */
22
    public $id;
23
    public $acronym;
24
    public $email;
25
    public $password;
26
    public $created;
27
    public $updated;
28
    public $deleted;
29
    public $active;
30
31
    /**
32
     * Set the password.
33
     *
34
     * @param string $password the password to use.
35
     *
36
     * @return void
37
     */
38 3
    public function setPassword($password)
39
    {
40 3
        $this->password = password_hash($password, PASSWORD_DEFAULT);
41 3
    }
42
43
    /**
44
     * Verify the acronym and the password, if successful the object contains
45
     * all details from the database row.
46
     *
47
     * @param string $acronym  acronym to check.
48
     * @param string $password the password to use.
49
     *
50
     * @return boolean true if acronym and password matches, else false.
51
     */
52 2
    public function verifyPassword($acronym, $password)
53
    {
54 2
        $this->find("acronym", $acronym);
55 2
        return password_verify($password, $this->password);
56
    }
57
58
    /**
59
     * Fetch data from the database for a specific user
60
     *
61
     * @param string $acronym  acronym for the user.
62
     *
63
     * @return array data for the user.
64
     */
65 2
    public function getUserData($acronym)
66
    {
67 2
        $data = $this->find("acronym", $acronym);
68 2
        return $data;
69
    }
70
}
71