Identity   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 3
cbo 0
dl 0
loc 56
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 14 1
A isActive() 0 4 1
A isEmailConfirmed() 0 4 1
A setNewUnconfirmedEmail() 0 6 1
A setConfirmedEmail() 0 7 1
1
<?php
2
/**
3
 * HIAM module for MRDP database compatibility
4
 *
5
 * @link      https://github.com/hiqdev/hiam-mrdp
6
 * @package   hiam-mrdp
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiam\mrdp\models;
12
13
use hiam\behaviors\SaveReferralParams;
14
15
/**
16
 * Identity model for MRDP database.
17
 *
18
 * @property string $roles
19
 * @property string $seller
20
 * @property integer $seller_id
21
 */
22
class Identity extends \hiam\models\Identity
23
{
24
    public $roles;
25
    public $seller;
26
    public $seller_id;
27
    public $email_confirmed;
28
    public $email_new;
29
    public $verified;
30
    public $send_me_news;
31
    public $referralParams;
32
33
    protected $activeStates = ['ok', 'active'];
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function rules()
39
    {
40
        return array_merge(parent::rules(), [
41
            ['seller_id',       'integer'],
42
43
            ['seller',          'trim'],
44
            ['seller',          'string', 'min' => 2, 'max' => 64],
45
46
            ['roles',           'trim'],
47
            ['email_confirmed', 'email'],
48
            ['verified',        'boolean'],
49
            ['send_me_news',    'boolean'],
50
        ]);
51
    }
52
53
    public function isActive()
54
    {
55
        return \in_array($this->state, $this->activeStates, true);
56
    }
57
58
    public function isEmailConfirmed()
59
    {
60
        return !empty($this->email_confirmed);
61
    }
62
63
    public function setNewUnconfirmedEmail(string $newEmail): bool
64
    {
65
        $this->email_new = $newEmail;
66
67
        return true;
68
    }
69
70
    public function setConfirmedEmail(string $email)
71
    {
72
        $this->state = 'ok';
73
        $this->email = $email;
74
        $this->email_confirmed = $email;
75
        $this->save();
76
    }
77
}
78