Completed
Push — master ( 443bff...94d0aa )
by Dmitry
13:27
created

Identity   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
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 53
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 13 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
/**
14
 * Identity model for MRDP database.
15
 *
16
 * @property string $roles
17
 * @property string $seller
18
 * @property integer $seller_id
19
 */
20
class Identity extends \hiam\models\Identity
21
{
22
    public $roles;
23
    public $seller;
24
    public $seller_id;
25
    public $email_confirmed;
26
    public $email_new;
27
    public $send_me_news;
28
29
    protected $activeStates = ['ok', 'active'];
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function rules()
35
    {
36
        return array_merge(parent::rules(), [
37
            ['seller_id',       'integer'],
38
39
            ['seller',          'trim'],
40
            ['seller',          'string', 'min' => 2, 'max' => 64],
41
42
            ['roles',           'trim'],
43
            ['email_confirmed', 'email'],
44
            ['send_me_news',    'boolean'],
45
        ]);
46
    }
47
48
    public function isActive()
49
    {
50
        return \in_array($this->state, $this->activeStates, true);
51
    }
52
53
    public function isEmailConfirmed()
54
    {
55
        return !empty($this->email_confirmed);
56
    }
57
58
    public function setNewUnconfirmedEmail(string $newEmail): bool
59
    {
60
        $this->email_new = $newEmail;
61
62
        return true;
63
    }
64
65
    public function setConfirmedEmail(string $email)
66
    {
67
        $this->state = 'ok';
68
        $this->email = $email;
69
        $this->email_confirmed = $email;
70
        $this->save();
71
    }
72
}
73