User::checkAvatar()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
ccs 0
cts 4
cp 0
crap 12
rs 10
1
<?php
2
3
namespace Aiur18\User;
4
5
use Anax\DatabaseActiveRecord\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
    /** Variables
18
     */
19
    public $id;
20
    public $acronym;
21
    public $password;
22
    public $firstname;
23
    public $lastname;
24
    public $created;
25
    public $updated;
26
    public $deleted;
27
    public $active;
28
29
    /** Method
30
     */
31
    public function setPassword($password)
32
    {
33
        $this->password = password_hash($password, PASSWORD_DEFAULT);
34
    }
35
36
    /** Method
37
     */
38
    public function verifyPassword($acronym, $password)
39
    {
40
        $this->find("acronym", $acronym);
41
        return password_verify($password, $this->password);
42
    }
43
44
45
      /**
46
     * Method
47
     */
48
    public function setSession($id)
49
    {
50
        $_SESSION['user_id'] = $id;
51
    }
52
53
      /**
54
     * Method
55
     */
56
    public function getSession()
57
    {
58
        return $_SESSION['user_id'];
59
    }
60
61
      /**
62
     * Method
63
     */
64
    public function logoutSession()
65
    {
66
        session_destroy();
67
        session_start();
68
    }
69
70
71
      /**
72
     * Method
73
     */
74
    public function checkAvatar($avatar)
75
    {
76
        if ($avatar == null || $avatar == "") {
77
            return "..\img\placeholder-avatar.jpg";
78
        } else {
79
            return $avatar;
80
        }
81
    }
82
}
83